コード例 #1
0
ファイル: SplineEditor.cs プロジェクト: qipa/SplineMesh
 void DeleteNode(SplineNode node)
 {
     if (spline.nodes.Count > 2)
     {
         spline.RemoveNode(node);
     }
 }
コード例 #2
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.F))
            {
                CurveSample sample = spline.GetSample(0.5f);
                spline.InsertNode(1, (new SplineNode(sample.location + Vector3.left * 3, (spline.nodes[0].Direction + spline.nodes[1].Direction) / 2)));

                GetComponent <SplineMeshTiling>().CreateMeshes();

                Debug.Log(sample.distanceInCurve + "|" + sample.timeInCurve);
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                spline.RemoveNode(spline.nodes[spline.nodes.Count - 1]);
                GetComponent <SplineMeshTiling>().CreateMeshes();
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                CurveSample sample = spline.GetSample(spline.nodes.Count - 2 + 0.5f);
                spline.nodes[spline.nodes.Count - 1].Position = sample.location;
                GetComponent <SplineMeshTiling>().CreateMeshes();
            }
        }
コード例 #3
0
    public void visualizeUndeformed(string frameName)
    {
        Frame targetFrame = myConstructorController.findFrame(frameName);

        targetFrame.setReleaseNeither();
        SplineMesh.Spline targetSpline = targetFrame.GetGameObject().GetComponentInChildren <SplineMesh.Spline>();
        int numNodesPrevious           = targetSpline.nodes.Count;

        while (targetSpline.nodes.Count > 2)
        {
            targetSpline.RemoveNode(targetSpline.nodes[targetSpline.nodes.Count - 1]);
        }

        targetSpline.nodes[0].Position  = new Vector3(0, 0, 0);
        targetSpline.nodes[0].Direction = new Vector3(0, (float)0.001, 0);
        targetSpline.nodes[1].Position  = new Vector3(0, 1, 0);
        targetSpline.nodes[1].Position  = new Vector3(0, (float)1.001, 0);
    }
コード例 #4
0
        private void UpdateSpline()
        {
            foreach (var penisNode in wayPoints.ToList())
            {
                if (penisNode == null)
                {
                    wayPoints.Remove(penisNode);
                }
            }
            int nodeCount = wayPoints.Count;

            // adjust the number of nodes in the spline.
            while (spline.nodes.Count < nodeCount)
            {
                spline.AddNode(new SplineNode(Vector3.zero, Vector3.zero));
            }
            while (spline.nodes.Count > nodeCount && spline.nodes.Count > 2)
            {
                spline.RemoveNode(spline.nodes.Last());
            }
        }
コード例 #5
0
ファイル: SplineEditor.cs プロジェクト: ntratcliff/SplineMesh
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            // hint
            EditorGUILayout.HelpBox("Hold shift and drag a node to create a new one.", MessageType.Info);

            // add button
            if (selection == null)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Add node after selected"))
            {
                Undo.RegisterCompleteObjectUndo(spline, "add spline node");
                SplineNode newNode = new SplineNode(selection.Direction, selection.Direction + selection.Direction - selection.Position);
                var        index   = spline.nodes.IndexOf(selection);
                if (index == spline.nodes.Count - 1)
                {
                    spline.AddNode(newNode);
                }
                else
                {
                    spline.InsertNode(index + 1, newNode);
                }
                selection = newNode;
            }
            GUI.enabled = true;

            // delete button
            if (selection == null || spline.nodes.Count <= 2)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Delete selected node"))
            {
                Undo.RegisterCompleteObjectUndo(spline, "delete spline node");
                spline.RemoveNode(selection);
                selection = null;
            }
            GUI.enabled = true;

            showUpVector  = GUILayout.Toggle(showUpVector, "Show up vector");
            spline.IsLoop = GUILayout.Toggle(spline.IsLoop, "Is loop (experimental)");

            // nodes
            EditorGUILayout.PropertyField(nodesProp);
            EditorGUI.indentLevel++;
            if (nodesProp.isExpanded)
            {
                for (int i = 0; i < nodesProp.arraySize; i++)
                {
                    SerializedProperty nodeProp = nodesProp.GetArrayElementAtIndex(i);
                    EditorGUILayout.PropertyField(nodeProp);
                    EditorGUI.indentLevel++;
                    if (nodeProp.isExpanded)
                    {
                        drawNodeData(nodeProp, spline.nodes[i]);
                    }
                    EditorGUI.indentLevel--;
                }
            }
            EditorGUI.indentLevel--;

            if (selection != null)
            {
                int index = spline.nodes.IndexOf(selection);
                SerializedProperty nodeProp = nodesProp.GetArrayElementAtIndex(index);
                EditorGUILayout.LabelField("Selected node (node " + index + ")");
                EditorGUI.indentLevel++;
                drawNodeData(nodeProp, selection);
                EditorGUI.indentLevel--;
            }
            else
            {
                EditorGUILayout.LabelField("No selected node");
            }
        }