public void Init(List <Triangle> rawTriangles) { this.allRawTriangle = rawTriangles; foreach (var tri in rawTriangles) { allTriangle.Add(new TriRef(tri)); } root = new BspNode(); root.Init(allTriangle); #if UNITY_EDITOR && SHOW_BSP_TREE_GIZOMS var tran = DrawNode(root, 0, _debugTrans); tran.transform.position += Vector3.up * 0.05f; #endif }
Transform DrawNode(BspNode node, int depth, Transform parent) { var val = Hash13(node.nodeId); Color color = new Color(val.x, val.y, val.z, 1); if (node.IsLeaf) { var tran = CreateGo(node.nodeId.ToString(), node.tris, color).transform; tran.SetParent(parent, true); return(tran); } else { var tran = CreateGo(node.nodeId.ToString(), node.SplitPlane, color).transform; tran.SetParent(parent, true); DrawNode(node.child[0], depth + 1, tran); DrawNode(node.child[1], depth + 1, tran); return(tran); } }