FairDinkum82
FairDinkum82

Reputation: 177

How to adjust the Camera position so that objects can be viewed in enough size with three.js?

I've made an application where it takes values from external file to create geometry. I'm very much successful in that. By default, my objects are viewing in very smaller in size. But when I tried with mouse ball rolling I can see the actual objects in the scene as it zooms into the scene. But, how could I obtain this size of objects as my scene is instantiated.

The link to working application : http://studenter.miun.se/~sagh0900/TrackBallAlt.Html

Here is the zoomed version view of scene and its objects

enter image description here

Upvotes: 1

Views: 169

Answers (1)

John McKnight
John McKnight

Reputation: 684

You can use either of these to get the size of the bounding box or sphere of your mesh.

// This computes it.
mesh.geometry.computeBoundingSphere();

// This gets it
var radius = mesh.geometry.boundingSphere.radius;


// Compute the bounding box
mesh.geometry.computeBoundingBox();

// This now has a min and max structure with x and y values of the box
mesh.geometry.boundingBox

Once you have that information you can set your camera so the objects are in view.

Upvotes: 2

Related Questions