【问题标题】:Creating a custom SCNGeometry polygon创建自定义 SCNGeometry 多边形
【发布时间】: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 情况有问题。

【问题讨论】:

标签: ios objective-c swift xcode arkit


【解决方案1】:

当使用多边形时,你必须使用

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

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

【讨论】:

    猜你喜欢
    • 2019-11-08
    • 1970-01-01
    • 2017-12-08
    • 2019-03-03
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 2017-08-27
    • 2020-12-14
    相关资源
    最近更新 更多