al404 Posted July 6, 2016 Share Posted July 6, 2016 i got stuck with my project, the file is pretty complex now i need to access camera control outside createScene function all my code is inside createScene, camera is created inside that function, i also have a function that i found in some post function ArcAnimation(camera, toAlpha, toBeta, toRadius, position, animSpeed) this function moves the camera i just moved this function outside createScene, because i need to trigger the first camera animation from an HTML element, but camera is not defined outside createScene i try to access camere with scene.camera since i initialize the scene with var scene = createScene(); but doesn't work Quote Link to comment Share on other sites More sharing options...
NasimiAsl Posted July 6, 2016 Share Posted July 6, 2016 you most define camera outside the createScene or use this window.eval('var camera;'); // This creates and positions a free camera (non-mesh) camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene); al404 1 Quote Link to comment Share on other sites More sharing options...
al404 Posted July 6, 2016 Author Share Posted July 6, 2016 if i bring camera out i guess i need to initialize scene outside, would this be ok? Quote Link to comment Share on other sites More sharing options...
adam Posted July 6, 2016 Share Posted July 6, 2016 Did you try scene.activeCamera ? al404 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted July 6, 2016 Share Posted July 6, 2016 As adam mentioned scene.activeCamera should work. but you can also do this: var camera; //createScene function //... camera = new BABYLON.camera... //... //end of createScene //do whatever you want to do moveCamera(); function moveCamera(){ if(!camera) return; camera.position.x += 10; camera.position.z += 10; } al404 1 Quote Link to comment Share on other sites More sharing options...
al404 Posted July 6, 2016 Author Share Posted July 6, 2016 i go with scene.activeCamera it works, i did try scene.camera and did not work probi i could also return an array with scene and camera from createScene, did not think about that before thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.