@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.
Files changed (77) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +110 -0
  3. package/package.json +62 -0
  4. package/src/asset-usage.js +108 -0
  5. package/src/asset-view.js +370 -0
  6. package/src/camera-view.js +128 -0
  7. package/src/debug.js +31 -0
  8. package/src/describe.js +302 -0
  9. package/src/entity-inspector-script.js +130 -0
  10. package/src/frame-graph-view.js +767 -0
  11. package/src/hierarchy-view.js +475 -0
  12. package/src/index.js +4 -0
  13. package/src/input/fly-controller.js +116 -0
  14. package/src/input/input.js +299 -0
  15. package/src/input/math.js +8 -0
  16. package/src/input/orbit-controller.js +158 -0
  17. package/src/input/pose.js +207 -0
  18. package/src/inspector.js +3293 -0
  19. package/src/instance-survey.js +50 -0
  20. package/src/list-view.js +410 -0
  21. package/src/material-view.js +197 -0
  22. package/src/memory-view.js +344 -0
  23. package/src/mesh-view.js +235 -0
  24. package/src/model.js +170 -0
  25. package/src/node-model.js +404 -0
  26. package/src/physics-debug.js +527 -0
  27. package/src/physics-view.js +314 -0
  28. package/src/picker/picker.js +545 -0
  29. package/src/picker/render-pass-picker.js +206 -0
  30. package/src/property-view.js +628 -0
  31. package/src/render-target-view.js +288 -0
  32. package/src/renderers/texture-renderer-shaders.js +139 -0
  33. package/src/renderers/texture-renderer.js +430 -0
  34. package/src/renderers/wire-renderer.js +954 -0
  35. package/src/script-view.js +288 -0
  36. package/src/shader-view.js +287 -0
  37. package/src/styles.js +918 -0
  38. package/src/texture-view.js +186 -0
  39. package/src/tooltip.js +72 -0
  40. package/src/viewport-tools.js +695 -0
  41. package/types/asset-usage.d.ts +23 -0
  42. package/types/asset-view.d.ts +94 -0
  43. package/types/camera-view.d.ts +45 -0
  44. package/types/debug.d.ts +14 -0
  45. package/types/describe.d.ts +43 -0
  46. package/types/entity-inspector-script.d.ts +87 -0
  47. package/types/frame-graph-view.d.ts +155 -0
  48. package/types/hierarchy-view.d.ts +172 -0
  49. package/types/index.d.ts +3 -0
  50. package/types/input/fly-controller.d.ts +42 -0
  51. package/types/input/input.d.ts +192 -0
  52. package/types/input/math.d.ts +1 -0
  53. package/types/input/orbit-controller.d.ts +63 -0
  54. package/types/input/pose.d.ts +126 -0
  55. package/types/inspector.d.ts +1304 -0
  56. package/types/instance-survey.d.ts +35 -0
  57. package/types/list-view.d.ts +151 -0
  58. package/types/material-view.d.ts +63 -0
  59. package/types/memory-view.d.ts +95 -0
  60. package/types/mesh-view.d.ts +89 -0
  61. package/types/model.d.ts +104 -0
  62. package/types/node-model.d.ts +54 -0
  63. package/types/physics-debug.d.ts +254 -0
  64. package/types/physics-view.d.ts +81 -0
  65. package/types/picker/picker.d.ts +255 -0
  66. package/types/picker/render-pass-picker.d.ts +47 -0
  67. package/types/property-view.d.ts +189 -0
  68. package/types/render-target-view.d.ts +98 -0
  69. package/types/renderers/texture-renderer-shaders.d.ts +9 -0
  70. package/types/renderers/texture-renderer.d.ts +231 -0
  71. package/types/renderers/wire-renderer.d.ts +347 -0
  72. package/types/script-view.d.ts +56 -0
  73. package/types/shader-view.d.ts +46 -0
  74. package/types/styles.d.ts +22 -0
  75. package/types/texture-view.d.ts +30 -0
  76. package/types/tooltip.d.ts +17 -0
  77. package/types/viewport-tools.d.ts +237 -0
