コード例 #1
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_meshDeformer == null)
            {
                m_meshDeformer = GetTarget() as MeshDeformer;
            }

            if (m_meshDeformer == null)
            {
                return;
            }


            int curveIndex = (SelectedIndex - 1) / 3;

            GUILayout.BeginHorizontal();
            {
                if (curveIndex == m_meshDeformer.CurveCount - 1)
                {
                    if (GUILayout.Button("Append"))
                    {
                        Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Append");
                        Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(), "Battlehub.MeshDeformer.Append");
                        EditorUtility.SetDirty(m_meshDeformer);
                        Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
                    }
                }

                if (curveIndex == 0)
                {
                    if (GUILayout.Button("Prepend"))
                    {
                        Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                        RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                        Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(true), "Battlehub.MeshDeformer.Prepend");
                        EditorUtility.SetDirty(m_meshDeformer);
                        Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Straighten"))
            {
                Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                EditorUtility.SetDirty(m_meshDeformer);
                m_meshDeformer.Straighten(SelectedIndex);
            }

            if (SelectedIndex >= 0 && curveIndex < m_meshDeformer.CurveCount)
            {
                if (GUILayout.Button("Remove"))
                {
                    Remove();
                }
            }
        }
コード例 #2
0
        public static void Prepend()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Prepend");
            Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
            foreach (Scaffold scaffold in scaffolds)
            {
                Undo.RecordObject(scaffold, "Battlehub.MeshDeformer.Prepend");
            }
            Undo.RegisterCreatedObjectUndo(deformer.Prepend(), "Battlehub.MeshDeformer.Prepend");
            EditorUtility.SetDirty(deformer);
            Selection.activeGameObject = deformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
        }
コード例 #3
0
 public static void RecordScaffolds(MeshDeformer deformer, string name)
 {
     Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
     for (int i = 0; i < scaffolds.Length; ++i)
     {
         Scaffold scaffold = scaffolds[i];
         Undo.RecordObject(scaffold, name);
     }
 }
コード例 #4
0
        public static void Insert()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Prepend");
            Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
            foreach (Scaffold scaffold in scaffolds)
            {
                Undo.RecordObject(scaffold, "Battlehub.MeshDeformer.Prepend");
            }
            SplineControlPoint ctrlPoint = selected.GetComponent <ControlPoint>();

            Undo.RegisterCreatedObjectUndo(deformer.Insert((ctrlPoint.Index + 2) / 3), "Battlehub.MeshDeformer.Insert");

            EditorUtility.SetDirty(deformer);
            Selection.activeGameObject = deformer.GetComponentsInChildren <ControlPoint>(true).ElementAt(ctrlPoint.Index + 3).gameObject;
        }
コード例 #5
0
        public static void RemoveDeformer()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            ControlPoint[] controlPoints = deformer.GetComponentsInChildren <ControlPoint>(true);
            for (int i = 0; i < controlPoints.Length; ++i)
            {
                Undo.DestroyObjectImmediate(controlPoints[i].gameObject);
            }

            Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
            for (int i = 0; i < scaffolds.Length; ++i)
            {
                Undo.DestroyObjectImmediate(scaffolds[i]);
            }

            Undo.DestroyObjectImmediate(deformer);
        }
コード例 #6
0
        public static void Append()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Append");
            Undo.RegisterCreatedObjectUndo(deformer.Append(), "Battlehub.MeshDeformer.Append");
            EditorUtility.SetDirty(deformer);
            Selection.activeGameObject = deformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
        }
コード例 #7
0
        public static void CombineAndSave()
        {
            GameObject   selected = Selection.activeObject as GameObject;
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            GameObject[] gameObjects = deformer.GetComponentsInChildren <Scaffold>().Select(s => s.gameObject).ToArray();

            CombineResult combineResult = MeshUtils.Combine(gameObjects, deformer.gameObject);

            if (combineResult != null)
            {
                CleanupCombined(combineResult.GameObject);
                MeshUtils.SaveMesh(new[] { combineResult.GameObject }, "Battlehub/");
            }
            else
            {
                Debug.LogWarning("Unable to Combine and Save");
            }
        }
