Skip to content

Commit

Permalink
test: add test for multi frame BlendShape with partially identity frames
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Nov 3, 2023
1 parent e4a61f6 commit 75397bd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
74 changes: 74 additions & 0 deletions Test~/MeshInfo2/MeshInfo2Test.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Anatawa12.AvatarOptimizer.Processors.SkinnedMeshes;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Rendering;

namespace Anatawa12.AvatarOptimizer.Test
{
Expand Down Expand Up @@ -95,5 +97,77 @@ public void RootBoneWithNoneMeshSkinnedMeshRenderer()
var meshInfo2 = new MeshInfo2(smr);
Assert.That(meshInfo2.RootBone, Is.EqualTo(secondGo.transform));
}

[Test]
public void MultiFrameBlendShapeWithPartiallyIdentity()
{
var mesh = BoxMesh();
var deltas = new Vector3[8];
deltas.AsSpan().Fill(new Vector3(1, 2, 3));
mesh.AddBlendShapeFrame("shape", 0, new Vector3[8], null, null);
mesh.AddBlendShapeFrame("shape", 1, new Vector3[8], null, null);
mesh.AddBlendShapeFrame("shape", 2, new Vector3[8], null, null);
mesh.AddBlendShapeFrame("shape", 3, deltas, null, null);
mesh.AddBlendShapeFrame("shape", 4, new Vector3[8], null, null);

var go = new GameObject();
var smr = go.AddComponent<SkinnedMeshRenderer>();
smr.sharedMesh = mesh;

var meshInfo2 = new MeshInfo2(smr);

foreach (var vertex in meshInfo2.Vertices)
{
var frames = vertex.BlendShapes["shape"];
Assert.That(frames.Length, Is.EqualTo(5));
for (var i = 0; i < frames.Length; i++)
{
Assert.That(frames[i].Weight, Is.EqualTo((float)i));
Assert.That(frames[i].Position, Is.EqualTo(i == 3 ? new Vector3(1, 2, 3) : new Vector3()));
}
}
}

private Mesh BoxMesh()
{
var mesh = new Mesh
{
vertices = new[]
{
new Vector3(-1, -1, -1),
new Vector3(+1, -1, -1),
new Vector3(-1, +1, -1),
new Vector3(+1, +1, -1),
new Vector3(-1, -1, +1),
new Vector3(+1, -1, +1),
new Vector3(-1, +1, +1),
new Vector3(+1, +1, +1),
},
triangles = new[]
{
0, 1, 2,
1, 3, 2,

4, 6, 5,
5, 6, 7,

0, 4, 1,

1, 4, 5,
1, 5, 3,

3, 5, 7,
3, 7, 2,

2, 7, 6,
2, 6, 0,
},
};

mesh.subMeshCount = 1;
mesh.SetSubMesh(0, new SubMeshDescriptor(0, mesh.triangles.Length));

return mesh;
}
}
}
3 changes: 2 additions & 1 deletion Test~/com.anatawa12.avatar-optimizer.test.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"VRC.SDK3.Dynamics.PhysBone.dll",
"VRC.Dynamics.dll",
"VRCSDK3A.dll",
"VRCSDKBase.dll"
"VRCSDKBase.dll",
"System.Memory.dll"
],
"autoReferenced": false,
"defineConstraints": [],
Expand Down

0 comments on commit 75397bd

Please sign in to comment.