Exemplo n.º 1
0
        void ApplyVRMSpringBoneCollider()
        {
            //gizmo以外は設定を反映する
            for (int j = 0; j < colliderObjects.Length; j++)
            {
                VRMSpringBoneColliderSetting settingData = (VRMSpringBoneColliderSetting)colliderObjects[j];
                GameObject targetObject = GameObject.Find(settingData.TargetName);
                VRMSpringBoneColliderGroup[] removeComponents = targetObject.GetComponents <VRMSpringBoneColliderGroup>();
                //すべて削除してからコライダーをつける
                foreach (VRMSpringBoneColliderGroup removeComponent in removeComponents)
                {
                    DestroyImmediate(removeComponent);
                }

                VRMSpringBoneColliderGroup collider = targetObject.AddComponent <VRMSpringBoneColliderGroup>();

                collider.Colliders = new VRMSpringBoneColliderGroup.SphereCollider[settingData.Colliders.Length];
                for (int i = 0; i < settingData.Colliders.Length; i++)
                {
                    collider.Colliders[i]        = new VRMSpringBoneColliderGroup.SphereCollider();
                    collider.Colliders[i].Radius = settingData.Colliders[i].Radius;
                    collider.Colliders[i].Offset = settingData.Colliders[i].Offset;
                }
            }
        }
        void ApplyVRMSpringBoneCollider()
        {
            //gizmo以外は設定を反映する
            for (int j = 0; j < colliderObjects.Length; j++)
            {
                DynamicBoneColliderSetting settingData = (DynamicBoneColliderSetting)colliderObjects[j];
                GameObject targetObject = GameObject.Find(settingData.TargetName);

                VRMSpringBoneColliderGroup collider = targetObject.AddComponent <VRMSpringBoneColliderGroup>();

                collider.Colliders = new VRMSpringBoneColliderGroup.SphereCollider[settingData.Colliders.Length];
                for (int i = 0; i < settingData.Colliders.Length; i++)
                {
                    collider.Colliders[i]        = new VRMSpringBoneColliderGroup.SphereCollider();
                    collider.Colliders[i].Radius = settingData.Colliders[i].m_Radius;
                    collider.Colliders[i].Offset = settingData.Colliders[i].m_Center;
                }
            }
        }
