Procházet zdrojové kódy

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 před 9 roky
rodič
revize
5045160821

+ 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);
 
 		/**	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. */
-		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. */
 		void importAnimations(FbxScene* scene, FBXImportOptions& importOptions, FBXImportScene& importScene);

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

@@ -213,7 +213,7 @@ namespace BansheeEngine
 			importBlendShapes(importedScene, fbxImportOptions);
 
 		if (fbxImportOptions.importSkin)
-			importSkin(importedScene);
+			importSkin(importedScene, fbxImportOptions);
 
 		if (fbxImportOptions.importAnimation)
 			importAnimations(fbxScene, fbxImportOptions, importedScene);
@@ -468,10 +468,10 @@ namespace BansheeEngine
 					Vector <TKeyframe<Quaternion>> keyFrames(numKeyframes);
 					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);
 
@@ -1268,7 +1268,7 @@ namespace BansheeEngine
 		}
 	}
 
-	void FBXImporter::importSkin(FBXImportScene& scene)
+	void FBXImporter::importSkin(FBXImportScene& scene, const FBXImportOptions& options)
 	{
 		for (auto& mesh : scene.meshes)
 		{
@@ -1292,16 +1292,17 @@ namespace BansheeEngine
 						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;
 		influences.resize(mesh.positions.size());
 
+		Matrix4 importScale = Matrix4::scaling(options.importScale);
 		UnorderedSet<FbxNode*> existingBones;
 		UINT32 boneCount = (UINT32)skin->GetClusterCount();
 		for (UINT32 i = 0; i < boneCount; i++)
@@ -1327,6 +1328,7 @@ namespace BansheeEngine
 
 			FbxAMatrix bindPose = linkTransform.Inverse() * clusterTransform;
 			bone.bindPose = FBXToNativeType(bindPose);
+			bone.bindPose = (bone.node->worldTransform * importScale) * bone.bindPose;
 
 			bool isDuplicate = !existingBones.insert(link).second;
 			bool isAdditive = cluster->GetLinkMode() == FbxCluster::eAdditive;