문제

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().

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top