Skip to content

Commit

Permalink
vrm spec 更新。InitRotationPoseProvider 修正。ENDSITE 対策
Browse files Browse the repository at this point in the history
  • Loading branch information
ousttrue committed Mar 2, 2023
1 parent 29e885c commit 655adf3
Show file tree
Hide file tree
Showing 10 changed files with 788 additions and 365 deletions.
7 changes: 6 additions & 1 deletion Assets/UniGLTF/Runtime/UniGLTF/IO/NodeImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ namespace UniGLTF
{
public static class NodeImporter
{
static int n = 0;
public static GameObject ImportNode(glTFNode node, int nodeIndex)
{
var nodeName = node.name;
if (nodeName == "ENDSITE")
{
nodeName = $"ENDSITE{n++}";
}
if (!string.IsNullOrEmpty(nodeName) && nodeName.Contains("/"))
{
Debug.LogWarningFormat("node {0} contains /. replace _", node.name);
Expand Down Expand Up @@ -120,7 +125,7 @@ public static TransformWithSkin BuildHierarchy(glTF gltf, int i, List<Transform>
// invisible in loading
renderer.enabled = false;

if (mesh.ShouldSetRendererNodeAsBone )
if (mesh.ShouldSetRendererNodeAsBone)
{
renderer.bones = new[] { renderer.transform };

Expand Down
26 changes: 8 additions & 18 deletions Assets/UniGLTF/Runtime/UniHumanoid/IO/BvhImporterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ public void Load()
hips.position = new Vector3(0, scaledHeight, 0); // foot to ground
}

//
// avatar
//
Avatar = description.CreateAvatar(Root.transform);
Avatar.name = "Avatar";
AvatarDescription = description;
var animator = Root.AddComponent<Animator>();
animator.avatar = Avatar;

//
// create AnimationClip
//
Expand All @@ -117,15 +108,14 @@ public void Load()
animation.clip = Animation;
animation.Play();

var humanPoseTransfer = Root.AddComponent<HumanPoseTransfer>();
humanPoseTransfer.Avatar = Avatar;

// create SkinnedMesh for bone visualize
var renderer = SkeletonMeshUtility.CreateRenderer(animator);
Material = new Material(Shader.Find("Standard"));
renderer.sharedMaterial = Material;
Mesh = renderer.sharedMesh;
Mesh.name = "box-man";
//
// avatar
//
Avatar = description.CreateAvatar(Root.transform);
Avatar.name = "Avatar";
AvatarDescription = description;
var animator = Root.AddComponent<Animator>();
animator.avatar = Avatar;
}

static Transform BuildHierarchy(Transform parent, BvhNode node, float toMeter)
Expand Down
13 changes: 11 additions & 2 deletions Assets/VRM10/Runtime/ControlRig/InitialRotationPoseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class InitRotationPoseProvider : INormalizedPoseProvider, ITPosePr
Transform m_root;
Transform m_hips;
private readonly Dictionary<HumanBodyBones, BoneInitialRotation> m_bones = new Dictionary<HumanBodyBones, BoneInitialRotation>();
private readonly Dictionary<HumanBodyBones, EuclideanTransform> m_worldMap = new Dictionary<HumanBodyBones, EuclideanTransform>();

public Vector3 HipTPoseWorldPosition => throw new System.NotImplementedException();

Expand All @@ -28,6 +29,7 @@ public InitRotationPoseProvider(Transform root, UniHumanoid.Humanoid humanoid)
foreach (var (t, bone) in humanoid.BoneMap)
{
m_bones.Add(bone, new BoneInitialRotation(t));
m_worldMap.Add(bone, new EuclideanTransform(root.localToWorldMatrix * t.localToWorldMatrix));
}
m_hips = m_bones[HumanBodyBones.Hips].Transform;
}
Expand All @@ -53,13 +55,20 @@ Vector3 INormalizedPoseProvider.GetRawHipsPosition()
}
else
{
throw new System.NotImplementedException();
return m_root.worldToLocalMatrix.MultiplyPoint(m_hips.position);
}
}

EuclideanTransform? ITPoseProvider.GetWorldTransform(HumanBodyBones bone)
{
throw new System.NotImplementedException();
if (m_worldMap.TryGetValue(bone, out var t))
{
return t;
}
else
{
return default;
}
}
}
}
Loading

0 comments on commit 655adf3

Please sign in to comment.