Преглед на файлове

Properly import rotation animation curves
Apply mesh import scale on the bind pose
Better handle bind pose matrix calculation so it accounts for the parent node

BearishSun преди 9 години
родител
ревизия
5045160821
променени са 2 файла, в които са добавени 12 реда и са изтрити 10 реда
  1. 2 2
      Source/BansheeFBXImporter/Include/BsFBXImporter.h
  2. 10 8
      Source/BansheeFBXImporter/Source/BsFBXImporter.cpp

+ 2 - 2
Source/BansheeFBXImporter/Include/BsFBXImporter.h

@@ -82,10 +82,10 @@ namespace BansheeEngine
 		void importBlendShapeFrame(FbxShape* shape, const FBXImportMesh& mesh, const FBXImportOptions& options, FBXBlendShapeFrame& outFrame);
 		void importBlendShapeFrame(FbxShape* shape, const FBXImportMesh& mesh, const FBXImportOptions& options, FBXBlendShapeFrame& outFrame);
 
 
 		/**	Imports skinning information and bones for all meshes. */
 		/**	Imports skinning information and bones for all meshes. */
-		void importSkin(FBXImportScene& scene);
+		void importSkin(FBXImportScene& scene, const FBXImportOptions& options);
 
 
 		/**	Imports skinning information and bones for the specified mesh. */
 		/**	Imports skinning information and bones for the specified mesh. */
-		void importSkin(FBXImportScene& scene, FbxSkin* skin, FBXImportMesh& mesh);
+		void importSkin(FBXImportScene& scene, FbxSkin* skin, FBXImportMesh& mesh, const FBXImportOptions& options);
 
 
 		/**	Imports all bone and blend shape animations from the FBX. */
 		/**	Imports all bone and blend shape animations from the FBX. */
 		void importAnimations(FbxScene* scene, FBXImportOptions& importOptions, FBXImportScene& importScene);
 		void importAnimations(FbxScene* scene, FBXImportOptions& importOptions, FBXImportScene& importScene);

+ 10 - 8
Source/BansheeFBXImporter/Source/BsFBXImporter.cpp

@@ -213,7 +213,7 @@ namespace BansheeEngine
 			importBlendShapes(importedScene, fbxImportOptions);
 			importBlendShapes(importedScene, fbxImportOptions);
 
 
 		if (fbxImportOptions.importSkin)
 		if (fbxImportOptions.importSkin)
-			importSkin(importedScene);
+			importSkin(importedScene, fbxImportOptions);
 
 
 		if (fbxImportOptions.importAnimation)
 		if (fbxImportOptions.importAnimation)
 			importAnimations(fbxScene, fbxImportOptions, importedScene);
 			importAnimations(fbxScene, fbxImportOptions, importedScene);
@@ -468,10 +468,10 @@ namespace BansheeEngine
 					Vector <TKeyframe<Quaternion>> keyFrames(numKeyframes);
 					Vector <TKeyframe<Quaternion>> keyFrames(numKeyframes);
 					for (UINT32 i = 0; i < numKeyframes; i++)
 					for (UINT32 i = 0; i < numKeyframes; i++)
 					{
 					{
-						const FBXKeyFrame& keyFrameW = bone.rotation[0].keyframes[i];
-						const FBXKeyFrame& keyFrameX = bone.rotation[1].keyframes[i];
-						const FBXKeyFrame& keyFrameY = bone.rotation[2].keyframes[i];
-						const FBXKeyFrame& keyFrameZ = bone.rotation[3].keyframes[i];
+						const FBXKeyFrame& keyFrameX = bone.rotation[0].keyframes[i];
+						const FBXKeyFrame& keyFrameY = bone.rotation[1].keyframes[i];
+						const FBXKeyFrame& keyFrameZ = bone.rotation[2].keyframes[i];
+						const FBXKeyFrame& keyFrameW = bone.rotation[3].keyframes[i];
 
 
 						keyFrames[i].value = Quaternion(keyFrameW.value, keyFrameX.value, keyFrameY.value, keyFrameZ.value);
 						keyFrames[i].value = Quaternion(keyFrameW.value, keyFrameX.value, keyFrameY.value, keyFrameZ.value);
 
 
@@ -1268,7 +1268,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void FBXImporter::importSkin(FBXImportScene& scene)
+	void FBXImporter::importSkin(FBXImportScene& scene, const FBXImportOptions& options)
 	{
 	{
 		for (auto& mesh : scene.meshes)
 		for (auto& mesh : scene.meshes)
 		{
 		{
@@ -1292,16 +1292,17 @@ namespace BansheeEngine
 						continue;
 						continue;
 				}
 				}
 
 
-				importSkin(scene, deformer, *mesh);
+				importSkin(scene, deformer, *mesh, options);
 			}
 			}
 		}
 		}
 	}
 	}
 
 
-	void FBXImporter::importSkin(FBXImportScene& scene, FbxSkin* skin, FBXImportMesh& mesh)
+	void FBXImporter::importSkin(FBXImportScene& scene, FbxSkin* skin, FBXImportMesh& mesh, const FBXImportOptions& options)
 	{
 	{
 		Vector<FBXBoneInfluence>& influences = mesh.boneInfluences;
 		Vector<FBXBoneInfluence>& influences = mesh.boneInfluences;
 		influences.resize(mesh.positions.size());
 		influences.resize(mesh.positions.size());
 
 
+		Matrix4 importScale = Matrix4::scaling(options.importScale);
 		UnorderedSet<FbxNode*> existingBones;
 		UnorderedSet<FbxNode*> existingBones;
 		UINT32 boneCount = (UINT32)skin->GetClusterCount();
 		UINT32 boneCount = (UINT32)skin->GetClusterCount();
 		for (UINT32 i = 0; i < boneCount; i++)
 		for (UINT32 i = 0; i < boneCount; i++)
@@ -1327,6 +1328,7 @@ namespace BansheeEngine
 
 
 			FbxAMatrix bindPose = linkTransform.Inverse() * clusterTransform;
 			FbxAMatrix bindPose = linkTransform.Inverse() * clusterTransform;
 			bone.bindPose = FBXToNativeType(bindPose);
 			bone.bindPose = FBXToNativeType(bindPose);
+			bone.bindPose = (bone.node->worldTransform * importScale) * bone.bindPose;
 
 
 			bool isDuplicate = !existingBones.insert(link).second;
 			bool isDuplicate = !existingBones.insert(link).second;
 			bool isAdditive = cluster->GetLinkMode() == FbxCluster::eAdditive;
 			bool isAdditive = cluster->GetLinkMode() == FbxCluster::eAdditive;