Esempio n. 1
0
 private void Update()
 {
     if (morphStates.Length == 0)
     {
         return;
     }
     for (int i = 0; i < computer.pointCount; i++)
     {
         Vector3 pos    = morphStates[0].points[i].position;
         Vector3 tan    = morphStates[0].points[i].tangent;
         Vector3 tan2   = morphStates[0].points[i].tangent2;
         Vector3 normal = morphStates[0].points[i].normal;
         Color   col    = morphStates[0].points[i].color;
         float   size   = morphStates[0].points[i].size;
         for (int n = 1; n < morphStates.Length; n++)
         {
             pos    += (morphStates[n].points[i].position - morphStates[0].points[i].position) * morphStates[n].percent;
             tan    += (morphStates[n].points[i].tangent - morphStates[0].points[i].tangent) * morphStates[n].percent;
             tan2   += (morphStates[n].points[i].tangent2 - morphStates[0].points[i].tangent2) * morphStates[n].percent;
             normal += (morphStates[n].points[i].normal - morphStates[0].points[i].normal) * morphStates[n].percent;
             col    += (morphStates[n].points[i].color - morphStates[0].points[i].color) * morphStates[n].percent;
             size   += (morphStates[n].points[i].size - morphStates[0].points[i].size) * morphStates[n].percent;
         }
         SplinePoint point = computer.GetPoint(i, Space.Local);
         point.type     = SplinePoint.Type.Broken;
         point.position = pos;
         point.tangent  = tan;
         point.tangent2 = tan2;
         point.normal   = normal;
         point.color    = col;
         point.size     = size;
         computer.SetPoint(i, point, Space.Local);
     }
 }
Esempio n. 2
0
        void AddConnection(SplineComputer computer, int pointIndex)
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            if (EditorUtility.DisplayDialog("Link point?", "Add point " + pointIndex + " to connections?", "Yes", "No"))
            {
                Undo.RecordObject(addComp, "Add connection");
                Undo.RecordObject(node, "Add Connection");
                if (connections.Length == 0)
                {
                    switch (EditorUtility.DisplayDialogComplex("Align node to point?", "This is the first connection for the node, would you like to snap or align the node's Transform the spline point.", "No", "Snap", "Snap and Align"))
                    {
                    case 1: SplinePoint point = addComp.GetPoint(pointIndex);
                        node.transform.position = point.position;
                        break;

                    case 2:
                        SplineResult result = addComp.Evaluate((double)pointIndex / (addComp.pointCount - 1));
                        node.transform.position = result.position;
                        node.transform.rotation = result.rotation;
                        break;
                    }
                }
                node.AddConnection(computer, pointIndex);
                addComp  = null;
                addPoint = 0;
                SceneView.RepaintAll();
                Repaint();
            }
        }
Esempio n. 3
0
 void OnSceneGUI(SceneView sceneView)
 {
     Handles.BeginGUI();
     for (int i = 0; i < pointIndices.Count; i++)
     {
         Vector2 screenPosition = HandleUtility.WorldToGUIPoint(currentComputer.GetPoint(pointIndices[i]).position);
         screenPosition.y -= 25f;
         string pointName = "P" + pointIndices[i];
         SplineEditorGUI.Label(new Rect(screenPosition.x - 120 + pointName.Length * 4, screenPosition.y, 120, 25), pointName);
     }
     Handles.EndGUI();
 }
Esempio n. 4
0
 /// <summary>
 /// Adds new columns.
 /// New points of the spline are added. Their positions are calculated from their twin predecessor in the spline.
 /// </summary>
 /// <param name="newPoints"> Overall count of points wanted in the new spline. </param>
 /// <param name="sc"> SplineComputer of the spline that is being adjusted. </param>
 protected void AddColumns(int newPoints, SplineComputer sc)
 {
     for (int i = 0; i < newPoints; ++i)
     {
         int index     = currentPointCount - basePointCount + 1;
         var twinPoint = sc.GetPoint(index);
         sc.SetPointPosition(currentPointCount, new Vector3(twinPoint.position.x + width, twinPoint.position.y, twinPoint.position.z));
         sc.SetPointSize(currentPointCount, point_size);
         sc.SetPointColor(currentPointCount, Color.white);
         sc.SetPointNormal(currentPointCount, sc.GetPointNormal(index));
         currentPointCount++;
     }
 }
Esempio n. 5
0
        public static int PointSelectionMenu(SplineComputer computer, int selected = 0, string title = "Select point")
        {
            GUILayout.Box(title, GUILayout.Width(Screen.width - 45), GUILayout.Height(50));
            GUI.BeginGroup(GUILayoutUtility.GetLastRect());
            string[] options = new string[(computer.isClosed ? computer.pointCount - 1 : computer.pointCount) + 1];
            for (int i = 0; i < options.Length - 1; i++)
            {
                options[i + 1] = "Point " + i;
                if (computer.type == Spline.Type.Bezier)
                {
                    options[i + 1] = "Point " + i + " Bezier " + (computer.GetPoint(i, SplineComputer.Space.Local).type == SplinePoint.Type.Smooth ? "(smooth)" : "(broken)");
                }
            }
            options[0] = "- Select -";
            int selection = EditorGUI.Popup(new Rect(10, 25, Screen.width - 65, 30), selected, options) - 1;

            GUI.EndGroup();
            return(selection);
        }
Esempio n. 6
0
        public virtual void AddConnection(SplineComputer computer, int pointIndex)
        {
            RemoveInvalidConnections();
            Node connected = computer.GetNode(pointIndex);

            if (connected != null)
            {
                Debug.LogError(computer.name + " is already connected to node " + connected.name + " at point " + pointIndex);
                return;
            }
            SplinePoint point = computer.GetPoint(pointIndex);

            point.SetPosition(transform.position);
            ArrayUtility.Add(ref connections, new Connection(computer, pointIndex, PointToLocal(point)));
            if (connections.Length == 1)
            {
                SetPoint(connections.Length - 1, point, true);
            }
            UpdateConnectedComputers();
        }
Esempio n. 7
0
        public virtual void AddConnection(SplineComputer computer, int pointIndex)
        {
            RemoveInvalidConnections();
            for (int i = 0; i < computer.nodeLinks.Length; i++)
            {
                if (computer.nodeLinks[i].pointIndex == pointIndex)
                {
                    Debug.LogError("Connection has been already added in " + computer.nodeLinks[i].node);
                    return;
                }
            }
            SplinePoint point = computer.GetPoint(pointIndex);

            point.SetPosition(transform.position);
            Connection newConnection = new Connection(computer, pointIndex, PointToLocal(point));

            Connection[] newConnections = new Connection[connections.Length + 1];
            connections.CopyTo(newConnections, 0);
            newConnections[connections.Length] = newConnection;
            connections = newConnections;
            SetPoint(connections.Length - 1, point);
            computer.AddNodeLink(this, pointIndex);
            UpdateConnectedComputers();
        }
Esempio n. 8
0
        public virtual void AddConnection(SplineComputer computer, int pointIndex)
        {
            RemoveInvalidConnections();
            for (int i = 0; i < computer.nodeLinks.Length; i++)
            {
                if (computer.nodeLinks[i].pointIndex == pointIndex)
                {
                    UnityEngine.Debug.LogError("Connection has been already added in " + computer.nodeLinks[i].node);
                    return;
                }
            }
            SplinePoint point = computer.GetPoint(pointIndex);

            point.SetPosition(base.transform.position);
            Connection connection = new Connection(computer, pointIndex, PointToLocal(point));

            Connection[] array = new Connection[connections.Length + 1];
            connections.CopyTo(array, 0);
            array[connections.Length] = connection;
            connections = array;
            SetPoint(connections.Length - 1, point, swappedTangents: true);
            computer.AddNodeLink(this, pointIndex);
            UpdateConnectedComputers();
        }
Esempio n. 9
0
        public override void Draw()
        {
            base.Draw();
            string[] options = new string[(computer.isClosed ? computer.pointCount - 1 : computer.pointCount) + 1];
            for (int i = 0; i < options.Length - 1; i++)
            {
                options[i + 1] = "Point " + (i + 1);
                if (computer.type == Spline.Type.Bezier)
                {
                    options[i + 1] = "Point " + i + " Bezier " + (computer.GetPoint(i, SplineComputer.Space.Local).type == SplinePoint.Type.Smooth ? "(smooth)" : "(broken)");
                }
            }
            options[0] = "- Select -";
            BeginPanel();
            if (selection.Count == 1)
            {
                lastSelection = singleSelection = selection[0];
            }
            else if (selection.Count > 1)
            {
                lastSelection = singleSelection = -1;
            }
            singleSelection = EditorGUILayout.Popup(GetTitle(), singleSelection + 1, options) - 1;
            if (lastSelection != singleSelection)
            {
                Select();
            }

            switch (ButtonGroup(new string[] { "Select All", "Deselect All", "Select Inverse" }, 30, true))
            {
            case 0:
                selection       = new List <int>();
                singleSelection = lastSelection = -1;
                for (int i = 0; i < computer.pointCount; i++)
                {
                    if (i == computer.pointCount - 1 && computer.isClosed)
                    {
                        break;
                    }
                    selection.Add(i);
                }
                Select();
                break;

            case 1:
                selection       = new List <int>();
                singleSelection = lastSelection = -1;
                Select();
                break;

            case 2:
                singleSelection = lastSelection = -1;
                List <int> inverse = new List <int>();
                for (int i = 0; i < (computer.isClosed ? computer.pointCount - 1 : computer.pointCount); i++)
                {
                    bool found = false;
                    for (int j = 0; j < selection.Count; j++)
                    {
                        if (selection[j] == i)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        inverse.Add(i);
                    }
                }
                selection = new List <int>(inverse);
                Select();
                break;
            }

            EndPanel();
        }