Skip to content

Commit

Permalink
fix(3dtiles): apply matrixWorld to boundingVolume.box
Browse files Browse the repository at this point in the history
Before this commit we only used the translation part of the transform.
We're now using the full 4x4 matrix to match the wording of the 3dtiles
specification:
"The transform property applies to [...] tile.boundingVolume , except
when tile.boundingVolume.region is defined"
  • Loading branch information
peppsac committed Jun 25, 2018
1 parent 374b860 commit e8805b9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Process/3dTilesProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,25 @@ export function pre3dTilesUpdate(context, layer) {

const cameraLocalPosition = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
const boundingVolumeBox = new THREE.Box3();
const boundingVolumeSphere = new THREE.Sphere();
function computeNodeSSE(camera, node) {
node.distance = 0;
if (node.boundingVolume.region) {
worldPosition.setFromMatrixPosition(node.boundingVolume.region.matrixWorld);
cameraLocalPosition.copy(camera.camera3D.position).sub(worldPosition);
node.distance = node.boundingVolume.region.box3D.distanceToPoint(cameraLocalPosition);
} else if (node.boundingVolume.box) {
worldPosition.setFromMatrixPosition(node.matrixWorld);
cameraLocalPosition.copy(camera.camera3D.position).sub(worldPosition);
node.distance = node.boundingVolume.box.distanceToPoint(cameraLocalPosition);
// boundingVolume.box is affected by matrixWorld
boundingVolumeBox.copy(node.boundingVolume.box);
boundingVolumeBox.applyMatrix4(node.matrixWorld);
node.distance = boundingVolumeBox.distanceToPoint(camera.camera3D.position);
} else if (node.boundingVolume.sphere) {
worldPosition.setFromMatrixPosition(node.matrixWorld);
cameraLocalPosition.copy(camera.camera3D.position).sub(worldPosition);
node.distance = Math.max(0.0, node.boundingVolume.sphere.distanceToPoint(cameraLocalPosition));
// boundingVolume.sphere is affected by matrixWorld
boundingVolumeSphere.copy(node.boundingVolume.sphere);
boundingVolumeSphere.applyMatrix4(node.matrixWorld);
node.distance = Math.max(0.0,
boundingVolumeSphere.distanceToPoint(camera.camera3D.position));
} else {
return Infinity;
}
Expand Down

0 comments on commit e8805b9

Please sign in to comment.