@playcanvas/inspector 0.3.0 → 0.4.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.
@@ -14,6 +14,9 @@ import { setTip } from './tooltip.js';
14
14
  * @ignore
15
15
  * @property {string} title - What is copied, as the menu names it.
16
16
  * @property {(options: CopyOptions) => CopyResult} copy - Makes the copy.
17
+ * @property {boolean} [plain] - Whether it has no links to follow, so the menu offers no deeper
18
+ * copies, as the figures of the Performance tab.
19
+ * @property {() => string} [csv] - Makes the copy as CSV, for a series of frames.
17
20
  */
18
21
 
19
22
  /**
package/src/styles.js CHANGED
@@ -32,7 +32,11 @@ const ICONS = {
32
32
  close: '<path d="M18 6 6 18M6 6l12 12"/>',
33
33
  translate: '<path d="M12 3v18M3 12h18"/><path d="m9 6 3-3 3 3"/><path d="m9 18 3 3 3-3"/><path d="m6 9-3 3 3 3"/><path d="m18 9 3 3-3 3"/>',
34
34
  rotate: '<path d="M20 12a8 8 0 1 1-2.34-5.66"/><path d="M20 3v4h-4"/>',
35
- scale: '<rect x="3" y="11" width="10" height="10" rx="1"/><path d="m13 11 8-8"/><path d="M15 3h6v6"/>'
35
+ scale: '<rect x="3" y="11" width="10" height="10" rx="1"/><path d="m13 11 8-8"/><path d="M15 3h6v6"/>',
36
+ // recording, as the browser's own profiler shows it: a ring around a dot to record, red while
37
+ // recording, and the sign for none to clear
38
+ record: '<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="12" r="4" fill="black" stroke="none"/>',
39
+ clear: '<circle cx="12" cy="12" r="8.5"/><path d="M18 6 6 18"/>'
36
40
  };
37
41
 
38
42
  /**
@@ -553,6 +557,177 @@ ${ICON_RULES}
553
557
  opacity: 0.45;
554
558
  }
555
559
 
560
+ /* the charts of the Performance tab want more room than a list, until the splitter is dragged */
561
+ .pci-hierarchy.pci-tall {
562
+ flex-basis: 68%;
563
+ }
564
+
565
+ .pci-group {
566
+ display: inline-flex;
567
+ align-items: center;
568
+ gap: 4px;
569
+ }
570
+
571
+ /* an icon button the size of the text buttons beside it, with their backing */
572
+ .pci-icon-btn.pci-small {
573
+ width: 26px;
574
+ height: 22px;
575
+ border-radius: 6px;
576
+ background: rgba(255, 255, 255, 0.07);
577
+ }
578
+
579
+ .pci-icon-btn.pci-small::before {
580
+ width: 14px;
581
+ height: 14px;
582
+ }
583
+
584
+ .pci-btn.pci-record.pci-active,
585
+ .pci-btn.pci-record.pci-active:not(:disabled):hover {
586
+ background: rgba(241, 76, 76, 0.18);
587
+ color: #ff5a52;
588
+ }
589
+
590
+ /* shrinks with the part above the splitter, scrolling its charts */
591
+ .pci-perf-charts {
592
+ flex: 1 1 auto;
593
+ position: relative;
594
+ min-height: 60px;
595
+ margin: 6px 8px 0;
596
+ overflow-x: hidden;
597
+ overflow-y: auto;
598
+ cursor: crosshair;
599
+ touch-action: none;
600
+ }
601
+
602
+ /* the Performance tab, which places the hover box of its charts */
603
+ .pci-perf {
604
+ position: relative;
605
+ }
606
+
607
+ /* the frames in view while zoomed in, under the plot */
608
+ .pci-perf-hscroll {
609
+ flex: 0 0 auto;
610
+ position: relative;
611
+ height: 8px;
612
+ margin: 4px 8px 0;
613
+ background: rgba(255, 255, 255, 0.05);
614
+ border-radius: 4px;
615
+ cursor: pointer;
616
+ touch-action: none;
617
+ }
618
+
619
+ .pci-perf-hscroll-thumb {
620
+ position: absolute;
621
+ top: 0;
622
+ bottom: 0;
623
+ min-width: 12px;
624
+ background: rgba(255, 255, 255, 0.3);
625
+ border-radius: 4px;
626
+ cursor: grab;
627
+ }
628
+
629
+ .pci-perf-hscroll-thumb:hover {
630
+ background: rgba(255, 255, 255, 0.45);
631
+ }
632
+
633
+ .pci-perf-hscroll.pci-inactive,
634
+ .pci-perf-hscroll.pci-inactive .pci-perf-hscroll-thumb {
635
+ cursor: default;
636
+ }
637
+
638
+ .pci-perf-hscroll.pci-inactive .pci-perf-hscroll-thumb {
639
+ background: rgba(255, 255, 255, 0.08);
640
+ }
641
+
642
+ .pci-perf-timeline {
643
+ flex: 0 0 auto;
644
+ position: relative;
645
+ margin: 6px 8px;
646
+ border-top: 1px solid var(--pci-border);
647
+ }
648
+
649
+ .pci-perf-charts canvas,
650
+ .pci-perf-timeline canvas {
651
+ position: absolute;
652
+ top: 0;
653
+ left: 0;
654
+ width: 100%;
655
+ height: 100%;
656
+ display: block;
657
+ }
658
+
659
+ /* the marks over the charts, redrawn alone as the pointer moves; the charts below take the pointer */
660
+ .pci-perf-charts canvas.pci-perf-overlay {
661
+ pointer-events: none;
662
+ }
663
+
664
+ /* what the pointer is over in the charts, beside it */
665
+ .pci-perf-hover {
666
+ display: none;
667
+ position: absolute;
668
+ z-index: 2;
669
+ max-width: 320px;
670
+ padding: 5px 8px;
671
+ background: var(--pci-raised);
672
+ color: var(--pci-text);
673
+ border: 1px solid var(--pci-border-strong);
674
+ border-radius: 6px;
675
+ box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
676
+ font-size: 11px;
677
+ line-height: 1.45;
678
+ pointer-events: none;
679
+ }
680
+
681
+ .pci-perf-hover-line {
682
+ display: flex;
683
+ align-items: center;
684
+ white-space: nowrap;
685
+ }
686
+
687
+ .pci-perf-hover-line.pci-indent {
688
+ padding-left: 10px;
689
+ }
690
+
691
+ .pci-perf-hover-line.pci-strong {
692
+ margin: 0 -4px;
693
+ padding-right: 4px;
694
+ border-radius: 3px;
695
+ background: rgba(255, 255, 255, 0.1);
696
+ color: #ffffff;
697
+ font-weight: 600;
698
+ }
699
+
700
+ .pci-perf-hover-line.pci-nested {
701
+ padding-left: 25px;
702
+ }
703
+
704
+ .pci-perf-hover-line.pci-muted {
705
+ color: #93a2a6;
706
+ }
707
+
708
+ .pci-perf-hover-line.pci-indent.pci-strong {
709
+ padding-left: 14px;
710
+ }
711
+
712
+ .pci-perf-hover-line.pci-wrap {
713
+ white-space: normal;
714
+ overflow-wrap: anywhere;
715
+ width: 280px;
716
+ }
717
+
718
+ .pci-perf-hover-line.pci-wrap .pci-perf-swatch {
719
+ align-self: flex-start;
720
+ margin-top: 4px;
721
+ }
722
+
723
+ .pci-perf-swatch {
724
+ flex: 0 0 auto;
725
+ width: 9px;
726
+ height: 9px;
727
+ margin-right: 6px;
728
+ border-radius: 2px;
729
+ }
730
+
556
731
  .pci-cell-toggle {
557
732
  flex: 0 0 auto;
558
733
  width: 12px;
@@ -827,7 +1002,10 @@ ${ICON_RULES}
827
1002
  color: var(--pci-text-faint);
828
1003
  }
