Type Method

newBoxWithDimensions:segments:geometryType:inwardNormals:allocator:

Creates a mesh in the shape of a rectangular box or cube.

Declaration

+ (instancetype)newBoxWithDimensions:(vector_float3)dimensions segments:(vector_uint3)segments geometryType:(MDLGeometryType)geometryType inwardNormals:(BOOL)inwardNormals allocator:(id<MDLMeshBufferAllocator>)allocator;

Parameters

dimensions

A vector containing the width (x-component), height (y-component), and depth (z-component) of the box to generate. If all components are equal, this method generates a cube.

segments

The number of points to generate along each dimension. A larger number of points increases rendering fidelity but decreases rendering performance.

geometryType

The type of geometric primitive from which to construct the mesh; must be either MDLGeometryKindTriangles, MDLGeometryKindQuads, or MDLGeometryTypeLines.

inwardNormals

YES to generate normal vectors pointing toward the inside of the box; NO to generate normal vectors pointing outward.

allocator

An object responsible for allocating mesh vertex data. If nil, Model I/O uses an internal allocator object.

Return Value

A new mesh object.

Discussion

This method generates vertex data for a box centered at the origin of its local coordinate system.

The inwardNormals parameter determines the direction of generated vertex normal vectors for the mesh. Specify YES if the mesh will be viewed from inside (for example, for use in a sky effect), or NO if the mesh will be viewed from outside.

The allocator parameter controls vertex data allocation for the mesh. For example, to use the MetalKit framework for loading vertex data into GPU buffers for rendering using Metal, pass a MTKMeshBufferAllocator object. By specifying an allocator, you can ensure that mesh data is copied a minimal number of times between being read from a file and being loaded into GPU memory for rendering.

See Also

Creating Parametric Meshes

+ newCylinderWithHeight:radii:radialSegments:verticalSegments:geometryType:inwardNormals:allocator:

Generates a mesh in the shape of a right circular or elliptical cylinder.

+ newPlaneWithDimensions:segments:geometryType:allocator:

Generates a mesh in the shape of a rectangular plane.

+ newIcosahedronWithRadius:inwardNormals:allocator:

Generates a mesh in the shape of a regular 20-sided polyhedron with triangular faces.