Jump to content

Update Camera position without scene.render()


Echnaton
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

 

 

Link to comment
Share on other sites

Doing something like this only renders the scene when you click (using FreeCamera).

                camera.onViewMatrixChangedObservable.add(function(){
                    scene.render();
                });
                
                setInterval(function(){
                    camera.update();
                }, 17);

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...