# How to see the vertex descriptor of the MDLMesh helper geometries

**URL:** <https://forums.kodeco.com/t/how-to-see-the-vertex-descriptor-of-the-mdlmesh-helper-geometries/180838>\
**Category:** Metal by Tutorials\
**Created:** [November 12, 2022, 11:30am UTC](https://forums.kodeco.com/t/how-to-see-the-vertex-descriptor-of-the-mdlmesh-helper-geometries/180838 "2022-11-12T11:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikoloffgeorgi](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/nikoloffgeorgi/32/109212_2.png) [@nikoloffgeorgi](https://forums.kodeco.com/u/nikoloffgeorgi)\
**Post date:** [November 12, 2022, 11:30am UTC](https://forums.kodeco.com/t/how-to-see-the-vertex-descriptor-of-the-mdlmesh-helper-geometries/180838/1 "2022-11-12T11:30:55Z")

</div>

Hi all,

In the book chapters, we use the `VertexDescriptor.defaultLayout` to specify the vertex layout of our meshes and conform them to the render pipelines:

```auto
extension MDLVertexDescriptor {
  static var defaultLayout: MDLVertexDescriptor = {
      let vertexDescriptor = MDLVertexDescriptor()
      // fill in the vertexDescriptor
      return vertexDescriptor
  }
}

```

I am having hard times understanding how do we conform other type of meshes to this?

Or to paraphrase my question, how do I conform a mesh created by:

```auto
MDLMesh(
    boxWithExtent extent: vector_float3,
    segments: vector_uint3,
    inwardNormals: Bool,
    geometryType: MDLGeometryType,
    allocator: MDLMeshBufferAllocator?
)

```

The spec hardly says anything about the vertex layout of this mesh. I can see only one vertex buffer is returned, so the normals, pos, uv, etc must be somehow interleaved. By trial and error I can see that the first 3 floats are positions, but can’t understand how to unpack the rest and fit it into the `VertexDescriptor.defaultLayout`

Thanks!

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [November 16, 2022, 12:15am UTC](https://forums.kodeco.com/t/how-to-see-the-vertex-descriptor-of-the-mdlmesh-helper-geometries/180838/2 "2022-11-16T00:15:45Z")

</div>

@nikoloffgeorgi - so sorry - I missed this one.

When you have an `MDLMesh`, you can print out its vertex descriptor to the console.

```auto
let mdlMesh = MDLMesh(
  boxWithExtent: [0.8, 0.8, 0.8],
  segments: [10, 10, 10],
  inwardNormals: false,
  geometryType: .triangles,
  allocator: allocator
)
print(mdlMesh.vertexDescriptor)

```

This gives the result for your box:

```auto
<MDLVertexDescriptor: 0x600000d18000 attributes:(
    "<MDLVertexAttribute: 0x600001810e80 name=position format=Float3 bufferIndex=0 offset=0>",
    "<MDLVertexAttribute: 0x600001810e40 name=normal format=Float3 bufferIndex=0 offset=12>",
    "<MDLVertexAttribute: 0x600001810fc0 name=textureCoordinate format=Float2 bufferIndex=0 offset=24>"
) layouts:{
    0 = "<MDLVertexBufferLayout: 0x600000f28790 stride=32>";
}>

```

So all the attributes are in `buffer[0]` with a stride of 32. `position` and `normal` are `float3` and `textureCoordinate` is `float2`.

You can create a new pipeline state for this vertex descriptor instead of using `defaultVertexDescriptor`. You could also decide to reconfigure `defaultVertexDescriptor` depending on how you want your models to import.

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [November 16, 2022, 12:36am UTC](https://forums.kodeco.com/t/how-to-see-the-vertex-descriptor-of-the-mdlmesh-helper-geometries/180838/3 "2022-11-16T00:36:36Z")

</div>

I also think that assigning an `MDLVertexDescriptor` to the `MDLMesh` will rearrange the buffers when you convert it to an `MTKMesh`. 🤞

This playground appears to work.

[VertexDescriptor.playground.zip](https://forums.kodeco.com/uploads/short-url/gjS404aizRFODF8zr7guzoACb5j.zip) (13.7 KB)

Here I have used `MDLVertexDescriptor.defaultLayout` from the lighting chapter, and assigned it to the box mesh. The `MDLMesh` to `MTKMesh` conversion appears to take place correctly, according to the new vertex descriptor.
