UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.39k stars 177 forks source link

xr.controller_grip_location_get pre_draw callback not working #1894

Open opheroth opened 1 month ago

opheroth commented 1 month ago

Copying location from xr.controller_grip_location_get is not working as expected inside a pre_draw callback. There's always a noticeable 1 frame delay on moving objects. I've tried getting the location using bge and bpy, but the problem is still there.

The blend file contains a basic scene with a moving cube, and a sphere. The navigation location works as expected and gets the position copied from the cube correctly, but the sphere should have the position copied from the left controller grip but the position gets delayed

Is there a way to correct this modifying only the python code inside the blend, or is this a bug?

CopyLocXR.zip

youle31 commented 1 month ago

Hi, you can try to move pre_draw callback execution from KX_KetsjiEngine::RenderCameras to KX_Scene::RenderAfterCameraSetup and test. If it works for you, i'm ok to move it here.

opheroth commented 1 month ago

Hi, I've tried moving it to different zones inside KX_Scene::RenderAfterCameraSetup, but the problem is still there. Setting a location works, but reading it, doesn't.

opheroth commented 1 month ago

Doing some tests, seems like moving the object works, but reading the position of the controllers, could be happening before the scripts, and even if the navigation location changes, the controller position is not updated to the new navigation location until the next frame. I've printed the controller location, and the sphere location, and they're at the same position at the moment of running the script, for now it can be semi-fixed calculating the previous location of the navigation location - actual navigation location, then that vector can be added to the controller location, but the rotation still gets delayed, is less noticeable, but still there. Edit: Forgot to mention that the calculation is done in python, not in the source code.

I'm still trying to find when are updated the values for controllers are. I would appreciate if you have a hint on where or how to fix it correctly.

youle31 commented 1 month ago

You can look at KX_Scene, and search for "wm_xr" occurences. I haven't an XR device, and idk how to deal with that. You can try to move what is in KX_Scene... I won't be abled to review, but you can ask BluePrintRandom on discord to test what you did if you have a change proposal.

opheroth commented 1 month ago

Thanks, I've made that and moved the callback section after the xr part in KH_Scene, but as mentioned, it seems it read the transformations, then the callback move the navigation_location, and if I read the controller location, it didn't updates, and reads the location before the navigation location change. If I find something I'll go to the discord channel and ask BluePrintRandom as you suggested. Thanks again.