Skip to content

Commit

Permalink
test: add test for sname name blendShape
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Dec 22, 2024
1 parent a3ce0a4 commit 52a5ee6
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Test~/MeshInfo2/MeshInfo2Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,59 @@ public void ComputeActualPositionWithBones()
Assert.That(position, Is.EqualTo(vertex.Position));
}
}

// test with binary-edited fbx which is originally exported from blender
[Test]
public void MultipleSameNameBlendShapeBlenderBinaryEdited()
{
var fbx = TestUtils.GetAssetAt<GameObject>("MeshInfo2/same-name-blendshape-blender-binary-edited.fbx");
var renderer = fbx.GetComponent<SkinnedMeshRenderer>();
var mesh = renderer.sharedMesh;

// check the mesh has same name blendShape
Assert.That(mesh.blendShapeCount, Is.EqualTo(2));
Assert.That(mesh.GetBlendShapeName(0), Is.EqualTo("BlendShape1"));
Assert.That(mesh.GetBlendShapeName(1), Is.EqualTo("BlendShape1"));

using var meshInfo2 = new MeshInfo2(renderer);
// we've checked no exception is thrown

// second shape is renamed
Assert.That(meshInfo2.BlendShapes[0].name, Is.EqualTo("BlendShape1"));
Assert.That(meshInfo2.BlendShapes[1].name, Does.StartWith("BlendShape1-nameConflict-"));
// and there is buffer for each vertex
foreach (var vertex in meshInfo2.Vertices)
{
Assert.That(vertex.BlendShapeBuffer.Shapes[meshInfo2.BlendShapes[0].name], Is.Not.Null);
Assert.That(vertex.BlendShapeBuffer.Shapes[meshInfo2.BlendShapes[1].name], Is.Not.Null);
}
}

// test with real fbx
[Test]
public void MultipleSameNameBlendShape3dsMax()
{
var fbx = TestUtils.GetAssetAt<GameObject>("MeshInfo2/same-name-blendshape-3ds-max.fbx");
var renderer = fbx.transform.Find("Box001").GetComponent<SkinnedMeshRenderer>();
var mesh = renderer.sharedMesh;

// check the mesh has same name blendShape
Assert.That(mesh.blendShapeCount, Is.EqualTo(2));
Assert.That(mesh.GetBlendShapeName(0), Is.EqualTo("Shape"));
Assert.That(mesh.GetBlendShapeName(1), Is.EqualTo("Shape"));

using var meshInfo2 = new MeshInfo2(renderer);
// we've checked no exception is thrown

// second shape is renamed
Assert.That(meshInfo2.BlendShapes[0].name, Is.EqualTo("Shape"));
Assert.That(meshInfo2.BlendShapes[1].name, Does.StartWith("Shape-nameConflict-"));
// and there is buffer for each vertex
foreach (var vertex in meshInfo2.Vertices)
{
Assert.That(vertex.BlendShapeBuffer.Shapes[meshInfo2.BlendShapes[0].name], Is.Not.Null);
Assert.That(vertex.BlendShapeBuffer.Shapes[meshInfo2.BlendShapes[1].name], Is.Not.Null);
}
}
}
}
Binary file added Test~/MeshInfo2/same-name-blendshape-3ds-max.fbx
Binary file not shown.
109 changes: 109 additions & 0 deletions Test~/MeshInfo2/same-name-blendshape-3ds-max.fbx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
109 changes: 109 additions & 0 deletions Test~/MeshInfo2/same-name-blendshape-blender-binary-edited.fbx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52a5ee6

Please sign in to comment.