Big and small objects

I’ve put together a quick example showing the problem of very small objects juddering against the background of large objects. Is there some trick that can help with the solution?

You are facing what is known as float precision limitations. You are so far away from the origin of the scene that the coordinates become imprecise.

To reclaim the precision, you must translate the camera back to the origin, as well as the rest of the scene. This trick is called floating origin and is a must use when working on space scenes :wink:

You can implement it yourself with a simple translation of the objects, or you can rely on the built in system in Babylon: Babylon.js docs

1 Like

is this possible to do with artRotateCamera? I haven’t really figured out how to do this yet

With an orbit camera you will have to do it by hand I am afraid.

Basically, at everyframe you translate every object by camera.globalPosition.negate() (including the camera target) and you will have maximal precision.

You can also do the translation when the distance to the origin is above some threshold if you don’t want to do it every frame.

It doesn’t seem to work, I must have done something wrong

There you go :wink:

I can’t position objects ( Why doesn’t parent work? I’m completely confused about this.

When using parenting, you only want to translate the parent mesh as it will also move the child meshes.

To do that, you can simply check if a mesh has a parent, and if that’s the case ignore it:

2 Likes

Thank you very much, everything seems to be working as it should now

1 Like

No problem :wink:

Can you tell me how to apply animation for such objects? I can’t get the animation to work with addInPlace(cameraInverseDisplacement)

1 Like

Hello!
You’re missing new in every example where you set the color of the line :wink:

1 Like

Could you make a PG so that I can take a look? I was able to use character animations with floating origin in some projects so I can probably make it work :wink:

I am always amazed at how JS will let you do ANYTHING and never even warn you about it :joy:

2 Likes

TypeScript rulez!

2 Likes

Haha. Not later than yesterday, I accidentaly deleted ‘return scene’ while editing.
All I got is a blank page with everything perfectly fine on the console. In fact, I never saw such a clean console :rofl: :joy:

2 Likes

I added animation, commented out the code with globalPosition.negate to make it clear how I want it to work

A solution that seems to work is to move the objects to the origin before rendering, then putting them back in place in the world after rendering:

Unfortunately, this does not work together with child components, and specifically with planet2(

Do you have a playground for that?