internal static CSGTreeNode DuplicateInternal(CSGTreeNode node) { switch (node.Type) { case CSGNodeType.Brush: { var srcTreeBrush = (CSGTreeBrush)node; return(CSGTreeBrush.Create(srcTreeBrush.UserID, srcTreeBrush.LocalTransformation, srcTreeBrush.BrushMesh, srcTreeBrush.Operation, srcTreeBrush.Flags)); } case CSGNodeType.Tree: { var srcTree = (CSGTree)node; return(CSGTree.Create(srcTree.UserID, DuplicateChildNodesInternal(srcTree))); } case CSGNodeType.Branch: { var srcTreeBranch = (CSGTreeBranch)node; return(CSGTreeBranch.Create(srcTreeBranch.UserID, srcTreeBranch.Operation, DuplicateChildNodesInternal(srcTreeBranch))); } default: throw new NotImplementedException(); } }
/// <summary>Generates a tree returns a <see cref="Chisel.Core.CSGTree"/> struct that contains a reference to it.</summary> /// <param name="userID">A unique id to help identify this particular tree. For instance, this could be an InstanceID to a [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html).</param> /// <param name="children">The child nodes that are children of this tree. A tree may not have duplicate children, contain itself or contain a <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns>A new <see cref="Chisel.Core.CSGTree"/>. May be an invalid node if it failed to create it.</returns> public static CSGTree Create(Int32 userID, params CSGTreeNode[] children) { int treeNodeID; if (!GenerateTree(userID, out treeNodeID)) { return new CSGTree() { treeNodeID = 0 } } ; if (children != null && children.Length > 0) { if (!CSGTreeNode.SetChildNodes(treeNodeID, children)) { CSGTreeNode.DestroyNode(treeNodeID); return(new CSGTree() { treeNodeID = 0 }); } } return(new CSGTree() { treeNodeID = treeNodeID }); }
/// <summary>Generates a brush and returns a <see cref="Chisel.Core.CSGTreeBrush"/> struct that contains a reference to it.</summary> /// <param name="userID">A unique id to help identify this particular brush. For instance, this could be an InstanceID to a [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html)</param> /// <param name="localTransformation">The transformation of the brush relative to the tree root</param> /// <param name="brushMesh">A <see cref="Chisel.Core.BrushMeshInstance"/>, which is a reference to a <see cref="Chisel.Core.BrushMesh"/>.</param> /// <param name="operation">The <see cref="Chisel.Core.CSGOperationType"/> that needs to be performed with this <see cref="Chisel.Core.CSGTreeBrush"/>.</param> /// <param name="flags"><see cref="Chisel.Core.CSGTreeBrush"/> specific flags</param> /// <returns>A new <see cref="Chisel.Core.CSGTreeBrush"/>. May be an invalid node if it failed to create it.</returns> public static CSGTreeBrush Create(Int32 userID, Matrix4x4 localTransformation, BrushMeshInstance brushMesh = default(BrushMeshInstance), CSGOperationType operation = CSGOperationType.Additive, CSGTreeBrushFlags flags = CSGTreeBrushFlags.Default) { int brushNodeID; if (GenerateBrush(userID, out brushNodeID)) { if (localTransformation != default(Matrix4x4)) { CSGTreeNode.SetNodeLocalTransformation(brushNodeID, ref localTransformation); } if (operation != CSGOperationType.Additive) { CSGTreeNode.SetNodeOperationType(brushNodeID, operation); } if (flags != CSGTreeBrushFlags.Default) { SetBrushFlags(brushNodeID, flags); } if (brushMesh.Valid) { SetBrushMesh(brushNodeID, brushMesh); } } else { brushNodeID = 0; } return(new CSGTreeBrush() { brushNodeID = brushNodeID }); }
/// <summary>Generates a branch and returns a <see cref="Chisel.Core.CSGTreeBranch"/> struct that contains a reference to it.</summary> /// <param name="userID">A unique id to help identify this particular branch. For instance, this could be an InstanceID to a [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html)</param> /// <param name="children">The child nodes that are children of this branch. A branch may not have duplicate children, contain itself or contain a <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns>A new <see cref="Chisel.Core.CSGTreeBranch"/>. May be an invalid node if it failed to create it.</returns> public static CSGTreeBranch Create(Int32 userID, params CSGTreeNode[] children) { int branchNodeID; if (!GenerateBranch(userID, out branchNodeID)) { return new CSGTreeBranch() { branchNodeID = 0 } } ; if (children != null && children.Length > 0) { if (!CSGTreeNode.SetChildNodes(branchNodeID, children)) { CSGTreeNode.DestroyNode(branchNodeID); return(new CSGTreeBranch() { branchNodeID = 0 }); } } return(new CSGTreeBranch() { branchNodeID = branchNodeID }); }
/// <summary>Generates a branch and returns a <see cref="Chisel.Core.CSGTreeBranch"/> struct that contains a reference to it.</summary> /// <param name="userID">A unique id to help identify this particular branch. For instance, this could be an InstanceID to a [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html)</param> /// <param name="children">The child nodes that are children of this branch. A branch may not have duplicate children, contain itself or contain a <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns>A new <see cref="Chisel.Core.CSGTreeBranch"/>. May be an invalid node if it failed to create it.</returns> public static CSGTreeBranch Create(Int32 userID = 0, CSGOperationType operation = CSGOperationType.Additive, params CSGTreeNode[] children) { int branchNodeID; if (!GenerateBranch(userID, out branchNodeID)) { return new CSGTreeBranch() { branchNodeID = 0 } } ; if (children != null && children.Length > 0) { if (operation != CSGOperationType.Additive) { CSGTreeNode.SetNodeOperationType(userID, operation); } if (!CSGTreeNode.SetChildNodes(branchNodeID, children)) { CSGTreeNode.DestroyNode(branchNodeID); return(new CSGTreeBranch() { branchNodeID = 0 }); } } return(new CSGTreeBranch() { branchNodeID = branchNodeID }); }
private bool GetNodesInFrustum(Plane[] planes, out CSGTreeNode[] nodes) { nodes = null; if (planes == null || planes.Length != 6) { return(false); } var planesHandle = GCHandle.Alloc(planes, GCHandleType.Pinned); var planesPtr = planesHandle.AddrOfPinnedObject(); var itemCount = FindNodesInFrustum(treeNodeID, planes.Length, planesPtr); planesHandle.Free(); if (itemCount > 0) { nodes = new CSGTreeNode[itemCount]; var nodesHandle = GCHandle.Alloc(nodes, GCHandleType.Pinned); var nodesPtr = nodesHandle.AddrOfPinnedObject(); var result = RetrieveNodesInFrustum(nodes.Length, nodesPtr); nodesHandle.Free(); if (!result) { nodes = null; } } return(nodes != null); }
/// <summary>Inserts an array of <see cref="Chisel.Core.CSGTreeNode"/>s into the <see cref="Chisel.Core.CSGTree"/> at the specified index.</summary> /// <param name="index">The zero-based index at which the new <see cref="Chisel.Core.CSGTreeNode"/>s should be inserted.</param> /// <param name="array">The array whose <see cref="Chisel.Core.CSGTreeNode"/>s should be inserted into the <see cref="Chisel.Core.CSGTree"/>. The array itself cannot be null.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool InsertRange(int index, params CSGTreeNode[] array) { if (array == null) { throw new ArgumentNullException("array"); } return(CSGTreeNode.InsertChildNodeRange(treeNodeID, index, array)); }
/// <summary>Sets all the children of this <see cref="Chisel.Core.CSGTree"/> to the give array of <see cref="Chisel.Core.CSGTreeNode"/>s at the specified index.</summary> /// <param name="array">The array whose <see cref="Chisel.Core.CSGTreeNode"/>s should be inserted into the <see cref="Chisel.Core.CSGTree"/>. The array itself cannot be null.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool SetChildren(CSGTreeNode[] array) { if (array == null) { throw new ArgumentNullException("array"); } return(CSGTreeNode.SetChildNodes(treeNodeID, array)); }
/// <summary>Adds the <see cref="Chisel.Core.CSGTreeNode"/>s of the specified array to the end of the <see cref="Chisel.Core.CSGTree"/>.</summary> /// <param name="array">The array whose <see cref="Chisel.Core.CSGTreeNode"/>s should be added to the end of the <see cref="Chisel.Core.CSGTree"/>. The array itself cannot be null.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool AddRange(params CSGTreeNode[] array) { if (array == null) { throw new ArgumentNullException("array"); } return(CSGTreeNode.InsertChildNodeRange(treeNodeID, Count, array)); }
internal static CSGTreeNode[] DuplicateChildNodesInternal(CSGTree tree) { var childCount = tree.Count; if (childCount == 0) { return(new CSGTreeNode[0]); } var duplicateNodes = new CSGTreeNode[childCount]; for (int i = 0; i < childCount; i++) { duplicateNodes[i] = DuplicateInternal(tree[i]); } return(duplicateNodes); }
internal static CSGTreeNode[] GetChildNodes(Int32 nodeID) { var childCount = GetChildNodeCount(nodeID); var children = new CSGTreeNode[childCount]; if (childCount == 0) { return(children); } GCHandle childrenHandle = GCHandle.Alloc(children, GCHandleType.Pinned); IntPtr childrenPtr = childrenHandle.AddrOfPinnedObject(); GetChildNodes(nodeID, childCount, childrenPtr, 0); childrenHandle.Free(); return(children); }
private static CSGTreeNode[] GetAllTreeNodes() { var nodeCount = GetNodeCount(); var allTreeNodeIDs = new CSGTreeNode[nodeCount]; if (nodeCount == 0) { return(allTreeNodeIDs); } GCHandle allNodeIDsHandle = GCHandle.Alloc(allTreeNodeIDs, GCHandleType.Pinned); IntPtr allNodeIDsPtr = allNodeIDsHandle.AddrOfPinnedObject(); GetAllTreeNodes(nodeCount, allNodeIDsPtr); allNodeIDsHandle.Free(); return(allTreeNodeIDs); }
internal static CSGTreeNode[] DuplicateInternal(CSGTreeNode[] nodes) { if (nodes == null) { return(null); } if (nodes.Length == 0) { return(new CSGTreeNode[0]); } var duplicateNodes = new CSGTreeNode[nodes.Length]; for (int i = 0; i < nodes.Length; i++) { duplicateNodes[i] = DuplicateInternal(nodes[i]); } return(duplicateNodes); }
private static bool DeepDestroyNode(CSGTreeNode node) { if (!node.Valid) { return(false); } switch (node.Type) { case CSGNodeType.Branch: if (!DeepDestroyNodes(((CSGTreeBranch)node).ChildrenToArray())) { return(false); } break; case CSGNodeType.Tree: if (!DeepDestroyNodes(((CSGTree)node).ChildrenToArray())) { return(false); } break; } return(CSGTreeNode.DestroyNode(node.nodeID)); }
/// <summary>Destroy this <see cref="Chisel.Core.CSGTreeNode"/>. Sets the state to invalid.</summary> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool Destroy() { var prevTreeNodeID = treeNodeID; treeNodeID = CSGTreeNode.InvalidNodeID; return(CSGTreeNode.DestroyNode(prevTreeNodeID)); }
/// <summary>Force set the dirty flag of the <see cref="Chisel.Core.CSGTreeNode"/>.</summary> public void SetDirty() { CSGTreeNode.SetDirty(treeNodeID); }
/// <summary>Copies the <see cref="Chisel.Core.CSGTreeNode"/>s of the <see cref="Chisel.Core.CSGTree"/> to a new array.</summary> /// <returns>An array containing the <see cref="Chisel.Core.CSGTreeNode"/>s of the <see cref="Chisel.Core.CSGTree"/>.</returns> public CSGTreeNode[] ChildrenToArray() { return(CSGTreeNode.GetChildNodes(treeNodeID)); }
// TODO: add description public static CSGTreeNode Duplicate(CSGTreeNode node) { return(DuplicateInternal(node)); }
/// <summary>Inserts an element into the <see cref="Chisel.Core.CSGTreeNode"/> at the specified index.</summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="Chisel.Core.CSGTreeNode"/> to insert.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool Insert(int index, CSGTreeNode item) { return(CSGTreeNode.InsertChildNode(treeNodeID, index, item.nodeID)); }
/// <summary>Determines the index of a specific child in the <see cref="Chisel.Core.CSGTree"/>.</summary> /// <param name="item">The <see cref="Chisel.Core.CSGTreeNode"/> to locate in the <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns>The index of <paramref name="item"/> if found in the <see cref="Chisel.Core.CSGTree"/>; otherwise, –1.</returns> public int IndexOf(CSGTreeNode item) { return(CSGTreeNode.IndexOfChildNode(treeNodeID, item.nodeID)); }
/// <summary>Removes all children from the <see cref="Chisel.Core.CSGTree"/>.</summary> public void Clear() { CSGTreeNode.ClearChildNodes(treeNodeID); }
/// <summary>Removes a range of children from the <see cref="Chisel.Core.CSGTree"/>.</summary> /// <param name="index">The zero-based starting index of the range of children to remove.</param> /// <param name="count">The number of children to remove.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool RemoveRange(int index, int count) { return(CSGTreeNode.RemoveChildNodeRange(treeNodeID, index, count)); }
/// <summary>Removes a specific <see cref="Chisel.Core.CSGTreeNode"/> from the <see cref="Chisel.Core.CSGTree"/>.</summary> /// <param name="item">The <see cref="Chisel.Core.CSGTreeNode"/> to remove from the <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool Remove(CSGTreeNode item) { return(CSGTreeNode.RemoveChildNode(treeNodeID, item.nodeID)); }
/// <summary>Destroy a <see cref="Chisel.Core.CSGTreeNode"/>s and its children.</summary> /// <param name="node">The top level <see cref="Chisel.Core.CSGTreeNode"/> to destroy</param> /// <returns>True on success, false if there was a problem with destroying the <see cref="Chisel.Core.CSGTreeNode"/>. See the log for more information.</returns> public static bool DeepDestroy(CSGTreeNode node) { return(DeepDestroyNode(node)); }
/// <summary>Gets child at the specified index.</summary> /// <param name="index">The zero-based index of the child to get.</param> /// <returns>The element at the specified index.</returns> public CSGTreeNode this[int index] { get { return(new CSGTreeNode { nodeID = CSGTreeNode.GetChildNodeAtIndex(treeNodeID, index) }); } }
/// <summary>Determines whether the <see cref="Chisel.Core.CSGTree"/> contains a specific value.</summary> /// <param name="item">The Object to locate in the <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns><b>true</b> if item is found in the <see cref="Chisel.Core.CSGTree"/>; otherwise, <b>false</b>.</returns> public bool Contains(CSGTreeNode item) { return(CSGTreeNode.IndexOfChildNode(treeNodeID, item.nodeID) != -1); }
public static bool ClearDirty(CSGTreeNode node) { return(ClearDirty(node.NodeID)); }
/// <summary>Copies the immediate children of the <see cref="Chisel.Core.CSGTree"/> to an Array, starting at a particular Array index.</summary> /// <param name="array">The one-dimensional Array that is the destination of the elements copied from <see cref="Chisel.Core.CSGTree"/>. The Array must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param> /// <returns>The number of children copied into <paramref name="array"/>.</returns> public int CopyChildrenTo(CSGTreeNode[] array, int arrayIndex) { return(CSGTreeNode.CopyTo(treeNodeID, array, arrayIndex)); }
/// <summary>Removes the child at the specified index of the <see cref="Chisel.Core.CSGTree"/>.</summary> /// <param name="index">The zero-based index of the child to remove.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool RemoveAt(int index) { return(CSGTreeNode.RemoveChildNodeAt(treeNodeID, index)); }
/// <summary>Adds a <see cref="Chisel.Core.CSGTreeNode"/> to the end of the <see cref="Chisel.Core.CSGTree"/>.</summary> /// <param name="item">The <see cref="Chisel.Core.CSGTreeNode"/> to be added to the end of the <see cref="Chisel.Core.CSGTree"/>.</param> /// <returns><b>true</b> on success, <b>false</b> on failure</returns> public bool Add(CSGTreeNode item) { return(CSGTreeNode.AddChildNode(treeNodeID, item.nodeID)); }