class TriangleMesh
// 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)
| Name | Summary |
|---|---|
TriangleMesh | constructor(numberVertices: Int, numberOfIndices: Int, materialRanges: IntArray, materials: Array<SceneMaterial>) Creates a new triangle mesh with the specified parameters. |
| Name | Summary |
|---|---|
handle | var handle: Long |
materials | var materials: Array<SceneMaterial> |
| Name | Summary |
|---|---|
destroy | fun destroy() |
updateGeometry | fun updateGeometry(startIndex: Int, positions: FloatArray?, normals: FloatArray?, uvs: FloatArray?, colors: IntArray?) Updates the geometry data of the mesh. |
updatePrimitives | fun updatePrimitives(startIndex: Int, indices: IntArray) Updates the triangle indices of the mesh. |