Explorar o código

Fixed some potential skeletal animation bugs

Ivan Safrin %!s(int64=11) %!d(string=hai) anos
pai
achega
98be7cb3be

+ 1 - 1
Core/Contents/Include/PolySkeleton.h

@@ -219,7 +219,7 @@ namespace Polycode {
 			* Returns a bone at the specified index.
 			* Returns a bone at the specified index.
 			* @param index Bone index.
 			* @param index Bone index.
 			*/
 			*/
-			Bone *getBone(int index) const;
+			Bone *getBone(unsigned int index) const;
 		
 		
 		
 		
 		protected:
 		protected:

+ 9 - 8
Core/Contents/Source/PolySceneMesh.cpp

@@ -272,16 +272,17 @@ void SceneMesh::renderMeshLocally() {
                 if(boneWeight > 0.0) {
                 if(boneWeight > 0.0) {
                     
                     
                     Bone *bone = skeleton->getBone(mesh->vertexBoneIndexArray.data[(i*4)+b]);
                     Bone *bone = skeleton->getBone(mesh->vertexBoneIndexArray.data[(i*4)+b]);
+                    if(bone) {
+                        Vector3 restVert(mesh->vertexPositionArray.data[i*3], mesh->vertexPositionArray.data[(i*3)+1], mesh->vertexPositionArray.data[(i*3)+2]);
                         
                         
-                    Vector3 restVert(mesh->vertexPositionArray.data[i*3], mesh->vertexPositionArray.data[(i*3)+1], mesh->vertexPositionArray.data[(i*3)+2]);
-                    
-                    tPos += bone->finalMatrix * restVert * (boneWeight);
+                        tPos += bone->finalMatrix * restVert * (boneWeight);
+                            
+                        Vector3 nvec(mesh->vertexNormalArray.data[i*3], mesh->vertexNormalArray.data[(i*3)+1], mesh->vertexNormalArray.data[(i*3)+2]);
                         
                         
-                    Vector3 nvec(mesh->vertexNormalArray.data[i*3], mesh->vertexNormalArray.data[(i*3)+1], mesh->vertexNormalArray.data[(i*3)+2]);
-                    
-                    nvec = bone->finalMatrix.rotateVector(nvec);
-                    
-                    norm += nvec * (boneWeight);
+                        nvec = bone->finalMatrix.rotateVector(nvec);
+                        
+                        norm += nvec * (boneWeight);
+                    }
                 }
                 }
             }
             }
 
 

+ 4 - 1
Core/Contents/Source/PolySkeleton.cpp

@@ -59,7 +59,10 @@ Bone *Skeleton::getBoneByName(const String& name) const {
 	return NULL;
 	return NULL;
 }
 }
 
 
-Bone *Skeleton::getBone(int index) const {
+Bone *Skeleton::getBone(unsigned int index) const {
+    if(index >= bones.size()) {
+        return NULL;
+    }
 	return bones[index];
 	return bones[index];
 }
 }