<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ModelIO",
  "identifier" : "/documentation/ModelIO/MDLMesh",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Model I/O"
    ],
    "preciseIdentifier" : "c:objc(cs)MDLMesh"
  },
  "title" : "MDLMesh"
}
-->

# MDLMesh

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

```
class MDLMesh
```

## Overview

A mesh contains one or more [`MDLSubmesh`](/documentation/ModelIO/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`](/documentation/ModelIO/MDLAsset) object, but you can also create meshes from your own vertex data or create parametric meshes. The [`MDLMesh`](/documentation/ModelIO/MDLMesh) class also supports processing meshes to generate vertex attributes or to bake lighting information.

## Topics

### Creating a Custom Mesh

[`init(vertexBuffer:vertexCount:descriptor:submeshes:)`](/documentation/ModelIO/MDLMesh/init(vertexBuffer:vertexCount:descriptor:submeshes:))

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

[`init(vertexBuffers:vertexCount:descriptor:submeshes:)`](/documentation/ModelIO/MDLMesh/init(vertexBuffers:vertexCount:descriptor:submeshes:))

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

[`init(bufferAllocator:)`](/documentation/ModelIO/MDLMesh/init(bufferAllocator:))

[`newSubdividedMesh(_:submeshIndex:subdivisionLevels:)`](/documentation/ModelIO/MDLMesh/newSubdividedMesh(_:submeshIndex:subdivisionLevels:))

Creates a new mesh by subdividing the specified mesh.

[`init(meshBySubdividingMesh:submeshIndex:subdivisionLevels:allocator:)`](/documentation/ModelIO/MDLMesh/init(meshBySubdividingMesh:submeshIndex:subdivisionLevels:allocator:))

### Working with Vertex Data

[`boundingBox`](/documentation/ModelIO/MDLMesh/boundingBox)

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

[`submeshes`](/documentation/ModelIO/MDLMesh/submeshes)

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

[`vertexBuffers`](/documentation/ModelIO/MDLMesh/vertexBuffers)

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

[`vertexCount`](/documentation/ModelIO/MDLMesh/vertexCount)

The number of vertices in the mesh.

[`vertexDescriptor`](/documentation/ModelIO/MDLMesh/vertexDescriptor)

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

[`allocator`](/documentation/ModelIO/MDLMesh/allocator)

[`addAttribute(withName:format:)`](/documentation/ModelIO/MDLMesh/addAttribute(withName:format:))

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

[`addAttribute(withName:format:type:data:stride:)`](/documentation/ModelIO/MDLMesh/addAttribute(withName:format:type:data:stride:))

[`addAttribute(withName:format:type:data:stride:time:)`](/documentation/ModelIO/MDLMesh/addAttribute(withName:format:type:data:stride:time:))

[`removeAttributeNamed(_:)`](/documentation/ModelIO/MDLMesh/removeAttributeNamed(_:))

[`replaceAttributeNamed(_:with:)`](/documentation/ModelIO/MDLMesh/replaceAttributeNamed(_:with:))

[`updateAttributeNamed(_:with:)`](/documentation/ModelIO/MDLMesh/updateAttributeNamed(_:with:))

[`addUnwrappedTextureCoordinates(forAttributeNamed:)`](/documentation/ModelIO/MDLMesh/addUnwrappedTextureCoordinates(forAttributeNamed:))

[`vertexAttributeData(forAttributeNamed:)`](/documentation/ModelIO/MDLMesh/vertexAttributeData(forAttributeNamed:))

Returns the vertex data for the specified attribute.

[`vertexAttributeData(forAttributeNamed:as:)`](/documentation/ModelIO/MDLMesh/vertexAttributeData(forAttributeNamed:as:))

### Generating Geometry Data

[`addNormals(withAttributeNamed:creaseThreshold:)`](/documentation/ModelIO/MDLMesh/addNormals(withAttributeNamed:creaseThreshold:))

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

[`addTangentBasis(forTextureCoordinateAttributeNamed:tangentAttributeNamed:bitangentAttributeNamed:)`](/documentation/ModelIO/MDLMesh/addTangentBasis(forTextureCoordinateAttributeNamed:tangentAttributeNamed:bitangentAttributeNamed:))

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

[`addTangentBasis(forTextureCoordinateAttributeNamed:normalAttributeNamed:tangentAttributeNamed:)`](/documentation/ModelIO/MDLMesh/addTangentBasis(forTextureCoordinateAttributeNamed:normalAttributeNamed:tangentAttributeNamed:))

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

[`makeVerticesUnique()`](/documentation/ModelIO/MDLMesh/makeVerticesUnique())

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

### Generating Ambient Occlusion Data

[`generateAmbientOcclusionTexture(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)`](/documentation/ModelIO/MDLMesh/generateAmbientOcclusionTexture(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:))

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

[`generateAmbientOcclusionTexture(withSize:raysPerSample:attenuationFactor:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)`](/documentation/ModelIO/MDLMesh/generateAmbientOcclusionTexture(withSize: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.

[`generateAmbientOcclusionVertexColors(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:)`](/documentation/ModelIO/MDLMesh/generateAmbientOcclusionVertexColors(withQuality:attenuationFactor:objectsToConsider:vertexAttributeNamed:))

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

[`generateAmbientOcclusionVertexColors(withRaysPerSample:attenuationFactor:objectsToConsider:vertexAttributeNamed:)`](/documentation/ModelIO/MDLMesh/generateAmbientOcclusionVertexColors(withRaysPerSample: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

[`generateLightMapTexture(withQuality:lightsToConsider:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)`](/documentation/ModelIO/MDLMesh/generateLightMapTexture(withQuality:lightsToConsider:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:))

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

[`generateLightMapTexture(withTextureSize:lightsToConsider:objectsToConsider:vertexAttributeNamed:materialPropertyNamed:)`](/documentation/ModelIO/MDLMesh/generateLightMapTexture(withTextureSize: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.

[`generateLightMapVertexColorsWithLights(toConsider:objectsToConsider:vertexAttributeNamed:)`](/documentation/ModelIO/MDLMesh/generateLightMapVertexColorsWithLights(toConsider:objectsToConsider:vertexAttributeNamed:))

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

### Creating Parametric Meshes

[`newBox(withDimensions:segments:geometryType:inwardNormals:allocator:)`](/documentation/ModelIO/MDLMesh/newBox(withDimensions:segments:geometryType:inwardNormals:allocator:))

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

[`newEllipsoid(withRadii:radialSegments:verticalSegments:geometryType:inwardNormals:hemisphere:allocator:)`](/documentation/ModelIO/MDLMesh/newEllipsoid(withRadii:radialSegments:verticalSegments:geometryType:inwardNormals:hemisphere:allocator:))

Creates a mesh in the shape of an ellipsoid or sphere.

[`newCylinder(withHeight:radii:radialSegments:verticalSegments:geometryType:inwardNormals:allocator:)`](/documentation/ModelIO/MDLMesh/newCylinder(withHeight:radii:radialSegments:verticalSegments:geometryType:inwardNormals:allocator:))

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

[`newEllipticalCone(withHeight:radii:radialSegments:verticalSegments:geometryType:inwardNormals:allocator:)`](/documentation/ModelIO/MDLMesh/newEllipticalCone(withHeight:radii:radialSegments:verticalSegments:geometryType:inwardNormals:allocator:))

Generates a mesh in the shape of an elliptical or circular cone.

[`newPlane(withDimensions:segments:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/newPlane(withDimensions:segments:geometryType:allocator:))

Generates a mesh in the shape of a rectangular plane.

[`newCapsule(withHeight:radii:radialSegments:verticalSegments:hemisphereSegments:geometryType:inwardNormals:allocator:)`](/documentation/ModelIO/MDLMesh/newCapsule(withHeight:radii:radialSegments:verticalSegments:hemisphereSegments:geometryType:inwardNormals:allocator:))

[`newIcosahedron(withRadius:inwardNormals:allocator:)`](/documentation/ModelIO/MDLMesh/newIcosahedron(withRadius:inwardNormals:allocator:))

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

[`newIcosahedron(withRadius:inwardNormals:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/newIcosahedron(withRadius:inwardNormals:geometryType:allocator:))

[`init(boxWithExtent:segments:inwardNormals:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(boxWithExtent:segments:inwardNormals:geometryType:allocator:))

[`init(sphereWithExtent:segments:inwardNormals:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(sphereWithExtent:segments:inwardNormals:geometryType:allocator:))

[`init(cylinderWithExtent:segments:inwardNormals:topCap:bottomCap:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(cylinderWithExtent:segments:inwardNormals:topCap:bottomCap:geometryType:allocator:))

[`init(coneWithExtent:segments:inwardNormals:cap:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(coneWithExtent:segments:inwardNormals:cap:geometryType:allocator:))

[`init(planeWithExtent:segments:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(planeWithExtent:segments:geometryType:allocator:))

[`init(icosahedronWithExtent:inwardNormals:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(icosahedronWithExtent:inwardNormals:geometryType:allocator:))

[`init(capsuleWithExtent:cylinderSegments:hemisphereSegments:inwardNormals:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(capsuleWithExtent:cylinderSegments:hemisphereSegments:inwardNormals:geometryType:allocator:))

[`init(hemisphereWithExtent:segments:inwardNormals:cap:geometryType:allocator:)`](/documentation/ModelIO/MDLMesh/init(hemisphereWithExtent:segments:inwardNormals:cap:geometryType:allocator:))



---

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)