0

Trying out http://www.goxtk.com, great stuff! Is there a quick way to get the bounding box for a model or some other point that could be used as the center of rotation of the camera? Worst case, what's the best way to loop over the points? Thanks for any replies!

4

1 回答 1

1

可以查询每个 X.object() 的质心,如下所示:

...
r = new X.renderer('r');
r.init();

o = new X.object();
o.load('test.vtk');

r.add(o);
r.render();

r.onShowtime = function() {

    // print the centroid
    console.log(o.points().centroid());

};
...

您必须重载 X.renderer 的 onShowtime 函数,以确保正确设置 X.object(加载.vtk 文件等)。

要配置相机,您可以执行以下操作:

...
r.camera().setPosition(-400,0,0); // set the position
r.camera().setFocus(-10,-10,-10); // set the focus point
r.camera().setUp(1,0,0); // set the (normalized) up vector
r.render();
...

无论如何,要循环要点:

...
// o is an X.object
var numberOfPoints = o.points().count();
var pointArrayLength = o.points().length(); // equals numberOfPoints * 3
var allPoints = o.points().all(); // as a flat 1D array optimized for WebGL

// just loop it :)
...
于 2012-02-06T14:49:50.760 回答