@playcanvas/inspector 0.1.0
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/LICENSE +19 -0
- package/README.md +110 -0
- package/package.json +62 -0
- package/src/asset-usage.js +108 -0
- package/src/asset-view.js +370 -0
- package/src/camera-view.js +128 -0
- package/src/debug.js +31 -0
- package/src/describe.js +302 -0
- package/src/entity-inspector-script.js +130 -0
- package/src/frame-graph-view.js +767 -0
- package/src/hierarchy-view.js +475 -0
- package/src/index.js +4 -0
- package/src/input/fly-controller.js +116 -0
- package/src/input/input.js +299 -0
- package/src/input/math.js +8 -0
- package/src/input/orbit-controller.js +158 -0
- package/src/input/pose.js +207 -0
- package/src/inspector.js +3293 -0
- package/src/instance-survey.js +50 -0
- package/src/list-view.js +410 -0
- package/src/material-view.js +197 -0
- package/src/memory-view.js +344 -0
- package/src/mesh-view.js +235 -0
- package/src/model.js +170 -0
- package/src/node-model.js +404 -0
- package/src/physics-debug.js +527 -0
- package/src/physics-view.js +314 -0
- package/src/picker/picker.js +545 -0
- package/src/picker/render-pass-picker.js +206 -0
- package/src/property-view.js +628 -0
- package/src/render-target-view.js +288 -0
- package/src/renderers/texture-renderer-shaders.js +139 -0
- package/src/renderers/texture-renderer.js +430 -0
- package/src/renderers/wire-renderer.js +954 -0
- package/src/script-view.js +288 -0
- package/src/shader-view.js +287 -0
- package/src/styles.js +918 -0
- package/src/texture-view.js +186 -0
- package/src/tooltip.js +72 -0
- package/src/viewport-tools.js +695 -0
- package/types/asset-usage.d.ts +23 -0
- package/types/asset-view.d.ts +94 -0
- package/types/camera-view.d.ts +45 -0
- package/types/debug.d.ts +14 -0
- package/types/describe.d.ts +43 -0
- package/types/entity-inspector-script.d.ts +87 -0
- package/types/frame-graph-view.d.ts +155 -0
- package/types/hierarchy-view.d.ts +172 -0
- package/types/index.d.ts +3 -0
- package/types/input/fly-controller.d.ts +42 -0
- package/types/input/input.d.ts +192 -0
- package/types/input/math.d.ts +1 -0
- package/types/input/orbit-controller.d.ts +63 -0
- package/types/input/pose.d.ts +126 -0
- package/types/inspector.d.ts +1304 -0
- package/types/instance-survey.d.ts +35 -0
- package/types/list-view.d.ts +151 -0
- package/types/material-view.d.ts +63 -0
- package/types/memory-view.d.ts +95 -0
- package/types/mesh-view.d.ts +89 -0
- package/types/model.d.ts +104 -0
- package/types/node-model.d.ts +54 -0
- package/types/physics-debug.d.ts +254 -0
- package/types/physics-view.d.ts +81 -0
- package/types/picker/picker.d.ts +255 -0
- package/types/picker/render-pass-picker.d.ts +47 -0
- package/types/property-view.d.ts +189 -0
- package/types/render-target-view.d.ts +98 -0
- package/types/renderers/texture-renderer-shaders.d.ts +9 -0
- package/types/renderers/texture-renderer.d.ts +231 -0
- package/types/renderers/wire-renderer.d.ts +347 -0
- package/types/script-view.d.ts +56 -0
- package/types/shader-view.d.ts +46 -0
- package/types/styles.d.ts +22 -0
- package/types/texture-view.d.ts +30 -0
- package/types/tooltip.d.ts +17 -0
- package/types/viewport-tools.d.ts +237 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draws the state of the Ammo dynamics world through Bullet's own debug drawer, so what you see is
|
|
3
|
+
* exactly what the physics engine simulates: compound and mesh shapes, contact points, joints.
|
|
4
|
+
*
|
|
5
|
+
* Bullet hands over every line as a pair of `btVector3` pointers. Those are read straight out of
|
|
6
|
+
* the Ammo heap into a growing pair of typed arrays, so a frame of thousands of lines allocates
|
|
7
|
+
* nothing, and the whole batch is submitted with one {@link WireRenderer#linesPacked} call.
|
|
8
|
+
*
|
|
9
|
+
* Contact points arrive during the physics step rather than from `debugDrawWorld`, so lines are
|
|
10
|
+
* accumulated across the frame and only reset once {@link AmmoDebugDraw#update} has drawn them.
|
|
11
|
+
*
|
|
12
|
+
* Usable on its own:
|
|
13
|
+
*
|
|
14
|
+
* ```javascript
|
|
15
|
+
* const physicsDebug = new AmmoDebugDraw(app);
|
|
16
|
+
* physicsDebug.enabled = true;
|
|
17
|
+
* physicsDebug.mode = DEBUG_DRAW.WIREFRAME | DEBUG_DRAW.CONTACT_POINTS;
|
|
18
|
+
* app.on('update', () => physicsDebug.update()); // fires after the physics step
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @ignore
|
|
22
|
+
*/
|
|
23
|
+
export class AmmoDebugDraw {
|
|
24
|
+
/**
|
|
25
|
+
* Whether a debug drawer can be attached right now: Ammo is loaded with `DebugDrawer` support
|
|
26
|
+
* and the rigid body system has created its world.
|
|
27
|
+
*
|
|
28
|
+
* @param {AppBase} app - The app.
|
|
29
|
+
* @returns {boolean} True when {@link attach} would succeed.
|
|
30
|
+
*/
|
|
31
|
+
static isAvailable(app: Vec3): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @param {AppBase} app - The app.
|
|
34
|
+
* @param {WireRenderer} [wire] - The renderer to draw through. Defaults to a new one.
|
|
35
|
+
*/
|
|
36
|
+
constructor(app: Vec3, wire?: WireRenderer);
|
|
37
|
+
/**
|
|
38
|
+
* The app whose rigid body system is drawn.
|
|
39
|
+
*
|
|
40
|
+
* @type {AppBase}
|
|
41
|
+
*/
|
|
42
|
+
app: Vec3;
|
|
43
|
+
/**
|
|
44
|
+
* The renderer the lines go through. Its layer and depth test are applied on every flush from
|
|
45
|
+
* {@link depthTest} and {@link layer}.
|
|
46
|
+
*
|
|
47
|
+
* @type {WireRenderer}
|
|
48
|
+
*/
|
|
49
|
+
wire: WireRenderer;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the world is drawn. While off, {@link mode} still applies its simulation flags such
|
|
52
|
+
* as {@link DEBUG_DRAW.NO_DEACTIVATION}.
|
|
53
|
+
*
|
|
54
|
+
* @type {boolean}
|
|
55
|
+
*/
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* A combination of {@link DEBUG_DRAW} flags.
|
|
59
|
+
*
|
|
60
|
+
* @type {number}
|
|
61
|
+
*/
|
|
62
|
+
mode: number;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the lines are depth tested against the scene. Off shows the physics world through
|
|
65
|
+
* the geometry.
|
|
66
|
+
*
|
|
67
|
+
* @type {boolean}
|
|
68
|
+
*/
|
|
69
|
+
depthTest: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The layer to draw into, or null for the immediate layer.
|
|
72
|
+
*
|
|
73
|
+
* @type {Layer|null}
|
|
74
|
+
*/
|
|
75
|
+
layer: Vec3 | null;
|
|
76
|
+
/**
|
|
77
|
+
* Only lines within this distance of {@link center} are drawn, in meters. Zero draws everything.
|
|
78
|
+
*
|
|
79
|
+
* @type {number}
|
|
80
|
+
*/
|
|
81
|
+
range: number;
|
|
82
|
+
/**
|
|
83
|
+
* The point {@link range} is measured from, typically the camera position.
|
|
84
|
+
*
|
|
85
|
+
* @type {Vec3|null}
|
|
86
|
+
*/
|
|
87
|
+
center: Vec3 | null;
|
|
88
|
+
/**
|
|
89
|
+
* When culling by range, drop lines with only one end in range instead of keeping them.
|
|
90
|
+
*
|
|
91
|
+
* @type {boolean}
|
|
92
|
+
*/
|
|
93
|
+
cullPartial: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Overrides the colors Bullet assigns, which encode the activation state. Null keeps them.
|
|
96
|
+
*
|
|
97
|
+
* @type {Color|null}
|
|
98
|
+
*/
|
|
99
|
+
color: Vec3 | null;
|
|
100
|
+
/**
|
|
101
|
+
* The number of line segments drawn by the last {@link update}.
|
|
102
|
+
*
|
|
103
|
+
* @type {number}
|
|
104
|
+
*/
|
|
105
|
+
lineCount: number;
|
|
106
|
+
/**
|
|
107
|
+
* The number of line segments dropped by range culling in the last {@link update}.
|
|
108
|
+
*
|
|
109
|
+
* @type {number}
|
|
110
|
+
*/
|
|
111
|
+
culledCount: number;
|
|
112
|
+
/** @private */
|
|
113
|
+
private _positions;
|
|
114
|
+
/** @private */
|
|
115
|
+
private _colors;
|
|
116
|
+
/** @private */
|
|
117
|
+
private _count;
|
|
118
|
+
/** @private */
|
|
119
|
+
private _culled;
|
|
120
|
+
/**
|
|
121
|
+
* @type {any}
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
private _drawer;
|
|
125
|
+
/**
|
|
126
|
+
* @type {any}
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
private _world;
|
|
130
|
+
/**
|
|
131
|
+
* Native bodies excluded from the drawing, see {@link hideBody}.
|
|
132
|
+
*
|
|
133
|
+
* @type {Set<any>}
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
private _hiddenBodies;
|
|
137
|
+
/**
|
|
138
|
+
* Whether a debug drawer is currently installed on the world.
|
|
139
|
+
*
|
|
140
|
+
* @type {boolean}
|
|
141
|
+
*/
|
|
142
|
+
get attached(): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Installs the debug drawer on the dynamics world. Called on demand by {@link update}.
|
|
145
|
+
*
|
|
146
|
+
* @returns {boolean} False when Ammo or the world is not available.
|
|
147
|
+
*/
|
|
148
|
+
attach(): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Removes the debug drawer from the world and frees it.
|
|
151
|
+
*/
|
|
152
|
+
detach(): void;
|
|
153
|
+
/**
|
|
154
|
+
* Excludes a body from the drawing by flagging it for Bullet. The flag is re-applied every
|
|
155
|
+
* frame, as the engine rewrites collision flags when it rebuilds a body.
|
|
156
|
+
*
|
|
157
|
+
* @param {any} body - The native `btRigidBody`.
|
|
158
|
+
*/
|
|
159
|
+
hideBody(body: any): void;
|
|
160
|
+
/**
|
|
161
|
+
* Draws a body again after {@link hideBody}.
|
|
162
|
+
*
|
|
163
|
+
* @param {any} body - The native `btRigidBody`.
|
|
164
|
+
*/
|
|
165
|
+
showBody(body: any): void;
|
|
166
|
+
/**
|
|
167
|
+
* Drops a hidden body without touching it, for a body the engine has destroyed.
|
|
168
|
+
*
|
|
169
|
+
* @param {any} body - The native `btRigidBody`.
|
|
170
|
+
*/
|
|
171
|
+
forgetBody(body: any): void;
|
|
172
|
+
/**
|
|
173
|
+
* @param {any} body - The native `btRigidBody`.
|
|
174
|
+
* @returns {boolean} Whether the body is excluded from the drawing.
|
|
175
|
+
*/
|
|
176
|
+
isBodyHidden(body: any): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* @param {any} body - The native `btRigidBody`.
|
|
179
|
+
* @param {boolean} visible - Whether Bullet should draw it.
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
private _setVisualizeFlag;
|
|
183
|
+
/**
|
|
184
|
+
* Draws the world for this frame. Call once per frame after the physics step, for example from
|
|
185
|
+
* a script's `postUpdate`.
|
|
186
|
+
*/
|
|
187
|
+
update(): void;
|
|
188
|
+
/**
|
|
189
|
+
* Submits the accumulated lines and resets the buffers.
|
|
190
|
+
*
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
193
|
+
private _flush;
|
|
194
|
+
/**
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
private _releaseDrawer;
|
|
198
|
+
/**
|
|
199
|
+
* Reads a `btVector3` at a heap pointer.
|
|
200
|
+
*
|
|
201
|
+
* @param {number} ptr - The pointer.
|
|
202
|
+
* @param {Vec3} out - Receives the vector.
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
private _read;
|
|
206
|
+
/**
|
|
207
|
+
* @param {number} from - Pointer to the start point.
|
|
208
|
+
* @param {number} to - Pointer to the end point.
|
|
209
|
+
* @param {number} color - Pointer to the color.
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
private _drawLine;
|
|
213
|
+
/**
|
|
214
|
+
* Draws a contact as its normal plus a small cross at the point.
|
|
215
|
+
*
|
|
216
|
+
* @param {number} point - Pointer to the contact point on the second body.
|
|
217
|
+
* @param {number} normal - Pointer to the contact normal.
|
|
218
|
+
* @param {number} color - Pointer to the color.
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
private _drawContactPoint;
|
|
222
|
+
/**
|
|
223
|
+
* @param {Vec3} a - The start point.
|
|
224
|
+
* @param {Vec3} b - The end point.
|
|
225
|
+
* @param {Vec3} c - The color as rgb.
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
private _push;
|
|
229
|
+
/**
|
|
230
|
+
* @private
|
|
231
|
+
*/
|
|
232
|
+
private _grow;
|
|
233
|
+
}
|
|
234
|
+
/** @import { Color } from 'playcanvas' */
|
|
235
|
+
/** @import { AppBase } from 'playcanvas' */
|
|
236
|
+
/** @import { Layer } from 'playcanvas' */
|
|
237
|
+
/**
|
|
238
|
+
* Bullet's `btIDebugDraw` mode flags, combined into {@link AmmoDebugDraw#mode}.
|
|
239
|
+
*
|
|
240
|
+
* @ignore
|
|
241
|
+
* @type {{ WIREFRAME: number, AABB: number, CONTACT_POINTS: number, NO_DEACTIVATION: number,
|
|
242
|
+
* CONSTRAINTS: number, CONSTRAINT_LIMITS: number, NORMALS: number, FRAMES: number }}
|
|
243
|
+
*/
|
|
244
|
+
export const DEBUG_DRAW: {
|
|
245
|
+
WIREFRAME: number;
|
|
246
|
+
AABB: number;
|
|
247
|
+
CONTACT_POINTS: number;
|
|
248
|
+
NO_DEACTIVATION: number;
|
|
249
|
+
CONSTRAINTS: number;
|
|
250
|
+
CONSTRAINT_LIMITS: number;
|
|
251
|
+
NORMALS: number;
|
|
252
|
+
FRAMES: number;
|
|
253
|
+
};
|
|
254
|
+
import { WireRenderer } from './renderers/wire-renderer.js';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export type PhysicsStats = {
|
|
2
|
+
/**
|
|
3
|
+
* - Whether a rigid body component system is registered.
|
|
4
|
+
*/
|
|
5
|
+
system: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* - Whether the physics world exists, i.e. the backend is loaded.
|
|
8
|
+
*/
|
|
9
|
+
world: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* - The number of rigid body components.
|
|
12
|
+
*/
|
|
13
|
+
bodies: number;
|
|
14
|
+
/**
|
|
15
|
+
* - The number of awake dynamic bodies.
|
|
16
|
+
*/
|
|
17
|
+
active: number;
|
|
18
|
+
/**
|
|
19
|
+
* - The number of contact points in the last step.
|
|
20
|
+
*/
|
|
21
|
+
contacts: number;
|
|
22
|
+
/**
|
|
23
|
+
* - The number of joint components.
|
|
24
|
+
*/
|
|
25
|
+
joints: number;
|
|
26
|
+
/**
|
|
27
|
+
* - The CPU time of the last physics step, in milliseconds.
|
|
28
|
+
*/
|
|
29
|
+
time: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* One row per rigid body: a checkbox that excludes the body from the debug drawing, name linking
|
|
33
|
+
* to the entity, type, shape, mass, and state with the speed of awake bodies. Sleeping and
|
|
34
|
+
* disabled bodies are dimmed.
|
|
35
|
+
*
|
|
36
|
+
* @param {AppBase} app - The app.
|
|
37
|
+
* @param {{ has: (entity: Entity) => boolean }} hidden - The bodies excluded from the drawing.
|
|
38
|
+
* @param {boolean} drawing - Whether the world is drawn at all; the checkboxes are disabled otherwise.
|
|
39
|
+
* @returns {ListRow[]} The rows.
|
|
40
|
+
*/
|
|
41
|
+
export function bodyRows(app: BODYTYPE_DYNAMIC, hidden: {
|
|
42
|
+
has: (entity: BODYTYPE_DYNAMIC) => boolean;
|
|
43
|
+
}, drawing: boolean): ListRow[];
|
|
44
|
+
/**
|
|
45
|
+
* Outlines an entity's primitive collision shape where the physics engine has it: at the entity's
|
|
46
|
+
* position and rotation with the component's offsets applied, ignoring the entity scale as
|
|
47
|
+
* primitive shapes do.
|
|
48
|
+
*
|
|
49
|
+
* @param {WireRenderer} wire - The renderer to draw with. Its color and depth test are used as set.
|
|
50
|
+
* @param {Entity} entity - The entity.
|
|
51
|
+
* @returns {boolean} False when the entity has no primitive collision shape to outline.
|
|
52
|
+
*/
|
|
53
|
+
export function drawCollisionShape(wire: WireRenderer, entity: BODYTYPE_DYNAMIC): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Outlines a joint. The joint entity's own frame is drawn as axes, and for each connected body the
|
|
56
|
+
* joint frame the constraint was created with is drawn where that body currently carries it: axes
|
|
57
|
+
* at the anchor (red is the primary joint axis, green the secondary), a line from the body's center
|
|
58
|
+
* to the anchor, and a line from the joint entity to the anchor. Where the two anchor frames have
|
|
59
|
+
* drifted apart, the constraint is being violated by that much.
|
|
60
|
+
*
|
|
61
|
+
* @param {WireRenderer} wire - The renderer to draw with. Its color and depth test are used as set.
|
|
62
|
+
* @param {Entity} entity - The entity carrying the joint component.
|
|
63
|
+
* @param {number} size - The axis length.
|
|
64
|
+
* @returns {boolean} False when the entity has no joint component.
|
|
65
|
+
*/
|
|
66
|
+
export function drawJoint(wire: WireRenderer, entity: BODYTYPE_DYNAMIC, size: number): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* One row per joint: name linking to the entity, the joint type, the two bodies it connects as
|
|
69
|
+
* links, and whether it has broken. Joints without a second body are attached to the world.
|
|
70
|
+
*
|
|
71
|
+
* @param {AppBase} app - The app.
|
|
72
|
+
* @returns {ListRow[]} The rows.
|
|
73
|
+
*/
|
|
74
|
+
export function jointRows(app: BODYTYPE_DYNAMIC): ListRow[];
|
|
75
|
+
/**
|
|
76
|
+
* @param {AppBase} app - The app.
|
|
77
|
+
* @returns {PhysicsStats} Counts for the status bar.
|
|
78
|
+
*/
|
|
79
|
+
export function physicsStats(app: BODYTYPE_DYNAMIC): PhysicsStats;
|
|
80
|
+
import type { ListRow } from './list-view.js';
|
|
81
|
+
import type { WireRenderer } from './renderers/wire-renderer.js';
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Picker object used to select mesh instances from screen coordinates. It can also optionally
|
|
3
|
+
* capture depth information to determine world positions of picked points.
|
|
4
|
+
*
|
|
5
|
+
* The picker works by rendering mesh instances to an offscreen render target with unique IDs
|
|
6
|
+
* encoded as colors. When queried, it reads back the pixel data to identify which mesh instance
|
|
7
|
+
* was at the specified screen coordinates. If depth picking is enabled, it also captures depth
|
|
8
|
+
* values to compute world positions.
|
|
9
|
+
*
|
|
10
|
+
* **Main API methods:**
|
|
11
|
+
* - {@link prepare} - Renders the pick buffer (call once per frame before picking)
|
|
12
|
+
* - {@link getSelectionAsync} - Get mesh instances in a screen area
|
|
13
|
+
* - {@link getWorldPointAsync} - Get world position at screen coordinates (requires depth)
|
|
14
|
+
*
|
|
15
|
+
* **Performance considerations:**
|
|
16
|
+
* The picker resolution can be set lower than the screen resolution for better performance,
|
|
17
|
+
* though this reduces picking precision and may miss small objects.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Create a picker with depth picking enabled at quarter resolution
|
|
21
|
+
* const picker = new Picker(app, canvas.width * 0.25, canvas.height * 0.25, true);
|
|
22
|
+
*
|
|
23
|
+
* // In your update loop, prepare the picker
|
|
24
|
+
* picker.resize(canvas.width * 0.25, canvas.height * 0.25);
|
|
25
|
+
* picker.prepare(camera, scene);
|
|
26
|
+
*
|
|
27
|
+
* // Pick mesh instances in an area
|
|
28
|
+
* picker.getSelectionAsync(x, y, width, height).then((meshInstances) => {
|
|
29
|
+
* meshInstances.forEach((meshInstance) => {
|
|
30
|
+
* console.log('Picked:', meshInstance.node.name);
|
|
31
|
+
* });
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Pick world position (requires depth enabled)
|
|
35
|
+
* picker.getWorldPointAsync(x, y).then((worldPoint) => {
|
|
36
|
+
* if (worldPoint) {
|
|
37
|
+
* console.log(worldPoint);
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* @see {@link http://playcanvas.github.io/#/graphics/area-picker|Area Picker Example}
|
|
42
|
+
* @see {@link https://playcanvas.github.io/#gaussian-splatting/picking|Gaussian Splatting Picking Example}
|
|
43
|
+
*
|
|
44
|
+
* @category Graphics
|
|
45
|
+
*/
|
|
46
|
+
export class Picker {
|
|
47
|
+
/**
|
|
48
|
+
* Create a new Picker instance.
|
|
49
|
+
*
|
|
50
|
+
* @param {AppBase} app - The application managing this picker instance.
|
|
51
|
+
* @param {number} width - The width of the pick buffer in pixels.
|
|
52
|
+
* @param {number} height - The height of the pick buffer in pixels.
|
|
53
|
+
* @param {boolean} [depth] - Whether to enable depth picking. When enabled, depth
|
|
54
|
+
* information is captured alongside mesh IDs using MRT. Defaults to false.
|
|
55
|
+
*/
|
|
56
|
+
constructor(app: Color, width: number, height: number, depth?: boolean);
|
|
57
|
+
/**
|
|
58
|
+
* @type {import('playcanvas').GraphicsDevice}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private device;
|
|
62
|
+
/**
|
|
63
|
+
* @type {RenderPassPicker}
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
private renderPass;
|
|
67
|
+
/**
|
|
68
|
+
* @type {boolean}
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
private depth;
|
|
72
|
+
/** @type {number} */
|
|
73
|
+
width: number;
|
|
74
|
+
/** @type {number} */
|
|
75
|
+
height: number;
|
|
76
|
+
/**
|
|
77
|
+
* Internal render target.
|
|
78
|
+
*
|
|
79
|
+
* @type {RenderTarget|null}
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
private renderTarget;
|
|
83
|
+
/**
|
|
84
|
+
* Color buffer texture for pick IDs.
|
|
85
|
+
*
|
|
86
|
+
* @type {Texture|null}
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
private colorBuffer;
|
|
90
|
+
/**
|
|
91
|
+
* Optional depth buffer texture for depth picking.
|
|
92
|
+
*
|
|
93
|
+
* @type {Texture|null}
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
private depthBuffer;
|
|
97
|
+
/**
|
|
98
|
+
* Internal render target for reading the depth buffer.
|
|
99
|
+
*
|
|
100
|
+
* @type {RenderTarget|null}
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
private renderTargetDepth;
|
|
104
|
+
/**
|
|
105
|
+
* Mapping table from ids to MeshInstances or GSplatComponents.
|
|
106
|
+
*
|
|
107
|
+
* @type {Map<number, MeshInstance | GSplatComponent>}
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
110
|
+
private mapping;
|
|
111
|
+
/**
|
|
112
|
+
* When the device is destroyed, this allows us to ignore async results.
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
private deviceValid;
|
|
117
|
+
/**
|
|
118
|
+
* Frees resources associated with this picker.
|
|
119
|
+
*/
|
|
120
|
+
destroy(): void;
|
|
121
|
+
/**
|
|
122
|
+
* Return the list of mesh instances selected by the specified rectangle in the previously
|
|
123
|
+
* prepared pick buffer. The rectangle using top-left coordinate system.
|
|
124
|
+
*
|
|
125
|
+
* Note: This function is not supported on WebGPU. Use {@link getSelectionAsync} instead.
|
|
126
|
+
* Note: This function is blocks the main thread while reading pixels from GPU memory. It's
|
|
127
|
+
* recommended to use {@link getSelectionAsync} instead.
|
|
128
|
+
*
|
|
129
|
+
* @param {number} x - The left edge of the rectangle.
|
|
130
|
+
* @param {number} y - The top edge of the rectangle.
|
|
131
|
+
* @param {number} [width] - The width of the rectangle. Defaults to 1.
|
|
132
|
+
* @param {number} [height] - The height of the rectangle. Defaults to 1.
|
|
133
|
+
* @returns {(MeshInstance | GSplatComponent)[]} An array of mesh instances or gsplat components
|
|
134
|
+
* that are in the selection.
|
|
135
|
+
* @example
|
|
136
|
+
* // Get the selection at the point (10,20)
|
|
137
|
+
* const selection = picker.getSelection(10, 20);
|
|
138
|
+
* @example
|
|
139
|
+
* // Get all models in rectangle with corners at (10,20) and (20,40)
|
|
140
|
+
* const selection = picker.getSelection(10, 20, 10, 20);
|
|
141
|
+
*/
|
|
142
|
+
getSelection(x: number, y: number, width?: number, height?: number): (Color | Color)[];
|
|
143
|
+
/**
|
|
144
|
+
* Return the list of mesh instances selected by the specified rectangle in the previously
|
|
145
|
+
* prepared pick buffer. The rectangle uses top-left coordinate system.
|
|
146
|
+
*
|
|
147
|
+
* This method is asynchronous and does not block the execution.
|
|
148
|
+
*
|
|
149
|
+
* @param {number} x - The left edge of the rectangle.
|
|
150
|
+
* @param {number} y - The top edge of the rectangle.
|
|
151
|
+
* @param {number} [width] - The width of the rectangle. Defaults to 1.
|
|
152
|
+
* @param {number} [height] - The height of the rectangle. Defaults to 1.
|
|
153
|
+
* @returns {Promise<(MeshInstance | GSplatComponent)[]>} - Promise that resolves with an
|
|
154
|
+
* array of mesh instances or gsplat components that are in the selection.
|
|
155
|
+
* @example
|
|
156
|
+
* // Get the mesh instances at the rectangle with start at (10,20) and size of (5,5)
|
|
157
|
+
* picker.getSelectionAsync(10, 20, 5, 5).then((meshInstances) => {
|
|
158
|
+
* console.log(meshInstances);
|
|
159
|
+
* });
|
|
160
|
+
*/
|
|
161
|
+
getSelectionAsync(x: number, y: number, width?: number, height?: number): Promise<(Color | Color)[]>;
|
|
162
|
+
/**
|
|
163
|
+
* Helper method to read pixels from a texture asynchronously.
|
|
164
|
+
*
|
|
165
|
+
* @param {Texture} texture - The texture to read from.
|
|
166
|
+
* @param {number} x - The x coordinate.
|
|
167
|
+
* @param {number} y - The y coordinate.
|
|
168
|
+
* @param {number} width - The width of the rectangle.
|
|
169
|
+
* @param {number} height - The height of the rectangle.
|
|
170
|
+
* @param {RenderTarget} renderTarget - The render target to use for reading.
|
|
171
|
+
* @returns {Promise<Uint8Array>} Promise resolving to the pixel data.
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
private _readTexture;
|
|
175
|
+
/**
|
|
176
|
+
* Return the world position of the mesh instance picked at the specified screen coordinates.
|
|
177
|
+
* The position is reconstructed at the center of the pixel containing the coordinates, which
|
|
178
|
+
* is where its depth was rasterized.
|
|
179
|
+
*
|
|
180
|
+
* @param {number} x - The x coordinate of the pixel to pick.
|
|
181
|
+
* @param {number} y - The y coordinate of the pixel to pick.
|
|
182
|
+
* @returns {Promise<Vec3|null>} Promise that resolves with the world position of the picked point,
|
|
183
|
+
* or null if no depth is available or nothing was picked.
|
|
184
|
+
* @example
|
|
185
|
+
* // Get the world position at screen coordinates (100, 50)
|
|
186
|
+
* picker.getWorldPointAsync(100, 50).then((worldPoint) => {
|
|
187
|
+
* if (worldPoint) {
|
|
188
|
+
* console.log('World position:', worldPoint);
|
|
189
|
+
* // Use the world position
|
|
190
|
+
* } else {
|
|
191
|
+
* console.log('No object at this position');
|
|
192
|
+
* }
|
|
193
|
+
* });
|
|
194
|
+
*/
|
|
195
|
+
getWorldPointAsync(x: number, y: number): Promise<Vec3 | null>;
|
|
196
|
+
/**
|
|
197
|
+
* Return the depth value of the mesh instance picked at the specified screen coordinates.
|
|
198
|
+
*
|
|
199
|
+
* @param {number} x - The x coordinate of the pixel to pick.
|
|
200
|
+
* @param {number} y - The y coordinate of the pixel to pick.
|
|
201
|
+
* @returns {Promise<number|null>} Promise that resolves with the linear normalized depth value
|
|
202
|
+
* of the picked point (0 = near plane, 1 = far plane), or null if depth picking is not enabled
|
|
203
|
+
* or no object was picked.
|
|
204
|
+
* @ignore
|
|
205
|
+
*/
|
|
206
|
+
getPointDepthAsync(x: number, y: number): Promise<number | null>;
|
|
207
|
+
/**
|
|
208
|
+
* Sanitize a rectangle specified in the public top-left coordinate system and convert it to
|
|
209
|
+
* the bottom-left origin used when reading pixels back.
|
|
210
|
+
*
|
|
211
|
+
* The rectangle is floored and clipped while still in top-left space, and only then flipped,
|
|
212
|
+
* which matters twice. Flipping first would floor `bufferHeight - y - height`, landing one row
|
|
213
|
+
* off the requested pixel for any fractional y - common when the pick buffer is smaller than
|
|
214
|
+
* the canvas and coordinates are scaled into it. And clipping a rectangle that overhangs the
|
|
215
|
+
* bottom edge in flipped space absorbs the overflow at the wrong end, shifting the rectangle
|
|
216
|
+
* up instead of dropping the rows that fall outside the buffer.
|
|
217
|
+
*
|
|
218
|
+
* @param {number} x - The left edge of the rectangle.
|
|
219
|
+
* @param {number} y - The top edge of the rectangle.
|
|
220
|
+
* @param {number} width - The width of the rectangle.
|
|
221
|
+
* @param {number} height - The height of the rectangle.
|
|
222
|
+
* @param {number} bufferHeight - The height of the buffer being read.
|
|
223
|
+
* @returns {Vec4} The sanitized rectangle, with y in a bottom-left coordinate system.
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
226
|
+
private _sanitizeFlippedRect;
|
|
227
|
+
sanitizeRect(x: any, y: any, width: any, height: any): any;
|
|
228
|
+
decodePixels(pixels: any, mapping: any): any[];
|
|
229
|
+
createTexture(name: any): any;
|
|
230
|
+
allocateRenderTarget(): void;
|
|
231
|
+
releaseRenderTarget(): void;
|
|
232
|
+
/**
|
|
233
|
+
* Primes the pick buffer with a rendering of the specified models from the point of view of
|
|
234
|
+
* the supplied camera. Once the pick buffer has been prepared, {@link getSelection} can
|
|
235
|
+
* be called multiple times on the same picker object. Therefore, if the models or camera do
|
|
236
|
+
* not change in any way, {@link prepare} does not need to be called again.
|
|
237
|
+
*
|
|
238
|
+
* @param {CameraComponent} camera - The camera component used to render the scene.
|
|
239
|
+
* @param {Scene} scene - The scene containing the pickable mesh instances.
|
|
240
|
+
* @param {Layer[]} [layers] - Layers from which objects will be picked. If not supplied, all
|
|
241
|
+
* layers of the specified camera will be used.
|
|
242
|
+
*/
|
|
243
|
+
prepare(camera: Color, scene: Color, layers?: Layer[]): void;
|
|
244
|
+
/**
|
|
245
|
+
* Sets the resolution of the pick buffer. The pick buffer resolution does not need to match
|
|
246
|
+
* the resolution of the corresponding frame buffer use for general rendering of the 3D scene.
|
|
247
|
+
* However, the lower the resolution of the pick buffer, the less accurate the selection
|
|
248
|
+
* results returned by {@link getSelection}. On the other hand, smaller pick buffers
|
|
249
|
+
* will yield greater performance, so there is a trade off.
|
|
250
|
+
*
|
|
251
|
+
* @param {number} width - The width of the pick buffer in pixels.
|
|
252
|
+
* @param {number} height - The height of the pick buffer in pixels.
|
|
253
|
+
*/
|
|
254
|
+
resize(width: number, height: number): void;
|
|
255
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A render pass implementing rendering of mesh instances into a pick buffer.
|
|
3
|
+
*
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export class RenderPassPicker {
|
|
7
|
+
constructor(device: any, renderer: any);
|
|
8
|
+
/** @type {BlendState} */
|
|
9
|
+
blendState: BlendState;
|
|
10
|
+
/** @type {CameraComponent} */
|
|
11
|
+
camera: BlendState;
|
|
12
|
+
/** @type {Scene} */
|
|
13
|
+
scene: BlendState;
|
|
14
|
+
/** @type {Layer[]} */
|
|
15
|
+
layers: BlendState[];
|
|
16
|
+
/** @type {Map<number, MeshInstance | GSplatComponent>} */
|
|
17
|
+
mapping: Map<number, BlendState | BlendState>;
|
|
18
|
+
/** @type {boolean} */
|
|
19
|
+
depth: boolean;
|
|
20
|
+
/** @type {number[]} */
|
|
21
|
+
_qualifiedLayerIndices: number[];
|
|
22
|
+
/** @type {Map<number, MeshInstance|null>} */
|
|
23
|
+
_pickMeshInstances: Map<number, BlendState | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Minimal view uniform format used by the picker. The pick shaders only need the view
|
|
26
|
+
* projection (and the view matrix for depth picking); any other view uniform a shader happens
|
|
27
|
+
* to reference falls back to the per-mesh uniform buffer automatically. This avoids pulling in
|
|
28
|
+
* the full forward view format (and its lighting / shadow uniforms) which the picker does not
|
|
29
|
+
* need.
|
|
30
|
+
*
|
|
31
|
+
* @type {UniformBufferFormat|null}
|
|
32
|
+
*/
|
|
33
|
+
_viewUniformFormat: UniformBufferFormat | null;
|
|
34
|
+
renderer: any;
|
|
35
|
+
getViewUniformFormat(): any;
|
|
36
|
+
/**
|
|
37
|
+
* @param {CameraComponent} camera - The camera component used for picking.
|
|
38
|
+
* @param {Scene} scene - The scene to pick from.
|
|
39
|
+
* @param {Layer[]} layers - The layers to pick from.
|
|
40
|
+
* @param {Map<number, MeshInstance | GSplatComponent>} mapping - Map to store ID to object mappings.
|
|
41
|
+
* @param {boolean} depth - Whether to render depth information.
|
|
42
|
+
*/
|
|
43
|
+
update(camera: BlendState, scene: BlendState, layers: BlendState[], mapping: Map<number, BlendState | BlendState>, depth: boolean): void;
|
|
44
|
+
emptyWorldClusters: any;
|
|
45
|
+
before(): void;
|
|
46
|
+
execute(): void;
|
|
47
|
+
}
|