// Create a triangle mesh with 3 vertices and 3 indices (one triangle)
val mesh = TriangleMesh(
numberVertices = 3,
numberOfIndices = 3,
materialRanges = intArrayOf(0, 3), // All indices use the first material
materials = arrayOf(material)
)
// Update the vertex positions, normals, and UVs
mesh.updateGeometry(
startIndex = 0,
positions = floatArrayOf(
0f, 0f, 0f, // Vertex 0
1f, 0f, 0f, // Vertex 1
0f, 1f, 0f // Vertex 2
),
normals = floatArrayOf(
0f, 0f, 1f, // Normal for vertex 0
0f, 0f, 1f, // Normal for vertex 1
0f, 0f, 1f // Normal for vertex 2
),
uvs = floatArrayOf(
0f, 0f, // UV for vertex 0
1f, 0f, // UV for vertex 1
0f, 1f // UV for vertex 2
),
colors = null // No per-vertex colors
)
// Update the triangle indices
mesh.updatePrimitives(
startIndex = 0,
indices = intArrayOf(0, 1, 2) // Triangle connecting vertices 0, 1, and 2
)
// Convert to a SceneMesh for rendering
val sceneMesh = SceneMesh.fromTriangleMesh(mesh)
class TriangleMesh
TriangleMesh
(
numberVertices
, numberOfIndices
, materialRanges
, materials
)
|
Creates a new triangle mesh with the specified parameters.
Signature
constructor(numberVertices: Int, numberOfIndices: Int, materialRanges: IntArray, materials: Array<SceneMaterial>) Parameters
numberVertices:
Int
numberOfIndices:
Int
materialRanges:
IntArray
materials:
Array
Returns |
handle
: Long
[Get] |
Signature
var handle: Long |
materials
: Array
[Get] |
Signature
var materials: Array<SceneMaterial> |
destroy
()
|
Signature
fun destroy() |
updateGeometry
(
startIndex
, positions
, normals
, uvs
, colors
)
|
Updates the geometry data of the mesh.
Signature
fun updateGeometry(startIndex: Int, positions: FloatArray?, normals: FloatArray?, uvs: FloatArray?, colors: IntArray?) Parameters
startIndex:
Int
positions:
FloatArray?
normals:
FloatArray?
uvs:
FloatArray?
colors:
IntArray?
|
updatePrimitives
(
startIndex
, indices
)
|
Updates the triangle indices of the mesh.
Triangle indices define how vertices are connected to form triangles. Each triplet of indices represents one triangle.
Signature
fun updatePrimitives(startIndex: Int, indices: IntArray) Parameters
startIndex:
Int
indices:
IntArray
|