Skip to content

Commit

Permalink
fix 3d tiles culling (#4064)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Dec 20, 2019
1 parent 1549262 commit 7bd2182
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 65 deletions.
4 changes: 2 additions & 2 deletions examples/layer-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"start-local-production": "webpack-dev-server --env.local --env.production --progress --hot --open"
},
"dependencies": {
"@loaders.gl/ply": "^2.0.0-beta.7",
"@loaders.gl/gltf": "^2.0.0-beta.7",
"@loaders.gl/ply": "^2.0.0-beta.8",
"@loaders.gl/gltf": "^2.0.0-beta.8",
"@luma.gl/experimental": "^8.0.0-beta.3",
"@luma.gl/debug": "^8.0.0-beta.2",
"colorbrewer": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions examples/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
},
"dependencies": {
"deck.gl": "^8.0.0-beta",
"@loaders.gl/csv": "^2.0.0-beta.7",
"@loaders.gl/core": "^2.0.0-beta.7",
"@loaders.gl/draco": "^2.0.0-beta.7",
"@loaders.gl/csv": "^2.0.0-beta.8",
"@loaders.gl/core": "^2.0.0-beta.8",
"@loaders.gl/draco": "^2.0.0-beta.8",
"@luma.gl/constants": "^8.0.0-beta.3",
"brace": "^0.11.1",
"react": "~16.9.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/website/3d-tiles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"deck.gl": "^8.0.0-beta",
"@loaders.gl/draco": "^2.0.0-beta.7",
"@loaders.gl/draco": "^2.0.0-beta.8",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"react-map-gl": "^5.0.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/website/mesh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start-local": "webpack-dev-server --env.local --progress --hot --open"
},
"dependencies": {
"@loaders.gl/obj": "^2.0.0-beta.7",
"@loaders.gl/obj": "^2.0.0-beta.8",
"deck.gl": "^8.0.0-beta",
"react": "^16.3.0",
"react-dom": "^16.3.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/website/point-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"start-local": "webpack-dev-server --env.local --progress --hot --open"
},
"dependencies": {
"@loaders.gl/las": "^2.0.0-beta.7",
"@loaders.gl/ply": "^2.0.0-beta.7",
"@loaders.gl/las": "^2.0.0-beta.8",
"@loaders.gl/ply": "^2.0.0-beta.8",
"deck.gl": "^8.0.0-beta",
"react": "^16.3.0",
"react-dom": "^16.3.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/website/scenegraph-layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"deck.gl": "^8.0.0-beta",
"@loaders.gl/gltf": "^2.0.0-beta.7",
"@loaders.gl/gltf": "^2.0.0-beta.8",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react-map-gl": "^5.0.0"
Expand Down
4 changes: 2 additions & 2 deletions modules/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"prepublishOnly": "npm run build-debugger && npm run build-bundle && npm run build-bundle -- --env.dev"
},
"dependencies": {
"@loaders.gl/core": "^2.0.0-beta.7",
"@loaders.gl/images": "^2.0.0-beta.7",
"@loaders.gl/core": "^2.0.0-beta.8",
"@loaders.gl/images": "^2.0.0-beta.8",
"@luma.gl/core": "^8.0.0-beta.4",
"@math.gl/web-mercator": "^3.1.1",
"gl-matrix": "^3.0.0",
Expand Down
6 changes: 3 additions & 3 deletions modules/geo-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
},
"dependencies": {
"@loaders.gl/3d-tiles": "^2.0.0-beta.7",
"@loaders.gl/core": "^2.0.0-beta.7",
"@loaders.gl/gltf": "^2.0.0-beta.7",
"@loaders.gl/3d-tiles": "^2.0.0-beta.8",
"@loaders.gl/core": "^2.0.0-beta.8",
"@loaders.gl/gltf": "^2.0.0-beta.8",
"@math.gl/culling": "^3.1.1",
"@math.gl/geospatial": "^3.1.1",
"@math.gl/web-mercator": "^3.1.1",
Expand Down
27 changes: 8 additions & 19 deletions modules/geo-layers/src/tile-3d-layer/get-frame-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Vector3} from 'math.gl';
import {CullingVolume, Plane} from '@math.gl/culling';
import {Ellipsoid} from '@math.gl/geospatial';

const scratchPlane = new Plane();
const scratchVector = new Vector3();
const scratchPosition = new Vector3();
const cullingVolume = new CullingVolume([
new Plane(),
Expand Down Expand Up @@ -43,7 +43,7 @@ export function getFrameState(viewport, frameNumber) {
enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))
).normalize();

