Vector3 project with current camera (avoid 1 frame delay)

I have some custom panning/zooming logic in my project, so I can’t use attachControl on the camera for panning. I still need the GUI moveToVector3 method though, which is internally based on Vector3.Project:

It works fine actually, but there is always a lag of one frame. First of all I had to do some contortions to get it work after loading (on the first frame) and also my GUI lags behind a little (just 1 frame, so it’s not that bad but still I’d like to avoid it).

I tried doing it with TransformNodes and linkWithMesh, but that was very glitchy (I generate linkOffsets on the fly, and they were randomly ignored), although a little smoother when it worked. I can make a PG on request, but it might take a while. From a cursory look at the source code, I can’t quite understand how linkWithMesh avoids the 1 frame lag or why there would be glitches.

Is there any other way to remove the 1 frame delay? TransformNodes are rather messy for my use case anyway.

When do you call the moveToVector3? To avoid any lag, you can do it on the scene.onAfterRenderObservable

I’ll try. Could make a difference. Currently I am doing it in a onDragObservable callback.

Did it work? Were you able to find a solution/alternative? onAfterRenderObservable did not solve it for me :frowning:

would be great to share a repro in the Playground so that @PolygonalSun might have a look ?

Apologies for bumping this up. But after further trial and error I was able to fix it using onBeforeRenderObservable.

1 Like

For anyone who finds this when dealing with a 1-frame delay on screen space projection, it’s possible Ontropy meant to say onBeforeCameraRenderObservable in the previous message. If you don’t want to rearrange your code into a different callback function, another way to remove the 1 frame delay is by calling scene.updateTransformMatrix() before doing your Vector3.Project

1 Like