Exemplo n.º 1
0
        public static void Straighten()
        {
            GameObject   selected  = Selection.activeObject as GameObject;
            ControlPoint ctrlPoint = selected.GetComponent <ControlPoint>();
            MeshDeformer deformer  = selected.GetComponentInParent <MeshDeformer>();
            int          index     = 0;

            if (ctrlPoint == null)
            {
                Scaffold scaffold = selected.GetComponent <Scaffold>();
                for (int i = 0; i < deformer.Scaffolds.Length; ++i)
                {
                    if (deformer.Scaffolds[i].Obj == scaffold)
                    {
                        index = deformer.Scaffolds[i].CurveIndices.Min() * 3 + 1;
                        break;
                    }
                }
            }
            else
            {
                index = ctrlPoint.Index;
            }


            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Straighten");
            MeshDeformerEditor.RecordScaffolds(deformer, "Battlehub.MeshDeformer.Straighten");
            EditorUtility.SetDirty(deformer);
            deformer.Straighten(index);
        }
Exemplo n.º 2
0
        private static void SetMode(GameObject selected, bool isRigid, ControlPointMode mode)
        {
            MeshDeformer meshDeformer = selected.GetComponentInParent <MeshDeformer>();

            if (meshDeformer == null)
            {
                return;
            }
            Scaffold     selectedScaffold     = selected.GetComponent <Scaffold>();
            ControlPoint selectedControlPoint = selected.GetComponent <ControlPoint>();


            Undo.RecordObject(meshDeformer, "Battlehub.MeshDeformer.SetMode");
            MeshDeformerEditor.RecordScaffolds(meshDeformer, "Battlehub.MeshDeformer.SetMode");
            EditorUtility.SetDirty(meshDeformer);

            if (selectedScaffold != null && selectedScaffold.gameObject != meshDeformer.gameObject)
            {
                ScaffoldWrapper scaffold = meshDeformer.Scaffolds.Where(s => s.Obj == selectedScaffold).FirstOrDefault();
                if (scaffold != null)
                {
                    for (int i = 0; i < scaffold.CurveIndices.Length; ++i)
                    {
                        int curveIndex = scaffold.CurveIndices[i];
                        if (mode == ControlPointMode.Free)
                        {
                            meshDeformer.SetIsRigid(curveIndex * 3, isRigid);
                        }

                        if (!isRigid)
                        {
                            meshDeformer.SetControlPointMode(curveIndex * 3, mode);
                            meshDeformer.SetControlPointMode(curveIndex * 3 + 3, mode);
                        }
                    }
                }
                else
                {
                    Debug.LogError("scaffold not found");
                }
            }
            else if (selectedControlPoint != null)
            {
                if (mode == ControlPointMode.Free)
                {
                    meshDeformer.SetIsRigid(selectedControlPoint.Index, isRigid);
                }

                if (!isRigid)
                {
                    meshDeformer.SetControlPointMode(selectedControlPoint.Index, mode);
                }
            }
            else
            {
                MeshDeformerEditor.SetMode(meshDeformer, mode, isRigid);
            }
        }
Exemplo n.º 3
0
        public static void Fit()
        {
            GameObject selected = Selection.activeObject as GameObject;
            SplineBase spline   = selected.GetComponentInParent <SplineBase>();

            if (spline is MeshDeformer)
            {
                MeshDeformer deformer = (MeshDeformer)spline;
                Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Fit");
                MeshDeformerEditor.RecordScaffolds(deformer, "Battlehub.MeshDeformer.Fit");
                EditorUtility.SetDirty(deformer);
            }
            else
            {
                Undo.RecordObject(spline, "Battlehub.MeshDeformer.Fit");
                EditorUtility.SetDirty(spline);
            }


            spline.Smooth();
        }
Exemplo n.º 4
0
        public static void Remove()
        {
            GameObject   selected  = Selection.activeObject as GameObject;
            ControlPoint ctrlPoint = selected.GetComponent <ControlPoint>();
            MeshDeformer deformer  = selected.GetComponentInParent <MeshDeformer>();

            Selection.activeGameObject = deformer.gameObject;

            Undo.RecordObject(deformer, "Battlehub.MeshDeformer.Remove");
            MeshDeformerEditor.RecordScaffolds(deformer, "Battlehub.MeshDeformer.Remove");

            GameObject removeObject;

            deformer.Remove((ctrlPoint.Index - 1) / 3, out removeObject);
            if (removeObject != null)
            {
                Undo.DestroyObjectImmediate(removeObject);
            }

            EditorUtility.SetDirty(deformer);
        }