public void Descript(FractalSystemNode node, int depth) { if (node.growRate < iterGrowRate) { stoppedCount++; node.ClearNode(); return; } if (depth >= iterationMax) { //因为在这个工程中,只会渲染整棵树,所以不需要下面串起来的链表。 node.ClearNode(); return; } if (node.child.Count == 0)//这个节点还没有展开过 { node.generateChildren(); } //node.updateChildren(); foreach (FractalSystemNode child in node.child) { Descript(child, depth + 1); } //同样因为没有链表,所以不用进行后续的处理。 }
void Render(World world, FractalRenderState state, FractalSystemNode node) { ((TreeVer4_Ultra)node)?.SetColors(trunkBlock, branchBlock, leafSetup.leaf); ((TreeVer4_Ultra)node)?.SetLeaf(leafSetup); node.Express(world, ref state); foreach (FractalSystemNode child in node.child) { Render(world, state, child); } }
void RenderNodeRec(FractalRenderState state, FractalSystemNode node) { node.Express( vertices, ref verticesCount, //Vertices indices, ref indicesCount, //Indices normals, ref normalsCount, //Normals uvs, uv2s, uv3s, uv4s, //TexCoord(uv) tangents, ref tmp, //Tangents ref state); foreach (FractalSystemNode child in node.child) { RenderNodeRec(state, child); } }
// Use this for initialization void Start() { UnityEngine.Random.seed = randomSeed; switch (fractalType) //Simple factory { case FractalType.boxTest: startNode = new BoxTest(); startNode.growRate = startGrowRate; break; case FractalType.treeVer1: startNode = new TreeVer1Beta(); startNode.growRate = startGrowRate; break; case FractalType.treeVer1_ReducedVertices: startNode = new TreeVer1_ReducedVertices(); startNode.growRate = startGrowRate; break; case FractalType.treeVer2Cyc_ConcretedNormals: startNode = new TreeVer2Cyc(); startNode.growRate = startGrowRate; break; case FractalType.treeVer3Cyc_Spline: startNode = new TreeVer3_CycWithSpline(); startNode.growRate = startGrowRate; break; } Descript(startNode, 0); //Debug.Log(stoppedCount); RenderMesh(); }
public void Generate(BoundsInt bound, World world) { Vector3 dirc = (bound.max - bound.min); //TestTree.FillCyclinder(world, (uint)Blocks.wood, bound.min, bound.max, 4, 2, dirc.normalized, dirc.normalized); System.Random random = new System.Random((bound.x << 16) ^ (bound.y << 8) ^ (bound.z)); startNode = new TreeVer4_Ultra(random, this.trunkLen, crownWidth, rootScale, endRadiusScale); startNode.growRate = startGrowRate; startNode.init(); Descript(startNode, 0); FractalRenderState state = new FractalRenderState(); state.position = new Vector3(bound.center.x, bound.min.y, bound.center.z); state.rotation = Quaternion.identity; state.scale = this.scale; Render(world, state, startNode); }
public void Descript(FractalSystemNode node, int depth) { // Check terminating conditions if (node.growRate < iterGrowRate) { return; } if (depth >= iterationMax) { node.ClearNode(); return; } // Expand the node if it have not been expanded. if (node.child.Count == 0) { node.generateChildren(); } foreach (FractalSystemNode child in node.child) { Descript(child, depth + 1); } }
public void ReDraw() { UnityEngine.Random.seed = randomSeed; switch (fractalType) //Simple factory { case FractalType.boxTest: startNode = new BoxTest(); startNode.growRate = startGrowRate; break; case FractalType.treeVer1: startNode = new TreeVer1Beta(); startNode.growRate = startGrowRate; break; case FractalType.treeVer1_ReducedVertices: startNode = new TreeVer1_ReducedVertices(); startNode.growRate = startGrowRate; break; case FractalType.treeVer2Cyc_ConcretedNormals: startNode = new TreeVer2Cyc(); startNode.growRate = startGrowRate; break; case FractalType.treeVer3Cyc_Spline: startNode = new TreeVer3_CycWithSpline(); startNode.growRate = startGrowRate; break; case FractalType.treeVer3_G: startNode = new TreeVer3_withGravity(); startNode.growRate = startGrowRate; break; case FractalType.treeVer4: startNode = new TreeVer4_Ultra(); startNode.growRate = startGrowRate; break; case FractalType.treeVer4_Frond: startNode = new TreeVer4_Frond(); startNode.growRate = startGrowRate; break; } startNode.startGrowRate = startGrowRate; indices.Clear(); indicesCount.Clear(); verticesCount = 0; for (int i = 0; i < startNode.submeshCount; i++) { indices.Add(new int[indicesMax]); indicesCount.Add(0); } startNode.randomSeed *= randomSeed; startNode.fractalMode = fractalMode; startNode.init(); Descript(startNode, 0); //Debug.Log(stoppedCount); RenderMesh(); }