0

I have a 3D model in .obj format. However the coordinates for this 3D model are not (0,0,0). This a 3D render of drone imagery so the coordinates are actual georeferenced coordinates.

I'm following the example in Three.js on how to load an obj with its mtl on webgl. I use the original HTML except that I simply replace the obj listed as male02 by CerroPelaoLow and the files are placed in the obj directory. Firefox displays the model correctly but the position is the problem.

Note that this render is generated by a program this way and even though I can manipulate the model with a program such as Meshlab I'd still prefer the minimum manipulation possible.

So how can I use local coordinates of my object or focus the camera and then use a different set of controls?

1 Answers1

0

You can use the boundingSphere or boundingBox of your object's geometry to determine the position and of your camera. I have already implemented a functionality to focus an object or a set objects. So, here I share some code:

// assuming following variables:
// object   -> your obj model (THREE.Mesh)
// camera   -> PerspectiveCamera
// controls -> I'm also using OrbitControls


// if boundingSphere isn't set yet
object.computeBoundingSphere();

var sphere = object.geometry.boundingSphere.clone();
sphere.applyMatrix4( object.matrixWorld );

// vector from current center to camera position (shouldn't be zero in length)
var s = new THREE.Vector3().subVectors( camera.position, controls.center );

var h = sphere.radius / Math.tan( camera.fov / 2 * Math.PI / 180 );

var newPos = new THREE.Vector3().addVectors( sphere.center, s.setLength(h) );

camera.position.copy( newPos );
controls.center.copy( sphere.center );
Brakebein
  • 2,197
  • 1
  • 16
  • 21