@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.
- package/LICENSE +19 -0
- package/README.md +110 -0
- package/package.json +62 -0
- package/src/asset-usage.js +108 -0
- package/src/asset-view.js +370 -0
- package/src/camera-view.js +128 -0
- package/src/debug.js +31 -0
- package/src/describe.js +302 -0
- package/src/entity-inspector-script.js +130 -0
- package/src/frame-graph-view.js +767 -0
- package/src/hierarchy-view.js +475 -0
- package/src/index.js +4 -0
- package/src/input/fly-controller.js +116 -0
- package/src/input/input.js +299 -0
- package/src/input/math.js +8 -0
- package/src/input/orbit-controller.js +158 -0
- package/src/input/pose.js +207 -0
- package/src/inspector.js +3293 -0
- package/src/instance-survey.js +50 -0
- package/src/list-view.js +410 -0
- package/src/material-view.js +197 -0
- package/src/memory-view.js +344 -0
- package/src/mesh-view.js +235 -0
- package/src/model.js +170 -0
- package/src/node-model.js +404 -0
- package/src/physics-debug.js +527 -0
- package/src/physics-view.js +314 -0
- package/src/picker/picker.js +545 -0
- package/src/picker/render-pass-picker.js +206 -0
- package/src/property-view.js +628 -0
- package/src/render-target-view.js +288 -0
- package/src/renderers/texture-renderer-shaders.js +139 -0
- package/src/renderers/texture-renderer.js +430 -0
- package/src/renderers/wire-renderer.js +954 -0
- package/src/script-view.js +288 -0
- package/src/shader-view.js +287 -0
- package/src/styles.js +918 -0
- package/src/texture-view.js +186 -0
- package/src/tooltip.js +72 -0
- package/src/viewport-tools.js +695 -0
- package/types/asset-usage.d.ts +23 -0
- package/types/asset-view.d.ts +94 -0
- package/types/camera-view.d.ts +45 -0
- package/types/debug.d.ts +14 -0
- package/types/describe.d.ts +43 -0
- package/types/entity-inspector-script.d.ts +87 -0
- package/types/frame-graph-view.d.ts +155 -0
- package/types/hierarchy-view.d.ts +172 -0
- package/types/index.d.ts +3 -0
- package/types/input/fly-controller.d.ts +42 -0
- package/types/input/input.d.ts +192 -0
- package/types/input/math.d.ts +1 -0
- package/types/input/orbit-controller.d.ts +63 -0
- package/types/input/pose.d.ts +126 -0
- package/types/inspector.d.ts +1304 -0
- package/types/instance-survey.d.ts +35 -0
- package/types/list-view.d.ts +151 -0
- package/types/material-view.d.ts +63 -0
- package/types/memory-view.d.ts +95 -0
- package/types/mesh-view.d.ts +89 -0
- package/types/model.d.ts +104 -0
- package/types/node-model.d.ts +54 -0
- package/types/physics-debug.d.ts +254 -0
- package/types/physics-view.d.ts +81 -0
- package/types/picker/picker.d.ts +255 -0
- package/types/picker/render-pass-picker.d.ts +47 -0
- package/types/property-view.d.ts +189 -0
- package/types/render-target-view.d.ts +98 -0
- package/types/renderers/texture-renderer-shaders.d.ts +9 -0
- package/types/renderers/texture-renderer.d.ts +231 -0
- package/types/renderers/wire-renderer.d.ts +347 -0
- package/types/script-view.d.ts +56 -0
- package/types/shader-view.d.ts +46 -0
- package/types/styles.d.ts +22 -0
- package/types/texture-view.d.ts +30 -0
- package/types/tooltip.d.ts +17 -0
- package/types/viewport-tools.d.ts +237 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ADDRESS_CLAMP_TO_EDGE, ADDRESS_MIRRORED_REPEAT, ADDRESS_REPEAT, FILTER_LINEAR, FILTER_LINEAR_MIPMAP_LINEAR, FILTER_LINEAR_MIPMAP_NEAREST, FILTER_NEAREST, FILTER_NEAREST_MIPMAP_LINEAR, FILTER_NEAREST_MIPMAP_NEAREST, FUNC_ALWAYS, FUNC_EQUAL, FUNC_GREATER, FUNC_GREATEREQUAL, FUNC_LESS, FUNC_LESSEQUAL, FUNC_NEVER, FUNC_NOTEQUAL
|
|
3
|
+
} from 'playcanvas';
|
|
4
|
+
|
|
5
|
+
import { containerParts, resourceAssets } from './asset-view.js';
|
|
6
|
+
import { describeValue } from './describe.js';
|
|
7
|
+
import { formatBytes, formatName, makeSection, push, read, reflectRows } from './model.js';
|
|
8
|
+
|
|
9
|
+
/** @import { AppBase } from 'playcanvas' */
|
|
10
|
+
/** @import { GraphicsDevice } from 'playcanvas' */
|
|
11
|
+
/** @import { RenderTarget } from 'playcanvas' */
|
|
12
|
+
/** @import { Texture } from 'playcanvas' */
|
|
13
|
+
/** @import { ListRow } from './list-view.js' */
|
|
14
|
+
/** @import { PropertySection } from './model.js' */
|
|
15
|
+
|
|
16
|
+
// texture properties the model shows explicitly, plumbing, and deprecated getters that warn when read
|
|
17
|
+
const SKIP_TEXTURE = [
|
|
18
|
+
'name', 'width', 'height', 'depth', 'format', 'gpuSize', 'mipmaps', 'numLevels', 'cubemap', 'volume', 'array',
|
|
19
|
+
'arrayLength', 'samples', 'minFilter', 'magFilter', 'addressU', 'addressV', 'addressW', 'anisotropy', 'compareOnRead',
|
|
20
|
+
'compareFunc', 'device', 'impl', 'rgbm', 'swizzleGGGR'
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// sampler state constants by value, so the panel shows names rather than numbers
|
|
24
|
+
const FILTER_NAMES = new Map([
|
|
25
|
+
[FILTER_NEAREST, 'FILTER_NEAREST'], [FILTER_LINEAR, 'FILTER_LINEAR'],
|
|
26
|
+
[FILTER_NEAREST_MIPMAP_NEAREST, 'FILTER_NEAREST_MIPMAP_NEAREST'], [FILTER_NEAREST_MIPMAP_LINEAR, 'FILTER_NEAREST_MIPMAP_LINEAR'],
|
|
27
|
+
[FILTER_LINEAR_MIPMAP_NEAREST, 'FILTER_LINEAR_MIPMAP_NEAREST'], [FILTER_LINEAR_MIPMAP_LINEAR, 'FILTER_LINEAR_MIPMAP_LINEAR']
|
|
28
|
+
]);
|
|
29
|
+
const ADDRESS_NAMES = new Map([
|
|
30
|
+
[ADDRESS_REPEAT, 'ADDRESS_REPEAT'], [ADDRESS_CLAMP_TO_EDGE, 'ADDRESS_CLAMP_TO_EDGE'], [ADDRESS_MIRRORED_REPEAT, 'ADDRESS_MIRRORED_REPEAT']
|
|
31
|
+
]);
|
|
32
|
+
const FUNC_NAMES = new Map([
|
|
33
|
+
[FUNC_NEVER, 'FUNC_NEVER'], [FUNC_LESS, 'FUNC_LESS'], [FUNC_EQUAL, 'FUNC_EQUAL'], [FUNC_LESSEQUAL, 'FUNC_LESSEQUAL'],
|
|
34
|
+
[FUNC_GREATER, 'FUNC_GREATER'], [FUNC_NOTEQUAL, 'FUNC_NOTEQUAL'], [FUNC_GREATEREQUAL, 'FUNC_GREATEREQUAL'], [FUNC_ALWAYS, 'FUNC_ALWAYS']
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {Map<number, string>} names - Constant names by value.
|
|
39
|
+
* @param {number} value - The value.
|
|
40
|
+
* @returns {import('./describe.js').Described} The name, or the number when it is not a known constant.
|
|
41
|
+
*/
|
|
42
|
+
function constant(names, value) {
|
|
43
|
+
const name = names.get(value);
|
|
44
|
+
return name ? { text: name, cls: 'obj' } : describeValue(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @type {WeakMap<Texture, number>} */
|
|
48
|
+
const ids = new WeakMap();
|
|
49
|
+
let nextId = 1;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Texture} texture - A texture.
|
|
53
|
+
* @returns {string} A row key that stays the same for the lifetime of the object.
|
|
54
|
+
*/
|
|
55
|
+
function keyOf(texture) {
|
|
56
|
+
let id = ids.get(texture);
|
|
57
|
+
if (id === undefined) {
|
|
58
|
+
id = nextId++;
|
|
59
|
+
ids.set(texture, id);
|
|
60
|
+
}
|
|
61
|
+
return `tex${id}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Texture} texture - A texture.
|
|
66
|
+
* @returns {string} Its dimensions, with the shape when it is not a plain 2D texture.
|
|
67
|
+
*/
|
|
68
|
+
function shapeText(texture) {
|
|
69
|
+
const shape = texture.cubemap ? ' cube' : texture.volume ? ` ×${texture.depth}` : texture.array ? ` [${texture.arrayLength}]` : '';
|
|
70
|
+
return `${texture.width}×${texture.height}${shape}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Every texture alive on the device, largest GPU footprint first. The device keeps a registry of
|
|
75
|
+
* the textures created on it, so this covers textures nothing rendered this frame too.
|
|
76
|
+
*
|
|
77
|
+
* @param {GraphicsDevice} device - The device.
|
|
78
|
+
* @returns {Texture[]} The textures.
|
|
79
|
+
*/
|
|
80
|
+
function collectTextures(device) {
|
|
81
|
+
return [...device.textures ?? []].sort((a, b) => b.gpuSize - a.gpuSize);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {GraphicsDevice} device - The device.
|
|
86
|
+
* @returns {Map<Texture, RenderTarget[]>} The render targets each attached texture belongs to.
|
|
87
|
+
*/
|
|
88
|
+
function attachmentTargets(device) {
|
|
89
|
+
/** @type {Map<Texture, RenderTarget[]>} */
|
|
90
|
+
const owners = new Map();
|
|
91
|
+
const add = (texture, rt) => {
|
|
92
|
+
if (!texture) return;
|
|
93
|
+
const list = owners.get(texture) ?? [];
|
|
94
|
+
list.push(rt);
|
|
95
|
+
owners.set(texture, list);
|
|
96
|
+
};
|
|
97
|
+
for (const rt of device.targets ?? []) {
|
|
98
|
+
const count = rt.colorBufferCount ?? 0;
|
|
99
|
+
for (let i = 0; i < count; i++) {
|
|
100
|
+
add(rt.getColorBuffer(i), rt);
|
|
101
|
+
add(rt.getResolveBuffer?.(i), rt);
|
|
102
|
+
}
|
|
103
|
+
add(rt.depthBuffer, rt);
|
|
104
|
+
add(rt.depthResolveBuffer, rt);
|
|
105
|
+
}
|
|
106
|
+
return owners;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* One row per texture on the device, largest first, tagged when it is a render target attachment.
|
|
111
|
+
*
|
|
112
|
+
* @param {GraphicsDevice} device - The device.
|
|
113
|
+
* @returns {ListRow[]} The rows.
|
|
114
|
+
*/
|
|
115
|
+
function textureRows(device) {
|
|
116
|
+
const owners = attachmentTargets(device);
|
|
117
|
+
return collectTextures(device).map((texture) => {
|
|
118
|
+
const name = texture.name || '(unnamed)';
|
|
119
|
+
const cells = [{ text: name, cls: 'pci-cell-name' }];
|
|
120
|
+
if (owners.has(texture)) cells.push({ text: 'target', cls: 'pci-cell-tag pci-cell-tag-info' });
|
|
121
|
+
cells.push({ text: `${shapeText(texture)} ${formatName(texture.format)}${texture.mipmaps ? ' mips' : ''}`, cls: 'pci-cell-info' });
|
|
122
|
+
cells.push({ text: formatBytes(texture.gpuSize), cls: 'pci-cell-info pci-cell-right' });
|
|
123
|
+
const title = `${name} ${shapeText(texture)} ${formatName(texture.format)}\n${formatBytes(texture.gpuSize)}${texture.mipmaps ? `, ${texture.numLevels} mip levels` : ''}`;
|
|
124
|
+
return { key: keyOf(texture), item: texture, name, title, cells };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Everything the property view shows for a texture: its storage, the render targets it is attached
|
|
130
|
+
* to (linked), and every other public property.
|
|
131
|
+
*
|
|
132
|
+
* @param {Texture} texture - The texture.
|
|
133
|
+
* @param {{ device: GraphicsDevice, app?: AppBase }} ctx - The device, and the app to find the
|
|
134
|
+
* asset the texture was loaded from.
|
|
135
|
+
* @returns {PropertySection[]} The sections.
|
|
136
|
+
*/
|
|
137
|
+
function buildTextureModel(texture, ctx) {
|
|
138
|
+
const sections = [];
|
|
139
|
+
|
|
140
|
+
const general = makeSection('texture', 'Texture');
|
|
141
|
+
push(general, 'name', describeValue(texture.name));
|
|
142
|
+
push(general, 'size', { text: shapeText(texture), cls: 'num' });
|
|
143
|
+
push(general, 'format', { text: formatName(texture.format), cls: 'obj' });
|
|
144
|
+
push(general, 'gpu size', { text: formatBytes(texture.gpuSize), cls: 'num' });
|
|
145
|
+
push(general, 'mipmaps', { text: texture.mipmaps ? `${texture.numLevels} levels` : 'false', cls: texture.mipmaps ? 'num' : 'bool' });
|
|
146
|
+
if (texture.samples > 1) push(general, 'samples', read(texture, 'samples'));
|
|
147
|
+
if (texture.cubemap) push(general, 'cubemap', describeValue(true));
|
|
148
|
+
if (texture.volume) push(general, 'volume depth', read(texture, 'depth'));
|
|
149
|
+
if (texture.array) push(general, 'array length', read(texture, 'arrayLength'));
|
|
150
|
+
|
|
151
|
+
const registry = ctx.app?.assets ?? null;
|
|
152
|
+
const asset = resourceAssets(registry).get(texture) ?? null;
|
|
153
|
+
if (asset) {
|
|
154
|
+
push(general, 'from asset', describeValue(asset));
|
|
155
|
+
// a texture a glb carries comes from the container that loaded it
|
|
156
|
+
const container = containerParts(registry).parentOf.get(asset);
|
|
157
|
+
if (container) push(general, 'from container', describeValue(container));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const owners = attachmentTargets(ctx.device).get(texture) ?? [];
|
|
161
|
+
push(general, 'attached to', {
|
|
162
|
+
text: owners.length ? `${owners.length} render target${owners.length === 1 ? '' : 's'}` : 'no render target',
|
|
163
|
+
cls: owners.length ? 'obj' : 'null',
|
|
164
|
+
items: owners.map(rt => ({ label: '', text: rt.name || '(unnamed)', cls: 'ref', target: rt }))
|
|
165
|
+
});
|
|
166
|
+
sections.push(general);
|
|
167
|
+
|
|
168
|
+
const sampling = makeSection('sampling', 'Sampling');
|
|
169
|
+
push(sampling, 'min filter', constant(FILTER_NAMES, texture.minFilter));
|
|
170
|
+
push(sampling, 'mag filter', constant(FILTER_NAMES, texture.magFilter));
|
|
171
|
+
push(sampling, 'address u', constant(ADDRESS_NAMES, texture.addressU));
|
|
172
|
+
push(sampling, 'address v', constant(ADDRESS_NAMES, texture.addressV));
|
|
173
|
+
if (texture.volume) push(sampling, 'address w', constant(ADDRESS_NAMES, texture.addressW));
|
|
174
|
+
push(sampling, 'anisotropy', read(texture, 'anisotropy'));
|
|
175
|
+
push(sampling, 'compare on read', read(texture, 'compareOnRead'));
|
|
176
|
+
if (texture.compareOnRead) push(sampling, 'compare func', constant(FUNC_NAMES, texture.compareFunc));
|
|
177
|
+
sections.push(sampling);
|
|
178
|
+
|
|
179
|
+
const rest = makeSection('props', 'Properties');
|
|
180
|
+
reflectRows(rest, texture, [], SKIP_TEXTURE);
|
|
181
|
+
if (rest.rows.length) sections.push(rest);
|
|
182
|
+
|
|
183
|
+
return sections;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { buildTextureModel, collectTextures, textureRows };
|
package/src/tooltip.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// milliseconds the pointer rests on an element before its tooltip shows
|
|
2
|
+
const DELAY = 350;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sets the tooltip of an element of the panel. It is kept in a data attribute, not the title:
|
|
6
|
+
* the browser's own tooltip shows only after a long rest, and some hosts do not show it at all
|
|
7
|
+
* for elements in a shadow root.
|
|
8
|
+
*
|
|
9
|
+
* @param {HTMLElement} element - The element.
|
|
10
|
+
* @param {string} text - The tooltip, or an empty string for none.
|
|
11
|
+
*/
|
|
12
|
+
function setTip(element, text) {
|
|
13
|
+
if (text) {
|
|
14
|
+
element.dataset.tip = text;
|
|
15
|
+
} else {
|
|
16
|
+
delete element.dataset.tip;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Shows the tooltip of whatever the pointer rests on in the panel, below it, or above it when
|
|
22
|
+
* there is no room below. The tooltip element lives in the panel, so it moves with the panel into
|
|
23
|
+
* a popped-out window.
|
|
24
|
+
*
|
|
25
|
+
* @param {HTMLElement} panel - The panel.
|
|
26
|
+
*/
|
|
27
|
+
function installTooltip(panel) {
|
|
28
|
+
const tip = document.createElement('div');
|
|
29
|
+
tip.className = 'pci-tip';
|
|
30
|
+
panel.appendChild(tip);
|
|
31
|
+
|
|
32
|
+
/** @type {HTMLElement|null} */
|
|
33
|
+
let current = null;
|
|
34
|
+
let timer = 0;
|
|
35
|
+
|
|
36
|
+
const hide = () => {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
current = null;
|
|
39
|
+
tip.style.display = 'none';
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const show = () => {
|
|
43
|
+
const text = current?.dataset.tip;
|
|
44
|
+
if (!current?.isConnected || !text) return;
|
|
45
|
+
tip.textContent = text;
|
|
46
|
+
tip.style.display = 'block';
|
|
47
|
+
|
|
48
|
+
const view = panel.ownerDocument.defaultView ?? window;
|
|
49
|
+
const rect = current.getBoundingClientRect();
|
|
50
|
+
const width = tip.offsetWidth;
|
|
51
|
+
const height = tip.offsetHeight;
|
|
52
|
+
const left = Math.max(4, Math.min(rect.left, view.innerWidth - width - 4));
|
|
53
|
+
const below = rect.bottom + 6;
|
|
54
|
+
const top = below + height > view.innerHeight - 4 ? Math.max(4, rect.top - height - 6) : below;
|
|
55
|
+
tip.style.left = `${left}px`;
|
|
56
|
+
tip.style.top = `${top}px`;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
panel.addEventListener('pointerover', (e) => {
|
|
60
|
+
const target = /** @type {HTMLElement|null} */ (/** @type {Element} */ (e.target).closest?.('[data-tip]'));
|
|
61
|
+
if (target === current) return;
|
|
62
|
+
hide();
|
|
63
|
+
if (!target || target === tip) return;
|
|
64
|
+
current = target;
|
|
65
|
+
timer = setTimeout(show, DELAY);
|
|
66
|
+
});
|
|
67
|
+
panel.addEventListener('pointerleave', hide);
|
|
68
|
+
panel.addEventListener('pointerdown', hide);
|
|
69
|
+
panel.addEventListener('wheel', hide, { passive: true });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { installTooltip, setTip };
|