API reference
API reference
Select your platform
No SDKs available
No versions available

TriangleMesh

TriangleMesh

class TriangleMesh
TriangleMesh provides direct access to the vertex and index data of a 3D mesh, allowing for dynamic creation and modification of geometry.
TriangleMesh can be used to create a SceneMesh via SceneMesh.fromTriangleMesh(), or to update an existing SceneMesh via SceneMesh.updateWithTriangleMesh().
Example usage:
// 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)

Constructors

NameSummary
TriangleMesh
constructor(numberVertices: Int, numberOfIndices: Int, materialRanges: IntArray, materials: Array<SceneMaterial>)

Creates a new triangle mesh with the specified parameters.

Properties

NameSummary
handle
var handle: Long
materials
var materials: Array<SceneMaterial>

Functions

NameSummary
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.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon