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); } }
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); }
public void SmoothSharedPathPoint(SPData SPData) { var node = SPData.Selections._PathPoint; //cach data for restore procedure SPData.SmoothData.InitNodePos = node.Point.position; var sharedPathPointIndex = SPData.Selections._SharedPathPointIndex; SPData.SmoothData.Nodes = new Node[SPData.SharedNodes[sharedPathPointIndex].ConnectedBranches.Count]; SPData.SmoothData.BranchesIndices = SPData.SharedNodes[sharedPathPointIndex].ConnectedBranches.ToArray(); //shared path point breaking for (int i = 0; i < SPData.SmoothData.Nodes.Length; i++) { var branchKey = SPData.SharedNodes[sharedPathPointIndex].ConnectedBranches[i]; var localIndex = node.LocalIndex(SPData, branchKey); var duplicate = SplinePlusAPI.DuplicatePathPoint(SPData, node); SPData.SmoothData.Nodes[i] = duplicate; SPData.DictBranches[branchKey].Nodes[localIndex] = duplicate; if (localIndex != 0) { BranchesClass.FlipHandles(SPData, branchKey, localIndex); } } SPData.SmoothData.newBranchesIndices = new List <int>(); //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; } //UpdateAllLinks var t = SplinePlusAPI.ConnectTwoNodes(SPData, SPData.SmoothData.Nodes[n], SPData.SmoothData.Nodes[i]); SPData.SmoothData.newBranchesIndices.Add(t); BranchesClass.FlipHandles(SPData, t, 0); BranchesClass.FlipHandles(SPData, t, 1); } } EditSmoothNodePoint(SPData, SPData.SmoothRadius); }
public static int ConnectTwoNodes(SPData SPData, Node pathPoint1, Node pathPoint2) { foreach (var branch in SPData.DictBranches) {// avoid creating duplicate branches if (branch.Value.Nodes[0].Equals(pathPoint1) && branch.Value.Nodes[branch.Value.Nodes.Count - 1].Equals(pathPoint2)) { return(branch.Key); } else if (branch.Value.Nodes[0].Equals(pathPoint2) && branch.Value.Nodes[branch.Value.Nodes.Count - 1].Equals(pathPoint1)) { return(branch.Key); } } var newBranch = new Branch(); newBranch.Nodes.Add(pathPoint1); newBranch.Nodes.Add(pathPoint2); SPData.DictBranches.Add(SPData.BranchesCount, newBranch); SPData.Selections._BranchKey = SPData.BranchesCount; SPData.BranchesCount++; BranchesClass.FlipHandles(SPData, SPData.Selections._BranchKey, 1); // detect if newly created branch has shared path points IsSharedPathPoint(SPData, pathPoint1, SPData.Selections._BranchKey); IsSharedPathPoint(SPData, pathPoint2, SPData.Selections._BranchKey); SPData.SplinePlus.SplineCreationClass.UpdateBranch(SPData, newBranch); SPData.Selections._PathPoint = SPData.DictBranches[SPData.Selections._BranchKey].Nodes[0]; return(SPData.Selections._BranchKey); }