Wrong volume bounding box

蓝咒 提交于 2020-01-05 21:15:31

问题


I'm using Xtk to make a widget to measure distances in a volume. In the scene there are four object: a volume, two spheres an a cube. the cube is placed at origin and the spheres are translated 30 units along X and Y axis, each in opposite direction, as shown below:

https://docs.google.com/file/d/0B2oRl7iWfVvTaXAyckNTOC04RlE/edit?usp=sharing

The cube and the spheres are placed in the right position, but the problem arises when the volume is included in the scene, changing the coordinate system and translating the origin:

https://docs.google.com/file/d/0B2oRl7iWfVvTR3BJdk13Zm9BdTQ/edit?usp=sharing

resetBoundingBox() function is called right after render() but it makes no difference. Even I have tried to add first the objects and then the volume to the renderer with no result.

The spheres also can be dragged, and this feature is also affected by the change of the corrdinate system because ath the moment of the beginning of the movement of the sphere, this is translated respect to mouse position.

Why is the origin being translated? It seems the volume affects the scene by nullifying resetBoundingBox().


回答1:


I think this happens because you assume the volume is centered on (0, 0, 0), which is a wrong assumption.

1- Compute the REAL volume center from the volume bounding box

var volume = new X.volume();
...
var center = [volume.bbox[0] + (volume.bbox[1]-volume.bbox[0])/2,
              volume.bbox[2] + (volume.bbox[3]-volume.bbox[2])/2,
              volume.bbox[4] + (volume.bbox[5]-volume.bbox[4])/2
              ]
...

2- Apply this center as translation to the objects of the scene

Hope this helps




回答2:


you have to call resetBoundingBox() in the onShowtime callback like this

r.onShowtime = function() {

  r.resetBoundingBox();

}

r.add(volume);

This has to do with centering the scene. Something, which should be optional in a new version of XTK.



来源:https://stackoverflow.com/questions/18576524/wrong-volume-bounding-box

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!