CustomMesh.BuilderFromMeshData


class CustomMesh.BuilderFromMeshData


Builder for CustomMesh providing raw data directly.

This will implicitly create a MeshBuffer for you. You provide the VertexLayout along with the raw vertex and index data:


val builder = CustomMesh.BuilderFromMeshData(session, myLayout)
     .addVertexData(myVertexData)
     .setIndexData(myIndexData)

From here, you have two options for defining the mesh topology:

  • You can explicitly add one or more subsets:


builder.addSubset(MeshSubset(MeshSubsetTopology.TRIANGLES, 0, subset1Count))
builder.addSubset(MeshSubset(MeshSubsetTopology.TRIANGLES, subset1Count, subset2Count))
  • Or, if the entire mesh uses the same topology, you can define a single subset that spans all the provided index data:


builder.setTopology(MeshSubsetTopology.TRIANGLES)

Finally, build the mesh:


val mesh = builder.build()

Summary

Public constructors

BuilderFromMeshData(session: Session, vertexLayout: VertexLayout)

Public functions

CustomMesh.BuilderFromMeshData

Adds a MeshSubset defining a part of the mesh.

CustomMesh.BuilderFromMeshData
addSubset(
    topology: MeshSubsetTopology,
    indexOffset: @IntRange(from = 0) Int,
    indexCount: @IntRange(from = 0) Int
)

Adds a MeshSubset defining a part of the mesh using the specified topology, index offset, and index count.

CustomMesh.BuilderFromMeshData

Adds vertex data for a single buffer.

CustomMesh.BuilderFromMeshData
addVertexData(
    buffer: ByteBuffer,
    offset: @IntRange(from = 0) Int,
    size: @IntRange(from = 1) Int
)

Adds vertex data for a single buffer using the provided ByteBuffer, offset, and size.

CustomMesh

Builds a new CustomMesh.

CustomMesh.BuilderFromMeshData

Sets an optional user-supplied bounding box for culling.

CustomMesh.BuilderFromMeshData

Sets the index data.

CustomMesh.BuilderFromMeshData
setIndexData(
    buffer: ByteBuffer,
    offset: @IntRange(from = 0) Int,
    size: @IntRange(from = 1) Int
)

Sets the index data using the provided ByteBuffer, offset, and size.

CustomMesh.BuilderFromMeshData

Sets the MeshSubsetTopology to use for the entire mesh, defining a single subset that spans all provided index data.

Public constructors

BuilderFromMeshData

Added in 1.0.0-alpha16
BuilderFromMeshData(session: Session, vertexLayout: VertexLayout)

Public functions

addSubset

Added in 1.0.0-alpha16
fun addSubset(subset: MeshSubset): CustomMesh.BuilderFromMeshData

Adds a MeshSubset defining a part of the mesh.

This cannot be used in combination with setTopology.

Throws
IllegalStateException

if a topology has already been set

addSubset

Added in 1.0.0-alpha16
fun addSubset(
    topology: MeshSubsetTopology,
    indexOffset: @IntRange(from = 0) Int,
    indexCount: @IntRange(from = 0) Int
): CustomMesh.BuilderFromMeshData

Adds a MeshSubset defining a part of the mesh using the specified topology, index offset, and index count.

This cannot be used in combination with setTopology.

Throws
IllegalStateException

if a topology has already been set

IllegalArgumentException

if indexOffset or indexCount is negative

addVertexData

Added in 1.0.0-alpha16
fun addVertexData(vertexData: ByteBufferRegion): CustomMesh.BuilderFromMeshData

Adds vertex data for a single buffer.

The order in which this method is called determines the buffer index. The first call provides data for buffer index 0, the second for buffer index 1, etc. The data is copied during build, so the original ByteBuffer can be modified or released after build without affecting the underlying MeshBuffer.

addVertexData

Added in 1.0.0-alpha16
fun addVertexData(
    buffer: ByteBuffer,
    offset: @IntRange(from = 0) Int = 0,
    size: @IntRange(from = 1) Int = buffer.capacity() - offset
): CustomMesh.BuilderFromMeshData

Adds vertex data for a single buffer using the provided ByteBuffer, offset, and size.

The order in which this method is called determines the buffer index. The first call provides data for buffer index 0, the second for buffer index 1, etc. The data is copied during build, so the original ByteBuffer can be modified or released after build without affecting the underlying MeshBuffer.

Parameters
buffer: ByteBuffer

containing the data

offset: @IntRange(from = 0) Int = 0

absolute starting position within the buffer (ignoring its current position) in bytes (defaults to 0)

size: @IntRange(from = 1) Int = buffer.capacity() - offset

number of bytes in the region (defaults to the remaining capacity of the buffer after the given offset)

Throws
IllegalArgumentException

if offset is negative, if size is zero or negative, if offset exceeds buffer.capacity(), or if offset + size exceeds buffer.capacity().

build

Added in 1.0.0-alpha16
@MainThread
fun build(): CustomMesh

Builds a new CustomMesh.

Throws
IllegalStateException

if index data or vertex data are missing, or if both or neither of subsets and topology are provided.

setBounds

Added in 1.0.0-alpha16
fun setBounds(bounds: BoundingBox): CustomMesh.BuilderFromMeshData

Sets an optional user-supplied bounding box for culling.

If not provided, the auto-computed bounding box of the entire MeshBuffer will be used.

setIndexData

Added in 1.0.0-alpha16
fun setIndexData(indexData: ByteBufferRegion): CustomMesh.BuilderFromMeshData

Sets the index data.

The data is copied during build, so the original ByteBuffer can be modified or released after build without affecting the underlying MeshBuffer.

setIndexData

Added in 1.0.0-alpha16
fun setIndexData(
    buffer: ByteBuffer,
    offset: @IntRange(from = 0) Int = 0,
    size: @IntRange(from = 1) Int = buffer.capacity() - offset
): CustomMesh.BuilderFromMeshData

Sets the index data using the provided ByteBuffer, offset, and size.

The data is copied during build, so the original ByteBuffer can be modified or released after build without affecting the underlying MeshBuffer.

Parameters
buffer: ByteBuffer

containing the data

offset: @IntRange(from = 0) Int = 0

absolute starting position within the buffer (ignoring its current position) in bytes (defaults to 0)

size: @IntRange(from = 1) Int = buffer.capacity() - offset

number of bytes in the region (defaults to the remaining capacity of the buffer after the given offset)

Throws
IllegalArgumentException

if offset is negative, if size is zero or negative, if offset exceeds buffer.capacity(), or if offset + size exceeds buffer.capacity().

setTopology

Added in 1.0.0-alpha16
fun setTopology(topology: MeshSubsetTopology): CustomMesh.BuilderFromMeshData

Sets the MeshSubsetTopology to use for the entire mesh, defining a single subset that spans all provided index data.

This cannot be used in combination with addSubset.

Throws
IllegalStateException

if subsets have already been added