-
Notifications
You must be signed in to change notification settings - Fork 44
fix: "SubsurfaceViewer: pickingRadius not working with overlapping la… #2669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,18 +4,17 @@ import type { | |
| PickingInfo, | ||
| UpdateParameters, | ||
| LayerContext, | ||
| Attribute, | ||
| } from "@deck.gl/core"; | ||
| import { COORDINATE_SYSTEM, Layer, project32, picking } from "@deck.gl/core"; | ||
|
|
||
| import type { Device, Texture, UniformValue } from "@luma.gl/core"; | ||
| import type { ShaderModule } from "@luma.gl/shadertools"; | ||
| import { lighting } from "@luma.gl/shadertools"; | ||
| import { Model, Geometry } from "@luma.gl/engine"; | ||
|
|
||
| import { phongMaterial } from "../shader_modules/phong-lighting/phong-material"; | ||
| import { precisionForTests } from "../shader_modules/test-precision/precisionForTests"; | ||
| import { decodeIndexFromRGB, utilities } from "../shader_modules"; | ||
|
|
||
| import { encodeIndexToRGB } from "../shader_modules/utilities"; | ||
| import type { | ||
| DeckGLLayerContext, | ||
| ExtendedLayerProps, | ||
|
|
@@ -27,9 +26,7 @@ import { | |
| type ColormapFunctionType, | ||
| getImageData, | ||
| } from "../utils/colormapTools"; | ||
|
|
||
| import type { RGBColor } from "../../utils"; | ||
|
|
||
| import fs from "./map.fs.glsl"; | ||
| import vs from "./map.vs.glsl"; | ||
| import fsLineShader from "./line.fs.glsl"; | ||
|
|
@@ -57,7 +54,6 @@ export interface PrivateMapLayerProps extends ExtendedLayerProps { | |
| } | ||
|
|
||
| const defaultProps = { | ||
| data: ["dummy"], | ||
| contours: [-1, -1], | ||
| isContoursDepth: true, | ||
| gridLines: false, | ||
|
|
@@ -90,13 +86,37 @@ export default class PrivateMapLayer extends Layer<PrivateMapLayerProps> { | |
| }); | ||
| } | ||
|
|
||
| calculatePickingColors(attribute: Attribute) { | ||
| const n = this.props.positions.length / 3; | ||
| const arr = new Uint8Array(n * 3); | ||
|
|
||
| for (let i = 0; i < arr.length / 3; i++) { | ||
| const pickingColor = encodeIndexToRGB(i); | ||
| arr[i * 3 + 0] = pickingColor[0]; | ||
| arr[i * 3 + 1] = pickingColor[1]; | ||
| arr[i * 3 + 2] = pickingColor[2]; | ||
| } | ||
| attribute.value = arr; | ||
| return; | ||
| } | ||
|
|
||
| initializeState(context: DeckGLLayerContext): void { | ||
| const gl = context.device; | ||
| const [mesh_model, mesh_lines_model] = this._getModels(gl); | ||
| this.setState({ | ||
| models: [mesh_model, mesh_lines_model], | ||
| isLoaded: false, | ||
| }); | ||
|
|
||
| this.getAttributeManager()!.remove(["instancePickingColors"]); | ||
|
|
||
| this.getAttributeManager()!.add({ | ||
| pickingColors: { | ||
| size: 3, | ||
| type: "uint8", | ||
| update: this.calculatePickingColors, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| shouldUpdateState({ | ||
|
|
@@ -285,10 +305,38 @@ export default class PrivateMapLayer extends Layer<PrivateMapLayerProps> { | |
| } | ||
| } | ||
|
|
||
| decodePickingColor(): number { | ||
| nullPickingColor() { | ||
| return [0, 0, 0]; | ||
| } | ||
|
|
||
| decodePickingColor(/*color: Uint8Array*/): number { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this used ? If not, remove it
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used by deck,gl to in this case map all colors to index zero. (As this layer does not have multiple index's)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add that in a comment, please. |
||
| return 0; | ||
| } | ||
|
|
||
| // Disable picking by setting all picking colors to null color. | ||
| // Used in multipicking to prevent recurring picks of the same layer. | ||
| _disablePickingIndex(/*objectIndex: number*/) { | ||
w1nklr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { pickingColors, instancePickingColors } = | ||
| this.getAttributeManager()!.attributes; | ||
| const colors = pickingColors || instancePickingColors; | ||
| if (!colors) { | ||
| return; | ||
| } | ||
|
|
||
| const pickingColor = this.nullPickingColor(); | ||
|
|
||
| const n = this.props.positions.length / 3; | ||
| const arr = new Uint8Array(n * 3); | ||
|
|
||
| for (let i = 0; i < arr.length / 3; i++) { | ||
| arr[i * 3 + 0] = pickingColor[0]; | ||
| arr[i * 3 + 1] = pickingColor[1]; | ||
| arr[i * 3 + 2] = pickingColor[2]; | ||
| } | ||
|
|
||
| colors.buffer.write(arr, 0); | ||
| } | ||
|
|
||
| getPickingInfo({ info }: { info: PickingInfo }): LayerPickInfo { | ||
| if (!info.color) { | ||
| return info; | ||
|
|
@@ -297,7 +345,6 @@ export default class PrivateMapLayer extends Layer<PrivateMapLayerProps> { | |
| const layer_properties: PropertyDataType[] = []; | ||
|
|
||
| // Note these colors are in the 0-255 range. | ||
|
|
||
| const [r, g, b] = info.color; | ||
| const vertexIndex = decodeIndexFromRGB([r, g, b]); | ||
|
|
||
|
|
@@ -316,8 +363,11 @@ export default class PrivateMapLayer extends Layer<PrivateMapLayerProps> { | |
|
|
||
| const properties = this.props.vertexProperties; | ||
| const property = properties[vertexIndex]; | ||
| layer_properties.push(createPropertyData("Property", property)); | ||
| if (Number.isNaN(property)) { | ||
| return info; | ||
| } | ||
|
|
||
| layer_properties.push(createPropertyData("Property", property)); | ||
| return { | ||
| ...info, | ||
| properties: layer_properties, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why changing the default value ?
Does it really fix anything ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this doesn't fix anything. 2 is barely mutlipicking. 10 is the default from deck.gl. It can affect performance if set to high. Of course its only a defaul value. I dont have any strong feelings about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I remember you did set to 2 for performance reason.
If there is no impact on this PR, reset it to 2 please.