Like FoxModel, but designed to render a mesh multiple times, useful for particles
or special effects.
Constructor
Variables
instanceData:FoxInstanceData
The data containing the transforms and colors information for the instances. This is a mat3x4 split into 3 attributes And an extra vec4 buffer for color/custom data
instanceCount:Int = 0
The number of instances that will be rendered, this is applied per mesh.
Increasing this value above the previous limit will rebuild instanceData.
updateMode:FoxInstanceUpdateMode = FoxInstanceUpdateMode.ONE_BY_ONE
The renderer updates one instance at a time, this can cause increased API calls when too many instances update per frame.
If you plan to update all instances at once, change updateMode to ALL. Keep in mind that
this will upload the entire instance buffer even if only one needs updating.
A balance between these modes is CHUNK, which uploads the region
of the updates.
For example: If instance 2 and 5 needs updating, the sliced
portion of the data between those indices will be utilized (2, 3, 4, 5).
Use this mode with caution. Tip: Update instances without any gaps in-between for best performance.
Methods
setInstanceTransform(instance:Int, matrix:Matrix3D):Void
This function changes an instance position, rotation and scale from a matrix.
Note: This will not include the last column of the matrix.
Parameters:
instance | The instance index |
|---|---|
matrix | The input matrix |
setInstanceTransformSeparate(instance:Int, ?position:Vector3D, ?rotation:Vector3D, ?scale:Vector3D):Void
If you want to transform an instance from a set of components, use this.
getInstanceTransform(instance:Int):Matrix3D
Extracts a Matrix3D containing the instance transform data
To get position, rotation and scale, use the matrix decompose()
setInstanceColor(instance:Int, color:Vector3D):Void
Changes the color of an instance. This value gets multiplied by vertex colors
and the color parameter of a material.
Parameters:
instance | The instance index |
|---|---|
color | The color value in RGBA float |