Reputation: 4590
I am just starting off with SceneKit and I have some code that renders a cube onto the screen. It shows up find but as soon as I add a camera node the cube no longer appears on screen. Given that I'd set the position of the cube's Node to 0,0,0 and the same for the camera, I cannot figure out what is wrong. I attempted to set the pointOfView
property of the SCNView
to the camera node but this did not work.
Here is the code for clarification:
func setup() {
box = SCNBox(width: 30, height: 30, length: 30, chamferRadius: 5)
shapeNode.geometry = box
shapeNode.position = SCNVector3(x:0, y:0, z:0)
mainNode.addChildNode(shapeNode)
scene.rootNode.addChildNode(mainNode)
sceneKitView = SCNView(frame:bounds, options:nil)
sceneKitView.autoenablesDefaultLighting = true
sceneKitView.allowsCameraControl = true
sceneKitView.scene = scene
sceneKitView.backgroundColor = UIColor.blackColor()
addSubview(sceneKitView)
// cameraNode.camera = SCNCamera()
// cameraNode.position = SCNVector3Make(0, 0, 10)
// scene.rootNode.addChildNode(cameraNode)
// sceneKitView.pointOfView = cameraNode
}
Upvotes: 0
Views: 562
Reputation: 13462
if both your camera and cube are at (0, 0, 0)
then the camera is inside the cube and can't see it. You can make your cube's material doubleSided
so that back-facing triangles are visible, but you probably just want to move your camera at something like (0, 0, 100)
(a camera's direction of view is along the negative Z axis, and your box has a size of 30).
Upvotes: 3