如何使用Swift在SceneKit中调试自定义几何 [英] How to debug custom geometry in SceneKit with Swift
问题描述
我正在尝试学习如何在SceneKit中创建自定义几何.但是,我尝试制作一个三角形,但没有显示任何内容.我不知道如何调试它.有没有办法找出三角形是否有效?我只是不知道从哪里开始.
I'm trying to learn how to create custom geometry in SceneKit. However, I've tried to make a triangle and it's not showing anything. I'm at a loss as to how to debug this. Is there a way to figure out if the triangle is valid? I just don't know where to start.
作为参考,有问题的游乐场代码如下.请注意,它是针对Swift 4编写的,但是Swift 3和Swift 4之间的更改很小,以至于无法在Swift 3中进行编译.
For reference, the playground code in question is below. Note that it is written against Swift 4, but the changes between Swift 3 and Swift 4 are so minor that getting it to compile in Swift 3 is trivial.
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])
推荐答案
创建自定义SCNGeometryElement
时,索引的类型必须为Int16
1 .我认为这在任何地方都没有记录.但是当您也更改索引的声明时
When creating custom SCNGeometryElement
s the type of the indices needs to be Int16
1. I don't think this documented anywhere. But when you change the declaration of the indices too
let indices: [Int16] = [
0, 2, 1
]
应该出现三角形.
修改
1:正如@mnuages指出的那样,SceneKit仅支持32位整数作为索引.因此,您可以使用Int8
,Int16
和Int32
.
1: As @mnuages has pointed out, SceneKit supports only 32bit Integers as indices. So you can use Int8
, Int16
and Int32
.
这篇关于如何使用Swift在SceneKit中调试自定义几何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!