将曲线添加到SCNGeometry,并计算法线

时间:2017-07-05 13:18:09

标签: ios swift scenekit scnnode

I've created a polygon using SCNGeometry我试图为我的形状添加曲线,我的代码是:

let vertices: [SCNVector3] = [
SCNVector3Make(-0.1304485, 0.551937, 0.8236193),
SCNVector3Make(0.01393811, 0.601815, 0.7985139),
SCNVector3Make(0.2971005, 0.5591929, 0.7739732),
SCNVector3Make(0.4516893, 0.5150381, 0.7285002),
SCNVector3Make(0.4629132, 0.4383712, 0.7704169),
SCNVector3Make(0.1333823, 0.5224985, 0.8421428),
SCNVector3Make(-0.1684743, 0.4694716, 0.8667254)]

let indices: [Int32] = [Int32(vertices.count), 0, 1, 2, 3, 4, 5, 6]
let vertexSource = SCNGeometrySource(vertices: vertices)
let indexData = Data(bytes: indices, count: indices.count * MemoryLayout<Int32>.size)
let element = SCNGeometryElement(data: indexData, primitiveType: .polygon, primitiveCount: 1, bytesPerIndex: MemoryLayout<Int32>.size)
let geometry = SCNGeometry(sources: [vertexSource], elements: [element])

let material = SCNMaterial()
material.isDoubleSided = true
geometry.materials = [material]

let node = SCNNode(geometry: geometry)

结果如下: geometry

所需形状,添加0.4曲线因子为: enter image description here

另一个问题是如何在给定顶点数组的情况下正确计算曲面的法线。

****** 更新 ******

分配geometry.subdivisionLevel = 10时,我会得到更平滑的圆形 enter image description here

但我仍然无法找到将曲线因子添加到多边形形状的方法。

0 个答案:

没有答案