Manipulating player size in WebXR

My issue

So I’ve been working on a huge exoplanet simulator for nine months now : 3D planets, accurate trajectories, a tiny bit of lighting and that’s it. All of this is meant to be included in a massive exoplanet database website, in case anyone using it would like to see more than numbers and classification. My current task consists of a VR-mode for the application, because it kind of fits in my studies and it seemed easy to implement. I was wrong.

My main issue currently is the fact that I don’t know at all how to “resize” the player in the WebXR session. But why would I want to do that ?

Size and scales

Currently, my project has scientifically accurate distances and scales : planets and stars are placed exactly like they are in reality (at least for the Solar System). This implies tremendous ratios between planet size and distances, factors between objects and their distance to the star are hitting 10 000+ and we are likely to hit millions when working on larger systems. Long story short, Babylon hates small meshes (less than .01 units) and absolutely messes up with everything. So my planets have to get a minimum size (for reference, Earth is exactly 1 unit, so around 12 500 km), and the distances have to follow up on those (1 Astronomical Unit = 150 000 000 km = 11 727 units). For the Solar System alone, we are talking about a diameter of approximately 700 000 units.

Now, I would like to scale up the player in the WebXR mode at… well, around the scale of the system. The aim is more or less to make the player manipulate the whole system like if it was an hologram or something - those details don’t matter here. What I want here is simply have the player grow all the way up, to catch up to the enormous size of those systems. The opposite way - shrinking the system - is quite impossible, because as I said, Babylon can’t handle really small objects. In last resort, maybe I will treat all planets as points instead of meshes, and go for the shrink solution but I’d rather avoid that as much as possible, REALLY.

So that’s it : I want to make the player be hundreds of thousands, maybe millions of units high. I tried various things before asking help here, none of those being really useful.

What I’ve tried

I am working with on 5.0.0-beta.5, if that can help. So I’ve begun with the Diving Deeper section of the documentation about WebXR. Everything in it is fine, except for the ReferenceSpace bit. Really, everything around the ReferenceSpace looked like it could help me, maybe with the DefaultCompensationHeight of the XRSession or anything along these lines. The problem is, it seems the support for the ReferenceSpace is gone. The API links to this object are no longer valid, I could hardly find any trace of it in the GitHub, and the console showed that the ReferenceSpace attribute of the XRSession was unusable. Any manipulation I tried on anything related to the ReferenceSpace led to an error. So I guess this thing is deprecated, even though I am not sure of that.

Now I can’t really think of a way to scale up things without manipulating the ReferenceSpace. Sure, I can move the XRCamera up (and I absolutely did), but it doesn’t change the height of the player, only its position.

Maybe there is a way to do what I am describing, that is yet to see with the official release of the 5.0. If any of you can help me understand how to scale up the player, or at least what happened to the ReferenceSpace support, I’ll gladly accept it. You can find the exact part of my project that uses WebXR right here : Exoplanet.eu - Exo3D (XR module). The rest of the project is also public so you can check it out, but it’s far from being finished so the app is looking somewhat empty.

cc @RaananW

I think you would be better to scale down (shrink) your world space. I’m not sure I understand your problems regarding scaling planet meshes too small. Your shrink/scale factor applied to your world makes them whatever size you want in the real world.

Perhaps you meant you are running in to floating point limitations? In which case, I believe you would need to adjust the models themselves then.

I think fundamentally, that is what is important for you to consider. When you go in to an XR space, the coordinate systems and scales generally all become relative to the real world space. I think that is somewhat fundamental to what XR means. So if you want your Earth to be 1m in the real world space, you will need to scale down your meshes correspondingly. Right?

Anyways, regarding reference spaces, I believe that is part of the WebXR spec. Babylon lets you specify the reference space as part of the WebXR helper init.

I’ve assumed messing with player “height” should be done rarely in WebXR. And if so, generally done using unbounded reference space.

I was expecting this answer, and you are right. It seems it is mostly a bad idea to change the player scale, I’ve seen it in a few other threads.

