Interface Instancer<I extends Instance>

Type Parameters:
I - the data that represents a copy of the instanced model.

@BackendImplemented public interface Instancer<I extends Instance>
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 Instance object.

When you call createInstance() you are given an Instance object that you can manipulate however you want. The changes you make to the Instance object are automatically made visible, and persistent. Changing the position of your Instance object every frame means that that copy of the model will be in a different position in the level each frame. Setting the position of your Instance once and not touching it again means that your model will be in the same position in the level 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
    stealInstance(I instance)
    Steal an instance from another instancer.
  • Method Details

    • createInstance

      I createInstance()
      Returns:
      a handle to a new copy of this model.
    • createInstances

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

      void stealInstance(@Nullable I instance)
      Steal an instance from another instancer.
      This has the effect of swapping the instance's model in-place.

      If the given instance is already owned by this instancer, this method does nothing.
      If the given instance is null, this method does nothing.
      If the given instance was created by a different backend, the behavior of this method is undefined.
      Parameters:
      instance - The instance to steal.