【问题标题】:How to generating a concave or convex polygon plane in SceneKit from SCNVector3如何从 SCNVector3 在 SceneKit 中生成凹面或凸面多边形平面
【发布时间】:2020-04-28 14:40:57
【问题描述】:

我正在尝试以具有自定义形状的平面的形式创建自定义 SCNGeometry,它可以放置在 ARKit 会话中。我在以下方法中使用选项 SCNGeometryPrimitiveTypePolygon 似乎工作正常:

extension SCNGeometry {

    class func polygonfrom(vectices: [SCNVector3]) -> SCNGeometry {
        let indices: [Int32] = getIndices(count: vectices.count)
        let indexData = Data(bytes: indices, count: indices.count * MemoryLayout<Int32>.size)
        let source = SCNGeometrySource(vertices: vectices)
        let element = SCNGeometryElement(data: indexData, primitiveType: .polygon, primitiveCount: 1, bytesPerIndex: MemoryLayout<Int32>.size)
        return SCNGeometry(sources: [source], elements: [element])
    }

    class private func getIndices(count: Int) -> [Int32] {
        var indices: [Int32] = []
        indices.append(Int32(count))
        for i in 0..<count{
            indices.append(Int32(i))
        }
        return indices
    }
}

不幸的是,它不适合凹多边形:

results

【问题讨论】:

    标签: ios swift scenekit arkit


    【解决方案1】:

    SCNShape 类代表您创建合适的三角测量。

    【讨论】:

      猜你喜欢
      • 2017-01-07
      • 2022-01-17
      • 2019-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      • 2010-10-03
      相关资源
      最近更新 更多