Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set coordinate system in three-geo #17

Open
zxo102 opened this issue Apr 10, 2020 · 5 comments
Open

how to set coordinate system in three-geo #17

zxo102 opened this issue Apr 10, 2020 · 5 comments

Comments

@zxo102
Copy link

zxo102 commented Apr 10, 2020

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
Copy link
Author

zxo102 commented Apr 11, 2020

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

@j-devel
Copy link
Contributor

j-devel commented Apr 11, 2020

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.

@zxo102
Copy link
Author

zxo102 commented Apr 11, 2020

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 );
"""

@j-devel
Copy link
Contributor

j-devel commented Apr 13, 2020

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

@zxo102
Copy link
Author

zxo102 commented Apr 13, 2020

J-devel, thanks for your comment.

j-devel added a commit that referenced this issue Jun 9, 2020
…ultUp` (#17)

Use `THREE.Object3D.DefaultUp` per [comment](#17 (comment)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants