Bläddra i källkod

Merge pull request #4679 from turol/blender-fixes

(Mostly) Blender fixes
Turo Lamminen 3 år sedan
förälder
incheckning
94c3ec57af

+ 2 - 2
code/AssetLib/Blender/BlenderDNA.h

@@ -416,10 +416,10 @@ template <>
 struct Structure::_defaultInitializer<ErrorPolicy_Fail> {
 
     template <typename T>
-    void operator()(T & /*out*/, const char * = "") {
+    void operator()(T & /*out*/, const char *message = "") {
         // obviously, it is crucial that _DefaultInitializer is used
         // only from within a catch clause.
-        throw DeadlyImportError("Constructing BlenderDNA Structure encountered an error");
+        throw DeadlyImportError("Constructing BlenderDNA Structure encountered an error: ", message);
     }
 };
 

+ 3 - 6
code/AssetLib/Blender/BlenderModifier.cpp

@@ -71,10 +71,6 @@ static const fpCreateModifier creators[] = {
     nullptr // sentinel
 };
 
-// ------------------------------------------------------------------------------------------------
-struct SharedModifierData : ElemBase {
-    ModifierData modifier;
-};
 
 // ------------------------------------------------------------------------------------------------
 void BlenderModifierShowcase::ApplyModifiers(aiNode &out, ConversionData &conv_data, const Scene &in, const Object &orig_object) {
@@ -157,6 +153,7 @@ void BlenderModifier_Mirror ::DoIt(aiNode &out, ConversionData &conv_data, const
     // hijacking the ABI, see the big note in BlenderModifierShowcase::ApplyModifiers()
     const MirrorModifierData &mir = static_cast<const MirrorModifierData &>(orig_modifier);
     ai_assert(mir.modifier.type == ModifierData::eModifierType_Mirror);
+    std::shared_ptr<Object> mirror_ob = mir.mirror_ob.lock();
 
     conv_data.meshes->reserve(conv_data.meshes->size() + out.mNumMeshes);
 
@@ -171,8 +168,8 @@ void BlenderModifier_Mirror ::DoIt(aiNode &out, ConversionData &conv_data, const
         const float ys = mir.flag & MirrorModifierData::Flags_AXIS_Y ? -1.f : 1.f;
         const float zs = mir.flag & MirrorModifierData::Flags_AXIS_Z ? -1.f : 1.f;
 
-        if (mir.mirror_ob) {
-            const aiVector3D center(mir.mirror_ob->obmat[3][0], mir.mirror_ob->obmat[3][1], mir.mirror_ob->obmat[3][2]);
+        if (mirror_ob) {
+            const aiVector3D center(mirror_ob->obmat[3][0], mirror_ob->obmat[3][1], mirror_ob->obmat[3][2]);
             for (unsigned int j = 0; j < mesh->mNumVertices; ++j) {
                 aiVector3D &v = mesh->mVertices[j];
 

+ 12 - 6
code/AssetLib/Blender/BlenderScene.cpp

@@ -624,7 +624,9 @@ void Structure ::Convert<ListBase>(
         const FileDatabase &db) const {
 
     ReadFieldPtr<ErrorPolicy_Igno>(dest.first, "*first", db);
-    ReadFieldPtr<ErrorPolicy_Igno>(dest.last, "*last", db);
+    std::shared_ptr<ElemBase> last;
+    ReadFieldPtr<ErrorPolicy_Igno>(last, "*last", db);
+    dest.last = last;
 
     db.reader->IncPtr(size);
 }
@@ -648,7 +650,9 @@ void Structure ::Convert<ModifierData>(
         const FileDatabase &db) const {
 
     ReadFieldPtr<ErrorPolicy_Warn>(dest.next, "*next", db);
-    ReadFieldPtr<ErrorPolicy_Warn>(dest.prev, "*prev", db);
+    std::shared_ptr<ElemBase> prev;
+    ReadFieldPtr<ErrorPolicy_Warn>(prev, "*prev", db);
+    dest.prev = prev;
     ReadField<ErrorPolicy_Igno>(dest.type, "type", db);
     ReadField<ErrorPolicy_Igno>(dest.mode, "mode", db);
     ReadFieldArray<ErrorPolicy_Igno>(dest.name, "name", db);
@@ -772,7 +776,9 @@ void Structure ::Convert<MirrorModifierData>(
     ReadField<ErrorPolicy_Igno>(dest.axis, "axis", db);
     ReadField<ErrorPolicy_Igno>(dest.flag, "flag", db);
     ReadField<ErrorPolicy_Igno>(dest.tolerance, "tolerance", db);
-    ReadFieldPtr<ErrorPolicy_Igno>(dest.mirror_ob, "*mirror_ob", db);
+    std::shared_ptr<Object> mirror_ob;
+    ReadFieldPtr<ErrorPolicy_Igno>(mirror_ob, "*mirror_ob", db);
+    dest.mirror_ob = mirror_ob;
 
     db.reader->IncPtr(size);
 }
@@ -833,9 +839,9 @@ void Structure::Convert<CustomDataLayer>(
     ReadField<ErrorPolicy_Fail>(dest.flag, "flag", db);
     ReadField<ErrorPolicy_Fail>(dest.active, "active", db);
     ReadField<ErrorPolicy_Fail>(dest.active_rnd, "active_rnd", db);
-    ReadField<ErrorPolicy_Fail>(dest.active_clone, "active_clone", db);
-    ReadField<ErrorPolicy_Fail>(dest.active_mask, "active_mask", db);
-    ReadField<ErrorPolicy_Fail>(dest.uid, "uid", db);
+    ReadField<ErrorPolicy_Warn>(dest.active_clone, "active_clone", db);
+    ReadField<ErrorPolicy_Warn>(dest.active_mask, "active_mask", db);
+    ReadField<ErrorPolicy_Warn>(dest.uid, "uid", db);
     ReadFieldArray<ErrorPolicy_Warn>(dest.name, "name", db);
     ReadCustomDataPtr<ErrorPolicy_Fail>(dest.data, dest.type, "*data", db);
 

+ 12 - 8
code/AssetLib/Blender/BlenderScene.h

@@ -124,7 +124,7 @@ struct ID : ElemBase {
 // -------------------------------------------------------------------------------
 struct ListBase : ElemBase {
     std::shared_ptr<ElemBase> first;
-    std::shared_ptr<ElemBase> last;
+    std::weak_ptr<ElemBase> last;
 };
 
 // -------------------------------------------------------------------------------
@@ -642,14 +642,21 @@ struct ModifierData : ElemBase {
     };
 
     std::shared_ptr<ElemBase> next WARN;
-    std::shared_ptr<ElemBase> prev WARN;
+    std::weak_ptr<ElemBase> prev WARN;
 
     int type, mode;
     char name[32];
 };
 
+
+// ------------------------------------------------------------------------------------------------
+struct SharedModifierData : ElemBase {
+    ModifierData modifier;
+};
+
+
 // -------------------------------------------------------------------------------
-struct SubsurfModifierData : ElemBase {
+struct SubsurfModifierData : SharedModifierData {
 
     enum Type {
 
@@ -662,7 +669,6 @@ struct SubsurfModifierData : ElemBase {
         FLAGS_SubsurfUV = 1 << 3
     };
 
-    ModifierData modifier FAIL;
     short subdivType WARN;
     short levels FAIL;
     short renderLevels;
@@ -670,7 +676,7 @@ struct SubsurfModifierData : ElemBase {
 };
 
 // -------------------------------------------------------------------------------
-struct MirrorModifierData : ElemBase {
+struct MirrorModifierData : SharedModifierData {
 
     enum Flags {
         Flags_CLIPPING = 1 << 0,
@@ -682,11 +688,9 @@ struct MirrorModifierData : ElemBase {
         Flags_VGROUP = 1 << 6
     };
 
-    ModifierData modifier FAIL;
-
     short axis, flag;
     float tolerance;
-    std::shared_ptr<Object> mirror_ob;
+    std::weak_ptr<Object> mirror_ob;
 };
 
 // -------------------------------------------------------------------------------

+ 0 - 2
code/AssetLib/LWO/LWOMaterial.cpp

@@ -707,12 +707,10 @@ void LWOImporter::LoadNodalBlocks(unsigned int size) {
         if (mFileBuffer + head.length > end) {
             throw DeadlyImportError("LWO3: cannot read length; LoadNodalBlocks");
         }
-        int node_idx = 0;
         uint8_t *const next = mFileBuffer + head.length;
         mFileBuffer += bufOffset;
         switch (head.type) {
         case AI_LWO_NNDS:
-            node_idx++;
             LoadNodes(head.length);
             break;
         }

+ 1 - 5
code/AssetLib/LWS/LWSLoader.cpp

@@ -516,7 +516,7 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
     std::list<LWS::NodeDesc> nodes;
 
     unsigned int cur_light = 0, cur_camera = 0, cur_object = 0;
-    unsigned int num_light = 0, num_camera = 0, num_object = 0;
+    unsigned int num_light = 0, num_camera = 0;
 
     // check magic identifier, 'LWSC'
     bool motion_file = false;
@@ -586,7 +586,6 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
             d.id = batch.AddLoadRequest(path, 0, &props);
 
             nodes.push_back(d);
-            ++num_object;
         } else if ((*it).tokens[0] == "LoadObject") { // 'LoadObject': load a LWO file into the scene-graph
 
             // add node to list
@@ -604,7 +603,6 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
 
             d.path = path;
             nodes.push_back(d);
-            ++num_object;
         } else if ((*it).tokens[0] == "AddNullObject") { // 'AddNullObject': add a dummy node to the hierarchy
 
             // add node to list
@@ -618,8 +616,6 @@ void LWSImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
             }
             d.name = c;
             nodes.push_back(d);
-
-            num_object++;
         }
         // 'NumChannels': Number of envelope channels assigned to last layer
         else if ((*it).tokens[0] == "NumChannels") {

+ 0 - 2
code/AssetLib/Obj/ObjFileParser.cpp

@@ -112,7 +112,6 @@ ObjFile::Model *ObjFileParser::GetModel() const {
 void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
     // only update every 100KB or it'll be too slow
     //const unsigned int updateProgressEveryBytes = 100 * 1024;
-    unsigned int progressCounter = 0;
     const unsigned int bytesToProcess = static_cast<unsigned int>(streamBuffer.size());
     const unsigned int progressTotal = bytesToProcess;
     unsigned int processed = 0;
@@ -129,7 +128,6 @@ void ObjFileParser::parseFile(IOStreamBuffer<char> &streamBuffer) {
         if (lastFilePos < filePos) {
             processed = static_cast<unsigned int>(filePos);
             lastFilePos = filePos;
-            progressCounter++;
             m_progress->UpdateFileRead(processed, progressTotal);
         }
 

+ 0 - 3
code/AssetLib/X3D/X3DImporter.cpp

@@ -477,9 +477,6 @@ void X3DImporter::ParseHelper_Node_Exit() {
     // check if we can walk up.
     if (mNodeElementCur != nullptr) {
         mNodeElementCur = mNodeElementCur->Parent;
-    } else {
-        int i = 0;
-        ++i;
     }
 }
 

+ 0 - 2
code/Common/ScenePreprocessor.cpp

@@ -118,10 +118,8 @@ void ScenePreprocessor::ProcessMesh(aiMesh *mesh) {
         // as if they were 2D channels .. just in case an application doesn't handle
         // this case
         if (2 == mesh->mNumUVComponents[i]) {
-            size_t num = 0;
             for (; p != end; ++p) {
                 p->z = 0.f;
-                num++;
             }
         } else if (1 == mesh->mNumUVComponents[i]) {
             for (; p != end; ++p) {

+ 0 - 3
contrib/openddlparser/code/OpenDDLParser.cpp

@@ -647,12 +647,9 @@ char *OpenDDLParser::parseBooleanLiteral(char *in, char *end, Value **boolean) {
 
     in = lookForNextToken(in, end);
     char *start(in);
-    size_t len(0);
     while (!isSeparator(*in) && in != end) {
         ++in;
-        ++len;
     }
-    ++len;
     int res = ::strncmp(Grammar::BoolTrue, start, strlen(Grammar::BoolTrue));
     if (0 != res) {
         res = ::strncmp(Grammar::BoolFalse, start, strlen(Grammar::BoolFalse));

+ 17 - 34
test/unit/utBlenderImportExport.cpp

@@ -64,8 +64,7 @@ TEST_F(utBlenderImporterExporter, importBlenFromFileTest) {
 TEST(utBlenderImporter, import4cubes) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/4Cubes4Mats_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, import269_regress1) {
@@ -77,22 +76,19 @@ TEST(utBlenderImporter, import269_regress1) {
 TEST(utBlenderImporter, importBlenderDefault248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/BlenderDefault_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importBlenderDefault250) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/BlenderDefault_250.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importBlenderDefault250Compressed) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/BlenderDefault_250_Compressed.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importBlenderDefault262) {
@@ -123,92 +119,79 @@ TEST(utBlenderImporter, importBlenderDefault293) {
 TEST(utBlenderImporter, importCubeHierarchy_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/CubeHierarchy_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importHuman) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/HUMAN.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+	ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importMirroredCube_252) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/MirroredCube_252.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importNoisyTexturedCube_VoronoiGlob_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/NoisyTexturedCube_VoronoiGlob_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importSmoothVsSolidCube_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/SmoothVsSolidCube_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importSuzanne_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/Suzanne_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importSuzanneSubdiv_252) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/SuzanneSubdiv_252.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importTexturedCube_ImageGlob_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/TexturedCube_ImageGlob_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importTexturedPlane_ImageUv_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/TexturedPlane_ImageUv_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importTexturedPlane_ImageUvPacked_248) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/TexturedPlane_ImageUvPacked_248.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importTorusLightsCams_250_compressed) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/TorusLightsCams_250_compressed.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, import_yxa_1) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/BLEND/yxa_1.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importBob) {
     Assimp::Importer importer;
     const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_NONBSD_DIR "/BLEND/Bob.blend", aiProcess_ValidateDataStructure);
-    // FIXME: this is probably not right, loading this should succeed
-    ASSERT_EQ(nullptr, scene);
+    ASSERT_NE(nullptr, scene);
 }
 
 TEST(utBlenderImporter, importFleurOptonl) {

+ 6 - 6
tools/assimp_cmd/Info.cpp

@@ -286,12 +286,6 @@ void PrintHierarchy(
 // -----------------------------------------------------------------------------------
 // Implementation of the assimp info utility to print basic file info
 int Assimp_Info(const char *const *params, unsigned int num) {
-    // --help
-    if (!strcmp(params[0], "-h") || !strcmp(params[0], "--help") || !strcmp(params[0], "-?")) {
-        printf("%s", AICMD_MSG_INFO_HELP_E);
-        return AssimpCmdError::Success;
-    }
-
     // asssimp info <file> [-r]
     if (num < 1) {
         printf("assimp info: Invalid number of arguments. "
@@ -299,6 +293,12 @@ int Assimp_Info(const char *const *params, unsigned int num) {
         return AssimpCmdError::InvalidNumberOfArguments;
     }
 
+    // --help
+    if (!strcmp(params[0], "-h") || !strcmp(params[0], "--help") || !strcmp(params[0], "-?")) {
+        printf("%s", AICMD_MSG_INFO_HELP_E);
+        return AssimpCmdError::Success;
+    }
+
     const std::string in = std::string(params[0]);
 
     // get -r and -v arguments