为什么 MDLMesh 有未命名的默认属性?

Why does MDLMesh have unnamed default attributes?

我正在发现 Model I/O,我想用它来生成顶点来创建一个球体,所以我使用这个 class 方法创建了一个 MDLMesh 对象:

let sphere = MDLMesh.newEllipsoidWithRadii(vector_float3(1, 1, 1), radialSegments: 300, verticalSegments: 300, geometryType: MDLGeometryType.KindTriangles, inwardNormals: false, hemisphere: false, allocator: MTKMeshBufferAllocator(device: device))  

然后,为了了解它是如何工作的,我想检查我的这个 MDLMesh 的属性,所以我是这样阅读它们的:

for attribute in sphere.vertexDescriptor.attributes {
            if let vertexAttribute = attribute as? MDLVertexAttribute {
                print("Attribute named : \(vertexAttribute.name), of format \(vertexAttribute.format.rawValue)")
            }
        }

这是输出:

Attribute named : position, of format 786435
Attribute named : normal, of format 786435
Attribute named : textureCoordinate, of format 786434
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0
Attribute named : , of format 0 Attribute named : , of format 0

我相信位置和法线是自动生成的,但为什么会有纹理坐标?使用什么规则来生成这些? 最重要的是,为什么所有这些未命名的属性都是无效格式?

谢谢

编辑:似乎有固定数量的属性(在我的例子中是 31 个),因为即使我添加新的自定义属性(例如通过生成法线),无效的属性也会被替换为那些新增属性,属性总数仍为31

A​​pple 似乎将默认 vertexDescriptor 配置为使用前 3 个属性创建,供您使用。它们恰好也是人们需要使用的最常见的属性。你还有 28 个属性 "holders" 以防你需要使用比这 3 个更多的属性。顺便说一句,它们不是无效格式,它们目前只占用 0 个字节,因为它们尚未创建和命名。您总共可以创建 15 种类型的顶点属性,如果需要,您还可以创建更多相同类型的顶点属性。有关 nameformat 的更多信息,您可以阅读 MDLVertexAttribute Class Reference 文档。