I want to be able to create a custom camera node in SceneKit and view my scene from it (instead of the default camera).
However, I've been encountering a very strange issue with SceneKit:
SCNCamera
, nothing shows up in my scene.SCNCamera
, the objects in my scene render correctly.This is the code I am using (very simple code; from a tutorial):
import UIKit
import SceneKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sceneView = SCNView()
sceneView.frame = self.view.frame
self.view.addSubview(sceneView)
let scene = SCNScene()
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
let cameraNode = SCNNode()
// If the below line of code is commented out (so no SCNCamera is added), everything shows up
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
let sphere = SCNSphere(radius: 5)
sphere.firstMaterial?.diffuse.contents = UIColor.red
let sphereNode = SCNNode(geometry: sphere)
cameraNode.addChildNode(sphereNode)
sceneView.backgroundColor = UIColor.green
sceneView.scene = scene
}
}
This seems pretty straightforward, yet I can't find any reason why this is happening on SO, etc.
Strangely, I also observe that if I try to access the camera node via sceneView.pointOfView
, I get nil
, even though sceneView.allowsCameraControl
is set to true
Any help is appreciated!
The sphere is a child node of the camera, without any offset (its position
is (0, 0, 0)
) and so the camera is inside the sphere. And if the sphere's material isn't doubleSided
then you won't see anything.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.