829
1004
 
1005
+ /* above anything of the part over it that overflows, so it can always be dragged back */
830
1006
  .pci-splitter {
1007
+ position: relative;
1008
+ z-index: 2;
831
1009
  flex: 0 0 5px;
832
1010
  background: var(--pci-raised);
833
1011
  border-top: 1px solid var(--pci-border-strong);
@@ -70,6 +70,14 @@ export class EntityInspector extends Script {
70
70
  * @type {string}
71
71
  */
72
72
  stepKey: string;
73
+ /**
74
+ * Whether to start recording frames for the Performance tab as soon as the panel is created,
75
+ * capturing the first frames of the scene.
76
+ *
77
+ * @attribute
78
+ * @type {boolean}
79
+ */
80
+ record: boolean;
73
81
  /**
74
82
  * @type {Inspector|null}
75
83
  * @private
@@ -151,6 +151,13 @@ export function captureFrameGraph(app: AppBase): FrameSnapshot;
151
151
  * @returns {ListRow[]} The rows.
152
152
  */
153
153
  export function passRows(frame: FrameSnapshot, device: GraphicsDevice): ListRow[];
154
+ /**
155
+ * Mirrors how the GPU profiler keys its per-pass timings.
156
+ *
157
+ * @param {FramePass} pass - The pass.
158
+ * @returns {string} The profiler name.
159
+ */
160
+ export function profilerName(pass: FramePass): string;
154
161
  import { RenderPassForward } from 'playcanvas';
155
162
  import { FramePass } from 'playcanvas';
156
163
  import type { PropertySection } from './model.js';
@@ -39,6 +39,12 @@ export type InspectorOptions = {
39
39
  * cannot switch itself off. Defaults to null.
40
40
  */
41
41
  lockedNode?: GraphNode | null;
42
+ /**
43
+ * - Whether to start recording frames for the Performance tab right
44
+ * away, as if Record were pressed, so the capture begins with the first frame the app runs after
45
+ * the inspector is created. Defaults to false. See {@link Inspector#recording}.
46
+ */
47
+ record?: boolean;
42
48
  /**
43
49
  * - Called with the new visibility
44
50
  * whenever the panel is shown or hidden, whether through {@link Inspector#visible}, the toggle key
@@ -48,8 +54,11 @@ export type InspectorOptions = {
48
54
  /**
49
55
  * - The local storage key the panel's settings are kept
50
56
  * under, so they survive a reload or a restart of the app: the physics drawing switch and options,
51
- * the bodies excluded from it (by entity path), the active tab, the panel width and the GPU
52
- * timings switch. Stored settings take precedence over the defaults given here. Defaults to
57
+ * the bodies excluded from it (by entity path), the active tab, the panel width, the GPU
58
+ * timings switch, and on the Performance tab the script timing switch, whether the CPU chart
59
+ * includes the inspector's time, the charts collapsed and lines hidden, and the script types the
60
+ * Scripts chart shows. Stored settings take
61
+ * precedence over the defaults given here. Defaults to
53
62
  * 'pc-inspector'; null keeps nothing.
54
63
  */
55
64
  storageKey?: string | null;
@@ -102,7 +111,7 @@ export type InspectorPhysicsDrawOptions = {
102
111
  range?: number;
103
112
  };
104
113
  /**
105
- * An in-page inspector for a running application. It docks a panel over the canvas with twelve
114
+ * An in-page inspector for a running application. It docks a panel over the canvas with thirteen
106
115
  * tabs above a live property view of whatever is selected:
107
116
  *
108
117
  * - Hierarchy: the entity tree. The property view shows the node's transform, every component it
@@ -117,6 +126,12 @@ export type InspectorPhysicsDrawOptions = {
117
126
  * prints them, with the layer steps of forward passes, the light of shadow passes and optional
118
127
  * GPU timings. Render target cells link to the next tab. With the debug engine, the debug frame
119
128
  * draws a forward pass only up to a chosen draw, stepped one draw at a time with the arrow keys.
129
+ * - Performance: frames recorded while Record is on, up to the last 1000, charted over
130
+ * the whole capture: the frame interval, the CPU time on the main thread by phase, the GPU time,
131
+ * the draw calls and video memory, and the events of each frame, such as shaders compiled and
132
+ * the main thread blocked. Clicking a frame shows it on a timeline of its own and everything
133
+ * recorded for it in the property view; dragging selects frames to compare their figures. The
134
+ * inspector's own time is told apart from the app's.
120
135
  * - Render targets: every render target on the device including the backbuffer, with its
121
136
  * attachments and the passes that rendered into it this frame, linking back to the frame graph.
122
137
  * The selected target's attachment can be previewed live in a corner of the viewport.
@@ -341,10 +356,77 @@ export class Inspector {
341
356
  /** @private */
342
357
  private _nextPropertyRefresh;
343
358
  /**
344
- * @type {'hierarchy'|'cameras'|'assets'|'passes'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'}
359
+ * @type {'hierarchy'|'cameras'|'assets'|'passes'|'perf'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'}
345
360
  * @private
346
361
  */
347
362
  private _tab;
363
+ /**
364
+ * The frames recorded for the Performance tab. Hooked into the app only while recording.
365
+ *
366
+ * @type {PerfCapture}
367
+ * @private
368
+ */
369
+ private _perf;
370
+ /**
371
+ * The charts of the Performance tab, and the frame they show.
372
+ *
373
+ * @type {PerfCharts}
374
+ * @private
375
+ */
376
+ private _perfCharts;
377
+ /**
378
+ * @type {HTMLButtonElement}
379
+ * @private
380
+ */
381
+ private _perfRecordBtn;
382
+ /**
383
+ * Shows the newest frame, and keeps following it as frames are recorded.
384
+ *
385
+ * @type {HTMLButtonElement}
386
+ * @private
387
+ */
388
+ private _perfLastBtn;
389
+ /**
390
+ * The GPU timings switch of the Performance tab, kept in step with the Frame graph's.
391
+ *
392
+ * @type {HTMLInputElement}
393
+ * @private
394
+ */
395
+ private _perfGpuToggle;
396
+ /**
397
+ * Whether the CPU chart includes the inspector's own time.
398
+ *
399
+ * @type {HTMLInputElement}
400
+ * @private
401
+ */
402
+ private _perfInspectorToggle;
403
+ /**
404
+ * Whether to time each script type while recording.
405
+ *
406
+ * @type {HTMLInputElement}
407
+ * @private
408
+ */
409
+ private _perfScriptsToggle;
410
+ /**
411
+ * @type {HTMLElement}
412
+ * @private
413
+ */
414
+ private _perfNote;
415
+ /**
416
+ * The filter bar, which the Performance tab has no list for.
417
+ *
418
+ * @type {HTMLElement}
419
+ * @private
420
+ */
421
+ private _filterEl;
422
+ /**
423
+ * Model builder for the property view on the Performance tab: the frames the charts show.
424
+ *
425
+ * @param {PerfCharts} charts - The charts.
426
+ * @returns {PropertySection[]} The sections.
427
+ * @private
428
+ */
429
+ private _perfModel;
348
430
  /**
349
431
  * @type {FrameSnapshot|null}
350
432
  * @private
@@ -874,6 +956,19 @@ export class Inspector {
874
956
  */
875
957
  set visible(value: boolean);
876
958
  get visible(): boolean;
959
+ /**
960
+ * Whether frames are being recorded for the Performance tab, as its Record button shows. Set it
961
+ * to start or stop a capture from code, such as around a part of the app to profile. Starting
962
+ * adds to the frames kept, up to the last 1000; the tab's Clear button forgets them.
963
+ *
964
+ * @type {boolean}
965
+ * @example
966
+ * inspector.recording = true;
967
+ * await loadLevel();
968
+ * inspector.recording = false;
969
+ */
970
+ set recording(value: boolean);
971
+ get recording(): boolean;
877
972
  /**
878
973
  * Advances the app by one frame. Only meaningful while paused.
879
974
  */
@@ -898,10 +993,18 @@ export class Inspector {
898
993
  */
899
994
  private _dockBack;
900
995
  /**
996
+ * Runs the panel's work for the frame, timed so a capture can tell it apart from the app's own:
997
+ * it runs inside the app's update.
998
+ *
901
999
  * @param {number} dt - The frame delta, scaled by the app time scale.
902
1000
  * @private
903
1001
  */
904
1002
  private _onUpdate;
1003
+ /**
1004
+ * @param {number} dt - The frame delta, scaled by the app time scale.
1005
+ * @private
1006
+ */
1007
+ private _updatePanel;
905
1008
  /**
906
1009
  * Draws the physics world for this frame. Runs from the app's update event, which fires after
907
1010
  * the rigid body system has stepped, so the drawn world matches the frame being rendered.
@@ -1123,10 +1226,67 @@ export class Inspector {
1123
1226
  * @private
1124
1227
  */
1125
1228
  private _makeToggle;
1229
+ /**
1230
+ * @returns {number} The least height of the part above the splitter. The Performance tab keeps
1231
+ * room for what does not shrink, its controls and its timeline, and a little of its charts,
1232
+ * which scroll; less would spill over the splitter.
1233
+ * @private
1234
+ */
1235
+ private _topMinHeight;
1236
+ /**
1237
+ * Raises the part above the splitter to the least height of the tab now shown, where it was
1238
+ * dragged lower on another tab.
1239
+ *
1240
+ * @private
1241
+ */
1242
+ private _fitTop;
1243
+ /**
1244
+ * Turns the GPU profiler on or off, from either of the switches, which follow each other.
1245
+ *
1246
+ * @param {boolean} on - Whether to time the GPU.
1247
+ * @private
1248
+ */
1249
+ private _setGpuTimings;
1250
+ /**
1251
+ * Turns the timing of scripts on or off, which takes effect right away while recording.
1252
+ *
1253
+ * @param {boolean} on - Whether to time each script type.
1254
+ * @private
1255
+ */
1256
+ private _setScriptTiming;
1257
+ /**
1258
+ * Starts or stops recording frames for the Performance tab.
1259
+ *
1260
+ * @param {boolean} on - Whether to record.
1261
+ * @private
1262
+ */
1263
+ private _setRecording;
1264
+ /**
1265
+ * The frame shown or the frames selected on the Performance tab changed.
1266
+ *
1267
+ * @private
1268
+ */
1269
+ private _onPerfChange;
1270
+ /**
1271
+ * Brings the recording controls of the Performance tab and its note up to date.
1272
+ *
1273
+ * @private
1274
+ */
1275
+ private _updatePerfBar;
1276
+ /**
1277
+ * Steps through the frames of the Performance tab with the arrow keys, Shift taking ten at a
1278
+ * time; Home shows the first frame, End follows the newest and Escape unselects the frames
1279
+ * selected together.
1280
+ *
1281
+ * @param {KeyboardEvent} e - A key pressed while the panel has focus.
1282
+ * @returns {boolean} Whether the key was used.
1283
+ * @private
1284
+ */
1285
+ private _onPerfKey;
1126
1286
  /**
1127
1287
  * Switches the list tab and points the property view at that tab's selection.
1128
1288
  *
1129
- * @param {'hierarchy'|'cameras'|'assets'|'passes'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'} tab - The tab.
1289
+ * @param {'hierarchy'|'cameras'|'assets'|'passes'|'perf'|'targets'|'textures'|'meshes'|'materials'|'scripts'|'memory'|'shaders'|'physics'} tab - The tab.
1130
1290
  * @private
1131
1291
  */
1132
1292
  private _setTab;
@@ -1170,6 +1330,7 @@ export class Inspector {
1170
1330
  * everything it lists is copied.
1171
1331
  *
1172
1332
  * @param {Node} target - What was right-clicked.
1333
+ * @param {MouseEvent} [e] - The click, for where it was on the charts of the Performance tab.
1173
1334
  * @returns {CopyTarget|null} What to copy, or null for a part of the panel nothing is copied
1174
1335
  * from, such as the toolbar.
1175
1336
  * @private
@@ -1202,6 +1363,30 @@ export class Inspector {
1202
1363
  * @private
1203
1364
  */
1204
1365
  private _copy;
1366
+ /**
1367
+ * Copies text made on demand, such as CSV.
1368
+ *
1369
+ * @param {() => string} make - Makes the text.
1370
+ * @param {string} what - What it is, for the note saying it was copied.
1371
+ * @private
1372
+ */
1373
+ private _copyText;
1374
+ /**
1375
+ * @param {string} text - The text.
1376
+ * @param {string} note - What the menu says once it is copied.
1377
+ * @private
1378
+ */
1379
+ private _writeClipboard;
1380
+ /**
1381
+ * What a right click on the Performance tab copies, as the charts tell it: the capture, a
1382
+ * series, a frame, the frames selected together, or the timeline. A capture and a series
1383
+ * cover the frames selected together, or every frame kept.
1384
+ *
1385
+ * @param {{ kind: string, key?: string, seq?: number }} what - What to copy.
1386
+ * @returns {CopyTarget|null} The copy, or null for nothing.
1387
+ * @private
1388
+ */
1389
+ private _perfCopy;
1205
1390
  /**
1206
1391
  * @returns {Set<object>} The app's own objects, which a copy never follows, as through them it
1207
1392
  * would reach everything else.
@@ -1219,6 +1404,15 @@ export class Inspector {
1219
1404
  * @private
1220
1405
  */
1221
1406
  private _copyModel;
1407
+ /**
1408
+ * Shows a GPU pass of the Performance tab on the Frame graph tab: the pass of the frame graph
1409
+ * with its name it was matched to, in the frame graph as it is now, unless that is frozen.
1410
+ *
1411
+ * @param {{ name: string, occurrence: number }} pass - The pass, by its profiler name and which
1412
+ * of the passes with that name it is.
1413
+ * @private
1414
+ */
1415
+ private _showPass;
1222
1416
  /**
1223
1417
  * Reveals a linked object in the tab that lists it: nodes in the hierarchy, passes in the frame
1224
1418
  * graph, render targets in their list.