The unit of measurement in the Babylonjs


I am creating a viewer where you can load any type of model inside, and get proper view and some additional features on it, like “dimension” feature, where you will be shown the dimensions of the mesh of course. I am creating this for one company, and they are using models that are sometimes in Inches, sometimes in milimeteres. Because Babylon is unitless of course, and formats (stl, obj) are also unitless (basically 1x1x1 cube in inches, and 1x1x1 cube in mm look the same in the viewer), I am having trouble deciding which unit to show (I can get proper values from the model, so something like 6x2x7 for example)

Now, I have some solutions that could be implemented, but they require manual input from them on every model they want to load. Basically I suggested using url parameter (this is also used to load the model from the AWS S3 bucket), but as I said that require that for every model they manually input that parameter. The issue is that they have thousands of these models, and it would be much better if somehow I could implement that this works automatically.

My question is if someone found any approach for solving this issue. Any idea could help.


That sounds like a nice external plugin - model unit conversion.

We support any foirm of model and any form of units. some use meters, some use mm, some use inch, and some feet. What “1” means, as you already found out, is dependent on the model (or better yet - the model creator). It should be a problem converting the units to new units. I think scaling would not work as expected, and that the best way is to take the positions array (from vertex data), and re-scale them all, one by one, ignoring x,y,z (because they are all in the same units) to, in pseudo code:

let positions = getPositionVertexData();
let newPositions => scale(p));

But I think your main issue would be to get the units used, just like you realized as well :slight_smile: . The only standard (that I know of) that defines this is glTF 2.0 - glTF/specification/2.0 at master · KhronosGroup/glTF · GitHub . Always meters. Which is amazingly wonderful. The rest - you will have to ask the designer.

Also, Web Xr has meters as an implisant standard. This is because when the headset moves 1Meter, the position changes by the same. Meshes need to also be in meters to look right.