【发布时间】:2016-11-02 17:48:10
【问题描述】:
我正在发现Model I/O,我想用它来生成顶点来创建一个球体,所以我使用这个类方法创建了一个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)")
}
}
这是输出:
属性命名:位置,格式为 786435
属性命名:正常,格式为 786435
属性名为:textureCoordinate,格式为 786434
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
属性名为 : ,格式为 0 属性名为 : ,格式为 0
我相信位置和法线是自动生成的,但为什么会有纹理坐标?使用什么规则来生成这些? 最重要的是,为什么会有所有这些无效格式的未命名属性?
谢谢
编辑:似乎有固定数量的属性(在我的情况下为 31 个),因为即使我添加新的自定义属性(例如通过生成法线),无效的属性也会被这些新属性替换属性总数还是31个。
【问题讨论】: