diff --git a/code/AssetLib/Blender/BlenderScene.cpp b/code/AssetLib/Blender/BlenderScene.cpp index 3a9a02fd0..ac10d7302 100644 --- a/code/AssetLib/Blender/BlenderScene.cpp +++ b/code/AssetLib/Blender/BlenderScene.cpp @@ -569,7 +569,7 @@ void Structure ::Convert( const FileDatabase &db) const { ReadFieldArray(dest.co, "co", db); - ReadFieldArray(dest.no, "no", db); + ReadFieldArray(dest.no, "no", db); ReadField(dest.flag, "flag", db); //ReadField(dest.mat_nr,"mat_nr",db); ReadField(dest.bweight, "bweight", db); diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 37654746e..f1f57c10b 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -1180,15 +1180,23 @@ unsigned int FBXConverter::ConvertMeshSingleMaterial(const MeshGeometry &mesh, c std::vector animMeshes; for (const BlendShape *blendShape : mesh.GetBlendShapes()) { for (const BlendShapeChannel *blendShapeChannel : blendShape->BlendShapeChannels()) { - const std::vector &shapeGeometries = blendShapeChannel->GetShapeGeometries(); - for (size_t i = 0; i < shapeGeometries.size(); i++) { + const auto& shapeGeometries = blendShapeChannel->GetShapeGeometries(); + for (const ShapeGeometry *shapeGeometry : shapeGeometries) { aiAnimMesh *animMesh = aiCreateAnimMesh(out_mesh); - const ShapeGeometry *shapeGeometry = shapeGeometries.at(i); - const std::vector &curVertices = shapeGeometry->GetVertices(); - const std::vector &curNormals = shapeGeometry->GetNormals(); - const std::vector &curIndices = shapeGeometry->GetIndices(); + const auto &curVertices = shapeGeometry->GetVertices(); + const auto &curNormals = shapeGeometry->GetNormals(); + const auto &curIndices = shapeGeometry->GetIndices(); //losing channel name if using shapeGeometry->Name() - animMesh->mName.Set(FixAnimMeshName(blendShapeChannel->Name())); + // if blendShapeChannel Name is empty or don't have a ".", add geoMetryName; + auto aniName = FixAnimMeshName(blendShapeChannel->Name()); + auto geoMetryName = FixAnimMeshName(shapeGeometry->Name()); + if (aniName.empty()) { + aniName = geoMetryName; + } + else if (aniName.find('.') == aniName.npos) { + aniName += "." + geoMetryName; + } + animMesh->mName.Set(aniName); for (size_t j = 0; j < curIndices.size(); j++) { const unsigned int curIndex = curIndices.at(j); aiVector3D vertex = curVertices.at(j); @@ -1410,13 +1418,12 @@ unsigned int FBXConverter::ConvertMeshMultiMaterial(const MeshGeometry &mesh, co std::vector animMeshes; for (const BlendShape *blendShape : mesh.GetBlendShapes()) { for (const BlendShapeChannel *blendShapeChannel : blendShape->BlendShapeChannels()) { - const std::vector &shapeGeometries = blendShapeChannel->GetShapeGeometries(); - for (size_t i = 0; i < shapeGeometries.size(); i++) { + const auto& shapeGeometries = blendShapeChannel->GetShapeGeometries(); + for (const ShapeGeometry *shapeGeometry : shapeGeometries) { aiAnimMesh *animMesh = aiCreateAnimMesh(out_mesh); - const ShapeGeometry *shapeGeometry = shapeGeometries.at(i); - const std::vector &curVertices = shapeGeometry->GetVertices(); - const std::vector &curNormals = shapeGeometry->GetNormals(); - const std::vector &curIndices = shapeGeometry->GetIndices(); + const auto& curVertices = shapeGeometry->GetVertices(); + const auto& curNormals = shapeGeometry->GetNormals(); + const auto& curIndices = shapeGeometry->GetIndices(); animMesh->mName.Set(FixAnimMeshName(shapeGeometry->Name())); for (size_t j = 0; j < curIndices.size(); j++) { unsigned int curIndex = curIndices.at(j); diff --git a/code/AssetLib/FBX/FBXDeformer.cpp b/code/AssetLib/FBX/FBXDeformer.cpp index df134a401..1aab55ea9 100644 --- a/code/AssetLib/FBX/FBXDeformer.cpp +++ b/code/AssetLib/FBX/FBXDeformer.cpp @@ -154,8 +154,10 @@ BlendShape::BlendShape(uint64_t id, const Element& element, const Document& doc, for (const Connection* con : conns) { const BlendShapeChannel* const bspc = ProcessSimpleConnection(*con, false, "BlendShapeChannel -> BlendShape", element); if (bspc) { - blendShapeChannels.push_back(bspc); - continue; + auto pr = blendShapeChannels.insert(bspc); + if (!pr.second) { + FBXImporter::LogWarn("there is the same blendShapeChannel id ", bspc->ID()); + } } } } @@ -179,8 +181,10 @@ BlendShapeChannel::BlendShapeChannel(uint64_t id, const Element& element, const for (const Connection* con : conns) { const ShapeGeometry* const sg = ProcessSimpleConnection(*con, false, "Shape -> BlendShapeChannel", element); if (sg) { - shapeGeometries.push_back(sg); - continue; + auto pr = shapeGeometries.insert(sg); + if (!pr.second) { + FBXImporter::LogWarn("there is the same shapeGeometrie id ", sg->ID()); + } } } } diff --git a/code/AssetLib/FBX/FBXDocument.h b/code/AssetLib/FBX/FBXDocument.h index 8873d65fd..821d4d5cb 100644 --- a/code/AssetLib/FBX/FBXDocument.h +++ b/code/AssetLib/FBX/FBXDocument.h @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define INCLUDED_AI_FBX_DOCUMENT_H #include +#include #include #include #include "FBXProperties.h" @@ -855,14 +856,14 @@ public: return fullWeights; } - const std::vector& GetShapeGeometries() const { + const std::unordered_set& GetShapeGeometries() const { return shapeGeometries; } private: float percent; WeightArray fullWeights; - std::vector shapeGeometries; + std::unordered_set shapeGeometries; }; /** DOM class for BlendShape deformers */ @@ -872,12 +873,12 @@ public: virtual ~BlendShape(); - const std::vector& BlendShapeChannels() const { + const std::unordered_set& BlendShapeChannels() const { return blendShapeChannels; } private: - std::vector blendShapeChannels; + std::unordered_set blendShapeChannels; }; /** DOM class for skin deformer clusters (aka sub-deformers) */ diff --git a/code/AssetLib/FBX/FBXMeshGeometry.cpp b/code/AssetLib/FBX/FBXMeshGeometry.cpp index ace4ad749..fcbaac169 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.cpp +++ b/code/AssetLib/FBX/FBXMeshGeometry.cpp @@ -69,13 +69,16 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, } const BlendShape* const bsp = ProcessSimpleConnection(*con, false, "BlendShape -> Geometry", element); if (bsp) { - blendShapes.push_back(bsp); + auto pr = blendShapes.insert(bsp); + if (!pr.second) { + FBXImporter::LogWarn("there is the same blendShape id ", bsp->ID()); + } } } } // ------------------------------------------------------------------------------------------------ -const std::vector& Geometry::GetBlendShapes() const { +const std::unordered_set& Geometry::GetBlendShapes() const { return blendShapes; } diff --git a/code/AssetLib/FBX/FBXMeshGeometry.h b/code/AssetLib/FBX/FBXMeshGeometry.h index f4a1a2673..3d67ec567 100644 --- a/code/AssetLib/FBX/FBXMeshGeometry.h +++ b/code/AssetLib/FBX/FBXMeshGeometry.h @@ -62,7 +62,7 @@ public: /// @param name The name instance /// @param doc The document instance Geometry( uint64_t id, const Element& element, const std::string& name, const Document& doc ); - + /// @brief The class destructor, default. virtual ~Geometry() = default; @@ -72,11 +72,12 @@ public: /// @brief Get the BlendShape attached to this geometry or nullptr /// @return The blendshape arrays. - const std::vector& GetBlendShapes() const; + const std::unordered_set& GetBlendShapes() const; private: const Skin* skin; - std::vector blendShapes; + std::unordered_set blendShapes; + }; typedef std::vector MatIndexArray; @@ -112,7 +113,7 @@ public: /// @return The binomal vector. const std::vector& GetBinormals() const; - /// @brief Return list of faces - each entry denotes a face and specifies how many vertices it has. + /// @brief Return list of faces - each entry denotes a face and specifies how many vertices it has. /// Vertices are taken from the vertex data arrays in sequential order. /// @return The face indices vector. const std::vector& GetFaceIndexCounts() const; diff --git a/code/PostProcessing/ValidateDataStructure.cpp b/code/PostProcessing/ValidateDataStructure.cpp index cae35b895..e31054972 100644 --- a/code/PostProcessing/ValidateDataStructure.cpp +++ b/code/PostProcessing/ValidateDataStructure.cpp @@ -911,7 +911,12 @@ void ValidateDSProcess::Validate(const aiNode *pNode) { nodeName, pNode->mNumChildren); } for (unsigned int i = 0; i < pNode->mNumChildren; ++i) { - Validate(pNode->mChildren[i]); + const aiNode *pChild = pNode->mChildren[i]; + Validate(pChild); + if (pChild->mParent != pNode) { + const char *parentName = (pChild->mParent != nullptr) ? pChild->mParent->mName.C_Str() : "null"; + ReportError("aiNode \"%s\" child %i \"%s\" parent is someone else: \"%s\"", pNode->mName.C_Str(), i, pChild->mName.C_Str(), parentName); + } } } } diff --git a/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp b/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp index 4614066e6..d50c2b35a 100644 --- a/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp +++ b/test/unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp @@ -190,7 +190,7 @@ private: Assimp::Importer importer; importer.SetPropertyBool(setting_key, setting_value); const aiScene *scene = importer.ReadFile(file_path, aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); func(scene); } diff --git a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp index 2389c0ffc..f733893ca 100644 --- a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp +++ b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp @@ -61,8 +61,8 @@ public: void flatShadeTexture() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "chrome_sphere.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); - EXPECT_NE(nullptr, scene->mMaterials); + ASSERT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene->mMaterials); aiShadingMode shading_mode = aiShadingMode_Flat; scene->mMaterials[0]->Get(AI_MATKEY_SHADING_MODEL, shading_mode); @@ -74,8 +74,8 @@ public: void chromeTexture() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "chrome_sphere.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); - EXPECT_NE(nullptr, scene->mMaterials); + ASSERT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene->mMaterials); int chrome; scene->mMaterials[0]->Get(AI_MDL_HL1_MATKEY_CHROME(aiTextureType_DIFFUSE, 0), chrome); @@ -87,8 +87,8 @@ public: void additiveBlendTexture() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "blend_additive.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); - EXPECT_NE(nullptr, scene->mMaterials); + ASSERT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene->mMaterials); aiBlendMode blend_mode = aiBlendMode_Default; scene->mMaterials[0]->Get(AI_MATKEY_BLEND_FUNC, blend_mode); @@ -101,8 +101,8 @@ public: void textureWithColorMask() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "alpha_test.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); - EXPECT_NE(nullptr, scene->mMaterials); + ASSERT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene->mMaterials); int texture_flags = 0; scene->mMaterials[0]->Get(AI_MATKEY_TEXFLAGS_DIFFUSE(0), texture_flags); diff --git a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp index 712f4da11..49ae8a16c 100644 --- a/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp +++ b/test/unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp @@ -136,7 +136,7 @@ public: void emptyBonesNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_bones.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_bones_names = { "Bone", @@ -172,7 +172,7 @@ public: void emptyBodypartsNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_bodyparts.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_bodyparts_names = { "Bodypart", @@ -209,7 +209,7 @@ public: void duplicateBodypartsNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_bodyparts.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_bodyparts_names = { "Bodypart", @@ -254,7 +254,7 @@ public: void duplicateSubModelsNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_submodels.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const std::vector expected_bodypart_sub_models_names = { { @@ -272,7 +272,7 @@ public: }; const aiNode *bodyparts_node = scene->mRootNode->FindNode(AI_MDL_HL1_NODE_BODYPARTS); - EXPECT_NE(nullptr, bodyparts_node); + ASSERT_NE(nullptr, bodyparts_node); EXPECT_EQ(3u, bodyparts_node->mNumChildren); StringVector actual_submodels_names; @@ -301,7 +301,7 @@ public: void duplicateSequenceNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_sequences.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_sequence_names = { "idle_1", @@ -337,7 +337,7 @@ public: void emptySequenceNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_sequences.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_sequence_names = { "Sequence", @@ -374,7 +374,7 @@ public: void duplicateSequenceGroupNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "duplicate_sequence_groups/duplicate_sequence_groups.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_sequence_names = { "default", @@ -412,7 +412,7 @@ public: void emptySequenceGroupNames() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MDL_HL1_MODELS_DIR "unnamed_sequence_groups/unnamed_sequence_groups.mdl", aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); const StringVector expected_sequence_names = { "default", @@ -440,7 +440,7 @@ public: Assimp::Importer importer; const aiScene *scene = importer.ReadFile(MDL_HL1_FILE_MAN, aiProcess_ValidateDataStructure); - EXPECT_NE(nullptr, scene); + ASSERT_NE(nullptr, scene); aiNode *scene_bones_node = scene->mRootNode->FindNode(AI_MDL_HL1_NODE_BONES); diff --git a/test/unit/utASEImportExport.cpp b/test/unit/utASEImportExport.cpp index 8014cbbc7..af05a2fe5 100644 --- a/test/unit/utASEImportExport.cpp +++ b/test/unit/utASEImportExport.cpp @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include using namespace Assimp; @@ -63,3 +64,112 @@ public: TEST_F(utASEImportExport, importACFromFileTest) { EXPECT_TRUE(importerTest()); } + + +TEST_F(utASEImportExport, importAnim1) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/anim.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importAnim2) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/anim2.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importCameraRollAnim) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/CameraRollAnim.ase", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importMotionCaptureROM) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/MotionCaptureROM.ase", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importRotatingCube) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/RotatingCube.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importTargetCameraAnim) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/TargetCameraAnim.ase", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importTestFormatDetection) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/TestFormatDetection", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importThreeCubesGreen) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/ThreeCubesGreen.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); + + ::Assimp::Importer importerLE; + const aiScene *sceneLE = importerLE.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/ThreeCubesGreen_UTF16LE.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, sceneLE); + + ::Assimp::Importer importerBE; + const aiScene *sceneBE = importerBE.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/ThreeCubesGreen_UTF16BE.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, sceneBE); + + // TODO: these scenes should probably be identical + // verify that is the case and then add tests to check it +} + + +TEST_F(utASEImportExport, importUVTransform_Normal) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/TestUVTransform/UVTransform_Normal.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importUVTransform_ScaleUV1_2_OffsetUV0_0_9_Rotate_72_mirrorU) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/TestUVTransform/UVTransform_ScaleUV1-2_OffsetUV0-0.9_Rotate-72_mirrorU.ase", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importUVTransform_ScaleUV2x) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/TestUVTransform/UVTransform_ScaleUV2x.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +} + + +TEST_F(utASEImportExport, importUVTransform_ScaleUV2x_Rotate45) { + ::Assimp::Importer importer; + const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/ASE/TestUVTransform/UVTransform_ScaleUV2x_Rotate45.ASE", aiProcess_ValidateDataStructure); + + ASSERT_NE(nullptr, scene); +}