3

I've created a polygon using SCNGeometry and I'm trying to add a curve to my shape, My code is:

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)

The outcome looks like this: geometry

Desired shape, adding 0.4 curve factor is: enter image description here

Another question is how do I properly calculate normals for the surface given an array of vertices.

****** Update ******

When assigning geometry.subdivisionLevel = 10 I get a smoother round shape enter image description here

But I still I can't figure out a way to add curve factor to the polygon shape.

ItayAmza
  • 819
  • 9
  • 21
  • What do you mean by curve factor? Is it the parameter of a well known algorithm? – mnuages Jul 06 '17 at 16:20
  • I'm talking about the [bezier curve](https://en.wikipedia.org/wiki/Bézier_curve) or something equivalent to [this](https://www.listech.com/liscad/help/see/topics/Glossary/SplineCurveFactor.htm), to determinate the curve for each line between the vertices. – ItayAmza Jul 06 '17 at 17:03
  • What you did? @ItayAmza – khunshan Jan 25 '18 at 12:21
  • Didn't find better solution than subdivisionLevel – ItayAmza Jan 25 '18 at 12:23

0 Answers0