7
2013
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
TODO:
– lots of things Oo..
Ideas:
– 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..)
Notes:
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: http://www.cgtextures.com/texview.php?id=106971
Webplayer:
http://unitycoder.com/upload/demos/ProceduralTreeGenerator/ (v1.0)
(quite a messy trees..maybe because branches are added randomly and no scaling to smaller size towards top yet..)
Inspiration:
– 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

Related Posts
6 Comments + Add Comment
Leave a comment
Recent posts
- Favorites in PackageManager
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
Recent Comments
- on Mesh Exploder (sources)
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by













it’s great, it’s wonky and stylistic. the trees look like they have been through some tough times, as the leaves fell off, and it is very appreciable the maths that went into that, it seems like the bases of a very nice tree gen. i have some flowers for it:
https://www.youtube.com/watch?v=4Fv4pCuJVUk
see end of video for the flowersy things.
we can exchange codes if you want, my one is just a random platonic symmetry generator.
bending the vertex normals:
http://wiki.polycount.com/VertexNormal
about leaf mesh optimization:
http://forum.unity3d.com/threads/forester-pro-for-unity-an-easy-to-use-tree-generator.163300/#post-1194149
L-System trees (script)
http://forum.unity3d.com/threads/l-systems-for-unity-free-script-included.272416/#post-1842170
Bézier Curves and Surfaces:
http://www.scratchapixel.com/lessons/advanced-rendering/bezier-curve-rendering-utah-teapot/curves-as-geometry
A port of proctree.js for use in the Unity engine
https://github.com/samueljlopes/Proctree-for-Unity/