コード例 #1
0
        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();
            }
        }
コード例 #2
0
        /// <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
            });
        }
コード例 #3
0
        /// <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
            });
        }
コード例 #4
0
        /// <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
            });
        }
コード例 #5
0
        /// <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
            });
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 /// <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));
 }
コード例 #8
0
 /// <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));
 }
コード例 #9
0
 /// <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));
 }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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));
        }
コード例 #15
0
 /// <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));
 }
コード例 #16
0
 /// <summary>Force set the dirty flag of the <see cref="Chisel.Core.CSGTreeNode"/>.</summary>
 public void SetDirty()
 {
     CSGTreeNode.SetDirty(treeNodeID);
 }
コード例 #17
0
 /// <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));
 }
コード例 #18
0
 // TODO: add description
 public static CSGTreeNode       Duplicate(CSGTreeNode node)
 {
     return(DuplicateInternal(node));
 }
コード例 #19
0
 /// <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));
 }
コード例 #20
0
 /// <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));
 }
コード例 #21
0
 /// <summary>Removes all children from the <see cref="Chisel.Core.CSGTree"/>.</summary>
 public void Clear()
 {
     CSGTreeNode.ClearChildNodes(treeNodeID);
 }
コード例 #22
0
 /// <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));
 }
コード例 #23
0
 /// <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));
 }
コード例 #24
0
 /// <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));
 }
コード例 #25
0
 /// <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)
         }); }
 }
コード例 #26
0
 /// <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);
 }
コード例 #27
0
 public static bool      ClearDirty(CSGTreeNode node)
 {
     return(ClearDirty(node.NodeID));
 }
コード例 #28
0
 /// <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));
 }
コード例 #29
0
 /// <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));
 }
コード例 #30
0
 /// <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));
 }