예제 #1
0
        void ExportVRMSpringBone()
        {
            Object[] objects = targetModel.GetComponentsInChildren <VRMSpringBone>();

            //gizmo以外はエクスポート 
            //transformは名前をエクスポートする(インポート時にFindで探す)
            for (int j = 0; j < objects.Length; j++)
            {
                VRMSpringBone springbone = (VRMSpringBone)objects[j];

                VRMSpringBoneSetting exportData
                    = ScriptableObject.CreateInstance <VRMSpringBoneSetting>();

                exportData.m_AttachObject = m_Utility.GetHierarchyPath(springbone.gameObject.transform);

                exportData.m_comment        = springbone.m_comment;
                exportData.m_stiffnessForce = springbone.m_stiffnessForce;
                exportData.m_gravityPower   = springbone.m_gravityPower;
                exportData.m_gravityDir     = springbone.m_gravityDir;
                exportData.m_dragForce      = springbone.m_dragForce;
                if (springbone.m_center != null)
                {
                    exportData.m_center = m_Utility.GetHierarchyPath(springbone.m_center.transform);
                }
                exportData.RootBones = new string[springbone.RootBones.Count];
                for (int i = 0; i < springbone.RootBones.Count; i++)
                {
                    exportData.RootBones[i] = m_Utility.GetHierarchyPath(springbone.RootBones[i].transform);
                }
                exportData.m_hitRadius = springbone.m_hitRadius;

                exportData.ColliderGroups = new string[springbone.ColliderGroups.Length];
                for (int i = 0; i < springbone.ColliderGroups.Length; i++)
                {
                    exportData.ColliderGroups[i]
                        = m_Utility.GetHierarchyPath(springbone.ColliderGroups[i].transform);

                    if (ColliderTergetName.Count == 0)
                    {
                        ColliderTergetName.Add(exportData.ColliderGroups[i]);
                    }
                    else
                    {
                        if (ColliderTergetName.IndexOf(exportData.ColliderGroups[i]) == -1)
                        {
                            ColliderTergetName.Add(exportData.ColliderGroups[i]);
                        }
                        ;
                    }
                }

                AssetDatabase.CreateAsset(
                    exportData, "Assets/Models/Resources/SpringBoneData/SpringBone/VRMSpringBoneData_" + j + ".asset");
            }
        }
예제 #2
0
        void ApplyVRMSpringBone()
        {
            //モデル上でsecondaryの部分を探す
            GameObject targetObject = GameObject.Find("secondary");

            //すべて削除してからスプリングボーンをつける
            VRMSpringBone[] removeComponents = targetObject.GetComponents <VRMSpringBone>();
            foreach (VRMSpringBone removeComponent in removeComponents)
            {
                DestroyImmediate(removeComponent);
            }

            //gizmo以外は設定を反映
            //transformはFind後したTransformを反映)
            for (int j = 0; j < boneObjects.Length; j++)
            {
                //設定データ
                VRMSpringBoneSetting settingData = (VRMSpringBoneSetting)boneObjects[j];
                //対象のボーン


                VRMSpringBone springbone = targetObject.AddComponent <VRMSpringBone>();

                springbone.m_comment        = settingData.m_comment;
                springbone.m_stiffnessForce = settingData.m_stiffnessForce;
                springbone.m_gravityPower   = settingData.m_gravityPower;
                springbone.m_gravityDir     = settingData.m_gravityDir;
                springbone.m_dragForce      = settingData.m_dragForce;
                if (settingData.m_center != null)
                {
                    GameObject findObject = GameObject.Find(settingData.m_center);
                    if (findObject != null)
                    {
                        springbone.m_center = findObject.GetComponent <Transform>();
                    }
                }
                springbone.RootBones = new List <Transform>();
                for (int i = 0; i < settingData.RootBones.Length; i++)
                {
                    GameObject findObject = GameObject.Find(settingData.RootBones[i]);
                    springbone.RootBones.Add(findObject.GetComponent <Transform>());
                }
                springbone.m_hitRadius    = settingData.m_hitRadius;
                springbone.ColliderGroups = new VRMSpringBoneColliderGroup[settingData.ColliderGroups.Length];
                for (int i = 0; i < settingData.ColliderGroups.Length; i++)
                {
                    GameObject findObject = GameObject.Find(settingData.ColliderGroups[i]);
                    springbone.ColliderGroups[i] = findObject.GetComponent <VRMSpringBoneColliderGroup>();
                }
            }
        }
        void ApplyVRMSpringBone()
        {
            //gizmo以外は設定を反映
            //transformはFind後したTransformを反映)
            for (int j = 0; j < boneObjects.Length; j++)
            {
                //設定データ
                VRMSpringBoneSetting settingData = (VRMSpringBoneSetting)boneObjects[j];

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

                VRMSpringBone springbone = targetObject.AddComponent <VRMSpringBone>();

                springbone.m_comment        = settingData.m_comment;
                springbone.m_stiffnessForce = settingData.m_stiffnessForce;
                springbone.m_gravityPower   = settingData.m_gravityPower;
                springbone.m_gravityDir     = settingData.m_gravityDir;
                springbone.m_dragForce      = settingData.m_dragForce;
                if (settingData.m_center != null)
                {
                    GameObject findObject = GameObject.Find(settingData.m_center);
                    if (findObject != null)
                    {
                        springbone.m_center = findObject.GetComponent <Transform>();
                    }
                }
                springbone.RootBones = new List <Transform>();
                for (int i = 0; i < settingData.RootBones.Length; i++)
                {
                    GameObject findObject
                        = GameObject.Find(m_Utility.ChangeRootPath(settingData.RootBones[i], targetModel.name));

                    springbone.RootBones.Add(findObject.GetComponent <Transform>());
                }
                springbone.m_hitRadius    = settingData.m_hitRadius;
                springbone.ColliderGroups = new VRMSpringBoneColliderGroup[settingData.ColliderGroups.Length];
                for (int i = 0; i < settingData.ColliderGroups.Length; i++)
                {
                    GameObject findObject
                        = GameObject.Find(m_Utility.ChangeRootPath(settingData.ColliderGroups[i], targetModel.name));

                    springbone.ColliderGroups[i] = findObject.GetComponent <VRMSpringBoneColliderGroup>();
                }
            }
        }
        void ApplyVRMSpringBone()
        {
            for (int j = 0; j < boneObjects.Length; j++)
            {
                GameObject findObject = null;
                //設定データ
                DynamicBoneSetting settingData = (DynamicBoneSetting)boneObjects[j];
                //対象のボーン
                GameObject    targetObject = GameObject.Find(settingData.m_AttachObject);
                VRMSpringBone springbone   = targetObject.AddComponent <VRMSpringBone>();

                springbone.m_stiffnessForce = settingData.m_Stiffness * 4.0f;

                //重力の設定 大きさが0であればY方向-1に設定
                //大きさは2以上は2にする
                springbone.m_gravityPower = settingData.m_Gravity.magnitude;

                if (springbone.m_gravityPower > 2.0f)
                {
                    springbone.m_gravityPower = 2.0f;
                }

                if (springbone.m_gravityPower != 0)
                {
                    springbone.m_gravityDir = settingData.m_Gravity / settingData.m_Gravity.magnitude;
                }
                else
                {
                    springbone.m_gravityDir = new Vector3(0, -1.0f, 0);
                }

                springbone.RootBones = new List <Transform>();
                findObject           = GameObject.Find(settingData.m_Root);
                springbone.RootBones.Add(findObject.GetComponent <Transform>());

                springbone.m_hitRadius = settingData.m_Radius;

                springbone.ColliderGroups = new VRMSpringBoneColliderGroup[settingData.m_Colliders.Count];
                for (int i = 0; i < settingData.m_Colliders.Count; i++)
                {
                    findObject = GameObject.Find(settingData.m_Colliders[i]);
                    springbone.ColliderGroups[i] = findObject.GetComponent <VRMSpringBoneColliderGroup>();
                }
            }
        }