コード例 #8
0
        public static bool Rollback(GameObject selected)
        {
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            if (deformer != null)
            {
                selected = deformer.gameObject;
                Selection.activeGameObject = selected;
            }
            MeshFilter meshFilter = selected.GetComponent <MeshFilter>();

            if (meshFilter == null)
            {
                EditorUtility.DisplayDialog("MeshFilter required", "Select object with MeshFilter component", "OK");
                return(false);
            }

            if (deformer != null)
            {
                if (!EditorUtility.DisplayDialog("Are you sure?", "This action is irreversible. Deformation will be lost", "Ok", "Cancel"))
                {
                    return(false);
                }

                ControlPoint[] controlPoints = deformer.GetComponentsInChildren <ControlPoint>(true);
                for (int i = 0; i < controlPoints.Length; ++i)
                {
                    Object.DestroyImmediate(controlPoints[i].gameObject);
                }

                Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
                for (int i = 0; i < scaffolds.Length; ++i)
                {
                    if (scaffolds[i].gameObject != deformer.gameObject)
                    {
                        Object.DestroyImmediate(scaffolds[i].gameObject);
                    }
                }

                Mesh original = deformer.Original;
                meshFilter.sharedMesh = original;

                Mesh colliderOriginal = deformer.ColliderOriginal;
                if (colliderOriginal != null)
                {
                    MeshCollider collider = deformer.GetComponent <MeshCollider>();
                    if (collider != null)
                    {
                        collider.sharedMesh = colliderOriginal;
                    }
                }

                Object.DestroyImmediate(deformer);
            }


            Scaffold scaffold = selected.GetComponent <Scaffold>();

            if (scaffold != null)
            {
                Object.DestroyImmediate(scaffold);
            }

            return(true);
        }
コード例 #9
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_meshDeformer == null)
            {
                m_meshDeformer = (MeshDeformer)GetTarget();
            }

            if (m_meshDeformer == null)
            {
                return;
            }

            Scaffold        scaffold        = (Scaffold)target;
            ScaffoldWrapper scaffoldWrapper = null;
            int             scaffoldIndex   = -1;

            for (int i = 0; i < m_meshDeformer.Scaffolds.Length; ++i)
            {
                if (scaffold == m_meshDeformer.Scaffolds[i].Obj)
                {
                    scaffoldIndex   = i;
                    scaffoldWrapper = m_meshDeformer.Scaffolds[i];
                    break;
                }
            }

            if (scaffoldWrapper != null)
            {
                EditorGUI.BeginChangeCheck();
                Mesh altMesh = (Mesh)EditorGUILayout.ObjectField("Alt Mesh", scaffold.AltMesh, typeof(Mesh), false);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(scaffold);
                    scaffold.AltMesh = altMesh;
                    m_meshDeformer.WrapAndDeform(scaffoldWrapper, altMesh);
                }

                if (GUILayout.Button("Reload Mesh"))
                {
                    EditorUtility.SetDirty(scaffold);
                    scaffold.AltMesh = altMesh;
                    m_meshDeformer.WrapAndDeform(scaffoldWrapper, altMesh);
                }

                if (GUILayout.Button("Invert Mesh"))
                {
                    Mesh invertedMesh = ScaleMesh(scaffold.transform, new Vector3(-1, 1, 1), scaffold.SourceMesh);
                    scaffold.AltMesh = invertedMesh;
                    m_meshDeformer.WrapAndDeform(scaffoldWrapper, invertedMesh);
                }

                EditorGUI.BeginChangeCheck();
                bool isRigid = EditorGUILayout.Toggle("Is Rigid", scaffoldWrapper.IsRigid);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_meshDeformer, UNDO_CHANGEMODE);
                    RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                    EditorUtility.SetDirty(m_meshDeformer);

                    for (int i = 0; i < scaffoldWrapper.CurveIndices.Length; ++i)
                    {
                        int curveIndex = scaffoldWrapper.CurveIndices[i];
                        m_meshDeformer.SetIsRigid(curveIndex * 3, isRigid);
                    }
                }
            }

            if (scaffold.gameObject != m_meshDeformer.gameObject)
            {
                GUILayout.BeginHorizontal();
                {
                    if (scaffoldIndex == 0)
                    {
                        if (GUILayout.Button("Prepend"))
                        {
                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                            RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Prepend(), "Battlehub.MeshDeformer.Prepend");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
                        }
                    }

                    if (scaffoldWrapper != null)
                    {
                        if (GUILayout.Button("Insert"))
                        {
                            int curveIndex = scaffoldWrapper.CurveIndices.Min();

                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Insert");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Insert(curveIndex), "Battlehub.MeshDeformer.Insert");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).ElementAt(curveIndex + 3).gameObject;
                        }
                    }

                    if (scaffoldIndex == m_meshDeformer.Scaffolds.Length - 1)
                    {
                        if (GUILayout.Button("Append"))
                        {
                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Append");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Append(), "Battlehub.MeshDeformer.Append");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
                        }
                    }
                }
                GUILayout.EndHorizontal();
            }

            if (scaffoldWrapper != null)
            {
                if (GUILayout.Button("Straighten"))
                {
                    Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                    RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                    EditorUtility.SetDirty(m_meshDeformer);
                    m_meshDeformer.Straighten(scaffoldWrapper.CurveIndices.Min() * 3 + 1);
                }
            }
        }
