Reputation: 31
I have to load 3 different types of geometry ( cubes, lines and points) from csv files into a scene add a camera and lights to look at it.
Sounds quite easy but I’m struggling with points and positioning to point collection in the Center of the scene.
I’m looking for some pseudo code that outlines the approach you would take to achieve this regardless of the geometry.
I’ve got this working with cubes , but points and lines I’m struggling with.
A rough idea of the process I am using currently is -:
Welcome any ideas.
Rich
Upvotes: 1
Views: 75
Reputation: 31086
A typical approach is to compute the AABB for the geometry and use it to center the geometry at the origin. The typical code in three.js
for this looks like so:
const aabb = new THREE.Box3().setFromObject( object );
const center = aabb.getCenter( new THREE.Vector3() );
object.position.x += ( object.position.x - center.x );
object.position.y += ( object.position.y - center.y );
object.position.z += ( object.position.z - center.z );
If you need a more complete solution that automatically configures the camera and controls (THREE.OrbitControls
) with optimal parameters, check out the code from the following three.js
based glTF
viewer:
three.js R108
Upvotes: 2