Просмотр исходного кода

Minor fixes.
- Fixes problem in encoder with generation materials that have names with non-alphanumeric characters in them.
- Model::getMaterial(int) now returns NULL instead of asserting if material index is not valid.

Steve Grenier 12 лет назад
Родитель
Сommit
9f5b8fbd24

+ 10 - 7
gameplay/src/Model.cpp

@@ -54,17 +54,20 @@ unsigned int Model::getMeshPartCount() const
 
 Material* Model::getMaterial(int partIndex)
 {
-    GP_ASSERT(partIndex == -1 || (partIndex >= 0 && partIndex < (int)getMeshPartCount()));
+    GP_ASSERT(partIndex == -1 || partIndex >= 0);
 
     Material* m = NULL;
 
-    if (partIndex >= 0 && partIndex < (int)_partCount)
+    if (partIndex < 0)
+        return _material;
+
+    if (partIndex >= (int)_partCount)
+        return NULL;
+
+    // Look up explicitly specified part material.
+    if (_partMaterials)
     {
-        // Look up explicitly specified part material.
-        if (_partMaterials)
-        {
-            m = _partMaterials[partIndex];
-        }
+        m = _partMaterials[partIndex];
     }
 
     if (m == NULL)

+ 2 - 2
gameplay/src/PhysicsVehicleWheel.cpp

@@ -7,7 +7,7 @@ namespace gameplay
 {
 
 PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, const PhysicsCollisionShape::Definition& shape, const PhysicsRigidBody::Parameters& parameters)
-    : PhysicsCollisionObject(node)
+    : PhysicsCollisionObject(node), _rigidBody(NULL), _host(NULL), _indexInHost(0)
 {
     // Note that the constructor for PhysicsRigidBody calls addCollisionObject and so
     // that is where the rigid body gets added to the dynamics world.
@@ -17,7 +17,7 @@ PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, const PhysicsCollisionShape
 }
 
 PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, PhysicsRigidBody* rigidBody)
-    : PhysicsCollisionObject(node)
+    : PhysicsCollisionObject(node), _rigidBody(NULL), _host(NULL), _indexInHost(0)
 {
     _rigidBody = rigidBody;
 

+ 1 - 0
tools/encoder/src/EncoderArguments.cpp

@@ -248,6 +248,7 @@ void EncoderArguments::printUsage() const
     LOG(1, "  -g:none\tDo not prompt to group animations.\n");
     LOG(1, "  -g <node id> <animation id>\n" \
         "\t\tGroup all animation channels targeting the nodes into a new animation.\n");
+    LOG(1, "  -m\t\tOutput material file for scene.\n");
     LOG(1, "  -tb <node id>\n" \
         "\t\tGenerates tangents and binormals for the given node.\n");
     LOG(1, "  -oa\n" \

+ 21 - 1
tools/encoder/src/FBXSceneEncoder.cpp

@@ -913,6 +913,25 @@ 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);
@@ -922,7 +941,8 @@ void FBXSceneEncoder::loadMaterial(FbxNode* fbxNode)
     for (int index = 0; index < materialCount; ++index)
     {
         FbxSurfaceMaterial* fbxMaterial = fbxNode->GetMaterial(index);
-        const string materialName(fbxMaterial->GetName());
+        string materialName(fbxMaterial->GetName());
+        fixMaterialName(materialName);
         Material* material = NULL;
         map<string, Material*>::iterator it = _materials.find(materialName);
         if (it != _materials.end())