Skip to content

About

Trees grown from a few numbers, with no model files, drawn by deki-3d (Deki Engine package)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

deki-trees

Experimental. New and unreleased. The component's properties and the shape of the trees may change without a migration path.

Trees grown from a few numbers, for the Deki engine. No model files: a tree is made when the scene loads, and again whenever one of its numbers changes.

Part of Deki Engine. Needs deki-3d, which draws them, on the GPU or with its software rasteriser.

Using it

Add a Mesh and a Tree to an object. The Tree grows the mesh and the Mesh draws it, so the Mesh's own settings (shading, tint, shadows) apply. The scene's camera must be Perspective, as for any mesh, and a Light or two makes the crown read as round.

Pick a Preset:

Preset What it grows
Oak A short trunk that forks low, under a wide round crown.
Aspen Tall and slim, with pale bark and a crown like a flame.
Tupelo A straight trunk with a tall, full crown.
Fir A straight trunk under a cone of boughs.
Custom Whatever the numbers below it say. It starts as the Oak.

Seed gives another tree of the same kind. Detail is the share of its leaf cards a tree keeps; the ones left are drawn larger, so the tree stays full. Lower it on a small board.

A tree's lengths are in the object's own units, so the object's scale sizes it. An oak is 12 units tall.

How a tree is made

The wood is grown as Weber and Penn's model grows it ("Creation and Rendering of Realistic Trees", SIGGRAPH 1995), the model behind Arbaro and Blender's Sapling. A tree is stems at levels: the trunk, its branches, their twigs. Every level has the same few numbers: how many stems the level below carries, at what angle they leave it and how they go round it, how long they are, how they curve, taper and fork. A branch's length follows the crown's shape, its thickness its length. Custom shows all of them, with the paper's meanings, so a tree from the paper or from those tools can be typed in.

The leaves are made the way games make soft foliage:

  • Masses of leaves. A broadleaf crown is a few solid, lumpy masses, found from where the branches put their leaves (k-means over the clusters' places). They give the crown its volume, hide the wood inside it and cost no cut-out pixels. Masses sets how many; 0 makes the crown of cards alone.
  • Cards of leaves round them. Each twig carries clusters of leaves, cut out by a texture of leaves the package paints itself. On a crown of masses a cluster deep inside its mass is left out and the rest sit on the mass's surface, one card each, so the outline is leafy and never a smooth shape. A renderer can turn these cards to face the camera. A conifer's are fronds: two cards along each bough, hanging from it like a roof, over a solid hull (Hull) drawn from where its leaves reach.
  • One light for the whole crown. Masses, hull and cards take their normals from where they are in the crown, not from the way each part faces, so the crown shades as one round thing. Colour is in the vertices: a little darker inside and underneath, lighter on top and outside.

A tree far away

A tree draws less the smaller it is on the screen, with nothing to set. It has a second set of leaves, the far leaves: about a fifth as many cards, each larger, drawn into the crown so the tree's outline stays where it was. From 260 pixels across down to 70 the leaves give way to the far leaves a card at a time, and below a third of the way the twigs are left out: the masses are in front of them.

Oak Aspen Tupelo Fir
Triangles up close, Detail 100% 2,664 2,860 3,168 3,344
Triangles far away 1,818 1,780 1,980 2,324
Corners 3,116 3,506 3,822 4,864

Most of a broadleaf tree's triangles are its solid masses and wood, which are cheap to draw; its cut-out leaf cards, the costly part, are a fifth of them.

Further away still, deki-3d's Impostor draws a tree as one card from pictures of it taken in the editor.

GrowTree() in TreeGenerator.h is the generator on its own, for code that wants a tree's mesh without a component. The mesh is one vertex buffer and one index buffer, in parts: masses or hull, limbs, twigs, leaves, far leaves.

Not there yet

  • Trees do not sway.
  • The same tree placed many times is grown once per object.
  • The leaves change with size a card at a time. A shader that shrinks each card into its middle would make the change smooth.

About

Trees grown from a few numbers, with no model files, drawn by deki-3d (Deki Engine package)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages