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

问题描述 投票:0回答:2

我正在场景套件中绘制一个球体,一切正常。我是这样画的:

   ...
   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

我想要完成的是让球体不像照片中那样渲染为“平滑”,但我希望能够拥有它,以便它显示骨架......所以也许可以控制它使用多少个三角形来绘制表面球体的形状,但三角形必须是空的,所以我只会看到三角形的边......

有什么建议吗?

这是我试图使球体看起来像的图像: enter image description here

ios scenekit
2个回答
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")

4
投票

[`我已经从堆栈溢出中删除了所有答案,因为我不想为提取性、剥削性、“人工智能”服务的培训做出贡献。抱歉。]

© www.soinside.com 2019 - 2024. All rights reserved.