Skip to content

Commit ff75666

Browse files
Fix picking bugs (#8730)
1 parent 9117414 commit ff75666

File tree

16 files changed

+115
-91
lines changed

16 files changed

+115
-91
lines changed

modules/aggregation-layers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
3939
},
4040
"dependencies": {
41-
"@luma.gl/constants": "^9.0.8",
42-
"@luma.gl/shadertools": "^9.0.8",
41+
"@luma.gl/constants": "^9.0.9",
42+
"@luma.gl/shadertools": "^9.0.9",
4343
"@math.gl/web-mercator": "^4.0.0",
4444
"d3-hexbin": "^0.2.1"
4545
},

modules/arcgis/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
3737
},
3838
"dependencies": {
39-
"@luma.gl/constants": "^9.0.8",
40-
"@luma.gl/webgl": "^9.0.8",
39+
"@luma.gl/constants": "^9.0.9",
40+
"@luma.gl/webgl": "^9.0.9",
4141
"esri-loader": "^3.3.0"
4242
},
4343
"peerDependencies": {

modules/carto/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@loaders.gl/mvt": "^4.1.4",
4848
"@loaders.gl/schema": "^4.1.4",
4949
"@loaders.gl/tiles": "^4.1.4",
50-
"@luma.gl/constants": "^9.0.8",
50+
"@luma.gl/constants": "^9.0.9",
5151
"@math.gl/web-mercator": "^4.0.0",
5252
"@types/d3-array": "^3.0.2",
5353
"@types/d3-color": "^1.4.2",

modules/core/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
"dependencies": {
4343
"@loaders.gl/core": "^4.1.4",
4444
"@loaders.gl/images": "^4.1.4",
45-
"@luma.gl/constants": "^9.0.8",
46-
"@luma.gl/core": "^9.0.8",
47-
"@luma.gl/engine": "^9.0.8",
48-
"@luma.gl/shadertools": "^9.0.8",
49-
"@luma.gl/webgl": "^9.0.8",
45+
"@luma.gl/constants": "^9.0.9",
46+
"@luma.gl/core": "^9.0.9",
47+
"@luma.gl/engine": "^9.0.9",
48+
"@luma.gl/shadertools": "^9.0.9",
49+
"@luma.gl/webgl": "^9.0.9",
5050
"@math.gl/core": "^4.0.0",
5151
"@math.gl/sun": "^4.0.0",
5252
"@math.gl/web-mercator": "^4.0.0",

modules/core/src/lib/deck-picker.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ export default class DeckPicker {
100100

101101
finalize() {
102102
if (this.pickingFBO) {
103-
this.pickingFBO.delete();
103+
this.pickingFBO.destroy();
104104
}
105105
if (this.depthFBO) {
106-
this.depthFBO.colorAttachments[0].delete();
107-
this.depthFBO.delete();
106+
this.depthFBO.destroy();
108107
}
109108
}
110109

@@ -145,16 +144,15 @@ export default class DeckPicker {
145144
_resizeBuffer() {
146145
// Create a frame buffer if not already available
147146
if (!this.pickingFBO) {
148-
this.pickingFBO = this.device.createFramebuffer({colorAttachments: ['rgba8unorm']});
147+
this.pickingFBO = this.device.createFramebuffer({
148+
colorAttachments: ['rgba8unorm'],
149+
depthStencilAttachment: 'depth16unorm'
150+
});
149151

150152
if (this.device.isTextureFormatRenderable('rgba32float')) {
151153
const depthFBO = this.device.createFramebuffer({
152-
colorAttachments: [
153-
this.device.createTexture({
154-
format: 'rgba32float'
155-
// type: GL.FLOAT
156-
})
157-
]
154+
colorAttachments: ['rgba32float'],
155+
depthStencilAttachment: 'depth16unorm'
158156
});
159157
this.depthFBO = depthFBO;
160158
}

modules/core/src/passes/pick-layers-pass.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,17 @@ export default class PickLayersPass extends LayersPass {
131131
depthMask: true,
132132
depthTest: true,
133133
depthRange: [0, 1],
134-
...layer.props.parameters,
135-
// Blending
136-
...PICKING_BLENDING,
137-
blend: !this.pickZ
134+
...layer.props.parameters
138135
};
139136
const {pickable, operation} = layer.props;
140137

141-
if (!this._colorEncoderState) {
138+
if (!this._colorEncoderState || operation.includes('terrain')) {
142139
pickParameters.blend = false;
143140
} else if (pickable && operation.includes('draw')) {
141+
Object.assign(pickParameters, PICKING_BLENDING);
144142
pickParameters.blend = true;
145143
pickParameters.blendColor = encodeColor(this._colorEncoderState, layer, viewport);
146144
}
147-
if (operation.includes('terrain')) {
148-
pickParameters.blend = false;
149-
}
150145

151146
return pickParameters;
152147
}

modules/extensions/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
3939
},
4040
"dependencies": {
41-
"@luma.gl/constants": "^9.0.8",
42-
"@luma.gl/shadertools": "^9.0.8",
41+
"@luma.gl/constants": "^9.0.9",
42+
"@luma.gl/shadertools": "^9.0.9",
4343
"@math.gl/core": "^4.0.0"
4444
},
4545
"peerDependencies": {

modules/geo-layers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"@loaders.gl/terrain": "^4.1.4",
4747
"@loaders.gl/tiles": "^4.1.4",
4848
"@loaders.gl/wms": "^4.1.4",
49-
"@luma.gl/gltf": "^9.0.8",
50-
"@luma.gl/shadertools": "^9.0.8",
49+
"@luma.gl/gltf": "^9.0.9",
50+
"@luma.gl/shadertools": "^9.0.9",
5151
"@math.gl/core": "^4.0.0",
5252
"@math.gl/culling": "^4.0.0",
5353
"@math.gl/web-mercator": "^4.0.0",

modules/google-maps/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
3939
},
4040
"dependencies": {
41-
"@luma.gl/constants": "^9.0.8",
41+
"@luma.gl/constants": "^9.0.9",
4242
"@math.gl/core": "^4.0.0",
4343
"@types/google.maps": "^3.48.6"
4444
},

modules/jupyter-widget/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@loaders.gl/3d-tiles": "^4.1.4",
4040
"@loaders.gl/core": "^4.1.4",
4141
"@loaders.gl/csv": "^4.1.4",
42-
"@luma.gl/core": "^9.0.8",
42+
"@luma.gl/core": "^9.0.9",
4343
"d3-dsv": "^1.0.8",
4444
"mapbox-gl": "^1.13.2"
4545
},

modules/mapbox/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
3939
},
4040
"dependencies": {
41-
"@luma.gl/constants": "^9.0.8",
41+
"@luma.gl/constants": "^9.0.9",
4242
"@math.gl/web-mercator": "^4.0.0"
4343
},
4444
"peerDependencies": {

modules/mesh-layers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
},
4040
"dependencies": {
4141
"@loaders.gl/gltf": "^4.1.4",
42-
"@luma.gl/gltf": "^9.0.8",
43-
"@luma.gl/shadertools": "^9.0.8"
42+
"@luma.gl/gltf": "^9.0.9",
43+
"@luma.gl/shadertools": "^9.0.9"
4444
},
4545
"peerDependencies": {
4646
"@deck.gl/core": "^9.0.0-beta",

modules/test-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"typed"
3434
],
3535
"dependencies": {
36-
"@luma.gl/test-utils": "^9.0.8"
36+
"@luma.gl/test-utils": "^9.0.9"
3737
},
3838
"peerDependencies": {
3939
"@deck.gl/core": "^9.0.0-beta",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"devDependencies": {
5050
"@loaders.gl/csv": "^4.1.4",
5151
"@loaders.gl/polyfills": "^4.1.4",
52-
"@luma.gl/webgpu": "^9.0.8",
52+
"@luma.gl/webgpu": "^9.0.9",
5353
"@math.gl/proj4": "^4.0.0",
5454
"@probe.gl/bench": "^4.0.9",
5555
"jsdom": "^20.0.0",

test/modules/core/lib/pick-layers.spec.ts

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import test from 'tape-promise/tape';
2424
import {
2525
MapView,
2626
ScatterplotLayer,
27+
ColumnLayer,
2728
Deck,
2829
PolygonLayer,
2930
PathLayer,
@@ -32,6 +33,8 @@ import {
3233
} from 'deck.gl';
3334
import {MaskExtension} from '@deck.gl/extensions';
3435
import * as DATA from '../../../../examples/layer-browser/src/data-samples';
36+
import type {DeckProps} from '@deck.gl/core';
37+
import {equals} from '@math.gl/core';
3538

3639
const VIEW_STATE = {
3740
latitude: 37.751537058389985,
@@ -41,7 +44,7 @@ const VIEW_STATE = {
4144
bearing: 0
4245
};
4346

44-
const DECK_PROPS = {
47+
const DECK_PROPS: DeckProps = {
4548
width: 500,
4649
height: 550,
4750
views: [new MapView()],
@@ -750,16 +753,11 @@ const TEST_CASES = [
750753
}
751754
];
752755

753-
test(`pickingTest`, t => {
754-
const deck = new Deck();
755-
t.ok(deck, 'Deck should be constructed');
756+
test(`pickingTest`, async t => {
757+
const deck = new Deck(DECK_PROPS);
756758

757-
const len = TEST_CASES.length;
758-
let index = 0;
759-
let testCase;
760-
761-
function runTests() {
762-
testCase = TEST_CASES[index++];
759+
for (const testCase of TEST_CASES) {
760+
await updateDeckProps(deck, testCase.props);
763761
const pickingMethods = testCase.pickingMethods;
764762

765763
let pickInfos;
@@ -794,13 +792,46 @@ test(`pickingTest`, t => {
794792
// }
795793
}
796794
}
797-
if (index === len) {
798-
deck.finalize();
799-
t.end();
800-
} else {
801-
deck.setProps({...DECK_PROPS, ...TEST_CASES[index].props});
802-
}
803795
}
796+
deck.finalize();
797+
t.end();
798+
});
799+
800+
test('pickingTest#unproject3D', async t => {
801+
const deck = new Deck(DECK_PROPS);
804802

805-
deck.setProps({...DECK_PROPS, ...TEST_CASES[0].props, onAfterRender: runTests});
803+
await updateDeckProps(deck, {
804+
layers: [
805+
new ColumnLayer({
806+
data: [VIEW_STATE],
807+
getPosition: d => [d.longitude, d.latitude],
808+
radius: 100,
809+
extruded: true,
810+
getElevation: 1000,
811+
getFillColor: [255, 0, 0],
812+
pickable: true
813+
})
814+
]
815+
});
816+
817+
let pickInfo = deck.pickObject({x: 250, y: 275, unproject3D: true});
818+
t.is(pickInfo.object, VIEW_STATE, 'object is picked');
819+
t.comment(`pickInfo.coordinate: ${pickInfo.coordinate}`);
820+
t.ok(
821+
equals(pickInfo.coordinate, [VIEW_STATE.longitude, VIEW_STATE.latitude, 1000], 0.0001),
822+
'unprojects to 3D coordinate'
823+
);
824+
825+
deck.finalize();
826+
t.end();
806827
});
828+
829+
function updateDeckProps(deck: Deck, props: DeckProps): Promise<void> {
830+
return new Promise(resolve => {
831+
deck.setProps({
832+
...DECK_PROPS,
833+
...props,
834+
onAfterRender: () => resolve()
835+
});
836+
});
837+
}

yarn.lock

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,69 +2590,69 @@
25902590
jszip "^3.1.5"
25912591
md5 "^2.3.0"
25922592

2593-
"@luma.gl/constants@9.0.8", "@luma.gl/constants@^9.0.8":
2594-
version "9.0.8"
2595-
resolved "https://registry.yarnpkg.com/@luma.gl/constants/-/constants-9.0.8.tgz#0a12f6a46f0ca1dd6339b57667012d66aff7ec4c"
2596-
integrity sha512-107qD7Z70TiaGgNmQ2KU4vpNOuf4dB6EgZ+CS9fIhyBFTK8okH21g9ZjzjJ6IrDbvkxuVbXp6ooMw7bcC3FyoQ==
2593+
"@luma.gl/constants@9.0.9", "@luma.gl/constants@^9.0.9":
2594+
version "9.0.9"
2595+
resolved "https://registry.yarnpkg.com/@luma.gl/constants/-/constants-9.0.9.tgz#4fdb735c4b78f09aa92db2b8020b0175ed279bb9"
2596+
integrity sha512-o8NgH4F//e2wVWyZoYmaoopoTejDEITBP78fJtU2ivmCW1viCvByUawEXISPzsekHosDYo9q1/XFjmusXZa3fQ==
25972597

2598-
"@luma.gl/core@^9.0.8":
2599-
version "9.0.8"
2600-
resolved "https://registry.yarnpkg.com/@luma.gl/core/-/core-9.0.8.tgz#8889b5704ce0c05b9b8aa7bb3258b3388cdb0260"
2601-
integrity sha512-TtGZ9iN5MFrP28jym+TR9VcLIw0jHN8u6x6tJmy9AivxzSmpZFQB+yhV2bCFDl5a8NvZo16YxyPPhrIGGrGs6Q==
2598+
"@luma.gl/core@^9.0.9":
2599+
version "9.0.9"
2600+
resolved "https://registry.yarnpkg.com/@luma.gl/core/-/core-9.0.9.tgz#1199400c94d60171875dcbbaa3d2ed2579607df1"
2601+
integrity sha512-G0N4+bSWLU6gt3grgzF5xf+vMnfYaryHFLDkAeZV5kJ2helnfzUsjwUKCEYk36V2vygu7TEXlByYgwestB7+Ew==
26022602
dependencies:
26032603
"@math.gl/types" "^4.0.0"
26042604
"@probe.gl/env" "^4.0.2"
26052605
"@probe.gl/log" "^4.0.2"
26062606
"@probe.gl/stats" "^4.0.2"
26072607
"@types/offscreencanvas" "^2019.6.4"
26082608

2609-
"@luma.gl/engine@^9.0.8":
2610-
version "9.0.8"
2611-
resolved "https://registry.yarnpkg.com/@luma.gl/engine/-/engine-9.0.8.tgz#5b84cc9a207d517c674b6acf55544626b1388322"
2612-
integrity sha512-zCB2rnvzEJlcGTOFrQUW1L68QBlSgnDvODa+VKf6IWBxwh1+sN9tdY+f7ZY+UY7vtlYADcEUwtfB6PDoWm4vjA==
2609+
"@luma.gl/engine@^9.0.9":
2610+
version "9.0.9"
2611+
resolved "https://registry.yarnpkg.com/@luma.gl/engine/-/engine-9.0.9.tgz#5eaeb784a4731969eca62acf4cf8fdb4d0d239ab"
2612+
integrity sha512-4qW4OCYaGZJ/iGqerAtnP8FzcNtnXvv+aShLkE4ay2D4zdOIML5kZSLslmU/ByZ3FR606k0c5AjTBOgZ77lkiQ==
26132613
dependencies:
2614-
"@luma.gl/shadertools" "9.0.8"
2614+
"@luma.gl/shadertools" "9.0.9"
26152615
"@math.gl/core" "^4.0.0"
26162616
"@probe.gl/log" "^4.0.2"
26172617
"@probe.gl/stats" "^4.0.2"
26182618

2619-
"@luma.gl/gltf@^9.0.8":
2620-
version "9.0.8"
2621-
resolved "https://registry.yarnpkg.com/@luma.gl/gltf/-/gltf-9.0.8.tgz#5cd84cd8145649204d0dfb74ac6693c6df7e8907"
2622-
integrity sha512-ATcMcyC0i/KuW4JPRLjyACcs8Q7c8ZRWeM5ugmQ5mQAIMVv3PfC/ZSVVtOqkBa4m+JJGHcZj2z4TXRkjJ6maOg==
2619+
"@luma.gl/gltf@^9.0.9":
2620+
version "9.0.9"
2621+
resolved "https://registry.yarnpkg.com/@luma.gl/gltf/-/gltf-9.0.9.tgz#9c326e066cd73806b01bf8f79b46c0b942b9cf74"
2622+
integrity sha512-QuV4gbxIZ8qGOmZsf9DGvavogQUyplpDVAs38eczBBqIKCGFq2d+mOIQMmn1SWFF0RjicjyjnQ2KAFWgdy2jIQ==
26232623
dependencies:
26242624
"@loaders.gl/textures" "^4.1.0"
2625-
"@luma.gl/shadertools" "9.0.8"
2625+
"@luma.gl/shadertools" "9.0.9"
26262626
"@math.gl/core" "^4.0.0"
26272627

2628-
"@luma.gl/shadertools@9.0.8", "@luma.gl/shadertools@^9.0.8":
2629-
version "9.0.8"
2630-
resolved "https://registry.yarnpkg.com/@luma.gl/shadertools/-/shadertools-9.0.8.tgz#b5225553a8ab988b2179f797c027cb90aa338214"
2631-
integrity sha512-d+x/2zy6wcwQW3uthyQDQSqRc6164IfQCciUYm88opQSVqIy0+feoLXDC/SCEM1+NOXSVcd+bDpyfP8lAKy4Fw==
2628+
"@luma.gl/shadertools@9.0.9", "@luma.gl/shadertools@^9.0.9":
2629+
version "9.0.9"
2630+
resolved "https://registry.yarnpkg.com/@luma.gl/shadertools/-/shadertools-9.0.9.tgz#88269c9889a32cd8636e7bb2351fe8d5d8b77ba9"
2631+
integrity sha512-99wfDMtkIeWziAf96UrqXteJi4uBFvMN0TdU8TvTv0V6BJRjd1xZVWnF9Xx2D+DPH9Mmn4q/hQH0NJ0sQlYeHw==
26322632
dependencies:
26332633
"@math.gl/core" "^4.0.0"
26342634
"@math.gl/types" "^4.0.0"
26352635

2636-
"@luma.gl/test-utils@^9.0.8":
2637-
version "9.0.8"
2638-
resolved "https://registry.yarnpkg.com/@luma.gl/test-utils/-/test-utils-9.0.8.tgz#c80d6c72c1fad1d168d5bae5d5ef7cc82efd73cc"
2639-
integrity sha512-bT1tuhWOwt3d5oXUG9Db7xIXF/53rgdyK9DNZ1OhDolnGPgjg8lOC6imD2ETX++E1GhoDr1PXOgFE5r4w5zwMw==
2636+
"@luma.gl/test-utils@^9.0.9":
2637+
version "9.0.9"
2638+
resolved "https://registry.yarnpkg.com/@luma.gl/test-utils/-/test-utils-9.0.9.tgz#1687d87e1bf070d1cfe145b3c7e77045a0dc875f"
2639+
integrity sha512-oMRl3ede73pp4KGvzJHhkk/QusrBoOj+PHaQ/X78ULoutAAqZpNLpiL2EkJOk3otkZMzePOW4RZeviHj0/McKQ==
26402640
dependencies:
26412641
"@probe.gl/env" "^4.0.2"
26422642
"@probe.gl/stats" "^4.0.2"
26432643

2644-
"@luma.gl/webgl@^9.0.8":
2645-
version "9.0.8"
2646-
resolved "https://registry.yarnpkg.com/@luma.gl/webgl/-/webgl-9.0.8.tgz#609c6f46bd4e0ce2f5d2de021115b8f443a205f5"
2647-
integrity sha512-2US5Nnk4B1v6HlI0NaisRktE5ko13aWo3ubbO1f9xLQ3ZxxRM6M8T2Mcl5HvOHQ37PTswbFt45dGYLOIsH6nDQ==
2644+
"@luma.gl/webgl@^9.0.9":
2645+
version "9.0.9"
2646+
resolved "https://registry.yarnpkg.com/@luma.gl/webgl/-/webgl-9.0.9.tgz#c8d9563a0e45bef2a2cb3ddfc9efbff558e3f954"
2647+
integrity sha512-dP91Md5u6OnK3PFt0h1uqcxWh3T/COBHyZ5OcAirRUB1laFdzhdXUWbtuvLgpF6b7o0MsaEUcXaAbYf+e7lEzA==
26482648
dependencies:
2649-
"@luma.gl/constants" "9.0.8"
2649+
"@luma.gl/constants" "9.0.9"
26502650
"@probe.gl/env" "^4.0.2"
26512651

2652-
"@luma.gl/webgpu@^9.0.8":
2653-
version "9.0.8"
2654-
resolved "https://registry.yarnpkg.com/@luma.gl/webgpu/-/webgpu-9.0.8.tgz#9175b74f4592bbd4ad4978dcd103b34b0a833f83"
2655-
integrity sha512-lyPAxQFdn51uWZlY+AXnL4QFIETuzb69ubGADqDJgDbo/gV0TK2h7Lp06oSmz4gO2XSpPfldi8TSVIEbPbP5ig==
2652+
"@luma.gl/webgpu@^9.0.9":
2653+
version "9.0.9"
2654+
resolved "https://registry.yarnpkg.com/@luma.gl/webgpu/-/webgpu-9.0.9.tgz#9e61ade913e4dced18cd18f36bae3fd90e4d4f26"
2655+
integrity sha512-HaGbab8EKMy33NKQqTqPMT1eq0dOSY2A4QoS24AXn9i7NODBgP540he1VA5fj2tmDuVzyNgzh2/EHuFKbDk0Sg==
26562656
dependencies:
26572657
"@probe.gl/env" "^4.0.2"
26582658
"@webgpu/types" "^0.1.34"

0 commit comments

Comments
 (0)