What unit of distance in threejs?

Hello.
I write numbers in functions to indicate the coordinates, sizes, and so on:
new THREE.BoxBufferGeometry(4, 4, 2);
object.position.set(4, 2, 0);
new THREE.Vector3(0, 1, 3);

Ок. What unit of distance in threejs? Meters, millimeters? :roll_eyes:

It’s a unitless system. The number 1 means whatever value you assign to it. If you want to go with meters, just make sure all units follow the same convention of meters, and you’ll have no problem.

If you want to go with inches, make sure all your measurements also assume inches, etc. It’s entirely up to you.

3 Likes

3 years of discussion on that topic awaits you, @Evil_Google.

2 Likes

Um, I would not say that. We always use the term world units. It’s right that you can map any concrete unit to it but usually it’s meter.

2 Likes

You can pick any kind of unit that fits your case. If you’re about to make an app on microscopic level it makes no sense to use a large unit that always deals with many decimal places.

Asides of having a reasonable unit for reasonable numbers to deal with, what you generally want to avoid is float precision issues which will first appear on GPU with 32bit or less, not so with JS having 64bit.

For regular scaled scenes such as the real world from a human point of view i’m using centimeter as 1 unit, meter is often used too, though you can quickly run into precision issues with WebGL depending on the size of your scene and the device which can be from super low end to super high end on this platform. I’d recommend reading the topic @mjurczyk linked.

OK, meter :slightly_smiling_face:

sofa dimensions in 3d max


create a box to check the dimensions

let t_geo = new THREE.BoxBufferGeometry(3.421, 1.071, 1.317);
let t_mat = new THREE.MeshBasicMaterial({color: 0xea3fb6});
let t_mesh = new THREE.Mesh(t_geo, t_mat);
t_mesh.position.set(-1.3,0,0);
t_mesh.rotation.y = THREE.Math.degToRad(-90)
scene.add(t_mesh);

In threejs the dimensions are slightly larger :roll_eyes:

Question - does it actually matter? Besides relative sizing between objects, user can’t really “measure” a unit in 3D space.

And if you need to calculate software-to-three size ratio, it should be enough to export a 1m x 1m x 1m cube from your software of choice and measure it using Box3. This should then give you an exact unit-to-metre ratio (which can be different for every software you export from - there are no industry rules or standards.)

Are you absolutely sure that the 3DS Max exporter did not transform the sofa in some way? To be sure, check the transformation of the asset’s entire object hierarchy. And also check the raw geometry data.

2 Likes

I think it’s important for ray-tracing, since some materials can affect colors depending on the length rays travel in them. So even if we don’t do that in three.js, it may be a good idea to start taking good habits now, for better future interoperability.

Take PointLight.distance for instance, if PointLight is to be used in WebGLRenderer and in a future hypothetical RaytracingRenderer, then distance must be of a certain unit, hence your scene must be scale accordingly.

1 Like

@felixmariotto yep, you’re right - I meant more of this thread’s context (for what I understand, just placing real-life models next to each other and maintaining proportions.)

1 Like

Rather than being forced into a specific unit system (which is not reasonable regarding the app specific world dimensions/precision issues that can occur) that should be a renderer setting defining a constant, to avoid something hardcoded as this.

3 Likes

I didn’t think about that, you’re right that’s even better. It’s true that floating point imprecision would be an issue with small models.

Hope this helps!

1 Like