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(); } }
public Data this[CSGTree treeNode] { get { if (!chiselTreeLookup.TryGetValue(treeNode, out int dataIndex)) { dataIndex = chiselTreeData.Count; chiselTreeLookup[treeNode] = dataIndex; chiselTreeData.Add(new Data()); chiselTreeData[dataIndex].Initialize(); } return(chiselTreeData[dataIndex]); } }
public void Remove(CSGTree tree) { if (!chiselTreeLookup.TryGetValue(tree, out int dataIndex)) { return; } var data = chiselTreeData[dataIndex]; data.Dispose(); // TODO: remove null entry and fix up indices chiselTreeData[dataIndex] = default; chiselTreeLookup.Remove(tree); }
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); }
private static CSGTree[] GetAllTrees() { var nodeCount = GetTreeCount(); var allTrees = new CSGTree[nodeCount]; if (nodeCount == 0) { return(allTrees); } GCHandle allTreeIDsHandle = GCHandle.Alloc(allTrees, GCHandleType.Pinned); IntPtr allTreeIDsPtr = allTreeIDsHandle.AddrOfPinnedObject(); GetAllTrees(nodeCount, allTreeIDsPtr); allTreeIDsHandle.Free(); return(allTrees); }