Skip to content

Instantly share code, notes, and snippets.

@DagAgren
Last active January 19, 2018 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DagAgren/5e228b6027325d8515811bb880d7601e to your computer and use it in GitHub Desktop.
Save DagAgren/5e228b6027325d8515811bb880d7601e to your computer and use it in GitHub Desktop.
import SceneKit
import QuartzCore
@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
var c: NSWindowController!
func applicationDidFinishLaunching(_ a: Notification) {
let w = NSWindow.init(contentRect: NSMakeRect(100, 100, 400, 400), styleMask: [.closable, .titled], backing: .buffered, defer: false)
c = NSWindowController(window: w)
c.showWindow(self)
w.makeKeyAndOrderFront(nil)
let scene = SCNScene()
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = .omni
lightNode.light!.color = NSColor.purple
lightNode.light!.intensity = 4000
lightNode.position = SCNVector3(x: 0, y: 3, z: 10)
scene.rootNode.addChildNode(lightNode)
let boxGeometry = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 1.0)
let boxNode = SCNNode(geometry: boxGeometry)
scene.rootNode.addChildNode(boxNode)
boxNode.runAction(SCNAction.repeatForever(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 1)))
let scnView = SCNView(frame: w.contentView!.bounds)
scnView.scene = scene
scnView.allowsCameraControl = true
scnView.showsStatistics = true
scnView.backgroundColor = NSColor.black
w.contentView?.addSubview(scnView)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment