From 45e33ce1bf8ed719531aa0a71c2f63bf26d16a13 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 24 Apr 2020 16:36:44 -0400 Subject: [PATCH 01/26] first commit --- port/AssimpRs/Cargo.toml | 9 +++++++++ port/AssimpRs/src/lib.rs | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 port/AssimpRs/Cargo.toml create mode 100644 port/AssimpRs/src/lib.rs diff --git a/port/AssimpRs/Cargo.toml b/port/AssimpRs/Cargo.toml new file mode 100644 index 000000000..705699b23 --- /dev/null +++ b/port/AssimpRs/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "AssimpRs" +version = "0.1.0" +authors = ["David Golembiowski "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/port/AssimpRs/src/lib.rs b/port/AssimpRs/src/lib.rs new file mode 100644 index 000000000..31e1bb209 --- /dev/null +++ b/port/AssimpRs/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} From df57ee6cb618a45872210f2a9019cc0b866ca6ca Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 24 Apr 2020 16:49:38 -0400 Subject: [PATCH 02/26] laying out the submodules --- port/AssimpRs/src/camera/mod.rs | 0 port/AssimpRs/src/core/mod.rs | 0 port/AssimpRs/src/errors/mod.rs | 0 port/AssimpRs/src/formats/mod.rs | 0 port/AssimpRs/src/material/mod.rs | 0 port/AssimpRs/src/postprocess/mod.rs | 0 port/AssimpRs/src/shims/mod.rs | 0 port/AssimpRs/src/socket/mod.rs | 0 port/AssimpRs/src/structs/mod.rs | 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 port/AssimpRs/src/camera/mod.rs create mode 100644 port/AssimpRs/src/core/mod.rs create mode 100644 port/AssimpRs/src/errors/mod.rs create mode 100644 port/AssimpRs/src/formats/mod.rs create mode 100644 port/AssimpRs/src/material/mod.rs create mode 100644 port/AssimpRs/src/postprocess/mod.rs create mode 100644 port/AssimpRs/src/shims/mod.rs create mode 100644 port/AssimpRs/src/socket/mod.rs create mode 100644 port/AssimpRs/src/structs/mod.rs diff --git a/port/AssimpRs/src/camera/mod.rs b/port/AssimpRs/src/camera/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/core/mod.rs b/port/AssimpRs/src/core/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/errors/mod.rs b/port/AssimpRs/src/errors/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/formats/mod.rs b/port/AssimpRs/src/formats/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/material/mod.rs b/port/AssimpRs/src/material/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/postprocess/mod.rs b/port/AssimpRs/src/postprocess/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/shims/mod.rs b/port/AssimpRs/src/shims/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/socket/mod.rs b/port/AssimpRs/src/socket/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/AssimpRs/src/structs/mod.rs b/port/AssimpRs/src/structs/mod.rs new file mode 100644 index 000000000..e69de29bb From 5d05c536e7a6421b347142450f5149058c1f48d2 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 24 Apr 2020 17:02:36 -0400 Subject: [PATCH 03/26] updated gitignore and made port library name compliant with cargo --- port/AssimpRs/Cargo.toml | 9 --------- port/AssimpRs/src/camera/mod.rs | 0 port/AssimpRs/src/core/mod.rs | 0 port/AssimpRs/src/errors/mod.rs | 0 port/AssimpRs/src/formats/mod.rs | 0 port/AssimpRs/src/lib.rs | 7 ------- port/AssimpRs/src/material/mod.rs | 0 port/AssimpRs/src/postprocess/mod.rs | 0 port/AssimpRs/src/shims/mod.rs | 0 port/AssimpRs/src/socket/mod.rs | 0 port/AssimpRs/src/structs/mod.rs | 0 11 files changed, 16 deletions(-) delete mode 100644 port/AssimpRs/Cargo.toml delete mode 100644 port/AssimpRs/src/camera/mod.rs delete mode 100644 port/AssimpRs/src/core/mod.rs delete mode 100644 port/AssimpRs/src/errors/mod.rs delete mode 100644 port/AssimpRs/src/formats/mod.rs delete mode 100644 port/AssimpRs/src/lib.rs delete mode 100644 port/AssimpRs/src/material/mod.rs delete mode 100644 port/AssimpRs/src/postprocess/mod.rs delete mode 100644 port/AssimpRs/src/shims/mod.rs delete mode 100644 port/AssimpRs/src/socket/mod.rs delete mode 100644 port/AssimpRs/src/structs/mod.rs diff --git a/port/AssimpRs/Cargo.toml b/port/AssimpRs/Cargo.toml deleted file mode 100644 index 705699b23..000000000 --- a/port/AssimpRs/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "AssimpRs" -version = "0.1.0" -authors = ["David Golembiowski "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/port/AssimpRs/src/camera/mod.rs b/port/AssimpRs/src/camera/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/core/mod.rs b/port/AssimpRs/src/core/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/errors/mod.rs b/port/AssimpRs/src/errors/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/formats/mod.rs b/port/AssimpRs/src/formats/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/lib.rs b/port/AssimpRs/src/lib.rs deleted file mode 100644 index 31e1bb209..000000000 --- a/port/AssimpRs/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/port/AssimpRs/src/material/mod.rs b/port/AssimpRs/src/material/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/postprocess/mod.rs b/port/AssimpRs/src/postprocess/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/shims/mod.rs b/port/AssimpRs/src/shims/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/socket/mod.rs b/port/AssimpRs/src/socket/mod.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/AssimpRs/src/structs/mod.rs b/port/AssimpRs/src/structs/mod.rs deleted file mode 100644 index e69de29bb..000000000 From 6363bf34c0f80ac41acd4fbd0a8b1b11f2533654 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 24 Apr 2020 17:03:41 -0400 Subject: [PATCH 04/26] see git commit message rust-port 5d05c536 --- .gitignore | 6 ++++++ port/assimp_rs/Cargo.lock | 6 ++++++ port/assimp_rs/Cargo.toml | 9 +++++++++ port/assimp_rs/src/camera/mod.rs | 0 port/assimp_rs/src/core/mod.rs | 0 port/assimp_rs/src/errors/mod.rs | 0 port/assimp_rs/src/formats/mod.rs | 0 port/assimp_rs/src/lib.rs | 17 +++++++++++++++++ port/assimp_rs/src/material/mod.rs | 0 port/assimp_rs/src/postprocess/mod.rs | 0 port/assimp_rs/src/shims/mod.rs | 0 port/assimp_rs/src/socket/mod.rs | 0 port/assimp_rs/src/structs/mod.rs | 0 13 files changed, 38 insertions(+) create mode 100644 port/assimp_rs/Cargo.lock create mode 100644 port/assimp_rs/Cargo.toml create mode 100644 port/assimp_rs/src/camera/mod.rs create mode 100644 port/assimp_rs/src/core/mod.rs create mode 100644 port/assimp_rs/src/errors/mod.rs create mode 100644 port/assimp_rs/src/formats/mod.rs create mode 100644 port/assimp_rs/src/lib.rs create mode 100644 port/assimp_rs/src/material/mod.rs create mode 100644 port/assimp_rs/src/postprocess/mod.rs create mode 100644 port/assimp_rs/src/shims/mod.rs create mode 100644 port/assimp_rs/src/socket/mod.rs create mode 100644 port/assimp_rs/src/structs/mod.rs diff --git a/.gitignore b/.gitignore index e975976bf..fe59f9a70 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,12 @@ test/gtest/src/gtest-stamp/Debug/ tools/assimp_view/assimp_viewer.vcxproj.user *.pyc +### Rust ### +# Generated by Cargo; will have compiled files and executables +port/assimp_rs/target/ +# Backup files generated by rustfmt +port/assimp_rs/**/*.rs.bk + # Unix editor backups *~ test/gtest/src/gtest-stamp/gtest-gitinfo.txt diff --git a/port/assimp_rs/Cargo.lock b/port/assimp_rs/Cargo.lock new file mode 100644 index 000000000..4f571f362 --- /dev/null +++ b/port/assimp_rs/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "assimp_rs" +version = "0.1.0" + diff --git a/port/assimp_rs/Cargo.toml b/port/assimp_rs/Cargo.toml new file mode 100644 index 000000000..073a2b283 --- /dev/null +++ b/port/assimp_rs/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "assimp_rs" +version = "0.1.0" +authors = ["David Golembiowski "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/port/assimp_rs/src/camera/mod.rs b/port/assimp_rs/src/camera/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/core/mod.rs b/port/assimp_rs/src/core/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/errors/mod.rs b/port/assimp_rs/src/errors/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/formats/mod.rs b/port/assimp_rs/src/formats/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/lib.rs b/port/assimp_rs/src/lib.rs new file mode 100644 index 000000000..dbb648876 --- /dev/null +++ b/port/assimp_rs/src/lib.rs @@ -0,0 +1,17 @@ +pub mod camera; +pub mod core; +pub mod errors; +pub mod formats; +pub mod material; +pub mod postprocess; +pub mod shims; +pub mod socket; +pub mod structs; + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(true, true); + } +} diff --git a/port/assimp_rs/src/material/mod.rs b/port/assimp_rs/src/material/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/postprocess/mod.rs b/port/assimp_rs/src/postprocess/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/shims/mod.rs b/port/assimp_rs/src/shims/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/socket/mod.rs b/port/assimp_rs/src/socket/mod.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/mod.rs b/port/assimp_rs/src/structs/mod.rs new file mode 100644 index 000000000..e69de29bb From 2108e08c900a624ae9a0a858860e7932635ee9a9 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 24 Apr 2020 18:15:51 -0400 Subject: [PATCH 05/26] adding structs --- port/assimp_rs/src/structs/mod.rs | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/port/assimp_rs/src/structs/mod.rs b/port/assimp_rs/src/structs/mod.rs index e69de29bb..fd9087648 100644 --- a/port/assimp_rs/src/structs/mod.rs +++ b/port/assimp_rs/src/structs/mod.rs @@ -0,0 +1,61 @@ +mod anim; +/* Animation + * NodeAnim + * MeshAnim + * MeshMorphAnim + */ +mod blob; +/* ExportDataBlob + */ +mod vec; +/* Vector2d + * Vector3d + * */ +mod matrix; +/* Matrix3by3 + * Matrix4by4 + */ +mod camera; +/* Camera */ +mod color; +/* Color3d + * Color4d + */ +mod key; +/* MeshKey + * MeshMorphKey + * QuatKey + * VectorKey + */ +mod texel; +mod plane; +mod string; +/* String + */ +mod material; +/* Material + * MaterialPropery + * MaterialPropertyString + */ +mod mem; +mod quaternion; +mod face; +mod vertex_weight; +mod mesh; +/* Mesh + */ +mod meta; +/* Metadata + * MetadataEntry + */ +mod node; +/* Node + * */ +mod light; +mod texture; +mod ray; +mod transform; +/* UVTransform */ +mod bone; +mod scene; +/* Scene */ From 060c45fcf3b4019446560c079adafb8a5b894f40 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 24 Apr 2020 22:15:32 -0400 Subject: [PATCH 06/26] initial layout for anim.rs --- port/assimp_rs/src/structs/anim.rs | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 port/assimp_rs/src/structs/anim.rs diff --git a/port/assimp_rs/src/structs/anim.rs b/port/assimp_rs/src/structs/anim.rs new file mode 100644 index 000000000..5374151eb --- /dev/null +++ b/port/assimp_rs/src/structs/anim.rs @@ -0,0 +1,44 @@ +pub struct Animation<'mA, 'mMA, 'nA> { + /* The name of the animation. If the modeling package this data was + * exported from does support only a single animation channel, this + * name is usually empty (length is zero). + */ + m_name: Option, + // Duration of the animation in ticks + m_duration: f64, + // Ticks per second. Zero (0.000... ticks/second) if not + // specified in the imported file + m_ticks_per_second: Option, + /* Number of bone animation channels. + Each channel affects a single node. + */ + m_num_channels: u64, + /* Node animation channels. Each channel + affects a single node. + ?? -> The array is m_num_channels in size. + (maybe refine to a derivative type of usize?) + */ + m_channels: &'nA NodeAnim, + /* Number of mesh animation channels. Each + channel affects a single mesh and defines + vertex-based animation. + */ + m_num_mesh_channels: u64, + /* The mesh animation channels. Each channel + affects a single mesh. + The array is m_num_mesh_channels in size + (maybe refine to a derivative of usize?) + */ + m_mesh_channels: &'mA MeshAnim, + /* The number of mesh animation channels. Each channel + affects a single mesh and defines some morphing animation. + */ + m_num_morph_mesh_channels: u64, + /* The morph mesh animation channels. Each channel affects a single mesh. + The array is mNumMorphMeshChannels in size. + */ + m_morph_mesh_channels: &'mMA MeshMorphAnim +} +pub struct NodeAnim {} +pub struct MeshAnim {} +pub struct MeshMorphAnim {} From e438310d8cc3718fdc32d62462b8217569f9c766 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Sat, 25 Apr 2020 00:12:58 -0400 Subject: [PATCH 07/26] should have added these earlier --- port/assimp_rs/src/structs/blob.rs | 0 port/assimp_rs/src/structs/bone.rs | 0 port/assimp_rs/src/structs/camera.rs | 0 port/assimp_rs/src/structs/color.rs | 0 port/assimp_rs/src/structs/face.rs | 0 port/assimp_rs/src/structs/key.rs | 0 port/assimp_rs/src/structs/light.rs | 0 port/assimp_rs/src/structs/material.rs | 0 port/assimp_rs/src/structs/matrix.rs | 0 port/assimp_rs/src/structs/mem.rs | 0 port/assimp_rs/src/structs/mesh.rs | 0 port/assimp_rs/src/structs/meta.rs | 0 port/assimp_rs/src/structs/node.rs | 0 port/assimp_rs/src/structs/plane.rs | 0 port/assimp_rs/src/structs/quaternion.rs | 0 port/assimp_rs/src/structs/ray.rs | 0 port/assimp_rs/src/structs/scene.rs | 0 port/assimp_rs/src/structs/string.rs | 0 port/assimp_rs/src/structs/texel.rs | 0 port/assimp_rs/src/structs/texture.rs | 0 port/assimp_rs/src/structs/transform.rs | 0 port/assimp_rs/src/structs/vec.rs | 0 port/assimp_rs/src/structs/vertex_weight.rs | 0 23 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 port/assimp_rs/src/structs/blob.rs create mode 100644 port/assimp_rs/src/structs/bone.rs create mode 100644 port/assimp_rs/src/structs/camera.rs create mode 100644 port/assimp_rs/src/structs/color.rs create mode 100644 port/assimp_rs/src/structs/face.rs create mode 100644 port/assimp_rs/src/structs/key.rs create mode 100644 port/assimp_rs/src/structs/light.rs create mode 100644 port/assimp_rs/src/structs/material.rs create mode 100644 port/assimp_rs/src/structs/matrix.rs create mode 100644 port/assimp_rs/src/structs/mem.rs create mode 100644 port/assimp_rs/src/structs/mesh.rs create mode 100644 port/assimp_rs/src/structs/meta.rs create mode 100644 port/assimp_rs/src/structs/node.rs create mode 100644 port/assimp_rs/src/structs/plane.rs create mode 100644 port/assimp_rs/src/structs/quaternion.rs create mode 100644 port/assimp_rs/src/structs/ray.rs create mode 100644 port/assimp_rs/src/structs/scene.rs create mode 100644 port/assimp_rs/src/structs/string.rs create mode 100644 port/assimp_rs/src/structs/texel.rs create mode 100644 port/assimp_rs/src/structs/texture.rs create mode 100644 port/assimp_rs/src/structs/transform.rs create mode 100644 port/assimp_rs/src/structs/vec.rs create mode 100644 port/assimp_rs/src/structs/vertex_weight.rs diff --git a/port/assimp_rs/src/structs/blob.rs b/port/assimp_rs/src/structs/blob.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/bone.rs b/port/assimp_rs/src/structs/bone.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/camera.rs b/port/assimp_rs/src/structs/camera.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/color.rs b/port/assimp_rs/src/structs/color.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/face.rs b/port/assimp_rs/src/structs/face.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/key.rs b/port/assimp_rs/src/structs/key.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/light.rs b/port/assimp_rs/src/structs/light.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/material.rs b/port/assimp_rs/src/structs/material.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/matrix.rs b/port/assimp_rs/src/structs/matrix.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/mem.rs b/port/assimp_rs/src/structs/mem.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/mesh.rs b/port/assimp_rs/src/structs/mesh.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/meta.rs b/port/assimp_rs/src/structs/meta.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/node.rs b/port/assimp_rs/src/structs/node.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/plane.rs b/port/assimp_rs/src/structs/plane.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/quaternion.rs b/port/assimp_rs/src/structs/quaternion.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/ray.rs b/port/assimp_rs/src/structs/ray.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/scene.rs b/port/assimp_rs/src/structs/scene.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/string.rs b/port/assimp_rs/src/structs/string.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/texel.rs b/port/assimp_rs/src/structs/texel.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/texture.rs b/port/assimp_rs/src/structs/texture.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/transform.rs b/port/assimp_rs/src/structs/transform.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/vec.rs b/port/assimp_rs/src/structs/vec.rs new file mode 100644 index 000000000..e69de29bb diff --git a/port/assimp_rs/src/structs/vertex_weight.rs b/port/assimp_rs/src/structs/vertex_weight.rs new file mode 100644 index 000000000..e69de29bb From 4dfdbbf171674756f281dbad07e335bb5e4d989d Mon Sep 17 00:00:00 2001 From: qarmin Date: Tue, 28 Apr 2020 20:31:59 +0200 Subject: [PATCH 08/26] Check index before using --- code/glTF/glTFCommon.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/glTF/glTFCommon.cpp b/code/glTF/glTFCommon.cpp index 1c662a16a..17da49fb8 100644 --- a/code/glTF/glTFCommon.cpp +++ b/code/glTF/glTFCommon.cpp @@ -145,13 +145,13 @@ bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) { size_t i = 5, j; if (uri[i] != ';' && uri[i] != ',') { // has media type? uri[1] = char(i); - for (; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) { + for (;i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) { // nothing to do! } } - while (uri[i] == ';' && i < uriLen) { + while (i < uriLen && uri[i] == ';') { uri[i++] = '\0'; - for (j = i; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) { + for (j = i; i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) { // nothing to do! } From e6c4175d8dff75d0a2a62ce15c4b4299130b40f8 Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Fri, 1 May 2020 11:49:15 +0100 Subject: [PATCH 09/26] Rename Collada export tests Use existing naming convention. Brings all Collada tests together in Test Explorers --- test/CMakeLists.txt | 3 +- ...adaExportLight.cpp => utColladaExport.cpp} | 51 +++++++- test/unit/utColladaExportCamera.cpp | 115 ------------------ 3 files changed, 50 insertions(+), 119 deletions(-) rename test/unit/{utColladaExportLight.cpp => utColladaExport.cpp} (78%) delete mode 100644 test/unit/utColladaExportCamera.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bf6694845..a5f8086e9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -124,8 +124,7 @@ SET( IMPORTERS unit/utBlendImportMaterials.cpp unit/utBlenderWork.cpp unit/utBVHImportExport.cpp - unit/utColladaExportCamera.cpp - unit/utColladaExportLight.cpp + unit/utColladaExport.cpp unit/utColladaImportExport.cpp unit/utCSMImportExport.cpp unit/utB3DImportExport.cpp diff --git a/test/unit/utColladaExportLight.cpp b/test/unit/utColladaExport.cpp similarity index 78% rename from test/unit/utColladaExportLight.cpp rename to test/unit/utColladaExport.cpp index 0327b296e..efb2d7f17 100644 --- a/test/unit/utColladaExportLight.cpp +++ b/test/unit/utColladaExport.cpp @@ -49,7 +49,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_EXPORT -class ColladaExportLight : public ::testing::Test { +class utColladaExport : public ::testing::Test { public: void SetUp() override { ex = new Assimp::Exporter(); @@ -58,7 +58,9 @@ public: void TearDown() override { delete ex; + ex = nullptr; delete im; + im = nullptr; } protected: @@ -66,8 +68,53 @@ protected: Assimp::Importer *im; }; +TEST_F(utColladaExport, testExportCamera) { + const char *file = "cameraExp.dae"; + + const aiScene *pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/cameras.dae", aiProcess_ValidateDataStructure); + ASSERT_NE(nullptr, pTest); + ASSERT_TRUE(pTest->HasCameras()); + + EXPECT_EQ(AI_SUCCESS, ex->Export(pTest, "collada", file)); + const unsigned int origNumCams(pTest->mNumCameras); + std::unique_ptr origFOV(new float[origNumCams]); + std::unique_ptr orifClipPlaneNear(new float[origNumCams]); + std::unique_ptr orifClipPlaneFar(new float[origNumCams]); + std::unique_ptr names(new aiString[origNumCams]); + std::unique_ptr pos(new aiVector3D[origNumCams]); + for (size_t i = 0; i < origNumCams; i++) { + const aiCamera *orig = pTest->mCameras[i]; + ASSERT_NE(nullptr, orig); + + origFOV[i] = orig->mHorizontalFOV; + orifClipPlaneNear[i] = orig->mClipPlaneNear; + orifClipPlaneFar[i] = orig->mClipPlaneFar; + names[i] = orig->mName; + pos[i] = orig->mPosition; + } + const aiScene *imported = im->ReadFile(file, aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, imported); + + EXPECT_TRUE(imported->HasCameras()); + EXPECT_EQ(origNumCams, imported->mNumCameras); + + for (size_t i = 0; i < imported->mNumCameras; i++) { + const aiCamera *read = imported->mCameras[i]; + + EXPECT_TRUE(names[i] == read->mName); + EXPECT_NEAR(origFOV[i], read->mHorizontalFOV, 0.0001f); + EXPECT_FLOAT_EQ(orifClipPlaneNear[i], read->mClipPlaneNear); + EXPECT_FLOAT_EQ(orifClipPlaneFar[i], read->mClipPlaneFar); + + EXPECT_FLOAT_EQ(pos[i].x, read->mPosition.x); + EXPECT_FLOAT_EQ(pos[i].y, read->mPosition.y); + EXPECT_FLOAT_EQ(pos[i].z, read->mPosition.z); + } +} + // ------------------------------------------------------------------------------------------------ -TEST_F(ColladaExportLight, testExportLight) { +TEST_F(utColladaExport, testExportLight) { const char *file = "lightsExp.dae"; const aiScene *pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/lights.dae", aiProcess_ValidateDataStructure); diff --git a/test/unit/utColladaExportCamera.cpp b/test/unit/utColladaExportCamera.cpp deleted file mode 100644 index c2c704056..000000000 --- a/test/unit/utColladaExportCamera.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* ---------------------------------------------------------------------------- -Open Asset Import Library (assimp) ---------------------------------------------------------------------------- - -Copyright (c) 2006-2020, assimp team - -All rights reserved. - -Redistribution and use of this software in source and binary forms, -with or without modification, are permitted provided that the following -conditions are met: - -* Redistributions of source code must retain the above -copyright notice, this list of conditions and the -following disclaimer. - -* Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the -following disclaimer in the documentation and/or other -materials provided with the distribution. - -* Neither the name of the assimp team, nor the names of its -contributors may be used to endorse or promote products -derived from this software without specific prior -written permission of the assimp team. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---------------------------------------------------------------------------- -*/ -#include "UnitTestPCH.h" - -#include -#include -#include -#include -#include - -#ifndef ASSIMP_BUILD_NO_EXPORT - -class ColladaExportCamera : public ::testing::Test { -public: - void SetUp() override { - ex = new Assimp::Exporter(); - im = new Assimp::Importer(); - } - - void TearDown() override { - delete ex; - ex = nullptr; - delete im; - im = nullptr; - } - -protected: - Assimp::Exporter *ex; - Assimp::Importer *im; -}; - -TEST_F(ColladaExportCamera, testExportCamera) { - const char *file = "cameraExp.dae"; - - const aiScene *pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/cameras.dae", aiProcess_ValidateDataStructure); - ASSERT_NE(nullptr, pTest); - ASSERT_TRUE(pTest->HasCameras()); - - EXPECT_EQ(AI_SUCCESS, ex->Export(pTest, "collada", file)); - const unsigned int origNumCams(pTest->mNumCameras); - std::unique_ptr origFOV(new float[origNumCams]); - std::unique_ptr orifClipPlaneNear(new float[origNumCams]); - std::unique_ptr orifClipPlaneFar(new float[origNumCams]); - std::unique_ptr names(new aiString[origNumCams]); - std::unique_ptr pos(new aiVector3D[origNumCams]); - for (size_t i = 0; i < origNumCams; i++) { - const aiCamera *orig = pTest->mCameras[i]; - ASSERT_NE(nullptr, orig); - - origFOV[i] = orig->mHorizontalFOV; - orifClipPlaneNear[i] = orig->mClipPlaneNear; - orifClipPlaneFar[i] = orig->mClipPlaneFar; - names[i] = orig->mName; - pos[i] = orig->mPosition; - } - const aiScene *imported = im->ReadFile(file, aiProcess_ValidateDataStructure); - - ASSERT_NE(nullptr, imported); - - EXPECT_TRUE(imported->HasCameras()); - EXPECT_EQ(origNumCams, imported->mNumCameras); - - for (size_t i = 0; i < imported->mNumCameras; i++) { - const aiCamera *read = imported->mCameras[i]; - - EXPECT_TRUE(names[i] == read->mName); - EXPECT_NEAR(origFOV[i], read->mHorizontalFOV, 0.0001f); - EXPECT_FLOAT_EQ(orifClipPlaneNear[i], read->mClipPlaneNear); - EXPECT_FLOAT_EQ(orifClipPlaneFar[i], read->mClipPlaneFar); - - EXPECT_FLOAT_EQ(pos[i].x, read->mPosition.x); - EXPECT_FLOAT_EQ(pos[i].y, read->mPosition.y); - EXPECT_FLOAT_EQ(pos[i].z, read->mPosition.z); - } -} - -#endif // ASSIMP_BUILD_NO_EXPORT From c6f2196f60fb219c1de423c0e27e04eba05c6c90 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 16:32:25 -0400 Subject: [PATCH 10/26] vector definitions --- port/assimp_rs/src/structs/vec.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/port/assimp_rs/src/structs/vec.rs b/port/assimp_rs/src/structs/vec.rs index e69de29bb..37e1c5150 100644 --- a/port/assimp_rs/src/structs/vec.rs +++ b/port/assimp_rs/src/structs/vec.rs @@ -0,0 +1,29 @@ +struct Vector2d { + x: f32, + y: f32 +} + +struct Vector3d { + x: f32, + y: f32, + z: f32 +} + +impl Vector2d { + pub fn new(x_f32: f32, y_f32: f32) -> Vector2d { + Vector2d { + x: x_f32, + y: y_f32 + } + } +} + +impl Vector3d { + pub fn new(x_f32: f32, y_f32: f32, z_f32: f32) -> Vector3d { + Vector3d { + x: x_f32, + y: y_f32, + z: z_f32 + } + } +} From c338c5ca02e4b05d50275844f8aa89895c69a1a1 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 16:47:35 -0400 Subject: [PATCH 11/26] Populating 3d and 4d matrix struct definitions --- port/assimp_rs/src/structs/matrix.rs | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/port/assimp_rs/src/structs/matrix.rs b/port/assimp_rs/src/structs/matrix.rs index e69de29bb..4673b2d69 100644 --- a/port/assimp_rs/src/structs/matrix.rs +++ b/port/assimp_rs/src/structs/matrix.rs @@ -0,0 +1,64 @@ +#[derive(Clone, Debug, Copy)] +struct Matrix3x3 { + a1: f32, + a2: f32, + a3: f32, + b1: f32, + b2: f32, + b3: f32, + c1: f32, + c2: f32, + c3: f32 +} + +#[derive(Clone, Debug, Copy)] +struct Matrix4x4 { + a1: f32, + a2: f32, + a3: f32, + a4: f32, + b1: f32, + b2: f32, + b3: f32, + b4: f32, + c1: f32, + c2: f32, + c3: f32, + c4: f32, + d1: f32, + d2: f32, + d3: f32, + d4: f32 +} + +impl Matrix3x3 { + pub fn new( + a1_f32: f32, a2_f32: f32, a3_f32: f32, + b1_f32: f32, b2_f32: f32, b3_f32: f32, + c1_f32: f32, c2_f32: f32, c3_f32: f32 + ) -> Matrix3x3 { + Matrix3x3 { + a1: a1_f32, a2: a2_f32, a3: a3_f32, + b1: b1_f32, b2: b2_f32, b3: b3_f32, + c1: c1_f32, c2: c2_f32, c3: c3_f32 + } + } +} + +impl Matrix4x4 { + pub fn new( + a1_f32: f32, a2_f32: f32, a3_f32: f32, a4_f32: f32, + b1_f32: f32, b2_f32: f32, b3_f32: f32, b4_f32: f32, + c1_f32: f32, c2_f32: f32, c3_f32: f32, c4_f32: f32, + d1_f32: f32, d2_f32: f32, d3_f32: f32, d4_f32: f32 + ) -> Matrix4x4 { + Matrix4x4 { + a1: a1_f32, a2: a2_f32, a3: a3_f32, a4: a4_f32, + b1: b1_f32, b2: b2_f32, b3: b3_f32, b4: b4_f32, + c1: c1_f32, c2: c2_f32, c3: c3_f32, c4: c4_f32, + d1: d1_f32, d2: d2_f32, d3: d3_f32, d4: d4_f32 + } + } +} + + From 4f8eb0f79ca0c1d88fab2bd357527e1d40137ee8 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 16:50:31 -0400 Subject: [PATCH 12/26] populating Texel struct definition for textures --- port/assimp_rs/src/structs/texel.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/port/assimp_rs/src/structs/texel.rs b/port/assimp_rs/src/structs/texel.rs index e69de29bb..b2c72f30e 100644 --- a/port/assimp_rs/src/structs/texel.rs +++ b/port/assimp_rs/src/structs/texel.rs @@ -0,0 +1,19 @@ +#[derive(Clone, Debug, Copy)] +struct Texel { + b: u32, + g: u32, + r: u32, + a: u32 +} + +impl Texel { + pub fn new(b_u32: u32, g_u32: u32, + r_u32: u32, a_u32: u32) -> Texel { + Texel { + b: b_u32, + g: g_u32, + r: r_u32, + a: a_u32 + } + } +} From ba633f95bb1af4bbca82738a95bf569cef035a35 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 16:54:56 -0400 Subject: [PATCH 13/26] populating colors --- port/assimp_rs/src/structs/color.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/port/assimp_rs/src/structs/color.rs b/port/assimp_rs/src/structs/color.rs index e69de29bb..0b5fc6413 100644 --- a/port/assimp_rs/src/structs/color.rs +++ b/port/assimp_rs/src/structs/color.rs @@ -0,0 +1,27 @@ +#[derive(Clone, Debug, Copy)] +struct Color3D { + r: f32, + g: f32, + b: f32 +} + +impl Color3D { + pub fn new(r_f32: f32, g_f32: f32, b_f32: f32) -> Color3D { + Color3D {r: r_f32, g: g_f32, b: b_f32 } + } +} + +#[derive(Clone, Debug, Copy)] +struct Color4D { + r: f32, + g: f32, + b: f32, + a: f32 +} + +impl Color4D { + pub fn new(r_f32: f32, g_f32: f32, b_f32: f32, a_f32: f32) -> Color4D { + Color4D {r: r_f32, g: g_f32, b: b_f32, a: a_f32 } + } +} + From 38b80f6c6b7dd60b0366af8eaaeca9a179128f33 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 16:58:32 -0400 Subject: [PATCH 14/26] populating plane struct --- port/assimp_rs/src/structs/plane.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/port/assimp_rs/src/structs/plane.rs b/port/assimp_rs/src/structs/plane.rs index e69de29bb..2b0b74499 100644 --- a/port/assimp_rs/src/structs/plane.rs +++ b/port/assimp_rs/src/structs/plane.rs @@ -0,0 +1,23 @@ +#[derive(Clone, Debug, Copy)] +struct Plane { + a: f32, + b: f32, + c: f32, + d: f32 +} + +impl Plane { + pub fn new( + a_f32: f32, + b_f32: f32, + c_f32: f32, + d_f32: f32 + ) -> Plane { + Plane { + a: a_f32, + b: b_f32, + c: b_f32, + d: d_f32 + } + } +} From e6837f73949d1d797f71531d0d6ba08dfee6a5fb Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 17:25:02 -0400 Subject: [PATCH 15/26] Need to consider different implementations of String kinds in Rust, and additionally how we may want to `impl Copy for Str`, i.e. `std::mem::swap` with placeholders to keep performance up. --- port/assimp_rs/src/structs/string.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/port/assimp_rs/src/structs/string.rs b/port/assimp_rs/src/structs/string.rs index e69de29bb..c99fabffb 100644 --- a/port/assimp_rs/src/structs/string.rs +++ b/port/assimp_rs/src/structs/string.rs @@ -0,0 +1,17 @@ +pub const MAXLEN: u32 = 1024; + +#[derive(Clone, Debug)] +struct Str { + length: u32, + data: Vec +} + +impl Str { + pub fn new(len_u32: u32, data_string: String) -> Str { + Str { + length: len_u32, + data: data_string.chars().collect() + } + } +} + From a286506c234068bbab212eb7de4c8ea5e853a934 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 17:32:55 -0400 Subject: [PATCH 16/26] fixed a couple of things. Adding MaterialPropertyString --- port/assimp_rs/src/structs/string.rs | 30 +++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/port/assimp_rs/src/structs/string.rs b/port/assimp_rs/src/structs/string.rs index c99fabffb..b88457df4 100644 --- a/port/assimp_rs/src/structs/string.rs +++ b/port/assimp_rs/src/structs/string.rs @@ -1,13 +1,16 @@ -pub const MAXLEN: u32 = 1024; +pub const MAXLEN: usize = 1024; +/// Want to consider replacing `Vec` +/// with a comparable definition at +/// https://doc.rust-lang.org/src/alloc/string.rs.html#415-417 #[derive(Clone, Debug)] struct Str { - length: u32, + length: usize, data: Vec } impl Str { - pub fn new(len_u32: u32, data_string: String) -> Str { + pub fn new(len_u32: usize, data_string: String) -> Str { Str { length: len_u32, data: data_string.chars().collect() @@ -15,3 +18,24 @@ impl Str { } } +/// MaterialPropertyStr +/// The size of length is truncated to 4 bytes on a 64-bit platform when used as a +/// material property (see MaterialSystem.cpp, as aiMaterial::AddProperty() ). +#[derive(Clone, Debug)] +struct MaterialPropertyStr { + length: usize, + data: Vec +} + + +impl MaterialPropertyStr { + pub fn new(len_u32: usize, data_string: String) -> MaterialPropertyStr { + MaterialPropertyStr { + length: len_u32, + data: data_string.chars().collect() + } + } +} + + + From 2d43a2447530fe2abe30f9aaeae558212734c231 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 17:41:16 -0400 Subject: [PATCH 17/26] memory info struct --- port/assimp_rs/src/structs/mem.rs | 0 port/assimp_rs/src/structs/memory.rs | 35 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) delete mode 100644 port/assimp_rs/src/structs/mem.rs create mode 100644 port/assimp_rs/src/structs/memory.rs diff --git a/port/assimp_rs/src/structs/mem.rs b/port/assimp_rs/src/structs/mem.rs deleted file mode 100644 index e69de29bb..000000000 diff --git a/port/assimp_rs/src/structs/memory.rs b/port/assimp_rs/src/structs/memory.rs new file mode 100644 index 000000000..c076f172a --- /dev/null +++ b/port/assimp_rs/src/structs/memory.rs @@ -0,0 +1,35 @@ +#[derive(Clone, Debug, Copy)] +struct MemoryInfo { + textures: u32, + materials: u32, + meshes: u32, + nodes: u32, + animations: u32, + cameras: u32, + lights: u32, + total: u32 +} + +impl MemoryInfo { + pub fn new( + textures_uint: u32, + materials_uint: u32, + meshes_uint: u32, + nodes_uint: u32, + animations_uint: u32, + cameras_uint: u32, + lights_uint: u32, + total_uint: u32) -> MemoryInfo { + + MemoryInfo { + textures: textures_uint, + materials: materials_uint, + meshes: meshes_uint, + nodes: nodes_uint, + animations: animations_uint, + cameras: cameras_uint, + lights: lights_uint, + total: total_uint + } + } +} From 778c3afbbb052bea25d6eaaccba1d663432b0b27 Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 18:11:44 -0400 Subject: [PATCH 18/26] Rust's import system dictates that we must make directories rather than use individual files to provide a clean public interface --- port/PyAssimp/pyassimp/.structs.py.swp | Bin 0 -> 16384 bytes port/assimp_rs/src/camera/mod.rs | 1 + port/assimp_rs/src/structs/.mod.rs.swp | Bin 0 -> 12288 bytes port/assimp_rs/src/structs/{ => anim}/anim.rs | 0 port/assimp_rs/src/structs/anim/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => blob}/blob.rs | 0 port/assimp_rs/src/structs/blob/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => bone}/bone.rs | 0 port/assimp_rs/src/structs/bone/mod.rs | 2 ++ .../src/structs/{ => camera}/camera.rs | 0 port/assimp_rs/src/structs/camera/mod.rs | 2 ++ .../src/structs/{ => color}/color.rs | 0 port/assimp_rs/src/structs/color/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => face}/face.rs | 0 port/assimp_rs/src/structs/face/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => key}/key.rs | 0 port/assimp_rs/src/structs/key/mod.rs | 2 ++ .../src/structs/{ => light}/light.rs | 0 port/assimp_rs/src/structs/light/mod.rs | 2 ++ .../src/structs/{ => material}/material.rs | 0 port/assimp_rs/src/structs/material/mod.rs | 2 ++ .../src/structs/{ => matrix}/matrix.rs | 0 port/assimp_rs/src/structs/matrix/mod.rs | 2 ++ .../src/structs/{ => memory}/memory.rs | 0 port/assimp_rs/src/structs/memory/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => mesh}/mesh.rs | 0 port/assimp_rs/src/structs/mesh/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => meta}/meta.rs | 0 port/assimp_rs/src/structs/meta/mod.rs | 2 ++ port/assimp_rs/src/structs/node/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => node}/node.rs | 0 port/assimp_rs/src/structs/plane/mod.rs | 2 ++ .../src/structs/{ => plane}/plane.rs | 0 port/assimp_rs/src/structs/quaternion/mod.rs | 2 ++ .../src/structs/quaternion/quaternion.rs | 7 +++++++ port/assimp_rs/src/structs/ray/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => ray}/ray.rs | 0 port/assimp_rs/src/structs/scene/mod.rs | 2 ++ .../src/structs/{ => scene}/scene.rs | 0 port/assimp_rs/src/structs/string/mod.rs | 2 ++ .../src/structs/{ => string}/string.rs | 0 port/assimp_rs/src/structs/texel/mod.rs | 2 ++ .../src/structs/{ => texel}/texel.rs | 0 port/assimp_rs/src/structs/texture/mod.rs | 2 ++ .../src/structs/{ => texture}/texture.rs | 0 port/assimp_rs/src/structs/transform/mod.rs | 2 ++ .../src/structs/{ => transform}/transform.rs | 0 port/assimp_rs/src/structs/vec/mod.rs | 2 ++ port/assimp_rs/src/structs/{ => vec}/vec.rs | 19 ++++++++++++++++++ port/assimp_rs/src/structs/vertex/mod.rs | 2 ++ .../{quaternion.rs => vertex/vertex.rs} | 0 port/assimp_rs/src/structs/vertex_weight.rs | 0 52 files changed, 75 insertions(+) create mode 100644 port/PyAssimp/pyassimp/.structs.py.swp create mode 100644 port/assimp_rs/src/structs/.mod.rs.swp rename port/assimp_rs/src/structs/{ => anim}/anim.rs (100%) create mode 100644 port/assimp_rs/src/structs/anim/mod.rs rename port/assimp_rs/src/structs/{ => blob}/blob.rs (100%) create mode 100644 port/assimp_rs/src/structs/blob/mod.rs rename port/assimp_rs/src/structs/{ => bone}/bone.rs (100%) create mode 100644 port/assimp_rs/src/structs/bone/mod.rs rename port/assimp_rs/src/structs/{ => camera}/camera.rs (100%) create mode 100644 port/assimp_rs/src/structs/camera/mod.rs rename port/assimp_rs/src/structs/{ => color}/color.rs (100%) create mode 100644 port/assimp_rs/src/structs/color/mod.rs rename port/assimp_rs/src/structs/{ => face}/face.rs (100%) create mode 100644 port/assimp_rs/src/structs/face/mod.rs rename port/assimp_rs/src/structs/{ => key}/key.rs (100%) create mode 100644 port/assimp_rs/src/structs/key/mod.rs rename port/assimp_rs/src/structs/{ => light}/light.rs (100%) create mode 100644 port/assimp_rs/src/structs/light/mod.rs rename port/assimp_rs/src/structs/{ => material}/material.rs (100%) create mode 100644 port/assimp_rs/src/structs/material/mod.rs rename port/assimp_rs/src/structs/{ => matrix}/matrix.rs (100%) create mode 100644 port/assimp_rs/src/structs/matrix/mod.rs rename port/assimp_rs/src/structs/{ => memory}/memory.rs (100%) create mode 100644 port/assimp_rs/src/structs/memory/mod.rs rename port/assimp_rs/src/structs/{ => mesh}/mesh.rs (100%) create mode 100644 port/assimp_rs/src/structs/mesh/mod.rs rename port/assimp_rs/src/structs/{ => meta}/meta.rs (100%) create mode 100644 port/assimp_rs/src/structs/meta/mod.rs create mode 100644 port/assimp_rs/src/structs/node/mod.rs rename port/assimp_rs/src/structs/{ => node}/node.rs (100%) create mode 100644 port/assimp_rs/src/structs/plane/mod.rs rename port/assimp_rs/src/structs/{ => plane}/plane.rs (100%) create mode 100644 port/assimp_rs/src/structs/quaternion/mod.rs create mode 100644 port/assimp_rs/src/structs/quaternion/quaternion.rs create mode 100644 port/assimp_rs/src/structs/ray/mod.rs rename port/assimp_rs/src/structs/{ => ray}/ray.rs (100%) create mode 100644 port/assimp_rs/src/structs/scene/mod.rs rename port/assimp_rs/src/structs/{ => scene}/scene.rs (100%) create mode 100644 port/assimp_rs/src/structs/string/mod.rs rename port/assimp_rs/src/structs/{ => string}/string.rs (100%) create mode 100644 port/assimp_rs/src/structs/texel/mod.rs rename port/assimp_rs/src/structs/{ => texel}/texel.rs (100%) create mode 100644 port/assimp_rs/src/structs/texture/mod.rs rename port/assimp_rs/src/structs/{ => texture}/texture.rs (100%) create mode 100644 port/assimp_rs/src/structs/transform/mod.rs rename port/assimp_rs/src/structs/{ => transform}/transform.rs (100%) create mode 100644 port/assimp_rs/src/structs/vec/mod.rs rename port/assimp_rs/src/structs/{ => vec}/vec.rs (60%) create mode 100644 port/assimp_rs/src/structs/vertex/mod.rs rename port/assimp_rs/src/structs/{quaternion.rs => vertex/vertex.rs} (100%) delete mode 100644 port/assimp_rs/src/structs/vertex_weight.rs diff --git a/port/PyAssimp/pyassimp/.structs.py.swp b/port/PyAssimp/pyassimp/.structs.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..1de72f0f8f12a4e35de38089723ca2b124ce4459 GIT binary patch literal 16384 zcmeI3%a0sK9mgB6iHYMl1TIK{RK^0&Mzga|k;Me0C3d7GyX&=g6Cwzi)O6R(R9xLX z>8_rgK@kuRJYvMdjs(Kt0$BV3Mu?Xp3oPIO7X$(h9EcRK5lARPfjkI&tGap~J>#7j zBo3fz`Qx7MU)8UxzV(={U(HtMA6VNUE9C_T$1RStx&HNsfAQV}PW4{L@o0;C>i(ER z(54KVV-msqQSETf4Lvs3VnHjOqjAjr=3Fz3;2<0Si4ogDqt0`3RnfK0#*U5fK|XM@PDL$Y~JL24E1@f zsnh4o`8B!ozs&Ktx&Qf`{Z(Us$lO0@9Atj}Y3wJBy`HnbV(i@5zn!zcZ0wI3`|YN{ zng5rJ{kXAzCTD-q*td=S=Q;a7jQxzUlh>smGXH-!_PVj3&Dmct_J@uA`JCNcI>gww z_N5;(|K_$mSp}>DRspMkRlq7>6|f3e1*`&A0jq#j;J=~(#RmT@JU^kqfUkisgD-&q)WF@~-Qd~{s53YVo&;^M3u@q2@XYIx2dsnpz+1rI_Cp774g3sT z0T;nn!PDR@_#jvTcY*!jS;QHB4=#c8;2iM432+>|5&Q+gi9drMfD7O&;0(AAydN9} ze?|ZJ19%Sn6kG;RgQviGa1N+G^l>oNL2y)RoCz$u|E8BZB)}5+0K@Prkzn7Sv^zIheYVA>lG6Eb!9NuS8PE5kf>* z=PpKU`e>Ce%@Y$h3@~A6Z};!qJG(;sL`bflNMiO_!UC7YcaSxCG<`pTkX?>V`>gVSaHrl`m`UZf|Qw zVUtC&Ly9qG!VS|2w>z<9e%Wm{3FX<%W5-rKZ_A`F&h*cdGpSTNN=4OlP{wG4LSmu} z(s>QiE}Lcu1M<%0*(w^iDX7Gh>&Ilb!2*)Rm;h-^%mk(9=d1+1V(mFgXUVg&rk%_7 z*8kbwsyo3XbJH{}9qFl~CPIoY=3=2fcvSaiq$wEUlf^XE za(lVdi}L38Qv9umw-BGyD=M{csWgWozH5Qn$3cu#1)WR83rP@4M069k(Q~Y%Ef)L@ zZ1I@bv{@q+vs*Jmj$Im%DocZth+?WO8*I-YYDwj6++;4VahLeUqY7W{G9mKu<0Rm6 z7Lno>i(<7cQX>7I0xyhWf*4YWh;BrDY*>h%Z&lJX?(6h-4eTMQP_VLQG3c1oMOcLf z-Qw&vxZ6PSMHti(jt$djx62UZ5&R4rQs$oSR!}BPc1|rb!}{o`wepy+GmRpO;4-ff z*5TpH{u2p)E)hMFm#B3q8INK#yOol@h#MYShf_(mF;+x_jtqwLTRnQhZio330 z!2@!BR%p(!wdQ&MbiqD6=pQVP>s~n(()k6Z5)<|H0+gA z_t%lzf9gSMi?2h%rrIZ?qNFP2hq@*)HY=oRTq+TPs3zD-*yX4Ly5W4TYN|-ReU5G= nwF)HG%|eW7Lj_&W_7Sr-&d%B}qN)3((b5kzPU^1PHqO5R$L{t! literal 0 HcmV?d00001 diff --git a/port/assimp_rs/src/camera/mod.rs b/port/assimp_rs/src/camera/mod.rs index e69de29bb..26ca1185b 100644 --- a/port/assimp_rs/src/camera/mod.rs +++ b/port/assimp_rs/src/camera/mod.rs @@ -0,0 +1 @@ +pub use self::structs::{Camera}; diff --git a/port/assimp_rs/src/structs/.mod.rs.swp b/port/assimp_rs/src/structs/.mod.rs.swp new file mode 100644 index 0000000000000000000000000000000000000000..a6b06ed631bd7b51b0450777a8e7c266e3c9b7eb GIT binary patch literal 12288 zcmeI2J!lj`6vrnP+L&mxwOBtO5HOqMt_U0iV-iKei7{SEh|Ig3(heX@lGo;^SfLz&vlmXl7!`TThI@)NcbI*c9hSRY9+a!XHvU( zMJiv(&{tZvL#_NIi^indy*6c#0Wz?Ifwo>fJvG>dqiZe1P4;q4v3hO}qQRUw1d88yO%2WPl8i0Wv@a$N(8217v^< zkO4BV2Muuiz&~@4vBn@akKg~x|Np-oV(c^c2;PC$;3aql9)k^VAKV4&K!O-t1DC-Z zI0LF+1RMjyU_aOgz7H|>1#E-&U<)qicSu_%17v^&eA{E}K&+q}Wr_7*c!yq#e5*o`_Bu~|9CX+HvmlH**%$qO04|6^L7FO zbjxF2s>BvW+;6=sLY>J4(KFo^u}2ryg=*F_nK#YY9oK}W@O1&h&e&`gXR;cZ6dP6| zn-ZF7`@&{{f$b)%LKXO3(*H*$SciunYOxj9J6Eji9=Fh{%sA%q7 Vector2d { Vector2d { @@ -27,3 +34,15 @@ impl Vector3d { } } } + +impl Vector4d { + pub fn new(x_f32: f32, y_f32: f32, z_f32: f32, w_f32: f32) -> Vector4d { + Vector4d { + x: x_f32, + y: y_f32, + z: z_f32, + w: w_f32 + } + } +} + diff --git a/port/assimp_rs/src/structs/vertex/mod.rs b/port/assimp_rs/src/structs/vertex/mod.rs new file mode 100644 index 000000000..d169246ce --- /dev/null +++ b/port/assimp_rs/src/structs/vertex/mod.rs @@ -0,0 +1,2 @@ +mod vertex; + diff --git a/port/assimp_rs/src/structs/quaternion.rs b/port/assimp_rs/src/structs/vertex/vertex.rs similarity index 100% rename from port/assimp_rs/src/structs/quaternion.rs rename to port/assimp_rs/src/structs/vertex/vertex.rs diff --git a/port/assimp_rs/src/structs/vertex_weight.rs b/port/assimp_rs/src/structs/vertex_weight.rs deleted file mode 100644 index e69de29bb..000000000 From 57e837092e6aaedf69912729b45568af30a20ffc Mon Sep 17 00:00:00 2001 From: David Golembiowski Date: Fri, 1 May 2020 18:23:14 -0400 Subject: [PATCH 19/26] populated module level files --- port/PyAssimp/pyassimp/.structs.py.swp | Bin 16384 -> 0 bytes port/assimp_rs/src/structs/.mod.rs.swp | Bin 12288 -> 0 bytes port/assimp_rs/src/structs/anim/mod.rs | 6 +++++- port/assimp_rs/src/structs/color/mod.rs | 5 ++++- port/assimp_rs/src/structs/matrix/mod.rs | 4 +++- port/assimp_rs/src/structs/memory/mod.rs | 2 +- port/assimp_rs/src/structs/mesh/mod.rs | 1 + port/assimp_rs/src/structs/quaternion/mod.rs | 1 + port/assimp_rs/src/structs/string/mod.rs | 3 ++- port/assimp_rs/src/structs/texel/mod.rs | 2 -- port/assimp_rs/src/structs/texel/texel.rs | 19 ------------------ port/assimp_rs/src/structs/texture/mod.rs | 1 + port/assimp_rs/src/structs/texture/texture.rs | 19 ++++++++++++++++++ port/assimp_rs/src/structs/vertex/mod.rs | 2 +- 14 files changed, 38 insertions(+), 27 deletions(-) delete mode 100644 port/PyAssimp/pyassimp/.structs.py.swp delete mode 100644 port/assimp_rs/src/structs/.mod.rs.swp delete mode 100644 port/assimp_rs/src/structs/texel/mod.rs delete mode 100644 port/assimp_rs/src/structs/texel/texel.rs diff --git a/port/PyAssimp/pyassimp/.structs.py.swp b/port/PyAssimp/pyassimp/.structs.py.swp deleted file mode 100644 index 1de72f0f8f12a4e35de38089723ca2b124ce4459..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3%a0sK9mgB6iHYMl1TIK{RK^0&Mzga|k;Me0C3d7GyX&=g6Cwzi)O6R(R9xLX z>8_rgK@kuRJYvMdjs(Kt0$BV3Mu?Xp3oPIO7X$(h9EcRK5lARPfjkI&tGap~J>#7j zBo3fz`Qx7MU)8UxzV(={U(HtMA6VNUE9C_T$1RStx&HNsfAQV}PW4{L@o0;C>i(ER z(54KVV-msqQSETf4Lvs3VnHjOqjAjr=3Fz3;2<0Si4ogDqt0`3RnfK0#*U5fK|XM@PDL$Y~JL24E1@f zsnh4o`8B!ozs&Ktx&Qf`{Z(Us$lO0@9Atj}Y3wJBy`HnbV(i@5zn!zcZ0wI3`|YN{ zng5rJ{kXAzCTD-q*td=S=Q;a7jQxzUlh>smGXH-!_PVj3&Dmct_J@uA`JCNcI>gww z_N5;(|K_$mSp}>DRspMkRlq7>6|f3e1*`&A0jq#j;J=~(#RmT@JU^kqfUkisgD-&q)WF@~-Qd~{s53YVo&;^M3u@q2@XYIx2dsnpz+1rI_Cp774g3sT z0T;nn!PDR@_#jvTcY*!jS;QHB4=#c8;2iM432+>|5&Q+gi9drMfD7O&;0(AAydN9} ze?|ZJ19%Sn6kG;RgQviGa1N+G^l>oNL2y)RoCz$u|E8BZB)}5+0K@Prkzn7Sv^zIheYVA>lG6Eb!9NuS8PE5kf>* z=PpKU`e>Ce%@Y$h3@~A6Z};!qJG(;sL`bflNMiO_!UC7YcaSxCG<`pTkX?>V`>gVSaHrl`m`UZf|Qw zVUtC&Ly9qG!VS|2w>z<9e%Wm{3FX<%W5-rKZ_A`F&h*cdGpSTNN=4OlP{wG4LSmu} z(s>QiE}Lcu1M<%0*(w^iDX7Gh>&Ilb!2*)Rm;h-^%mk(9=d1+1V(mFgXUVg&rk%_7 z*8kbwsyo3XbJH{}9qFl~CPIoY=3=2fcvSaiq$wEUlf^XE za(lVdi}L38Qv9umw-BGyD=M{csWgWozH5Qn$3cu#1)WR83rP@4M069k(Q~Y%Ef)L@ zZ1I@bv{@q+vs*Jmj$Im%DocZth+?WO8*I-YYDwj6++;4VahLeUqY7W{G9mKu<0Rm6 z7Lno>i(<7cQX>7I0xyhWf*4YWh;BrDY*>h%Z&lJX?(6h-4eTMQP_VLQG3c1oMOcLf z-Qw&vxZ6PSMHti(jt$djx62UZ5&R4rQs$oSR!}BPc1|rb!}{o`wepy+GmRpO;4-ff z*5TpH{u2p)E)hMFm#B3q8INK#yOol@h#MYShf_(mF;+x_jtqwLTRnQhZio330 z!2@!BR%p(!wdQ&MbiqD6=pQVP>s~n(()k6Z5)<|H0+gA z_t%lzf9gSMi?2h%rrIZ?qNFP2hq@*)HY=oRTq+TPs3zD-*yX4Ly5W4TYN|-ReU5G= nwF)HG%|eW7Lj_&W_7Sr-&d%B}qN)3((b5kzPU^1PHqO5R$L{t! diff --git a/port/assimp_rs/src/structs/.mod.rs.swp b/port/assimp_rs/src/structs/.mod.rs.swp deleted file mode 100644 index a6b06ed631bd7b51b0450777a8e7c266e3c9b7eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2J!lj`6vrnP+L&mxwOBtO5HOqMt_U0iV-iKei7{SEh|Ig3(heX@lGo;^SfLz&vlmXl7!`TThI@)NcbI*c9hSRY9+a!XHvU( zMJiv(&{tZvL#_NIi^indy*6c#0Wz?Ifwo>fJvG>dqiZe1P4;q4v3hO}qQRUw1d88yO%2WPl8i0Wv@a$N(8217v^< zkO4BV2Muuiz&~@4vBn@akKg~x|Np-oV(c^c2;PC$;3aql9)k^VAKV4&K!O-t1DC-Z zI0LF+1RMjyU_aOgz7H|>1#E-&U<)qicSu_%17v^&eA{E}K&+q}Wr_7*c!yq#e5*o`_Bu~|9CX+HvmlH**%$qO04|6^L7FO zbjxF2s>BvW+;6=sLY>J4(KFo^u}2ryg=*F_nK#YY9oK}W@O1&h&e&`gXR;cZ6dP6| zn-ZF7`@&{{f$b)%LKXO3(*H*$SciunYOxj9J6Eji9=Fh{%sA%q7 Texel { - Texel { - b: b_u32, - g: g_u32, - r: r_u32, - a: a_u32 - } - } -} diff --git a/port/assimp_rs/src/structs/texture/mod.rs b/port/assimp_rs/src/structs/texture/mod.rs index a9d56e75b..1b5c9308d 100644 --- a/port/assimp_rs/src/structs/texture/mod.rs +++ b/port/assimp_rs/src/structs/texture/mod.rs @@ -1,2 +1,3 @@ mod texture; +pub use self::texture::Texel; diff --git a/port/assimp_rs/src/structs/texture/texture.rs b/port/assimp_rs/src/structs/texture/texture.rs index e69de29bb..b2c72f30e 100644 --- a/port/assimp_rs/src/structs/texture/texture.rs +++ b/port/assimp_rs/src/structs/texture/texture.rs @@ -0,0 +1,19 @@ +#[derive(Clone, Debug, Copy)] +struct Texel { + b: u32, + g: u32, + r: u32, + a: u32 +} + +impl Texel { + pub fn new(b_u32: u32, g_u32: u32, + r_u32: u32, a_u32: u32) -> Texel { + Texel { + b: b_u32, + g: g_u32, + r: r_u32, + a: a_u32 + } + } +} diff --git a/port/assimp_rs/src/structs/vertex/mod.rs b/port/assimp_rs/src/structs/vertex/mod.rs index d169246ce..97ae3eced 100644 --- a/port/assimp_rs/src/structs/vertex/mod.rs +++ b/port/assimp_rs/src/structs/vertex/mod.rs @@ -1,2 +1,2 @@ mod vertex; - +// pub use self::vertex:: From 8e73984a1105f6b713942fd8125e5bf9cd3e2f6e Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Mon, 4 May 2020 17:47:09 +0100 Subject: [PATCH 20/26] Collada Root Nodes aren't allowed to have meshes Create a null parent node instead --- code/AssetLib/Collada/ColladaExporter.cpp | 12 +++-- code/AssetLib/Collada/ColladaParser.cpp | 2 +- test/unit/utColladaImportExport.cpp | 55 +++++++++++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/code/AssetLib/Collada/ColladaExporter.cpp b/code/AssetLib/Collada/ColladaExporter.cpp index 5e4cdda2d..e15e81985 100644 --- a/code/AssetLib/Collada/ColladaExporter.cpp +++ b/code/AssetLib/Collada/ColladaExporter.cpp @@ -233,12 +233,13 @@ void ColladaExporter::WriteHeader() { add_root_node = true; } - if (mScene->mRootNode->mNumChildren == 0) { + // Assimp root nodes can have meshes, Collada Scenes cannot + if (mScene->mRootNode->mNumChildren == 0 || mScene->mRootNode->mMeshes != 0) { add_root_node = true; } if (add_root_node) { - aiScene *scene; + aiScene *scene = nullptr; SceneCombiner::CopyScene(&scene, mScene); aiNode *root = new aiNode("Scene"); @@ -1493,12 +1494,9 @@ void ColladaExporter::WriteNode(const aiNode *pNode) { const std::string node_name = GetNodeName(pNode); mOutput << startstr << "" << endstr; diff --git a/code/AssetLib/Collada/ColladaParser.cpp b/code/AssetLib/Collada/ColladaParser.cpp index d83980929..04e6eb7d4 100644 --- a/code/AssetLib/Collada/ColladaParser.cpp +++ b/code/AssetLib/Collada/ColladaParser.cpp @@ -2479,7 +2479,7 @@ void ColladaParser::ReadSceneLibrary() { // read name if given. int indexName = TestAttribute("name"); - const char *attrName = "unnamed"; + const char *attrName = "Scene"; if (indexName > -1) attrName = mReader->getAttributeValue(indexName); diff --git a/test/unit/utColladaImportExport.cpp b/test/unit/utColladaImportExport.cpp index 876f60c54..3d6e0db23 100644 --- a/test/unit/utColladaImportExport.cpp +++ b/test/unit/utColladaImportExport.cpp @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "UnitTestPCH.h" #include +#include #include #include #include @@ -211,6 +212,60 @@ TEST_F(utColladaImportExport, importDaeFromFileTest) { EXPECT_TRUE(importerTest()); } +unsigned int GetMeshUseCount(const aiNode *rootNode) { + unsigned int result = rootNode->mNumMeshes; + for (unsigned int i = 0; i < rootNode->mNumChildren; ++i) { + result += GetMeshUseCount(rootNode->mChildren[i]); + } + return result; +} + +TEST_F(utColladaImportExport, exportRootNodeMeshTest) { + Assimp::Importer importer; + Assimp::Exporter exporter; + const char *outFile = "exportRootNodeMeshTest_out.dae"; + + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/duck.dae", aiProcess_ValidateDataStructure); + ASSERT_TRUE(scene != nullptr) << "Fatal: could not import duck.dae!"; + + ASSERT_EQ(0u, scene->mRootNode->mNumMeshes) << "Collada import should not give the root node a mesh"; + + { + // Clone the scene and give the root node a mesh and a transform + aiScene *rootMeshScene = nullptr; + SceneCombiner::CopyScene(&rootMeshScene, scene); + ASSERT_TRUE(rootMeshScene != nullptr) << "Fatal: could not copy scene!"; + // Do this by moving the meshes from the first child that has some + aiNode *rootNode = rootMeshScene->mRootNode; + ASSERT_TRUE(rootNode->mNumChildren > 0) << "Fatal: root has no children"; + aiNode *meshNode = rootNode->mChildren[0]; + ASSERT_EQ(1u, meshNode->mNumMeshes) << "Fatal: First child node has no duck mesh"; + + // Move the meshes to the parent + rootNode->mNumMeshes = meshNode->mNumMeshes; + rootNode->mMeshes = new unsigned int[rootNode->mNumMeshes]; + for (unsigned int i = 0; i < rootNode->mNumMeshes; ++i) { + rootNode->mMeshes[i] = meshNode->mMeshes[i]; + } + + meshNode->mNumMeshes = 0; + delete[] meshNode->mMeshes; + + ASSERT_EQ(AI_SUCCESS, exporter.Export(rootMeshScene, "collada", outFile)) << "Fatal: Could not export file"; + } + + // Reimport and look for meshes + scene = importer.ReadFile(outFile, aiProcess_ValidateDataStructure); + ASSERT_TRUE(scene != nullptr) << "Fatal: could not reimport!"; + + // A Collada root node is not allowed to have a mesh + ASSERT_EQ(0u, scene->mRootNode->mNumMeshes) << "Collada reimport should not give the root node a mesh"; + + // Walk nodes and counts used meshes + // Should be exactly one + EXPECT_EQ(1u, GetMeshUseCount(scene->mRootNode)) << "Nodes had unexpected number of meshes in use"; +} + TEST_F(utColladaImportExport, exporterUniqueIdsTest) { Assimp::Importer importer; Assimp::Exporter exporter; From 56a4e615336ea7410b25fe612b216340217adc0f Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Tue, 5 May 2020 10:16:13 +0100 Subject: [PATCH 21/26] Collada: Don't copy the scene when exporting This was purely to add a virtual top-level node Use a flag instead. Also add more const --- code/AssetLib/Collada/ColladaExporter.cpp | 105 ++++++++++------------ code/AssetLib/Collada/ColladaExporter.h | 7 +- 2 files changed, 53 insertions(+), 59 deletions(-) diff --git a/code/AssetLib/Collada/ColladaExporter.cpp b/code/AssetLib/Collada/ColladaExporter.cpp index 480d6790b..567f7c8e7 100644 --- a/code/AssetLib/Collada/ColladaExporter.cpp +++ b/code/AssetLib/Collada/ColladaExporter.cpp @@ -117,22 +117,37 @@ static const std::string XMLIDEncode(const std::string &name) { return idEncoded.str(); } +// ------------------------------------------------------------------------------------------------ +// Helper functions to create unique ids +inline bool IsUniqueId(const std::unordered_set &idSet, const std::string &idStr) { + return (idSet.find(idStr) == idSet.end()); +} + +inline std::string MakeUniqueId(const std::unordered_set &idSet, const std::string &idPrefix, const std::string &postfix) { + std::string result(idPrefix + postfix); + if (!IsUniqueId(idSet, result)) { + // Select a number to append + size_t idnum = 1; + do { + result = idPrefix + '_' + to_string(idnum) + postfix; + ++idnum; + } while (!IsUniqueId(idSet, result)); + } + return result; +} + // ------------------------------------------------------------------------------------------------ // Constructor for a specific scene to export ColladaExporter::ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file) : mIOSystem(pIOSystem), mPath(path), - mFile(file) { + mFile(file), + mScene(pScene), + endstr("\n") { // make sure that all formatting happens using the standard, C locale and not the user's current locale mOutput.imbue(std::locale("C")); mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION); - mScene = pScene; - mSceneOwned = false; - - // set up strings - endstr = "\n"; - // start writing the file WriteFile(); } @@ -140,9 +155,6 @@ ColladaExporter::ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, con // ------------------------------------------------------------------------------------------------ // Destructor ColladaExporter::~ColladaExporter() { - if (mSceneOwned) { - delete mScene; - } } // ------------------------------------------------------------------------------------------------ @@ -171,10 +183,11 @@ void ColladaExporter::WriteFile() { // customized, Writes the animation library WriteAnimationsLibrary(); - // useless Collada fu at the end, just in case we haven't had enough indirections, yet. + // instantiate the scene(s) + // For Assimp there will only ever be one mOutput << startstr << "" << endstr; PushTag(); - mOutput << startstr << "mRootNode) + "\" />" << endstr; + mOutput << startstr << "" << endstr; PopTag(); mOutput << startstr << "" << endstr; PopTag(); @@ -209,13 +222,13 @@ void ColladaExporter::WriteHeader() { mScene->mRootNode->mTransformation.Decompose(scaling, rotation, position); rotation.Normalize(); - bool add_root_node = false; + mAdd_root_node = false; ai_real scale = 1.0; if (std::abs(scaling.x - scaling.y) <= epsilon && std::abs(scaling.x - scaling.z) <= epsilon && std::abs(scaling.y - scaling.z) <= epsilon) { scale = (ai_real)((((double)scaling.x) + ((double)scaling.y) + ((double)scaling.z)) / 3.0); } else { - add_root_node = true; + mAdd_root_node = true; } std::string up_axis = "Y_UP"; @@ -226,34 +239,19 @@ void ColladaExporter::WriteHeader() { } else if (rotation.Equal(z_rot, epsilon)) { up_axis = "Z_UP"; } else { - add_root_node = true; + mAdd_root_node = true; } if (!position.Equal(aiVector3D(0, 0, 0))) { - add_root_node = true; + mAdd_root_node = true; } // Assimp root nodes can have meshes, Collada Scenes cannot if (mScene->mRootNode->mNumChildren == 0 || mScene->mRootNode->mMeshes != 0) { - add_root_node = true; + mAdd_root_node = true; } - if (add_root_node) { - aiScene *scene = nullptr; - SceneCombiner::CopyScene(&scene, mScene); - - aiNode *root = new aiNode("Scene"); - - root->mNumChildren = 1; - root->mChildren = new aiNode *[root->mNumChildren]; - - root->mChildren[0] = scene->mRootNode; - scene->mRootNode->mParent = root; - scene->mRootNode = root; - - mScene = scene; - mSceneOwned = true; - + if (mAdd_root_node) { up_axis = "Y_UP"; scale = 1.0; } @@ -1227,17 +1225,29 @@ void ColladaExporter::WriteFloatArray(const std::string &pIdString, FloatDataTyp // ------------------------------------------------------------------------------------------------ // Writes the scene library void ColladaExporter::WriteSceneLibrary() { - const std::string sceneId = GetNodeUniqueId(mScene->mRootNode); - const std::string sceneName = GetNodeName(mScene->mRootNode); + // Determine if we are using the aiScene root or our own + std::string sceneName("Scene"); + if (mAdd_root_node) { + mSceneId = MakeUniqueId(mUniqueIds, sceneName, std::string()); + mUniqueIds.insert(mSceneId); + } else { + mSceneId = GetNodeUniqueId(mScene->mRootNode); + sceneName = GetNodeName(mScene->mRootNode); + } mOutput << startstr << "" << endstr; PushTag(); - mOutput << startstr << "" << endstr; + mOutput << startstr << "" << endstr; PushTag(); - // start recursive write at the root node - for (size_t a = 0; a < mScene->mRootNode->mNumChildren; ++a) - WriteNode(mScene->mRootNode->mChildren[a]); + if (mAdd_root_node) { + // Export the root node + WriteNode(mScene->mRootNode); + } else { + // Have already exported the root node + for (size_t a = 0; a < mScene->mRootNode->mNumChildren; ++a) + WriteNode(mScene->mRootNode->mChildren[a]); + } PopTag(); mOutput << startstr << "" << endstr; @@ -1610,23 +1620,6 @@ void ColladaExporter::WriteNode(const aiNode *pNode) { mOutput << startstr << "" << endstr; } -inline bool IsUniqueId(const std::unordered_set &idSet, const std::string &idStr) { - return (idSet.find(idStr) == idSet.end()); -} - -inline std::string MakeUniqueId(const std::unordered_set &idSet, const std::string &idPrefix, const std::string &postfix) { - std::string result(idPrefix + postfix); - if (!IsUniqueId(idSet, result)) { - // Select a number to append - size_t idnum = 1; - do { - result = idPrefix + '_' + to_string(idnum) + postfix; - ++idnum; - } while (!IsUniqueId(idSet, result)); - } - return result; -} - void ColladaExporter::CreateNodeIds(const aiNode *node) { GetNodeUniqueId(node); for (size_t a = 0; a < node->mNumChildren; ++a) diff --git a/code/AssetLib/Collada/ColladaExporter.h b/code/AssetLib/Collada/ColladaExporter.h index bea65bafc..e9a3530ae 100644 --- a/code/AssetLib/Collada/ColladaExporter.h +++ b/code/AssetLib/Collada/ColladaExporter.h @@ -196,13 +196,14 @@ public: const std::string mFile; /// The scene to be written - const aiScene *mScene; - bool mSceneOwned; + const aiScene *const mScene; + std::string mSceneId; + bool mAdd_root_node = false; /// current line start string, contains the current indentation for simple stream insertion std::string startstr; /// current line end string for simple stream insertion - std::string endstr; + const std::string endstr; // pair of color and texture - texture precedences color struct Surface { From dc8550290ef2ce2b9d26e98c4172cbb289b56f83 Mon Sep 17 00:00:00 2001 From: RichardTea <31507749+RichardTea@users.noreply.github.com> Date: Tue, 5 May 2020 10:53:26 +0100 Subject: [PATCH 22/26] Ensure to delete the scene copy after the test --- test/unit/utColladaImportExport.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/unit/utColladaImportExport.cpp b/test/unit/utColladaImportExport.cpp index 3d6e0db23..451c8e235 100644 --- a/test/unit/utColladaImportExport.cpp +++ b/test/unit/utColladaImportExport.cpp @@ -53,6 +53,20 @@ using namespace Assimp; class utColladaImportExport : public AbstractImportExportBase { public: + // Clones the scene in an exception-safe way + struct SceneCloner { + SceneCloner(const aiScene *scene) { + sceneCopy = nullptr; + SceneCombiner::CopyScene(&sceneCopy, scene); + } + + ~SceneCloner() { + delete sceneCopy; + sceneCopy = nullptr; + } + aiScene *sceneCopy; + }; + virtual bool importerTest() final { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/duck.dae", aiProcess_ValidateDataStructure); @@ -231,12 +245,10 @@ TEST_F(utColladaImportExport, exportRootNodeMeshTest) { ASSERT_EQ(0u, scene->mRootNode->mNumMeshes) << "Collada import should not give the root node a mesh"; { - // Clone the scene and give the root node a mesh and a transform - aiScene *rootMeshScene = nullptr; - SceneCombiner::CopyScene(&rootMeshScene, scene); - ASSERT_TRUE(rootMeshScene != nullptr) << "Fatal: could not copy scene!"; + SceneCloner clone(scene); + ASSERT_TRUE(clone.sceneCopy != nullptr) << "Fatal: could not copy scene!"; // Do this by moving the meshes from the first child that has some - aiNode *rootNode = rootMeshScene->mRootNode; + aiNode *rootNode = clone.sceneCopy->mRootNode; ASSERT_TRUE(rootNode->mNumChildren > 0) << "Fatal: root has no children"; aiNode *meshNode = rootNode->mChildren[0]; ASSERT_EQ(1u, meshNode->mNumMeshes) << "Fatal: First child node has no duck mesh"; @@ -248,10 +260,12 @@ TEST_F(utColladaImportExport, exportRootNodeMeshTest) { rootNode->mMeshes[i] = meshNode->mMeshes[i]; } + // Remove the meshes from the original node meshNode->mNumMeshes = 0; delete[] meshNode->mMeshes; + meshNode->mMeshes = nullptr; - ASSERT_EQ(AI_SUCCESS, exporter.Export(rootMeshScene, "collada", outFile)) << "Fatal: Could not export file"; + ASSERT_EQ(AI_SUCCESS, exporter.Export(clone.sceneCopy, "collada", outFile)) << "Fatal: Could not export file"; } // Reimport and look for meshes From b990f703a0f7705fb51fdfa72f40911211a95553 Mon Sep 17 00:00:00 2001 From: Kalyan Kumar Date: Thu, 7 May 2020 15:00:21 -0700 Subject: [PATCH 23/26] Add IMPORTED_CONFIGURATIONS property to cmake target. --- assimpTargets-debug.cmake.in | 6 ++++++ assimpTargets-release.cmake.in | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/assimpTargets-debug.cmake.in b/assimpTargets-debug.cmake.in index de6459eaf..b7efe71f9 100644 --- a/assimpTargets-debug.cmake.in +++ b/assimpTargets-debug.cmake.in @@ -73,6 +73,9 @@ else() else() set(sharedLibraryName "libassimp${ASSIMP_LIBRARY_SUFFIX}@CMAKE_DEBUG_POSTFIX@@CMAKE_SHARED_LIBRARY_SUFFIX@.@ASSIMP_VERSION_MAJOR@") endif() + + # Import target "assimp::assimp" for configuration "Debug" + set_property(TARGET assimp::assimp APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(assimp::assimp PROPERTIES IMPORTED_SONAME_DEBUG "${sharedLibraryName}" IMPORTED_LOCATION_DEBUG "@CMAKE_INSTALL_FULL_LIBDIR@/${sharedLibraryName}" @@ -81,6 +84,9 @@ else() list(APPEND _IMPORT_CHECK_FILES_FOR_assimp::assimp "@CMAKE_INSTALL_FULL_LIBDIR@/${sharedLibraryName}" ) else() set(staticLibraryName "libassimp${ASSIMP_LIBRARY_SUFFIX}@CMAKE_DEBUG_POSTFIX@@CMAKE_STATIC_LIBRARY_SUFFIX@") + + # Import target "assimp::assimp" for configuration "Debug" + set_property(TARGET assimp::assimp APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(assimp::assimp PROPERTIES IMPORTED_LOCATION_DEBUG "@CMAKE_INSTALL_FULL_LIBDIR@/${staticLibraryName}" ) diff --git a/assimpTargets-release.cmake.in b/assimpTargets-release.cmake.in index 6a5bafcf7..c716006dd 100644 --- a/assimpTargets-release.cmake.in +++ b/assimpTargets-release.cmake.in @@ -73,6 +73,9 @@ else() else() set(sharedLibraryName "libassimp${ASSIMP_LIBRARY_SUFFIX}@CMAKE_SHARED_LIBRARY_SUFFIX@.@ASSIMP_VERSION_MAJOR@") endif() + + # Import target "assimp::assimp" for configuration "Release" + set_property(TARGET assimp::assimp APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(assimp::assimp PROPERTIES IMPORTED_SONAME_RELEASE "${sharedLibraryName}" IMPORTED_LOCATION_RELEASE "@CMAKE_INSTALL_FULL_LIBDIR@/${sharedLibraryName}" @@ -81,6 +84,9 @@ else() list(APPEND _IMPORT_CHECK_FILES_FOR_assimp::assimp "@CMAKE_INSTALL_FULL_LIBDIR@/${sharedLibraryName}" ) else() set(staticLibraryName "libassimp${ASSIMP_LIBRARY_SUFFIX}@CMAKE_STATIC_LIBRARY_SUFFIX@") + + # Import target "assimp::assimp" for configuration "Release" + set_property(TARGET assimp::assimp APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(assimp::assimp PROPERTIES IMPORTED_LOCATION_RELEASE "@CMAKE_INSTALL_FULL_LIBDIR@/${staticLibraryName}" ) From aef4ecada533c40d41ae4e885eaa39bfe74601cb Mon Sep 17 00:00:00 2001 From: Jeremy Cytryn Date: Wed, 6 May 2020 23:41:05 -0700 Subject: [PATCH 24/26] Fail gltf/gltf2 export whenever invalid / incomplete JSON is generated This can happen currently for example if NaNs are introduced in accessor bounds as rapidjson cannot write NaN/inf floats (see subsequent commit for fix there) and will halt writing to buffer at this point. Fix here ensures that whenever anything like this happens we throw an exception so this ends up as a registered export failure case, rather than silently exporting the incomplete JSON --- code/AssetLib/glTF/glTFAssetWriter.inl | 12 ++++++++---- code/AssetLib/glTF2/glTF2AssetWriter.inl | 10 ++++++---- .../BoxWithInfinites.glb | Bin 0 -> 1900 bytes test/unit/utglTF2ImportExport.cpp | 10 ++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 test/models/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb diff --git a/code/AssetLib/glTF/glTFAssetWriter.inl b/code/AssetLib/glTF/glTFAssetWriter.inl index 5e4416ee9..d8d2556fa 100644 --- a/code/AssetLib/glTF/glTFAssetWriter.inl +++ b/code/AssetLib/glTF/glTFAssetWriter.inl @@ -59,7 +59,7 @@ namespace glTF { namespace { template - inline + inline Value& MakeValue(Value& val, T(&r)[N], MemoryPoolAllocator<>& al) { val.SetArray(); val.Reserve(N, al); @@ -70,7 +70,7 @@ namespace glTF { } template - inline + inline Value& MakeValue(Value& val, const std::vector & r, MemoryPoolAllocator<>& al) { val.SetArray(); val.Reserve(static_cast(r.size()), al); @@ -530,7 +530,9 @@ namespace glTF { StringBuffer docBuffer; PrettyWriter writer(docBuffer); - mDoc.Accept(writer); + if (!mDoc.Accept(writer)) { + throw DeadlyExportError("Failed to write scene data!"); + } if (jsonOutFile->Write(docBuffer.GetString(), docBuffer.GetSize(), 1) != 1) { throw DeadlyExportError("Failed to write scene data!"); @@ -569,7 +571,9 @@ namespace glTF { StringBuffer docBuffer; Writer writer(docBuffer); - mDoc.Accept(writer); + if (!mDoc.Accept(writer)) { + throw DeadlyExportError("Failed to write scene data!"); + } if (outfile->Write(docBuffer.GetString(), docBuffer.GetSize(), 1) != 1) { throw DeadlyExportError("Failed to write scene data!"); diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 798f38c1c..361af40cd 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -613,7 +613,9 @@ namespace glTF2 { StringBuffer docBuffer; PrettyWriter writer(docBuffer); - mDoc.Accept(writer); + if (!mDoc.Accept(writer)) { + throw DeadlyExportError("Failed to write scene data!"); + } if (jsonOutFile->Write(docBuffer.GetString(), docBuffer.GetSize(), 1) != 1) { throw DeadlyExportError("Failed to write scene data!"); @@ -664,7 +666,9 @@ namespace glTF2 { StringBuffer docBuffer; Writer writer(docBuffer); - mDoc.Accept(writer); + if (!mDoc.Accept(writer)) { + throw DeadlyExportError("Failed to write scene data!"); + } uint32_t jsonChunkLength = (docBuffer.GetSize() + 3) & ~3; // Round up to next multiple of 4 auto paddingLength = jsonChunkLength - docBuffer.GetSize(); @@ -816,5 +820,3 @@ namespace glTF2 { } } - - diff --git a/test/models/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb b/test/models/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb new file mode 100644 index 0000000000000000000000000000000000000000..ae83f1f06578eb6b6dc74988dc1c52b9dd6477ab GIT binary patch literal 1900 zcmb7ES#R1v5T^HiU$1DNTFFJWfdqI#BuXSIjug`N0Y#ND3#{Y=txcLJLgb(2FZ3U! z-z;lllC-3l@y?8Azi(#t79$)Z%!wi%v&soOarPtT3xAS5EauEy-YFF}HjC~jHZz#x zx;%+5g!QMxA(!6;|HUe%!TQHBZx4rx8m1cpHQ+(Ke>~x=Qnc(1a!vzeW)}<= zD>wVTvz%L z`vxR`uV@D3MSm8(3LGCzU|ZqQ4-t>+!B7Mu<`Gh%wl#P#ipQ+7X`2@lsj=xsU)SXH zWV=*Cp^hBU+UE=94P8MumSO;M%f9I26)ZJ5jb;^SjZ$d&f6OlAHCIx|4RWE@J298S z@m5;Y;RAGK(w9vhJDw-pPBU?o0lW-#sxZ1_W-_<96jB0tBQjGbmk&13Do+ShM8$ZQZ!`yTJ2r2|$O zB6&_r=JRNb<)mYwm%0fL6(WT%VxTWR`U(xLO=?#wA%cOx$-)|eG{$=Mr?fdx?_RrG z->JN@lC{eN<~$Qqn$@>Y4Mm|IZk{=TC}vT==P?m_NDaILG6?1zv?kjIcGdL;WP z?J1YEwqjF%$hd|9lav;z_TP F{RglTzqJ4W literal 0 HcmV?d00001 diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 55cd2ef6a..99481101e 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -436,6 +436,16 @@ TEST_F(utglTF2ImportExport, error_string_preserved) { ASSERT_NE(error.find("BoxTextured0.bin"), std::string::npos) << "Error string should contain an error about missing .bin file"; } +TEST_F(utglTF2ImportExport, export_bad_accessor_bounds) { + Assimp::Importer importer; + Assimp::Exporter exporter; + const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb", aiProcess_ValidateDataStructure); + ASSERT_NE(scene, nullptr); + + EXPECT_EQ(aiReturn_FAILURE, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.glb")); + EXPECT_EQ(aiReturn_FAILURE, exporter.Export(scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.gltf")); +} + #endif // ASSIMP_BUILD_NO_EXPORT TEST_F(utglTF2ImportExport, sceneMetadata) { From c5a9fbd47f309cf33e2f8fdef03c952b3e212d63 Mon Sep 17 00:00:00 2001 From: Jeremy Cytryn Date: Wed, 6 May 2020 23:59:48 -0700 Subject: [PATCH 25/26] Gracefully handle NaNs and Infs in gltf2 accessor bound computation --- code/AssetLib/glTF2/glTF2Exporter.cpp | 13 ++++++++++--- test/unit/utglTF2ImportExport.cpp | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index da6d9ab2e..7ed4f2670 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -172,6 +172,13 @@ void SetAccessorRange(Ref acc, void* data, size_t count, for (unsigned int j = 0 ; j < numCompsOut ; j++) { double valueTmp = buffer_ptr[j]; + // Gracefully tolerate rogue NaN's in buffer data + // Any NaNs/Infs introduced in accessor bounds will end up in + // document and prevent rapidjson from writing out valid JSON + if (!std::isfinite(valueTmp)) { + continue; + } + if (valueTmp < acc->min[j]) { acc->min[j] = valueTmp; } @@ -348,7 +355,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref& texture, aiTe if (path[0] == '*') { // embedded aiTexture* curTex = mScene->mTextures[atoi(&path[1])]; - + texture->source->name = curTex->mFilename.C_Str(); // The asset has its own buffer, see Image::SetData @@ -762,7 +769,7 @@ void glTF2Exporter::ExportMeshes() for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) { if (!aim->HasTextureCoords(i)) continue; - + // Flip UV y coords if (aim -> mNumUVComponents[i] > 1) { for (unsigned int j = 0; j < aim->mNumVertices; ++j) { diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 99481101e..4ba7c69d4 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -442,8 +442,8 @@ TEST_F(utglTF2ImportExport, export_bad_accessor_bounds) { const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites.glb", aiProcess_ValidateDataStructure); ASSERT_NE(scene, nullptr); - EXPECT_EQ(aiReturn_FAILURE, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.glb")); - EXPECT_EQ(aiReturn_FAILURE, exporter.Export(scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.gltf")); + EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.glb")); + EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.gltf")); } #endif // ASSIMP_BUILD_NO_EXPORT From c3a21666dadd01f7a2f532d3dc0ecaf2045aa81b Mon Sep 17 00:00:00 2001 From: Jeremy Cytryn Date: Thu, 7 May 2020 01:21:54 -0700 Subject: [PATCH 26/26] Make gltf2 export normal normalization safe This avoids introducing NaNs e.g. when the input mesh has 0-length normals --- code/AssetLib/glTF/glTFExporter.cpp | 2 +- code/AssetLib/glTF2/glTF2Exporter.cpp | 2 +- .../BoxBadNormals-glTF-Binary/BoxBadNormals.glb | Bin 0 -> 1924 bytes test/unit/utglTF2ImportExport.cpp | 15 +++++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/models/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals.glb diff --git a/code/AssetLib/glTF/glTFExporter.cpp b/code/AssetLib/glTF/glTFExporter.cpp index e6c14e7dd..b85affc08 100644 --- a/code/AssetLib/glTF/glTFExporter.cpp +++ b/code/AssetLib/glTF/glTFExporter.cpp @@ -348,7 +348,7 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr if (path[0] == '*') { // embedded aiTexture* curTex = mScene->mTextures[atoi(&path[1])]; - + prop.texture->source->name = curTex->mFilename.C_Str(); uint8_t *data = reinterpret_cast(curTex->pcData); diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 7ed4f2670..566f95e80 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -758,7 +758,7 @@ void glTF2Exporter::ExportMeshes() // Normalize all normals as the validator can emit a warning otherwise if ( nullptr != aim->mNormals) { for ( auto i = 0u; i < aim->mNumVertices; ++i ) { - aim->mNormals[ i ].Normalize(); + aim->mNormals[ i ].NormalizeSafe(); } } diff --git a/test/models/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals.glb b/test/models/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals.glb new file mode 100644 index 0000000000000000000000000000000000000000..c36727d12ce675125a3f48e1ebeb68fd1a3992b2 GIT binary patch literal 1924 zcmb_d+iu!G5OweO`|TC&Q!6>hHX#XqsYsMaRDe@R`w~T!fdwr2g4QNYgpl&kkLb@- z{ee{KC-uy-OH2}}M2gK}E;~E3GdsH;gnK(T4a4|x&oF-8HjGbguQ_3Un(~af6L!c& z8YD4unNzfw$p$>;!p{-`jW^sks=~zLvnYiT5m|ZLZMoLNI5EVC8w1 zB_yn}Y;RTT)z&;ur!_?~<+f0reOrWaPc|6F5%w2b^Gh?cIejhH| zgZyM?V*|_a#ejOEv|3qH$+R;O^bpW?&Psd1mz;cU-pcE!Ox~NlN)3@)TZ!_F{EUmh z4;RYP;yqMl)DaDy`C%AzTgiAZjM0|V=^a1iTS=IR9ltC48!feA$;Y-Uj#Y6griEAT zwQ`_M(X&GP(mH!;G9Cpu2!~wj_Q`>T_4(mw=r8H z#dDboPltRVj|Mc9hzOz}gZJ5BB)y>+I(NAfLEH;)@NjMrG{b&%#uG?6OCwd;*R#O@$Udv#w_WU_L{iSF8pFg2E>RE;-(`D?m z%?ahBo@Mx}*v|ajz!duK-BOffeEy6(z+C{JLrF=#4?F-K0*@3W`7!VWcnUmIl;r2Y V3*aU2N>P$u18;!0z&k}r{s%56wT%D( literal 0 HcmV?d00001 diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 4ba7c69d4..f0f18d503 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -446,6 +446,21 @@ TEST_F(utglTF2ImportExport, export_bad_accessor_bounds) { EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "gltf2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxWithInfinites-glTF-Binary/BoxWithInfinites_out.gltf")); } +TEST_F(utglTF2ImportExport, export_normalized_normals) { + Assimp::Importer importer; + Assimp::Exporter exporter; + const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals.glb", aiProcess_ValidateDataStructure); + ASSERT_NE(scene, nullptr); + EXPECT_EQ(aiReturn_SUCCESS, exporter.Export(scene, "glb2", ASSIMP_TEST_MODELS_DIR "/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals_out.glb")); + + // load in again and ensure normal-length normals but no Nan's or Inf's introduced + scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/BoxBadNormals-glTF-Binary/BoxBadNormals_out.glb", aiProcess_ValidateDataStructure); + for ( auto i = 0u; i < scene->mMeshes[0]->mNumVertices; ++i ) { + const auto length = scene->mMeshes[0]->mNormals[i].Length(); + EXPECT_TRUE(abs(length) < 1e-6 || abs(length - 1) < 1e-6); + } +} + #endif // ASSIMP_BUILD_NO_EXPORT TEST_F(utglTF2ImportExport, sceneMetadata) {