Skip to content

Commit

Permalink
fix avatar root detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikoga committed May 12, 2024
1 parent 0e07d32 commit 1deebe4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
23 changes: 17 additions & 6 deletions Runtime/RuntimeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
#if NDMF_VRCSDK3_AVATARS
using VRC.SDK3.Avatars.Components;
#endif
#if NDMF_VRM0
using VRM;
#endif
#if NDMF_VRM1
using UniVRM10;
#endif

namespace nadena.dev.ndmf.runtime
{
Expand Down Expand Up @@ -95,8 +101,17 @@ public static string AvatarRootPath(GameObject child)
public static bool IsAvatarRoot(Transform target)
{
#if NDMF_VRCSDK3_AVATARS
return target.GetComponent<VRCAvatarDescriptor>();
#else
if (target.GetComponent<VRCAvatarDescriptor>()) return true;
#endif
#if NDMF_VRM0
if (target.GetComponent<VRMMeta>()) return true;
#endif
#if NDMF_VRM1
if (target.GetComponent<Vrm10Instance>()) return true;
#endif
#if NDMF_VRCSDK3_AVATARS || NDMF_VRM0 || NDMF_VRM1
return false;
#else
var an = target.GetComponent<Animator>();
if (!an) return false;
var parent = target.transform.parent;
Expand Down Expand Up @@ -173,11 +188,7 @@ internal static IEnumerable<Transform> FindAvatarsInScene(Scene scene)
{
foreach (var root in scene.GetRootGameObjects())
{
#if NDMF_VRCSDK3_AVATARS
foreach (var avatar in root.GetComponentsInChildren<VRCAvatarDescriptor>())
#else
foreach (var avatar in root.GetComponentsInChildren<Animator>())
#endif
{
if (IsAvatarRoot(avatar.transform)) yield return avatar.transform;
}
Expand Down
33 changes: 30 additions & 3 deletions UnitTests~/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
using VRC.SDK3.Avatars.Components;
#endif

#if NDMF_VRM0
using VRM;
#endif

#if NDMF_VRM1
using UniVRM10;
using UniHumanoid;
#endif

namespace UnitTests
{
public class TestBase
Expand Down Expand Up @@ -58,16 +67,34 @@ protected BuildContext CreateContext(GameObject root)
return new BuildContext(root, TEMP_ASSET_PATH); // TODO - cleanup
}

protected GameObject CreateRoot(string name)
protected GameObject CreateRoot(string name) => CreatePlatformRoot(name, isVRC: true, isVRM0: true, isVRM1: true);

protected GameObject CreatePlatformRoot(string name, bool isVRC, bool isVRM0, bool isVRM1)
{
//var path = AssetDatabase.GUIDToAssetPath(MinimalAvatarGuid);
//var go = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>(path));
var go = new GameObject();
go.name = name;
go.AddComponent<Animator>();
#if NDMF_VRCSDK3_AVATARS
go.AddComponent<VRCAvatarDescriptor>();
go.AddComponent<PipelineManager>();
if (isVRC)
{
go.AddComponent<VRCAvatarDescriptor>();
go.AddComponent<PipelineManager>();
}
#endif
#if NDMF_VRM0
if (isVRM0)
{
go.AddComponent<VRMMeta>();
}
#endif
#if NDMF_VRM1
if (isVRM1)
{
go.AddComponent<Vrm10Instance>();
go.AddComponent<Humanoid>();
}
#endif

objects.Add(go);
Expand Down

0 comments on commit 1deebe4

Please sign in to comment.