gpt4 book ai didi

ios - 创建自定义 SCNGeometry 多边形

转载 作者:行者123 更新时间:2023-11-28 13:46:36 24 4
gpt4 key购买 nike

我正在尝试创建自定义 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(代码=1,子代码=0x106362e20)”。似乎这种情况下的功能不是快速实现的,而是针对 Objective-C 的?我有什么办法可以利用它吗?

我还尝试对 primitiveType-value 使用其他选项,并且使用这些值没有崩溃,进一步加强了我的信念,即 .polygon 案例有问题。

最佳答案

当使用 polygon 时,你必须使用

  init(data: Data?, primitiveType: SCNGeometryPrimitiveType, primitiveCount: Int, bytesPerIndex: Int)

初始化 SCNGeometryElement。有关详细信息,请参阅苹果文档。

关于ios - 创建自定义 SCNGeometry 多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55325825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com