commonSpacePlanesToWGS84(viewport);
commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);

// TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function
return {
Expand All @@ -59,14 +59,8 @@ export function getFrameState(viewport, frameNumber) {
};
}

function commonSpacePlanesToWGS84(viewport) {
function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {
// Extract frustum planes based on current view.
const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0];
const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(
viewportCenterCartographic,
new Vector3()
);

const frustumPlanes = viewport.getFrustumPlanes();
let i = 0;
for (const dir in frustumPlanes) {
Expand All @@ -80,15 +74,10 @@ function commonSpacePlanesToWGS84(viewport) {

const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3());

scratchPlane.normal
.copy(cartesianPos)
.subtract(viewportCenterCartesian)
.scale(-1) // Want the normal to point into the frustum since that's what culling expects
.normalize();
scratchPlane.distance = Math.abs(scratchPlane.normal.dot(cartesianPos));

cullingVolume.planes[i].normal.copy(scratchPlane.normal);
cullingVolume.planes[i].distance = scratchPlane.distance;
i = i + 1;
cullingVolume.planes[i++].fromPointNormal(
cartesianPos,
// Want the normal to point into the frustum since that's what culling expects
scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos)
);
}
}
6 changes: 3 additions & 3 deletions modules/jupyter-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"@deck.gl/layers": "8.0.0-beta.2",
"@deck.gl/mesh-layers": "8.0.0-beta.2",
"@jupyter-widgets/base": "^2",
"@loaders.gl/3d-tiles": "^2.0.0-beta.7",
"@loaders.gl/core": "^2.0.0-beta.7",
"@loaders.gl/csv": "^2.0.0-beta.7",
"@loaders.gl/3d-tiles": "^2.0.0-beta.8",
"@loaders.gl/core": "^2.0.0-beta.8",
"@loaders.gl/csv": "^2.0.0-beta.8",
"@luma.gl/constants": "^8.0.0-beta.4",
"mapbox-gl": "^1.2.1"
},
Expand Down
2 changes: 1 addition & 1 deletion modules/layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
},
"dependencies": {
"@loaders.gl/images": "^2.0.0-beta.7",
"@loaders.gl/images": "^2.0.0-beta.8",
"@mapbox/tiny-sdf": "^1.1.0",
"earcut": "^2.0.6"
},
Expand Down
16 changes: 15 additions & 1 deletion test/modules/geo-layers/tile-3d-layer/get-frame-state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import test from 'tape-catch';
import {getFrameState} from '@deck.gl/geo-layers/tile-3d-layer/get-frame-state';
import {Viewport} from 'deck.gl';
import {equals} from 'math.gl';
import {equals, Vector3} from 'math.gl';
import {Ellipsoid} from '@math.gl/geospatial';

