SceneKit how to draw a sphere showing a mesh surface instead of a smooth one?

I draw a sphere in the Scene Kit and everything works fine. I draw it like this:

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

This paints the sphere with a smooth surface (see image). I'denter image description here

What I'm trying to accomplish is to prevent the sphere from being “smooth” like in the photo, but I want to have it so that it displays the skeleton ... so maybe you can control how many triangles it uses to draw the surface spheres, but the triangles should be empty, so I just see the sides of the triangles ...

Any suggestion?

So, here is an image of what I'm trying to make a sphere: enter image description here

+4
source share
1 answer
  • Your desire number 1: "nonsmooth" sphere
  • №2: wireframe

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")
+2

All Articles