Procedural Tree Mesh Generator (wip)


Small test for doing procedural trees.. (screenshot showing trunk with resolution 8 and 5 sides..)

Current features:
– Trunk creation: adjustable height, height segments, resolution (amount of “sides”)
– Using quads
– Perlin noise rotations for trunk direction
– Adjustable root segment radius multiplier (so root part is thicker)
– Branches: length, size, amount
– Leaves: texture, plane width

– lots of things Oo..


– For destruction mode..could encode values into vertex colors! So when some branch is clicked, can search all vertices that are in the same branch! (or do soft selection on those vertices..)


Error: “error CS0019: Operator `*’ cannot be applied to operands of type `UnityEngine.Vector3′ and `UnityEngine.Quaternion'”
Code: myVector = myVector*myRotation;
Solution: myVector = myRotation*myVector; // uh
–  Used this ReMap function for remapping values from different ranges..
– Huh took several hours to align branches to vertex normal direction, tried everything: transform.LookAt(), Quaternion.LookRotation(), Vector3.RotateTowards().. finally this did it: transform.rotation = Quaternion.FromToRotation(Vector3.up, normalDir);
– Texture used for leaves:

Webplayer: (v1.0)
(quite a messy trees..maybe because branches are added randomly and no scaling to smaller size towards top yet..)

Procedural trees (vimeo)
CanTree (online tree generator)

Image#2: Rotation on creation now works.. Vertices are not shared, so had to get them connected by rotating with 2 different values (lower part with currentRot and upper with nextRot)


Image#3: Doing branches creation in 2nd pass..(Debug.LineDraw here for testing, using vertex normal to go away from the center..)


Image#4: Branches..currently separate gameobjects because “mesh.CombineMeshes” keeps giving some error ” totalNumIndices <= (maxIndices+1)”..


Image#5: Random branches not yet matching to the center position..(as they were generated after trunk was done, would have to know the rotated trunk center position..uh..)


Image#6: Fixed ^that by saving segment center positions to a list..then Vector3.Lerp() on the branch y position between 2 segments..

Image#7: Recursive branch function gone wrong..


Image#8: Skipped recursive function for now.. duplicated makeBranch() function and adjusted few variables there instead.. starting to look like a tree almost.


Image#9: Ok its ready!…not. Got some leaves working, just simple quad planes from start of the branch to the end.. Used shader “AlphaTest-Diffuse.shader”, modified it to be 2 sided by adding line “Cull Off” before line “LOD 200” (built in shader sources)


Image#10: Adjusted branch generation..more realistic, but not yet using any of that fibonacci stuff


5 Comments + Add Comment

Leave a comment


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.