@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
package/src/model.js ADDED
@@ -0,0 +1,170 @@
1
+ import { pixelFormatInfo } from 'playcanvas';
2
+
3
+ import { collectProperties, describeValue } from './describe.js';
4
+
5
+ /** @import { FramePass } from 'playcanvas' */
6
+ /** @import { GraphicsDevice } from 'playcanvas' */
7
+ /** @import { RenderTarget } from 'playcanvas' */
8
+ /** @import { Described } from './describe.js' */
9
+
10
+ /**
11
+ * @typedef {object} PropertyRow
12
+ * @ignore
13
+ * @property {string} key - A key unique within the section, stable across refreshes.
14
+ * @property {string} label - The label.
15
+ * @property {Described} value - The value.
16
+ * @property {number} [depth] - How far the row is indented below the row above it.
17
+ * @property {boolean} [group] - Whether the row starts an entry of the collection above it, drawn
18
+ * with a divider so the entries of an expanded array read apart.
19
+ */
20
+
21
+ /**
22
+ * @typedef {object} PropertySection
23
+ * @ignore
24
+ * @property {string} key - A key unique within the view, stable across refreshes.
25
+ * @property {string} title - The title.
26
+ * @property {PropertyRow[]} rows - The rows.
27
+ * @property {boolean} [collapsed] - Whether the section starts out collapsed.
28
+ */
29
+
30
+ /**
31
+ * @param {string} key - The section key.
32
+ * @param {string} title - The section title.
33
+ * @param {boolean} [collapsed] - Whether the section starts out collapsed.
34
+ * @returns {PropertySection} An empty section.
35
+ */
36
+ function makeSection(key, title, collapsed = false) {
37
+ return { key, title, rows: [], collapsed };
38
+ }
39
+
40
+ /**
41
+ * Reads a property, turning a throwing getter into an error value rather than a broken panel.
42
+ *
43
+ * @param {object} obj - The object.
44
+ * @param {string} name - The property name.
45
+ * @returns {Described} The described value.
46
+ */
47
+ function read(obj, name) {
48
+ try {
49
+ return describeValue(obj[name]);
50
+ } catch (e) {
51
+ return { text: `<${e?.message ?? e}>`, cls: 'err' };
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Appends a row to a list, followed by one indented row per expanded collection entry.
57
+ *
58
+ * @param {PropertyRow[]} rows - The rows to append to.
59
+ * @param {string} label - The label.
60
+ * @param {Described} value - The value.
61
+ */
62
+ function pushRow(rows, label, value) {
63
+ rows.push({ key: label, label, value });
64
+ if (value.items) {
65
+ value.items.forEach((item, i) => {
66
+ rows.push({ key: `${label}[${i}]`, label: item.label ?? '', value: item, depth: 1, group: true });
67
+ });
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Appends a row to a section, followed by one indented row per expanded collection entry.
73
+ *
74
+ * @param {PropertySection} section - The section.
75
+ * @param {string} label - The label.
76
+ * @param {Described} value - The value.
77
+ */
78
+ function push(section, label, value) {
79
+ pushRow(section.rows, label, value);
80
+ }
81
+
82
+ /**
83
+ * Appends one row per public property of an object, see {@link collectProperties}.
84
+ *
85
+ * @param {PropertyRow[]} rows - The rows to append to.
86
+ * @param {object} obj - The object to reflect on.
87
+ * @param {object[]} stopPrototypes - Prototypes at which to stop walking the chain.
88
+ * @param {string[]} [skip] - Property names to leave out.
89
+ */
90
+ function reflectInto(rows, obj, stopPrototypes, skip) {
91
+ for (const prop of collectProperties(obj, stopPrototypes, skip)) {
92
+ pushRow(rows, prop, read(obj, prop));
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Appends one row per public property of an object, see {@link collectProperties}.
98
+ *
99
+ * @param {PropertySection} section - The section.
100
+ * @param {object} obj - The object to reflect on.
101
+ * @param {object[]} stopPrototypes - Prototypes at which to stop walking the chain.
102
+ * @param {string[]} [skip] - Property names to leave out.
103
+ */
104
+ function reflectRows(section, obj, stopPrototypes, skip) {
105
+ reflectInto(section.rows, obj, stopPrototypes, skip);
106
+ }
107
+
108
+ /**
109
+ * @param {number} bytes - A byte count.
110
+ * @returns {string} The count in the largest unit that keeps it above one, with two decimals.
111
+ */
112
+ function formatBytes(bytes) {
113
+ if (bytes < 1024) return `${bytes} B`;
114
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
115
+ if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
116
+ return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
117
+ }
118
+
119
+ /**
120
+ * @param {number|undefined} format - A PIXELFORMAT_* constant.
121
+ * @returns {string} Its name, or the number when unknown.
122
+ */
123
+ function formatName(format) {
124
+ if (format === undefined || format === null) return '-';
125
+ return pixelFormatInfo.get(format)?.name ?? String(format);
126
+ }
127
+
128
+ /**
129
+ * Passes are named after their class unless given a name, so the class-family prefix carries no
130
+ * information in a list of passes.
131
+ *
132
+ * @param {FramePass} pass - The pass.
133
+ * @returns {string} The name without a leading 'RenderPass' or 'FramePass'.
134
+ */
135
+ function passDisplayName(pass) {
136
+ const name = pass.name;
137
+ for (const prefix of ['RenderPass', 'FramePass']) {
138
+ if (name.startsWith(prefix) && name.length > prefix.length) {
139
+ return name.slice(prefix.length);
140
+ }
141
+ }
142
+ return name;
143
+ }
144
+
145
+ /**
146
+ * @param {RenderTarget} rt - A render target.
147
+ * @param {GraphicsDevice} device - The device, to recognize the backbuffer.
148
+ * @returns {string} The attachments in the trace's notation, e.g. `[C×2][D][S]`.
149
+ */
150
+ function attachmentsText(rt, device) {
151
+ const numColor = rt === device.backBuffer ? 1 : (rt.colorBufferCount ?? 0);
152
+ return `${numColor > 0 ? `[C${numColor > 1 ? `×${numColor}` : ''}]` : ''}${rt.depth ? '[D]' : ''}${rt.stencil ? '[S]' : ''}`;
153
+ }
154
+
155
+ /**
156
+ * @param {RenderTarget|null} rt - A render target, or null for an unknown backbuffer.
157
+ * @param {GraphicsDevice} device - The device, to recognize the backbuffer.
158
+ * @returns {string} A one-line summary: name, size, attachments, samples and mip level.
159
+ */
160
+ function renderTargetSummary(rt, device) {
161
+ if (!rt) return 'Backbuffer';
162
+ const name = rt === device.backBuffer ? 'Backbuffer' : (rt.name || '(unnamed)');
163
+ return `${name} ${rt.width}×${rt.height} ${attachmentsText(rt, device)}` +
164
+ `${rt.samples > 1 ? ` ×${rt.samples}` : ''}${rt.mipLevel > 0 ? ` mip ${rt.mipLevel}` : ''}`;
165
+ }
166
+
167
+ export {
168
+ attachmentsText, formatBytes, formatName, makeSection, passDisplayName, push, pushRow, read, reflectInto,
169
+ reflectRows, renderTargetSummary
170
+ };
@@ -0,0 +1,404 @@
1
+ import {
2
+ Component, Entity, INDEXFORMAT_UINT16, INDEXFORMAT_UINT32, INDEXFORMAT_UINT8, MeshInstance, PRIMITIVE_LINELOOP, PRIMITIVE_LINES, PRIMITIVE_LINESTRIP, PRIMITIVE_POINTS, PRIMITIVE_TRIANGLES, PRIMITIVE_TRIFAN, PRIMITIVE_TRISTRIP, Script, ScriptType, Texture, vertexTypesNames
3
+ } from 'playcanvas';
4
+
5
+ import { pushAssetRows } from './asset-view.js';
6
+ import { collectProperties, describeValue } from './describe.js';
7
+ import { formatBytes, makeSection, push, pushRow, read, reflectInto, reflectRows } from './model.js';
8
+
9
+ /** @import { LayerComposition } from 'playcanvas' */
10
+ /** @import { Material } from 'playcanvas' */
11
+ /** @import { Mesh } from 'playcanvas' */
12
+ /** @import { GraphNode } from 'playcanvas' */
13
+ /** @import { Described } from './describe.js' */
14
+ /** @import { PropertyRow, PropertySection } from './model.js' */
15
+
16
+ // component properties that are plumbing rather than state, plus deprecated aliases whose getters
17
+ // would log a deprecation warning just by being read
18
+ const SKIP_COMPONENT = [
19
+ 'enabled', 'system', 'entity', 'data',
20
+ 'renderPasses', 'lodBaseDistance', 'lodMultiplier', 'lodDistances', 'splatBudget', 'noFog', 'bodyType'
21
+ ];
22
+
23
+ // script properties that are plumbing rather than state
24
+ const SKIP_SCRIPT = ['enabled', 'app', 'entity'];
25
+
26
+ // mesh instance properties shown up front, or that are plumbing
27
+ const SKIP_MESH_INSTANCE = ['node', 'mesh', 'material', 'visible', 'key'];
28
+
29
+ // mesh properties shown up front, or that are plumbing
30
+ const SKIP_MESH = ['vertexBuffer', 'indexBuffer', 'primitive', 'device', 'id'];
31
+
32
+ const INDEX_FORMAT_NAMES = {
33
+ [INDEXFORMAT_UINT8]: 'UINT8',
34
+ [INDEXFORMAT_UINT16]: 'UINT16',
35
+ [INDEXFORMAT_UINT32]: 'UINT32'
36
+ };
37
+
38
+ const PRIMITIVE_NAMES = {
39
+ [PRIMITIVE_POINTS]: 'POINTS',
40
+ [PRIMITIVE_LINES]: 'LINES',
41
+ [PRIMITIVE_LINELOOP]: 'LINELOOP',
42
+ [PRIMITIVE_LINESTRIP]: 'LINESTRIP',
43
+ [PRIMITIVE_TRIANGLES]: 'TRIANGLES',
44
+ [PRIMITIVE_TRISTRIP]: 'TRISTRIP',
45
+ [PRIMITIVE_TRIFAN]: 'TRIFAN'
46
+ };
47
+
48
+ // material getters that only exist to warn about their removal or deprecation, and the variant cache shown up front
49
+ const SKIP_MATERIAL = [
50
+ 'variants',
51
+ 'ambientTint', 'anisotropy', 'aoMapVertexColor', 'aoUvSet', 'blend', 'chunks', 'clearCoatGlossiness',
52
+ 'diffuseMapVertexColor', 'diffuseTint', 'dirty', 'emissiveMapVertexColor', 'emissiveTint',
53
+ 'glossMapVertexColor', 'lightMapVertexColor', 'metalnessMapVertexColor', 'opacityMapVertexColor', 'shader',
54
+ 'sheenGlossiness', 'sheenTint', 'specularMapVertexColor', 'specularTint'
55
+ ];
56
+
57
+ /**
58
+ * @param {GraphNode} node - The node.
59
+ * @returns {PropertySection} The general section.
60
+ */
61
+ function nodeSection(node) {
62
+ const isEntity = node instanceof Entity;
63
+ const section = makeSection('node', isEntity ? 'Entity' : 'GraphNode');
64
+
65
+ push(section, 'name', describeValue(node.name));
66
+ if (isEntity) push(section, 'guid', describeValue(node.guid));
67
+ push(section, 'enabled', describeValue(node._enabled));
68
+ push(section, 'enabled in hierarchy', describeValue(node.enabled));
69
+ push(section, 'tags', describeValue(node.tags.list()));
70
+ push(section, 'path', describeValue(node.path));
71
+ push(section, 'parent', describeValue(node.parent));
72
+ push(section, 'children', describeValue(node.children.length));
73
+
74
+ return section;
75
+ }
76
+
77
+ /**
78
+ * @param {GraphNode} node - The node.
79
+ * @returns {PropertySection} The transform section.
80
+ */
81
+ function transformSection(node) {
82
+ const section = makeSection('transform', 'Transform');
83
+
84
+ push(section, 'local position', describeValue(node.getLocalPosition()));
85
+ push(section, 'local rotation', describeValue(node.getLocalEulerAngles()));
86
+ push(section, 'local scale', describeValue(node.getLocalScale()));
87
+ push(section, 'world position', describeValue(node.getPosition()));
88
+ push(section, 'world rotation', describeValue(node.getEulerAngles()));
89
+ push(section, 'world scale', describeValue(node.getScale()));
90
+ push(section, 'forward', describeValue(node.forward));
91
+
92
+ return section;
93
+ }
94
+
95
+ /**
96
+ * @param {string} name - The component name.
97
+ * @param {Component} component - The component.
98
+ * @returns {PropertySection} The component section.
99
+ */
100
+ function componentSection(name, component) {
101
+ const section = makeSection(`c:${name}`, name);
102
+ push(section, 'enabled', read(component, 'enabled'));
103
+ // asset references first, with their ids resolved to the assets they name
104
+ const assetProperties = pushAssetRows(section, component);
105
+
106
+ const handled = [...SKIP_COMPONENT, ...assetProperties];
107
+
108
+ // layer ids, named from the composition they belong to
109
+ const layers = /** @type {any} */ (component).layers;
110
+ if (Array.isArray(layers)) {
111
+ const composition = /** @type {any} */ (component).system?.app?.scene?.layers ?? null;
112
+ push(section, 'layers', layersValue(layers, composition));
113
+ handled.push('layers');
114
+ }
115
+
116
+ // mesh instances open in place, their meshes and materials linking to their tabs
117
+ const instances = /** @type {any} */ (component).meshInstances;
118
+ if (Array.isArray(instances) && instances.length) {
119
+ push(section, 'meshInstances', meshInstancesValue(instances));
120
+ handled.push('meshInstances');
121
+ }
122
+
123
+ // the scripts of a script component, each linking to its class in the Scripts tab
124
+ const scripts = /** @type {any} */ (component).scripts;
125
+ if (name === 'script' && Array.isArray(scripts)) {
126
+ push(section, 'scripts', {
127
+ text: `${scripts.length} script${scripts.length === 1 ? '' : 's'}`,
128
+ cls: scripts.length ? 'obj' : 'null',
129
+ items: scripts.map((script, index) => ({
130
+ label: `[${index}]`,
131
+ text: `${scriptNameOf(script)}${script.enabled ? '' : ' (disabled)'}`,
132
+ cls: 'ref',
133
+ target: script.constructor
134
+ }))
135
+ });
136
+ // the component also exposes each script by name, which its own section below shows
137
+ handled.push('scripts', ...scripts.map(scriptNameOf));
138
+ }
139
+
140
+ reflectRows(section, component, [Component.prototype], handled);
141
+ return section;
142
+ }
143
+
144
+ /**
145
+ * @param {ScriptType|Script} script - A script instance.
146
+ * @returns {string} The name its class is known by.
147
+ */
148
+ function scriptNameOf(script) {
149
+ const ctor = /** @type {any} */ (script.constructor);
150
+ return ctor.scriptName ?? ctor.__name ?? ctor.name;
151
+ }
152
+
153
+ /**
154
+ * The layers a component renders in. Components hold them as ids, which say nothing on their own,
155
+ * so each is named from the scene's layer composition.
156
+ *
157
+ * @param {number[]} ids - The layer ids.
158
+ * @param {LayerComposition|null} composition - The scene's composition.
159
+ * @returns {Described} The layers, named.
160
+ */
161
+ function layersValue(ids, composition) {
162
+ if (ids.length === 0) return describeValue(ids);
163
+ return {
164
+ text: ids.map((id) => {
165
+ const layer = composition?.getLayerById(id) ?? null;
166
+ return layer ? `${layer.name} (${id})` : `#${id} (not in the composition)`;
167
+ }).join(', '),
168
+ cls: 'obj'
169
+ };
170
+ }
171
+
172
+ /**
173
+ * @param {import('playcanvas').VertexFormat} format - A vertex format.
174
+ * @returns {Described} The format, expanding into one row per element.
175
+ */
176
+ function vertexFormatValue(format) {
177
+ return {
178
+ text: `${format.elements.length} elements, ${format.size} bytes per vertex${format.interleaved ? ', interleaved' : ''}`,
179
+ cls: 'obj',
180
+ expand: () => format.elements.map(element => ({
181
+ key: element.name,
182
+ label: element.name,
183
+ value: {
184
+ text: `${element.numComponents} × ${vertexTypesNames[element.dataType] ?? element.dataType}` +
185
+ ` offset ${element.offset} stride ${element.stride} size ${element.size}` +
186
+ `${element.normalize ? ' normalized' : ''}${element.asInt ? ' integer' : ''}`,
187
+ cls: 'num'
188
+ }
189
+ }))
190
+ };
191
+ }
192
+
193
+ /**
194
+ * @param {{ type: number, base: number, baseVertex: number, count: number, indexed?: boolean }} primitive - A
195
+ * primitive of a mesh.
196
+ * @returns {string} What it draws, and from where.
197
+ */
198
+ function primitiveText(primitive) {
199
+ const { type, base, baseVertex, count, indexed } = primitive;
200
+ return `${PRIMITIVE_NAMES[type] ?? type} count ${count} base ${base}` +
201
+ `${baseVertex ? ` base vertex ${baseVertex}` : ''}${indexed ? ' indexed' : ''}`;
202
+ }
203
+
204
+ /**
205
+ * The draw ranges of a mesh. Almost every mesh has exactly one, so a single primitive reads on the
206
+ * row itself rather than hiding behind an entry.
207
+ *
208
+ * @param {{ type: number, base: number, baseVertex: number, count: number, indexed?: boolean }[]} primitives - The
209
+ * primitives of a mesh.
210
+ * @returns {Described} The primitives.
211
+ */
212
+ function primitiveValue(primitives) {
213
+ if (!Array.isArray(primitives) || primitives.length === 0) return describeValue(primitives);
214
+ if (primitives.length === 1) return { text: primitiveText(primitives[0]), cls: 'num' };
215
+ return {
216
+ text: `${primitives.length} primitives`,
217
+ cls: 'obj',
218
+ items: primitives.map((primitive, index) => ({
219
+ label: `[${index}]`,
220
+ text: primitiveText(primitive),
221
+ cls: 'num'
222
+ }))
223
+ };
224
+ }
225
+
226
+ /**
227
+ * @param {Mesh} mesh - A mesh.
228
+ * @returns {PropertyRow[]} Its rows, with the vertex format opening into its elements.
229
+ */
230
+ function meshRows(mesh) {
231
+ const rows = [];
232
+ const vertexBuffer = mesh.vertexBuffer;
233
+ const indexBuffer = mesh.indexBuffer?.[0];
234
+
235
+ if (vertexBuffer) {
236
+ pushRow(rows, 'vertex buffer', {
237
+ text: `${vertexBuffer.numVertices} vertices, ${formatBytes(vertexBuffer.numBytes)}`,
238
+ cls: 'num',
239
+ target: vertexBuffer
240
+ });
241
+ pushRow(rows, 'vertex format', vertexFormatValue(vertexBuffer.format));
242
+ } else {
243
+ pushRow(rows, 'vertex buffer', describeValue(null));
244
+ }
245
+ pushRow(rows, 'index buffer', indexBuffer ? {
246
+ text: `${indexBuffer.numIndices} indices, ${INDEX_FORMAT_NAMES[indexBuffer.format] ?? indexBuffer.format}, ${formatBytes(indexBuffer.numBytes)}`,
247
+ cls: 'num',
248
+ target: indexBuffer
249
+ } : describeValue(null));
250
+ pushRow(rows, 'primitive', primitiveValue(mesh.primitive));
251
+
252
+ reflectInto(rows, mesh, [], SKIP_MESH);
253
+ return rows;
254
+ }
255
+
256
+ /**
257
+ * The textures a material samples: those set on its properties, such as the maps of a
258
+ * StandardMaterial, and those set as parameters, which is how a ShaderMaterial carries them.
259
+ *
260
+ * @param {Material} material - A material.
261
+ * @returns {Set<Texture>} The textures.
262
+ */
263
+ function materialTextures(material) {
264
+ const textures = new Set();
265
+ for (const name of collectProperties(material, [], SKIP_MATERIAL)) {
266
+ let value;
267
+ try {
268
+ value = material[name];
269
+ } catch {
270
+ continue;
271
+ }
272
+ if (value instanceof Texture) textures.add(value);
273
+ }
274
+ for (const parameter of Object.values(material.parameters ?? {})) {
275
+ if (parameter?.data instanceof Texture) textures.add(parameter.data);
276
+ }
277
+ return textures;
278
+ }
279
+
280
+ /**
281
+ * @param {Material} material - A material.
282
+ * @returns {PropertyRow[]} Its rows, textures and compiled variants linking to their tabs.
283
+ */
284
+ function materialRows(material) {
285
+ const rows = [];
286
+ pushRow(rows, 'variants', describeValue([...material.variants.values()]));
287
+ // the buffer holding the material's uniforms, once it has rendered on a device that uses one
288
+ const uniformBuffer = /** @type {any} */ (material)._uniformBuffer;
289
+ if (uniformBuffer) pushRow(rows, 'uniform buffer', describeValue(uniformBuffer));
290
+ reflectInto(rows, material, [], SKIP_MATERIAL);
291
+ return rows;
292
+ }
293
+
294
+ /**
295
+ * @param {MeshInstance} instance - A mesh instance.
296
+ * @returns {PropertyRow[]} Its rows, with the mesh and the material linking to their tabs.
297
+ */
298
+ function meshInstanceRows(instance) {
299
+ const rows = [];
300
+ const mesh = instance.mesh;
301
+ const material = instance.material;
302
+
303
+ pushRow(rows, 'node', read(instance, 'node'));
304
+ // links to the Meshes tab, which shows the mesh's geometry and everything else using it
305
+ pushRow(rows, 'mesh', describeValue(mesh));
306
+ // links to the Materials tab, which shows its properties and everything else using it
307
+ pushRow(rows, 'material', describeValue(material));
308
+ pushRow(rows, 'visible', read(instance, 'visible'));
309
+ // an instance overriding material values keeps its own copy of the material's uniforms
310
+ const uniformBuffer = /** @type {any} */ (instance)._materialUniformBuffer;
311
+ if (uniformBuffer) pushRow(rows, 'material uniform buffer', describeValue(uniformBuffer));
312
+ reflectInto(rows, instance, [], SKIP_MESH_INSTANCE);
313
+ return rows;
314
+ }
315
+
316
+ /**
317
+ * The mesh instances of a component, as one row per instance that opens into its properties. The
318
+ * value of each is the instance itself rather than a link to its node, since the node is one of
319
+ * the rows it opens into.
320
+ *
321
+ * @param {MeshInstance[]} instances - The mesh instances.
322
+ * @returns {Described} The list.
323
+ */
324
+ function meshInstancesValue(instances) {
325
+ return {
326
+ text: `Array(${instances.length}) of MeshInstance`,
327
+ cls: 'obj',
328
+ items: instances.map((instance, index) => {
329
+ const described = describeValue(instance, 1);
330
+ delete described.target;
331
+ return {
332
+ label: `[${index}]`,
333
+ ...described,
334
+ expand: instance instanceof MeshInstance ? () => meshInstanceRows(instance) : undefined
335
+ };
336
+ })
337
+ };
338
+ }
339
+
340
+ /**
341
+ * @param {import('playcanvas').ScriptComponent} scriptComponent - The script component.
342
+ * @returns {PropertySection[]} One section per script instance.
343
+ */
344
+ function scriptSections(scriptComponent) {
345
+ const sections = [];
346
+ const scripts = scriptComponent.scripts ?? [];
347
+
348
+ scripts.forEach((script, index) => {
349
+ const ctor = /** @type {any} */ (script.constructor);
350
+ const name = scriptNameOf(script);
351
+ const section = makeSection(`s:${index}:${name}`, `script › ${name}`);
352
+ // the class links to the Scripts tab, which lists every entity using it and its source
353
+ push(section, 'script', { text: name, cls: 'ref', target: ctor });
354
+ section.rows.push(...scriptInstanceRows(script));
355
+ sections.push(section);
356
+ });
357
+
358
+ return sections;
359
+ }
360
+
361
+ /**
362
+ * @param {ScriptType|Script} script - A script instance.
363
+ * @returns {PropertyRow[]} Its rows: whether it is enabled, then its attributes.
364
+ */
365
+ function scriptInstanceRows(script) {
366
+ const rows = [];
367
+ const ctor = /** @type {any} */ (script.constructor);
368
+ pushRow(rows, 'enabled', read(script, 'enabled'));
369
+ if (script instanceof ScriptType) {
370
+ // classic scripts declare their attributes up front
371
+ for (const attribute in ctor.attributes?.index ?? {}) {
372
+ pushRow(rows, attribute, read(script, attribute));
373
+ }
374
+ } else {
375
+ reflectInto(rows, script, [Script.prototype, ScriptType.prototype], SKIP_SCRIPT);
376
+ }
377
+ return rows;
378
+ }
379
+
380
+ /**
381
+ * Everything the property view shows for a node: identity, transform, one section per component
382
+ * and one per script instance. A component's mesh instances open in place, each into its own
383
+ * properties, with its mesh and material linking to their tabs.
384
+ *
385
+ * @param {GraphNode} node - The node.
386
+ * @returns {PropertySection[]} The sections.
387
+ */
388
+ function buildNodeModel(node) {
389
+ const sections = [nodeSection(node), transformSection(node)];
390
+
391
+ if (node instanceof Entity) {
392
+ for (const name of Object.keys(node.c)) {
393
+ const component = node.c[name];
394
+ sections.push(componentSection(name, component));
395
+ if (name === 'script') {
396
+ sections.push(...scriptSections(/** @type {any} */ (component)));
397
+ }
398
+ }
399
+ }
400
+
401
+ return sections;
402
+ }
403
+
404
+ export { buildNodeModel, layersValue, materialRows, materialTextures, meshInstanceRows, meshRows, scriptInstanceRows, vertexFormatValue };