@playcanvas/inspector 0.2.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.
Files changed (49) hide show
  1. package/README.md +147 -5
  2. package/package.json +1 -1
  3. package/src/asset-view.js +24 -17
  4. package/src/camera-view.js +5 -3
  5. package/src/context-menu.js +231 -0
  6. package/src/copy-json.js +692 -0
  7. package/src/describe.js +20 -1
  8. package/src/entity-inspector-script.js +10 -0
  9. package/src/frame-graph-view.js +41 -9
  10. package/src/hierarchy-view.js +29 -3
  11. package/src/inspector.js +958 -80
  12. package/src/list-view.js +118 -12
  13. package/src/material-view.js +7 -6
  14. package/src/memory-view.js +224 -66
  15. package/src/mesh-view.js +6 -5
  16. package/src/model.js +24 -2
  17. package/src/node-model.js +81 -11
  18. package/src/perf-capture.js +2034 -0
  19. package/src/perf-chart.js +3989 -0
  20. package/src/perf-copy.js +367 -0
  21. package/src/perf-view.js +1224 -0
  22. package/src/property-view.js +162 -5
  23. package/src/render-target-view.js +3 -3
  24. package/src/script-view.js +21 -12
  25. package/src/styles.js +374 -2
  26. package/src/texture-view.js +4 -4
  27. package/src/transform-tool.js +185 -0
  28. package/types/asset-view.d.ts +3 -1
  29. package/types/camera-view.d.ts +4 -0
  30. package/types/context-menu.d.ts +90 -0
  31. package/types/copy-json.d.ts +69 -0
  32. package/types/describe.d.ts +1 -1
  33. package/types/entity-inspector-script.d.ts +8 -0
  34. package/types/frame-graph-view.d.ts +7 -0
  35. package/types/hierarchy-view.d.ts +13 -0
  36. package/types/inspector.d.ts +339 -25
  37. package/types/list-view.d.ts +44 -3
  38. package/types/material-view.d.ts +3 -1
  39. package/types/memory-view.d.ts +24 -25
  40. package/types/mesh-view.d.ts +3 -1
  41. package/types/model.d.ts +16 -1
  42. package/types/node-model.d.ts +17 -1
  43. package/types/perf-capture.d.ts +871 -0
  44. package/types/perf-chart.d.ts +1407 -0
  45. package/types/perf-copy.d.ts +61 -0
  46. package/types/perf-view.d.ts +231 -0
  47. package/types/property-view.d.ts +41 -0
  48. package/types/script-view.d.ts +3 -1
  49. package/types/transform-tool.d.ts +92 -0
