我想繪製SceneKit貝塞爾曲線,認爲這會工作:SceneKit繪製曲線
func drawCurvedLine() {
let scene = SCNScene()
let scnView = self.view as! SCNView
scnView.scene = scene
scnView.allowsCameraControl = true
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: -20, y: -20))
path.addCurveToPoint(CGPoint(x: 20, y: 20),
controlPoint1: CGPoint(x: 5, y: 5),
controlPoint2: CGPoint(x: 15, y: 15))
path.closePath()
path.flatness = 0.3
var scnShape:SCNShape = SCNShape(path: path, extrusionDepth: 2)
scnShape.firstMaterial?.diffuse.contents = UIColor.purpleColor()
let shapeNode = SCNNode(geometry: scnShape)
scene.rootNode.addChildNode(shapeNode)
}
但是我的結果是這樣的截圖:
有誰知道爲什麼curveTo控制點被忽略或如何切換它們?或者在SceneKit中繪製曲線的任何其他方法?
編輯更新路徑座標:
path.moveToPoint(CGPoint(X:-20,Y:-20)) path.addCurveToPoint(CGPoint(X:20,Y:20) , controlPoint1:CGPoint(X:10,Y:0), controlPoint2:CGPoint(X:10,Y:0))
我可以得到這樣的:
但是我想我正在尋找不填充形狀。理想情況下,我想在這裏實現一條彎曲的管狀線。 (想象一下電力電纜或其他一些......)。我想我會喜歡有相當於SCNLine或SCNTube「在貝塞爾路徑上渲染」
好吧,爲了使它更像線條形狀,請嘗試沿着任意軸平移所有點。 (CGPoint(x:20,y:-20)) path.addCurveToPoint(CGPoint(x:20,y:20),controlPoint1:CGPoint(x:10,y:0),控制點2:CGPoint(x:10,y:0))'(原始點) Then: 'path.moveToPoint(CGPoint(x:20,y:-17))' 'path.addCurveToPoint(CGPoint(x: (x:10,y:0),controlPoint2:CGPoint(x:10,y:3))' (對所有y值加3)。 研究倒角SCNShape並使用SCNLightTypeOmni或SCNLightTypeDirectional類型的SCNLight。 – jperl