Floating Origin Physics

I already found it, const scene = new Scene(engine, { floatingOriginMode: true });

1 Like

nice! yes exactly, its a scene-level option :slight_smile: if you run into features that are not working properly with this mode enabled please reply in this thread. as of right now im aware of infinite distance and billboardmode

1 Like

Funny finding, everything works super okey if every mesh has a Physics Aggregate, but if you have a normal mesh and a glow layer this happens

The mesh render get stuck but the glow layer does moves as it should

ShipGame

Everything seems to work with big distances here if every mesh has an Aggregate @georgie

Thanks for reporting! I will look into it. Do you have a playground link you can share?

If there any way I can export a scene for the playground, I did it on VS code in a Sveltekit project, just because I’m use to it.

You can serialize the scene Save Your Scene or Meshes | Babylon.js Documentation and then load it into a playground

Can you serialize the scene twice – once with floatingOriginMode and once without, and create a playground that loads them both (with one commented out) So i can toggle between the 2 via commenting / uncommenting the loaded line and then i can debug?

1 Like

I got stuck trying to load it into the Playground, I have the serialized scene but I didn’t find any way to used the serialized data.

This is the only way I found to do it here’s the serialized data of both cases:

No FloatingOrigin: https://raw.githubusercontent.com/Peipol/babylonjsRawScene/refs/heads/main/myScene(floatingFalse).babylon

With FloatingOrigin:
https://raw.githubusercontent.com/Peipol/babylonjsRawScene/refs/heads/main/myScene.babylon

1 Like

When load the 2 scenes above I see different positioning on screen – is this what you see before serializing as well?

FloatingFalse:

FloatingTrue:

My intention is to compare the matrices of all objects on scene with / without floatingorigin so i can see where the discrepancy may be.

Maybe u can reproduce a similar scenario in playground (using physics aggregates) without your exact scene? I haven’t been able to reproduce behavior differences between floating origin on/off when dealing w physics, so would love your help :slight_smile: Can be super basic meshes

1 Like

Yeah I’ll will do try with basic shapes on the playground anything to help the community

1 Like

I finally recreated the bug in the playground, the movement is weird but with wasd you can get near the the planet and with a PBRmaterial and a glow layer you’ll see that the glow move as it should except for the planet actual mesh.

Try just to move left and you’ll see this:

yup looks like some matrices might be out of sync @georgie

1 Like

@Peipol thank you for the repro playground, I am investigating

3 Likes

hey @Peipol did some investigating. TLDR the bug is because camera movement isn’t properly causing transformnodes to be marked as dirty in all cases and thus the offset is being applied to a cached worldmatrix (causing odd visual behavior). I will work on the proper fix!

You can temporarily see fixed behavior by forcing planet mesh to be dirty (here is example) – of course we wouldn’t want to actually do that on each tick of render loop for perf reasons, this is just for demonstration :slight_smile:

1 Like

Thanks @georgie!!, as I keep working on this project I’ll try to keep fully inform the community about anything I find here.

1 Like

Hey @Peipol upon further investigation I found the true root cause (marking meshes as dirty/forcing recalculation of the matrix was just a happenstance fix. The worldmatrix shouldn’t change w camera movement – the problem was the offsetting logic not being applied properly. Forcing recalc of worldmatrix was hiding the offset bug)

here is the fix!
Fix floating origin bugs causing meshes to not be properly offset by georginahalpern · Pull Request #17234 · BabylonJS/Babylon.js

4 Likes

Thank you for solving this it will help me a lot

1 Like

@peipol I have an incoming change that moves FloatingOriginMode to engine instead of scene creation options.

To enable it, pass { useFloatingOriginMode: true } when creating engine.

And to enable in playground, override the createEngine function like this Babylon.js Playground

I will make an announcement post as well once the PR is checked in

FloatingOriginMode moved to engine; Fix matrix precision setter by georginahalpern · Pull Request #17334 · BabylonJS/Babylon.js

2 Likes