Last active
November 23, 2021 09:21
-
-
Save sorin-ref/ba58e4bd2e2801264b51ec8750d31dbb to your computer and use it in GitHub Desktop.
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 SceneKit | |
| import PlaygroundSupport | |
| var sceneView = SCNView() | |
| PlaygroundPage.current.liveView = sceneView | |
| var scene = SCNScene() | |
| sceneView.scene = scene | |
| var object = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 1) | |
| var objectMaterial = object.firstMaterial! | |
| objectMaterial.diffuse.contents = UIColor.systemPurple | |
| objectMaterial.lightingModel = .physicallyBased | |
| var objectNode = SCNNode(geometry: object) | |
| objectNode.rotation = SCNVector4(x: 0.5, y: 1, z: 0, w: 0) | |
| scene.rootNode.addChildNode(objectNode) | |
| var background = SCNBox(width: 40, height: 40, length: 1, chamferRadius: 0) | |
| var backgroundMaterial = background.firstMaterial! | |
| backgroundMaterial.diffuse.contents = UIColor.systemYellow | |
| backgroundMaterial.lightingModel = .physicallyBased | |
| var backgroundNode = SCNNode(geometry: background) | |
| backgroundNode.position = SCNVector3(x: 0, y: 0, z: -10) | |
| scene.rootNode.addChildNode(backgroundNode) | |
| var spin = CABasicAnimation(keyPath: "rotation.w") | |
| spin.toValue = 2 * CGFloat.pi | |
| spin.duration = 5 | |
| spin.repeatCount = .greatestFiniteMagnitude | |
| objectNode.addAnimation(spin, forKey: "spin") | |
| var light = SCNLight() | |
| light.type = .directional | |
| var lightNode = SCNNode() | |
| lightNode.light = light | |
| scene.rootNode.addChildNode(lightNode) | |
| var camera = SCNCamera() | |
| var cameraNode = SCNNode() | |
| cameraNode.camera = camera | |
| cameraNode.position = SCNVector3(x: 0, y: 0, z: 20) | |
| scene.rootNode.addChildNode(cameraNode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment