出于学习目的,我从网上下载了一个.dae文件。导入到SceneKit后,我无法将其设置为屏幕中心。
我尝试了许多职位,似乎没有任何影响。
任何人都可以帮助我吗?非常感谢你!
这是我的主要代码,整个项目可以在github
中找到class GameViewController: UIViewController {
// MARK: properties
var rotate3D: Rotate3D = Rotate3D(rx: 0, ry: 0, rz: 0)
var geometryNode: SCNNode!
override func viewDidLoad() {
super.viewDidLoad()
// create a new scene
let scene = SCNScene(named: "art.scnassets/Nico_Robin.dae")!
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 300, z: 500)
// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.light!.color = UIColor.whiteColor()
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.whiteColor()
scene.rootNode.addChildNode(ambientLightNode)
// retrieve the ship node
geometryNode = scene.rootNode.childNodeWithName("Nico_Robin", recursively: true)!
print("girl position:", geometryNode.position)
// geometryNode.position = SCNVector3(x:0, y:0, z: 0)
// geometryNode.scale = SCNVector3(0.1, 0.1, 0.1)
// animate the 3d object
// geometryNode.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(0, y: 2, z: 0, duration: 1)))
// retrieve the SCNView
let scnView = self.view as! SCNView
// set the scene to the view
scnView.scene = scene
// allows the user to manipulate the camera
// scnView.allowsCameraControl = true
// show statistics such as fps and timing information
scnView.showsStatistics = true
// configure the view
scnView.backgroundColor = UIColor.whiteColor()
// add a tap gesture recognizer
let panGesture = UIPanGestureRecognizer(target: self, action: "handlePan:")
scnView.addGestureRecognizer(panGesture)
// let tapGesture = UITapGestureRecognizer(target: self, action: "handleTap:")
// scnView.addGestureRecognizer(tapGesture)
}
=====================
感谢上帝我弄明白了,在设置cameraNode.camera?.automaticallyAdjustsZRange = true;
后,我可以看到对象和相机position
按预期生效!