EZ-Tree is a procedural tree generator with dozens of tunable parameters. The standalone tree generation code is published as a library and can be imported into your own application for dynamically generating trees on demand. Additionally, there is a standalone web app which allows you to create trees within the browser and export as .PNG or .GLB files.
npm i @dgreenheck/ez-tree// Create new instance
const tree = new Tree();
// Set parameters
tree.options.seed = 12345;
tree.options.trunk.length = 20;
tree.options.branch.levels = 3;
// Generate tree and add to your Three.js scene
tree.generate();
scene.add(tree);Any time the tree parameters are changed, you must call generate() to regenerate the geometry.
For scenes with many trees, generateLODs() builds the tree at multiple levels of detail hosted in a THREE.LOD object inside the tree group. The renderer automatically switches levels based on camera distance. All levels are meshed from the same skeleton, so the tree's silhouette stays consistent across switches — distant levels just use fewer ring segments and fewer (but larger) leaves.
const tree = new Tree();
tree.loadPreset('Ash Medium');
tree.generateLODs(); // instead of generate()
scene.add(tree);The default levels (Tree.defaultLODLevels) switch at 100 and 250 units, reducing to roughly 40% and 20% of the full triangle count. You can pass custom levels:
tree.generateLODs([
{ distance: 0, detail: {} }, // full detail
{
distance: 80,
hysteresis: 0.05,
detail: {
sectionStride: 3, // sample every 3rd ring along each branch
segmentFactor: 0.75, // reduce radial segments to 75% (min 3)
leafStride: 2, // keep every 2nd leaf...
leafScale: 1.4, // ...enlarged to preserve canopy coverage
billboard: 'single', // drop the second crossed leaf quad
},
},
]);All LOD levels share one bark material and one leaf material, so tree.update(time) animates wind at every level. Calling generate() afterwards tears the LOD down and restores the single full-detail mesh pair (note that exporting a tree generated with generateLODs() to GLB will include every level).
If you have your own LOD or instancing system, tree.createGeometry(detail) returns raw { branches, leaves } BufferGeometry pairs at any detail level without touching the tree's own meshes.
To run the standalone app locally, you first need to build the EZ-Tree library before running the app.
npm install
npm run appdocker compose build
docker compose up -dThe TreeOptions class defines an options object that controls various parameters of a procedurally generated tree. Each property of this object allows for customization of the tree's appearance, including bark, branches, and leaves. Below is a detailed explanation of each property of the TreeOptions object.
seed: Sets the initial value for random generation, ensuring consistent tree generation when using the same seed.type: Defines the type of the tree, which can be set to one of the options from theTreeTypeenumeration (e.g.,TreeType.Deciduous).
The bark object controls the appearance and properties of the tree trunk.
type: Specifies the type of bark texture to use, selected from theBarkTypeenumeration (e.g.,BarkType.Oak).tint: Determines the color tint applied to the bark, defined as a hexadecimal color value (e.g.,0xfffffffor white).flatShading: Boolean property indicating whether to use flat shading (true) or smooth shading (false) for the bark.textured: Boolean value that indicates if a texture is applied to the bark (trueorfalse).textureScale: Controls the scale of the bark texture in both thexandyaxes. It is an object with propertiesxandyto define the scaling factors.
The branch object defines parameters for the trunk and branch levels of the tree.
levels: Number of recursive branch levels. Setting this to0creates only the trunk, while higher values add more branches.angle: Defines the angle, in degrees, at which child branches grow relative to their parent branch. This is specified separately for each level.children: Specifies the number of child branches at each level, with the index (0,1,2, etc.) representing the level.force: Represents an external directional force encouraging tree growth, defined bydirection(a vector object{ x, y, z }) andstrength(a numeric value).gnarliness: Defines how twisted or curled each branch level should be, specified for each level.length: Length of the branches at each level. This is an object with keys representing each level.radius: Radius (or thickness) of the branches at each level.sections: Number of segments along the length of each branch level, controlling the resolution of the branch mesh.segments: Number of radial segments that make up each branch, with a higher value resulting in a smoother cylinder.start: Specifies where along the parent branch (as a fraction from0to1) the child branches should start forming.taper: Controls the tapering of the branches at each level. A value between0and1defines the reduction in radius from base to tip.twist: Defines the amount of twisting applied to each branch level.
The leaves object defines properties that control the appearance and placement of leaves.
type: Specifies the type of leaf texture, selected from theLeafTypeenumeration (e.g.,LeafType.Oak).billboard: Defines how leaves are rendered. TheBillboardenumeration can be set toSingleorDoubleto indicate single or perpendicular double-sided leaves.angle: Defines the angle of the leaves relative to the parent branch, in degrees.count: Number of leaves to generate.start: Specifies where along the length of the branch (as a value between0and1) leaves should start growing.size: Size of the leaves, represented as a numeric value.sizeVariance: Specifies how much variance in size each leaf instance should have, making the leaves look more natural.tint: Tint color applied to the leaves, defined as a hexadecimal color value (e.g.,0xfffffffor white).alphaTest: Sets the alpha threshold for leaf transparency, controlling the transparency of the leaf textures.
