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
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
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/