Skip to content

Commit 9308a6c

Browse files
authored
Merge pull request #268 from Unity-Technologies/UNI-32754-skinned-mesh-export
Uni 32754 skinned mesh export
2 parents a1bca2a + 0bf5e55 commit 9308a6c

29 files changed

+2512
-50
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 412 additions & 43 deletions
Large diffs are not rendered by default.

Assets/FbxExporters/Editor/UnitTests/FbxAnimationTest.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@ namespace FbxExporters.UnitTests
1212

1313
public class AnimationTestDataClass
1414
{
15-
public static IEnumerable<string> m_transformPropertyNames { get {
16-
var goAnim = new GameObject ();
17-
return (from b in AnimationUtility.GetAnimatableBindings (goAnim, goAnim) select b.propertyName);
18-
}}
19-
2015
// TODO: remove items that become supported by exporter
2116
public static IEnumerable<System.Type> m_exceptionTypes = new List<System.Type> ()
2217
{
2318
typeof(MeshFilter),
2419
typeof(SkinnedMeshRenderer),
25-
typeof(Camera),
20+
typeof(Camera), // TODO: uncomment this to add unit tests
2621
typeof(Transform), // NOTE: has it's own special tests
2722
};
2823

@@ -325,7 +320,7 @@ public int ComponentSingleAnimTest (System.Type componentType)
325320

326321
string [] propertyNames =
327322
(from b in AnimationUtility.GetAnimatableBindings (targetObject, targetObject)
328-
select b.propertyName).Except(AnimationTestDataClass.m_transformPropertyNames).ToArray();
323+
where b.type==componentType select b.propertyName).ToArray();
329324

330325
if (propertyNames.Length == 0)
331326
{

Assets/FbxExporters/Editor/UnitTests/FbxLightTest.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/UnitTests/ModelExporterTest.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,5 +506,93 @@ private void CompareMeshComponentAttributes(Mesh mesh, Mesh fbxMesh)
506506
Assert.AreEqual (mesh.colors, fbxMesh.colors);
507507
Assert.AreEqual (mesh.tangents, fbxMesh.tangents);
508508
}
509+
510+
[Test]
511+
public void TestSkinnedMeshExport(){
512+
// for now use this cowboy taken from the asset store as the test file
513+
// TODO: find a better/simpler test file
514+
var fbxPath = "FbxExporters/Editor/UnitTests/Models/Cowboy/cowboyMidPoly(riged).fbx";
515+
516+
// add fbx to scene
517+
GameObject originalFbxObj = AssetDatabase.LoadMainAssetAtPath("Assets/" + fbxPath) as GameObject;
518+
Assert.IsNotNull (originalFbxObj);
519+
GameObject originalGO = GameObject.Instantiate (originalFbxObj);
520+
Assert.IsTrue (originalGO);
521+
522+
// export fbx
523+
// get GameObject
524+
string filename = GetRandomFbxFilePath();
525+
ModelExporter.ExportObject (filename, originalGO);
526+
GameObject fbxObj = AssetDatabase.LoadMainAssetAtPath(filename) as GameObject;
527+
Assert.IsTrue (fbxObj);
528+
529+
var originalSkinnedMesh = originalGO.GetComponentInChildren<SkinnedMeshRenderer> ();
530+
Assert.IsNotNull (originalSkinnedMesh);
531+
532+
var exportedSkinnedMesh = fbxObj.GetComponentInChildren<SkinnedMeshRenderer> ();
533+
Assert.IsNotNull (exportedSkinnedMesh);
534+
535+
Assert.IsTrue (originalSkinnedMesh.name == exportedSkinnedMesh.name ||
536+
(originalSkinnedMesh.transform.parent == null && exportedSkinnedMesh.transform.parent == null));
537+
538+
// check if skeletons match
539+
// compare bones
540+
var originalBones = originalSkinnedMesh.bones;
541+
var exportedBones = exportedSkinnedMesh.bones;
542+
543+
Assert.IsNotNull (originalBones);
544+
Assert.IsNotNull (exportedBones);
545+
546+
Assert.AreEqual (originalBones.Length, exportedBones.Length);
547+
548+
for(int i = 0; i < originalBones.Length; i++){
549+
var originalBone = originalBones [i];
550+
var exportedBone = exportedBones [i];
551+
552+
Assert.AreEqual (originalBone.name, exportedBone.name);
553+
Assert.AreEqual (originalBone.parent, exportedBone.parent);
554+
555+
// NOTE: not comparing transforms as the exported transforms are taken from
556+
// the bind pose whereas the originals are not necessarily.
557+
}
558+
559+
// compare bind poses
560+
var origMesh = originalSkinnedMesh.sharedMesh;
561+
Assert.IsNotNull (origMesh);
562+
var exportedMesh = exportedSkinnedMesh.sharedMesh;
563+
Assert.IsNotNull (exportedMesh);
564+
565+
var origBindposes = origMesh.bindposes;
566+
Assert.IsNotNull (origBindposes);
567+
var exportedBindposes = exportedMesh.bindposes;
568+
Assert.IsNotNull (exportedBindposes);
569+
570+
Assert.AreEqual(origBindposes.Length, exportedBindposes.Length);
571+
572+
for (int i = 0; i < origBindposes.Length; i++) {
573+
var origBp = origBindposes [i];
574+
var expBp = exportedBindposes [i];
575+
576+
// TODO: (UNI-34293) fix so bones with negative scale export with correct bind pose
577+
if (originalBones [i].name == "EyeL") {
578+
continue;
579+
}
580+
581+
for (int j = 0; j < 4; j++) {
582+
for (int k = 0; k < 4; k++) {
583+
Assert.That (origBp.GetColumn (j)[k], Is.EqualTo(expBp.GetColumn (j)[k]).Within(0.001f), string.Format("bind pose doesn't match {0},{1}", j, k));
584+
}
585+
}
586+
}
587+
588+
// TODO: find a way to compare bone weights.
589+
// The boneweights are by vertex, and duplicate vertices
590+
// are removed on export so the lists are not necessarily
591+
// the same length or order.
592+
var origWeights = origMesh.boneWeights;
593+
Assert.IsNotNull (origWeights);
594+
var expWeights = exportedMesh.boneWeights;
595+
Assert.IsNotNull (expWeights);
596+
}
509597
}
510598
}

Assets/FbxExporters/Editor/UnitTests/Models.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/FbxExporters/Editor/UnitTests/Models/Cowboy.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
169 KB
Loading

Assets/FbxExporters/Editor/UnitTests/Models/Cowboy/BodyMGO.png.meta

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
3.62 KB
Loading

Assets/FbxExporters/Editor/UnitTests/Models/Cowboy/HeadMGO.png.meta

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)