SceneKit 如何绘制显示网格状表面而不是平滑的球体?

zum*_*zum 5 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)
Run Code Online (Sandbox Code Playgroud)

这将绘制具有光滑表面的球体(见图)。我会在此处输入图片说明

我想要完成的是让球体不像照片中那样呈现“平滑”,但我希望能够让它显示骨架......所以也许可以控制它用来绘制表面的三角形数量球体但三角形需要是空的,所以我只会看到三角形的边......

有什么建议吗?

所以这是 zI 试图使球体看起来像的图像: 在此处输入图片说明

Ef *_*Dot 4

  • 你的愿望#1:“不光滑”的球体
  • 你的愿望#2:线框

将其粘贴到 Xcode Playground 中:

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")
Run Code Online (Sandbox Code Playgroud)