瀏覽代碼

Merge branch 'master' into fix-segfault-fbx-import

Kim Kulling 6 年之前
父節點
當前提交
e20640c2c8
共有 2 個文件被更改,包括 10 次插入14 次删除
  1. 2 2
      code/FBX/FBXImporter.cpp
  2. 8 12
      code/FBX/FBXMeshGeometry.cpp

+ 2 - 2
code/FBX/FBXImporter.cpp

@@ -193,8 +193,8 @@ void FBXImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
         // convert the FBX DOM to aiScene
         // convert the FBX DOM to aiScene
         ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones, unit);
         ConvertToAssimpScene(pScene, doc, settings.removeEmptyBones, unit);
         
         
-        // Set file scale relative to meters
-        SetFileScale( doc.GlobalSettings().UnitScaleFactor() );
+        // units is relative to CM :) we need it in meters for assimp
+        SetFileScale( doc.GlobalSettings().UnitScaleFactor() * 0.01f);
 
 
         std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
         std::for_each(tokens.begin(),tokens.end(),Util::delete_fun<Token>());
     }
     }

+ 8 - 12
code/FBX/FBXMeshGeometry.cpp

@@ -610,11 +610,11 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
     const std::string& ReferenceInformationType)
     const std::string& ReferenceInformationType)
 {
 {
     const size_t face_count = m_faces.size();
     const size_t face_count = m_faces.size();
-    if(face_count == 0)
+    if( 0 == face_count )
     {
     {
         return;
         return;
     }
     }
-
+    
     // materials are handled separately. First of all, they are assigned per-face
     // materials are handled separately. First of all, they are assigned per-face
     // and not per polyvert. Secondly, ReferenceInformationType=IndexToDirect
     // and not per polyvert. Secondly, ReferenceInformationType=IndexToDirect
     // has a slightly different meaning for materials.
     // has a slightly different meaning for materials.
@@ -625,16 +625,14 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
         if (materials_out.empty()) {
         if (materials_out.empty()) {
             FBXImporter::LogError(Formatter::format("expected material index, ignoring"));
             FBXImporter::LogError(Formatter::format("expected material index, ignoring"));
             return;
             return;
-        }
-        else if (materials_out.size() > 1) {
+        } else if (materials_out.size() > 1) {
             FBXImporter::LogWarn(Formatter::format("expected only a single material index, ignoring all except the first one"));
             FBXImporter::LogWarn(Formatter::format("expected only a single material index, ignoring all except the first one"));
             materials_out.clear();
             materials_out.clear();
         }
         }
 
 
         materials_out.resize(m_vertices.size());
         materials_out.resize(m_vertices.size());
         std::fill(materials_out.begin(), materials_out.end(), materials_out.at(0));
         std::fill(materials_out.begin(), materials_out.end(), materials_out.at(0));
-    }
-    else if (MappingInformationType == "ByPolygon" && ReferenceInformationType == "IndexToDirect") {
+    } else if (MappingInformationType == "ByPolygon" && ReferenceInformationType == "IndexToDirect") {
         materials_out.resize(face_count);
         materials_out.resize(face_count);
 
 
         if(materials_out.size() != face_count) {
         if(materials_out.size() != face_count) {
@@ -643,18 +641,16 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
             );
             );
             return;
             return;
         }
         }
-    }
-    else {
+    } else {
         FBXImporter::LogError(Formatter::format("ignoring material assignments, access type not implemented: ")
         FBXImporter::LogError(Formatter::format("ignoring material assignments, access type not implemented: ")
             << MappingInformationType << "," << ReferenceInformationType);
             << MappingInformationType << "," << ReferenceInformationType);
     }
     }
 }
 }
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 ShapeGeometry::ShapeGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc)
 ShapeGeometry::ShapeGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc)
-    : Geometry(id, element, name, doc)
-{
-    const Scope* sc = element.Compound();
-    if (!sc) {
+: Geometry(id, element, name, doc) {
+    const Scope *sc = element.Compound();
+    if (nullptr == sc) {
         DOMError("failed to read Geometry object (class: Shape), no data scope found");
         DOMError("failed to read Geometry object (class: Shape), no data scope found");
     }
     }
     const Element& Indexes = GetRequiredElement(*sc, "Indexes", &element);
     const Element& Indexes = GetRequiredElement(*sc, "Indexes", &element);