I didn’t specify it, but I don’t have models for the planets. They are Babylon spheres with low quality textures. And yes, I think I had floating point limitations. The issue is, I must be able to generate planets among a database of like, four to five thousands entries ? I can’t make a model for all of them. I will defintely try modeling but on the long term I don’t think this will work - for my project at least.

Shrinking seems like a way better option, but I will have to deal with either extremely small meshes, or no meshes at all. I don’t feel like saying to the user “Hey look, here is Jupiter ! Well you can’t see it because it is a point, but it is definitely here”…

Thank you for your answer, I will experiment on things you suggested first.

I don’t have an answer, but I’ve been thinking about this too. While it may seem odd to try to scale the player, being able to do so opens some interesting interface paradigms. A few examples where I’ve seen this put to clever use in VR:

  1. Horizon Worlds uses dynamic player scaling while in “build mode”. It lets creators quickly resize yourself to work with large or small models.
  2. Demeo: a VR board game that lets players scale themselves in relation to the pieces on the board.
  3. Google Earth: wow

I used this trick a few years ago in Unity and more recently tried it in A-Frame. In those systems, you only have to scale the object or entity that contains the camera. I’ve not been able to reproduce this effect in Babylon JS, but it sure would be great if we could.

@RaananW do you think WebXR player/camera scaling is possible in Babylon JS?

In case it helps, here is PG showing use of planet size values, but scaled to work in XR units:

If you zoom in you will end up at Earth looking at Jupiter. I also scaled the distance from Earth to Jupiter down significantly (independently of the size scale), because otherwise, just like in the real world, it would look like a star and take a long time to go back and forth. :slight_smile:

Agreed, it is a cool UX/effect/paradigm for use in WebXR. As for implementation, would it be possible to set all nodes of a scene as children of a parent Node, and then scale that parent Node up/down inversely to the player “scale”? i.e. To make the player 2x, scale everything else down 0.5.

Well, I am not that far away from being able to do something similar. This is a huge project so I couldn’t describe anything, but I do have scaling options for the planets, to make them bigger than in reality. Here is a capture of the simulation with realistic scales :

And now, with a custom specific scale, that is unique for every system (you can see how much bigger everything is by looking at the bottom center or so) :

Honestly I could totally do the opposite way and shrink down everything, but as I said, meshes would not appreciate it. To quote what I wrote in my documentation :

“The default unit we are using is the Babylon unit. We chose to make the diameter of the Earth equal to 1 Babylon unit, and scale everything else based on this. This implies really high distances for the engine (we are talking in millions of units) and at first we were unsure that the engine could even handle it. The problem is that if we take the problem from the other side - by taking huge distances as a unit, like 1 AU = 1 Babylon unit - this creates tiny objects, going from 5.10^-8 to 0.01 units. The Earth is at a microscopic 0.008 and already makes the scene go completely wrong : skybox ‘freezing’, incorrect proportions and very wrong camera placement. This is why we take the planets as reference and not the distances.”

I’ve started to take a look at that but I have not quite studied it that much. Maybe this will help, thank you anyway !

1 Like

XR scaling is an open issue we have had for quite some time now. I can’t seem to finx it dorectly, I believe it was a part of an issue that had several tasks.

As in XR 1 unit === 1 meter, i would not upscale the player (which you can do) but down-scale the world to fit the user’s size. Having said that, it should be rather straightforward to scale the user’s position in a factor defined by a property on the xr-camera (i.e. - scale the position provided by XR in this factor). There is currently no easy way of doing that, but I can experiment with it a bit and see if it works as expected. I would still scale down the world to stay conform with the 1 meter unit size. but I do understand it is not always possible…

To be able to track it - [XR] World/camera scaling · Issue #12441 · BabylonJS/Babylon.js (github.com)

Not sure when i’ll address it though

2 Likes

Thank you ! I will keep this part of my work in standby for now, I have other features that I can do first. If I have any clue to resolve this issue, I will let you know as well

1 Like