@playcanvas/inspector 0.5.0 → 0.6.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/README.md +53 -4
- package/package.json +2 -2
- package/src/asset-view.js +65 -2
- package/src/camera-view.js +1 -1
- package/src/describe.js +1 -1
- package/src/inspector.js +368 -48
- package/src/layer-view.js +235 -0
- package/src/mcp-tools.js +6 -3
- package/src/memory-view.js +59 -3
- package/src/mesh-view.js +50 -1
- package/src/ref-registry.js +2 -1
- package/src/render-target-view.js +75 -1
- package/src/shader-view.js +32 -1
- package/src/snapshot-view.js +268 -0
- package/src/styles.js +261 -0
- package/src/texture-view.js +1 -1
- package/src/treemap-view.js +837 -0
- package/types/asset-view.d.ts +10 -0
- package/types/inspector.d.ts +147 -2
- package/types/layer-view.d.ts +80 -0
- package/types/memory-view.d.ts +11 -0
- package/types/mesh-view.d.ts +13 -0
- package/types/render-target-view.d.ts +12 -0
- package/types/shader-view.d.ts +12 -0
- package/types/snapshot-view.d.ts +166 -0
- package/types/texture-view.d.ts +12 -1
- package/types/treemap-view.d.ts +379 -0
package/src/inspector.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Asset, Color, Component, Entity, FramePass, GraphNode, LAYERID_UI, Material, Mesh, MeshInstance, RenderPassForward, RenderTarget, Shader, Texture
|
|
2
|
+
Asset, Color, Component, Entity, FramePass, GraphNode, Layer, LAYERID_UI, Material, Mesh, MeshInstance, RenderPassForward, RenderTarget, Shader, Texture
|
|
3
3
|
} from 'playcanvas';
|
|
4
4
|
|
|
5
5
|
import { TextureRenderer } from './renderers/texture-renderer.js';
|
|
6
6
|
import { WireRenderer } from './renderers/wire-renderer.js';
|
|
7
7
|
|
|
8
8
|
import { pushResourceUsage } from './asset-usage.js';
|
|
9
|
-
import { ASSET_SORTS, assetRows, buildAssetModel, collectAssets } from './asset-view.js';
|
|
9
|
+
import { ASSET_SORTS, assetRows, assetSnapshot, buildAssetModel, collectAssets } from './asset-view.js';
|
|
10
10
|
import { buildCameraModel, cameraRows, collectCameras } from './camera-view.js';
|
|
11
|
+
import { buildLayerModel, collectSubLayers, layerRows } from './layer-view.js';
|
|
11
12
|
import { ContextMenu } from './context-menu.js';
|
|
12
13
|
import { copyGroup, copyList, copyListRow, copySubject, stringifyCopy } from './copy-json.js';
|
|
13
14
|
import { INSTANCES_PER_PAGE, LayerStepSelection, buildPassModel, buildStepModel, captureFrameGraph, passRows, profilerName } from './frame-graph-view.js';
|
|
14
|
-
import { bufferKind, bufferOwners, buildBufferModel, KIND_NAMES, memoryRows, videoMemory } from './memory-view.js';
|
|
15
|
+
import { bufferKind, bufferOwners, buildBufferModel, KIND_NAMES, memoryRows, memorySnapshot, videoMemory } from './memory-view.js';
|
|
15
16
|
import { HierarchyView, filterSuggestions } from './hierarchy-view.js';
|
|
16
17
|
import { ListView } from './list-view.js';
|
|
17
18
|
import {
|
|
18
19
|
buildMaterialModel, materialListRows, materialsUsingShader, materialsUsingTexture, surveyMaterials,
|
|
19
20
|
usedByMaterialsSection
|
|
20
21
|
} from './material-view.js';
|
|
21
|
-
import { buildMeshModel, meshBytes, meshListRows, meshNote, surveyMeshes } from './mesh-view.js';
|
|
22
|
+
import { buildMeshModel, meshBytes, meshListRows, meshNote, meshSnapshot, surveyMeshes } from './mesh-view.js';
|
|
22
23
|
import { formatBytes, formatName, passDisplayName } from './model.js';
|
|
23
24
|
import { TOOLS as MCP_TOOLS, endPerfSession, validate as validateMcpArgs } from './mcp-tools.js';
|
|
24
25
|
import { buildComponentModel, buildNodeModel, meshInstanceRows } from './node-model.js';
|
|
@@ -33,8 +34,10 @@ import { LogCapture } from './log-capture.js';
|
|
|
33
34
|
import { PropertyView } from './property-view.js';
|
|
34
35
|
import { RefRegistry } from './ref-registry.js';
|
|
35
36
|
import { buildScriptModel, isScriptClass, scriptListRows, surveyScripts } from './script-view.js';
|
|
36
|
-
import { buildRenderTargetModel, formatChannels, isDepthFormat, previewAttachments, previewSupport, renderTargetRows, storedBottomUp } from './render-target-view.js';
|
|
37
|
-
import { buildShaderModel, collectShaders, shaderRows, stateName } from './shader-view.js';
|
|
37
|
+
import { buildRenderTargetModel, formatChannels, isDepthFormat, previewAttachments, previewSupport, renderTargetRows, renderTargetSnapshot, storedBottomUp } from './render-target-view.js';
|
|
38
|
+
import { buildShaderModel, collectShaders, shaderRows, shaderSnapshot, stateName } from './shader-view.js';
|
|
39
|
+
import { SnapshotPanel, createSnapshotList } from './snapshot-view.js';
|
|
40
|
+
import { TreemapView } from './treemap-view.js';
|
|
38
41
|
import { styles } from './styles.js';
|
|
39
42
|
import { installTooltip, setTip } from './tooltip.js';
|
|
40
43
|
import { CameraFly, CameraOrbit, CanvasCapture, RENDER_MODES, ViewportPicker, WireframeMode, isScreenCamera, screenCameraAt } from './viewport-tools.js';
|
|
@@ -50,6 +53,8 @@ import { TRANSFORM_POINTER_EVENTS, TransformTool } from './transform-tool.js';
|
|
|
50
53
|
/** @import { CopyTarget } from './property-view.js' */
|
|
51
54
|
/** @import { TransformMode } from './transform-tool.js' */
|
|
52
55
|
/** @import { McpHost, McpTool } from './mcp-tools.js' */
|
|
56
|
+
/** @import { SnapshotContent, SnapshotList } from './snapshot-view.js' */
|
|
57
|
+
/** @import { TreemapData } from './treemap-view.js' */
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
60
|
* Options for {@link Inspector}.
|
|
@@ -149,6 +154,7 @@ const PERF_SERIES_NAMES = {
|
|
|
149
154
|
const TAB_TIPS = {
|
|
150
155
|
hierarchy: 'The entity tree, and the components and properties of the selected entity',
|
|
151
156
|
cameras: 'The cameras of the scene in render order, with where they draw, their render mode and a way to fly each',
|
|
157
|
+
layers: 'The layers of the composition in the order they render, each opaque and transparent half apart, with the cameras, lights and mesh instances of each and a way to hide it',
|
|
152
158
|
assets: 'The assets of the registry, and what uses each',
|
|
153
159
|
passes: 'The passes that rendered the last frame, with the layers, draws and targets of each',
|
|
154
160
|
perf: 'Record frames and chart their CPU and GPU time, draw calls, memory and events over the whole capture.\nClick a frame to see everything recorded for it, drag to select frames, scroll to zoom, Shift+drag to pan,\ndouble-click to see the whole capture. A dashed line marks the display interval, red ticks the hitches',
|
|
@@ -467,7 +473,9 @@ class Inspector {
|
|
|
467
473
|
_nextPropertyRefresh = 0;
|
|
468
474
|
|
|
469
475
|
/**
|
|
470
|
-
*
|
|
476
|
+
* The tab shown: one of the fixed tabs, or a treemap tab, by its id.
|
|
477
|
+
*
|
|
478
|
+
* @type {'hierarchy'|'cameras'|'layers'|'assets'|'passes'|'perf'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'|`treemap${number}`}
|
|
471
479
|
* @private
|
|
472
480
|
*/
|
|
473
481
|
_tab = 'hierarchy';
|
|
@@ -732,6 +740,79 @@ class Inspector {
|
|
|
732
740
|
*/
|
|
733
741
|
_cameraList;
|
|
734
742
|
|
|
743
|
+
/**
|
|
744
|
+
* @type {ListView}
|
|
745
|
+
* @private
|
|
746
|
+
*/
|
|
747
|
+
_layerList;
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* The layers hidden from the Layers tab, each turned off until shown again, reset or the panel
|
|
751
|
+
* closes. A layer the app turns back on itself meanwhile is left to it.
|
|
752
|
+
*
|
|
753
|
+
* @type {Set<Layer>}
|
|
754
|
+
* @private
|
|
755
|
+
*/
|
|
756
|
+
_hiddenLayers = new Set();
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* The snapshots captured on each tab that takes them, kept here rather than with the panel's
|
|
760
|
+
* elements, which are built again when the panel docks back from its own window.
|
|
761
|
+
*
|
|
762
|
+
* @type {Map<string, SnapshotList>}
|
|
763
|
+
* @private
|
|
764
|
+
*/
|
|
765
|
+
_snapshots = new Map();
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* The snapshots section of each tab that takes them, by tab.
|
|
769
|
+
*
|
|
770
|
+
* @type {Record<string, SnapshotPanel>}
|
|
771
|
+
* @private
|
|
772
|
+
*/
|
|
773
|
+
_snapshotPanels = {};
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* The treemap tabs open, by id, each showing a snapshot or two compared, with the tab the
|
|
777
|
+
* snapshots came from. Kept here, so the tabs are built again with the panel.
|
|
778
|
+
*
|
|
779
|
+
* @type {Map<string, { source: string, key: string, data: TreemapData, view: TreemapView|null }>}
|
|
780
|
+
* @private
|
|
781
|
+
*/
|
|
782
|
+
_treemapTabs = new Map();
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* The number the id of the next treemap tab takes.
|
|
786
|
+
*
|
|
787
|
+
* @type {number}
|
|
788
|
+
* @private
|
|
789
|
+
*/
|
|
790
|
+
_nextTreemap = 1;
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* The tab bar.
|
|
794
|
+
*
|
|
795
|
+
* @type {HTMLElement}
|
|
796
|
+
* @private
|
|
797
|
+
*/
|
|
798
|
+
_tabsEl;
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* The body of the panel: the tabs over the properties.
|
|
802
|
+
*
|
|
803
|
+
* @type {HTMLElement}
|
|
804
|
+
* @private
|
|
805
|
+
*/
|
|
806
|
+
_bodyEl;
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* The button on the Layers tab that shows the hidden layers again.
|
|
810
|
+
*
|
|
811
|
+
* @type {HTMLButtonElement}
|
|
812
|
+
* @private
|
|
813
|
+
*/
|
|
814
|
+
_showLayersBtn;
|
|
815
|
+
|
|
735
816
|
/**
|
|
736
817
|
* The render mode applied from the Cameras tab.
|
|
737
818
|
*
|
|
@@ -951,6 +1032,21 @@ class Inspector {
|
|
|
951
1032
|
}
|
|
952
1033
|
});
|
|
953
1034
|
|
|
1035
|
+
/**
|
|
1036
|
+
* Model builder for the property view when a layer is selected.
|
|
1037
|
+
*
|
|
1038
|
+
* @param {Layer} layer - The layer.
|
|
1039
|
+
* @returns {PropertySection[]} The sections.
|
|
1040
|
+
* @private
|
|
1041
|
+
*/
|
|
1042
|
+
_layerModel = layer => buildLayerModel(layer, {
|
|
1043
|
+
app: this._app,
|
|
1044
|
+
layerActions: {
|
|
1045
|
+
hide: (target, hidden) => this._hideLayer(target, hidden),
|
|
1046
|
+
hidden: target => this._hiddenLayers.has(target)
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
1049
|
+
|
|
954
1050
|
/**
|
|
955
1051
|
* Model builder for the property view when a script class is selected.
|
|
956
1052
|
*
|
|
@@ -1918,12 +2014,14 @@ class Inspector {
|
|
|
1918
2014
|
|
|
1919
2015
|
// body: a tabbed list over the properties, with a draggable splitter
|
|
1920
2016
|
const body = el('div', 'pci-body');
|
|
2017
|
+
this._bodyEl = body;
|
|
1921
2018
|
this._hierarchyEl = el('div', 'pci-hierarchy');
|
|
1922
2019
|
|
|
1923
2020
|
const tabs = el('div', 'pci-tabs');
|
|
2021
|
+
this._tabsEl = tabs;
|
|
1924
2022
|
this._tabButtons = {};
|
|
1925
2023
|
const tabList = [
|
|
1926
|
-
['hierarchy', 'Hierarchy'], ['cameras', 'Cameras'], ['assets', 'Assets'], ['passes', 'Frame graph'], ['perf', 'Performance'],
|
|
2024
|
+
['hierarchy', 'Hierarchy'], ['cameras', 'Cameras'], ['layers', 'Layers'], ['assets', 'Assets'], ['passes', 'Frame graph'], ['perf', 'Performance'],
|
|
1927
2025
|
['targets', 'Render targets'], ['textures', 'Textures'], ['meshes', 'Meshes'], ['materials', 'Materials'], ['scripts', 'Scripts'], ['memory', 'Memory'],
|
|
1928
2026
|
['shaders', 'Shaders'], ['physics', 'Physics']
|
|
1929
2027
|
];
|
|
@@ -2050,7 +2148,8 @@ class Inspector {
|
|
|
2050
2148
|
this._previewNote = el('div', 'pci-note pci-note-info');
|
|
2051
2149
|
this._previewNote.style.display = 'none';
|
|
2052
2150
|
const targetList = el('div', 'pci-list');
|
|
2053
|
-
targetPanel.append(targetBar, this._previewNote, targetList
|
|
2151
|
+
targetPanel.append(targetBar, this._previewNote, targetList,
|
|
2152
|
+
this._snapshotSection('targets', 'Render targets', () => renderTargetSnapshot(this._app.graphicsDevice)));
|
|
2054
2153
|
|
|
2055
2154
|
// textures: the same live preview for the selected texture
|
|
2056
2155
|
const texturePanel = el('div', 'pci-listpanel');
|
|
@@ -2071,14 +2170,14 @@ class Inspector {
|
|
|
2071
2170
|
const assetBar = el('div', 'pci-subbar');
|
|
2072
2171
|
this._assetSort = this._makeSelect(assetBar, 'Sort by', ASSET_SORTS, 'The order of the asset list');
|
|
2073
2172
|
const assetList = el('div', 'pci-list');
|
|
2074
|
-
assetPanel.append(assetBar, assetList);
|
|
2173
|
+
assetPanel.append(assetBar, assetList, this._snapshotSection('assets', 'Assets', () => assetSnapshot(this._app.assets)));
|
|
2075
2174
|
|
|
2076
2175
|
// meshes: a note when some vertex buffers belong to no mesh found, over the list
|
|
2077
2176
|
const meshPanel = el('div', 'pci-listpanel');
|
|
2078
2177
|
this._meshNote = el('div', 'pci-note pci-note-info');
|
|
2079
2178
|
this._meshNote.style.display = 'none';
|
|
2080
2179
|
const meshList = el('div', 'pci-list');
|
|
2081
|
-
meshPanel.append(this._meshNote, meshList);
|
|
2180
|
+
meshPanel.append(this._meshNote, meshList, this._snapshotSection('meshes', 'Meshes', () => meshSnapshot(surveyMeshes(this._app), this._app.assets)));
|
|
2082
2181
|
|
|
2083
2182
|
// materials: a plain list
|
|
2084
2183
|
const materialPanel = el('div', 'pci-listpanel');
|
|
@@ -2100,6 +2199,17 @@ class Inspector {
|
|
|
2100
2199
|
cameraBar.appendChild(this._resetViewBtn);
|
|
2101
2200
|
const cameraList = el('div', 'pci-list');
|
|
2102
2201
|
cameraPanel.append(cameraBar, cameraList);
|
|
2202
|
+
|
|
2203
|
+
// layers: the composition in render order, with a way to show the hidden ones again
|
|
2204
|
+
const layerPanel = el('div', 'pci-listpanel');
|
|
2205
|
+
const layerBar = el('div', 'pci-subbar');
|
|
2206
|
+
this._showLayersBtn = /** @type {HTMLButtonElement} */ (el('button', 'pci-btn', 'Show all'));
|
|
2207
|
+
setTip(this._showLayersBtn, 'Turn the layers hidden here back on');
|
|
2208
|
+
this._showLayersBtn.disabled = true;
|
|
2209
|
+
this._showLayersBtn.addEventListener('click', () => this._showHiddenLayers());
|
|
2210
|
+
layerBar.appendChild(this._showLayersBtn);
|
|
2211
|
+
const layerList = el('div', 'pci-list');
|
|
2212
|
+
layerPanel.append(layerBar, layerList);
|
|
2103
2213
|
this._renderMode.addEventListener('change', () => this._applyRenderMode());
|
|
2104
2214
|
// choosing a camera shows its render mode, and changes nothing until a mode is picked
|
|
2105
2215
|
this._renderScope.addEventListener('change', () => {
|
|
@@ -2116,12 +2226,13 @@ class Inspector {
|
|
|
2116
2226
|
// memory: a group per kind of resource, each opening to its buffers
|
|
2117
2227
|
const memoryPanel = el('div', 'pci-listpanel');
|
|
2118
2228
|
const bufferList = el('div', 'pci-list');
|
|
2119
|
-
memoryPanel.append(bufferList
|
|
2229
|
+
memoryPanel.append(bufferList,
|
|
2230
|
+
this._snapshotSection('memory', 'Memory', () => memorySnapshot(this._app.graphicsDevice, bufferOwners(this._app))));
|
|
2120
2231
|
|
|
2121
2232
|
// shaders: a plain list
|
|
2122
2233
|
const shaderPanel = el('div', 'pci-listpanel');
|
|
2123
2234
|
const shaderList = el('div', 'pci-list');
|
|
2124
|
-
shaderPanel.append(shaderList);
|
|
2235
|
+
shaderPanel.append(shaderList, this._snapshotSection('shaders', 'Shaders', () => shaderSnapshot(this._app.graphicsDevice)));
|
|
2125
2236
|
|
|
2126
2237
|
for (const input of [this._previewToggle, this._previewAttachment, this._previewChannels, this._texturePreviewToggle, this._textureChannels, this._assetSort]) {
|
|
2127
2238
|
input.addEventListener('change', () => this._saveSettings());
|
|
@@ -2183,11 +2294,13 @@ class Inspector {
|
|
|
2183
2294
|
materials: materialPanel,
|
|
2184
2295
|
scripts: scriptPanel,
|
|
2185
2296
|
cameras: cameraPanel,
|
|
2297
|
+
layers: layerPanel,
|
|
2186
2298
|
memory: memoryPanel,
|
|
2187
2299
|
shaders: shaderPanel,
|
|
2188
2300
|
physics: physicsPanel
|
|
2189
2301
|
};
|
|
2190
|
-
this._hierarchyEl.append(tabs, filter, tree, cameraPanel, assetPanel, passPanel, perfPanel, targetPanel, texturePanel, meshPanel, materialPanel, scriptPanel, memoryPanel, shaderPanel, physicsPanel);
|
|
2302
|
+
this._hierarchyEl.append(tabs, filter, tree, cameraPanel, layerPanel, assetPanel, passPanel, perfPanel, targetPanel, texturePanel, meshPanel, materialPanel, scriptPanel, memoryPanel, shaderPanel, physicsPanel);
|
|
2303
|
+
for (const [id, tab] of this._treemapTabs) this._addTreemapTab(id, tab);
|
|
2191
2304
|
|
|
2192
2305
|
const splitter = el('div', 'pci-splitter');
|
|
2193
2306
|
const properties = el('div', 'pci-properties');
|
|
@@ -2312,6 +2425,10 @@ class Inspector {
|
|
|
2312
2425
|
if (this._tab === 'cameras') this._properties.setSubject(camera, this._cameraModel, key);
|
|
2313
2426
|
this._updateStatus();
|
|
2314
2427
|
}, target => this._selectAny(target));
|
|
2428
|
+
this._layerList = new ListView(layerList, (layer, key) => {
|
|
2429
|
+
if (this._tab === 'layers') this._properties.setSubject(layer, this._layerModel, key);
|
|
2430
|
+
this._updateStatus();
|
|
2431
|
+
}, target => this._selectAny(target));
|
|
2315
2432
|
this._scriptList = new ListView(scriptList, (cls, key) => {
|
|
2316
2433
|
if (this._tab === 'scripts') this._properties.setSubject(cls, this._scriptModel, key);
|
|
2317
2434
|
this._updateStatus();
|
|
@@ -2491,7 +2608,8 @@ class Inspector {
|
|
|
2491
2608
|
physicsDraw: this._physicsDraw,
|
|
2492
2609
|
physicsDrawOptions: this._physicsDrawOptions,
|
|
2493
2610
|
hiddenBodies,
|
|
2494
|
-
tab
|
|
2611
|
+
// treemap tabs do not outlive the page, so the tab their snapshots came from is kept
|
|
2612
|
+
tab: this._treemapTabs.get(this._tab)?.source ?? this._tab,
|
|
2495
2613
|
width: this._width,
|
|
2496
2614
|
gpuTimings: this._gpuToggle.checked,
|
|
2497
2615
|
perfInspector: this._perfInspectorToggle.checked,
|
|
@@ -3094,6 +3212,116 @@ class Inspector {
|
|
|
3094
3212
|
if (element.style.display !== display) element.style.display = display;
|
|
3095
3213
|
}
|
|
3096
3214
|
|
|
3215
|
+
/**
|
|
3216
|
+
* Builds the snapshots section of a tab, over the snapshots the tab already has.
|
|
3217
|
+
*
|
|
3218
|
+
* @param {string} tab - The tab.
|
|
3219
|
+
* @param {string} title - Its name.
|
|
3220
|
+
* @param {() => SnapshotContent} measure - Measures what the tab shows, now.
|
|
3221
|
+
* @returns {HTMLElement} The section.
|
|
3222
|
+
* @private
|
|
3223
|
+
*/
|
|
3224
|
+
_snapshotSection(tab, title, measure) {
|
|
3225
|
+
let list = this._snapshots.get(tab);
|
|
3226
|
+
if (!list) {
|
|
3227
|
+
list = createSnapshotList();
|
|
3228
|
+
this._snapshots.set(tab, list);
|
|
3229
|
+
}
|
|
3230
|
+
const panel = new SnapshotPanel(list, title, measure, data => this._showTreemap(tab, data));
|
|
3231
|
+
this._snapshotPanels[tab] = panel;
|
|
3232
|
+
return panel.el;
|
|
3233
|
+
}
|
|
3234
|
+
|
|
3235
|
+
/**
|
|
3236
|
+
* Shows a treemap of snapshots in a tab of its own, added at the end of the tab bar, or switches
|
|
3237
|
+
* to the tab already showing them. Several can be open at once.
|
|
3238
|
+
*
|
|
3239
|
+
* @param {string} source - The tab the snapshots were captured on.
|
|
3240
|
+
* @param {TreemapData} data - The snapshots.
|
|
3241
|
+
* @returns {string} The id of the treemap's tab.
|
|
3242
|
+
* @private
|
|
3243
|
+
*/
|
|
3244
|
+
_showTreemap(source, data) {
|
|
3245
|
+
const key = `${source}:${data.from?.number ?? ''}:${data.to.number}`;
|
|
3246
|
+
for (const [id, tab] of this._treemapTabs) {
|
|
3247
|
+
if (tab.key === key) {
|
|
3248
|
+
this._setTab(/** @type {any} */ (id));
|
|
3249
|
+
return id;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
const id = `treemap${this._nextTreemap++}`;
|
|
3253
|
+
const tab = { source, key, data, view: null };
|
|
3254
|
+
this._treemapTabs.set(id, tab);
|
|
3255
|
+
this._addTreemapTab(id, tab);
|
|
3256
|
+
this._setTab(/** @type {any} */ (id));
|
|
3257
|
+
return id;
|
|
3258
|
+
}
|
|
3259
|
+
|
|
3260
|
+
/**
|
|
3261
|
+
* Builds the button and the panel of a treemap tab. The button's cross closes the tab, as does
|
|
3262
|
+
* a middle click on it.
|
|
3263
|
+
*
|
|
3264
|
+
* @param {string} id - The tab's id.
|
|
3265
|
+
* @param {{ data: TreemapData, view: TreemapView|null }} tab - The tab.
|
|
3266
|
+
* @private
|
|
3267
|
+
*/
|
|
3268
|
+
_addTreemapTab(id, tab) {
|
|
3269
|
+
// a box shows what it measured in the tab listing it; when that tab no longer lists it,
|
|
3270
|
+
// the treemap stays, to say so
|
|
3271
|
+
const view = new TreemapView(tab.data, {
|
|
3272
|
+
label: (target) => {
|
|
3273
|
+
const where = this._tabOf(target);
|
|
3274
|
+
return where ? `the ${this._tabButtons[where].textContent} tab` : null;
|
|
3275
|
+
},
|
|
3276
|
+
open: (target) => {
|
|
3277
|
+
if (this._selectAny(target)) return true;
|
|
3278
|
+
this._setTab(/** @type {any} */ (id));
|
|
3279
|
+
return false;
|
|
3280
|
+
}
|
|
3281
|
+
});
|
|
3282
|
+
tab.view = view;
|
|
3283
|
+
view.el.style.display = 'none';
|
|
3284
|
+
this._hierarchyEl.appendChild(view.el);
|
|
3285
|
+
this._panels[id] = view.el;
|
|
3286
|
+
|
|
3287
|
+
const button = el('button', 'pci-tab pci-tab-closable', view.title);
|
|
3288
|
+
setTip(button, `A treemap of ${tab.data.from ? 'two snapshots' : 'a snapshot'} of the ${tab.data.tab} tab. A middle click closes it`);
|
|
3289
|
+
const close = el('span', 'pci-tab-close', '×');
|
|
3290
|
+
setTip(close, 'Close this tab');
|
|
3291
|
+
close.addEventListener('click', (e) => {
|
|
3292
|
+
e.stopPropagation();
|
|
3293
|
+
this._closeTreemap(id);
|
|
3294
|
+
});
|
|
3295
|
+
button.appendChild(close);
|
|
3296
|
+
button.addEventListener('click', () => this._setTab(/** @type {any} */ (id)));
|
|
3297
|
+
// a middle press would start the browser's scrolling
|
|
3298
|
+
button.addEventListener('mousedown', (e) => {
|
|
3299
|
+
if (e.button === 1) e.preventDefault();
|
|
3300
|
+
});
|
|
3301
|
+
button.addEventListener('auxclick', (e) => {
|
|
3302
|
+
if (e.button === 1) this._closeTreemap(id);
|
|
3303
|
+
});
|
|
3304
|
+
this._tabsEl.appendChild(button);
|
|
3305
|
+
this._tabButtons[id] = button;
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
/**
|
|
3309
|
+
* Closes a treemap tab, going back to the tab its snapshots came from when it was shown.
|
|
3310
|
+
*
|
|
3311
|
+
* @param {string} id - The tab's id.
|
|
3312
|
+
* @private
|
|
3313
|
+
*/
|
|
3314
|
+
_closeTreemap(id) {
|
|
3315
|
+
const tab = this._treemapTabs.get(id);
|
|
3316
|
+
if (!tab) return;
|
|
3317
|
+
this._treemapTabs.delete(id);
|
|
3318
|
+
tab.view?.el.remove();
|
|
3319
|
+
this._tabButtons[id]?.remove();
|
|
3320
|
+
delete this._tabButtons[id];
|
|
3321
|
+
delete this._panels[id];
|
|
3322
|
+
if (this._tab === id) this._setTab(/** @type {any} */ (tab.source));
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3097
3325
|
/**
|
|
3098
3326
|
* @param {HTMLElement} parent - The bar to add the toggle to.
|
|
3099
3327
|
* @param {string} label - The label.
|
|
@@ -3253,15 +3481,18 @@ class Inspector {
|
|
|
3253
3481
|
/**
|
|
3254
3482
|
* Switches the list tab and points the property view at that tab's selection.
|
|
3255
3483
|
*
|
|
3256
|
-
* @param {'hierarchy'|'cameras'|'assets'|'passes'|'perf'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'} tab - The tab.
|
|
3484
|
+
* @param {'hierarchy'|'cameras'|'layers'|'assets'|'passes'|'perf'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'|`treemap${number}`} tab - The tab.
|
|
3257
3485
|
* @private
|
|
3258
3486
|
*/
|
|
3259
3487
|
_setTab(tab) {
|
|
3260
3488
|
this._tab = tab;
|
|
3261
3489
|
this._menu?.hide();
|
|
3490
|
+
const treemap = this._treemapTabs.get(tab);
|
|
3262
3491
|
this._filterBy.style.display = tab === 'hierarchy' ? '' : 'none';
|
|
3263
|
-
// the Performance
|
|
3264
|
-
this._filterEl.style.display = tab === 'perf' ? 'none' : '';
|
|
3492
|
+
// the Performance and treemap tabs have no list to filter
|
|
3493
|
+
this._filterEl.style.display = tab === 'perf' || treemap ? 'none' : '';
|
|
3494
|
+
// a treemap has the whole height, the properties put away while it shows
|
|
3495
|
+
this._bodyEl.classList.toggle('pci-full', !!treemap);
|
|
3265
3496
|
this._hierarchyEl.classList.toggle('pci-tall', tab === 'perf');
|
|
3266
3497
|
if (tab === 'perf') this._perfCharts.invalidate();
|
|
3267
3498
|
this._updateFilterHint();
|
|
@@ -3271,6 +3502,8 @@ class Inspector {
|
|
|
3271
3502
|
for (const [id, panel] of Object.entries(this._panels)) {
|
|
3272
3503
|
panel.style.display = id === tab ? '' : 'none';
|
|
3273
3504
|
}
|
|
3505
|
+
// drawn once shown, when it has a size
|
|
3506
|
+
treemap?.view?.render();
|
|
3274
3507
|
// measured with the tab's panel shown
|
|
3275
3508
|
if (tab === 'perf') this._fitTop();
|
|
3276
3509
|
this._refreshLists(false);
|
|
@@ -3292,6 +3525,14 @@ class Inspector {
|
|
|
3292
3525
|
_refreshLists(capture) {
|
|
3293
3526
|
const device = this._app.graphicsDevice;
|
|
3294
3527
|
|
|
3528
|
+
const treemap = this._treemapTabs.get(this._tab);
|
|
3529
|
+
if (treemap) {
|
|
3530
|
+
// a treemap holds still: it is drawn again only when its tab changes size
|
|
3531
|
+
treemap.view?.fit();
|
|
3532
|
+
this._updateStatus();
|
|
3533
|
+
return;
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3295
3536
|
if (this._tab === 'hierarchy') {
|
|
3296
3537
|
this._hierarchy.refresh();
|
|
3297
3538
|
} else if (this._tab === 'physics') {
|
|
@@ -3342,6 +3583,13 @@ class Inspector {
|
|
|
3342
3583
|
if (camera !== this._properties.subject) {
|
|
3343
3584
|
this._properties.setSubject(camera, this._cameraModel, this._cameraList.selectedKey);
|
|
3344
3585
|
}
|
|
3586
|
+
} else if (this._tab === 'layers') {
|
|
3587
|
+
this._pruneHiddenLayers();
|
|
3588
|
+
this._layerList.setRows(layerRows(this._app, layer => this._hiddenLayers.has(layer)));
|
|
3589
|
+
const layer = this._layerList.selected;
|
|
3590
|
+
if (layer !== this._properties.subject) {
|
|
3591
|
+
this._properties.setSubject(layer, this._layerModel, this._layerList.selectedKey);
|
|
3592
|
+
}
|
|
3345
3593
|
} else if (this._tab === 'scripts') {
|
|
3346
3594
|
this._scriptList.setRows(scriptListRows(surveyScripts(this._app)));
|
|
3347
3595
|
const cls = this._scriptList.selected;
|
|
@@ -3412,6 +3660,7 @@ class Inspector {
|
|
|
3412
3660
|
this._materialList.filter = names;
|
|
3413
3661
|
this._scriptList.filter = names;
|
|
3414
3662
|
this._cameraList.filter = names;
|
|
3663
|
+
this._layerList.filter = names;
|
|
3415
3664
|
this._bodyList.filter = names;
|
|
3416
3665
|
this._refreshLists(false);
|
|
3417
3666
|
// the instances listed under a forward pass narrow with the filter too
|
|
@@ -3432,6 +3681,7 @@ class Inspector {
|
|
|
3432
3681
|
materials: this._materialList,
|
|
3433
3682
|
scripts: this._scriptList,
|
|
3434
3683
|
cameras: this._cameraList,
|
|
3684
|
+
layers: this._layerList,
|
|
3435
3685
|
memory: this._bufferList,
|
|
3436
3686
|
assets: this._assetList,
|
|
3437
3687
|
physics: this._bodyList
|
|
@@ -3726,6 +3976,7 @@ class Inspector {
|
|
|
3726
3976
|
if (obj instanceof Shader) return buildShaderModel(obj);
|
|
3727
3977
|
if (obj instanceof Asset) return buildAssetModel(obj, ctx);
|
|
3728
3978
|
if (isScriptClass(obj)) return buildScriptModel(/** @type {Function} */ (obj), ctx);
|
|
3979
|
+
if (obj instanceof Layer) return this._layerModel(obj);
|
|
3729
3980
|
if (obj instanceof Material) return buildMaterialModel(obj, ctx);
|
|
3730
3981
|
if (obj instanceof Mesh) return buildMeshModel(obj, ctx);
|
|
3731
3982
|
if (bufferKind(obj)) return buildBufferModel(obj, ctx);
|
|
@@ -3748,45 +3999,45 @@ class Inspector {
|
|
|
3748
3999
|
if (entry) this._passList.selectItem(entry.pass);
|
|
3749
4000
|
}
|
|
3750
4001
|
|
|
4002
|
+
/**
|
|
4003
|
+
* @param {*} target - An object.
|
|
4004
|
+
* @returns {'hierarchy'|'targets'|'passes'|'textures'|'shaders'|'assets'|'scripts'|'layers'|'materials'|'meshes'|'memory'|null}
|
|
4005
|
+
* The tab that lists objects of its kind, or null when none does.
|
|
4006
|
+
* @private
|
|
4007
|
+
*/
|
|
4008
|
+
_tabOf(target) {
|
|
4009
|
+
if (target instanceof GraphNode) return 'hierarchy';
|
|
4010
|
+
if (target instanceof RenderTarget) return 'targets';
|
|
4011
|
+
if (target instanceof FramePass) return 'passes';
|
|
4012
|
+
if (target instanceof Texture) return 'textures';
|
|
4013
|
+
if (target instanceof Shader) return 'shaders';
|
|
4014
|
+
if (target instanceof Asset) return 'assets';
|
|
4015
|
+
if (isScriptClass(target)) return 'scripts';
|
|
4016
|
+
if (target instanceof Layer) return 'layers';
|
|
4017
|
+
if (target instanceof Material) return 'materials';
|
|
4018
|
+
if (target instanceof Mesh) return 'meshes';
|
|
4019
|
+
if (bufferKind(target)) return 'memory';
|
|
4020
|
+
return null;
|
|
4021
|
+
}
|
|
4022
|
+
|
|
3751
4023
|
/**
|
|
3752
4024
|
* Reveals a linked object in the tab that lists it: nodes in the hierarchy, passes in the frame
|
|
3753
4025
|
* graph, render targets in their list.
|
|
3754
4026
|
*
|
|
3755
4027
|
* @param {*} target - The object.
|
|
4028
|
+
* @returns {boolean} Whether the tab lists it, as one listing what is on the device does not
|
|
4029
|
+
* once the object is destroyed.
|
|
3756
4030
|
* @private
|
|
3757
4031
|
*/
|
|
3758
4032
|
_selectAny(target) {
|
|
3759
|
-
|
|
3760
|
-
|
|
4033
|
+
const tab = this._tabOf(target);
|
|
4034
|
+
if (!tab) return false;
|
|
4035
|
+
this._setTab(tab);
|
|
4036
|
+
if (tab === 'hierarchy') {
|
|
3761
4037
|
this._hierarchy.select(target);
|
|
3762
|
-
|
|
3763
|
-
this._setTab('targets');
|
|
3764
|
-
this._targetList.selectItem(target);
|
|
3765
|
-
} else if (target instanceof FramePass) {
|
|
3766
|
-
this._setTab('passes');
|
|
3767
|
-
this._passList.selectItem(target);
|
|
3768
|
-
} else if (target instanceof Texture) {
|
|
3769
|
-
this._setTab('textures');
|
|
3770
|
-
this._textureList.selectItem(target);
|
|
3771
|
-
} else if (target instanceof Shader) {
|
|
3772
|
-
this._setTab('shaders');
|
|
3773
|
-
this._shaderList.selectItem(target);
|
|
3774
|
-
} else if (target instanceof Asset) {
|
|
3775
|
-
this._setTab('assets');
|
|
3776
|
-
this._assetList.selectItem(target);
|
|
3777
|
-
} else if (isScriptClass(target)) {
|
|
3778
|
-
this._setTab('scripts');
|
|
3779
|
-
this._scriptList.selectItem(target);
|
|
3780
|
-
} else if (target instanceof Material) {
|
|
3781
|
-
this._setTab('materials');
|
|
3782
|
-
this._materialList.selectItem(target);
|
|
3783
|
-
} else if (target instanceof Mesh) {
|
|
3784
|
-
this._setTab('meshes');
|
|
3785
|
-
this._meshList.selectItem(target);
|
|
3786
|
-
} else if (bufferKind(target)) {
|
|
3787
|
-
this._setTab('memory');
|
|
3788
|
-
this._bufferList.selectItem(target);
|
|
4038
|
+
return true;
|
|
3789
4039
|
}
|
|
4040
|
+
return this._tabLists()[tab].selectItem(target);
|
|
3790
4041
|
}
|
|
3791
4042
|
|
|
3792
4043
|
/**
|
|
@@ -3925,7 +4176,10 @@ class Inspector {
|
|
|
3925
4176
|
let counts = '';
|
|
3926
4177
|
let selected = '';
|
|
3927
4178
|
|
|
3928
|
-
switch (this._tab) {
|
|
4179
|
+
switch (this._treemapTabs.has(this._tab) ? 'treemap' : this._tab) {
|
|
4180
|
+
case 'treemap':
|
|
4181
|
+
counts = this._treemapTabs.get(this._tab).data.measure;
|
|
4182
|
+
break;
|
|
3929
4183
|
case 'passes': {
|
|
3930
4184
|
const gpu = this._frame?.frameTime;
|
|
3931
4185
|
// WebGL times the frame with a single query; only WebGPU timestamps each pass
|
|
@@ -3990,6 +4244,15 @@ class Inspector {
|
|
|
3990
4244
|
selected = this._cameraList.selected?.entity.name ?? '';
|
|
3991
4245
|
break;
|
|
3992
4246
|
}
|
|
4247
|
+
case 'layers': {
|
|
4248
|
+
const subLayers = collectSubLayers(this._app.scene?.layers);
|
|
4249
|
+
const layers = new Set(subLayers.map(sub => sub.layer));
|
|
4250
|
+
const rendering = subLayers.filter(sub => sub.enabled && sub.layer.cameras.length > 0).length;
|
|
4251
|
+
counts = `${layers.size} layers · ${subLayers.length} in the composition · ${rendering} rendering`;
|
|
4252
|
+
if (this._hiddenLayers.size) counts += ` · ${this._hiddenLayers.size} hidden`;
|
|
4253
|
+
selected = this._layerList.selected?.name ?? '';
|
|
4254
|
+
break;
|
|
4255
|
+
}
|
|
3993
4256
|
case 'scripts': {
|
|
3994
4257
|
const survey = surveyScripts(this._app);
|
|
3995
4258
|
const instances = [...survey.values()].reduce((sum, script) => sum + script.instances.length, 0);
|
|
@@ -4255,9 +4518,66 @@ class Inspector {
|
|
|
4255
4518
|
this._stopFly();
|
|
4256
4519
|
this._setTransformMode(null);
|
|
4257
4520
|
this._resetRenderOverrides();
|
|
4521
|
+
this._showHiddenLayers();
|
|
4258
4522
|
this._modeEl.textContent = '';
|
|
4259
4523
|
}
|
|
4260
4524
|
|
|
4525
|
+
/**
|
|
4526
|
+
* Hides a layer from the view by turning it off, or turns a layer hidden here back on. Only a
|
|
4527
|
+
* layer the app has on can be hidden, so showing it again restores what the app had.
|
|
4528
|
+
*
|
|
4529
|
+
* @param {Layer} layer - The layer.
|
|
4530
|
+
* @param {boolean} hidden - Whether to hide it.
|
|
4531
|
+
* @private
|
|
4532
|
+
*/
|
|
4533
|
+
_hideLayer(layer, hidden) {
|
|
4534
|
+
if (hidden) {
|
|
4535
|
+
if (!layer.enabled || this._hiddenLayers.has(layer)) return;
|
|
4536
|
+
this._hiddenLayers.add(layer);
|
|
4537
|
+
layer.enabled = false;
|
|
4538
|
+
} else {
|
|
4539
|
+
if (!this._hiddenLayers.delete(layer)) return;
|
|
4540
|
+
layer.enabled = true;
|
|
4541
|
+
}
|
|
4542
|
+
this._afterLayersChanged();
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
|
+
/**
|
|
4546
|
+
* Turns every layer hidden here back on.
|
|
4547
|
+
*
|
|
4548
|
+
* @private
|
|
4549
|
+
*/
|
|
4550
|
+
_showHiddenLayers() {
|
|
4551
|
+
if (this._hiddenLayers.size === 0) return;
|
|
4552
|
+
for (const layer of this._hiddenLayers) layer.enabled = true;
|
|
4553
|
+
this._hiddenLayers.clear();
|
|
4554
|
+
this._afterLayersChanged();
|
|
4555
|
+
}
|
|
4556
|
+
|
|
4557
|
+
/**
|
|
4558
|
+
* Forgets the hidden layers the app has turned back on itself, or taken out of the composition,
|
|
4559
|
+
* so the panel never turns on a layer it no longer hides.
|
|
4560
|
+
*
|
|
4561
|
+
* @private
|
|
4562
|
+
*/
|
|
4563
|
+
_pruneHiddenLayers() {
|
|
4564
|
+
const composition = this._app.scene?.layers;
|
|
4565
|
+
for (const layer of this._hiddenLayers) {
|
|
4566
|
+
if (layer.enabled || !composition?.layerList.includes(layer)) this._hiddenLayers.delete(layer);
|
|
4567
|
+
}
|
|
4568
|
+
if (this._showLayersBtn) this._showLayersBtn.disabled = this._hiddenLayers.size === 0;
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
/**
|
|
4572
|
+
* @private
|
|
4573
|
+
*/
|
|
4574
|
+
_afterLayersChanged() {
|
|
4575
|
+
if (this._showLayersBtn) this._showLayersBtn.disabled = this._hiddenLayers.size === 0;
|
|
4576
|
+
this._refreshLists(false);
|
|
4577
|
+
this._properties.refresh();
|
|
4578
|
+
this._updateStatus();
|
|
4579
|
+
}
|
|
4580
|
+
|
|
4261
4581
|
/**
|
|
4262
4582
|
* Puts back the shader pass each camera had before the panel changed it, and turns wireframe
|
|
4263
4583
|
* off.
|