Interface Instancer<D extends InstanceData>

Type Parameters:
D - the data that represents a copy of the instanced model.
All Known Implementing Classes:
AbstractInstancer, CPUInstancer, GPUInstancer

public interface Instancer<D extends InstanceData>
An instancer is how you interact with an instanced model.

Instanced models can have many copies, and on most systems it's very fast to draw all of the copies at once. There is no limit to how many copies an instanced model can have. Each copy is represented by an InstanceData object.

When you call createInstance() you are given an InstanceData object that you can manipulate however you want. The changes you make to the InstanceData object are automatically made visible, and persistent. Changing the position of your InstanceData object every frame means that that copy of the model will be in a different position in the world each frame. Setting the position of your InstanceData once and not touching it again means that your model will be in the same position in the world every frame. This persistence is useful because it means the properties of your model don't have to be re-evaluated every frame.

  • Method Summary

    Modifier and Type
    Method
    Description
     
    default void
    Populate arr with new instances of this model.
    void
    Notify the Instancer that some of its data needs updating.
    void
    Notify the Instances that some of its data should be removed.
    void
    stealInstance(D inOther)
    Copy a data from another Instancer to this.
  • Method Details

    • createInstance

      D createInstance()
      Returns:
      a handle to a new copy of this model.
    • stealInstance

      void stealInstance(D inOther)
      Copy a data from another Instancer to this. This has the effect of swapping out one model for another.
      Parameters:
      inOther - the data associated with a different model.
    • notifyDirty

      void notifyDirty()
      Notify the Instancer that some of its data needs updating.

      This might be ignored, depending on the implementation. For the GPUInstancer, this triggers a scan of all instances.

    • notifyRemoval

      void notifyRemoval()
      Notify the Instances that some of its data should be removed.

      By the time the next frame is drawn, the instanceData passed will no longer be considered for rendering.

    • createInstances

      default void createInstances(D[] arr)
      Populate arr with new instances of this model.
      Parameters:
      arr - An array to fill.