---
title: LowLevelMesh
framework: realitykit
role: symbol
role_heading: Class
path: realitykit/lowlevelmesh
---

# LowLevelMesh

A container for vertex data that you can use to create and update meshes using your own format.

## Declaration

```swift
@MainActor class LowLevelMesh
```

## Mentioned in

Creating a plane with low-level mesh

## Overview

Overview Use LowLevelMesh when you want to bring your own vertex format to RealityKit or update your data frequently. To update your data in LowLevelMesh, you can either use Swift for CPU processing, or Metal Compute Shaders for GPU processing. note: Use MeshDescriptor for a simpler alternative to LowLevelMesh. For information on loading a model from a USD or Reality file, see Loading entities from a file. Express your vertex by creating a LowLevelMesh.Descriptor that describes your layout, along with the required index and vertex capacities. This descriptor is similar to MTLVertexDescriptor, with additional semantics that make the data available in your shaders. To use LowLevelMesh, first define your own vertex structure, either in a Metal header or using a Swift structure: struct MyVertex {     var position: SIMD3<Float> = .zero     var color: UInt32 = .zero } Next, describe your structure to LowLevelMesh by creating a list of vertex attributes and a vertex layout. This description informs LowLevelMesh how to represent the vertex data in memory: extension MyVertex {     static var vertexAttributes: [LowLevelMesh.Attribute] = [         .init(semantic: .position, format: .float3, offset: MemoryLayout<Self>.offset(of: \.position)!),         .init(semantic: .color, format: .uchar4Normalized_bgra, offset: MemoryLayout<Self>.offset(of: \.color)!)     ]

static var vertexLayouts: [LowLevelMesh.Layout] = [         .init(bufferIndex: 0, bufferStride: MemoryLayout<Self>.stride)     ]

static var descriptor: LowLevelMesh.Descriptor {         var desc = LowLevelMesh.Descriptor()         desc.vertexAttributes = MyVertex.vertexAttributes         desc.vertexLayouts = MyVertex.vertexLayouts         desc.indexType = .uint32         return desc     } } Create a LowLevelMesh.Descriptor and LowLevelMesh, and assign your mesh data and parts: func triangleMesh() throws -> LowLevelMesh {     var desc = MyVertex.descriptor     desc.vertexCapacity = 3     desc.indexCapacity = 3

let mesh = try LowLevelMesh(descriptor: desc)

mesh.withUnsafeMutableBytes(bufferIndex: 0) { rawBytes in         let vertices = rawBytes.bindMemory(to: MyVertex.self)         vertices[0] = MyVertex(position: [-1, -1, 0], color: 0xFF00FF00)         vertices[1] = MyVertex(position: [ 1, -1, 0], color: 0xFFFF0000)         vertices[2] = MyVertex(position: [ 0,  1, 0], color: 0xFF0000FF)     }

mesh.withUnsafeMutableIndices { rawIndices in         let indices = rawIndices.bindMemory(to: UInt32.self)         indices[0] = 0         indices[1] = 1         indices[2] = 2     }

let meshBounds = BoundingBox(min: [-1, -1, 0], max: [1, 1, 0])     mesh.parts.replaceAll([         LowLevelMesh.Part(             indexCount: 3,             topology: .triangle,             bounds: meshBounds         )     ])

return mesh } To finish, create a MeshResource from the LowLevelMesh, and add it to a ModelComponent. You can then add this model to any Entity in your scene: func triangleEntity() throws -> Entity {     let lowLevelMesh = try triangleMesh()     let resource = try MeshResource(from: lowLevelMesh)

let modelComponent = ModelComponent(mesh: resource, materials: [UnlitMaterial()])

let entity = Entity()     entity.name = "Triangle"     entity.components.set(modelComponent)     entity.scale *= 0.1     return entity } The low-level mesh creates a triangular shape in your RealityKit scene:

The MeshResource retains a reference to the LowLevelMesh, reflecting any changes when the renderer updates.

## Topics

### Creating a low-level mesh

- [init(descriptor:)](realitykit/lowlevelmesh/init(descriptor:).md)

### Describing a low-level mesh

- [descriptor](realitykit/lowlevelmesh/descriptor-swift.property.md)
- [parts](realitykit/lowlevelmesh/parts.md)
- [indexCapacity](realitykit/lowlevelmesh/indexcapacity.md)
- [vertexCapacity](realitykit/lowlevelmesh/vertexcapacity.md)

### Accessing mesh data on the CPU with Swift

- [withUnsafeBytes(bufferIndex:_:)](realitykit/lowlevelmesh/withunsafebytes(bufferindex:_:).md)
- [withUnsafeMutableBytes(bufferIndex:_:)](realitykit/lowlevelmesh/withunsafemutablebytes(bufferindex:_:).md)
- [withUnsafeIndices(_:)](realitykit/lowlevelmesh/withunsafeindices(_:).md)
- [withUnsafeMutableIndices(_:)](realitykit/lowlevelmesh/withunsafemutableindices(_:).md)
- [replaceUnsafeMutableBytes(bufferIndex:_:)](realitykit/lowlevelmesh/replaceunsafemutablebytes(bufferindex:_:).md)
- [replaceUnsafeMutableIndices(_:)](realitykit/lowlevelmesh/replaceunsafemutableindices(_:).md)

### Accessing mesh data on the GPU with Metal

- [read(bufferIndex:using:)](realitykit/lowlevelmesh/read(bufferindex:using:).md)
- [readIndices(using:)](realitykit/lowlevelmesh/readindices(using:).md)
- [replace(bufferIndex:using:)](realitykit/lowlevelmesh/replace(bufferindex:using:).md)
- [replaceIndices(using:)](realitykit/lowlevelmesh/replaceindices(using:).md)

### Structures

- [LowLevelMesh.Attribute](realitykit/lowlevelmesh/attribute.md)
- [LowLevelMesh.Descriptor](realitykit/lowlevelmesh/descriptor-swift.struct.md)
- [LowLevelMesh.Layout](realitykit/lowlevelmesh/layout.md)
- [LowLevelMesh.Part](realitykit/lowlevelmesh/part.md)
- [LowLevelMesh.PartsCollection](realitykit/lowlevelmesh/partscollection.md)

### Enumerations

- [LowLevelMesh.VertexSemantic](realitykit/lowlevelmesh/vertexsemantic.md)

## Relationships

### Conforms To

- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Updatable meshes

- [Integrating virtual objects with your environment](realitykit/integrating-virtual-objects-with-your-environment.md)
- [Creating a spatial drawing app with RealityKit](realitykit/creating-a-spatial-drawing-app-with-realitykit.md)
- [Creating a plane with low-level mesh](realitykit/creating-a-plane-with-low-level-mesh.md)
- [LowLevelMesh.Descriptor](realitykit/lowlevelmesh/descriptor-swift.struct.md)
- [LowLevelMesh.Part](realitykit/lowlevelmesh/part.md)
- [LowLevelMesh.Layout](realitykit/lowlevelmesh/layout.md)
- [LowLevelMesh.Attribute](realitykit/lowlevelmesh/attribute.md)
- [LowLevelMesh.VertexSemantic](realitykit/lowlevelmesh/vertexsemantic.md)
- [LowLevelMesh.PartsCollection](realitykit/lowlevelmesh/partscollection.md)
- [LowLevelBuffer](realitykit/lowlevelbuffer.md)
- [LowLevelInstanceData](realitykit/lowlevelinstancedata.md)
