Esempio n. 1
0
    void BranchEdit(SPData SPData)
    {
        if (!SPData.IsLooped && SPData.ObjectType != SPType.Extrude)
        {
            AddBranch(SPData);
        }

        if (SPData.DictBranches.Count == 0)
        {
            return;
        }
        if (GUI.Button(new Rect(272, 30, 30, 30), new GUIContent(SplinePlusEditor.Delete.image, "Delete the selected node "), GUIStyle.none) && EditorUtility.DisplayDialog("Branch deletion?",
                                                                                                                                                                            "Are you sure you want to delete this branch? "
                                                                                                                                                                            , "Yes", "No"))
        {
            BranchesClass.DeleteBranch(SPData, SPData.Selections._BranchKey);
            SceneView.RepaintAll();
        }

        if (GUI.Button(new Rect(304, 30, 30, 30), new GUIContent(SplinePlusEditor.FlipHandles.image, "Flips the handles of the selected node "), GUIStyle.none))
        {
            Undo.RecordObject(SPData.SplinePlus, "handles Fliped");
            BranchesClass.FlipHandles(SPData, SPData.Selections._BranchKey, SPData.Selections._LocalNodeIndex);

            EditorUtility.SetDirty(SPData.SplinePlus);
        }
        var rec = new Rect(336, 30, 30, 30);

        if (SPData.ObjectType != SPType.Extrude && !SPData.IsLooped)
        {
            rec = new Rect(368, 30, 30, 30);
            if (GUI.Button(new Rect(336, 30, 30, 30), new GUIContent(SplinePlusEditor.BreakAt.image, "Break the selected branch at the selected node"), GUIStyle.none))
            {
                if (!SPData.Selections._PathPoint.Equals(null))
                {
                    Undo.RecordObject(SPData.SplinePlus, "Break at branch");
                    var node = SPData.Selections._PathPoint;
                    BranchesClass.BreakBranch(SPData, node);
                    EditorUtility.SetDirty(SPData.SplinePlus);
                }
                else
                {
                    EditorUtility.DisplayDialog("Error",
                                                "You need to have a node selected where you want your branch to be broken at "
                                                , "Ok");
                }
            }
        }
        else
        {
            rec = new Rect(336, 30, 30, 30);
        }

        if (GUI.Button(rec, new GUIContent(SplinePlusEditor.Reverse.image, "Reverse the direction of the selected branch "), GUIStyle.none))
        {
            Undo.RecordObject(SPData.SplinePlus, "branch Reversed");
            BranchesClass.ReverseBranch(SPData, SPData.Selections._BranchKey);
            EditorUtility.SetDirty(SPData.SplinePlus);
        }
    }
Esempio n. 2
0
    public static void SmoothSharedPathPoint(SPData SPData, SharedNode sharedNode, float radius)
    {
        SPData.SmoothData.InitNodePos     = sharedNode.Node.Point.position;
        SPData.SmoothData.Nodes           = new Node[sharedNode.ConnectedBranches.Count];
        SPData.SmoothData.BranchesIndices = sharedNode.ConnectedBranches.ToArray();

        //shared path point breaking
        for (int i = 0; i < SPData.SmoothData.Nodes.Length; i++)
        {
            var branchKey = sharedNode.ConnectedBranches[i];

            var localIndex = sharedNode.Node.LocalIndex(SPData, branchKey);

            if (localIndex != 0)
            {
                BranchesClass.ReverseBranch(SPData, branchKey);
            }

            var duplicate = DuplicatePathPoint(SPData, SPData.DictBranches[branchKey].Nodes[0]);
            SPData.SmoothData.Nodes[i] = duplicate;
            SPData.DictBranches[branchKey].Nodes[0] = duplicate;
        }

        for (int i = 0; i < SPData.SmoothData.Nodes.Length; i++)
        {
            var branchKey = SPData.SmoothData.BranchesIndices[i];
            BranchesClass.FlipHandles(SPData, branchKey, 0);

            var mid = Vector3.Lerp(SPData.DictBranches[branchKey].Nodes[0].Point.position,
                                   SPData.DictBranches[branchKey].Nodes[1].Point.position, 0.5f);

            SPData.SmoothData.Nodes[i].Point.position = Vector3.Lerp(SPData.SmoothData.InitNodePos,
                                                                     mid, radius);

            SPData.SmoothData.Nodes[i].Point2.position      = SPData.SmoothData.InitNodePos;
            SPData.SmoothData.Nodes[i].Point1.localPosition = -SPData.SmoothData.Nodes[i].Point2.localPosition;
        }

        // path points welding
        for (int i = 0; i < SPData.SmoothData.Nodes.Length; i++)// path points created after chamfer,
        {
            for (int n = i; n < SPData.SmoothData.Nodes.Length; n++)
            {
                if (n == i)
                {
                    continue;
                }
                ConnectTwoNodes(SPData, SPData.SmoothData.Nodes[n], SPData.SmoothData.Nodes[i]);
            }
        }

        // remove initiale shared path point
        SPData.SharedNodes.Remove(sharedNode);
        MonoBehaviour.DestroyImmediate(sharedNode.Node.Point.gameObject);
    }