Exemple #1
0
        // Use this for initialization
        void Start()
        {
            MeshDeformer deformer = gameObject.AddComponent <MeshDeformer>();

            deformer.Axis = Axis.Y;
            deformer.ResetDeformer();
            deformer.Append();
            deformer.Append();
            deformer.CurvesPerMesh = 2;
            deformer.Spacing       = 1;
            deformer.Approximation = 50;
            deformer.SetControlPointLocal(0, new Vector3(-1, -4, -1));
        }
        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;
        }
Exemple #3
0
 public override void Append()
 {
     if (SplineRuntimeEditor.Instance != null)
     {
         MeshDeformer deformer = SplineRuntimeEditor.Instance.SelectedSpline as MeshDeformer;
         if (deformer != null)
         {
             deformer.Append();
         }
         else
         {
             base.Append();
         }
     }
 }
 public override void Append()
 {
     RunAction <SplineBase>((spline, go) =>
     {
         MeshDeformer deformer = spline as MeshDeformer;
         if (deformer != null)
         {
             deformer.Append();
         }
         else
         {
             base.Append();
         }
     });
 }
Exemple #5
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_meshDeformer == null)
            {
                m_meshDeformer = GetTarget() as MeshDeformer;
            }

            if (m_meshDeformer == null)
            {
                return;
            }

            if (targets.Length == 1)
            {
                int curveIndex = (SelectedIndex - 1) / 3;
                GUILayout.BeginHorizontal();
                {
                    if (curveIndex == 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 (GUILayout.Button("Insert"))
                    {
                        Undo.RecordObject(m_meshDeformer, "Battlehub.MeshDeformer.Insert");
                        RecordScaffolds(m_meshDeformer, "Battlehub.MeshDeformer.Insert");
                        Undo.RegisterCreatedObjectUndo(m_meshDeformer.Insert((SelectedIndex + 2) / 3), "Battlehub.MeshDeformer.Insert");
                        EditorUtility.SetDirty(m_meshDeformer);
                        Selection.activeGameObject = m_meshDeformer.GetComponentsInChildren <ControlPoint>(true).ElementAt(SelectedIndex + 3).gameObject;
                    }

                    if (curveIndex == m_meshDeformer.CurveCount - 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 (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();
                    }
                }
            }
        }
Exemple #6
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);
                }
            }
        }
Exemple #7
0
        protected override void OnInspectorGUIOverride()
        {
            if (m_deformer == null)
            {
                m_deformer = GetTarget() as MeshDeformer;
            }

            if (m_deformer == null)
            {
                return;
            }

            DoOriginalMeshes();

            EditorGUI.BeginChangeCheck();
            Axis axis = (Axis)EditorGUILayout.EnumPopup("Deformation Axis", m_deformer.Axis);

            if (EditorGUI.EndChangeCheck())
            {
                ChangeAxis(m_deformer, axis);
            }

            EditorGUI.BeginChangeCheck();
            int sliceCount = EditorGUILayout.IntField("Approximation", m_deformer.Approximation);

            if (EditorGUI.EndChangeCheck())
            {
                if (sliceCount > 100)
                {
                    if (!EditorUtility.DisplayDialog("Are you sure", "Are you sure you want to set Approximation = " + sliceCount, "Yes", "No"))
                    {
                        sliceCount = m_deformer.Approximation;
                    }
                }
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Approximation Changed");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Approximation Changed");
                EditorUtility.SetDirty(m_deformer);

                Debug.Log("Undo Operations will be Collapsed");
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());

                m_deformer.Approximation = sliceCount;
            }

            EditorGUI.BeginChangeCheck();
            float spacing = EditorGUILayout.FloatField("Spacing", m_deformer.Spacing);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Spacing Changed");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Spacing Changed");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.Spacing = spacing;
            }

            EditorGUI.BeginChangeCheck();
            int curvesPerMesh = EditorGUILayout.IntField("Curves Per Mesh", m_deformer.CurvesPerMesh);

            if (EditorGUI.EndChangeCheck())
            {
                Selection.activeGameObject = m_deformer.gameObject;
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.CurvesPerMesh Changed");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.CurvesPerMesh Changed");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.CurvesPerMesh = curvesPerMesh;
            }

            EditorGUI.BeginChangeCheck();
            bool loop = EditorGUILayout.Toggle("Loop", m_deformer.Loop);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_deformer, UNDO_TOGGLELOOP);
                EditorUtility.SetDirty(m_deformer);
                m_deformer.Loop = loop;
            }


            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Append"))
                {
                    Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Append");
                    Undo.RegisterCreatedObjectUndo(m_deformer.Append(), "Battlehub.MeshDeformer.Append");
                    EditorUtility.SetDirty(m_deformer);
                }

                if (GUILayout.Button("Prepend"))
                {
                    Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Prepend");
                    RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Prepend");
                    Undo.RegisterCreatedObjectUndo(m_deformer.Prepend(), "Battlehub.MeshDeformer.Prepend");
                    EditorUtility.SetDirty(m_deformer);
                }
            }
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Smooth Spline"))
            {
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Fit");
                RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.Fit");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.Smooth();
            }

            GUILayout.BeginHorizontal();
            {
                GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
                {
                    if (GUILayout.Button("Set Rigid Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, true);
                    }

                    if (GUILayout.Button("Set Free Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, false);
                    }
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
                {
                    if (GUILayout.Button("Set Aligned Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, false);
                        SetMode(m_deformer, ControlPointMode.Aligned, false);
                    }

                    if (GUILayout.Button("Set Mirrored Mode"))
                    {
                        Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        RecordScaffolds(m_deformer, "Battlehub.MeshDeformer.SetMode");
                        EditorUtility.SetDirty(m_deformer);
                        SetMode(m_deformer, ControlPointMode.Free, false);
                        SetMode(m_deformer, ControlPointMode.Mirrored, false);
                    }
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();



#if MD_GIZMOS
            EditorGUI.BeginChangeCheck();
            bool drawGizoms = EditorGUILayout.Toggle("Draw Gizmos", m_deformer.DrawGizmos);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.Approximation Changed");
                EditorUtility.SetDirty(m_deformer);
                m_deformer.DrawGizmos = drawGizoms;
            }
#endif
        }