<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/MeshResource",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation12MeshResourceC"
  },
  "title" : "MeshResource"
}
-->

# MeshResource

A high-level representation of a collection of vertices and edges that define a shape.

```
@MainActor @preconcurrency class MeshResource
```

## Overview

Use [`MeshResource`](/documentation/RealityKit/MeshResource) to create procedural geometry from built-in primitives
like boxes, spheres, planes, and cylinders, or from custom mesh data. Assign
a mesh resource to an entity’s [`ModelComponent`](/documentation/RealityKit/ModelComponent) alongside an array of
[`Material`](/documentation/RealityKit/Material) instances to render the shape in a scene.

Check [`expectedMaterialCount`](/documentation/RealityKit/MeshResource/expectedMaterialCount) to determine how many materials the mesh requires.

## Topics

### Creating a mesh resource

[`generate(from:)`](/documentation/RealityKit/MeshResource/generate(from:)-4aahn)

Create a mesh resource from contents.

[`generate(from:)`](/documentation/RealityKit/MeshResource/generate(from:)-4aahn)

Create a mesh resource from contents.

[`init(from:)`](/documentation/RealityKit/MeshResource/init(from:)-1i7c9)

Asynchronously creates a mesh resource from a low-level mesh.

[`init(from:)`](/documentation/RealityKit/MeshResource/init(from:)-1i7c9)

Asynchronously creates a mesh resource from a low-level mesh.

[`init(shape:)`](/documentation/RealityKit/MeshResource/init(shape:)-3rtda)

Generates a MeshResource from a ShapeResource.

[`init(shape:)`](/documentation/RealityKit/MeshResource/init(shape:)-3rtda)

Generates a MeshResource from a ShapeResource.

[`generateAsync(from:)`](/documentation/RealityKit/MeshResource/generateAsync(from:)-1n2vv)

Create a mesh resource from contents asynchronously.

[`generateAsync(from:)`](/documentation/RealityKit/MeshResource/generateAsync(from:)-1n2vv)

Create a mesh resource from contents asynchronously.

### Creating a low level resource

[`init(from:)`](/documentation/RealityKit/MeshResource/init(from:)-1i7c9)

Asynchronously creates a mesh resource from a low-level mesh.

[`init(from:)`](/documentation/RealityKit/MeshResource/init(from:)-1i7c9)

Asynchronously creates a mesh resource from a low-level mesh.

[`lowLevelMesh`](/documentation/RealityKit/MeshResource/lowLevelMesh)

The low-level mesh that this mesh is built from, if any.

### Configuring the resource

[`expectedMaterialCount`](/documentation/RealityKit/MeshResource/expectedMaterialCount)

The number of material entries required to render the mesh resource.

[`replace(with:)`](/documentation/RealityKit/MeshResource/replace(with:)-g0kn)

Replace the contents of this mesh resource.

[`replace(with:)`](/documentation/RealityKit/MeshResource/replace(with:)-g0kn)

Replace the contents of this mesh resource.

[`replaceAsync(with:)`](/documentation/RealityKit/MeshResource/replaceAsync(with:))

Replace the contents of this mesh resource asynchronously.

### Accessing resource data

[`contents`](/documentation/RealityKit/MeshResource/contents-swift.property)

Get the contents of the mesh asset.

### Getting a bounding box

[`bounds`](/documentation/RealityKit/MeshResource/bounds)

A box that bounds the mesh in local coordinate space.

### Creating a box

[`generateBox(size:cornerRadius:)`](/documentation/RealityKit/MeshResource/generateBox(size:cornerRadius:)-8em0v)

Creates a box mesh from a length for the box’s width, height, and depth, and a radius for the corners.

[`generateBox(size:cornerRadius:)`](/documentation/RealityKit/MeshResource/generateBox(size:cornerRadius:)-2ovma)

Creates a box mesh from a vector of three scalar values that represent width, height, and depth, respectively, and a radius for the corners.

[`generateBox(width:height:depth:cornerRadius:splitFaces:)`](/documentation/RealityKit/MeshResource/generateBox(width:height:depth:cornerRadius:splitFaces:))

Creates a box mesh from a width, height, depth and a corner radius, with the ability to assign different materials to each face.

[`generateBox(size:majorCornerRadius:minorCornerRadius:)`](/documentation/RealityKit/MeshResource/generateBox(size:majorCornerRadius:minorCornerRadius:))

Creates a box mesh from a vector of three scalar values that represent width, height, and depth, respectively, and radii for the corners.

### Creating a plane

[`generatePlane(width:height:cornerRadius:)`](/documentation/RealityKit/MeshResource/generatePlane(width:height:cornerRadius:))

Creates a new rectangle mesh with the specified dimensions in the entity’s xy-plane.

[`generatePlane(width:depth:cornerRadius:)`](/documentation/RealityKit/MeshResource/generatePlane(width:depth:cornerRadius:))

Creates a new rectangle mesh with the specified dimensions in the entity’s xz-plane.

### Creating a primitive shape

[`generateSphere(radius:)`](/documentation/RealityKit/MeshResource/generateSphere(radius:))

Creates a new sphere mesh with the specified radius.

[`generateCone(height:radius:)`](/documentation/RealityKit/MeshResource/generateCone(height:radius:))

Creates a new cone mesh with the specified dimensions.

[`generateCylinder(height:radius:)`](/documentation/RealityKit/MeshResource/generateCylinder(height:radius:))

Creates a new cylinder mesh with the specified dimensions.

### Creating a text mesh resource

[`generateText(_:extrusionDepth:font:containerFrame:alignment:lineBreakMode:)`](/documentation/RealityKit/MeshResource/generateText(_:extrusionDepth:font:containerFrame:alignment:lineBreakMode:)-3py6y)

Generates a 3D mesh for rendering static text.

[`generateText(_:extrusionDepth:font:containerFrame:alignment:lineBreakMode:)`](/documentation/RealityKit/MeshResource/generateText(_:extrusionDepth:font:containerFrame:alignment:lineBreakMode:)-3py6y)

Generates a 3D mesh for rendering static text.

[`init(extruding:textOptions:extrusionOptions:)`](/documentation/RealityKit/MeshResource/init(extruding:textOptions:extrusionOptions:)-7xk2s)

Synchronously generates a 3D mesh from a string,
with options for text layout and custom extrusions.

[`init(extruding:textOptions:extrusionOptions:)`](/documentation/RealityKit/MeshResource/init(extruding:textOptions:extrusionOptions:)-7xk2s)

Synchronously generates a 3D mesh from a string,
with options for text layout and custom extrusions.

### Creating a 3D mesh by extruding a 2D path

[`init(extruding:extrusionOptions:)`](/documentation/RealityKit/MeshResource/init(extruding:extrusionOptions:)-6640v)

Synchronously generates a 3D mesh by extruding a 2D path.

[`init(extruding:extrusionOptions:)`](/documentation/RealityKit/MeshResource/init(extruding:extrusionOptions:)-6640v)

Synchronously generates a 3D mesh by extruding a 2D path.

### Creating a mesh from an anchor

[`init(from:)`](/documentation/RealityKit/MeshResource/init(from:)-1i7c9)

Asynchronously creates a mesh resource from a low-level mesh.

[`init(from:)`](/documentation/RealityKit/MeshResource/init(from:)-1i7c9)

Asynchronously creates a mesh resource from a low-level mesh.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)