ancientholiday Posted September 19, 2015 Share Posted September 19, 2015 Hello, In Babylon JS, only one camera is active at a time, howver you can construct multiple cameras in a scene. How can you allow the users to swtich cameras on a button click. For example, in this Three Js scene, you can hit 1 or 2 button to switch cameras, making an active camera false or true.https://stemkoski.github.io/Three.js/Multiple-Cameras.html The only example i have seen in Babylon JS is the Train example, however there is no explanation of how to switch the cameas on button click. Thanks,Moses Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 19, 2015 Share Posted September 19, 2015 Hello, scene.activeCamera = myCamera; 8Observer8 1 Quote Link to comment Share on other sites More sharing options...
ancientholiday Posted September 19, 2015 Author Share Posted September 19, 2015 Hello, scene.activeCamera = myCamera;whenever i attach click event to myCamera, it does not change the camera. Quote Link to comment Share on other sites More sharing options...
ancientholiday Posted September 19, 2015 Author Share Posted September 19, 2015 Hello, scene.activeCamera = myCamera;i tried to add button 1 and button 2 attach to different cameras. It does not work var b1 = document.getElementById('b1'), b2 = document.getElementById('b2'); //var currentCAM= camera; console.log(currentCAM); function show() { alert(currentCAM); } b1.onclick = function() { var currentCAM = camera2; show(); return currentCAM; console.log(currentCAM); }; b2.onclick = function() { currentCAM = camera; show(); return speed; console.log(currentCAM); }; console.log(currentCAM); Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 19, 2015 Share Posted September 19, 2015 Here is an example: http://www.babylonjs-playground.com/#2FY4XTClic in the window to switch camera. Quote Link to comment Share on other sites More sharing options...
ancientholiday Posted September 20, 2015 Author Share Posted September 20, 2015 Here is an example: http://www.babylonjs-playground.com/#2FY4XTClic in the window to switch camera.Ok. I get it. As a true / false boolean situation, I can change the cameras. I can also apply this to buttons by attaching a button to the condition: switchCam = !switchCam; Thanks! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted September 20, 2015 Share Posted September 20, 2015 Hi again, AH! http://urbanproductions.com/wingy/babylon/cameras/10cam/index.html (view source). That's how I did it, once (BJS v1.14). I'm not a very good coder, but... maybe there's something in there you can use. I created and styled my buttons dynamically... with JS. *shrug* I did a playground version of it, too, but it quit working with one of the BJS versions and I haven't fixed it yet, sorry. Start simple... get some buttons, make sure they can run functions with their onclicks. Maybe each function has a simple alert. Flesh-out the functions (make them switch cameras) AFTER you know that your buttons are causing functions to run. This way, you have separated the HTML/DOM activity (onclicks)... from the BJS activity (camera stuff). Party on. Quote Link to comment Share on other sites More sharing options...
ancientholiday Posted September 21, 2015 Author Share Posted September 21, 2015 Hi again, AH! http://urbanproductions.com/wingy/babylon/cameras/10cam/index.html (view source). That's how I did it, once (BJS v1.14). I'm not a very good coder, but... maybe there's something in there you can use. I created and styled my buttons dynamically... with JS. *shrug* I did a playground version of it, too, but it quit working with one of the BJS versions and I haven't fixed it yet, sorry. Start simple... get some buttons, make sure they can run functions with their onclicks. Maybe each function has a simple alert. Flesh-out the functions (make them switch cameras) AFTER you know that your buttons are causing functions to run. This way, you have separated the HTML/DOM activity (onclicks)... from the BJS activity (camera stuff). Party on.Your code has an interesting strategy. Instead of switchng camera names, you actually create a new camera on button click that has the same camea name. it seems there must be something that prevents changing the active camera names after run-time rendering has started. DesignVibe 1 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.