Units in Three.js

coordinate-system
units

#1

Hii,
I want to create a line of 1 cm in THREE.Scene.I make a line by passing vertices value of {0,0,0} to {1,0,0}
which makes straight horizontal line,But I have a doubt is it a 1 mm or 1 cm line ?? or is it measure in Pixel.

Thanks & Regards
Gaurav


#2

Edit: Quite embarrassingly, the answer I posted here was inaccurate, as explained below.


#3

But that’s just imaginary… or related to the bullet physics engine.

You can define any world scale you want, it might depend on your need for precision. From my experience i use 1 unit as 1 cm, this prevents precision loss that occurs pretty quickly on animations on mobile phones (the more distant you are from the origin). But i also use a multi-dimension coordinate system for theoretical “infinite” large coordinates. So it also might depend on your scene size. Engines like bullet offer an option for world scale.


#4

Oops. Sorry. I didn’t know it could be modified. By default though, everything in three is in meters, no?


#5

Metres, microns, parsecs. Any measurement unit you wish. Units in Three.js are abstract.


#6

Hmm… so where do we set that? Can three convert English too? (although this stoopid american has become quite accustomed to working in meters in 3d)


#7

There is no realworld unit relation anywhere besides the physics engine i guess. But using 1:1 meter doesn’t work well with phones and larger distances for the animations/GPU side.


#8

I don’t want to hijack this poor persons thread… but Fyrestar & prisoner849, do guys just work strictly with dynamic geo you are creating programmatically (and thus defining their measurements is a snap), or are you, like myself, working extensively with meshes created in your 3d apps and importing them into three? Those meshes I create are all in meters – and if I have a one meter wide mesh and move it with mesh.position.set(1, 2, 0);, it will move it one meter (the equivalent of one width of itself) to the right and 2 meters off ground… So I just can’t imagine how I could suddenly be working in some other measurement with these… Please elaborate if you can. I want to be well informed and have all options available.


#9

You should export everything at the same unit system from your modelling software. Just to make everything proportional. It also might depend on this software, as some have a different system. If i import Blender in C4D the models can be rediculous large or small. The software probably offers a independent unit, just as THREE which will be the same.

As mentioned i use a 1 unit 1 centimeter world scale, just cause of the precision issues that will appear on some mobile at larger distances. But i also use a coordinate system that is independent of larger numbers beyond 32 or 64 bit, so if you use smaller units as 1 you could hit the upper limit ealier if that is relevant to you at all.

Export a cube at 1 cm or 1 meter, by just looking in the model file (text-format), if the cube has coordinates like -0.5, 0.5 etc., the cube will have a size of exactly 1 unit. Most software uses the international standard you probably mentioned (1 = 1 Meter)


#10

Thank you very much for the explanation. I won’t likely ever need to work with anything other than meters, but I’m glad I have deeper understanding of this nonetheless, should my needs change.


#11

This question was already answered multiple times by Ben Houston at stackoverflow:



How do we size something using screen pixels?
#12

Notice that when you resize a Three.js application, the height of the viewport affect object sizing, so there isn’t really an absolute size for everything. I’m thinking of how to introduce absolute sizing to Three.js. For starters, figuring this out will begin to help understand how to do that. Ultimately, Three is drawing to the pixels on the screen, so there is for sure some way to map a size in Three to a number of pixels on the screen given that the camera is configured in a specific way and that obbjects are position on a specific plane perpendicular to the camera’s line of site.

Once I figure that out (I’m sure someone already knows), then in certain environments (f.e. Electron, Cordova) it is possible to get the physical dimensions of a display. Then it would be possible to specify that something is 1 inch wide, and for us to be able to place the object somewhere in the camera’s frustum so that the size we see on the display is actually 1 inch (measured with a ruler).

Being able to do this sort of thing is useful for display-independent sizing, which would be nice to have for cross-platform applications.