コード例 #10
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_meshDeformer == null)
            {
                m_meshDeformer = (MeshDeformer)GetTarget();
            }

            if (m_meshDeformer == null)
            {
                return;
            }

            Scaffold        scaffold        = (Scaffold)target;
            ScaffoldWrapper scaffoldWrapper = null;
            int             scaffoldIndex   = -1;

            for (int i = 0; i < m_meshDeformer.Scaffolds.Length; ++i)
            {
                if (scaffold == m_meshDeformer.Scaffolds[i].Obj)
                {
                    scaffoldIndex   = i;
                    scaffoldWrapper = m_meshDeformer.Scaffolds[i];
                    break;
                }
            }

            if (scaffoldWrapper != null)
            {
                EditorGUI.BeginChangeCheck();
                bool isRigid = EditorGUILayout.Toggle("Is Rigid", scaffoldWrapper.IsRigid);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_meshDeformer, UNDO_CHANGEMODE);
                    RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                    EditorUtility.SetDirty(m_meshDeformer);

                    for (int i = 0; i < scaffoldWrapper.CurveIndices.Length; ++i)
                    {
                        int curveIndex = scaffoldWrapper.CurveIndices[i];
                        m_meshDeformer.SetIsRigid(curveIndex * 3, isRigid);
                    }
                }
            }

            if (scaffold.gameObject != m_meshDeformer.gameObject)
            {
                GUILayout.BeginHorizontal();
                {
                    if (scaffoldIndex == m_meshDeformer.Scaffolds.Length - 1)
                    {
                        if (GUILayout.Button("Append"))
                        {
                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Append");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(), "Battlehub.MeshDeformer.Append");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).Last().gameObject;
                        }
                    }

                    if (scaffoldIndex == 0)
                    {
                        if (GUILayout.Button("Prepend"))
                        {
                            Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                            RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Prepend");
                            Undo.RegisterCreatedObjectUndo(m_meshDeformer.Extend(true), "Battlehub.MeshDeformer.Prepend");
                            EditorUtility.SetDirty(m_meshDeformer);
                            Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).First().gameObject;
                        }
                    }
                }
                GUILayout.EndHorizontal();
            }

            if (scaffoldWrapper != null)
            {
                if (GUILayout.Button("Straighten"))
                {
                    Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                    RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Straighten");
                    EditorUtility.SetDirty(m_meshDeformer);
                    m_meshDeformer.Straighten(scaffoldWrapper.CurveIndices.Min() * 3 + 1);
                }
            }
        }