<!--
{
  "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" : "MetalKit",
  "identifier" : "/documentation/MetalKit/MTKMesh/init(mesh:device:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "MetalKit"
    ],
    "preciseIdentifier" : "c:objc(cs)MTKMesh(im)initWithMesh:device:error:"
  },
  "title" : "init(mesh:device:)"
}
-->

# init(mesh:device:)

Initializes a MetalKit mesh and its submeshes from a Model I/O mesh.

```
init(mesh: MDLMesh, device: any MTLDevice) throws
```

## Parameters

`mesh`

The source Model I/O mesh from which to create this MetalKit mesh.

`device`

The Metal device on which to create MetalKit mesh resources.

## Return Value

A new MetalKit mesh object, or `nil` if an error occured.

## Discussion

This initializer does *not* initialize any children meshes of the Model I/O mesh.

All vertex buffers in the source Model I/O mesh and the index buffer of each of its submeshes must have been created with a [`MTKMeshBufferAllocator`](/documentation/MetalKit/MTKMeshBufferAllocator) object.

A Model I/O submesh may have its index type and/or geometric primitive type converted to a corresponding Metal type as listed in the tables below. If the geometric primitive type cannot be converted, an error is returned through `error`.

|MDLIndexBitDepth                                                                                  |MTLIndexType        |
|--------------------------------------------------------------------------------------------------|--------------------|
|`MDLIndexBitDepthInvalid` ![](spacer) `MDLIndexBitDepthUInt8` ![](spacer) `MDLIndexBitDepthUInt16`|`MTLIndexTypeUInt16`|
|`MDLIndexBitDepthUInt32`                                                                          |`MTLIndexTypeUInt32`|

|MDLGeometryType                                                                                            |MTLPrimitiveType               |
|-----------------------------------------------------------------------------------------------------------|-------------------------------|
|`MDLGeometryTypePoints`                                                                                    |`MTLPrimitiveTypePoint`        |
|`MDLGeometryTypeLines`                                                                                     |`MTLPrimitiveTypeLine`         |
|`MDLGeometryTypeTriangleStrips`                                                                            |`MTLPrimitiveTypeTriangleStrip`|
|`MDLGeometryTypeTriangles` ![](spacer) `MDLGeometryTypeQuads` ![](spacer) `MDLGeometryTypeVariableTopology`|`MTLPrimitiveTypeTriangle`     |

> Note:
> In macOS, vertex buffers allocated from a ``doc://com.apple.metalkit/documentation/MetalKit/MTKMeshBufferAllocator`` object are aligned to 256 bytes. Index buffers are not aligned.

---

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)