iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.1k stars 298 forks source link

3DTile volume.region is an OBB not an Array #980

Closed bkuster closed 5 years ago

bkuster commented 5 years ago

When determining the extent of a b3dm, the volume is analyzed. This can be one of three: region, box or sphere. Both box and sphere are handled correctly, but region is still treated as the original user input and not the derived internal data type, which is an oriented bbox _in the parents frame of reference created here.

Code producing the issue: https://github.com/iTowns/itowns/blob/87bb03e55836311f20142f811e9788ce90971120/src/Process/3dTilesProcessing.js#L38-L44

Possible fix

I tried hacking in the following. Since I'm new to working with both iTowns and THREE, there most likely is a better solution, but this works:

if (volume.region) {
  const box = tmpBox3.copy(volume.region.box3D)
     .applyMatrix4(volume.region.matrix) // XXX not sure if this is matrix or matrixWorld?
     .applyMatrix4(transform);
  return Extent.fromBox3(crs, box);
}

If you care for a PR with this solution, I'm more then happy to open one up.

gchoqueux commented 5 years ago

I will look at this solution for release 2.7.0.

gchoqueux commented 5 years ago

@bkuster thank you for revealing this issue and proposing a solution. This solution seems correct.

you can avoid a multiplication because transform is already multiplying in matrixWorld

if (volume.region) {
  const box = tmpBox3.copy(volume.region.box3D)
     .applyMatrix4(volume.region.matrixWorld);
  return Extent.fromBox3(crs, box);
}

Could you open the PR?

bkuster commented 5 years ago

sure thing!