Я пытаюсь создать собственную 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
}
}
К сожалению, он не подходит для вогнутого многоугольника:
результаты