Exemplo n.º 3
0
        void ExportVRMSpringBoneCollider()
        {
            //gizmo以外はエクスポート
            for (int j = 0; j < ColliderTergetName.Count; j++)
            {
                GameObject colliderObject             = GameObject.Find(ColliderTergetName[j]);
                VRMSpringBoneColliderGroup   collider = colliderObject.GetComponent <VRMSpringBoneColliderGroup>();
                VRMSpringBoneColliderSetting exportData
                    = ScriptableObject.CreateInstance <VRMSpringBoneColliderSetting>();
                exportData.TargetName = m_Utility.GetHierarchyPath(colliderObject.transform);
                exportData.Colliders  = new VRMSpringBoneColliderSetting.SphereCollider[collider.Colliders.Length];
                for (int i = 0; i < collider.Colliders.Length; i++)
                {
                    exportData.Colliders[i]        = new VRMSpringBoneColliderSetting.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/VRMSpringBoneColliderData_" + j + ".asset");
            }
        }
        void ApplyVRMSpringBoneCollider()
        {
            //gizmo以外は設定を反映する
            for (int j = 0; j < colliderObjects.Length; j++)
            {
                VRMSpringBoneColliderSetting settingData = (VRMSpringBoneColliderSetting)colliderObjects[j];

                //対象のボーン
                //m_Utility.ChangeRootPath 設定されたパスをターゲット対象に変更する
                GameObject targetObject
                    = GameObject.Find(m_Utility.ChangeRootPath(settingData.TargetName, targetModel.name));

                VRMSpringBoneColliderGroup collider = targetObject.AddComponent <VRMSpringBoneColliderGroup>();

                collider.Colliders = new VRMSpringBoneColliderGroup.SphereCollider[settingData.Colliders.Length];
                for (int i = 0; i < settingData.Colliders.Length; i++)
                {
                    collider.Colliders[i]        = new VRMSpringBoneColliderGroup.SphereCollider();
                    collider.Colliders[i].Radius = settingData.Colliders[i].Radius;
                    collider.Colliders[i].Offset = settingData.Colliders[i].Offset;
                }
            }
        }
Exemplo n.º 5
0
 private void OnEnable()
 {
     m_target = (VRMSpringBoneColliderGroup)target;
 }
Exemplo n.º 6
0
        public static void LoadSecondary(Transform root, List <Transform> nodes,
                                         glTF_VRM_SecondaryAnimation secondaryAnimation)
        {
            var secondary = root.Find("secondary");

            if (secondary == null)
            {
                secondary = new GameObject("secondary").transform;
                secondary.SetParent(root, false);
            }

            // clear components
            var vrmSpringBones             = root.GetComponentsInChildren <VRMSpringBone>();
            var vrmSpringBoneColliderGroup = root.GetComponentsInChildren <VRMSpringBoneColliderGroup>();

            var length = (vrmSpringBones?.Length ?? 0) + (vrmSpringBoneColliderGroup?.Length ?? 0);
            var remove = new Component[length];

            var index = 0;

            if (vrmSpringBones != null)
            {
                foreach (var vrmSpringBone in vrmSpringBones)
                {
                    remove[index++] = vrmSpringBone;
                }
            }

            if (vrmSpringBoneColliderGroup != null)
            {
                foreach (var vrmSpringBoneCollider in vrmSpringBoneColliderGroup)
                {
                    remove[index++] = vrmSpringBoneCollider;
                }
            }

            foreach (var x in remove)
            {
                if (Application.isPlaying)
                {
                    GameObject.Destroy(x);
                }
                else
                {
                    GameObject.DestroyImmediate(x);
                }
            }

            //var secondaryAnimation = context.VRM.extensions.VRM.secondaryAnimation;
            var colliders = new List <VRMSpringBoneColliderGroup>();

            foreach (var colliderGroup in secondaryAnimation.colliderGroups)
            {
                var vrmGroup = nodes[colliderGroup.node].gameObject.AddComponent <VRMSpringBoneColliderGroup>();
                vrmGroup.Colliders = colliderGroup.colliders.Select(x =>
                {
                    return(new VRMSpringBoneColliderGroup.SphereCollider
                    {
                        Offset = x.offset,
                        Radius = x.radius
                    });
                }).ToArray();
                colliders.Add(vrmGroup);
            }

            if (secondaryAnimation.boneGroups.Count > 0)
            {
                foreach (var boneGroup in secondaryAnimation.boneGroups)
                {
                    var vrmBoneGroup = secondary.gameObject.AddComponent <VRMSpringBone>();
                    if (boneGroup.center != -1)
                    {
                        vrmBoneGroup.m_center = nodes[boneGroup.center];
                    }

                    vrmBoneGroup.m_comment        = boneGroup.comment;
                    vrmBoneGroup.m_dragForce      = boneGroup.dragForce;
                    vrmBoneGroup.m_gravityDir     = boneGroup.gravityDir;
                    vrmBoneGroup.m_gravityPower   = boneGroup.gravityPower;
                    vrmBoneGroup.m_hitRadius      = boneGroup.hitRadius;
                    vrmBoneGroup.m_stiffnessForce = boneGroup.stiffiness;

                    if (boneGroup.colliderGroups != null && boneGroup.colliderGroups.Any())
                    {
                        var colliderGroups = new VRMSpringBoneColliderGroup[boneGroup.colliderGroups.Length];
                        int i = 0;
                        foreach (var colliderGroup in boneGroup.colliderGroups)
                        {
                            colliderGroups[i] = colliders[colliderGroup];
                        }

                        vrmBoneGroup.ColliderGroups = colliderGroups;
                    }

                    var boneList = new List <Transform>();
                    foreach (var x in boneGroup.bones)
                    {
                        boneList.Add(nodes[x]);
                    }

                    vrmBoneGroup.RootBones = boneList;
                }
            }
            else
            {
                secondary.gameObject.AddComponent <VRMSpringBone>();
            }
        }