three-geo icon indicating copy to clipboard operation
three-geo copied to clipboard

how to set coordinate system in three-geo

Open zxo102 opened this issue 4 years ago • 5 comments

Hi, For an engineering purpose, I would like to set Z axis (blue color) as up one and X (red), Y(green) as a ground plane. I try
THREE.Object3D.DefaultUp = new THREE.Vector3(0,0,1); which seems not changing the default coordinate system (y (green) is up) in three-geo.

Thanks a lot.

ouyang

zxo102 avatar Apr 10 '20 12:04 zxo102

I found the demo: https://github.com/w3reality/three-geo/tree/master/examples/editor
and here it is: //camera.up.set(0, 0, 1); // important for OrbitControls THREE.Object3D.DefaultUp = new THREE.Vector3(0,0,1); Thanks for the examples @j-devel

zxo102 avatar Apr 11 '20 01:04 zxo102

Yes, in your case (with elevation along the z-axis), simply updating the camera's up-vector as

camera.up.set(0, 0, 1);

should work.

j-devel avatar Apr 11 '20 04:04 j-devel

j-develop, thanks for your reply.

I am not sure what is the difference between camera.up.set(0, 0, 1); and THREE.Object3D.DefaultUp = new THREE.Vector3(0,0,1);

Someone metioned THREE.Object3D.DefaultUp = new THREE.Vector3(0,0,1); at https://stackoverflow.com/questions/42079679/reorienting-axes-in-three-js-fails-when-webpage-is-refreshed

""" If you do this very early inside your code, so before you instantiate (create) any objects, all objects would have by default the up property set correctly from the start and then you probably don't need to do any additional custom configuration. You can change the default up with this line of code:

THREE.Object3D.DefaultUp.set( 0, 0, 1 ); """

zxo102 avatar Apr 11 '20 04:04 zxo102

I see. Putting THREE.Object3D.DefaultUp = new THREE.Vector3(0, 0, 1); prior to any Object3D object instantiations guarantees that the up-vector is properly set for all objects in the app following the 'xyZ' convention (where the capital Z is elevation).

For example, in the 'editor' example case, we can start code like

THREE.Object3D.DefaultUp = new THREE.Vector3(0, 0, 1);

const canvas = document.getElementById("canvas");
const camera = new THREE.PerspectiveCamera(75, canvas.width/canvas.height, 0.001, 1000);
camera.position.set(0, 0, 1.5);
//camera.up.set(0, 0, 1); // <---- we don't need this in favor of `DefaultUp` line above

I think this DefaultUp approach is more consistent and better than just updating the up-vector of camera as we are currently doing in some examples (e.g. editor, simple-viewer, and geo-viewer). What do you think? @zxo102

j-devel avatar Apr 13 '20 14:04 j-devel

J-devel, thanks for your comment.

zxo102 avatar Apr 13 '20 23:04 zxo102