@@ -0,0 +1,61 @@
1
+ /** @import { PerfCapture, PerfLoad } from './perf-capture.js' */
2
+ /**
3
+ * The series a chart, or a section under the charts, copies: the figures of each frame, by the
4
+ * name they are copied under and the channel they are read from.
5
+ *
6
+ * @type {Record<string, [string, string][]>}
7
+ */
8
+ export const SERIES: Record<string, [string, string][]>;
9
+ /**
10
+ * The whole capture, or a span of it: a header and every frame.
11
+ *
12
+ * @param {PerfCapture} capture - The capture.
13
+ * @param {number} from - The first frame.
14
+ * @param {number} to - The last frame, inclusive.
15
+ * @param {object} [device] - What to say about the device.
16
+ * @returns {object} The capture.
17
+ */
18
+ export function captureJson(capture: PerfCapture, from: number, to: number, device?: object): object;
19
+ /**
20
+ * Everything recorded for a frame. Durations are in milliseconds, memory in bytes; a figure the
21
+ * engine did not provide is left out.
22
+ *
23
+ * The start of the app, when the capture began with it, has how long it lasted, what loaded and
24
+ * the moments in it, with times from the page opening.
25
+ *
26
+ * @param {PerfCapture} capture - The capture.
27
+ * @param {number} seq - A kept frame.
28
+ * @returns {object} The frame.
29
+ */
30
+ export function frameJson(capture: PerfCapture, seq: number): object;
31
+ /**
32
+ * The figures of frames selected together: their averages, 95th percentiles and largest.
33
+ *
34
+ * @param {PerfCapture} capture - The capture.
35
+ * @param {number} from - The first frame.
36
+ * @param {number} to - The last frame, inclusive.
37
+ * @returns {object} The figures.
38
+ */
39
+ export function rangeJson(capture: PerfCapture, from: number, to: number): object;
40
+ /**
41
+ * The series of a chart or section, a row per frame: the frame and its figures. The GPU series
42
+ * has a column per pass, the scripts series a column per script type and only the frames that
43
+ * timed scripts, the counters series a column per counter and only the frames that set one, the
44
+ * events series lists only the frames that had events, with what happened by kind, and the
45
+ * loading series has a row per asset, request and moment, in the frame it ended in.
46
+ *
47
+ * @param {PerfCapture} capture - The capture.
48
+ * @param {string} key - The chart or section: 'frame', 'cpu', 'gpu', 'draws', 'scripts',
49
+ * 'counters', 'loading', 'memory', 'resources' or 'events'.
50
+ * @param {number} from - The first frame.
51
+ * @param {number} to - The last frame, inclusive.
52
+ * @returns {object[]} The rows.
53
+ */
54
+ export function seriesRows(capture: PerfCapture, key: string, from: number, to: number): object[];
55
+ /**
56
+ * @param {object[]} rows - Rows of the same kind, as {@link seriesRows} makes them.
57
+ * @returns {string} The rows as CSV, with a header of every column any row has, in the order
58
+ * they first appear.
59
+ */
60
+ export function toCsv(rows: object[]): string;
61
+ import type { PerfCapture } from './perf-capture.js';
@@ -0,0 +1,231 @@
1
+ export type PerfPart = object;
2
+ export type PerfRangeStats = object;
3
+ export type PerfSelection = object;
4
+ export type PerfScriptLegend = object;
5
+ export type PerfEventKind = object;
6
+ export const ASSET_COLOR: "#8e8e93";
7
+ export const ASSET_COLORS: {
8
+ [k: string]: string;
9
+ };
10
+ export const ASSET_KINDS: {
11
+ name: string;
12
+ color: string;
13
+ types: string[];
14
+ }[];
15
+ /** @import { PerfCapture, PerfEvent, PerfGpuPass, PerfLoad } from './perf-capture.js' */
16
+ /** @import { Described } from './describe.js' */
17
+ /** @import { PropertyRow, PropertySection } from './model.js' */
18
+ /**
19
+ * @typedef {object} PerfPart
20
+ * @ignore
21
+ * @property {string} key - A key unique among the parts.
22
+ * @property {string} name - The display name.
23
+ * @property {string} color - The CSS color it is drawn in.
24
+ * @property {string} channel - The channel of the capture holding it, which the charts read
25
+ * directly: a call per bar would box every figure it returns.
26
+ * @property {string} [tip] - What it covers.
27
+ */
28
+ /**
29
+ * @typedef {object} PerfRangeStats
30
+ * @ignore
31
+ * @property {number} count - How many frames had the figure.
32
+ * @property {number} avg - The mean.
33
+ * @property {number} p95 - The 95th percentile.
34
+ * @property {number} max - The largest.
35
+ */
36
+ /**
37
+ * @typedef {object} PerfSelection
38
+ * @ignore
39
+ * @property {PerfCapture} capture - The capture.
40
+ * @property {number} seq - The frame shown, or -1 for none.
41
+ * @property {{ from: number, to: number }|null} range - The frames selected together, inclusive,
42
+ * or null.
43
+ * @property {{ supported: boolean, enabled: boolean, enable: () => void }} gpu - The GPU profiler:
44
+ * whether the device has one, whether it is on, and how to turn it on.
45
+ * @property {{ enabled: boolean, enable: () => void, rows?: number, pinned?: ReadonlySet<string>, pin?: (name: string) => void }} [scripts] - Script
46
+ * timing: whether it is on and how to turn it on; how many of the longest script types the
47
+ * Scripts chart gives a band of their own, besides those pinned; the names of those pinned; and
48
+ * how to pin or unpin one.
49
+ */
50
+ /**
51
+ * @typedef {object} PerfScriptLegend
52
+ * @ignore
53
+ * @property {{ id: number, name: string, color: string, pinned: boolean }[]} types - The script
54
+ * types with a band of their own in the Scripts chart, top down: those pinned, then the longest of
55
+ * the others, each by its index into {@link PerfCapture#scriptNames}.
56
+ * @property {Map<number, string>} colors - The color of each of them, by id.
57
+ * @property {number} others - How many more types took time, sharing one band.
58
+ * @property {string} signature - The types in order, telling when the bands change.
59
+ */
60
+ /**
61
+ * The main-thread CPU time of a frame, part by part, bottom up as the CPU chart stacks them. They
62
+ * add up to the update and the render, which hold the rest.
63
+ *
64
+ * @type {PerfPart[]}
65
+ */
66
+ export const CPU_PARTS: PerfPart[];
67
+ /**
68
+ * @typedef {object} PerfEventKind
69
+ * @ignore
70
+ * @property {string} key - A key unique among the kinds.
71
+ * @property {string} name - The display name.
72
+ * @property {string} [short] - The name beside the charts, where the display name is too long.
73
+ * @property {string} color - The CSS color its marks are drawn in.
74
+ * @property {string} tip - What it marks.
75
+ */
76
+ /**
77
+ * What the events of a frame can be, each a row of its own under the charts.
78
+ *
79
+ * @type {PerfEventKind[]}
80
+ */
81
+ export const EVENT_KINDS: PerfEventKind[];
82
+ export const FAILED_COLOR: "#ff453a";
83
+ export const HITCH_FACTOR: 2;
84
+ export const MAIN_THREAD_COLOR: "#ff2d92";
85
+ export const MILESTONE_COLOR: "#e5e5ea";
86
+ export const OTHER_SCRIPTS_COLOR: "#8e8e93";
87
+ /**
88
+ * The render phases a profiler or debug engine times, part of the render.
89
+ *
90
+ * @type {[string, string][]}
91
+ */
92
+ export const RENDER_PHASES: [string, string][];
93
+ export const REQUEST_COLOR: "#64d2ff";
94
+ export const SCRIPT_COLORS: string[];
95
+ export const SCRIPT_ROWS: 10;
96
+ /**
97
+ * Builds the property view sections for the frames selected in a capture: the range, when frames
98
+ * are selected together, then everything recorded for the frame shown.
99
+ *
100
+ * @param {PerfSelection} selection - The selection.
101
+ * @returns {PropertySection[]} The sections.
102
+ */
103
+ export function buildPerfModel(selection: PerfSelection): PropertySection[];
104
+ /**
105
+ * @param {number} n - A count of calls, or their mean over frames.
106
+ * @returns {string} The count, with a decimal for a mean that is not whole.
107
+ */
108
+ export function callCount(n: number): string;
109
+ /**
110
+ * The typical figures of a capture, against which a frame is judged: the frame interval the app
111
+ * manages at best, normally the display's, and the median one.
112
+ *
113
+ * @param {PerfCapture} capture - The capture.
114
+ * @returns {{ budget: number, median: number }} The 5th percentile and the median frame interval,
115
+ * NaN while nothing is recorded.
116
+ */
117
+ export function captureNorms(capture: PerfCapture): {
118
+ budget: number;
119
+ median: number;
120
+ };
121
+ /**
122
+ * @param {string} name - The profiler name of the pass running an effect, as FramePassBloom.
123
+ * @returns {string} The name of the effect, as Bloom.
124
+ */
125
+ export function effectName(name: string): string;
126
+ /**
127
+ * @param {PerfCapture} capture - The capture.
128
+ * @param {number} seq - A kept frame.
129
+ * @param {string} kind - The key of one of the {@link EVENT_KINDS}.
130
+ * @returns {string[]} What the frame's events of that kind were, a line each.
131
+ */
132
+ export function eventLines(capture: PerfCapture, seq: number, kind: string): string[];
133
+ /**
134
+ * @param {number} ms - A duration in milliseconds, which can be long.
135
+ * @returns {string} The duration in milliseconds below a second, in seconds above.
136
+ */
137
+ export function formatDuration(ms: number): string;
138
+ /**
139
+ * @param {PerfCapture} capture - The capture.
140
+ * @param {number} seq - A kept frame.
141
+ * @returns {number} The kinds of event the frame had, a bit per kind of {@link EVENT_KINDS} in
142
+ * its order.
143
+ */
144
+ export function eventMask(capture: PerfCapture, seq: number): number;
145
+ /**
146
+ * @param {PerfCapture} capture - The capture.
147
+ * @param {string} kind - The key of one of the {@link EVENT_KINDS}.
148
+ * @returns {string} Why the browser or engine cannot report that kind of event, or an empty string
149
+ * when it can.
150
+ */
151
+ export function eventUnsupported(capture: PerfCapture, kind: string): string;
152
+ /**
153
+ * @param {number} value - A count.
154
+ * @returns {string} The count with thousands separators, or a dash when unknown.
155
+ */
156
+ export function formatCount(value: number): string;
157
+ /**
158
+ * @param {number} ms - A duration in milliseconds.
159
+ * @returns {string} The duration, to two decimals below ten.
160
+ */
161
+ export function formatMs(ms: number): string;
162
+ /**
163
+ * @param {number} value - A value the app counts, of a unit of its own.
164
+ * @returns {string} The value: a whole number as a count, others to a few digits.
165
+ */
166
+ export function formatValue(value: number): string;
167
+ /**
168
+ * What held a frame back: the processor that was busy for most of it, the display, or neither,
169
+ * when the time went outside the engine.
170
+ *
171
+ * @param {PerfCapture} capture - The capture.
172
+ * @param {number} seq - A kept frame.
173
+ * @param {number} budget - The frame interval the app manages at best.
174
+ * @returns {string} The verdict.
175
+ */
176
+ export function frameVerdict(capture: PerfCapture, seq: number, budget: number): string;
177
+ /**
178
+ * @param {PerfCapture} capture - The capture.
179
+ * @param {number} seq - A kept frame.
180
+ * @param {number} median - The median frame interval of the capture.
181
+ * @returns {boolean} Whether the frame took far longer than the median frame.
182
+ */
183
+ export function isHitch(capture: PerfCapture, seq: number, median: number): boolean;
184
+ /**
185
+ * @param {PerfLoad} load - A load.
186
+ * @returns {string} The color it is drawn in.
187
+ */
188
+ export function loadColor(load: PerfLoad): string;
189
+ /**
190
+ * @param {PerfLoad} load - A load.
191
+ * @returns {string} What it was: an asset or a request with how long it took, its request and
192
+ * its size, or a moment with when it was.
193
+ */
194
+ export function loadText(load: PerfLoad): string;
195
+ /**
196
+ * @param {PerfCapture} capture - The capture.
197
+ * @param {number} seq - A kept entry.
198
+ * @returns {number} The slot of the frame before it, or -1 where none is kept, or where the entry
199
+ * before it is the start of the app, which has no figures of a frame to compare with.
200
+ */
201
+ export function previousSlot(capture: PerfCapture, seq: number): number;
202
+ /**
203
+ * @param {PerfCapture} capture - The capture.
204
+ * @param {string|Float64Array} key - The channel, or a ring of values like one.
205
+ * @param {number} from - The first frame.
206
+ * @param {number} to - The last frame, inclusive.
207
+ * @returns {PerfRangeStats} Its mean, 95th percentile and largest over the frames.
208
+ */
209
+ export function rangeStats(capture: PerfCapture, key: string | Float64Array, from: number, to: number): PerfRangeStats;
210
+ /**
211
+ * @param {number} index - The place of a script type among those with a band of their own.
212
+ * @returns {string} Its color: one of {@link SCRIPT_COLORS}, shaded lighter, then darker, on each
213
+ * time round them.
214
+ */
215
+ export function scriptColorAt(index: number): string;
216
+ /**
217
+ * The script types the Scripts chart gives a band of their own: those pinned, then the ones that
218
+ * took the longest over a span of frames, the frames selected together or the whole capture, so a
219
+ * selection around a spike brings forward the scripts behind it.
220
+ *
221
+ * @param {PerfCapture} capture - The capture.
222
+ * @param {number} from - The first frame the types are ranked over.
223
+ * @param {number} to - The last, inclusive.
224
+ * @param {number} rows - How many of the longest types get a band, besides those pinned.
225
+ * @param {ReadonlySet<string>} pinned - The names of the types pinned.
226
+ * @returns {PerfScriptLegend} The legend.
227
+ */
228
+ export function scriptLegend(capture: PerfCapture, from: number, to: number, rows: number, pinned: ReadonlySet<string>): PerfScriptLegend;
229
+ import type { PropertySection } from './model.js';
230
+ import type { PerfCapture } from './perf-capture.js';
231
+ import type { PerfLoad } from './perf-capture.js';
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Something a context menu of the panel can copy.
3
+ */
4
+ export type CopyTarget = object;
1
5
  export type RowElements = object;
