We've seen a few ways that trees can be added to a scene. In Chapter 18, a red palm trees was loaded as a 3D model, while trees were represented as images pasted onto transparent QuadArray surfaces in Chapter 27. The drawback of both approaches is that the trees never change, never grow.
Figures 1-5 show a sequence of screen shots of the Trees3D application. Five trees grow from saplings, young green shoots turn brown, leaves sprout, all taking place over a period of a few seconds.
A tree is a collection of tree limbs, each one encoded as a TreeLimb object. TreeLimb collects together the techniques for making a branch grow longer, thicker, and change colour. Instead of using a GeometryUpdater interface (as in the particle systems demos of Chapter 21), the underlying shape (a cylinder) is manipulated by non-uniform scaling, a much simpler approach.
The leaves at the end of a branch are represented by two ImagesCsSeries 'screens' which show pictures of leaves that are always oriented towards the viewer. The image on a screen can be replaced by another one, perhaps an image containing more leaves, creating the effect that the leaves are 'growing' and changing.
The modifications carried out on a tree limb in each time frame are specified by 'rules' in a GrowthBehavior object, which is triggered every 100ms. The rules can be easily adjusted to make limbs change in a variety of ways.
Each time Trees3D is executed, the trees will look different due to random elements in the rules.
An approach not used here are rewrite rules in the style of a Lindenmayer system (L-system). We briefly compare our rule mechanism with L-systems at the end of the chapter.