CustomMesh.BuilderFromMeshData
public final 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( |
Public methods |
|
|---|---|
final @NonNull CustomMesh.BuilderFromMeshData |
addSubset(@NonNull MeshSubset subset)Adds a |
final @NonNull CustomMesh.BuilderFromMeshData |
addSubset(Adds a |
final @NonNull CustomMesh.BuilderFromMeshData |
addVertexData(@NonNull ByteBufferRegion vertexData)Adds vertex data for a single buffer. |
final @NonNull CustomMesh.BuilderFromMeshData |
addVertexData(Adds vertex data for a single buffer using the provided |
final @NonNull CustomMesh |
Builds a new |
final @NonNull CustomMesh.BuilderFromMeshData |
setBounds(@NonNull BoundingBox bounds)Sets an optional user-supplied bounding box for culling. |
final @NonNull CustomMesh.BuilderFromMeshData |
setIndexData(@NonNull ByteBufferRegion indexData)Sets the index data. |
final @NonNull CustomMesh.BuilderFromMeshData |
setIndexData(Sets the index data using the provided |
final @NonNull CustomMesh.BuilderFromMeshData |
setTopology(@NonNull MeshSubsetTopology topology)Sets the |
Public constructors
BuilderFromMeshData
public BuilderFromMeshData(
@NonNull Session session,
@NonNull VertexLayout vertexLayout
)
Public methods
addSubset
public final @NonNull CustomMesh.BuilderFromMeshData addSubset(@NonNull MeshSubset subset)
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
public final @NonNull CustomMesh.BuilderFromMeshData addSubset(
@NonNull MeshSubsetTopology topology,
@IntRange(from = 0) int indexOffset,
@IntRange(from = 0) int indexCount
)
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 |
addVertexData
public final @NonNull CustomMesh.BuilderFromMeshData addVertexData(@NonNull ByteBufferRegion vertexData)
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
public final @NonNull CustomMesh.BuilderFromMeshData addVertexData(
@NonNull ByteBuffer buffer,
@IntRange(from = 0) int offset,
@IntRange(from = 1) int size
)
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 | |
|---|---|
@NonNull ByteBuffer buffer |
containing the data |
@IntRange(from = 0) int offset |
absolute starting position within the buffer (ignoring its current position) in bytes (defaults to 0) |
@IntRange(from = 1) int size |
number of bytes in the region (defaults to the remaining capacity of the buffer after the given offset) |
| Throws | |
|---|---|
IllegalArgumentException |
if |
build
@MainThread
public final @NonNull CustomMesh build()
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
public final @NonNull CustomMesh.BuilderFromMeshData setBounds(@NonNull BoundingBox bounds)
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
public final @NonNull CustomMesh.BuilderFromMeshData setIndexData(@NonNull ByteBufferRegion indexData)
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
public final @NonNull CustomMesh.BuilderFromMeshData setIndexData(
@NonNull ByteBuffer buffer,
@IntRange(from = 0) int offset,
@IntRange(from = 1) int size
)
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 | |
|---|---|
@NonNull ByteBuffer buffer |
containing the data |
@IntRange(from = 0) int offset |
absolute starting position within the buffer (ignoring its current position) in bytes (defaults to 0) |
@IntRange(from = 1) int size |
number of bytes in the region (defaults to the remaining capacity of the buffer after the given offset) |
| Throws | |
|---|---|
IllegalArgumentException |
if |
setTopology
public final @NonNull CustomMesh.BuilderFromMeshData setTopology(@NonNull MeshSubsetTopology topology)
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 |