2
6
  export type SectionElements = object;
3
7
  /**
@@ -98,6 +102,13 @@ export class PropertyView {
98
102
  * @private
99
103
  */
100
104
  private _emptyEl;
105
+ /**
106
+ * The rows and sections by the elements showing them, to find what a menu was opened on.
107
+ *
108
+ * @type {WeakMap<Element, RowElements|SectionElements>}
109
+ * @private
110
+ */
111
+ private _byElement;
101
112
  /**
102
113
  * The subject being shown.
103
114
  *
@@ -124,6 +135,20 @@ export class PropertyView {
124
135
  * @private
125
136
  */
126
137
  private _loadScroll;
138
+ /**
139
+ * What a copy made from an element of the panel copies: the row or the section title the
140
+ * element is in, and anywhere else the subject itself.
141
+ *
142
+ * @param {Node} node - The element, such as the target of a context menu event.
143
+ * @returns {CopyTarget|null} What to copy, or null when the element is not in the panel or
144
+ * nothing is shown.
145
+ */
146
+ copyTargetAt(node: Node): CopyTarget | null;
147
+ /**
148
+ * @returns {CopyTarget|null} A copy of the subject, rebuilt when it is made so it reads the
149
+ * live object, or null when nothing is shown.
150
+ */
151
+ subjectCopyTarget(): CopyTarget | null;
127
152
  /**
128
153
  * Re-reads every shown property and updates the text that changed.
129
154
  */
