modular-avatar/UnitTests~/RetargetMeshesTest.cs
kaikoga 3667dc319a
chore: Wrap VRC dependencies and VRCAvatarDescriptors (#504)
* add version defines

* refactor: prefer BuildContext.ctor() overload taking GameObject

* wrap unit tests entirely with MA_VRCSDK3_AVATARS

* wrap unit tests smart with MA_VRCSDK3_AVATARS

* wrap runtime entirely with MA_VRCSDK3_AVATARS

* wrap VRC.SDKBase.IEditorOnly with MA_VRCSDK3_AVATARS

* wrap editor entirely with MA_VRCSDK3_AVATARS

* fix AvatarObjectReference.Get(Component)

* wrap editor smart with MA_VRCSDK3_AVATARS

* wrap BuildContext smart with MA_VRCSDK3_AVATARS

* wrap PluginDefinition smart with MA_VRCSDK3_AVATARS

* style: move conditional compiles one step outside
2023-11-10 15:37:56 +09:00

63 lines
2.4 KiB
C#

using nadena.dev.modular_avatar.animation;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEngine;
namespace modular_avatar_tests
{
public class RetargetMeshesTest : TestBase
{
// Real world case of this test case is with skinned mesh without bones or skinned mesh renderer with null mesh.
[Test]
public void RootBoneOnly()
{
var root = CreateRoot("root");
var a = CreateChild(root, "a");
var b = CreateChild(a, "b");
var skinnedMeshRenderer = root.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.sharedMesh = new Mesh();
skinnedMeshRenderer.rootBone = b.transform;
Debug.Assert(skinnedMeshRenderer.bones.Length == 0);
var build_context = new nadena.dev.ndmf.BuildContext(root, null);
var torc = new AnimationServicesContext();
torc.OnActivate(build_context);
var bonedb = new BoneDatabase();
bonedb.AddMergedBone(b.transform);
new RetargetMeshes().OnPreprocessAvatar(root, bonedb, torc.PathMappings);
Assert.AreEqual(a.transform, skinnedMeshRenderer.rootBone);
}
[Test]
public void NoMeshRootBoneOnly()
{
var root = CreateRoot("root");
var a = CreateChild(root, "a");
var b = CreateChild(a, "b");
b.transform.localScale = new Vector3(2, 2, 2);
var skinnedMeshRenderer = root.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.sharedMesh = null;
skinnedMeshRenderer.localBounds = new Bounds(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
skinnedMeshRenderer.rootBone = b.transform;
Debug.Assert(skinnedMeshRenderer.bones.Length == 0);
var build_context = new nadena.dev.ndmf.BuildContext(root, null);
var torc = new AnimationServicesContext();
torc.OnActivate(build_context);
var bonedb = new BoneDatabase();
bonedb.AddMergedBone(b.transform);
new RetargetMeshes().OnPreprocessAvatar(root, bonedb, torc.PathMappings);
Assert.AreEqual(a.transform, skinnedMeshRenderer.rootBone);
Assert.AreEqual(new Bounds(new Vector3(0, 0, 0), new Vector3(2, 2, 2)),
skinnedMeshRenderer.localBounds);
}
}
}