const EPSILON = 1e-5;
const expected = {
Expand All @@ -41,6 +42,8 @@ test('getFrameState', t => {
height: 775,
latitude: 50.751537058389985,
longitude: 42.42694203247012,
pitch: 30,
bearing: -120,
zoom: 15.5
});

Expand All @@ -58,5 +61,16 @@ test('getFrameState', t => {
t.ok(equals(results.camera.up, expected.camera.up, EPSILON), 'camera.up should match.');
t.ok(results.cullingVolume.planes.length, 6, 'Should have 6 planes.');

const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(
[viewport.longitude, viewport.latitude, 0],
new Vector3()
);
for (const plane of results.cullingVolume.planes) {
t.ok(
plane.getPointDistance(viewportCenterCartesian) > 0,
'viewport center is on the inside of the frustum plane'
);
}

t.end();
});
82 changes: 56 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1473,28 +1473,36 @@
npmlog "^4.1.2"
write-file-atomic "^2.3.0"

"@loaders.gl/3d-tiles@^2.0.0-beta.7":
version "2.0.0-beta.7"
resolved "https://registry.yarnpkg.com/@loaders.gl/3d-tiles/-/3d-tiles-2.0.0-beta.7.tgz#d314f29557b536ccd2a0268cc59dd465d4987a99"
integrity sha512-CTS7ilzlJ4lhVR681NFHxK8O+umNCMN+o/0k7CXy1JYMtuJyWRKrxwbNua2D6LW98cTgkp9AaH7yHdwM8yvcVw==
dependencies:
"@loaders.gl/core" "2.0.0-beta.7"
"@loaders.gl/gltf" "2.0.0-beta.7"
"@loaders.gl/loader-utils" "2.0.0-beta.7"
"@loaders.gl/math" "2.0.0-beta.7"
"@loaders.gl/3d-tiles@^2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/3d-tiles/-/3d-tiles-2.0.0-beta.8.tgz#12096ded1c54dcdb497a98ad099cffba943d5f80"
integrity sha512-W+EfXyUheMVai4sFxqnsw5ChK3nQHDz1gAs2+e5GpGu6Mc1rgvjNOgOLCj9JYk+FQ9/uteAgtsxLKFOSGlNWxA==
dependencies:
"@loaders.gl/core" "2.0.0-beta.8"
"@loaders.gl/gltf" "2.0.0-beta.8"
"@loaders.gl/loader-utils" "2.0.0-beta.8"
"@loaders.gl/math" "2.0.0-beta.8"
"@math.gl/culling" "^3.1.1"
"@math.gl/geospatial" "^3.1.1"
math.gl "^3.1.1"
probe.gl "^3.2.0"

"@loaders.gl/core@2.0.0-beta.7", "@loaders.gl/core@^2.0.0-beta.7":
"@loaders.gl/core@2.0.0-beta.7":
version "2.0.0-beta.7"
resolved "https://registry.yarnpkg.com/@loaders.gl/core/-/core-2.0.0-beta.7.tgz#a065b7b1cb6f2e2981333f723b79f28a0ec54fdd"
integrity sha512-H14RucR6Ch5jh93Y2FK3ug6chhjf1VLR3UM85hIHwcy4/AUYoZBEk61a3Jy1ciQfRRooCTAbufR4GpE+mE/tlg==
dependencies:
"@babel/runtime" "^7.3.1"
"@loaders.gl/loader-utils" "2.0.0-beta.7"

"@loaders.gl/core@2.0.0-beta.8", "@loaders.gl/core@^2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/core/-/core-2.0.0-beta.8.tgz#cee015d2fdc0d762d5628b88985b5bd69165527d"
integrity sha512-bCi8uTPHRw2iCFRM2TF9wXqjQsMbafL0xoXFJ+NJ/J6Ihst62/ncWScmFxKFMQW71gvQeW5+wDm78AAmzsYINA==
dependencies:
"@babel/runtime" "^7.3.1"
"@loaders.gl/loader-utils" "2.0.0-beta.8"

"@loaders.gl/csv@^2.0.0-beta.7":
version "2.0.0-beta.7"
resolved "https://registry.yarnpkg.com/@loaders.gl/csv/-/csv-2.0.0-beta.7.tgz#93f2cc07dccf3a707b30d16099fda1fc5ec56e71"
Expand All @@ -1503,19 +1511,27 @@
"@loaders.gl/core" "2.0.0-beta.7"
"@loaders.gl/tables" "2.0.0-beta.7"

"@loaders.gl/gltf@2.0.0-beta.7", "@loaders.gl/gltf@^2.0.0-beta.7":
version "2.0.0-beta.7"
resolved "https://registry.yarnpkg.com/@loaders.gl/gltf/-/gltf-2.0.0-beta.7.tgz#de1e04af5c34764f3133d204fe4159e94bda33f4"
integrity sha512-HAbjAv4qEkZK4VtRkmo31YF+vfri6eKGwOVX7wTTEVTeCmcvPFqdjq7IRBU996qHJfdjzTKQcIX3i04u5gj2Tg==
"@loaders.gl/csv@^2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/csv/-/csv-2.0.0-beta.8.tgz#3f272f9149cfbe70e6ee898dcedcb38459bdbddb"
integrity sha512-qBZ2lGIbvJLEU0tsvyPtD5dzegJrGZnJ/1Qh/WKr327enip/S2WAJ3fWcL9UvoPyMLcNVujJXV7U1ADDKkpwMQ==
dependencies:
"@loaders.gl/core" "2.0.0-beta.7"
"@loaders.gl/images" "2.0.0-beta.7"
"@loaders.gl/loader-utils" "2.0.0-beta.7"
"@loaders.gl/core" "2.0.0-beta.8"
"@loaders.gl/tables" "2.0.0-beta.8"

"@loaders.gl/images@2.0.0-beta.7", "@loaders.gl/images@^2.0.0-beta.7":
version "2.0.0-beta.7"
resolved "https://registry.yarnpkg.com/@loaders.gl/images/-/images-2.0.0-beta.7.tgz#1c6e6a8de0a9c0240e724b6d42331c955e13b7d8"
integrity sha512-kLAcwK7KfNRc5GF82ODZ2JPAlyNBvSQJK4DRNo4jkRTrq3gBWlPyT9U6rFb8o77fhtageHJ8pj4hyreT2mo+FQ==
"@loaders.gl/gltf@2.0.0-beta.8", "@loaders.gl/gltf@^2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/gltf/-/gltf-2.0.0-beta.8.tgz#af17d11b37fdc65c184cd7206f6313e640acf9ed"
integrity sha512-QI9JUYSB01NMv8MOzomq3ojHnUJ8N2Y9kLEZEmZWt/SLzEQrVlT9RgYAJI3YA8rgP39pGJ9/+FOkM/o8S/Ae7Q==
dependencies:
"@loaders.gl/core" "2.0.0-beta.8"
"@loaders.gl/images" "2.0.0-beta.8"
"@loaders.gl/loader-utils" "2.0.0-beta.8"

"@loaders.gl/images@2.0.0-beta.8", "@loaders.gl/images@^2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/images/-/images-2.0.0-beta.8.tgz#1ceb5f4887a0e47c2f391b3e7b11e3598641014d"
integrity sha512-z+0aCNoglbTCj6Thlig6zFzB9nbfhhiCCSH1kk2QCLIZMJv2M1oHL11vo/yoiD2GOMv9nqT8bKzDtwSgzsvidg==

"@loaders.gl/images@^2.0.0-beta":
version "2.0.0-beta.1"
Expand All @@ -1529,12 +1545,19 @@
dependencies:
"@babel/runtime" "^7.3.1"

"@loaders.gl/math@2.0.0-beta.7":
version "2.0.0-beta.7"
resolved "https://registry.yarnpkg.com/@loaders.gl/math/-/math-2.0.0-beta.7.tgz#7662c0723d371917264261138ab2ffe297f32c25"
integrity sha512-WA5hkDVHdUg+j2/LJpOTJABNNOBxXBdcPaPMFdGbzXWbqrnrbW0AldXHQwT2Ap7Rq1mff2XFNjr/jlPa1c/ESg==
"@loaders.gl/loader-utils@2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/loader-utils/-/loader-utils-2.0.0-beta.8.tgz#e152902699e0c2ca8752738b5f128bad56690edc"
integrity sha512-HSVTPFlLe4B3XSHBJjxqCi9MLlPbbeUDuo0GtHxl+0/r7wFnhJZhiALDKbk8FG67Mh22wzu1mL82WsyR39IQQA==
dependencies:
"@loaders.gl/images" "2.0.0-beta.7"
"@babel/runtime" "^7.3.1"

"@loaders.gl/math@2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/math/-/math-2.0.0-beta.8.tgz#3991bfa4bea90869e4115aa48ff35a1a3b3ff038"
integrity sha512-WopDEeAsCS0EMwtPcLHwKLTsh9joAecgIOHZm8ejSl6PJG+wH5MQpavGpd+LIxT0YBkfoInEYj2b5+W/nwV7OA==
dependencies:
"@loaders.gl/images" "2.0.0-beta.8"
math.gl "^3.1.1"

"@loaders.gl/polyfills@^2.0.0-beta.7":
Expand All @@ -1555,6 +1578,13 @@
dependencies:
"@loaders.gl/core" "2.0.0-beta.7"

"@loaders.gl/tables@2.0.0-beta.8":
version "2.0.0-beta.8"
resolved "https://registry.yarnpkg.com/@loaders.gl/tables/-/tables-2.0.0-beta.8.tgz#5030c1e6497afc18486d8625dd8e18f0a82ae550"
integrity sha512-nl9L88+/K4y60WbWvmODuWbBos7YWv43rvGMrtCdO6zsa5xFk6Gr6yZmqbsIhRsMoi4eypMVYaGDRuTVP1l+UA==
dependencies:
"@loaders.gl/core" "2.0.0-beta.8"

"@luma.gl/constants@8.0.0-beta.4", "@luma.gl/constants@^8.0.0-beta.4":
version "8.0.0-beta.4"
resolved "https://registry.yarnpkg.com/@luma.gl/constants/-/constants-8.0.0-beta.4.tgz#3dea057bbf44fc44725c539d821d9ea5c558abab"
Expand Down

0 comments on commit 7bd2182

Please sign in to comment.