【发布时间】:2019-08-14 23:41:55
【问题描述】:
我正在尝试创建一个自定义的SCNPlane 类,它可以具有任何多边形的形式,因为常规的 SCNPlane 只能是一个矩形。
我试图通过扩展SCNGeometry 来实现这一点。下面是我使用的代码:
extension SCNGeometry {
static func polygonPlane(vertices: [SCNVector3]) -> SCNGeometry {
let src = SCNGeometrySource(vertices: vertices)
var indices: [UInt32] = []
var index: UInt32 = 0
for _ in vertices {
indices.append(index)
index += 1
}
let inds = SCNGeometryElement(indices: indices, primitiveType: .polygon)
return SCNGeometry(sources: [src], elements: [inds])
}
}
如您所见,该方法将顶点数组作为输入,我希望将这些顶点连接起来,以便使用提供的顶点创建具有指定几何形状的平面。
在上面的代码中使用SCNGeometryPrimitiveType.polygon 时,我收到一个奇怪的错误:“线程 1:EXC_BREAKPOINT (code=1, subcode=0x106362e20)”。似乎这种情况下的功能没有在 swift 中实现,但它是针对 Objective-C 的?我有什么办法可以利用它吗?
我还尝试使用原始类型值的其他选项,使用这些值没有崩溃,进一步加强了我的信念,即 .polygon 情况有问题。
【问题讨论】:
-
通过关注this post解决了问题
标签: ios objective-c swift xcode arkit