如何使用 Swift 调试 SceneKit 中的自定义几何体

2023-12-03

我正在尝试学习如何在 SceneKit 中创建自定义几何体。但是,我尝试制作一个三角形,但它没有显示任何内容。我不知道如何调试这个。有没有办法判断三角形是否有效?我只是不知道从哪里开始。

作为参考,相关的游乐场代码如下。请注意,它是针对 Swift 4 编写的,但 Swift 3 和 Swift 4 之间的变化非常小,因此在 Swift 3 中编译它是微不足道的。

import UIKit
import SceneKit

let points = [
    SCNVector3Make(0, 0, 0),
    SCNVector3Make(0, 10, 0),
    SCNVector3Make(10, 0, 0),
]
let indices = [
    0,2,1,
]

let vertexSource = SCNGeometrySource(vertices: points)
let element = SCNGeometryElement(indices: indices, primitiveType: .triangles)
let geo = SCNGeometry(sources: [vertexSource], elements: [element])

When creating custom SCNGeometryElements the type of the indices needs to be Int161. I don't think this documented anywhere. But when you change the declaration of the indices too

let indices: [Int16] = [
    0, 2, 1
]

应该会出现三角形。


Edit

1:正如 @mnuages 所指出的,SceneKit 仅支持 32 位整数作为索引。所以你可以使用Int8, Int16 and Int32.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Swift 调试 SceneKit 中的自定义几何体 的相关文章

随机推荐