コード例 #1
0
        public override void OnInspectorGUI()
        {
            var bones = m_target.Bones;

            if (bones == null)
            {
                return;
            }

            BoneField(HumanBodyBones.Hips, bones);

            if (bones[(int)HumanBodyBones.Hips] == null)
            {
                EditorGUILayout.HelpBox(@"First, you set hips", MessageType.Warning);
            }
            else
            {
                if (GUILayout.Button("Guess bone mapping"))
                {
                    m_target.GuessBoneMapping();
                }
                EditorGUILayout.HelpBox(@"Guess bones from hips", MessageType.Info);

                if (GUILayout.Button("Ensure T-Pose"))
                {
                    m_target.EnsureTPose();
                }
                EditorGUILayout.HelpBox(@"Arms to Horizontal", MessageType.Info);

                if (GUILayout.Button("Create avatar"))
                {
                    var avatarWithDescription = m_target.CreateAvatar();
                    if (avatarWithDescription.Avatar != null)
                    {
                        //var parentObject = PrefabUtility.GetPrefabParent(this);
                        //var assetPath = AssetDatabase.GetAssetPath(parentObject);
                        var prefabRoot = PrefabUtility.GetPrefabParent(m_target.gameObject);
                        var assetPath  = AssetDatabase.GetAssetPath(prefabRoot);

                        var path = (string.IsNullOrEmpty(assetPath))
                            ? string.Format("Assets/{0}.asset", avatarWithDescription.Avatar.name)
                            : string.Format("{0}/{1}.asset", Path.GetDirectoryName(assetPath), Path.GetFileNameWithoutExtension(assetPath))
                        ;
                        AssetDatabase.CreateAsset(avatarWithDescription.Description, path); // overwrite
                        AssetDatabase.AddObjectToAsset(avatarWithDescription.Avatar, path);
                        AssetDatabase.ImportAsset(path);
                        Debug.LogFormat("Create avatar {0}", path);
                    }
                    else
                    {
                        Debug.LogWarning("fail to CreateAvatar");
                    }
                }
                EditorGUILayout.HelpBox(@"before create,

1. Model root transform should reset(origin without rotation)
2. Model forward to Z+(rotate child of model root)
3. Required bones filled(todo)
", MessageType.Info);
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Arm", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
            EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.EndHorizontal();
            BoneField(HumanBodyBones.LeftShoulder, HumanBodyBones.RightShoulder, bones);
            BoneField(HumanBodyBones.LeftUpperArm, HumanBodyBones.RightUpperArm, bones);
            BoneField(HumanBodyBones.LeftLowerArm, HumanBodyBones.RightLowerArm, bones);
            BoneField(HumanBodyBones.LeftHand, HumanBodyBones.RightHand, bones);

            EditorGUILayout.LabelField("Body", EditorStyles.boldLabel);
            BoneField(HumanBodyBones.Spine, bones);
            BoneField(HumanBodyBones.Chest, bones);
            BoneField(HumanBodyBones.UpperChest, bones);
            BoneField(HumanBodyBones.Neck, bones);
            BoneField(HumanBodyBones.Head, bones);
            BoneField(HumanBodyBones.Jaw, bones);
            BoneField(HumanBodyBones.LeftEye, HumanBodyBones.RightEye, bones);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Leg", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
            EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.EndHorizontal();
            BoneField(HumanBodyBones.LeftUpperLeg, HumanBodyBones.RightUpperLeg, bones);
            BoneField(HumanBodyBones.LeftLowerLeg, HumanBodyBones.RightLowerLeg, bones);
            BoneField(HumanBodyBones.LeftFoot, HumanBodyBones.RightFoot, bones);
            BoneField(HumanBodyBones.LeftToes, HumanBodyBones.RightToes, bones);

            m_handFoldout = EditorGUILayout.Foldout(m_handFoldout, "Hand");
            if (m_handFoldout)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Thumb", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftThumbProximal, HumanBodyBones.RightThumbProximal, bones);
                BoneField(HumanBodyBones.LeftThumbIntermediate, HumanBodyBones.RightThumbIntermediate, bones);
                BoneField(HumanBodyBones.LeftThumbDistal, HumanBodyBones.RightThumbDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Index", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftIndexProximal, HumanBodyBones.RightIndexProximal, bones);
                BoneField(HumanBodyBones.LeftIndexIntermediate, HumanBodyBones.RightIndexIntermediate, bones);
                BoneField(HumanBodyBones.LeftIndexDistal, HumanBodyBones.RightIndexDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Middle", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftMiddleProximal, HumanBodyBones.RightMiddleProximal, bones);
                BoneField(HumanBodyBones.LeftMiddleIntermediate, HumanBodyBones.RightMiddleIntermediate, bones);
                BoneField(HumanBodyBones.LeftMiddleDistal, HumanBodyBones.RightMiddleDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Ring", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftRingProximal, HumanBodyBones.RightRingProximal, bones);
                BoneField(HumanBodyBones.LeftRingIntermediate, HumanBodyBones.RightRingIntermediate, bones);
                BoneField(HumanBodyBones.LeftRingDistal, HumanBodyBones.RightRingDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Little", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftLittleProximal, HumanBodyBones.RightLittleProximal, bones);
                BoneField(HumanBodyBones.LeftLittleIntermediate, HumanBodyBones.RightLittleIntermediate, bones);
                BoneField(HumanBodyBones.LeftLittleDistal, HumanBodyBones.RightLittleDistal, bones);
            }

            EditorUtility.SetDirty(m_target);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            var bones = m_target.Bones;

            if (bones == null)
            {
                return;
            }

            BoneField(HumanBodyBones.Hips, bones);

            if (bones[(int)HumanBodyBones.Hips] == null)
            {
                EditorGUILayout.HelpBox(@"First, you set hips", MessageType.Warning);
            }
            else
            {
                if (GUILayout.Button("Guess bone mapping"))
                {
                    m_target.GuessBoneMapping();
                }
                EditorGUILayout.HelpBox(@"Guess bones from hips", MessageType.Info);

                if (GUILayout.Button("Ensure T-Pose"))
                {
                    m_target.EnsureTPose();
                }
                EditorGUILayout.HelpBox(@"Arms to Horizontal", MessageType.Info);

                if (GUILayout.Button("Create avatar"))
                {
                    var description = AvatarDescription.Create(m_target.Description);
                    BoneMapping.SetBonesToDescription(m_target, description);
                    var avatar = description.CreateAvatarAndSetup(m_target.transform);
                    if (avatar != null)
                    {
                        avatar.name = "avatar";
#if UNITY_2018_2_OR_NEWER
                        var prefabRoot = PrefabUtility.GetCorrespondingObjectFromSource(m_target.gameObject);
#else
                        var prefabRoot = PrefabUtility.GetPrefabParent(m_target.gameObject);
#endif
                        var prefabPath = AssetDatabase.GetAssetPath(prefabRoot);

                        var path = (string.IsNullOrEmpty(prefabPath))
                            ? string.Format("Assets/{0}.asset", avatar.name)
                            : string.Format("{0}/{1}.asset", Path.GetDirectoryName(prefabPath), Path.GetFileNameWithoutExtension(prefabPath))
                        ;
                        path = EditorUtility.SaveFilePanel(
                            "Save avatar",
                            Path.GetDirectoryName(path),
                            string.Format("{0}.avatar.asset", serializedObject.targetObject.name),
                            "asset");
                        var assetPath = HumanPoseTransferEditor.ToAssetPath(path);
                        if (!string.IsNullOrEmpty(assetPath))
                        {
                            AssetDatabase.CreateAsset(description, assetPath); // overwrite
                            AssetDatabase.AddObjectToAsset(avatar, assetPath);

                            Debug.LogFormat("Create avatar {0}", path);
                            AssetDatabase.ImportAsset(assetPath);
                            Selection.activeObject = avatar;
                        }
                        else
                        {
                            Debug.LogWarning("fail to CreateAvatar");
                        }
                    }
                }
                EditorGUILayout.HelpBox(@"before create,

1. Model root transform should reset(origin without rotation)
2. Model forward to Z+(rotate child of model root)
3. Required bones filled
", MessageType.Info);
            }

            /*
             * m_settingsFoldout = EditorGUILayout.Foldout(m_settingsFoldout, "AvatarSettings");
             * if (m_settingsFoldout)
             * {
             *  EditorGUILayout.FloatField("armStretch", m_target.armStretch);
             *  EditorGUILayout.FloatField("legStretch", m_target.legStretch);
             *  EditorGUILayout.FloatField("upperArmTwist", m_target.upperArmTwist);
             *  EditorGUILayout.FloatField("lowerArmTwist", m_target.lowerArmTwist);
             *  EditorGUILayout.FloatField("upperLegTwist", m_target.upperLegTwist);
             *  EditorGUILayout.FloatField("lowerLegTwist", m_target.lowerLegTwist);
             *  EditorGUILayout.FloatField("feetSpacing", m_target.feetSpacing);
             *  EditorGUILayout.Toggle("hasTranslationDoF", m_target.hasTranslationDoF);
             *  //public BoneLimit[] human;
             * }
             */

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Arm", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
            EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.EndHorizontal();
            BoneField(HumanBodyBones.LeftShoulder, HumanBodyBones.RightShoulder, bones);
            BoneField(HumanBodyBones.LeftUpperArm, HumanBodyBones.RightUpperArm, bones);
            BoneField(HumanBodyBones.LeftLowerArm, HumanBodyBones.RightLowerArm, bones);
            BoneField(HumanBodyBones.LeftHand, HumanBodyBones.RightHand, bones);

            EditorGUILayout.LabelField("Body and Head", EditorStyles.boldLabel);
            BoneField(HumanBodyBones.Spine, bones);
            BoneField(HumanBodyBones.Chest, bones);
#if UNITY_5_6_OR_NEWER
            BoneField(HumanBodyBones.UpperChest, bones);
#endif
            BoneField(HumanBodyBones.Neck, bones);
            BoneField(HumanBodyBones.Head, bones);
            BoneField(HumanBodyBones.Jaw, bones);
            BoneField(HumanBodyBones.LeftEye, HumanBodyBones.RightEye, bones);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Leg", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
            EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.EndHorizontal();
            BoneField(HumanBodyBones.LeftUpperLeg, HumanBodyBones.RightUpperLeg, bones);
            BoneField(HumanBodyBones.LeftLowerLeg, HumanBodyBones.RightLowerLeg, bones);
            BoneField(HumanBodyBones.LeftFoot, HumanBodyBones.RightFoot, bones);
            BoneField(HumanBodyBones.LeftToes, HumanBodyBones.RightToes, bones);

            m_handFoldout = EditorGUILayout.Foldout(m_handFoldout, "Hand");
            if (m_handFoldout)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Thumb", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftThumbProximal, HumanBodyBones.RightThumbProximal, bones);
                BoneField(HumanBodyBones.LeftThumbIntermediate, HumanBodyBones.RightThumbIntermediate, bones);
                BoneField(HumanBodyBones.LeftThumbDistal, HumanBodyBones.RightThumbDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Index", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftIndexProximal, HumanBodyBones.RightIndexProximal, bones);
                BoneField(HumanBodyBones.LeftIndexIntermediate, HumanBodyBones.RightIndexIntermediate, bones);
                BoneField(HumanBodyBones.LeftIndexDistal, HumanBodyBones.RightIndexDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Middle", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftMiddleProximal, HumanBodyBones.RightMiddleProximal, bones);
                BoneField(HumanBodyBones.LeftMiddleIntermediate, HumanBodyBones.RightMiddleIntermediate, bones);
                BoneField(HumanBodyBones.LeftMiddleDistal, HumanBodyBones.RightMiddleDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Ring", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftRingProximal, HumanBodyBones.RightRingProximal, bones);
                BoneField(HumanBodyBones.LeftRingIntermediate, HumanBodyBones.RightRingIntermediate, bones);
                BoneField(HumanBodyBones.LeftRingDistal, HumanBodyBones.RightRingDistal, bones);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Little", EditorStyles.boldLabel, GUILayout.Width(LABEL_WIDTH));
                EditorGUILayout.LabelField("Left", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Right", EditorStyles.boldLabel, GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                BoneField(HumanBodyBones.LeftLittleProximal, HumanBodyBones.RightLittleProximal, bones);
                BoneField(HumanBodyBones.LeftLittleIntermediate, HumanBodyBones.RightLittleIntermediate, bones);
                BoneField(HumanBodyBones.LeftLittleDistal, HumanBodyBones.RightLittleDistal, bones);
            }

            EditorUtility.SetDirty(m_target);
        }