【发布时间】:2020-03-12 22:27:02
【问题描述】:
import UIKit
import SceneKit
class Scene: SCNScene {
var cameraPosition = SCNVector3Make(0, 0, 10)
var lightPosition = SCNVector3Make(0, 0, 0)
var ship = SCNNode()
func setup() {
createCameraNode()
createShipNode()
createAmbientLight()
createLight()
}
func createCameraNode () {
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = cameraPosition
self.rootNode.addChildNode(cameraNode)
}
func createShipNode() {
ship = self.rootNode.childNodeWithName("ship", recursively: true)!
}
func createAmbientLight() {
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
self.rootNode.addChildNode(ambientLightNode)
}
func createLight() {
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = lightPosition
self.rootNode.addChildNode(lightNode)
}
}
这就是我的代码的样子。我有以下问题。当我在场景中添加相机节点时,我的对象消失了。当我删除函数 createCameraNode 时,一切正常,我的飞船出现在屏幕上。我试图用 z 轴上的负值和正值更改相机位置,但仍然没有结果。谁能解释一下为什么?
【问题讨论】: