This commit is contained in:
Perfare 2018-10-23 01:18:19 +08:00
parent 2c58fae804
commit 22b2d472bc
3 changed files with 36 additions and 35 deletions

View File

@ -382,23 +382,13 @@ namespace AssetStudio
iMesh.SubmeshList.Add(iSubmesh);
}
if (meshR is SkinnedMeshRenderer sMesh)
{
//Bone
iMesh.BoneList = new List<ImportedBone>(sMesh.m_Bones.Length);
for (int i = 0; i < sMesh.m_Bones.Length; i++)
iMesh.BoneList = new List<ImportedBone>();
if (mesh.m_BindPose?.Length > 0 && mesh.m_BoneNameHashes?.Length > 0 && mesh.m_BindPose.Length == mesh.m_BoneNameHashes.Length)
{
for (int i = 0; i < mesh.m_BindPose.Length; i++)
{
var bone = new ImportedBone();
if (sMesh.m_Bones[i].TryGetTransform(out var m_Transform))
{
if (m_Transform.m_GameObject.TryGetGameObject(out var m_GameObject))
{
bone.Name = m_GameObject.m_Name;
}
}
//No first use m_BoneNameHashes, because it may be wrong
if (string.IsNullOrEmpty(bone.Name))
{
var boneHash = mesh.m_BoneNameHashes[i];
bone.Name = GetNameFromBonePathHashes(boneHash);
if (string.IsNullOrEmpty(bone.Name))
@ -410,7 +400,6 @@ namespace AssetStudio
//throw new Exception("A Bone could neither be found by hash in Avatar nor by index in SkinnedMeshRenderer.");
continue;
}
}
var om = new float[4, 4];
var m = mesh.m_BindPose[i];
om[0, 0] = m[0, 0];
@ -432,14 +421,25 @@ namespace AssetStudio
bone.Matrix = om;
iMesh.BoneList.Add(bone);
}
}
//hierarchy has been optimized
if (sMesh.m_Bones.Length == 0 && mesh.m_BindPose?.Length > 0 && mesh.m_BoneNameHashes?.Length > 0)
if (meshR is SkinnedMeshRenderer sMesh)
{
//TODO Repeat code with above
for (int i = 0; i < mesh.m_BindPose.Length; i++)
//Bone for 4.3 down and other
if (iMesh.BoneList.Count == 0)
{
for (int i = 0; i < sMesh.m_Bones.Length; i++)
{
var bone = new ImportedBone();
if (sMesh.m_Bones[i].TryGetTransform(out var m_Transform))
{
if (m_Transform.m_GameObject.TryGetGameObject(out var m_GameObject))
{
bone.Name = m_GameObject.m_Name;
}
}
if (string.IsNullOrEmpty(bone.Name))
{
var boneHash = mesh.m_BoneNameHashes[i];
bone.Name = GetNameFromBonePathHashes(boneHash);
if (string.IsNullOrEmpty(bone.Name))
@ -451,6 +451,7 @@ namespace AssetStudio
//throw new Exception("A Bone could neither be found by hash in Avatar nor by index in SkinnedMeshRenderer.");
continue;
}
}
var om = new float[4, 4];
var m = mesh.m_BindPose[i];
om[0, 0] = m[0, 0];

View File

@ -659,6 +659,7 @@ namespace AssetStudio
StatusStripUpdate($"Finished exporting {filename}.fbx");
}
}
StatusStripUpdate("Finished");
});
}

View File

@ -574,6 +574,7 @@ namespace AssetStudio
if (hasBones)
{
FbxSkin* pSkin = FbxSkin::Create(pScene, "");
FbxAMatrix lMeshMatrix = pMeshNode->EvaluateGlobalTransform();
for (int j = 0; j < boneList->Count; j++)
{
FbxCluster* pCluster = pClusterArray->GetAt(j);
@ -589,8 +590,6 @@ namespace AssetStudio
}
}
FbxAMatrix lMeshMatrix = pMeshNode->EvaluateGlobalTransform();
pCluster->SetTransformMatrix(lMeshMatrix);
pCluster->SetTransformLinkMatrix(lMeshMatrix * lBoneMatrix.Inverse());