mirror of
https://github.com/Theaninova/mhlib.git
synced 2025-12-11 03:56:18 +00:00
update dependencies
This commit is contained in:
@@ -92,7 +92,7 @@ void fragment() {
|
||||
);
|
||||
}
|
||||
|
||||
void light() {
|
||||
/*void light() {
|
||||
DIFFUSE_LIGHT =project(
|
||||
tex_diffuse,
|
||||
tex_diffuse_projection,
|
||||
@@ -102,4 +102,4 @@ void light() {
|
||||
tex_diffuse_projection_world_coords,
|
||||
UV
|
||||
);
|
||||
}
|
||||
}*/
|
||||
|
||||
123
rust/Cargo.lock
generated
123
rust/Cargo.lock
generated
@@ -33,9 +33,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "binrw"
|
||||
version = "0.11.1"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "272caaf6e0bfb7d508c0606e541e2c68f85c0d6352b62d0b299924eed59fe384"
|
||||
checksum = "ab81d22cbd2d745852348b2138f3db2103afa8ce043117a374581926a523e267"
|
||||
dependencies = [
|
||||
"array-init",
|
||||
"binrw_derive",
|
||||
@@ -44,9 +44,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "binrw_derive"
|
||||
version = "0.11.1"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb4b28c1e534d96213c8966bb9240095757aa0909128985f97d16afd2e7257a8"
|
||||
checksum = "d6b019a3efebe7f453612083202887b6f1ace59e20d010672e336eea4ed5be97"
|
||||
dependencies = [
|
||||
"either",
|
||||
"owo-colors",
|
||||
@@ -69,9 +69,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.12.1"
|
||||
version = "3.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8"
|
||||
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
@@ -286,7 +286,7 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
[[package]]
|
||||
name = "godot"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#c0935ac122dd94983f0f790cd07d6c7629a7429e"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#7dbd80f6f87e4aa4d1a257aa8395de2533ab6dbc"
|
||||
dependencies = [
|
||||
"godot-core",
|
||||
"godot-macros",
|
||||
@@ -295,7 +295,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "godot-bindings"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#c0935ac122dd94983f0f790cd07d6c7629a7429e"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#7dbd80f6f87e4aa4d1a257aa8395de2533ab6dbc"
|
||||
dependencies = [
|
||||
"godot4-prebuilt",
|
||||
]
|
||||
@@ -303,19 +303,20 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "godot-codegen"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#c0935ac122dd94983f0f790cd07d6c7629a7429e"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#7dbd80f6f87e4aa4d1a257aa8395de2533ab6dbc"
|
||||
dependencies = [
|
||||
"godot-bindings",
|
||||
"heck",
|
||||
"nanoserde",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "godot-core"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#c0935ac122dd94983f0f790cd07d6c7629a7429e"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#7dbd80f6f87e4aa4d1a257aa8395de2533ab6dbc"
|
||||
dependencies = [
|
||||
"glam",
|
||||
"godot-codegen",
|
||||
@@ -325,7 +326,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "godot-ffi"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#c0935ac122dd94983f0f790cd07d6c7629a7429e"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#7dbd80f6f87e4aa4d1a257aa8395de2533ab6dbc"
|
||||
dependencies = [
|
||||
"godot-bindings",
|
||||
"godot-codegen",
|
||||
@@ -335,7 +336,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "godot-macros"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#c0935ac122dd94983f0f790cd07d6c7629a7429e"
|
||||
source = "git+https://github.com/godot-rust/gdext?branch=master#7dbd80f6f87e4aa4d1a257aa8395de2533ab6dbc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -345,7 +346,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "godot4-prebuilt"
|
||||
version = "0.0.0"
|
||||
source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=4.0.1#f9e8cfec0ec565201801b02160ef836800746617"
|
||||
source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=4.0.3#fd48aa5a437e63416360ff44e533177036e7460f"
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
@@ -410,9 +411,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.61"
|
||||
version = "0.3.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730"
|
||||
checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
@@ -459,12 +460,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
version = "0.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
@@ -591,9 +589,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
version = "1.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b"
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
@@ -609,22 +607,22 @@ checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.0.12"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc"
|
||||
checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead"
|
||||
dependencies = [
|
||||
"pin-project-internal",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.0.12"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
|
||||
checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -656,9 +654,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.56"
|
||||
version = "1.0.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
|
||||
checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -674,9 +672,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
version = "1.0.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
@@ -703,6 +701,21 @@ dependencies = [
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
|
||||
|
||||
[[package]]
|
||||
name = "renderwarelib"
|
||||
version = "0.1.0"
|
||||
@@ -724,9 +737,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.162"
|
||||
version = "1.0.163"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6"
|
||||
checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
@@ -745,13 +758,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.162"
|
||||
version = "1.0.163"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
|
||||
checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
"syn 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -807,9 +820,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.15"
|
||||
version = "2.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
|
||||
checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -833,7 +846,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.15",
|
||||
"syn 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -849,9 +862,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0"
|
||||
|
||||
[[package]]
|
||||
name = "venial"
|
||||
@@ -871,9 +884,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.84"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b"
|
||||
checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"wasm-bindgen-macro",
|
||||
@@ -881,24 +894,24 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-backend"
|
||||
version = "0.2.84"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9"
|
||||
checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn 2.0.18",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.84"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5"
|
||||
checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
@@ -906,22 +919,22 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.84"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
|
||||
checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn 2.0.18",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.84"
|
||||
version = "0.2.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d"
|
||||
checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93"
|
||||
|
||||
[[package]]
|
||||
name = "weezl"
|
||||
@@ -931,9 +944,9 @@ checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
|
||||
|
||||
[[package]]
|
||||
name = "xml-rs"
|
||||
version = "0.8.6"
|
||||
version = "0.8.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40e1a60e6e271dfb0db2db95987551348db75ebd6a78be07b9039b036f7dae2a"
|
||||
checksum = "2d8f380ae16a37b30e6a2cf67040608071384b1450c189e61bea3ff57cde922d"
|
||||
|
||||
[[package]]
|
||||
name = "zune-inflate"
|
||||
|
||||
@@ -1,21 +1,69 @@
|
||||
use godot::engine::{load, Image};
|
||||
use godot::engine::{load, AnimatedTexture, Image, ImageTexture, Texture2D};
|
||||
use godot::log::godot_error;
|
||||
use godot::obj::Gd;
|
||||
use lightwave_3d::lwo2::tags::image_clip::{ImageClip, ImageClipSubChunk};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn collect_clip(target: &mut HashMap<u32, Gd<Image>>, clip: ImageClip) {
|
||||
for img in clip.attributes.iter() {
|
||||
match img {
|
||||
ImageClipSubChunk::StillImage(still) => {
|
||||
let path = format!("sar://{}", still.name.replace('\\', "/").replace(':', ":/"));
|
||||
let mut image: Gd<Image> = load(path);
|
||||
image.set_name(still.name.clone().into());
|
||||
target.insert(clip.index, image);
|
||||
fn convert_path(path: &str) -> String {
|
||||
path.replace('\\', "/").replace(':', ":/")
|
||||
}
|
||||
|
||||
fn load_texture(path: &str, name: &str) -> Gd<ImageTexture> {
|
||||
let mut image: Gd<Image> = load(path);
|
||||
image.set_name(name.into());
|
||||
let mut texture = ImageTexture::new();
|
||||
texture.set_name(name.into());
|
||||
texture.set_image(image);
|
||||
texture
|
||||
}
|
||||
|
||||
pub fn collect_clip(target: &mut HashMap<u32, Gd<Texture2D>>, clip: ImageClip) {
|
||||
let mut attributes = clip.attributes.iter();
|
||||
|
||||
match attributes.next().unwrap() {
|
||||
ImageClipSubChunk::StillImage(still) => {
|
||||
let path = format!("sar://{}", convert_path(&still.name));
|
||||
for meta in attributes {
|
||||
godot_error!("TODO: {:?}", meta)
|
||||
}
|
||||
x => {
|
||||
godot_error!("TODO: Clip chunk {:?}", x)
|
||||
target.insert(clip.index, load_texture(&path, &still.name).upcast());
|
||||
}
|
||||
ImageClipSubChunk::ImageSequence(sequence) => {
|
||||
let mut texture = AnimatedTexture::new();
|
||||
texture.set_frames(sequence.data.end as i64 - sequence.data.start as i64);
|
||||
if sequence.data.flags & 0x1 != 1 {
|
||||
godot_error!("Non-looping animated textures are not supported!")
|
||||
}
|
||||
let mut frame_duration = 15.0 / 60.0;
|
||||
|
||||
for meta in attributes {
|
||||
match meta {
|
||||
ImageClipSubChunk::Time(time) => {
|
||||
frame_duration = time.frame_rate as f64 / 60.0;
|
||||
}
|
||||
x => godot_error!("TODO: {:?}", x),
|
||||
}
|
||||
}
|
||||
|
||||
for i in sequence.data.start..sequence.data.end {
|
||||
let path = format!(
|
||||
"sar://{}{:0width$}{}",
|
||||
convert_path(&sequence.data.prefix),
|
||||
i,
|
||||
sequence.data.suffix,
|
||||
width = sequence.data.num_digits as usize
|
||||
);
|
||||
let frame = i as i64 - sequence.data.start as i64;
|
||||
|
||||
texture.set_frame_texture(frame, load_texture(&path, &i.to_string()).upcast());
|
||||
texture.set_frame_duration(frame, frame_duration);
|
||||
}
|
||||
|
||||
// texture.set_current_frame(sequence.data.offset as i64);
|
||||
target.insert(clip.index, texture.upcast());
|
||||
}
|
||||
x => {
|
||||
godot_error!("TODO: Clip chunk {:?}", x)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::lwo::surface_info::SurfaceInfo;
|
||||
use godot::builtin::{Array, Dictionary, Vector2, Vector3};
|
||||
use godot::engine::mesh::{ArrayFormat, PrimitiveType};
|
||||
use godot::engine::{ArrayMesh, SurfaceTool};
|
||||
use godot::log::godot_print;
|
||||
use godot::obj::{Gd, Share};
|
||||
use itertools::Itertools;
|
||||
use lightwave_3d::lwo2::tags::polygon_list::PolygonList;
|
||||
@@ -24,16 +25,13 @@ pub struct IntermediateLayer {
|
||||
}
|
||||
|
||||
impl IntermediateLayer {
|
||||
pub fn commit(mut self, materials: &HashMap<u16, MaterialUvInfo>) -> Gd<ArrayMesh> {
|
||||
pub fn commit(self, materials: &HashMap<u16, MaterialUvInfo>) -> Gd<ArrayMesh> {
|
||||
let mut mesh = ArrayMesh::new();
|
||||
mesh.set_name(self.name.clone().into());
|
||||
let mut surface_material_ids = Vec::<u16>::new();
|
||||
|
||||
self.uv_mappings.sort_by(|a, b| a.0.cmp(&b.0));
|
||||
|
||||
for material_id in self.material_mappings.values().unique() {
|
||||
let material = &materials[material_id];
|
||||
let surface_info = SurfaceInfo::collect_from_layer(&self, material);
|
||||
let surface_info = SurfaceInfo::collect_from_layer(&self, &materials[material_id]);
|
||||
|
||||
if !surface_info.is_empty() {
|
||||
mesh.add_surface_from_arrays(
|
||||
@@ -47,6 +45,16 @@ impl IntermediateLayer {
|
||||
}
|
||||
}
|
||||
|
||||
godot_print!(
|
||||
"{}: {:?}",
|
||||
&self.name,
|
||||
surface_material_ids
|
||||
.iter()
|
||||
.unique()
|
||||
.map(|id| { (*id, materials[id].material.get_name().to_string()) })
|
||||
.collect_vec()
|
||||
);
|
||||
|
||||
let mut final_mesh = post_process_mesh(
|
||||
mesh,
|
||||
materials,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use godot::builtin::{Basis, Color, EulerOrder, ToVariant, Transform3D, Variant, Vector3};
|
||||
use godot::engine::{load, Image, ImageTexture, ShaderMaterial};
|
||||
use godot::engine::{load, PlaceholderTexture2D, ShaderMaterial, Texture2D};
|
||||
use godot::log::{godot_error, godot_print};
|
||||
use godot::obj::{Gd, Share};
|
||||
use lightwave_3d::lwo2::sub_tags::blocks::image_texture::{
|
||||
@@ -24,7 +24,11 @@ pub struct MaterialUvInfo {
|
||||
}
|
||||
|
||||
impl MaterialUvInfo {
|
||||
pub fn collect(surface: SurfaceDefinition, images: &HashMap<u32, Gd<Image>>, id: u16) -> Self {
|
||||
pub fn collect(
|
||||
surface: SurfaceDefinition,
|
||||
textures: &HashMap<u32, Gd<Texture2D>>,
|
||||
id: u16,
|
||||
) -> Self {
|
||||
let mut m = MaterialUvInfo {
|
||||
diffuse_channel: None,
|
||||
color_channel: None,
|
||||
@@ -39,7 +43,7 @@ impl MaterialUvInfo {
|
||||
match attr {
|
||||
SurfaceParameterSubChunk::Blocks(blocks) => {
|
||||
if let SurfaceBlocks::ImageMapTexture { header, attributes } = blocks.data {
|
||||
let mut texture = ImageTexture::new();
|
||||
let mut texture: Gd<Texture2D> = PlaceholderTexture2D::new().upcast();
|
||||
let mut chan = TextureChannel::Color;
|
||||
let mut uv_channel = None;
|
||||
let mut major_axis = 0;
|
||||
@@ -67,9 +71,12 @@ impl MaterialUvInfo {
|
||||
for attr in attributes {
|
||||
match attr {
|
||||
SurfaceBlockImageTextureSubChunk::ImageMap(r) => {
|
||||
if let Some(i) = images.get(&r.texture_image) {
|
||||
godot_print!("{}", i.get_name());
|
||||
texture.set_image(i.share());
|
||||
if let Some(tex) = textures.get(&r.texture_image) {
|
||||
godot_print!("{}", tex.get_name());
|
||||
debug_assert!(texture
|
||||
.try_cast::<PlaceholderTexture2D>()
|
||||
.is_some());
|
||||
texture = tex.share()
|
||||
} else {
|
||||
godot_error!("Missing texture {:?}", r);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::lwo::mapping::{collect_discontinuous_mappings, collect_mappings};
|
||||
use crate::lwo::material::MaterialUvInfo;
|
||||
use godot::builtin::{Vector2, Vector3};
|
||||
use godot::engine::node::InternalMode;
|
||||
use godot::engine::{Image, MeshInstance3D, Node3D, PackedScene};
|
||||
use godot::engine::{MeshInstance3D, Node3D, PackedScene, Texture2D};
|
||||
use godot::log::{godot_error, godot_print, godot_warn};
|
||||
use godot::obj::{Gd, Share};
|
||||
use itertools::Itertools;
|
||||
@@ -13,8 +13,8 @@ use lightwave_3d::LightWaveObject;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn lightwave_to_gd(lightwave: LightWaveObject) -> Gd<PackedScene> {
|
||||
let mut surfaces = HashMap::<u16, MaterialUvInfo>::new();
|
||||
let mut images = HashMap::<u32, Gd<Image>>::new();
|
||||
let mut materials = HashMap::<u16, MaterialUvInfo>::new();
|
||||
let mut textures = HashMap::<u32, Gd<Texture2D>>::new();
|
||||
let mut layers = vec![];
|
||||
let mut tag_strings = vec![];
|
||||
|
||||
@@ -26,7 +26,11 @@ pub fn lightwave_to_gd(lightwave: LightWaveObject) -> Gd<PackedScene> {
|
||||
}
|
||||
Tag::Layer(layer_tag) => {
|
||||
layers.push(IntermediateLayer {
|
||||
name: layer_tag.name.clone(),
|
||||
name: if layer_tag.name.is_empty() {
|
||||
format!("layer_{}", layer_tag.number)
|
||||
} else {
|
||||
layer_tag.name.clone()
|
||||
},
|
||||
parent: layer_tag.parent,
|
||||
id: layer_tag.number,
|
||||
pivot: Vector3 {
|
||||
@@ -132,7 +136,7 @@ pub fn lightwave_to_gd(lightwave: LightWaveObject) -> Gd<PackedScene> {
|
||||
}
|
||||
x => godot_warn!("{}", String::from_utf8(x.to_vec()).unwrap()),
|
||||
},
|
||||
Tag::ImageClip(clip) => collect_clip(&mut images, clip.data),
|
||||
Tag::ImageClip(clip) => collect_clip(&mut textures, clip.data),
|
||||
Tag::SurfaceDefinition(surf) => {
|
||||
let surf_name = surf.name.clone();
|
||||
let (tag_index, _) = tag_strings
|
||||
@@ -141,9 +145,9 @@ pub fn lightwave_to_gd(lightwave: LightWaveObject) -> Gd<PackedScene> {
|
||||
.expect("Invalid File");
|
||||
godot_print!("'{}': {}", surf_name, tag_index);
|
||||
|
||||
surfaces.insert(
|
||||
materials.insert(
|
||||
tag_index as u16,
|
||||
MaterialUvInfo::collect(surf.data, &images, tag_index as u16),
|
||||
MaterialUvInfo::collect(surf.data, &textures, tag_index as u16),
|
||||
);
|
||||
}
|
||||
Tag::BoundingBox(_) => (),
|
||||
@@ -171,7 +175,7 @@ pub fn lightwave_to_gd(lightwave: LightWaveObject) -> Gd<PackedScene> {
|
||||
for layer in layers {
|
||||
let mut instance = MeshInstance3D::new_alloc();
|
||||
instance.set_name(layer.name.clone().into());
|
||||
instance.set_mesh(layer.commit(&surfaces).upcast());
|
||||
instance.set_mesh(layer.commit(&materials).upcast());
|
||||
|
||||
root_node.add_child(
|
||||
instance.share().upcast(),
|
||||
|
||||
@@ -68,46 +68,42 @@ impl SurfaceInfo {
|
||||
);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
for (i, inc) in self.material_incomplete.into_iter().enumerate() {
|
||||
if inc != 0 {
|
||||
godot_error!(
|
||||
"{} ({}%) incomplete UVs",
|
||||
inc,
|
||||
(inc as f32 / self.vertices.len() as f32) * 100.0
|
||||
);
|
||||
}
|
||||
for inc in self.material_incomplete.into_iter().filter(|it| it != &0) {
|
||||
let percentage = (inc as f32 / self.vertices.len() as f32) * 100.0;
|
||||
godot_error!("{} ({}%) incomplete UVs", inc, percentage);
|
||||
}
|
||||
|
||||
arrays
|
||||
}
|
||||
|
||||
pub fn collect_from_layer(layer: &IntermediateLayer, material: &MaterialUvInfo) -> Self {
|
||||
let material_uv_names = [
|
||||
let uv_names = [
|
||||
material.diffuse_channel.as_ref(),
|
||||
material.color_channel.as_ref(),
|
||||
];
|
||||
|
||||
let materials_subset = material_uv_names
|
||||
let uv_subset = uv_names
|
||||
.iter()
|
||||
.map(|it| it.and_then(|it| layer.uv_mappings.iter().find(|(name, _)| name == it)))
|
||||
.collect_vec();
|
||||
|
||||
let mut surface_info = SurfaceInfo {
|
||||
uv_sets: materials_subset
|
||||
uv_sets: uv_subset
|
||||
.iter()
|
||||
.map(|it| it.map(|_| PackedVector2Array::new()))
|
||||
.collect(),
|
||||
material_incomplete: material_uv_names.iter().map(|_| 0).collect_vec(),
|
||||
material_incomplete: uv_names.iter().map(|_| 0).collect_vec(),
|
||||
..SurfaceInfo::default()
|
||||
};
|
||||
|
||||
let mut surface_polygons = layer.polygons.iter().enumerate().filter(|(id, _)| {
|
||||
layer.material_mappings.get(&(*id as i32)).unwrap_or(&0) == &material.id
|
||||
});
|
||||
let surface_polygons =
|
||||
layer.polygons.iter().enumerate().filter(|(id, _)| {
|
||||
layer.material_mappings.get(&(*id as i32)).unwrap() == &material.id
|
||||
});
|
||||
|
||||
for (id, poly) in surface_polygons {
|
||||
for index in triangulate(&poly.vert) {
|
||||
let uv = materials_subset
|
||||
let uv = uv_subset
|
||||
.iter()
|
||||
.map(|it| it.and_then(|(_, it)| find_mapping(it, id, index)))
|
||||
.collect_vec();
|
||||
|
||||
@@ -7,7 +7,7 @@ use binrw::{binread, parser, until_exclusive, BinResult, NullString};
|
||||
pub struct Container {
|
||||
#[br(temp, args(string_size))]
|
||||
pub header: FileEntry,
|
||||
#[br(parse_with = until_end, args_raw(string_size))]
|
||||
#[br(parse_with = until_end, args_raw((string_size,)))]
|
||||
pub entries: Vec<FileEntry>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user