public SpringBoneManager CreateVrmSpringBone(List <Node> nodes) { var gltfVrm = Gltf.Extensions.VRMCSpringBone; if ((gltfVrm is null)) { return(null); } var springBone = new SpringBoneManager(); // springs foreach (var group in gltfVrm.Springs.GroupBy(x => x.Setting.Value)) { var sb = new SpringBone(); sb.Comment = group.First().Name; sb.HitRadius = group.First().HitRadius.Value; var setting = gltfVrm.Settings[group.Key]; sb.DragForce = setting.DragForce.Value; sb.GravityDir = setting.GravityDir.ToVector3(); sb.GravityPower = setting.GravityPower.Value; sb.Stiffness = setting.Stiffness.Value; foreach (var spring in group) { // root sb.Bones.Add(nodes[spring.SpringRoot.Value]); // collider foreach (var colliderNode in spring.Colliders) { var collider = springBone.Colliders.FirstOrDefault(x => x.Node == nodes[colliderNode]); if (collider == null) { collider = new SpringBoneColliderGroup(nodes[colliderNode], Gltf.Nodes[colliderNode].Extensions.VRMCNodeCollider.Shapes.Select(x => { if (x.Sphere != null) { return(VrmSpringBoneCollider.CreateSphere(x.Sphere.Offset.ToVector3(), x.Sphere.Radius.Value)); } else if (x.Capsule != null) { return(VrmSpringBoneCollider.CreateCapsule(x.Capsule.Offset.ToVector3(), x.Capsule.Radius.Value, x.Capsule.Tail.ToVector3())); } else { throw new NotImplementedException(); } })); springBone.Colliders.Add(collider); } sb.Colliders.Add(collider); } } springBone.Springs.Add(sb); } return(springBone); }
static VrmSpringBoneCollider CreateCollider(VrmProtobuf.ColliderShape z) { if (z.Sphere != null) { return(VrmSpringBoneCollider.CreateSphere(z.Sphere.Offset.ToVector3(), z.Sphere.Radius.Value)); } if (z.Capsule != null) { return(VrmSpringBoneCollider.CreateCapsule(z.Capsule.Offset.ToVector3(), z.Capsule.Radius.Value, z.Capsule.Tail.ToVector3())); } throw new NotImplementedException(); }
static VrmSpringBoneCollider CreateCollider(VrmProtobuf.VRMCSpringBone.Types.ColliderGroup.Types.Collider z) { switch (z.Type) { case VrmProtobuf.VRMCSpringBone.Types.ColliderGroup.Types.ColliderTypes.Sphere: return(VrmSpringBoneCollider.CreateSphere(z.Offset.ToVector3(), z.Radius)); case VrmProtobuf.VRMCSpringBone.Types.ColliderGroup.Types.ColliderTypes.Capsule: return(VrmSpringBoneCollider.CreateCapsule(z.Offset.ToVector3(), z.Radius, z.Tail.ToVector3())); } throw new Exception(); }
public SpringBoneManager CreateVrmSpringBone(List <Node> nodes) { if ((gltfVrmSpringBone is null)) { return(null); } var springBoneManager = new SpringBoneManager(); // springs if (gltfVrmSpringBone.Springs != null) { foreach (var gltfSpring in gltfVrmSpringBone.Springs) { var springBone = new SpringBone(); springBone.Comment = gltfSpring.Name; // joint foreach (var gltfJoint in gltfSpring.Joints) { var joint = new SpringJoint(nodes[gltfJoint.Node.Value]); joint.HitRadius = gltfJoint.HitRadius.Value; joint.DragForce = gltfJoint.DragForce.Value; joint.GravityDir = gltfJoint.GravityDir.ToVector3(); joint.GravityPower = gltfJoint.GravityPower.Value; joint.Stiffness = gltfJoint.Stiffness.Value; joint.Exclude = gltfJoint.Exclude.GetValueOrDefault(); springBone.Joints.Add(joint); } // collider springBone.Colliders.AddRange(gltfSpring.Colliders.Select(colliderNode => { if (UniGLTF.Extensions.VRMC_node_collider.GltfDeserializer.TryGet(Gltf.nodes[colliderNode].extensions, out UniGLTF.Extensions.VRMC_node_collider.VRMC_node_collider extension)) { var collider = new SpringBoneColliderGroup(nodes[colliderNode], extension.Shapes.Select(x => { if (x.Sphere != null) { return(VrmSpringBoneCollider.CreateSphere(x.Sphere.Offset.ToVector3(), x.Sphere.Radius.Value)); } else if (x.Capsule != null) { return(VrmSpringBoneCollider.CreateCapsule(x.Capsule.Offset.ToVector3(), x.Capsule.Radius.Value, x.Capsule.Tail.ToVector3())); } else { throw new NotImplementedException(); } })); return(collider); } else { return(null); } }).Where(x => x != null)); springBoneManager.Springs.Add(springBone); } } return(springBoneManager); }