Mesh

Objectunityengine.Mesh (extern class)

Represents 3D geometry data for rendering. Meshes contain vertex positions, normals, UVs, colors, and triangle indices.

In Ceramic's Unity backend, Meshes are used for efficient batch rendering of 2D sprites and shapes. The backend dynamically builds meshes from Ceramic's visual elements for optimal GPU performance.

Key components:

  • Vertex buffer: Per-vertex data (position, UV, color, etc.)
  • Index buffer: Triangle definitions referencing vertices
  • SubMeshes: Separate sections for different materials

Modern Unity mesh API features:

  • Direct buffer access for performance
  • Multiple vertex streams
  • 32-bit index support for large meshes
  • Efficient update flags
See: MeshTopology, VertexAttributeDescriptor

Instance Members

unity
subMeshCount: Int

Number of sub-meshes in this mesh. Each sub-mesh can use a different material.

Ceramic typically uses one sub-mesh per draw call, allowing batching of similar visuals.


unity
SetVertexBufferParams(vertexCount: Int, attributes: cs.NativeArray<unityengine.rendering.VertexAttributeDescriptor>): Void

Defines the vertex buffer layout and size. Must be called before setting vertex data.

Name Type Description
vertexCount Int Total number of vertices
attributes cs.NativeArray<unityengine.rendering.VertexAttributeDescriptor> Array defining vertex data layout: - Position (Vector3) - UV coordinates (Vector2) - Color (Color32) - Normal (Vector3) etc. * This configures how vertex data is interpreted by shaders.

unity
SetVertexBufferData(data: cs.NativeArray<Single>, dataStart: Int, meshBufferStart: Int, count: Int, stream: Int, flags: unityengine.rendering.MeshUpdateFlags): Void

Uploads vertex data to the GPU. Data must match the layout from SetVertexBufferParams.

Name Type Description
data cs.NativeArray<Single> Source array of vertex data (interleaved floats)
dataStart Int Starting index in source array
meshBufferStart Int Starting vertex index in mesh
count Int Number of floats to copy
stream Int Vertex stream index (0 for main stream)
flags unityengine.rendering.MeshUpdateFlags Update behavior: - Default: Normal update - DontValidateIndices: Skip validation for performance - DontResetBoneBounds: Preserve skeletal bounds * For Ceramic, this typically contains position, UV, and color data.

unity
SetIndexBufferParams(indexCount: Int, format: unityengine.rendering.IndexFormat): Void

Defines the index buffer size and format. Must be called before setting index data.

Name Type Description
indexCount Int Total number of indices (3 per triangle)
format unityengine.rendering.IndexFormat Index data type: - UInt16: 16-bit indices (max 65k vertices) - UInt32: 32-bit indices (max 4B vertices) * Ceramic uses UInt16 for most cases as meshes are rebuilt frequently.

unity
SetIndexBufferData(data: cs.NativeArray<cs.types.UInt16>, dataStart: Int, meshBufferStart: Int, count: Int, flags: unityengine.rendering.MeshUpdateFlags): Void

Uploads triangle index data to the GPU. Defines which vertices form triangles.

Name Type Description
data cs.NativeArray<cs.types.UInt16> Source array of indices (triangle vertex references)
dataStart Int Starting index in source array
meshBufferStart Int Starting index in mesh buffer
count Int Number of indices to copy
flags unityengine.rendering.MeshUpdateFlags Update behavior flags * Indices should be in groups of 3 for triangle topology. Winding order affects face culling (clockwise = front).

Defines a sub-mesh within the mesh. Each sub-mesh can render with a different material.

Name Type Description
index Int Sub-mesh index (0 to subMeshCount-1)
desc unityengine.rendering.SubMeshDescriptor Sub-mesh definition: - indexStart: First index in buffer - indexCount: Number of indices - topology: Usually MeshTopology.Triangles
flags unityengine.rendering.MeshUpdateFlags Update behavior flags * Ceramic uses sub-meshes to batch visuals by texture/shader.

unity
new(): Void

Creates a new empty Mesh. Must set vertex and index data before use.

Creating a simple quad:

var mesh = new Mesh();
mesh.SetVertexBufferParams(4, vertexLayout);
// Set vertices...
mesh.SetIndexBufferParams(6, IndexFormat.UInt16);
// Set indices...

Metadata

Name Parameters
:nativeGen -