我正在尝试学习如何在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])
创建customSCNGeometryElement
时,索引的类型必须为Int16
1。我认为这在任何地方都没有记录。但是当您也更改索引的声明时
let indices: [Int16] = [
0, 2, 1
]
三角形应该出现。
编辑
1:正如@mnuages指出的那样,SceneKit仅支持32位整数作为索引。所以,你可以使用Int8
,Int16
和Int32
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句