Viewer API - Accessing Bound Center and Bounding Box values

viewer-api
viewer

(Fjiang) #1

The Sketchfab viewer outputs the following info every time it starts up:

Bound center : [ 0.030100000000000016, 0.0023699999999999832, -0.008918589785844144 ]
Bound radius : 3.7283695298351667
Bbox min : [ -2.01874, -1.14179, -2.90614 ]
Bbox max : [ 2.0789400000000002, 1.14653, 2.888302820428312 ]

I'm trying to access these values within JavaScript so that my camera revolves around the exact center of the model. Right now that center is set to [0, 0, 0], and this causes some models to drift during revolution. Unfortunately, I can't just copy the above values into my code because the program is supposed to work with any model regardless of its position.

For a while I suspected getNodeMap() would have what I'm looking for, but all I could find was one or two of the above numbers scattered throughout the nodes object. There's also another post dealing with the same issue, but the author doesn't seem to require a dynamic solution that adapts to each model.


(Shaderbytes) #2

You are forgetting that sketchfab can have many different loose objects in a scene. So the values they output there are scene related not per object and besides this info is not exposed in the API at all.

You can get the matrix of an object and use the lookat function to focus the camera onto an object , see here :

http://www.shaderbytes.co.za/sketchfab/development/api/examples/example_5.html

Although the focal point is not based on the objects bounding box but rather the world origin (transform) that was present when uploading the model. There is no way that I know of to get the bounding box values for an object and so you cant calculate a bounding box center point.