@@ -0,0 +1,430 @@
1
+ import {
2
+ BLEND_NORMAL, CULLFACE_NONE, EVENT_POSTRENDER_LAYER, EVENT_PRERENDER_LAYER, FILTER_NEAREST, FILTER_NEAREST_MIPMAP_LINEAR, FILTER_NEAREST_MIPMAP_NEAREST, GraphNode, isIntegerPixelFormat, isSrgbPixelFormat, Mesh, MeshInstance, PIXELFORMAT_DEPTH, PIXELFORMAT_DEPTH16, PIXELFORMAT_DEPTHSTENCIL, PIXELFORMAT_R16F, PIXELFORMAT_R32F, PIXELFORMAT_R8, PIXELFORMAT_RG32F, PIXELFORMAT_RGB32F, PIXELFORMAT_RGBA32F, PRIMITIVE_TRISTRIP, ShaderMaterial
3
+ } from 'playcanvas';
4
+
5
+ import { Debug } from '../debug.js';
6
+
7
+ import { createTextureShaderDesc } from './texture-renderer-shaders.js';
8
+
9
+ // the red channel replicated, for single-channel formats shown with the default selection
10
+ const SINGLE_CHANNEL_INDICES = new Int32Array([0, 0, 0]);
11
+
12
+ /**
13
+ * @import { AppBase } from 'playcanvas'
14
+ * @import { CameraComponent } from 'playcanvas'
15
+ * @import { Texture } from 'playcanvas'
16
+ * @import { RenderTarget } from 'playcanvas'
17
+ * @import { Camera } from 'playcanvas'
18
+ * @import { Layer } from 'playcanvas'
19
+ * @import { ShaderDesc } from 'playcanvas'
20
+ */
21
+
22
+ /**
23
+ * @typedef {object} TextureSlot
24
+ * @property {MeshInstance} meshInstance - The persistent screen-space quad.
25
+ * @property {ShaderMaterial} material - Material owned by this slot.
26
+ * @property {string} mode - The last sampling mode.
27
+ * @property {string} encoding - The last source encoding.
28
+ * @property {Int32Array} channelIndices - Channels selected for this preview.
29
+ * @property {Texture|null} texture - The texture shown this frame, or null.
30
+ * @ignore
31
+ */
32
+
33
+ /**
34
+ * @typedef {object} TexturePool
35
+ * @property {TextureSlot[]} slots - Slots in submission order.
36
+ * @property {MeshInstance[]} meshInstances - Registered instances, used for cleanup.
37
+ * @property {number} used - Number of submissions this frame.
38
+ * @ignore
39
+ */
40
+
41
+ /**
42
+ * @param {RenderTarget} rt - A render target.
43
+ * @param {Texture} texture - A texture.
44
+ * @returns {boolean} Whether the texture is one of the target's attachments.
45
+ */
46
+ function rendersInto(rt, texture) {
47
+ if (rt.depthBuffer === texture || rt.depthResolveBuffer === texture) return true;
48
+ for (let i = 0; i < rt.colorBufferCount; i++) {
49
+ if (rt.getColorBuffer(i) === texture || rt.getResolveBuffer(i) === texture) return true;
50
+ }
51
+ return false;
52
+ }
53
+
54
+ /**
55
+ * Displays textures for a single frame, for debugging. Call {@link draw} or {@link sceneDepth}
56
+ * during update or prerender on every frame the preview should be visible. Positions specify
57
+ * the top-left corner in normalized camera-viewport coordinates: (0, 0) is top-left and (1, 1)
58
+ * is bottom-right. Width and height are fractions of the viewport; a rectangle of (0, 0, 1, 1)
59
+ * fills it. Signed sizes can flip a preview, and rectangles can extend outside the viewport.
60
+ *
61
+ * Supports 2D color textures in normalized, floating-point and device-supported compressed
62
+ * formats. Linear and sRGB color, and RGBM, RGBE and RGBP encoded HDR color, are detected
63
+ * automatically with the default {@link channels} selection, and single-channel formats such as
64
+ * {@link PIXELFORMAT_R8} display their channel as grayscale. Other selections display stored
65
+ * channel values, including alpha, as opaque previews.
66
+ *
67
+ * Depth textures using {@link PIXELFORMAT_DEPTH}, {@link PIXELFORMAT_DEPTH16} or
68
+ * {@link PIXELFORMAT_DEPTHSTENCIL} are displayed as raw grayscale values. Use {@link sceneDepth}
69
+ * to display the rendering camera's scene depth, linearized and normalized by its far clip
70
+ * distance. The camera must have scene depth capture enabled.
71
+ *
72
+ * Cube, volume, array, integer and multisampled textures are not supported. On WebGL2, raw depth
73
+ * textures must have comparison sampling disabled, and both raw depth and non-filterable float
74
+ * textures require nearest minification and magnification filters. WebGPU supports these textures
75
+ * regardless of their filtering and comparison sampler settings.
76
+ *
77
+ * Resources are released automatically when the application is destroyed, or earlier by calling
78
+ * {@link destroy}. Supplied textures are never destroyed by this helper.
79
+ *
80
+ * Previews produce fully opaque pixels but are drawn as alpha-blended instances, so they render in
81
+ * layers that only draw their transparent sub-layer, such as the default UI layer, which is also
82
+ * where they escape a camera frame's post-processing. They do not write or test depth and do not
83
+ * cast shadows. Ordering against other transparent geometry follows the destination layer's
84
+ * transparent sort mode.
85
+ *
86
+ * Every camera rendering the destination layer draws the previews, including cameras rendering
87
+ * into a texture. Set {@link camera} to limit them to a single camera, typically the one rendering
88
+ * to the screen. A render pass whose target has the previewed texture among its attachments never
89
+ * draws that preview: sampling a texture while rendering into it is undefined on WebGL and an
90
+ * error on WebGPU. Both rules are applied as each layer is rendered, against the target the pass
91
+ * really renders into, so they hold for camera frames and custom render passes and do not depend
92
+ * on frustum culling.
93
+ *
94
+ * @example
95
+ * const textures = new TextureRenderer(app);
96
+ * app.on('update', () => {
97
+ * textures.draw(texture, 0.7, 0.7, 0.25, 0.25);
98
+ * });
99
+ * @example
100
+ * // camera is an entity with a camera component.
101
+ * camera.camera.requestSceneDepthMap(true);
102
+ * const textures = new TextureRenderer(app);
103
+ * app.on('update', () => {
104
+ * textures.sceneDepth(0.7, 0.7, 0.25, 0.25);
105
+ * });
106
+ * @category Graphics
107
+ */
108
+ class TextureRenderer {
109
+ /**
110
+ * The layer used by subsequent draw calls, or null to use the application's default debug
111
+ * drawing layer (normally Immediate). Defaults to null.
112
+ *
113
+ * @type {Layer|null}
114
+ */
115
+ layer = null;
116
+
117
+ /**
118
+ * The only camera that draws the previews, or null to let every camera rendering the
119
+ * destination layer draw them. Defaults to null.
120
+ *
121
+ * @type {CameraComponent|null}
122
+ */
123
+ camera = null;
124
+
125
+ /** @private */
126
+ _channels = 'rgb';
127
+
128
+ /** @private */
129
+ _channelIndices = new Int32Array([0, 1, 2]);
130
+
131
+ /**
132
+ * Channels displayed by subsequent {@link draw} calls. Must be exactly three characters from
133
+ * 'r', 'g', 'b' and 'a'. Defaults to 'rgb', which displays automatically decoded color, or the
134
+ * stored channel as grayscale for single-channel formats. Other selections display stored
135
+ * channel values without color decoding: for example, 'rrr' displays
136
+ * red as grayscale, 'aaa' displays alpha, and 'bgr' swaps red and blue. Values from 0 to 1 map
137
+ * directly from black to white. Output is always opaque. Ignored for depth textures and
138
+ * {@link sceneDepth}. Invalid values leave the previous selection unchanged.
139
+ *
140
+ * @type {string}
141
+ * @example
142
+ * textures.channels = 'aaa';
143
+ * textures.draw(texture, 0, 0, 0.25, 0.25);
144
+ */
145
+ set channels(value) {
146
+ if (value === this._channels) return;
147
+ if (typeof value !== 'string' || !/^[rgba]{3}$/.test(value)) {
148
+ Debug.warnOnce('TextureRenderer.channels must contain exactly three characters from r, g, b and a.');
149
+ return;
150
+ }
151
+ this._channels = value;
152
+ for (let i = 0; i < 3; i++) {
153
+ this._channelIndices[i] = 'rgba'.indexOf(value[i]);
154
+ }
155
+ }
156
+
157
+ get channels() {
158
+ return this._channels;
159
+ }
160
+
161
+ /**
162
+ * @type {Map<Layer, TexturePool>}
163
+ * @private
164
+ */
165
+ _pools = new Map();
166
+
167
+ /**
168
+ * @type {Map<string, ShaderDesc>}
169
+ * @private
170
+ */
171
+ _shaderDescs = new Map();
172
+
173
+ /**
174
+ * @type {Mesh|null}
175
+ * @private
176
+ */
177
+ _mesh = null;
178
+
179
+ /**
180
+ * Creates a debug texture renderer.
181
+ *
182
+ * @param {AppBase} app - The application to render into and bind resource lifetime to.
183
+ */
184
+ constructor(app) {
185
+ /** @private */
186
+ this._app = app;
187
+ // postrender also covers explicit app.render(); frameend discards submissions on ticks
188
+ // where autoRender is disabled, preventing the slot pool from growing while paused.
189
+ app.on('postrender', this._endFrame, this);
190
+ app.on('frameend', this._endFrame, this);
191
+ app.on('destroy', this.destroy, this);
192
+ app.scene.on(EVENT_PRERENDER_LAYER, this._onPreRenderLayer, this);
193
+ app.scene.on(EVENT_POSTRENDER_LAYER, this._onPostRenderLayer, this);
194
+ }
195
+
196
+ /**
197
+ * Displays a 2D color or depth texture for this frame. Color encoding and supported filtering
198
+ * are detected automatically when {@link channels} is 'rgb'. Other selections display stored
199
+ * channel values. Raw depth is shown as grayscale without
200
+ * projection-dependent linearization; use {@link sceneDepth} for camera depth. Texture row 0
201
+ * is displayed at the top. For rendered textures, use {@link RENDERTARGET_ORIGIN_TOP} on their
202
+ * render target for consistent orientation across backends.
203
+ *
204
+ * Cube, volume, array, integer and multisampled textures are not supported. On WebGL2,
205
+ * depth textures must have comparison sampling disabled. Raw depth and non-filterable float
206
+ * textures must use nearest minification and magnification filters on WebGL2. WebGPU samples
207
+ * these textures independently of their filtering and comparison sampler settings.
208
+ *
209
+ * @param {Texture} texture - The caller-owned texture to display.
210
+ * @param {number} x - Left edge as a fraction of the camera viewport width.
211
+ * @param {number} y - Top edge as a fraction of the camera viewport height.
212
+ * @param {number} width - Width as a fraction of the camera viewport width.
213
+ * @param {number} height - Height as a fraction of the camera viewport height.
214
+ */
215
+ draw(texture, x, y, width, height) {
216
+ if (!this._app) return;
217
+ const device = this._app.graphicsDevice;
218
+ if (!texture || texture.device !== device || texture.cubemap || texture.volume ||
219
+ texture.arrayLength || texture.samples > 1 || isIntegerPixelFormat(texture.format)) {
220
+ Debug.warnOnce('TextureRenderer.draw requires a non-multisampled 2D color or depth texture from the same graphics device.');
221
+ return;
222
+ }
223
+
224
+ const format = texture.format;
225
+ const depth = format === PIXELFORMAT_DEPTH || format === PIXELFORMAT_DEPTH16 || format === PIXELFORMAT_DEPTHSTENCIL;
226
+ if (depth && device.isWebGL2 && texture.compareOnRead) {
227
+ Debug.warnOnce('TextureRenderer cannot display comparison depth textures on WebGL2.');
228
+ return;
229
+ }
230
+ const unfilterable = !device.textureFloatFilterable &&
231
+ (format === PIXELFORMAT_R32F || format === PIXELFORMAT_RG32F || format === PIXELFORMAT_RGB32F || format === PIXELFORMAT_RGBA32F);
232
+ // WebGL still checks sampler completeness for texelFetch, even though no filtering occurs.
233
+ // Do not change caller-owned sampler state just to make a debug preview render.
234
+ if (device.isWebGL2 && (depth || unfilterable)) {
235
+ const minFilter = texture.minFilter;
236
+ const nearestMin = minFilter === FILTER_NEAREST || minFilter === FILTER_NEAREST_MIPMAP_NEAREST ||
237
+ (!texture.mipmaps && minFilter === FILTER_NEAREST_MIPMAP_LINEAR);
238
+ if (!nearestMin || texture.magFilter !== FILTER_NEAREST) {
239
+ Debug.warnOnce('TextureRenderer requires nearest filtering for raw depth and non-filterable float textures on WebGL2.');
240
+ return;
241
+ }
242
+ }
243
+ // a single stored channel reads as grayscale rather than as red with black behind it
244
+ const singleChannel = format === PIXELFORMAT_R8 || format === PIXELFORMAT_R16F || format === PIXELFORMAT_R32F;
245
+ const decoded = this._channels === 'rgb' && !singleChannel;
246
+ const channelIndices = this._channels === 'rgb' ? SINGLE_CHANNEL_INDICES : this._channelIndices;
247
+ const encoding = depth ? 'linear' : decoded ? texture.encoding :
248
+ isSrgbPixelFormat(format) ? 'raw-srgb' : 'raw';
249
+ this._draw(texture, depth ? 'depth' : unfilterable ? 'unfilterable' : 'filtered',
250
+ encoding, x, y, width, height, channelIndices);
251
+ }
252
+
253
+ /**
254
+ * Displays the rendering camera's scene depth for this frame, linearized and normalized by
255
+ * its far clip distance. The camera must already supply a scene depth map, for example using
256
+ * {@link CameraComponent#requestSceneDepthMap}, and this layer must render after depth capture.
257
+ *
258
+ * @param {number} x - Left edge as a fraction of the camera viewport width.
259
+ * @param {number} y - Top edge as a fraction of the camera viewport height.
260
+ * @param {number} width - Width as a fraction of the camera viewport width.
261
+ * @param {number} height - Height as a fraction of the camera viewport height.
262
+ */
263
+ sceneDepth(x, y, width, height) {
264
+ this._draw(null, 'scene-depth', 'linear', x, y, width, height, SINGLE_CHANNEL_INDICES);
265
+ }
266
+
267
+ /**
268
+ * @param {Texture|null} texture - Source texture, or null for scene depth.
269
+ * @param {string} mode - Sampling mode.
270
+ * @param {string} encoding - Source encoding.
271
+ * @param {number} x - Normalized left edge.
272
+ * @param {number} y - Normalized top edge.
273
+ * @param {number} width - Normalized width.
274
+ * @param {number} height - Normalized height.
275
+ * @param {Int32Array} channelIndices - The channels shown by a raw encoding.
276
+ * @private
277
+ */
278
+ _draw(texture, mode, encoding, x, y, width, height, channelIndices) {
279
+ if (!this._app || !Number.isFinite(x) || !Number.isFinite(y) ||
280
+ !Number.isFinite(width) || !Number.isFinite(height) || width === 0 || height === 0) return;
281
+
282
+ const layer = this.layer ?? this._app.scene.defaultDrawLayer;
283
+ if (!layer) return;
284
+ let pool = this._pools.get(layer);
285
+ if (!pool) {
286
+ pool = { slots: [], meshInstances: [], used: 0 };
287
+ this._pools.set(layer, pool);
288
+ }
289
+
290
+ let slot = pool.slots[pool.used++];
291
+ if (!slot) {
292
+ if (!this._mesh) {
293
+ this._mesh = new Mesh(this._app.graphicsDevice);
294
+ this._mesh.setPositions([-0.5, -0.5, 0, 0.5, -0.5, 0, -0.5, 0.5, 0, 0.5, 0.5, 0]);
295
+ this._mesh.update(PRIMITIVE_TRISTRIP);
296
+ }
297
+ const material = new ShaderMaterial();
298
+ material.name = 'Debug texture';
299
+ material.cull = CULLFACE_NONE;
300
+ material.depthTest = false;
301
+ material.depthWrite = false;
302
+ // blended so the quad counts as transparent: layers such as UI only render that sub-layer
303
+ material.blendType = BLEND_NORMAL;
304
+ const meshInstance = new MeshInstance(this._mesh, material, new GraphNode(`Debug texture ${pool.slots.length}`));
305
+ meshInstance.castShadow = false;
306
+ meshInstance.pick = false;
307
+ meshInstance.cull = false;
308
+ meshInstance.shaderPassMask = 0;
309
+ slot = { meshInstance, material, mode: '', encoding: '', channelIndices: new Int32Array(3), texture: null };
310
+ pool.slots.push(slot);
311
+ pool.meshInstances.push(meshInstance);
312
+ layer.addMeshInstances([meshInstance], true);
313
+ }
314
+
315
+ if (slot.mode !== mode || slot.encoding !== encoding) {
316
+ const key = `${mode}-${encoding}`;
317
+ let desc = this._shaderDescs.get(key);
318
+ if (!desc) {
319
+ desc = createTextureShaderDesc(mode, encoding);
320
+ this._shaderDescs.set(key, desc);
321
+ }
322
+ slot.material.shaderDesc = desc;
323
+ slot.material.update();
324
+ slot.mode = mode;
325
+ slot.encoding = encoding;
326
+ }
327
+ if (encoding === 'raw' || encoding === 'raw-srgb') {
328
+ slot.channelIndices.set(channelIndices);
329
+ slot.material.setParameter('textureChannels', slot.channelIndices);
330
+ }
331
+ slot.material.setParameter('colorMap', texture);
332
+ slot.texture = texture;
333
+ const meshInstance = slot.meshInstance;
334
+ meshInstance.node.setLocalPosition(2 * x + width - 1, 1 - 2 * y - height, 0);
335
+ meshInstance.node.setLocalScale(2 * width, -2 * height, 1);
336
+ meshInstance.shaderPassMask = 0;
337
+ meshInstance.visible = true;
338
+ }
339
+
340
+ /**
341
+ * Whether a pass draws a preview: only the selected camera if one is set, and never a pass
342
+ * rendering into the texture the preview samples.
343
+ *
344
+ * @param {TextureSlot} slot - The preview.
345
+ * @param {Camera} camera - The camera rendering the layer.
346
+ * @param {RenderTarget|null} renderTarget - The target the pass renders into.
347
+ * @returns {boolean} True to draw the preview in this pass.
348
+ * @private
349
+ */
350
+ _isDrawnBy(slot, camera, renderTarget) {
351
+ if (this.camera && camera !== this.camera.camera) return false;
352
+ return !slot.texture || !renderTarget || !rendersInto(renderTarget, slot.texture);
353
+ }
354
+
355
+ /**
356
+ * Applies camera and attachment restrictions after culling, using the actual pass target.
357
+ * The pass mask skips shader preparation and resource binding as well as the draw itself.
358
+ *
359
+ * @param {CameraComponent} cameraComponent - The camera rendering the layer.
360
+ * @param {Layer} layer - The layer about to be rendered.
361
+ * @private
362
+ */
363
+ _onPreRenderLayer(cameraComponent, layer) {
364
+ const pool = this._pools.get(layer);
365
+ if (!pool) return;
366
+ const camera = cameraComponent.camera;
367
+ const renderTarget = this._app.graphicsDevice.renderTarget;
368
+ for (let i = 0; i < pool.used; i++) {
369
+ const slot = pool.slots[i];
370
+ slot.meshInstance.shaderPassMask = this._isDrawnBy(slot, camera, renderTarget) ? 0xFFFFFFFF : 0;
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Keeps previews out of other passes until their destination layer explicitly enables them.
376
+ *
377
+ * @param {CameraComponent} cameraComponent - The camera that rendered the layer.
378
+ * @param {Layer} layer - The layer that was rendered.
379
+ * @private
380
+ */
381
+ _onPostRenderLayer(cameraComponent, layer) {
382
+ const pool = this._pools.get(layer);
383
+ if (!pool) return;
384
+ for (let i = 0; i < pool.used; i++) {
385
+ pool.slots[i].meshInstance.shaderPassMask = 0;
386
+ }
387
+ }
388
+
389
+ /** @private */
390
+ _endFrame() {
391
+ for (const pool of this._pools.values()) {
392
+ for (let i = 0; i < pool.used; i++) {
393
+ const slot = pool.slots[i];
394
+ slot.meshInstance.visible = false;
395
+ slot.meshInstance.shaderPassMask = 0;
396
+ // A dormant debug renderer must not keep caller-owned textures alive.
397
+ slot.material.setParameter('colorMap', null);
398
+ slot.texture = null;
399
+ }
400
+ pool.used = 0;
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Removes all previews and releases the renderer's resources. Does not destroy supplied
406
+ * textures. Safe to call repeatedly; subsequent draw calls are ignored.
407
+ */
408
+ destroy() {
409
+ if (!this._app) return;
410
+ this._app.off('postrender', this._endFrame, this);
411
+ this._app.off('frameend', this._endFrame, this);
412
+ this._app.off('destroy', this.destroy, this);
413
+ this._app.scene.off(EVENT_PRERENDER_LAYER, this._onPreRenderLayer, this);
414
+ this._app.scene.off(EVENT_POSTRENDER_LAYER, this._onPostRenderLayer, this);
415
+ for (const [layer, pool] of this._pools) {
416
+ layer.removeMeshInstances(pool.meshInstances, true);
417
+ for (const slot of pool.slots) {
418
+ slot.meshInstance.destroy();
419
+ slot.material.destroy();
420
+ }
421
+ }
422
+ this._pools.clear();
423
+ this._shaderDescs.clear();
424
+ // MeshInstance.destroy releases the shared mesh when its last instance is destroyed.
425
+ this._mesh = null;
426
+ this._app = null;
427
+ }
428
+ }
429
+
430
+ export { TextureRenderer };