Class

MDLMesh

A container for vertex buffer data to be used in rendering a 3D object.

Declaration

@interface MDLMesh : MDLObject

Overview

A mesh contains one or more MDLSubmesh objects. Each submesh contains index buffer data that describes how the mesh’s vertices should be combined for drawing and references material information describing an intended surface appearance for the submesh. Typically, you obtain meshes by traversing the object hierarchy of a MDLAsset object, but you can also create meshes from your own vertex data or create parametric meshes. The MDLMesh class also supports processing meshes to generate vertex attributes or to bake lighting information.

Topics

Creating a Custom Mesh

- initWithVertexBuffer:vertexCount:descriptor:submeshes:

Creates a mesh from a single vertex buffer with the specified parameters.

- initWithVertexBuffers:vertexCount:descriptor:submeshes:

Creates a mesh by unifying vertex data from multiple sources with the specified parameters.

+ newSubdividedMesh:submeshIndex:subdivisionLevels:

Creates a new mesh by subdividing the specified mesh.

Working with Vertex Data

boundingBox

The minimum region entirely enclosing the mesh’s vertex positions, expressed in the model coordinate system of the mesh.

submeshes

The array of submeshes to be used in rendering the mesh.

vertexBuffers

The array of buffers that provide vertex data for the mesh.

vertexCount

The number of vertices in the mesh.

vertexDescriptor

A description of the format and layout of the mesh’s vertex buffers.

- addAttributeWithName:format:

Adds a vertex attribute to the mesh and creates a new, empty corresponding vertex buffer.

- vertexAttributeDataForAttributeNamed:

Returns the vertex data for the specified attribute.

Generating Geometry Data

- addNormalsWithAttributeNamed:creaseThreshold:

Generates surface normal data for the mesh based on its vertex position data.

- addTangentBasisForTextureCoordinateAttributeNamed:tangentAttributeNamed:bitangentAttributeNamed:

Generates surface tangent and bitangent data for the mesh based on its vertex position and texture coordinate data.

- addTangentBasisForTextureCoordinateAttributeNamed:normalAttributeNamed:tangentAttributeNamed:

Generates surface tangent data for the mesh based on its vertex position, surface normal, and texture coordinate data.

- makeVerticesUnique

Modifies the mesh’s vertex buffers so that no vertices are shared by multiple faces.

Deprecated

Generating Ambient Occlusion Data

- generateAmbientOcclusionTextureWithQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:

Calculates ambient occlusion (AO) information for the mesh and saves it in the mesh as a material property texture.

- generateAmbientOcclusionTextureWithSize:raysPerSample:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:

Calculates ambient occlusion (AO) information for the mesh and saves it in the mesh as a material property texture of the specified size.

- generateAmbientOcclusionVertexColorsWithQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:

Calculates ambient occlusion (AO) information for the mesh and saves it in the mesh as a vertex color attribute.

- generateAmbientOcclusionVertexColorsWithRaysPerSample:attenuationFactor:objectsToConsider:vertexAttributeNamed:

Calculates ambient occlusion (AO) information for the mesh, using the specified number of rays per sample, and saves it in the mesh as a vertex color attribute.

Generating Light Map Data

- generateLightMapTextureWithQuality:lightsToConsider:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:

Calculates static lighting information for the mesh and saves it in the mesh as a material property texture.

- generateLightMapTextureWithTextureSize:lightsToConsider:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:

Calculates static lighting information for the mesh and saves it in the mesh as a material property texture of the specified size.

- generateLightMapVertexColorsWithLightsToConsider:objectsToConsider:vertexAttributeNamed:

Calculates static lighting information for the mesh and saves it in the mesh as a vertex color attribute.

Creating Parametric Meshes

+ newBoxWithDimensions:segments:geometryType:inwardNormals:allocator:

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

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

Importing Mesh Objects from SceneKit

+ meshWithSCNGeometry:bufferAllocator:

Creates a mesh from the specified SceneKit geometry, using the specified allocator.

+ meshWithSCNGeometry:

Creates a mesh from the specified SceneKit geometry.

Relationships

Inherits From

See Also

3D Asset Basics

MDLAsset

An indexed container for 3D objects and associated information, such as transform hierarchies, meshes, cameras, and lights.

MDLObject

The base class for objects that are part of a 3D asset, including meshes, cameras, and lights.

MDLTransform

A description of the local coordinate space transformations for a 3D object.

MDLSubmesh

A container for index buffer data and material information to be used in rendering all or part of a 3D object.

MDLSubmeshTopology

A description of how a submesh's index buffer data is arranged and how that arrangement should be used to produce the submesh's intended 3D shape.

MDLNamed

The common interface for Model I/O objects that expose a human-readable name.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software