@luma.gl/engine 9.1.0-alpha.2 → 9.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/key-frames.js +1 -0
- package/dist/animation/key-frames.js.map +1 -0
- package/dist/animation/timeline.js +1 -0
- package/dist/animation/timeline.js.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +1 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/animation-loop/animation-loop.d.ts +2 -0
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +24 -6
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/animation-loop/animation-props.js +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +5 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +3 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/animation-loop/request-animation-frame.d.ts +4 -2
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +5 -3
- package/dist/animation-loop/request-animation-frame.js.map +1 -0
- package/dist/application-utils/load-file.d.ts +1 -1
- package/dist/application-utils/load-file.d.ts.map +1 -1
- package/dist/application-utils/load-file.js +2 -2
- package/dist/application-utils/load-file.js.map +1 -0
- package/dist/application-utils/random.js +1 -0
- package/dist/application-utils/random.js.map +1 -0
- package/dist/async-texture/async-texture.d.ts +14 -2
- package/dist/async-texture/async-texture.d.ts.map +1 -1
- package/dist/async-texture/async-texture.js +40 -3
- package/dist/async-texture/async-texture.js.map +1 -0
- package/dist/compute/buffer-transform.d.ts +41 -0
- package/dist/compute/buffer-transform.d.ts.map +1 -0
- package/dist/{transform → compute}/buffer-transform.js +19 -12
- package/dist/compute/buffer-transform.js.map +1 -0
- package/dist/{computation.d.ts → compute/computation.d.ts} +3 -3
- package/dist/compute/computation.d.ts.map +1 -0
- package/dist/{computation.js → compute/computation.js} +7 -8
- package/dist/compute/computation.js.map +1 -0
- package/dist/compute/swap.d.ts +48 -0
- package/dist/compute/swap.d.ts.map +1 -0
- package/dist/compute/swap.js +91 -0
- package/dist/compute/swap.js.map +1 -0
- package/dist/{transform → compute}/texture-transform.d.ts +0 -6
- package/dist/compute/texture-transform.d.ts.map +1 -0
- package/dist/{transform → compute}/texture-transform.js +10 -15
- package/dist/compute/texture-transform.js.map +1 -0
- package/dist/debug/copy-texture-to-image.js +1 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.js +2 -1
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.js +2 -1
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.js +1 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +2952 -5816
- package/dist/dist.min.js +422 -91
- package/dist/{lib → factories}/pipeline-factory.d.ts +11 -1
- package/dist/factories/pipeline-factory.d.ts.map +1 -0
- package/dist/factories/pipeline-factory.js +181 -0
- package/dist/factories/pipeline-factory.js.map +1 -0
- package/dist/{lib → factories}/shader-factory.d.ts +5 -1
- package/dist/factories/shader-factory.d.ts.map +1 -0
- package/dist/{lib → factories}/shader-factory.js +39 -4
- package/dist/factories/shader-factory.js.map +1 -0
- package/dist/geometries/cone-geometry.js +1 -0
- package/dist/geometries/cone-geometry.js.map +1 -0
- package/dist/geometries/cube-geometry.js +1 -0
- package/dist/geometries/cube-geometry.js.map +1 -0
- package/dist/geometries/cylinder-geometry.js +1 -0
- package/dist/geometries/cylinder-geometry.js.map +1 -0
- package/dist/geometries/ico-sphere-geometry.js +1 -0
- package/dist/geometries/ico-sphere-geometry.js.map +1 -0
- package/dist/geometries/plane-geometry.js +1 -0
- package/dist/geometries/plane-geometry.js.map +1 -0
- package/dist/geometries/sphere-geometry.js +1 -0
- package/dist/geometries/sphere-geometry.js.map +1 -0
- package/dist/geometries/truncated-cone-geometry.js +1 -0
- package/dist/geometries/truncated-cone-geometry.js.map +1 -0
- package/dist/geometry/geometry-table.js +1 -0
- package/dist/geometry/geometry-table.js.map +1 -0
- package/dist/geometry/geometry-utils.js +1 -0
- package/dist/geometry/geometry-utils.js.map +1 -0
- package/dist/geometry/geometry.js +1 -0
- package/dist/geometry/geometry.js.map +1 -0
- package/dist/geometry/gpu-geometry.js +1 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.js +1 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +1440 -217
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +23 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -0
- package/dist/model/model.d.ts +11 -10
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +92 -69
- package/dist/model/model.js.map +1 -0
- package/dist/model/split-uniforms-and-bindings.d.ts +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -1
- package/dist/model/split-uniforms-and-bindings.js.map +1 -0
- package/dist/models/billboard-texture-model.d.ts +23 -0
- package/dist/models/billboard-texture-model.d.ts.map +1 -0
- package/dist/models/billboard-texture-model.js +78 -0
- package/dist/models/billboard-texture-model.js.map +1 -0
- package/dist/models/billboard-texture-module.d.ts +10 -0
- package/dist/models/billboard-texture-module.d.ts.map +1 -0
- package/dist/models/billboard-texture-module.js +37 -0
- package/dist/models/billboard-texture-module.js.map +1 -0
- package/dist/{lib → models}/clip-space.d.ts +3 -1
- package/dist/models/clip-space.d.ts.map +1 -0
- package/dist/models/clip-space.js +77 -0
- package/dist/models/clip-space.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +28 -0
- package/dist/modules/picking/color-picking.d.ts.map +1 -0
- package/dist/modules/picking/color-picking.js +177 -0
- package/dist/modules/picking/color-picking.js.map +1 -0
- package/dist/modules/picking/index-picking.d.ts +32 -0
- package/dist/modules/picking/index-picking.d.ts.map +1 -0
- package/dist/modules/picking/index-picking.js +148 -0
- package/dist/modules/picking/index-picking.js.map +1 -0
- package/dist/modules/picking/legacy-picking-manager.d.ts +27 -0
- package/dist/modules/picking/legacy-picking-manager.d.ts.map +1 -0
- package/dist/modules/picking/legacy-picking-manager.js +76 -0
- package/dist/modules/picking/legacy-picking-manager.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +45 -0
- package/dist/modules/picking/picking-manager.d.ts.map +1 -0
- package/dist/modules/picking/picking-manager.js +101 -0
- package/dist/modules/picking/picking-manager.js.map +1 -0
- package/dist/modules/picking/picking-uniforms.d.ts +79 -0
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -0
- package/dist/modules/picking/picking-uniforms.js +109 -0
- package/dist/modules/picking/picking-uniforms.js.map +1 -0
- package/dist/passes/get-fragment-shader.d.ts +12 -0
- package/dist/passes/get-fragment-shader.d.ts.map +1 -0
- package/dist/passes/get-fragment-shader.js +117 -0
- package/dist/passes/get-fragment-shader.js.map +1 -0
- package/dist/passes/shader-pass-renderer.d.ts +63 -0
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -0
- package/dist/passes/shader-pass-renderer.js +197 -0
- package/dist/passes/shader-pass-renderer.js.map +1 -0
- package/dist/scenegraph/group-node.js +1 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.js +1 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +1 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +8 -19
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +28 -18
- package/dist/shader-inputs.js.map +1 -0
- package/dist/utils/deep-equal.js +1 -0
- package/dist/utils/deep-equal.js.map +1 -0
- package/dist/utils/uid.js +1 -0
- package/dist/utils/uid.js.map +1 -0
- package/package.json +6 -6
- package/src/animation-loop/animation-loop.ts +27 -6
- package/src/animation-loop/make-animation-loop.ts +8 -3
- package/src/animation-loop/request-animation-frame.ts +4 -3
- package/src/application-utils/load-file.ts +2 -4
- package/src/async-texture/async-texture.ts +48 -10
- package/src/{transform → compute}/buffer-transform.ts +30 -14
- package/src/{computation.ts → compute/computation.ts} +14 -8
- package/src/compute/swap.ts +116 -0
- package/src/{transform → compute}/texture-transform.ts +9 -18
- package/src/debug/debug-framebuffer.ts +1 -1
- package/src/debug/debug-shader-layout.ts +1 -1
- package/src/factories/pipeline-factory.ts +222 -0
- package/src/{lib → factories}/shader-factory.ts +41 -5
- package/src/index.ts +35 -16
- package/src/model/model.ts +132 -77
- package/src/model/split-uniforms-and-bindings.ts +4 -4
- package/src/models/billboard-texture-model.ts +98 -0
- package/src/models/billboard-texture-module.ts +49 -0
- package/src/models/clip-space.ts +88 -0
- package/src/modules/picking/README.md +88 -0
- package/src/modules/picking/color-picking.ts +190 -0
- package/src/modules/picking/index-picking.ts +156 -0
- package/src/modules/picking/legacy-picking-manager.ts +99 -0
- package/src/modules/picking/picking-manager.ts +137 -0
- package/src/modules/picking/picking-uniforms.ts +179 -0
- package/src/passes/get-fragment-shader.ts +129 -0
- package/src/passes/shader-pass-renderer.ts +252 -0
- package/src/shader-inputs.ts +44 -59
- package/dist/computation.d.ts.map +0 -1
- package/dist/lib/clip-space.d.ts.map +0 -1
- package/dist/lib/clip-space.js +0 -46
- package/dist/lib/pipeline-factory.d.ts.map +0 -1
- package/dist/lib/pipeline-factory.js +0 -98
- package/dist/lib/shader-factory.d.ts.map +0 -1
- package/dist/transform/buffer-transform.d.ts +0 -35
- package/dist/transform/buffer-transform.d.ts.map +0 -1
- package/dist/transform/texture-transform.d.ts.map +0 -1
- package/src/lib/clip-space.ts +0 -53
- package/src/lib/pipeline-factory.ts +0 -126
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { pickingUniforms, GLSL_UNIFORMS, WGSL_UNIFORMS, INVALID_INDEX } from "./picking-uniforms.js";
|
|
5
|
+
// SHADERS
|
|
6
|
+
const source = /* wgsl */ `\
|
|
7
|
+
${WGSL_UNIFORMS}
|
|
8
|
+
|
|
9
|
+
const INDEX_PICKING_MODE_INSTANCE = 0;
|
|
10
|
+
const INDEX_PICKING_MODE_CUSTOM = 1;
|
|
11
|
+
const INDEX_PICKING_INVALID_INDEX = ${INVALID_INDEX}; // 2^32 - 1
|
|
12
|
+
|
|
13
|
+
struct indexPickingFragmentInputs = {
|
|
14
|
+
objectIndex: int32;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
let indexPickingFragmentInputs: indexPickingFragmentInputs;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Vertex shaders should call this function to set the object index.
|
|
21
|
+
* If using instance or vertex mode, argument will be ignored, 0 can be supplied.
|
|
22
|
+
*/
|
|
23
|
+
fn picking_setObjectIndex(objectIndex: int32) {
|
|
24
|
+
switch (picking.indexMode) {
|
|
25
|
+
case INDEX_PICKING_MODE_INSTANCE, default: {
|
|
26
|
+
picking_objectIndex = instance_index;
|
|
27
|
+
};
|
|
28
|
+
case INDEX_PICKING_MODE_CUSTOM: {
|
|
29
|
+
picking_objectIndex = objectIndex;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
`;
|
|
35
|
+
const vs = /* glsl */ `\
|
|
36
|
+
${GLSL_UNIFORMS}
|
|
37
|
+
|
|
38
|
+
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
39
|
+
const int INDEX_PICKING_MODE_CUSTOM = 1;
|
|
40
|
+
|
|
41
|
+
const int INDEX_PICKING_INVALID_INDEX = ${INVALID_INDEX}; // 2^32 - 1
|
|
42
|
+
|
|
43
|
+
flat out int picking_objectIndex;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Vertex shaders should call this function to set the object index.
|
|
47
|
+
* If using instance or vertex mode, argument will be ignored, 0 can be supplied.
|
|
48
|
+
*/
|
|
49
|
+
void picking_setObjectIndex(int objectIndex) {
|
|
50
|
+
switch (picking.indexMode) {
|
|
51
|
+
case INDEX_PICKING_MODE_INSTANCE:
|
|
52
|
+
picking_objectIndex = gl_InstanceID;
|
|
53
|
+
break;
|
|
54
|
+
case INDEX_PICKING_MODE_CUSTOM:
|
|
55
|
+
picking_objectIndex = objectIndex;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
const fs = /* glsl */ `\
|
|
61
|
+
${GLSL_UNIFORMS}
|
|
62
|
+
|
|
63
|
+
const int INDEX_PICKING_INVALID_INDEX = ${INVALID_INDEX}; // 2^32 - 1
|
|
64
|
+
|
|
65
|
+
flat in int picking_objectIndex;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if this vertex is highlighted (part of the selected batch and object)
|
|
69
|
+
*/
|
|
70
|
+
bool picking_isFragmentHighlighted() {
|
|
71
|
+
return
|
|
72
|
+
bool(picking.isHighlightActive) &&
|
|
73
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
74
|
+
picking.highlightedObjectIndex == picking_objectIndex
|
|
75
|
+
;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns highlight color if this item is selected.
|
|
80
|
+
*/
|
|
81
|
+
vec4 picking_filterHighlightColor(vec4 color) {
|
|
82
|
+
// If we are still picking, we don't highlight
|
|
83
|
+
if (bool(picking.isActive)) {
|
|
84
|
+
return color;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// If we are not highlighted, return color as is
|
|
88
|
+
if (!picking_isFragmentHighlighted()) {
|
|
89
|
+
return color;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Blend in highlight color based on its alpha value
|
|
93
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
94
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
95
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
96
|
+
|
|
97
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
98
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* Returns picking color if picking enabled else unmodified argument.
|
|
103
|
+
*/
|
|
104
|
+
ivec4 picking_getPickingColor() {
|
|
105
|
+
// Assumes that colorAttachment0 is rg32int
|
|
106
|
+
// TODO? - we could render indices into a second color attachment and not mess with fragColor
|
|
107
|
+
return ivec4(picking_objectIndex, picking.batchIndex, 0u, 0u);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
vec4 picking_filterPickingColor(vec4 color) {
|
|
111
|
+
if (bool(picking.isActive)) {
|
|
112
|
+
if (picking_objectIndex == INDEX_PICKING_INVALID_INDEX) {
|
|
113
|
+
discard;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return color;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* Returns picking color if picking is enabled if not
|
|
121
|
+
* highlight color if this item is selected, otherwise unmodified argument.
|
|
122
|
+
*/
|
|
123
|
+
vec4 picking_filterColor(vec4 color) {
|
|
124
|
+
vec4 outColor = color;
|
|
125
|
+
outColor = picking_filterHighlightColor(outColor);
|
|
126
|
+
outColor = picking_filterPickingColor(outColor);
|
|
127
|
+
return outColor;
|
|
128
|
+
}
|
|
129
|
+
`;
|
|
130
|
+
/**
|
|
131
|
+
* Provides support for color-based picking and highlighting.
|
|
132
|
+
*
|
|
133
|
+
* In particular, supports picking a specific instance in an instanced
|
|
134
|
+
* draw call and highlighting an instance based on its picking color,
|
|
135
|
+
* and correspondingly, supports picking and highlighting groups of
|
|
136
|
+
* primitives with the same picking color in non-instanced draw-calls
|
|
137
|
+
*
|
|
138
|
+
* @note Color based picking has the significant advantage in that it can be added to any
|
|
139
|
+
* existing shader without requiring any additional picking logic.
|
|
140
|
+
*/
|
|
141
|
+
export const picking = {
|
|
142
|
+
...pickingUniforms,
|
|
143
|
+
name: 'picking',
|
|
144
|
+
source,
|
|
145
|
+
vs,
|
|
146
|
+
fs
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=index-picking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-picking.js","sourceRoot":"","sources":["../../../src/modules/picking/index-picking.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,OAAO,EAAC,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAC,8BAA2B;AAEhG,UAAU;AAEV,MAAM,MAAM,GAAG,UAAU,CAAC;EACxB,aAAa;;;;sCAIuB,aAAa;;;;;;;;;;;;;;;;;;;;;;;CAuBlD,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;EACpB,aAAa;;;;;0CAK2B,aAAa;;;;;;;;;;;;;;;;;;CAkBtD,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;EACpB,aAAa;;0CAE2B,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEtD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,GAAG,eAAe;IAClB,IAAI,EAAE,SAAS;IACf,MAAM;IACN,EAAE;IACF,EAAE;CAC6E,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Device, Framebuffer } from '@luma.gl/core';
|
|
2
|
+
import { picking } from '@luma.gl/shadertools';
|
|
3
|
+
import { ShaderInputs } from "../../shader-inputs.js";
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for using the legacy picking module
|
|
6
|
+
*/
|
|
7
|
+
export declare class LegacyPickingManager {
|
|
8
|
+
device: Device;
|
|
9
|
+
framebuffer: Framebuffer | null;
|
|
10
|
+
shaderInputs: ShaderInputs<{
|
|
11
|
+
picking: typeof picking.props;
|
|
12
|
+
}>;
|
|
13
|
+
constructor(device: Device, shaderInputs: ShaderInputs);
|
|
14
|
+
destroy(): void;
|
|
15
|
+
getFramebuffer(): Framebuffer;
|
|
16
|
+
/** Clear highlighted / picked object */
|
|
17
|
+
clearPickState(): void;
|
|
18
|
+
/** Prepare for rendering picking colors */
|
|
19
|
+
beginRenderPass(): import("@luma.gl/core").RenderPass;
|
|
20
|
+
updatePickState(mousePosition: [number, number]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get pick position in device pixel range
|
|
23
|
+
* use the center pixel location in device pixel range
|
|
24
|
+
*/
|
|
25
|
+
getPickPosition(mousePosition: number[]): [number, number];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=legacy-picking-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-picking-manager.d.ts","sourceRoot":"","sources":["../../../src/modules/picking/legacy-picking-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAC,YAAY,EAAC,+BAA4B;AAGjD;;GAEG;AACH,qBAAa,oBAAoB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,WAAW,GAAG,IAAI,CAAQ;IACvC,YAAY,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,OAAO,OAAO,CAAC,KAAK,CAAA;KAAC,CAAC,CAAC;gBAEhD,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAKtD,OAAO;IAIP,cAAc;IAUd,wCAAwC;IACxC,cAAc;IAId,2CAA2C;IAC3C,eAAe;IAef,eAAe,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IA+B/C;;;OAGG;IACH,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAM3D"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/**
|
|
5
|
+
* Helper class for using the legacy picking module
|
|
6
|
+
*/
|
|
7
|
+
export class LegacyPickingManager {
|
|
8
|
+
device;
|
|
9
|
+
framebuffer = null;
|
|
10
|
+
shaderInputs;
|
|
11
|
+
constructor(device, shaderInputs) {
|
|
12
|
+
this.device = device;
|
|
13
|
+
this.shaderInputs = shaderInputs;
|
|
14
|
+
}
|
|
15
|
+
destroy() {
|
|
16
|
+
this.framebuffer?.destroy();
|
|
17
|
+
}
|
|
18
|
+
getFramebuffer() {
|
|
19
|
+
if (!this.framebuffer) {
|
|
20
|
+
this.framebuffer = this.device.createFramebuffer({
|
|
21
|
+
colorAttachments: ['rgba8unorm'],
|
|
22
|
+
depthStencilAttachment: 'depth24plus'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return this.framebuffer;
|
|
26
|
+
}
|
|
27
|
+
/** Clear highlighted / picked object */
|
|
28
|
+
clearPickState() {
|
|
29
|
+
this.shaderInputs.setProps({ picking: { highlightedObjectColor: null } });
|
|
30
|
+
}
|
|
31
|
+
/** Prepare for rendering picking colors */
|
|
32
|
+
beginRenderPass() {
|
|
33
|
+
const framebuffer = this.getFramebuffer();
|
|
34
|
+
framebuffer.resize(this.device.getCanvasContext().getPixelSize());
|
|
35
|
+
this.shaderInputs.setProps({ picking: { isActive: true } });
|
|
36
|
+
const pickingPass = this.device.beginRenderPass({
|
|
37
|
+
framebuffer,
|
|
38
|
+
clearColor: [0, 0, 0, 0],
|
|
39
|
+
clearDepth: 1
|
|
40
|
+
});
|
|
41
|
+
return pickingPass;
|
|
42
|
+
}
|
|
43
|
+
updatePickState(mousePosition) {
|
|
44
|
+
const framebuffer = this.getFramebuffer();
|
|
45
|
+
// use the center pixel location in device pixel range
|
|
46
|
+
const [pickX, pickY] = this.getPickPosition(mousePosition);
|
|
47
|
+
// Read back
|
|
48
|
+
const color255 = this.device.readPixelsToArrayWebGL(framebuffer, {
|
|
49
|
+
sourceX: pickX,
|
|
50
|
+
sourceY: pickY,
|
|
51
|
+
sourceWidth: 1,
|
|
52
|
+
sourceHeight: 1
|
|
53
|
+
});
|
|
54
|
+
// console.log(color255);
|
|
55
|
+
// Check if we have
|
|
56
|
+
let highlightedObjectColor = [...color255].map(x => x / 255);
|
|
57
|
+
const isHighlightActive = highlightedObjectColor[0] + highlightedObjectColor[1] + highlightedObjectColor[2] > 0;
|
|
58
|
+
if (!isHighlightActive) {
|
|
59
|
+
highlightedObjectColor = null;
|
|
60
|
+
}
|
|
61
|
+
this.shaderInputs.setProps({
|
|
62
|
+
picking: { isActive: false, highlightedObjectColor }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get pick position in device pixel range
|
|
67
|
+
* use the center pixel location in device pixel range
|
|
68
|
+
*/
|
|
69
|
+
getPickPosition(mousePosition) {
|
|
70
|
+
const devicePixels = this.device.getCanvasContext().cssToDevicePixels(mousePosition);
|
|
71
|
+
const pickX = devicePixels.x + Math.floor(devicePixels.width / 2);
|
|
72
|
+
const pickY = devicePixels.y + Math.floor(devicePixels.height / 2);
|
|
73
|
+
return [pickX, pickY];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=legacy-picking-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-picking-manager.js","sourceRoot":"","sources":["../../../src/modules/picking/legacy-picking-manager.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAOpC;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAC/B,M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O,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Device, Framebuffer } from '@luma.gl/core';
|
|
2
|
+
import { ShaderInputs } from "../../shader-inputs.js";
|
|
3
|
+
import { pickingUniforms } from "./picking-uniforms.js";
|
|
4
|
+
/** Information about picked object */
|
|
5
|
+
export type PickInfo = {
|
|
6
|
+
batchIndex: number | null;
|
|
7
|
+
objectIndex: number | null;
|
|
8
|
+
};
|
|
9
|
+
export type PickingManagerProps = {
|
|
10
|
+
/** Shader Inputs from models to pick */
|
|
11
|
+
shaderInputs?: ShaderInputs<{
|
|
12
|
+
picking: typeof pickingUniforms.props;
|
|
13
|
+
}>;
|
|
14
|
+
/** Callback */
|
|
15
|
+
onObjectPicked?: (info: PickInfo) => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Helper class for using the new picking module
|
|
19
|
+
* @todo Port to WebGPU
|
|
20
|
+
* @todo Support multiple models
|
|
21
|
+
* @todo Switching picking module
|
|
22
|
+
*/
|
|
23
|
+
export declare class PickingManager {
|
|
24
|
+
device: Device;
|
|
25
|
+
props: Required<PickingManagerProps>;
|
|
26
|
+
/** Info from latest pick operation */
|
|
27
|
+
pickInfo: PickInfo;
|
|
28
|
+
/** Framebuffer used for picking */
|
|
29
|
+
framebuffer: Framebuffer | null;
|
|
30
|
+
static defaultProps: Required<PickingManagerProps>;
|
|
31
|
+
constructor(device: Device, props: PickingManagerProps);
|
|
32
|
+
destroy(): void;
|
|
33
|
+
getFramebuffer(): Framebuffer;
|
|
34
|
+
/** Clear highlighted / picked object */
|
|
35
|
+
clearPickState(): void;
|
|
36
|
+
/** Prepare for rendering picking colors */
|
|
37
|
+
beginRenderPass(): import("@luma.gl/core").RenderPass;
|
|
38
|
+
getPickInfo(mousePosition: [number, number]): PickInfo | null;
|
|
39
|
+
/**
|
|
40
|
+
* Get pick position in device pixel range
|
|
41
|
+
* use the center pixel location in device pixel range
|
|
42
|
+
*/
|
|
43
|
+
getPickPosition(mousePosition: number[]): [number, number];
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=picking-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-manager.d.ts","sourceRoot":"","sources":["../../../src/modules/picking/picking-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,+BAA4B;AACjD,OAAO,EAAC,eAAe,EAAgB,8BAA2B;AAGlE,sCAAsC;AACtC,MAAM,MAAM,QAAQ,GAAG;IACrB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,wCAAwC;IACxC,YAAY,CAAC,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,OAAO,eAAe,CAAC,KAAK,CAAA;KAAC,CAAC,CAAC;IACrE,eAAe;IACf,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACrC,sCAAsC;IACtC,QAAQ,EAAE,QAAQ,CAAyC;IAC3D,mCAAmC;IACnC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAQ;IAEvC,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,mBAAmB,CAAC,CAGhD;gBAEU,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB;IAKtD,OAAO;IAKP,cAAc;IAUd,wCAAwC;IACxC,cAAc;IAId,2CAA2C;IAC3C,eAAe;IAef,WAAW,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,QAAQ,GAAG,IAAI;IA4C7D;;;OAGG;IACH,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAM3D"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { INVALID_INDEX } from "./picking-uniforms.js";
|
|
5
|
+
/**
|
|
6
|
+
* Helper class for using the new picking module
|
|
7
|
+
* @todo Port to WebGPU
|
|
8
|
+
* @todo Support multiple models
|
|
9
|
+
* @todo Switching picking module
|
|
10
|
+
*/
|
|
11
|
+
export class PickingManager {
|
|
12
|
+
device;
|
|
13
|
+
props;
|
|
14
|
+
/** Info from latest pick operation */
|
|
15
|
+
pickInfo = { batchIndex: null, objectIndex: null };
|
|
16
|
+
/** Framebuffer used for picking */
|
|
17
|
+
framebuffer = null;
|
|
18
|
+
static defaultProps = {
|
|
19
|
+
shaderInputs: undefined,
|
|
20
|
+
onObjectPicked: () => { }
|
|
21
|
+
};
|
|
22
|
+
constructor(device, props) {
|
|
23
|
+
this.device = device;
|
|
24
|
+
this.props = { ...PickingManager.defaultProps, ...props };
|
|
25
|
+
}
|
|
26
|
+
destroy() {
|
|
27
|
+
this.framebuffer?.destroy();
|
|
28
|
+
}
|
|
29
|
+
// TODO - Ask for a cached framebuffer? a Framebuffer factory?
|
|
30
|
+
getFramebuffer() {
|
|
31
|
+
if (!this.framebuffer) {
|
|
32
|
+
this.framebuffer = this.device.createFramebuffer({
|
|
33
|
+
colorAttachments: ['rgba8unorm', 'rg32sint'],
|
|
34
|
+
depthStencilAttachment: 'depth24plus'
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return this.framebuffer;
|
|
38
|
+
}
|
|
39
|
+
/** Clear highlighted / picked object */
|
|
40
|
+
clearPickState() {
|
|
41
|
+
this.props.shaderInputs.setProps({ picking: { highlightedObjectIndex: null } });
|
|
42
|
+
}
|
|
43
|
+
/** Prepare for rendering picking colors */
|
|
44
|
+
beginRenderPass() {
|
|
45
|
+
const framebuffer = this.getFramebuffer();
|
|
46
|
+
framebuffer.resize(this.device.getDefaultCanvasContext().getPixelSize());
|
|
47
|
+
this.props.shaderInputs?.setProps({ picking: { isActive: true } });
|
|
48
|
+
const pickingPass = this.device.beginRenderPass({
|
|
49
|
+
framebuffer,
|
|
50
|
+
clearColors: [new Float32Array([0, 0, 0, 0]), new Int32Array([-1, -1, 0, 0])],
|
|
51
|
+
clearDepth: 1
|
|
52
|
+
});
|
|
53
|
+
return pickingPass;
|
|
54
|
+
}
|
|
55
|
+
getPickInfo(mousePosition) {
|
|
56
|
+
const framebuffer = this.getFramebuffer();
|
|
57
|
+
// use the center pixel location in device pixel range
|
|
58
|
+
const [pickX, pickY] = this.getPickPosition(mousePosition);
|
|
59
|
+
// Read back
|
|
60
|
+
const pixelData = this.device.readPixelsToArrayWebGL(framebuffer, {
|
|
61
|
+
sourceX: pickX,
|
|
62
|
+
sourceY: pickY,
|
|
63
|
+
sourceWidth: 1,
|
|
64
|
+
sourceHeight: 1,
|
|
65
|
+
sourceAttachment: 1
|
|
66
|
+
});
|
|
67
|
+
if (!pixelData) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const pickInfo = {
|
|
71
|
+
objectIndex: pixelData[0] === INVALID_INDEX ? null : pixelData[0],
|
|
72
|
+
batchIndex: pixelData[1] === INVALID_INDEX ? null : pixelData[1]
|
|
73
|
+
};
|
|
74
|
+
// Call callback if picked object has changed
|
|
75
|
+
if (pickInfo.objectIndex !== this.pickInfo.objectIndex ||
|
|
76
|
+
pickInfo.batchIndex !== this.pickInfo.batchIndex) {
|
|
77
|
+
this.pickInfo = pickInfo;
|
|
78
|
+
this.props.onObjectPicked(pickInfo);
|
|
79
|
+
// console.log(`Object ${pickInfo.objectIndex} in batch ${pickInfo.batchIndex} was picked`)
|
|
80
|
+
}
|
|
81
|
+
this.props.shaderInputs?.setProps({
|
|
82
|
+
picking: {
|
|
83
|
+
isActive: false,
|
|
84
|
+
highlightedBatchIndex: pickInfo.batchIndex,
|
|
85
|
+
highlightedObjectIndex: pickInfo.objectIndex
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return this.pickInfo;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get pick position in device pixel range
|
|
92
|
+
* use the center pixel location in device pixel range
|
|
93
|
+
*/
|
|
94
|
+
getPickPosition(mousePosition) {
|
|
95
|
+
const devicePixels = this.device.getDefaultCanvasContext().cssToDevicePixels(mousePosition);
|
|
96
|
+
const pickX = devicePixels.x + Math.floor(devicePixels.width / 2);
|
|
97
|
+
const pickY = devicePixels.y + Math.floor(devicePixels.height / 2);
|
|
98
|
+
return [pickX, pickY];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=picking-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-manager.js","sourceRoot":"","sources":["../../../src/modules/picking/picking-manager.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAkB,aAAa,EAAC,8BAA2B;AAgBlE;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACzB,MAAM,CAAS;IACf,KAAK,CAAgC;IACrC,sCAAsC;IACtC,QAAQ,GAAa,EAAC,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;IAC3D,mCAAmC;IACnC,WAAW,GAAuB,IAAI,CAAC;IAEvC,MAAM,CAAC,YAAY,GAAkC;QACnD,YAAY,EAAE,SAAU;QACxB,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;KACzB,CAAC;IAEF,YAAY,MAAc,EAAE,KAA0B;QACpD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,EAAC,GAAG,cAAc,CAA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AAW;aAC7C;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,aAAuB;QACrC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAC5F,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { NumberArray4 } from '@math.gl/types';
|
|
2
|
+
export declare const INVALID_INDEX = -1;
|
|
3
|
+
/**
|
|
4
|
+
* Props for the picking module, which depending on mode renders picking colors or highlighted item.
|
|
5
|
+
* When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer.
|
|
6
|
+
* When inactive, renders normal colors, with the exception of selected object which is rendered with highlight
|
|
7
|
+
* can distinguish between 2^32 different objects in each of 2^32 different batches.
|
|
8
|
+
*/
|
|
9
|
+
export type PickingProps = {
|
|
10
|
+
/** Are we picking? I.e. rendering picking colors? */
|
|
11
|
+
isActive?: boolean;
|
|
12
|
+
/** Whether to use instance_index (built-in) or a custom application supplied index (usually from an attribute) */
|
|
13
|
+
indexMode?: 'instance' | 'custom';
|
|
14
|
+
/** Batch index (used when rendering multiple models to identify which model was picked), defaults to 0 */
|
|
15
|
+
batchIndex?: number;
|
|
16
|
+
/** Index of the highlighted batch, defaults to 0 */
|
|
17
|
+
highlightedBatchIndex?: number | null;
|
|
18
|
+
/** Set an index to highlight that item, or `null` to explicitly clear **/
|
|
19
|
+
highlightedObjectIndex?: number | null;
|
|
20
|
+
/** Color of visual highlight of "selected" item () */
|
|
21
|
+
highlightColor?: NumberArray4;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Uniforms for the picking module, which renders picking colors and highlighted item.
|
|
25
|
+
* When active, renders picking colors, assumed to be rendered to off-screen "picking" buffer.
|
|
26
|
+
* When inactive, renders normal colors, with the exception of selected object which is rendered with highlight
|
|
27
|
+
*/
|
|
28
|
+
export type PickingUniforms = {
|
|
29
|
+
/**
|
|
30
|
+
* When true, renders picking colors. Set when rendering to off-screen "picking" buffer.
|
|
31
|
+
* When false, renders normal colors, with the exception of selected object which is rendered with highlight
|
|
32
|
+
*/
|
|
33
|
+
isActive: boolean;
|
|
34
|
+
/** Set to true when picking an attribute value instead of object index */
|
|
35
|
+
indexMode: 0 | 1;
|
|
36
|
+
/** Index of batch currently being rendered */
|
|
37
|
+
batchIndex: number;
|
|
38
|
+
/** Do we have a highlighted item? */
|
|
39
|
+
isHighlightActive: boolean;
|
|
40
|
+
/** Color of visual highlight of "selected" item. Note: RGBA components must in the range 0-1 */
|
|
41
|
+
highlightColor: NumberArray4;
|
|
42
|
+
/** Indicates which batch to visually highlight an item in (defaults to 0) */
|
|
43
|
+
highlightedBatchIndex: number;
|
|
44
|
+
/** Indicates which index in the batch to highlight an item in */
|
|
45
|
+
highlightedObjectIndex: number;
|
|
46
|
+
};
|
|
47
|
+
export type PickingBindings = {};
|
|
48
|
+
export declare const GLSL_UNIFORMS = "precision highp float;\nprecision highp int;\n\nuniform pickingUniforms {\n int isActive;\n int indexMode;\n int batchIndex;\n\n int isHighlightActive;\n int highlightedBatchIndex;\n int highlightedObjectIndex;\n vec4 highlightColor;\n} picking;\n";
|
|
49
|
+
export declare const WGSL_UNIFORMS = "struct pickingUniforms {\n isActive: int32;\n indexMode: int32;\n batchIndex: int32;\n\n isHighlightActive: int32;\n highlightedBatchIndex: int32;\n highlightedObjectIndex: int32;\n highlightColor: vec4<f32>;\n} picking;\n";
|
|
50
|
+
declare function getUniforms(props?: PickingProps, prevUniforms?: PickingUniforms): PickingUniforms;
|
|
51
|
+
/**
|
|
52
|
+
* Provides support for color-based picking and highlighting.
|
|
53
|
+
*
|
|
54
|
+
* In particular, supports picking a specific instance in an instanced
|
|
55
|
+
* draw call and highlighting an instance based on its picking color,
|
|
56
|
+
* and correspondingly, supports picking and highlighting groups of
|
|
57
|
+
* primitives with the same picking color in non-instanced draw-calls
|
|
58
|
+
*
|
|
59
|
+
* @note Color based picking has the significant advantage in that it can be added to any
|
|
60
|
+
* existing shader without requiring any additional picking logic.
|
|
61
|
+
*/
|
|
62
|
+
export declare const pickingUniforms: {
|
|
63
|
+
readonly props: PickingProps;
|
|
64
|
+
readonly uniforms: PickingUniforms;
|
|
65
|
+
readonly name: "picking";
|
|
66
|
+
readonly uniformTypes: Required<import("modules/shadertools/dist/lib/utils/uniform-types").UniformTypes<PickingUniforms>>;
|
|
67
|
+
readonly defaultUniforms: {
|
|
68
|
+
readonly isActive: false;
|
|
69
|
+
readonly indexMode: 0;
|
|
70
|
+
readonly batchIndex: 0;
|
|
71
|
+
readonly isHighlightActive: true;
|
|
72
|
+
readonly highlightedBatchIndex: -1;
|
|
73
|
+
readonly highlightedObjectIndex: -1;
|
|
74
|
+
readonly highlightColor: NumberArray4;
|
|
75
|
+
};
|
|
76
|
+
readonly getUniforms: typeof getUniforms;
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=picking-uniforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-uniforms.d.ts","sourceRoot":"","sources":["../../../src/modules/picking/picking-uniforms.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAMjD,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kHAAkH;IAClH,SAAS,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IAClC,0GAA0G;IAC1G,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,oDAAoD;IACpD,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,0EAA0E;IAC1E,sBAAsB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,sDAAsD;IACtD,cAAc,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,0EAA0E;IAC1E,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IAEnB,qCAAqC;IACrC,iBAAiB,EAAE,OAAO,CAAC;IAC3B,gGAAgG;IAChG,cAAc,EAAE,YAAY,CAAC;IAC7B,6EAA6E;IAC7E,qBAAqB,EAAE,MAAM,CAAC;IAC9B,iEAAiE;IACjE,sBAAsB,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,EAAE,CAAC;AAejC,eAAO,MAAM,aAAa,mQAczB,CAAC;AAEF,eAAO,MAAM,aAAa,0OAWzB,CAAC;AAEF,iBAAS,WAAW,CAAC,KAAK,GAAE,YAAiB,EAAE,YAAY,CAAC,EAAE,eAAe,GAAG,eAAe,CA2C9F;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe;oBACb,YAAY;uBACT,eAAe;;;;;;;;;;;;;CAgBgD,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
/** Default color for auto highlight, a cyan color */
|
|
5
|
+
const DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
|
|
6
|
+
export const INVALID_INDEX = -1;
|
|
7
|
+
// GLSL_UNIFORMS
|
|
8
|
+
const uniformTypes = {
|
|
9
|
+
isActive: 'i32',
|
|
10
|
+
indexMode: 'i32',
|
|
11
|
+
batchIndex: 'i32',
|
|
12
|
+
isHighlightActive: 'i32',
|
|
13
|
+
highlightedBatchIndex: 'i32',
|
|
14
|
+
highlightedObjectIndex: 'i32',
|
|
15
|
+
highlightColor: 'vec4<f32>'
|
|
16
|
+
};
|
|
17
|
+
export const GLSL_UNIFORMS = /* glsl */ `\
|
|
18
|
+
precision highp float;
|
|
19
|
+
precision highp int;
|
|
20
|
+
|
|
21
|
+
uniform pickingUniforms {
|
|
22
|
+
int isActive;
|
|
23
|
+
int indexMode;
|
|
24
|
+
int batchIndex;
|
|
25
|
+
|
|
26
|
+
int isHighlightActive;
|
|
27
|
+
int highlightedBatchIndex;
|
|
28
|
+
int highlightedObjectIndex;
|
|
29
|
+
vec4 highlightColor;
|
|
30
|
+
} picking;
|
|
31
|
+
`;
|
|
32
|
+
export const WGSL_UNIFORMS = /* wgsl */ `\
|
|
33
|
+
struct pickingUniforms {
|
|
34
|
+
isActive: int32;
|
|
35
|
+
indexMode: int32;
|
|
36
|
+
batchIndex: int32;
|
|
37
|
+
|
|
38
|
+
isHighlightActive: int32;
|
|
39
|
+
highlightedBatchIndex: int32;
|
|
40
|
+
highlightedObjectIndex: int32;
|
|
41
|
+
highlightColor: vec4<f32>;
|
|
42
|
+
} picking;
|
|
43
|
+
`;
|
|
44
|
+
function getUniforms(props = {}, prevUniforms) {
|
|
45
|
+
const uniforms = { ...prevUniforms };
|
|
46
|
+
// picking
|
|
47
|
+
if (props.isActive !== undefined) {
|
|
48
|
+
uniforms.isActive = Boolean(props.isActive);
|
|
49
|
+
}
|
|
50
|
+
switch (props.indexMode) {
|
|
51
|
+
case 'instance':
|
|
52
|
+
uniforms.indexMode = 0;
|
|
53
|
+
break;
|
|
54
|
+
case 'custom':
|
|
55
|
+
uniforms.indexMode = 1;
|
|
56
|
+
break;
|
|
57
|
+
case undefined:
|
|
58
|
+
// no change
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
switch (props.highlightedObjectIndex) {
|
|
62
|
+
case undefined:
|
|
63
|
+
// Unless highlightedObjectColor explicitly null or set, do not update state
|
|
64
|
+
break;
|
|
65
|
+
case null:
|
|
66
|
+
// Clear highlight
|
|
67
|
+
uniforms.isHighlightActive = false;
|
|
68
|
+
uniforms.highlightedObjectIndex = INVALID_INDEX;
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
uniforms.isHighlightActive = true;
|
|
72
|
+
uniforms.highlightedObjectIndex = props.highlightedObjectIndex;
|
|
73
|
+
}
|
|
74
|
+
if (typeof props.highlightedBatchIndex === 'number') {
|
|
75
|
+
uniforms.highlightedBatchIndex = props.highlightedBatchIndex;
|
|
76
|
+
}
|
|
77
|
+
if (props.highlightColor) {
|
|
78
|
+
uniforms.highlightColor = props.highlightColor;
|
|
79
|
+
}
|
|
80
|
+
return uniforms;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Provides support for color-based picking and highlighting.
|
|
84
|
+
*
|
|
85
|
+
* In particular, supports picking a specific instance in an instanced
|
|
86
|
+
* draw call and highlighting an instance based on its picking color,
|
|
87
|
+
* and correspondingly, supports picking and highlighting groups of
|
|
88
|
+
* primitives with the same picking color in non-instanced draw-calls
|
|
89
|
+
*
|
|
90
|
+
* @note Color based picking has the significant advantage in that it can be added to any
|
|
91
|
+
* existing shader without requiring any additional picking logic.
|
|
92
|
+
*/
|
|
93
|
+
export const pickingUniforms = {
|
|
94
|
+
props: {},
|
|
95
|
+
uniforms: {},
|
|
96
|
+
name: 'picking',
|
|
97
|
+
uniformTypes,
|
|
98
|
+
defaultUniforms: {
|
|
99
|
+
isActive: false,
|
|
100
|
+
indexMode: 0,
|
|
101
|
+
batchIndex: 0,
|
|
102
|
+
isHighlightActive: true,
|
|
103
|
+
highlightedBatchIndex: INVALID_INDEX,
|
|
104
|
+
highlightedObjectIndex: INVALID_INDEX,
|
|
105
|
+
highlightColor: DEFAULT_HIGHLIGHT_COLOR
|
|
106
|
+
},
|
|
107
|
+
getUniforms
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=picking-uniforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"picking-uniforms.js","sourceRoot":"","sources":["../../../src/modules/picking/picking-uniforms.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,qDAAqD;AACrD,MAAM,uBAAuB,GAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,CAAC;AAoDhC,gBAAgB;AAEhB,MAAM,YAAY,GAA0E;IAC1F,QAAQ,EAAE,KAAK;IACf,SAAS,EAAE,KAAK;IAChB,UAAU,EAAE,KAAK;IAEjB,iBAAiB,EAAE,KAAK;IACxB,qBAAqB,EAAE,KAAK;IAC5B,sBAAsB,EAAE,KAAK;IAC7B,cAAc,EAAE,WAAW;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;;;;;;;;;;;;;;CAcvC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;;;;;;;;;;;CAWvC,CAAC;AAEF,SAAS,WAAW,CAAC,QAAsB,EAAE,EAAE,YAA8B;IAC3E,MAAM,QAAQ,GAAG,EAAC,GAAG,YAAY,EAAoB,CAAC;IAEtD,UAAU;IACV,IAAI,KAAK,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QACjC,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ,KAAK,CAAC,SAAS,EAAE,CAAC;QACxB,KAAK,UAAU;YACb,QAAQ,CAAC,SAAS,GAAG,CA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
|
+
* Gets fragment shader source for a shader pass sub pass
|
|
4
|
+
* @param options
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function getFragmentShaderForRenderPass(options: {
|
|
8
|
+
shaderPass: ShaderPass;
|
|
9
|
+
action: 'filter' | 'sample';
|
|
10
|
+
shadingLanguage: 'wgsl' | 'glsl';
|
|
11
|
+
}): string;
|
|
12
|
+
//# sourceMappingURL=get-fragment-shader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-fragment-shader.d.ts","sourceRoot":"","sources":["../../src/passes/get-fragment-shader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE;IACtD,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC;CAClC,GAAG,MAAM,CAkBT"}
|