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.
Declaration
@MainActor @preconcurrency static func generateBox(width: Float, height: Float, depth: Float, cornerRadius: Float = 0, splitFaces: Bool = false) -> MeshResourceParameters
- 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
cornerRadiuscan be, at most, equal to the smallest value of thewidth,height, anddepthparameters. For example, if the box’s dimensions are3.0x4.0x5.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) |