Add new MeshInstancer StageNode
Currently there are two ways to have a mesh appear in a stage, these are:
- Actors. Single mesh, fully dynamic, individually culled, multiple LODs, has behaviours
- Geoms. Single mesh, fully static, culled using a GeomCuller (e.g. Octree), single LOD, has behaviours
There is an issue though when you want to render a load of instances of the same mesh, and cull them if they are outside the frustum, or you want to dynamically show/hide instances of the same mesh - things like foliage, rocks, decals, etc.
The only option at the moment is to create an Actor but this is problematic for memory and performance reasons. This issue is to add a third option: MeshInstancer.
A MeshInstancer would be a StageNode. This means the instancer itself would have behaviours, and would be culled out entirely if it (and all its mesh instances) were outside the frustum. It would be instantiated with a single MeshPtr, but initially would return no renderables. Once you've created a mesh instancer you would be able to call one of the following:
-
MeshInstanceID spawn_instance(transform)
- creates a new mesh instance, the transform is relative to the MeshInstancer transform -
bool destroy_instance(MeshInstanceID)
- Destroy a mesh instance, returns true if destruction succeeds -
bool hide_instance(MeshInstanceID)
- Stops rendering the instance -
bool show_instance(MeshInstanceID)
- Resumes rendering the instance
MeshInstances are not stage nodes, they will not form part of the scene hierarchy, but they will behave as though they are a child of the MeshInstancer. Destroying a MeshInstancer will destroy all the instances, hiding a MeshInstancer will hide all the instances. Moving a MeshInstancer will move all the instances etc.
Internally, all that will be stored per instance will be a local transformation matrix, an absolute transformation matrix, and a visible/invisible flag.