Class

MDLMesh

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

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

Generating Geometry Data

func addNormals(withAttributeNamed: String?, creaseThreshold: Float)

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

func addTangentBasis(forTextureCoordinateAttributeNamed: String, tangentAttributeNamed: String, bitangentAttributeNamed: String?)

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

func addTangentBasis(forTextureCoordinateAttributeNamed: String, normalAttributeNamed: String, tangentAttributeNamed: String)

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

func makeVerticesUnique()

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

Deprecated

Generating Ambient Occlusion Data

func generateAmbientOcclusionTexture(withSize: vector_int2, raysPerSample: Int, attenuationFactor: Float, objectsToConsider: [MDLObject], vertexAttributeNamed: String, materialPropertyNamed: String)

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

func generateAmbientOcclusionVertexColors(withQuality: Float, attenuationFactor: Float, objectsToConsider: [MDLObject], vertexAttributeNamed: String)

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

func generateAmbientOcclusionVertexColors(withRaysPerSample: Int, attenuationFactor: Float, objectsToConsider: [MDLObject], vertexAttributeNamed: String)

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

func generateLightMapTexture(withTextureSize: vector_int2, lightsToConsider: [MDLLight], objectsToConsider: [MDLObject], vertexAttributeNamed: String, materialPropertyNamed: String)

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

func generateLightMapVertexColorsWithLights(toConsider: [MDLLight], objectsToConsider: [MDLObject], vertexAttributeNamed: String)

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

Creating Parametric Meshes

class func newIcosahedron(withRadius: Float, inwardNormals: Bool, allocator: MDLMeshBufferAllocator?)

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

Importing Mesh Objects from SceneKit

init(scnGeometry: SCNGeometry, bufferAllocator: MDLMeshBufferAllocator?)

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

init(scnGeometry: SCNGeometry)

Creates a mesh from the specified SceneKit geometry.

Relationships

Inherits From

See Also

3D Asset Basics

class MDLAsset

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

class MDLObject

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

class MDLTransform

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

class MDLSubmesh

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

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

protocol MDLNamed

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