Your point cloud’s position is already ( 0, 0, 0 ) by default.
I’m guessing you want the points to be centered at the origin, you can call geometry.center() ( see the docs ).
So points in pointcloud have huge x,y cartesian values. So it gets rendered at faraway position from origin. I want it to render at cartesian system origin so that I can position my camera accordingly for better viewing.
let bounds = new THREE.Box3();
bounds.setFromObject( pointCloud );
bounds.getCenter(pointCloud.position).multiplyScalar(-1);
to reposition the mesh.
or…
transform the geometry/vertices themselves:
let bounds = new THREE.Box3();
bounds.setFromObject( pointCloud );
let ncenter = bounds.getCenter(new THREE.Vector3()).multiplyScalar(-1);
pointCloud.geometry.translate(ncenter.x,ncenter.y,ncenter.z);
What exactly it does?
So first we create a bound, and set it using pointcloud in second line of code, which I assume would compute a bounding box for pointcloud’s current position. So no shifting yet.
So I assume when we call multiplyScalar, it moves pointcloud to origin. Am I right?
Yup!
I didn’t write it super clearly bc I like shrimpy code.
But it would probably break if .position starts out non-zero.
getCenter takes a vec3 to return the result in, so I’m just skipping a copy/saving an alloc.
A cleaner version:
let bounds = new THREE.Box3();
bounds.setFromObject( pointCloud );
let center = bounds.getCenter(new THREE.Vector3());
pointCloud.position.sub(center);