Units in Three.js

Then it’s still unitless, right? If it’s real unit, it shall not depend on anything.



or
https://helpx.adobe.com/photoshop/using/grid-guides.html

If it’s real unit, it shall not depend on anything.

All units are defined in one of two ways:

  1. Base units. In the SI system these are metres, kilograms and seconds and so on. These are defined in terms of some natural constant, but the choice is arbitrary. Basically, a metre is one metre long just because we all agreed that one ten-millionth of the distance from the equator to the North Pole should be called a metre.

  2. Derived units, defined in terms of these base units, e.g watts are defined by joules and seconds. Joules are defined by newtons and metres. Newtons are defined by kilograms and metres and seconds. Three.js units are defined by metres.

All units in the end are just conventions designed to make sharing calculations easier. But you don’t have to follow any of these conventions. If it’s more useful to you to use a metre that’s defined as the distance from Earth to the Moon, then go ahead. If it’s more useful to you to use a three.js unit that’s defined based on cubits or stadions then that’s fine too. But the rest of us will still keeping using the standard metre and the standard threejs unit (unless we need to make really tiny or really big scenes).

I think my question is the relationship between 3js unit and reality.

Softwares like Maya, or Alias or Catia or AutoCAD or Photoshop all have a way to map/calibrate to reality units.
Say we have a 10mm20mm30mm cube in Maya, or Alias or Catia or AutoCAD, we export to .stl then make a physical prototype, it’ll give me a 10mm20mm30mm cube. We also have a way to view it in computer with it’s true size.

Or say we have a 10mm20mm rectangle in Photoshop, we print it true size. The print we get is a 10mm20mm rectangle on paper.

But there isn’t something like this in 3js, or is there?

Even if screens are of different sizes? All you will see is just a box (at all the respect, but 10 x 20 x 30 is not a cube) with markers around it with numbers of chosen units.

My recent project:
MeasurementBox_dynamic_values
Values of dimensions can be presented with different units.

Printer’s driver does all the job.

1 Like

From this page on STL file spec

The StL file does not contain any scale information; the coordinates are in arbitrary unit

Other places I’ve seen say that STL units are usually interpreted as millimetees.

What might be happening in your case is that you’re creating a model scaled in cm, exporting it to STL where it has arbitrary units, then loading it in the printer where the units are again interpreted as cm.

Or possibly AutoCAD is smart enough to know that all 3d printers interpret STL units as mm, so when you export a model that’s in cm it puts a scale factor so that it prints the right size.

2 Likes

the relationship between 3js unit and reality.

As @prisoner849 points out, there cannot be a fixed relationship between three.js units and reality, unless you’re always viewing your scene on the same screen. A cube that measures 1cm across on my phone might be 2.5cm across on your laptop with the camera the same distance away from it.

So, you can choose the length of the unit. But since the ‘base’ unit of length is the metre, that’s always the default choice for units involving length.

2 Likes

There is one other important reason for choosing metres, and that’s lighting calculations. If you want to use physically correct lighting, then you should always scale your scene realistically. I.e. a bedroom should be around 5 metres across.

Then, if you set up a 100w (~1700 lumen) bulb like this it should illuminate your scene in a very realistic manner:

renderer.physicallyCorrectLights = true;

const light = new PointLight(
0xffffff, 
1, // intensity, over written by power below
0, // 0 means infinite distance
2 // decay of two means physically accurate
) 

light.power =1700
1 Like

Yes. I don’t use Maya, but in Alias, you can calibrate it in orthographic then view in true size.

Not really, you can also view in true size in photoshop. Under ‘View’-> ‘100%’.

calibrate it in orthographic then view in true size

You could do that in three.js as well, using an orthographic camera and measuring your screen.

The only difference really is that in three.js you have to do that yourself since it’s just a framework whereas in Alias, which is a full modeling program, it’s already been set up for you.

1 Like

Anyway, it relies on the information about how many points (physical dots of a display) within an inch on a screen. Thus, it relies on resolution of a device, so a software has to know about it, retrieving this information from device driver or having its own database of devices and their resolutions.

2 Likes

I still don’t get why is screen(resolution) related. In reality a cube LOOKS like 1cm by someone with blurry vision will still LOOK like 1cm by someone with clear vision standing in the same distance away. If we send a ruler to measure the cube, it shall tell us ‘this is xcm(fixed)’.
I’m confused in here.
But how does Photoshop always have the exactly the same unit as reality?

Because of information on DPI (dots per inch) or PPI (pixels per inch) of a device.

1 Like

I wasn’t aware that Photoshop has such accurate measurement. Have you tried getting out a ruler to test it?

1 Like

@looeee
I tried it, when I was developing a software for printing, so it all depends on correctness of information from device’s driver :slight_smile: Usually 9 out of 10 monitors gave wrong results with longer, than 1 cm, length of a line on a screen. But printers are more precise with it, so I always took correct result. At least, on laser printers (I worked with Xerox big stations - VIPP language, templates for documents, ah, good ol’ times :relaxed: )

It was several years ago, so maybe now the situation became better :slight_smile: Or maybe I had such bad monitors or wrong rulers :smile: and thus everything was perfectly okay with size of lines :laughing:.

2 Likes
  1. In photoshop, set 100%/or print size, in View.
  2. set units to be mm, type to be points. in Edit->Preference->Units&rulers.
  3. Ctrl+R to show ruler, drag the horizontal/vertical ruler to make a 50mmx50mm square.
  4. Measure it with real ruler.

And it turns out to be 3mm longer than 50mm on real ruler, 6% off, almost fooled me.

3 Likes

That’s what I was talking about :slight_smile:

I am using this Photoshop grid generator to make custom grids.

Hi,
The result on a picture is awesome. Do you have live demo to get this result?

A simple solution is to apply a uniform scale transform to the imported mesh. For example, if you have a model specified in inches, and you want to have it in meters, just model.scale.setScalar(0.0254). :slight_smile:

1 Like

Thanks pal! I got that stuff all squared away two years ago, when I posted that… :wink: