public static VrmProtobuf.VRMCSpringBone.Types.ColliderGroup ToGltf(this SpringBoneColliderGroup x, List <Node> nodes) { var node = nodes.IndexOfThrow(x.Node); var colliderGroup = new VrmProtobuf.VRMCSpringBone.Types.ColliderGroup { Node = node, }; foreach (var y in x.Colliders) { var collider = new VrmProtobuf.VRMCSpringBone.Types.ColliderGroup.Types.Collider { Type = (VrmProtobuf.VRMCSpringBone.Types.ColliderGroup.Types.ColliderTypes)y.ColliderType, Radius = y.Radius, }; collider.Offset.Add(y.Offset.X); collider.Offset.Add(y.Offset.Y); collider.Offset.Add(y.Offset.Z); if (y.ColliderType == VrmSpringBoneColliderTypes.Capsule) { collider.Tail.Add(y.CapsuleTail.X); collider.Tail.Add(y.CapsuleTail.Y); collider.Tail.Add(y.CapsuleTail.Z); } colliderGroup.Colliders.Add(collider); } return(colliderGroup); }
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); }
public static VrmProtobuf.SpringBone.Types.ColliderGroup ToGltf(this SpringBoneColliderGroup x, List <Node> nodes) { var node = nodes.IndexOfThrow(x.Node); var colliderGroup = new VrmProtobuf.SpringBone.Types.ColliderGroup { Node = node, }; foreach (var y in x.Colliders) { var collider = new VrmProtobuf.SpringBone.Types.ColliderGroup.Types.Collider { Radius = y.Radius, }; collider.Offset.Add(y.Offset.X); collider.Offset.Add(y.Offset.Y); collider.Offset.Add(y.Offset.Z); colliderGroup.Colliders.Add(collider); } return(colliderGroup); }
void ExportSpringBoneCollider() { //gizmo以外はエクスポート for (int j = 0; j < ColliderTergetName.Count; j++) { GameObject colliderObject = GameObject.Find(ColliderTergetName[j]); SpringBoneColliderGroup collider = colliderObject.GetComponent <SpringBoneColliderGroup>(); SpringBoneColliderSetting exportData = ScriptableObject.CreateInstance <SpringBoneColliderSetting>(); exportData.TargetName = m_Utility.GetHierarchyPath(colliderObject.transform); exportData.Colliders = new SpringBoneColliderSetting.SphereCollider[collider.Colliders.Length]; for (int i = 0; i < collider.Colliders.Length; i++) { exportData.Colliders[i] = new SpringBoneColliderSetting.SphereCollider(); exportData.Colliders[i].Radius = collider.Colliders[i].Radius; exportData.Colliders[i].Offset = collider.Colliders[i].Offset; } AssetDatabase.CreateAsset( exportData, "Assets/Models/Resources/SpringBoneData/Collider/SpringBoneColliderData_" + j + ".asset"); } }
void ApplySpringBoneCollider() { //gizmo以外は設定を反映する for (int j = 0; j < colliderObjects.Length; j++) { SpringBoneColliderSetting settingData = (SpringBoneColliderSetting)colliderObjects[j]; //対象のボーン //m_Utility.ChangeRootPath 設定されたパスをターゲット対象に変更する GameObject targetObject = GameObject.Find(m_Utility.ChangeRootPath(settingData.TargetName, targetModel.name)); SpringBoneColliderGroup collider = targetObject.AddComponent <SpringBoneColliderGroup>(); collider.Colliders = new SpringBoneColliderGroup.SphereCollider[settingData.Colliders.Length]; for (int i = 0; i < settingData.Colliders.Length; i++) { collider.Colliders[i] = new SpringBoneColliderGroup.SphereCollider(); collider.Colliders[i].Radius = settingData.Colliders[i].Radius; collider.Colliders[i].Offset = settingData.Colliders[i].Offset; } } }
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); }