A helper to create lines for a mesh.

Supports updating efficiently on the GPU.

Lines don't support UV mapping, instead, the data represents values as follows: - U is set to the line lerp points, it will interpolate between 0 and 1 from the line start point to the line end point - V is set to the length of the line in local space

However, lines can still use vertex colors, just make sure your material supports it.

Constructor

new(?lineMaterial:FoxMaterial)

Variables

@:value([])linePositions:Array<Float> = []

@:value([])lineColors:Array<Float> = []

@:value([])lineUVs:Array<Float> = []

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

@:value(0)lineCount:Int = 0

private@:value(new IntMap())__vertexUpdates:Map<Int, Array<Float>> = new IntMap()

private@:value(new IntMap())__colorsUpdates:Map<Int, Array<Float>> = new IntMap()

private@:value(new IntMap())__uvsUpdates:Map<Int, Array<Float>> = new IntMap()

Methods

@:value({ endColor : 0xFFFFFFFF, startColor : 0xFFFFFFFF })addLine(from:Vector3D, to:Vector3D, startColor:FlxColor = 0xFFFFFFFF, endColor:FlxColor = 0xFFFFFFFF):Void

Adds a line to the mesh. Call build() when you're done

Note: This method will allocate memory each time, to update lines efficiently in real time, check updateLine()

Parameters:

from

The position where the line will start

end

The position where the line will end

color

Optional: The line color

build():Void

Callocates added lines to the GPU. Call this after creating lines with addLine()

flushUpdates():Void

Pushes all updated lines to the GPU. Call this after updating lines with updateLine()

updateLine(index:Int, from:Vector3D, to:Vector3D, ?startColor:FlxColor, ?endColor:FlxColor):Void

clear():Void

Inherited Variables

Defined by FoxMesh

@:value(null)vertexBuffer:VertexBuffer3D = null

@:value(null)uvBuffer:VertexBuffer3D = null

@:value(null)indexBuffer:IndexBuffer3D = null

@:value(null)normalBuffer:VertexBuffer3D = null

@:value(null)tangentBuffer:VertexBuffer3D = null

@:value(null)colorBuffer:VertexBuffer3D = null

@:value(null)boneWeights:VertexBuffer3D = null

@:value(null)boneIndices:VertexBuffer3D = null

@:value(0x88E4)bufferUsage:Int = 0x88E4

The buffer usage pattern for optimization purposes.

Note: This will be applied on the next call to setArrays().

@:value(3)vertexPerFace:Int = 3

By default, this mesh will use 3 vertices per face (a triangle), but you can change it to 4 (quads) or 2 (lines).

This will affect how the mesh is processed when drawing.

Note: To apply it correctly, call setArrays() directly afterwards.

Note 2: This currently needs to be implemented.

@:value(null)material:FoxMaterial = null

@:value(null)assetsKey:String = null

@:value(null)bounds:BoundingBox = null

@:value(null)context:Context3D = null

@:value(false)__isCopy:Bool = false

Inherited Methods

Defined by FoxMesh

setBuffer(type:FoxMeshBufferType, data:Array<Float>):Void

Writes buffer data on the GPU

Parameters:

type

The buffer to write to

data

The data array

setBufferRaw(type:FoxMeshBufferType, data:ArrayBufferView):Void

Writes buffer data on the GPU using an existing ArrayBufferView. This method runs faster than setBuffer

setIndexBuffer(data:Array<Int>):Void

Same as setBuffer() but exclusive to the Index buffer

setIndexBufferRaw(data:UInt16Array):Void

@:value({ offset : 0 })updateBuffer(type:FoxMeshBufferType, data:Array<Float>, offset:Int = 0):Void

Updates buffer data on the GPU

Use this to set portions of it or are updating data constantly. Tip: Make sure the buffer is set to GL.DYNAMIC_DRAW on its usage.

Parameters:

type

The buffer to update

data

The data array

offset

The index of the buffer where to start writing data

@:value({ offset : 0 })updateIndexBuffer(data:Array<Int>, offset:Int = 0):Void

Same as updateBuffer() but exclusive to the Index buffer

@:value({ offset : 0 })updateBufferRaw(type:FoxMeshBufferType, data:ArrayBufferView, offset:Int = 0):Void

Same as updateBuffer() and updateIndexBuffer(), but there's no data copying to a typed array, instead, you provide it.

This method is faster than the other ones, but needs more setup.

setArrays(?vertices:Array<Float>, ?uvtData:Array<Float>, ?indices:Array<Int>, ?material_:FoxMaterial, ?normals:Array<Float>, ?colors:Array<Float>, ?weights:Array<Float>, ?influences:Array<Int>):Void

Creates buffers and uploads data to the GPU.

getBufferByType(type:FoxMeshBufferType):VertexBuffer3D

Returns a vertex buffer of this mesh.

Parameters:

type

The buffer type. See FoxMeshBufferType

calculateBounds(vertices:Dynamic):BoundingBox

copy():FoxMesh

Copies this mesh object, does not create new data on GPU. Use this to use different materials or mix different buffers.

Warning! destroying this copy won't free memory on the GPU unless the original is destroyed!

destroy():Void