/// <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
            });
        }
Example #2
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
            });
        }
Example #3
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
            });
        }
Example #4
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));
        }
 /// <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));
 }
Example #6
0
 /// <summary>Destroy this <see cref="Chisel.Core.CSGTreeBrush"/>. Sets the state to invalid.</summary>
 /// <returns><b>true</b> on success, <b>false</b> on failure</returns>
 public bool Destroy()
 {
     var prevBrushNodeID = brushNodeID; brushNodeID = CSGTreeNode.InvalidNodeID; return(CSGTreeNode.DestroyNode(prevBrushNodeID));
 }