Like FoxModel, but designed to render a mesh multiple times, useful for particles or special effects.

Constructor

@:value({ culling : true, layers : 0x1, z : 0, y : 0, x : 0, numInstances : 0 })new(numInstances:Int = 0, x:Float = 0, y:Float = 0, z:Float = 0, layers:FoxLayer = 0x1, ?groups:Array<Int>, culling:Bool = true)

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

@:value(0)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.

private@:value(0)__maxInstanceCount:Int = 0

@:value(new List())__instanceUpdates:List<Int> = new List()

Holds the pending updates for instances.

@:value(0xFEDE10B0)__instanceMinChunk:UInt = 0xFEDE10B0

@:value(-1)__instanceMaxChunk:UInt = -1

@:value(false)__instanceBufferDirty:Bool = false

@:value(FoxInstanceUpdateMode.ONE_BY_ONE)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

privateset_instanceCount(v:Int):Int

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

setInstanceFlxColor(instance:Int, color:FlxColor):Void

getInstanceColor(instance:Int):Vector3D

getInstanceFlxColor(instance:Int):FlxColor

pushUpdate(instance:Int):Void

Inherited Variables

Defined by FoxModel

context:Context3D

@:value(new Matrix3D())__prevTransform:Matrix3D = new Matrix3D()

This is the object's transform from a previous frame, used for motion vector calculations.

Having to calculate previous transforms on empty objects is a bit pointless, so that's why this is here.

@:value([0])groups:Array<Int> = [0]

The draw groups from a scene this object will be drawn on.

Used mainly to separate meshes in passes in an optimized manner.

Note: When changing this array manually, always set FoxRenderer.mustRebuildDrawGroups to true to ensure proper updating.

There are dedicated functions for this below:

  • addToDrawGroup(group)
  • removeFromDrawGroup(group)
  • setDrawGroupAt(i, group)

@:value([])meshes:Array<FoxMesh> = []

Meshes that will be rendered by this model, they inherit this model transform.

Note: When changing this array manually, always set FoxRenderer.mustRebuildDrawGroups to true to ensure proper updating.

There are dedicated functions for this below:

  • setMeshAt(i, mesh)
  • addMesh(mesh)
  • removeMesh(mesh)
  • removeMeshByIndex(mesh)

@:value(null)materialOverride:FoxMaterial = null

If set, this material will be applied to every mesh of this model when rendering.

@:value(null)materialOverlay:FoxMaterial = null

If set, this material will be applied over every mesh of this model.

This will draw the meshes again using this material.

@:value(null)skin:FoxSkinData = null

The skin associated with this mesh, assigned when added to a FoxArmature

@:value(true)castShadows:Bool = true

Wheter or not cast shadows (rendering in the shadow pass)

@:value(false)castColoredShadows:Bool = false

If true, this model will cast colored shadows, useful for tinted transluscent objects (stained glass, liquids, fabric).

Requires castShadows to be true.

Note: This is not implemented yet.

Defined by FoxObject

parent:FoxObject

If set, will adapt parent transform. Make sure the parent has a higher priority so it updates in order

position:Vector3D

@:value(new Vector3D())rotation:Vector3D = new Vector3D()

@:value(new Vector3D(1, 1, 1))scale:Vector3D = new Vector3D(1, 1, 1)

x:Float

y:Float

z:Float

angleX:Float

angleY:Float

angleZ:Float

@:value(new Matrix3D())transform:Matrix3D = new Matrix3D()

This is the global transform for this Object, it encodes position, rotation and scale in a 4x4 matrix

@:value(new Vector3D())read onlyglobalPosition:Vector3D = new Vector3D()

@:value(new Vector3D())read onlyglobalRotation:Vector3D = new Vector3D()

@:value(new Vector3D())read onlyglobalScale:Vector3D = new Vector3D()

Defined by FoxBasic

@:value("FoxBasic")name:String = "FoxBasic"

@:value(true)visible:Bool = true

@:value(true)active:Bool = true

@:value(null)scene:FoxScene = null

@:value(false)__destroyed:Bool = false

animation:FoxAnimationPlayer

An animation controller for this basic. Although properties have to be manually linked, this is intended to be a general-purpose animator for this object

Inherited Methods

Defined by FoxModel

privateset_groups(v:Array<Int>):Array<Int>

privateset_meshes(v:Array<FoxMesh>):Array<FoxMesh>

inlineaddMesh(mesh:FoxMesh):Void

inlinesetMeshAt(index:Int, mesh:FoxMesh):Void

inlineremoveMesh(mesh:FoxMesh):Void

inlineremoveMeshByIndex(index:Int):Void

inlineaddToDrawGroup(group:Int):Void

inlineremoveFromDrawGroup(group:Int):Void

inlinesetDrawGroupAt(index:Int, group:Int):Void

getMaterial(meshIdx:Int):FoxMaterial

Shortcut to get a material from a mesh by index

setMaterial(meshIdx:Int, mat:FoxMaterial):Void

Shortcut to assign a material to a mesh by index

loadJSON(name:String):Null<{meshes:Array<FoxMesh>, materials:Map<String, FoxMaterial>}>

Loads a FoxLite JSON model

loadOBJ(name:String, ?extraShaderFlags:Array<String>, ?customShaderPath:String):Null<{meshes:Array<FoxMesh>, materials:Map<String, FoxMaterial>}>

Defined by FoxObject

@:value({ z : 0, y : 0, x : 0 })inlinesetPosition(x:Float = 0, y:Float = 0, z:Float = 0):Void

@:value({ z : 0, y : 0, x : 0 })inlinesetRotation(x:Float = 0, y:Float = 0, z:Float = 0):Void

@:value({ z : 0, y : 0, x : 0 })inlinesetAngle(x:Float = 0, y:Float = 0, z:Float = 0):Void

Same as setRotation() but for angle degrees.

inlinesetAngleFromVector(angles:Vector3D):Void

Sets the object's angle degrees from a Vector3D

getAngle(?output:Vector3D):Vector3D

Gets the object's rotation as degrees, as a Vector3D

Parameters:

output

(Optional) the output vector to store the angles without allocating a new one

Returns:

a Vector3D containing angleX, angleY and angleZ

@:value({ w : 1, z : 0, y : 0, x : 0 })setRotationQuaternion(x:Float = 0, y:Float = 0, z:Float = 0, w:Float = 1):Vector3D

Sets the object's rotation from a Quaternion, which is needed for accurate rotation representation when interpolating.

How dows it work? hell if i know

inlinesetRotationQuaternionFromVector(quat:Vector3D):Vector3D

@:value({ z : 1, y : 1, x : 1 })inlinesetScale(x:Float = 1, y:Float = 1, z:Float = 1):Void

copyComponentsFrom(object:FoxObject):Void

Copies position, rotation and scale from another FoxObject, so the other object's components doesn't affect this one when changing them

privateget_globalPosition():Vector3D

privateget_globalRotation():Vector3D

privateget_globalScale():Vector3D

privateget_x():Float

privateget_y():Float

privateget_z():Float

privateinlineset_x(v:Float):Float

privateinlineset_y(v:Float):Float

privateinlineset_z(v:Float):Float

privateset_angleX(v:Float):Float

privateset_angleY(v:Float):Float

privateset_angleZ(v:Float):Float

privateget_angleX():Float

privateget_angleY():Float

privateget_angleZ():Float