<!--
{
  "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/generateBox(width:height:depth:cornerRadius:splitFaces:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation12MeshResourceC11generateBox5width6height5depth12cornerRadius10splitFacesACSf_S3fSbtFZ"
  },
  "title" : "generateBox(width:height:depth:cornerRadius:splitFaces:)"
}
-->

# 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.

```
@MainActor @preconcurrency static func generateBox(width: Float, height: Float, depth: Float, cornerRadius: Float = 0, splitFaces: Bool = false) -> MeshResource
```

## Parameters

`width`

The length of the box’s width, in meters, along the x-axis.

`height`

The length of the box’s height, in meters, along the y-axis.

`depth`

The length of the box’s depth, in meters, along the z-axis.

`cornerRadius`

The radius of each corner’s circular arc, in meters.
Values for `cornerRadius` can be, at most, equal to the smallest
value of the `width`, `height`, and `depth` parameters.
For example, if the box’s dimensions are `3.0` x `4.0` x `5.0`,
the corner radius needs to be in the range `[0.0, 1.5]`.

`splitFaces`

A Boolean value that indicates whether you can assign up
to six separate materials, one for each face. If `false`, you can only
assign one material for all six faces.

## Discussion

The method centers the box at the entity’s origin and aligns the box’s
faces with the coordinate system’s axes.

When `splitFaces` is `true`, the box contains six submeshes, one per
face, allowing you to assign a different material to each face. The
faces correspond to material indices in the following order:

|Material Index|Face       |
|--------------|-----------|
|0             |Front (+Z) |
|1             |Top (+Y)   |
|2             |Back (-Z)  |
|3             |Bottom (-Y)|
|4             |Right (+X) |
|5             |Left (-X)  |

> Note: The method clamps `cornerRadius` so that it doesn’t exceed half
> the length of the box’s smallest dimension.

---

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)