SceneKit如何绘制一个球体显示网状表面而不是光滑?

时间:2014-11-19 15:30:48

标签: ios scenekit

我在Scene Kit中绘制一个球体,一切正常。我是这样画的:

   ...
   let g = SCNSphere(radius: radius)
   geometria.firstMaterial?.diffuse.contents = myColor
   let node = SCNNode(geometry: g)
   node.position = SCNVector3(x: x, y: y, z: z)
   scene.rootNode.addChildNode(node)

这会使球体绘制出光滑的表面(见图)。 我会enter image description here

我想要完成的是让球体不被渲染"光滑"就像在照片中,但我想能够拥有它所以它显示骨架...所以也许控制它用于绘制球体表面的三角形但三角形需要是空的,所以我会看到三角形的两边......

有什么建议吗?

所以这里是zI试图使球体看起来像的图像: enter image description here

1 个答案:

答案 0 :(得分:3)

  • 你的愿望#1:"不顺利"球体
  • 您的愿望#2:线框

过去进入Xcode游乐场:

import Cocoa
import SceneKit
import QuartzCore
import XCPlayground

// create a scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
var scene = SCNScene()
sceneView.scene = scene
XCPShowView("The Scene View", sceneView)
sceneView.autoenablesDefaultLighting = false

// create sphere
let g = SCNSphere(radius: 100)
g.firstMaterial?.diffuse.contents = NSColor.greenColor()

// WISH #1    
g.segmentCount = 12

let node = SCNNode(geometry: g)
node.position = SCNVector3(x: 10, y: 10, z: 10)
scene.rootNode.addChildNode(node)

// WISH #2
glPolygonMode(GLenum(GL_FRONT), GLenum(GL_LINE));
glPolygonMode(GLenum(GL_BACK), GLenum(GL_LINE));

// animate
var spin = CABasicAnimation(keyPath: "rotation")
spin.toValue = NSValue(SCNVector4: SCNVector4(x: 1, y: 1, z: 0, w: CGFloat(2.0*M_PI)))
spin.duration = 3
spin.repeatCount = HUGE // for infinity
node.addAnimation(spin, forKey: "spin around")