three-geo
three-geo copied to clipboard
how to set coordinate system in three-geo
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
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
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-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 ); """
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, thanks for your comment.