Created
February 23, 2015 21:14
-
-
Save mpampols/b756d81eca29394bd393 to your computer and use it in GitHub Desktop.
A playground experiment using SceneKit in iOS 8 SDK that shows a plane, a torus and a light attached to it casting shadows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SceneKit | |
import QuartzCore | |
import XCPlayground | |
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 350, height: 450)) | |
var scene = SCNScene() | |
sceneView.scene = scene | |
XCPShowView("View", sceneView) | |
sceneView.allowsCameraControl = true | |
var camera1 = SCNCamera() | |
var camera1Node = SCNNode() | |
camera1Node.camera = camera1 | |
camera1Node.position = SCNVector3(x: 0, y: 0, z: 5) | |
scene.rootNode.addChildNode(camera1Node) | |
var light1 = SCNLight() | |
light1.type = SCNLightTypeSpot | |
light1.castsShadow = true | |
light1.color = UIColor.whiteColor() | |
var light1Node = SCNNode() | |
light1Node.light = light1 | |
light1Node.position = SCNVector3(x: 4, y: 5, z: 3) | |
scene.rootNode.addChildNode(light1Node) | |
var torus = SCNTorus(ringRadius: 1, pipeRadius: 0.25) | |
var torusNode = SCNNode(geometry: torus) | |
let lookAt = SCNLookAtConstraint(target: torusNode) | |
light1Node.constraints = [lookAt] | |
scene.rootNode.addChildNode(torusNode) | |
torus.firstMaterial?.diffuse.contents = UIColor.whiteColor() | |
torus.firstMaterial?.specular.contents = UIColor.whiteColor() | |
var plane = SCNPlane(width: 5.0, height: 5.0) | |
var planeNode = SCNNode(geometry: plane) | |
scene.rootNode.addChildNode(planeNode) | |
plane.firstMaterial?.diffuse.contents = UIColor.whiteColor() | |
plane.firstMaterial?.specular.contents = UIColor.whiteColor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version
import UIKit
import SceneKit
import QuartzCore
import XCPlayground
import PlaygroundSupport
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 350, height: 450))
var scene = SCNScene()
sceneView.scene = scene
PlaygroundPage.current.liveView = sceneView
//XCPShowView(identifier: "View", view: sceneView)
sceneView.allowsCameraControl = true
var camera1 = SCNCamera()
var camera1Node = SCNNode()
camera1Node.camera = camera1
camera1Node.position = SCNVector3(x: 0, y: 0, z: 5)
scene.rootNode.addChildNode(camera1Node)
var light1 = SCNLight()
light1.type = SCNLight.LightType.spot
light1.castsShadow = true
light1.color = UIColor.white
var light1Node = SCNNode()
light1Node.light = light1
light1Node.position = SCNVector3(x: 4, y: 5, z: 3)
scene.rootNode.addChildNode(light1Node)
var torus = SCNTorus(ringRadius: 1, pipeRadius: 0.25)
var torusNode = SCNNode(geometry: torus)
let lookAt = SCNLookAtConstraint(target: torusNode)
light1Node.constraints = [lookAt]
scene.rootNode.addChildNode(torusNode)
torus.firstMaterial?.diffuse.contents = UIColor.white
torus.firstMaterial?.specular.contents = UIColor.white
var plane = SCNPlane(width: 5.0, height: 5.0)
var planeNode = SCNNode(geometry: plane)
scene.rootNode.addChildNode(planeNode)
plane.firstMaterial?.diffuse.contents = UIColor.white
plane.firstMaterial?.specular.contents = UIColor.white