Echnaton Posted October 26, 2017 Share Posted October 26, 2017 Hello I try to save processing power by only render the scene, when something has changed. Now i noticed that the key strokes that change the camera position are only processed when I call scene.render(). Is there a way to update the camera position without scene.render()? camera._updatePosition() does only work for gravity. Quote Link to comment Share on other sites More sharing options...
adam Posted October 26, 2017 Share Posted October 26, 2017 14 minutes ago, Echnaton said: I try to save processing power by only render the scene, when something has changed. When you update the camera position, something has changed. Therefore you need to render the scene again. Quote Link to comment Share on other sites More sharing options...
Echnaton Posted October 26, 2017 Author Share Posted October 26, 2017 thank you for your reply. To detect that something has changed I would like to compare the current camera position with the one when I rendered last and then decide to render again. But the camera position gets only updated during scene rendering. So is there a way to detect, that the camera moved without rendering? Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 26, 2017 Share Posted October 26, 2017 Hi, there are properties that change when a user input is being provided. the position, as you already found, is only updated during the render cycle. For example, the FreeCamera has the cameraRotation and cameraDirection properties that are being changed by the inputs. They are both vectors, so you will need to check their length() in order to see if they are not 0,0,0 vectors ArcRotate has inertialAlphaOffset, inertialBetaOffset, inertialRadiusOffset, inertialPanningX and inertialPanningY . Those are all numbers. if they are all not 0, the camera will move. Those might help you, as they are updated async using js events and not during the rendering. Quote Link to comment Share on other sites More sharing options...
adam Posted October 26, 2017 Share Posted October 26, 2017 27 minutes ago, Echnaton said: thank you for your reply. To detect that something has changed I would like to compare the current camera position with the one when I rendered last and then decide to render again. But the camera position gets only updated during scene rendering. So is there a way to detect, that the camera moved without rendering? You should be able to use the observables in the Camera class: https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.camera.ts#L131 Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 26, 2017 Share Posted October 26, 2017 Hi @adam, I believe the observers are being executed only during the render loop (when the view matrix is updated). So without rendering they won't execute. but this needs to be tested. Quote Link to comment Share on other sites More sharing options...
adam Posted October 26, 2017 Share Posted October 26, 2017 2 hours ago, RaananW said: Hi @adam, I believe the observers are being executed only during the render loop (when the view matrix is updated). So without rendering they won't execute. but this needs to be tested. You're right. I think calling camera.getViewMatrix() every frame would work. That would cause onViewMatrixChangedObservable to notify when necessary. Edit: This doesn't appear to help with controls, though. You might need to just call scene.render() whenever you suspect the user has moved the camera (listen to mouse/pointer and specific keys). Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 26, 2017 Share Posted October 26, 2017 The key trigger for everything on camera is camera.update() Echnaton 1 Quote Link to comment Share on other sites More sharing options...
adam Posted October 26, 2017 Share Posted October 26, 2017 Doing something like this only renders the scene when you click (using FreeCamera). camera.onViewMatrixChangedObservable.add(function(){ scene.render(); }); setInterval(function(){ camera.update(); }, 17); GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Echnaton Posted October 27, 2017 Author Share Posted October 27, 2017 thank you all for your replies the camera.update() function is what i was looking for. adam 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.