Bladeren bron

Merge pull request #988 from dgough/next

Updated the encoder to always write material names in the GPB file
Sean Paul Taylor 12 jaren geleden
bovenliggende
commit
f0df308bb4

+ 34 - 28
tools/encoder/src/FBXSceneEncoder.cpp

@@ -1,5 +1,3 @@
-#ifdef USE_FBX
-
 #include <algorithm>
 #include <string>
 #include <sstream>
@@ -14,6 +12,9 @@ using std::vector;
 using std::map;
 using std::ostringstream;
 
+// Fix bad material names
+static void fixMaterialName(string& name);
+
 FBXSceneEncoder::FBXSceneEncoder()
     : _groupAnimation(NULL), _autoGroupAnimations(false)
 {
@@ -60,11 +61,8 @@ void FBXSceneEncoder::write(const string& filepath, const EncoderArguments& argu
 
     print("Loading Scene.");
     loadScene(fbxScene);
-    if (arguments.outputMaterialEnabled())
-    {
-        print("Load materials");
-        loadMaterials(fbxScene);
-    }
+    print("Load materials");
+    loadMaterials(fbxScene);
     print("Loading animations.");
     loadAnimations(fbxScene, arguments);
     sdkManager->Destroy();
@@ -913,25 +911,6 @@ void FBXSceneEncoder::loadMaterials(FbxScene* fbxScene)
     }
 }
 
-// Fix bad material names
-void fixMaterialName(string& name)
-{
-    static int unnamedCount = 0;
-
-    for (string::size_type i = 0, len = name.length(); i < len; ++i)
-    {
-        if (!isalnum(name[i]))
-            name[i] = '_';
-    }
-
-    if (name.length() == 0)
-    {
-        ostringstream stream;
-        stream << "unnamed_" << (++unnamedCount);
-        name = stream.str();
-    }
-}
-
 void FBXSceneEncoder::loadMaterial(FbxNode* fbxNode)
 {
     Node* node = findNode(fbxNode);
@@ -952,7 +931,16 @@ void FBXSceneEncoder::loadMaterial(FbxNode* fbxNode)
         }
         else
         {
-            material = createMaterial(materialName, fbxMaterial, node);
+            if (EncoderArguments::getInstance()->outputMaterialEnabled())
+            {
+                material = createMaterial(materialName, fbxMaterial, node);
+            }
+            else
+            {
+                // If outputMaterialEnabled() is not enabled then only create the materials for the purpose of writing 
+                // the material name in the GPB file. There is no need to load uniforms and samplers for the material.
+                material = new Material(materialName);
+            }
             _materials[materialName] = material;
         }
 
@@ -1381,4 +1369,22 @@ void FBXSceneEncoder::triangulateRecursive(FbxNode* fbxNode)
     }
 }
 
-#endif
+// Functions
+
+void fixMaterialName(string& name)
+{
+    static int unnamedCount = 0;
+
+    for (string::size_type i = 0, len = name.length(); i < len; ++i)
+    {
+        if (!isalnum(name[i]))
+            name[i] = '_';
+    }
+
+    if (name.length() == 0)
+    {
+        ostringstream stream;
+        stream << "unnamed_" << (++unnamedCount);
+        name = stream.str();
+    }
+}

+ 0 - 3
tools/encoder/src/FBXSceneEncoder.h

@@ -1,8 +1,6 @@
 #ifndef FBXSCENEEENCODER_H_
 #define FBXSCENEEENCODER_H_
 
-#ifdef USE_FBX
-
 #define FBXSDK_NEW_API
 
 #include <iostream>
@@ -295,4 +293,3 @@ private:
 };
 
 #endif
-#endif

+ 0 - 4
tools/encoder/src/FBXUtil.cpp

@@ -1,5 +1,3 @@
-#ifdef USE_FBX
-
 #include <algorithm>
 #include <string>
 #include <sstream>
@@ -805,5 +803,3 @@ std::string toString(double value)
     stream << value;
     return stream.str();
 }
-
-#endif

+ 0 - 3
tools/encoder/src/FBXUtil.h

@@ -1,8 +1,6 @@
 #ifndef FBXUTIL_H_
 #define FBXUTIL_H_
 
-#ifdef USE_FBX
-
 #define FBXSDK_NEW_API
 
 #include <iostream>
@@ -203,4 +201,3 @@ std::string toString(const FbxDouble3& fbxDouble, double d);
 std::string toString(double value);
 
 #endif
-#endif

+ 0 - 5
tools/encoder/src/main.cpp

@@ -72,15 +72,10 @@ int main(int argc, const char** argv)
         }
     case EncoderArguments::FILEFORMAT_FBX:
         {
-#ifdef USE_FBX
             std::string realpath(arguments.getFilePath());
             FBXSceneEncoder fbxEncoder;
             fbxEncoder.write(realpath, arguments);
             break;
-#else
-            LOG(1, "Error: FBX not enabled. Install the FBX SDK and use the preprocessor definition USE_FBX.\n");
-            return -1;
-#endif
         }
     case EncoderArguments::FILEFORMAT_TTF:
         {