Ejemplo n.º 1
0
        public void SlerpContacts(MeshDeformer deformer, Mesh original, Mesh colliderOriginal, ScaffoldWrapper prev, ScaffoldWrapper next)
        {
            if (m_isRigid)
            {
                return;
            }

            if (m_scaffold != null)
            {
                Scaffold prevObj = null;
                if (prev != null)
                {
                    int contactPointIndex = prev.CurveIndices.Max() * 3 + 3;
                    ControlPointMode mode = deformer.GetControlPointMode(contactPointIndex);
                    if (mode != ControlPointMode.Free)
                    {
                        prevObj = prev.Obj;
                    }
                }
                Scaffold nextObj = null;
                if (next != null)
                {
                    int contactPointIndex = next.CurveIndices.Min() * 3;
                    ControlPointMode mode = deformer.GetControlPointMode(contactPointIndex);
                    if (mode != ControlPointMode.Free)
                    {
                        nextObj = next.Obj;
                    }
                }
                m_scaffold.SlerpContacts(deformer, original, colliderOriginal, prevObj, nextObj, m_isRigid);
            }
        }
Ejemplo n.º 2
0
        private void InsertCurve(Vector3[] points, ControlPointSetting setting, ControlPointMode mode, int curveIndex, float length, bool enforceNeighbour)
        {
            Array.Resize(ref m_points, m_points.Length + points.Length);
            Array.Resize(ref m_settings, m_settings.Length + points.Length / 3);
            Array.Resize(ref m_modes, m_modes.Length + points.Length / 3);

            int pointIndex = curveIndex * 3;
            int modeIndex  = (pointIndex + 1) / 3;

            for (int i = m_points.Length - 1; i >= pointIndex + points.Length; --i)
            {
                m_points[i] = m_points[i - points.Length];
            }

            for (int i = m_modes.Length - 1; i >= modeIndex + points.Length / 3; --i)
            {
                m_settings[i] = m_settings[i - points.Length / 3];
                m_modes[i]    = m_modes[i - points.Length / 3];
                RaiseControlPointModeChanged(i);
            }

            for (int i = pointIndex; i < pointIndex + points.Length; ++i)
            {
                m_points[i] = points[i - pointIndex];
            }

            for (int i = modeIndex; i < modeIndex + points.Length / 3; ++i)
            {
                m_settings[i] = setting;
                m_modes[i]    = mode;
                RaiseControlPointModeChanged(i);
            }

            Vector3 dir = transform.InverseTransformDirection(GetDirection(0.0f, curveIndex));

            for (int i = pointIndex - 1; i >= 0; i--)
            {
                m_points[i] -= dir * length;
            }

            if (enforceNeighbour)
            {
                EnforceMode(pointIndex + points.Length + 1);
            }
            else
            {
                EnforceMode(pointIndex + points.Length - 1);
            }

            if (m_loop)
            {
                m_points[m_points.Length - 1] = m_points[0];
                m_settings[0] = m_settings[m_settings.Length - 1];
                m_modes[m_modes.Length - 1] = m_modes[0];
                RaiseControlPointModeChanged(m_modes.Length - 1);
                EnforceMode(1);
            }

            SyncCtrlPoints();
        }
Ejemplo n.º 3
0
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");
        EditorGUI.BeginChangeCheck();
        // get the point modified on the inspector
        // add a Vector3 field
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            // set the new value if modified through inspector
            spline.SetControlPoint(selectedIndex, point);
        }

        EditorGUI.BeginChangeCheck();

        // Add a Pop up field to the inspector
        ControlPointMode mode = (ControlPointMode)
                                EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