@@ -185,5 +210,21 @@ export class PropertyView {
185
210
  * @private
186
211
  */
187
212
  private _createRow;
213
+ /**
214
+ * Opens the text field of an editable value. Enter hands the text to the edit and closes the
215
+ * field once the edit takes it, or marks the text as not taken; leaving the field does the
216
+ * same, and gives up on text that is not taken; Escape closes it without a change.
217
+ *
218
+ * @param {RowElements} elements - The row.
219
+ * @private
220
+ */
221
+ private _startEdit;
222
+ /**
223
+ * Closes the text field of a value, which shows its text again on the next refresh.
224
+ *
225
+ * @param {RowElements} elements - The row.
226
+ * @private
227
+ */
228
+ private _endEdit;
188
229
  }
189
230
  import type { PropertySection } from './model.js';
@@ -24,11 +24,13 @@ export type ScriptEntry = {
24
24
  * using it, each instance opening in place into its attributes, and its source.
25
25
  *
26
26
  * @param {Function} cls - The script class.
27
- * @param {{ app: AppBase }} ctx - The app.
27
+ * @param {{ app: AppBase, backlinks?: boolean }} ctx - The app, and whether to list the entities
28
+ * using the class, which a copy has no use for.
28
29
  * @returns {PropertySection[]} The sections.
29
30
  */
30
31
  export function buildScriptModel(cls: Function, ctx: {
31
32
  app: AppBase;
33
+ backlinks?: boolean;
32
34
  }): PropertySection[];
33
35
  /**
34
36
  * @param {Function} cls - A class.
@@ -0,0 +1,92 @@
1
+ export type TransformMode = "translate" | "rotate" | "scale";
2
+ declare const POINTER_EVENTS: string[];
3
+ /**
4
+ * Moves, rotates or scales a node in the view with one of the engine's transform gizmos, drawn on
5
+ * a layer of its own over the view of a camera. The gizmo listens to the canvas itself, after the
6
+ * app's own listeners, so a drag of its handles would also reach the app and move its camera too.
7
+ * The tool takes those listeners away and hands the gizmo the pointer itself: a press on a handle
8
+ * and the drag that follows go to the gizmo alone, and everything else to the app as usual.
9
+ *
10
+ * The gizmo has no public way to be handed input, so it is handed its own pointer handlers. Engines
11
+ * whose gizmos lack them get no tool, see {@link TransformTool.supported}.
12
+ *
13
+ * @ignore
14
+ */
15
+ export class TransformTool {
16
+ /**
17
+ * Whether the engine's gizmos can be driven by the tool.
18
+ *
19
+ * @type {boolean}
20
+ */
21
+ static get supported(): boolean;
22
+ /**
23
+ * @param {AppBase} app - The app.
24
+ * @param {TransformMode} mode - What the tool does to the node.
25
+ * @param {CameraComponent} camera - The camera whose view the gizmo is drawn and used in.
26
+ * @param {() => void} [onTransform] - Called whenever the gizmo changes the node.
27
+ */
28
+ constructor(app: AppBase, mode: TransformMode, camera: CameraComponent, onTransform?: () => void);
29
+ /**
30
+ * What the tool does to the node.
31
+ *
32
+ * @type {TransformMode}
33
+ */
34
+ mode: TransformMode;
35
+ /**
36
+ * @type {AppBase}
37
+ * @private
38
+ */
39
+ private _app;
40
+ /**
41
+ * @type {Layer}
42
+ * @private
43
+ */
44
+ private _layer;
45
+ /**
46
+ * @type {any}
47
+ * @private
48
+ */
49
+ private _gizmo;
50
+ /**
51
+ * Whether a handle is being dragged, which keeps the pointer from the app until it is let go.
52
+ *
53
+ * @type {boolean}
54
+ * @private
55
+ */
56
+ private _dragging;
57
+ /**
58
+ * Whether the click that follows the end of a drag is still to come, to keep it from the app.
59
+ *
60
+ * @type {boolean}
61
+ * @private
62
+ */
63
+ private _endingDrag;
64
+ /**
65
+ * The entity of the gizmo, which the app's hierarchy holds while the tool is on.
66
+ *
67
+ * @type {Entity}
68
+ */
69
+ get root(): Entity;
70
+ /**
71
+ * Puts the gizmo on a node, or takes it off.
72
+ *
73
+ * @param {GraphNode|null} node - The node, or null for none.
74
+ */
75
+ attach(node: GraphNode | null): void;
76
+ /**
77
+ * Hands the gizmo a pointer event on the canvas, ahead of everything else listening to it.
78
+ *
79
+ * @param {Event} e - The event.
80
+ * @returns {boolean} Whether the gizmo keeps the event, which nothing else is then to see.
81
+ */
82
+ handle(e: Event): boolean;
83
+ /**
84
+ * Takes the gizmo, its layer and its entity out of the app.
85
+ */
86
+ destroy(): void;
87
+ }
88
+ import type { Entity } from 'playcanvas';
89
+ import type { GraphNode } from 'playcanvas';
90
+ import type { AppBase } from 'playcanvas';
91
+ import type { CameraComponent } from 'playcanvas';
92
+ export { POINTER_EVENTS as TRANSFORM_POINTER_EVENTS };