Default Camera is not animating.

Hello. Sorry for my poor english.


I´m a fully noob with 3D and Scenekit. I´m using Scenekit for a simple task, show a interactive 3D model and let to the user control the camera. I´m using the property allowsCameraControl.


The problem I want to animate the default camera to some point of interest of 3D model (for example with a button). I´m using this:


[SCNTransaction begin];

[SCNTransaction setAnimationDuration:0.5];

[SCNTransaction setCompletionBlock:^{

[SCNTransaction begin];

[SCNTransaction setAnimationDuration:0.5];

((SCNView *)self.view).pointOfView.position = SCNVector3Make(-2.978351,0.515628,8.975238);

((SCNView *)self.view).pointOfView.rotation = SCNVector4Make(-0.440378,0.106008,0.891532,2.689772);

[SCNTransaction commit];

}];


The transaction is working only if the user moved the camera with gestures before, the name for the camera is "kSCNFreeViewCameraNameCamera" in this case. If the user did not move the camera with gestures, the camera move too but no animation or transaction, the name for the camera is "default camera" in this case.


Do you know what is wrong?


Thanks.

Accepted Reply

OK then. I might not have tried to get the camera node this way.


I overlooked your code; the completion block is called when the transaction is finished, therefore, you must not put your animation code in it!


Your code should look like this instead:

[SCNTransaction begin];
[SCNTransaction setAnimationDuration:0.5];
((SCNView *)self.view).pointOfView.position = SCNVector3Make(-2.978351,0.515628,8.975238);
((SCNView *)self.view).pointOfView.rotation = SCNVector4Make(-0.440378,0.106008,0.891532,2.689772); 
[SCNTransaction commit];

Replies

Hello,


The default camera is only a handy way to get a scene visible and manipulable with a single line of code.

Unfortunately, the default camera node is not accessible (I don't even know if this node exists in the Scene at all).


I'm afraid you'll have to create your own camera node and implement your own event handling (NS/UIResponder methods of NS/UIView) to move this node. Apple does not provide the source code for the default implementation, either.

Hello.

Thanks for the response, but the default camera is accesible with the next line:


((SCNView *)self.view).pointOfView.camera


I can update the position, rotation, and z deep valors. The only problem I have is the animation is not working into SCNTransaction, but I can move the position of camera.

OK then. I might not have tried to get the camera node this way.


I overlooked your code; the completion block is called when the transaction is finished, therefore, you must not put your animation code in it!


Your code should look like this instead:

[SCNTransaction begin];
[SCNTransaction setAnimationDuration:0.5];
((SCNView *)self.view).pointOfView.position = SCNVector3Make(-2.978351,0.515628,8.975238);
((SCNView *)self.view).pointOfView.rotation = SCNVector4Make(-0.440378,0.106008,0.891532,2.689772); 
[SCNTransaction commit];