Ejemplo n.º 4
0
        public void AddCurve(int _atIndex, ControlPointMode _defaultMode = ControlPointMode.Mirrored)
        {
            Vector3 p1        = points[_atIndex * 3];
            Vector3 p2        = points[(_atIndex + 1) * 3];
            Vector3 center    = (p1 + p2) * 0.5f;
            Vector3 direction = (p2 - p1).normalized;

            points.InsertRange((_atIndex * 3) + 2, new Vector3[]
            {
                center - direction,
                center,
                center + direction
            });

            modes.Insert(_atIndex, _defaultMode);
            EnforceMode(_atIndex);

            if (isLooped)
            {
                points[points.Count - 1] = points[0];
                modes[modes.Count - 1]   = modes[0];
                EnforceMode(0);
            }

            hasChanged = true;
        }
        private void UpdateMaterial()
        {
            if (m_renderer != null)
            {
                SplineRuntimeEditor runtimeEditor = SplineRuntimeEditor.Instance;
                if (runtimeEditor != null)
                {
                    if (m_index % 3 == 0)
                    {
                        m_renderer.sharedMaterial = runtimeEditor.NormalMaterial;
                    }
                    else
                    {
                        if (m_index >= m_spline.ControlPointCount)
                        {
                            return;
                        }

                        ControlPointMode mode = m_spline.GetControlPointMode(m_index);
                        if (mode == ControlPointMode.Mirrored)
                        {
                            m_renderer.sharedMaterial = runtimeEditor.MirroredModeMaterial;
                        }
                        else if (mode == ControlPointMode.Aligned)
                        {
                            m_renderer.sharedMaterial = runtimeEditor.AlignedModeMaterial;
                        }
                        else
                        {
                            m_renderer.sharedMaterial = runtimeEditor.FreeModeMaterial;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
    private void EnforceMode(int index)
    {
        int modeIndex         = (index + 1) / 3;
        ControlPointMode mode = modes[modeIndex];

        if (mode == ControlPointMode.Free || modeIndex == 0 || modeIndex == modes.Length - 1)
        {
            return;
        }

        int middleIndex = modeIndex * 3;
        int fixedIndex, enforcedIndex;

        if (index <= middleIndex)
        {
            fixedIndex    = middleIndex - 1;
            enforcedIndex = middleIndex + 1;
        }
        else
        {
            fixedIndex    = middleIndex + 1;
            enforcedIndex = middleIndex - 1;
        }

        Vector3 middle          = points[middleIndex];
        Vector3 enforcedTangent = middle - points[fixedIndex];

        if (mode == ControlPointMode.Aligned)
        {
            enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, points[enforcedIndex]);
        }
        points[enforcedIndex] = middle + enforcedTangent;
    }
Ejemplo n.º 7
0
        public void SetControlPointMode(int index, ControlPointMode mode, bool raiseCurveChanged = true)
        {
            int modeIndex = (index + 1) / 3;

            m_modes[modeIndex] = mode;
            RaiseControlPointModeChanged(modeIndex);
            if (m_loop)
            {
                if (modeIndex == 0)
                {
                    m_modes[m_modes.Length - 1] = mode;
                    RaiseControlPointModeChanged(m_modes.Length - 1);
                }
                else if (modeIndex == m_modes.Length - 1)
                {
                    m_modes[0] = mode;
                    RaiseControlPointModeChanged(0);
                }
            }
            EnforceMode(index);
#if UNITY_EDITOR
            m_persistentVersions[0]++;
            OnVersionChanged();
#endif

            if (raiseCurveChanged)
            {
                OnCurveChanged(index, Math.Max(0, (index - 1) / 3));
            }
        }
Ejemplo n.º 8
0
 public void SetControlPointMode(ControlPointMode mode)
 {
     for (int i = 0; i <= CurveCount; ++i)
     {
         SetControlPointMode(i * 3, mode);
     }
 }
Ejemplo n.º 9
0
        protected override SplineBase Read(ContentReader input, SplineBase existingInstance)
        {
            SplineBase spline = existingInstance;

            Setup.SplineMarkerResolution = input.ReadSingle();

            int pointLength = input.ReadInt32();

            Transform[] points = new Transform[pointLength];
            for (int i = 0; i < pointLength; i++)
            {
                points[i] = new Transform(input.ReadVector2());
            }

            int pointModeLength = input.ReadInt32();

            ControlPointMode[] pointModes = new ControlPointMode[pointModeLength];
            for (int i = 0; i < pointModeLength; i++)
            {
                pointModes[i] = (ControlPointMode)Enum.Parse(typeof(ControlPointMode), input.ReadString());
            }

            int triggerLength = input.ReadInt32();

            Trigger[] trigger = new Trigger[triggerLength];
            for (int i = 0; i < triggerLength; i++)
            {
                trigger[i] = new Trigger(
                    input.ReadString(),
                    input.ReadSingle(),
                    input.ReadSingle() * Setup.SplineMarkerResolution,
                    input.ReadString());
            }

            Transform[] tangents = null;
            if (spline.IsHermite)
            {
                int tangentLength = input.ReadInt32();
                tangents = new Transform[tangentLength];
                for (int i = 0; i < tangentLength; i++)
                {
                    tangents[i] = new Transform(input.ReadVector2())
                    {
                        UserData = input.ReadObject <HermiteSpline.TangentData>()
                    };
                }
            }

            spline.LoadSplineData(
                points,
                pointModes,
                trigger,
                tangents);

            spline.Loop = input.ReadBoolean();

            return(spline);
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        public void EnforceMode(int index)
        {
            if (index == Setup.CenterSplineIndex)
            {
                return;
            }

            int modeIndex         = (index + 1) / 3;
            ControlPointMode mode = _Modes[modeIndex];

            if (mode == ControlPointMode.Free || !Loop && (modeIndex == 0 || modeIndex == _Modes.Length - 1))
            {
                return;
            }

            int middleIndex = modeIndex * 3;
            int fixedIndex, enforcedIndex;

            if (index <= middleIndex)
            {
                fixedIndex = middleIndex - 1;
                if (fixedIndex < 0)
                {
                    fixedIndex = _Points.Length - 2;
                }
                enforcedIndex = middleIndex + 1;
                if (enforcedIndex >= _Points.Length)
                {
                    enforcedIndex = 1;
                }
            }
            else
            {
                fixedIndex = middleIndex + 1;
                if (fixedIndex >= _Points.Length)
                {
                    fixedIndex = 1;
                }
                enforcedIndex = middleIndex - 1;
                if (enforcedIndex < 0)
                {
                    enforcedIndex = _Points.Length - 2;
                }
            }

            Transform middle          = _Points[middleIndex];
            Vector2   enforcedTangent = middle.Position - _Points[fixedIndex].Position;

            if (mode == ControlPointMode.Aligned)
            {
                enforcedTangent.Normalize();
                enforcedTangent *= Vector2.Distance(middle.Position, _Points[enforcedIndex].Position);
            }
            _Points[enforcedIndex].SetPosition(middle.Position + enforcedTangent);
        }
Ejemplo n.º 12
0
        private ControlPointMode[] LoadJsonPointModeData(ControlPointModeDummy[] pointModeData)
        {
            ControlPointMode[] modePoints = new ControlPointMode[pointModeData.Length];

            for (int i = 0; i < pointModeData.Length; i++)
            {
                modePoints[i] = (ControlPointMode)Enum.Parse(typeof(ControlPointMode), pointModeData[i].Mode);
            }

            return(modePoints);
        }
Ejemplo n.º 13
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Right)
            {
                if (GetSpline.SelectTransform(new Vector2(e.X, e.Y)) != null && !GetSpline.SelectedTransform.IsCenter)
                {
                    ControlPointMode nextMode = MySpline.GetControlPointMode(GetSpline.SelectedTransform.Index).Next();
                    MySpline.SetControlPointMode(GetSpline.SelectedTransform.Index, nextMode);
                }
            }
        }
Ejemplo n.º 14
0
        private void EnforceMode(int _index)
        {
            int modeIndex = (_index + 1) / 3;

            ControlPointMode mode = modes[modeIndex];

            if (mode == ControlPointMode.Free || !isLooped && (modeIndex == 0 || modeIndex == modes.Count - 1))
            {
                return;
            }

            int middleIndex = modeIndex * 3;
            int fixedIndex, enforcedIndex;

            if (_index <= middleIndex)
            {
                fixedIndex = middleIndex - 1;
                if (fixedIndex < 0)
                {
                    fixedIndex = points.Count - 2;
                }
                enforcedIndex = middleIndex + 1;
                if (enforcedIndex >= points.Count - 2)
                {
                    enforcedIndex = 1;
                }
            }
            else
            {
                fixedIndex = middleIndex + 1;
                if (fixedIndex >= points.Count)
                {
                    fixedIndex = 1;
                }
                enforcedIndex = middleIndex - 1;
                if (enforcedIndex < 0)
                {
                    enforcedIndex = points.Count - 2;
                }
            }

            Vector3 middle          = points[middleIndex];
            Vector3 enforcedTangent = middle - points[fixedIndex];

            if (mode == ControlPointMode.Aligned)
            {
                enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, points[enforcedIndex]);
            }

            points[enforcedIndex] = middle + enforcedTangent;
        }
Ejemplo n.º 15
0
        private void EnforceMode(int index)
        {
            int modeIndex         = (index + 1) / 3;
            ControlPointMode mode = m_modes[modeIndex];

            if (mode == ControlPointMode.Free || !m_loop && (modeIndex == 0 || modeIndex == m_modes.Length - 1))
            {
                return;
            }

            int middleIndex = modeIndex * 3;
            int fixedIndex, enforcedIndex;

            if (index <= middleIndex)
            {
                fixedIndex = middleIndex - 1;
                if (fixedIndex < 0)
                {
                    fixedIndex = m_points.Length - 2;
                }
                enforcedIndex = middleIndex + 1;
                if (enforcedIndex >= m_points.Length)
                {
                    enforcedIndex = 1;
                }
            }
            else
            {
                fixedIndex = middleIndex + 1;
                if (fixedIndex >= m_points.Length)
                {
                    fixedIndex = 1;
                }
                enforcedIndex = middleIndex - 1;
                if (enforcedIndex < 0)
                {
                    enforcedIndex = m_points.Length - 2;
                }
            }

            Vector3 middle          = m_points[middleIndex];
            Vector3 enforcedTangent = middle - m_points[fixedIndex];

            if (mode == ControlPointMode.Aligned)
            {
                enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, m_points[enforcedIndex]);
            }
            m_points[enforcedIndex] = middle + enforcedTangent;
            RaiseControlPointChanged(enforcedIndex);
        }
 private void SetControlPointMode(int index, ControlPointMode mode)
 {
     if (target is SplineControlPoint)
     {
         for (int i = 0; i < targets.Length; ++i)
         {
             SplineControlPoint controlPoint = (SplineControlPoint)targets[i];
             m_splineBase.SetControlPointMode(controlPoint.Index, mode);
         }
     }
     else
     {
         m_splineBase.SetControlPointMode(index, mode);
     }
 }
Ejemplo n.º 17
0
    public void SetControlPointMode(int p, ControlPointMode mode)
    {
        int modeIndex = (p + 1) / 3;

        modes[modeIndex] = mode;

        /* If we are in loop mode, ensure both ends share the same constraint if either changed */
        if (loop)
        {
            if (modeIndex == 0)
            {
                modes[modes.Length - 1] = mode;
            }
            else if (modeIndex == modes.Length - 1)
            {
                modes[0] = mode;
            }
        }
        EnforceConstraintMode(p);
    }
Ejemplo n.º 18
0
        private static void SetMode(GameObject selected, ControlPointMode mode)
        {
            Spline spline = selected.GetComponentInParent <Spline>();

            if (spline == null)
            {
                return;
            }

            SplineControlPoint selectedControlPoint = selected.GetComponent <SplineControlPoint>();

            if (selectedControlPoint != null)
            {
                SplineBaseEditor.SetMode(spline, mode, selectedControlPoint.Index);
            }
            else
            {
                SplineBaseEditor.SetMode(spline, mode);
            }
        }
Ejemplo n.º 19
0
        public void SetControlPointMode(int index, ControlPointMode mode)
        {
            var modeIndex = (index + 1) / 3;

            _controlPointModes[modeIndex] = mode;

            if (_isLoop)
            {
                if (modeIndex == 0)
                {
                    _controlPointModes[_controlPointModes.Length - 1] = mode;
                }
                else if (modeIndex == _controlPointModes.Length - 1)
                {
                    _controlPointModes[0] = mode;
                }
            }

            EnforceMode(index);
        }
Ejemplo n.º 20
0
        public void SetMode(int _index, ControlPointMode _mode)
        {
            int modeIndex = (_index + 1) / 3;

            modes[modeIndex] = _mode;

            if (isLooped)
            {
                if (modeIndex == 0)
                {
                    modes[modes.Count - 1] = _mode;
                }
                else if (modeIndex == modes.Count - 1)
                {
                    modes[0] = _mode;
                }
            }

            EnforceMode(_index);
            hasChanged = true;
        }
Ejemplo n.º 21
0
        public static void SetMode(MeshDeformer deformer, ControlPointMode mode, bool isRigid)
        {
            ScaffoldWrapper[] scaffolds = deformer.Scaffolds;
            for (int s = 0; s < scaffolds.Length; ++s)
            {
                ScaffoldWrapper scaffold = scaffolds[s];
                for (int i = 0; i < scaffold.CurveIndices.Length; ++i)
                {
                    int curveIndex = scaffold.CurveIndices[i];
                    if (mode == ControlPointMode.Free)
                    {
                        deformer.SetIsRigid(curveIndex * 3, isRigid);
                    }

                    if (!isRigid)
                    {
                        deformer.SetControlPointMode(curveIndex * 3, mode);
                        deformer.SetControlPointMode(curveIndex * 3 + 3, mode);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public void SetControlPointMode(int index, ControlPointMode mode)
        {
            if (index == Setup.CenterSplineIndex)
            {
                return;
            }

            int modeIndex = (index + 1) / 3;

            _Modes[modeIndex] = mode;
            if (_Loop)
            {
                if (modeIndex == 0)
                {
                    _Modes[_Modes.Length - 1] = mode;
                }
                else if (modeIndex == _Modes.Length - 1)
                {
                    _Modes[0] = mode;
                }
            }
            EnforceMode(index);
        }
Ejemplo n.º 23
0
        private static void SetMode(GameObject selected, ControlPointMode mode)
        {
            Spline spline = selected.GetComponentInParent <Spline>();

            if (spline == null)
            {
                return;
            }

            SplineControlPoint selectedControlPoint = selected.GetComponent <SplineControlPoint>();

            Undo.RecordObject(spline, "Battlehub.Spline.SetMode");
            EditorUtility.SetDirty(spline);

            if (selectedControlPoint != null)
            {
                spline.SetControlPointMode(selectedControlPoint.Index, mode);
            }
            else
            {
                spline.SetControlPointMode(mode);
            }
        }
Ejemplo n.º 24
0
    private void DrawSelectedPointInspector()
    {
        GUILayout.Label("Selected Point");
        EditorGUI.BeginChangeCheck();
        Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, point);
        }

        EditorGUI.BeginChangeCheck();
        ControlPointMode mode = (ControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Point Mode");
            spline.SetControlPointMode(selectedIndex, mode);
            EditorUtility.SetDirty(spline);
        }
    }
Ejemplo n.º 25
0
        protected void AppendCurve(Vector3[] points, ControlPointSetting setting, ControlPointMode mode, bool enforceNeighbour)
        {
            Array.Resize(ref m_points, m_points.Length + points.Length);
            Array.Resize(ref m_settings, m_settings.Length + points.Length / 3);
            Array.Resize(ref m_modes, m_modes.Length + points.Length / 3);

            for (int i = 0; i < points.Length; i++)
            {
                m_points[m_points.Length - points.Length + i] = points[i];
            }

            for (int i = 0; i < points.Length / 3; i++)
            {
                m_settings[m_settings.Length - points.Length / 3 + i] = setting;
                m_modes[m_modes.Length - points.Length / 3 + i]       = mode;
                RaiseControlPointModeChanged(m_modes.Length - points.Length / 3 + i);
            }

            if (enforceNeighbour)
            {
                EnforceMode(m_points.Length - points.Length - 2);
            }
            else
            {
                EnforceMode(m_points.Length - points.Length);
            }

            if (m_loop)
            {
                m_points[0]   = m_points[m_points.Length - 1];
                m_settings[0] = m_settings[m_settings.Length - 1];
                m_modes[0]    = m_modes[m_modes.Length - 1];
                RaiseControlPointModeChanged(0);
                EnforceMode(m_points.Length - 1);
            }
            SyncCtrlPoints();
        }
Ejemplo n.º 26
0
        protected void SetPoints(int curveIndex, Vector3[] points, ControlPointMode mode, bool raiseCurveChanged)
        {
            int index = curveIndex * 3;

            for (int i = 0; i < points.Length; ++i)
            {
                m_points[index] = points[i];
                RaiseControlPointChanged(index);

                SetControlPointMode(index, mode, raiseCurveChanged);
                index++;
            }

            EnforceMode(index);
#if UNITY_EDITOR
            m_persistentVersions[0]++;
            OnVersionChanged();
#endif

            if (raiseCurveChanged)
            {
                OnCurveChanged(index, Math.Max(0, (index - 1) / 3));
            }
        }
        public void AddCurve(int _atIndex, ControlPointMode _defaultMode = ControlPointMode.Mirrored)
        {
            Vector3 p1 = points[_atIndex * 3];
            Vector3 p2 = points[(_atIndex + 1) * 3];
            Vector3 center = (p1 + p2) * 0.5f;
            Vector3 direction = (p2 - p1).normalized;

            points.InsertRange((_atIndex * 3) + 2, new Vector3[]
            {
                center - direction,
                center,
                center + direction
            });

            modes.Insert(_atIndex, _defaultMode);
            EnforceMode(_atIndex);

            if (isLooped)
            {
                points[points.Count - 1] = points[0];
                modes[modes.Count - 1] = modes[0];
                EnforceMode(0);
            }

            hasChanged = true;
        }
Ejemplo n.º 28
0
    /*
     *  Function which will enforce the constraint between points
     *	To be called when a a point is Set or a mode is Set
     */

    public void EnforceConstraintMode(int index)
    {
        // get current mode
        int curModeIndex      = (index + 1) / 3;
        ControlPointMode mode = modes[curModeIndex];

        /* We can only enforce the constraint on points which belong to the union of 2 curves.
         * We disregard the extreme cases IFF NOT LOOPING (first and last control point and the case on which the mode
         * is FREE, since there is nothing to adjust
         */
        if (mode == ControlPointMode.FREE || !loop && (curModeIndex == 0 || curModeIndex == modes.Length - 1))
        {
            return;
        }

        /*
         *	Find the middle point
         *	1. if the middle is selected:
         *		a. adjust the one after it
         *	2. else, adjust the opposite of the currently selected
         *
         *  3. LOOPING:
         *      If we are looping, we have to ROLL over indexes.
         */
        int midIndex = curModeIndex * 3, fixIndex, adjustIndex;

        if (midIndex <= index)
        {
            fixIndex = midIndex - 1;
            if (fixIndex < 0)   // loop case
            {
                fixIndex = controlPoints.Length - 2;
            }
            adjustIndex = midIndex + 1;              // this will be the adjusted one
            if (adjustIndex >= controlPoints.Length) // loop case
            {
                adjustIndex = 1;
            }
        }
        else
        {
            fixIndex = midIndex + 1;
            if (fixIndex >= controlPoints.Length)  // loop case
            {
                fixIndex = 1;
            }
            adjustIndex = midIndex - 1;
            if (adjustIndex < 0)  // loop case
            {
                adjustIndex = controlPoints.Length - 2;
            }
        }


        Vector3 middlePoint = controlPoints[midIndex];

        /*  Mirroring */
        Vector3 enforcedTangent = middlePoint - controlPoints[fixIndex];

        /* Align - respect distance */
        if (mode == ControlPointMode.ALIGNED)
        {
            enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middlePoint, controlPoints[adjustIndex]);
        }
        controlPoints[adjustIndex] = middlePoint + enforcedTangent;
    }
        protected void DrawSelectedPointInspector()
        {
            if (DrawSelectedPointInspectorOverride())
            {
                EditorGUI.BeginChangeCheck();
                ControlPointMode mode = (ControlPointMode)
                                        EditorGUILayout.EnumPopup("Mode", m_splineBase.GetControlPointMode(m_selectedIndex));
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, UNDO_CHANGEMODE);
                    EditorUtility.SetDirty(m_splineBase);
                    SetControlPointMode(m_selectedIndex, mode);
                }

                EditorGUI.BeginChangeCheck();

                int   index = (m_selectedIndex / 3) * 3;
                Twist twist = m_splineBase.GetTwist(index);
                EditorGUI.BeginChangeCheck();
                float twistAngle = EditorGUILayout.FloatField("Twist Angle", twist.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Twist Angle");
                    EditorUtility.SetDirty(m_splineBase);
                    twist.Data = twistAngle;
                    SetTwist(index, twist);
                }


                if (m_splineBase.Loop || m_selectedIndex / 3 < m_splineBase.CurveCount)
                {
                    float t1 = twist.T1;
                    float t2 = twist.T2;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.MinMaxSlider(new GUIContent("Twist Offset"), ref t1, ref t2, 0.0f, 1.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Twist Offset");
                        EditorUtility.SetDirty(m_splineBase);
                        twist.T1 = t1;
                        twist.T2 = t2;
                        SetTwist(index, twist);
                    }
                }

                Thickness thickness = m_splineBase.GetThickness(index);
                EditorGUI.BeginChangeCheck();
                Vector3 thicknessValue = EditorGUILayout.Vector3Field("Thickness", thickness.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Thickness");
                    EditorUtility.SetDirty(m_splineBase);
                    thickness.Data = thicknessValue;
                    SetThickness(index, thickness);
                }

                if (m_splineBase.Loop || m_selectedIndex / 3 < m_splineBase.CurveCount)
                {
                    float t1 = thickness.T1;
                    float t2 = thickness.T2;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.MinMaxSlider(new GUIContent("Thickness Offset"), ref t1, ref t2, 0.0f, 1.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Thickness Offset");
                        EditorUtility.SetDirty(m_splineBase);
                        thickness.T1 = t1;
                        thickness.T2 = t2;
                        SetThickness(index, thickness);
                    }
                }


                Wrap wrap = m_splineBase.GetWrap(index);
                EditorGUI.BeginChangeCheck();
                float wrapValue = EditorGUILayout.FloatField("Wrap Curvature", wrap.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Wrap");
                    EditorUtility.SetDirty(m_splineBase);
                    wrap.Data = wrapValue;
                    SetWrap(index, wrap);
                }

                if (m_splineBase.Loop || m_selectedIndex / 3 < m_splineBase.CurveCount)
                {
                    float t1 = wrap.T1;
                    float t2 = wrap.T2;
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.MinMaxSlider(new GUIContent("Wrap Offset"), ref t1, ref t2, 0.0f, 1.0f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Wrap Offset");
                        EditorUtility.SetDirty(m_splineBase);
                        wrap.T1 = t1;
                        wrap.T2 = t2;
                        SetWrap(index, wrap);
                    }
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();

                int   index = (m_selectedIndex / 3) * 3;
                Twist twist = m_splineBase.GetTwist(index);
                EditorGUI.BeginChangeCheck();
                float twistAngle = EditorGUILayout.FloatField("Twist Angle", twist.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Twist Angle");
                    EditorUtility.SetDirty(m_splineBase);
                    twist.Data = twistAngle;
                    SetTwist(index, twist);
                }

                Thickness thickness = m_splineBase.GetThickness(index);
                EditorGUI.BeginChangeCheck();
                Vector3 thicknessValue = EditorGUILayout.Vector3Field("Thickness", thickness.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Thickness");
                    EditorUtility.SetDirty(m_splineBase);
                    thickness.Data = thicknessValue;
                    SetThickness(index, thickness);
                }

                Wrap wrap = m_splineBase.GetWrap(index);
                EditorGUI.BeginChangeCheck();
                float wrapValue = EditorGUILayout.FloatField("Wrap Curvature", wrap.Data);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_splineBase, "Battlehub.MeshDeformer2 Wrap");
                    EditorUtility.SetDirty(m_splineBase);
                    wrap.Data = wrapValue;
                    SetWrap(index, wrap);
                }
            }
        }
        public void SetMode(int _index, ControlPointMode _mode)
        {
            int modeIndex = (_index + 1) / 3;
            modes[modeIndex] = _mode;

            if (isLooped)
            {
                if(modeIndex == 0)
                {
                    modes[modes.Count - 1] = _mode;
                }
                else if(modeIndex == modes.Count - 1)
                {
                    modes[0] = _mode;
                }
            }

            EnforceMode(_index);
            hasChanged = true;
        }
Ejemplo n.º 31
0
 public void SetControlPointMode(int index, ControlPointMode mode)
 {
     modes[(index + 1) / 3] = mode;
     EnforceMode(index);
 }
Ejemplo n.º 32
0
        public static Spline CreateSpline(Vector3 position, Thickness thickness, Twist twist, ControlPointMode mode = ControlPointMode.Mirrored, string undorecord = "Battlehub.Spline.Create")
        {
            GameObject spline = new GameObject();

            spline.name = "Spline";

            if (!FindObjectOfType <GLRenderer>())
            {
                GameObject go = new GameObject();
                go.name = "GLRenderer";
                go.AddComponent <GLRenderer>();
            }

            Undo.RegisterCreatedObjectUndo(spline, undorecord);

            Spline splineComponent = spline.AddComponent <Spline>();

            splineComponent.SetControlPointMode(mode);
            splineComponent.SetTwist(0, twist);
            splineComponent.SetTwist(3, twist);
            splineComponent.SetThickness(0, thickness);
            splineComponent.SetThickness(3, thickness);
            spline.transform.position = position;

            return(splineComponent);
        }