mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
Fixed #272
This commit is contained in:
parent
2c58fae804
commit
22b2d472bc
@ -382,34 +382,23 @@ namespace AssetStudio
|
|||||||
iMesh.SubmeshList.Add(iSubmesh);
|
iMesh.SubmeshList.Add(iSubmesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meshR is SkinnedMeshRenderer sMesh)
|
//Bone
|
||||||
|
iMesh.BoneList = new List<ImportedBone>();
|
||||||
|
if (mesh.m_BindPose?.Length > 0 && mesh.m_BoneNameHashes?.Length > 0 && mesh.m_BindPose.Length == mesh.m_BoneNameHashes.Length)
|
||||||
{
|
{
|
||||||
//Bone
|
for (int i = 0; i < mesh.m_BindPose.Length; i++)
|
||||||
iMesh.BoneList = new List<ImportedBone>(sMesh.m_Bones.Length);
|
|
||||||
for (int i = 0; i < sMesh.m_Bones.Length; i++)
|
|
||||||
{
|
{
|
||||||
var bone = new ImportedBone();
|
var bone = new ImportedBone();
|
||||||
if (sMesh.m_Bones[i].TryGetTransform(out var m_Transform))
|
var boneHash = mesh.m_BoneNameHashes[i];
|
||||||
{
|
bone.Name = GetNameFromBonePathHashes(boneHash);
|
||||||
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))
|
if (string.IsNullOrEmpty(bone.Name))
|
||||||
{
|
{
|
||||||
var boneHash = mesh.m_BoneNameHashes[i];
|
bone.Name = avatar?.FindBoneName(boneHash);
|
||||||
bone.Name = GetNameFromBonePathHashes(boneHash);
|
}
|
||||||
if (string.IsNullOrEmpty(bone.Name))
|
if (string.IsNullOrEmpty(bone.Name))
|
||||||
{
|
{
|
||||||
bone.Name = avatar?.FindBoneName(boneHash);
|
//throw new Exception("A Bone could neither be found by hash in Avatar nor by index in SkinnedMeshRenderer.");
|
||||||
}
|
continue;
|
||||||
if (string.IsNullOrEmpty(bone.Name))
|
|
||||||
{
|
|
||||||
//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 om = new float[4, 4];
|
||||||
var m = mesh.m_BindPose[i];
|
var m = mesh.m_BindPose[i];
|
||||||
@ -432,24 +421,36 @@ namespace AssetStudio
|
|||||||
bone.Matrix = om;
|
bone.Matrix = om;
|
||||||
iMesh.BoneList.Add(bone);
|
iMesh.BoneList.Add(bone);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//hierarchy has been optimized
|
if (meshR is SkinnedMeshRenderer sMesh)
|
||||||
if (sMesh.m_Bones.Length == 0 && mesh.m_BindPose?.Length > 0 && mesh.m_BoneNameHashes?.Length > 0)
|
{
|
||||||
|
//Bone for 4.3 down and other
|
||||||
|
if (iMesh.BoneList.Count == 0)
|
||||||
{
|
{
|
||||||
//TODO Repeat code with above
|
for (int i = 0; i < sMesh.m_Bones.Length; i++)
|
||||||
for (int i = 0; i < mesh.m_BindPose.Length; i++)
|
|
||||||
{
|
{
|
||||||
var bone = new ImportedBone();
|
var bone = new ImportedBone();
|
||||||
var boneHash = mesh.m_BoneNameHashes[i];
|
if (sMesh.m_Bones[i].TryGetTransform(out var m_Transform))
|
||||||
bone.Name = GetNameFromBonePathHashes(boneHash);
|
|
||||||
if (string.IsNullOrEmpty(bone.Name))
|
|
||||||
{
|
{
|
||||||
bone.Name = avatar?.FindBoneName(boneHash);
|
if (m_Transform.m_GameObject.TryGetGameObject(out var m_GameObject))
|
||||||
|
{
|
||||||
|
bone.Name = m_GameObject.m_Name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(bone.Name))
|
if (string.IsNullOrEmpty(bone.Name))
|
||||||
{
|
{
|
||||||
//throw new Exception("A Bone could neither be found by hash in Avatar nor by index in SkinnedMeshRenderer.");
|
var boneHash = mesh.m_BoneNameHashes[i];
|
||||||
continue;
|
bone.Name = GetNameFromBonePathHashes(boneHash);
|
||||||
|
if (string.IsNullOrEmpty(bone.Name))
|
||||||
|
{
|
||||||
|
bone.Name = avatar?.FindBoneName(boneHash);
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(bone.Name))
|
||||||
|
{
|
||||||
|
//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 om = new float[4, 4];
|
||||||
var m = mesh.m_BindPose[i];
|
var m = mesh.m_BindPose[i];
|
||||||
|
@ -659,6 +659,7 @@ namespace AssetStudio
|
|||||||
StatusStripUpdate($"Finished exporting {filename}.fbx");
|
StatusStripUpdate($"Finished exporting {filename}.fbx");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StatusStripUpdate("Finished");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,6 +574,7 @@ namespace AssetStudio
|
|||||||
if (hasBones)
|
if (hasBones)
|
||||||
{
|
{
|
||||||
FbxSkin* pSkin = FbxSkin::Create(pScene, "");
|
FbxSkin* pSkin = FbxSkin::Create(pScene, "");
|
||||||
|
FbxAMatrix lMeshMatrix = pMeshNode->EvaluateGlobalTransform();
|
||||||
for (int j = 0; j < boneList->Count; j++)
|
for (int j = 0; j < boneList->Count; j++)
|
||||||
{
|
{
|
||||||
FbxCluster* pCluster = pClusterArray->GetAt(j);
|
FbxCluster* pCluster = pClusterArray->GetAt(j);
|
||||||
@ -589,8 +590,6 @@ namespace AssetStudio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FbxAMatrix lMeshMatrix = pMeshNode->EvaluateGlobalTransform();
|
|
||||||
|
|
||||||
pCluster->SetTransformMatrix(lMeshMatrix);
|
pCluster->SetTransformMatrix(lMeshMatrix);
|
||||||
pCluster->SetTransformLinkMatrix(lMeshMatrix * lBoneMatrix.Inverse());
|
pCluster->SetTransformLinkMatrix(lMeshMatrix * lBoneMatrix.Inverse());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user