Skip to content

Commit 6506aa7

Browse files
committed
add bind pose and bone weight comparison
1 parent 803603b commit 6506aa7

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private void CompareCameraValues(Camera camera, Camera fbxCamera, float delta=0.
380380

381381
[Test]
382382
public void TestSkinnedMeshExport(){
383-
var fbxPath = "Cowboy/3D assets/Cowboy/cowboyMidPoly(riged).fbx";
383+
var fbxPath = "Cowboy/3D assets/Cowboy/cowboyMidPoly(riged).fbx";//"DefaultMale.fbx";
384384

385385
// add fbx to scene
386386
GameObject originalFbxObj = AssetDatabase.LoadMainAssetAtPath("Assets/" + fbxPath) as GameObject;
@@ -421,6 +421,7 @@ public void TestSkinnedMeshExport(){
421421
var exportedBone = exportedBones [i];
422422

423423
Assert.AreEqual (originalBone.name, exportedBone.name);
424+
Assert.AreEqual (originalBone.parent, exportedBone.parent);
424425

425426
Debug.Log ("bone name: " + originalBone.name);
426427

@@ -429,6 +430,73 @@ public void TestSkinnedMeshExport(){
429430
Assert.AreEqual (originalBone.localRotation, exportedBone.localRotation);
430431
Assert.AreEqual (originalBone.localScale, exportedBone.localScale);*/
431432
}
433+
434+
// compare bind poses
435+
var origMesh = originalSkinnedMesh.sharedMesh;
436+
Assert.IsNotNull (origMesh);
437+
var exportedMesh = exportedSkinnedMesh.sharedMesh;
438+
Assert.IsNotNull (exportedMesh);
439+
440+
var origBindposes = origMesh.bindposes;
441+
Assert.IsNotNull (origBindposes);
442+
var exportedBindposes = exportedMesh.bindposes;
443+
Assert.IsNotNull (exportedBindposes);
444+
445+
Assert.AreEqual(origBindposes.Length, exportedBindposes.Length);
446+
447+
for (int i = 0; i < origBindposes.Length; i++) {
448+
var origBp = origBindposes [i];
449+
var expBp = exportedBindposes [i];
450+
451+
452+
Debug.Log ("bind pose bone: " + originalBones [i].name);
453+
454+
Vector3 origPos = origBp.GetColumn(3);
455+
var origQ = Quaternion.LookRotation(
456+
origBp.GetColumn(2),
457+
origBp.GetColumn(1)
458+
);
459+
Vector3 origS = new Vector3(
460+
origBp.GetColumn(0).magnitude,
461+
origBp.GetColumn(1).magnitude,
462+
origBp.GetColumn(2).magnitude
463+
);
464+
465+
Vector3 expPos = expBp.GetColumn(3);
466+
var expQ = Quaternion.LookRotation(
467+
expBp.GetColumn(2),
468+
expBp.GetColumn(1)
469+
);
470+
Vector3 expS = new Vector3(
471+
expBp.GetColumn(0).magnitude,
472+
expBp.GetColumn(1).magnitude,
473+
expBp.GetColumn(2).magnitude
474+
);
475+
476+
Debug.Log ("original TRS: " + origPos + ", " + origQ.eulerAngles + ", " + origS);
477+
Debug.Log ("exported TRS: " + expPos + ", " + expQ.eulerAngles + ", " + expS);
478+
479+
for (int j = 0; j < 4; j++) {
480+
for (int k = 0; k < 4; k++) {
481+
Assert.AreEqual (origBp.GetColumn (j)[k], expBp.GetColumn (j)[k], 0.001);
482+
}
483+
}
484+
}
485+
486+
// compare bone weights
487+
var origWeights = origMesh.boneWeights;
488+
Assert.IsNotNull (origWeights);
489+
var expWeights = exportedMesh.boneWeights;
490+
Assert.IsNotNull (expWeights);
491+
492+
Debug.Log ("orig mesh vertices: " + origMesh.vertexCount);
493+
Debug.Log ("exp mesh vertices: " + exportedMesh.vertexCount);
494+
495+
//Assert.AreEqual (origWeights.Length, expWeights.Length);
496+
497+
/*for (int i = 0, n = Mathf.Min(origWeights.Length, expWeights.Length); i < n; i++) {
498+
Assert.AreEqual (origWeights [i], expWeights [i]);
499+
}*/
432500
}
433501
}
434502
}

0 commit comments

Comments
 (0)