@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,475 @@
|
|
|
1
|
+
import { Entity } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { setTip } from './tooltip.js';
|
|
4
|
+
|
|
5
|
+
/** @import { GraphNode } from 'playcanvas' */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What the hierarchy filter matches its text against: a node's name, the type of one of its
|
|
9
|
+
* components, or the name of one of its scripts.
|
|
10
|
+
*
|
|
11
|
+
* @typedef {'name'|'component'|'script'} FilterBy
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {GraphNode} node - A node.
|
|
17
|
+
* @returns {string[]} The names of the scripts on it.
|
|
18
|
+
*/
|
|
19
|
+
function scriptNames(node) {
|
|
20
|
+
const scripts = /** @type {any} */ (node).c?.script?.scripts ?? [];
|
|
21
|
+
return scripts.map((script) => {
|
|
22
|
+
const ctor = script.constructor;
|
|
23
|
+
return String(ctor.scriptName ?? ctor.__name ?? ctor.name ?? '');
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {GraphNode} node - A node.
|
|
29
|
+
* @returns {string[]} The types of the components on it.
|
|
30
|
+
*/
|
|
31
|
+
function componentTypes(node) {
|
|
32
|
+
return node instanceof Entity ? Object.keys(node.c) : [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {GraphNode} node - A node.
|
|
37
|
+
* @param {string} text - The lower-cased filter text.
|
|
38
|
+
* @param {FilterBy} by - What the text matches.
|
|
39
|
+
* @returns {boolean} Whether the node matches.
|
|
40
|
+
*/
|
|
41
|
+
function matchesFilter(node, text, by) {
|
|
42
|
+
const values = by === 'component' ? componentTypes(node) : by === 'script' ? scriptNames(node) : [node.name || ''];
|
|
43
|
+
return values.some(value => value.toLowerCase().includes(text));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The distinct component types or script names in a hierarchy, sorted, to suggest while filtering
|
|
48
|
+
* by them.
|
|
49
|
+
*
|
|
50
|
+
* @param {GraphNode|null} root - The root of the hierarchy.
|
|
51
|
+
* @param {FilterBy} by - What to collect: 'component' or 'script'.
|
|
52
|
+
* @returns {string[]} The values, empty when filtering by name.
|
|
53
|
+
*/
|
|
54
|
+
function filterSuggestions(root, by) {
|
|
55
|
+
if (!root || by === 'name') return [];
|
|
56
|
+
const values = new Set();
|
|
57
|
+
root.forEach((node) => {
|
|
58
|
+
for (const value of by === 'component' ? componentTypes(node) : scriptNames(node)) values.add(value);
|
|
59
|
+
});
|
|
60
|
+
return [...values].sort();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {object} HierarchyEntry
|
|
65
|
+
* @ignore
|
|
66
|
+
* @property {HTMLElement} el - The node container, holding the row and the children container.
|
|
67
|
+
* @property {HTMLElement} row - The clickable row.
|
|
68
|
+
* @property {HTMLElement} arrowEl - The expand and collapse arrow.
|
|
69
|
+
* @property {HTMLInputElement} toggleEl - The checkbox bound to the node's own enabled flag.
|
|
70
|
+
* @property {HTMLElement} nameEl - The name label.
|
|
71
|
+
* @property {HTMLElement} badgesEl - The component badges.
|
|
72
|
+
* @property {HTMLElement} countEl - The number of children.
|
|
73
|
+
* @property {HTMLElement} totalEl - The number of nodes in the whole subtree below the node.
|
|
74
|
+
* @property {HTMLElement} childrenEl - The container the child entries live in.
|
|
75
|
+
* @property {string|undefined} name - The name last rendered.
|
|
76
|
+
* @property {string|undefined} badges - The badge text last rendered.
|
|
77
|
+
* @property {number} depth - The depth last rendered.
|
|
78
|
+
* @property {boolean} match - Whether the entry matched the filter on the last refresh.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {string} tag - The element tag.
|
|
83
|
+
* @param {string} className - The class name.
|
|
84
|
+
* @returns {HTMLElement} The element.
|
|
85
|
+
*/
|
|
86
|
+
function el(tag, className) {
|
|
87
|
+
const element = document.createElement(tag);
|
|
88
|
+
element.className = className;
|
|
89
|
+
return element;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A tree view over a {@link GraphNode} hierarchy. Rows are keyed by node and reconciled in place on
|
|
94
|
+
* every refresh, so the expansion state, the selection and the scroll position survive the scene
|
|
95
|
+
* changing underneath. Collapsed subtrees are not materialized, which keeps large scenes cheap.
|
|
96
|
+
*
|
|
97
|
+
* @ignore
|
|
98
|
+
*/
|
|
99
|
+
class HierarchyView {
|
|
100
|
+
/**
|
|
101
|
+
* The element the tree is rendered into.
|
|
102
|
+
*
|
|
103
|
+
* @type {HTMLElement}
|
|
104
|
+
*/
|
|
105
|
+
container;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Called with the newly selected node, or null when the selection is cleared.
|
|
109
|
+
*
|
|
110
|
+
* @type {(node: GraphNode|null) => void}
|
|
111
|
+
*/
|
|
112
|
+
onSelect;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Called after a node's enabled flag was flipped from its checkbox.
|
|
116
|
+
*
|
|
117
|
+
* @type {((node: GraphNode) => void)|undefined}
|
|
118
|
+
*/
|
|
119
|
+
onToggle;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Decides which nodes get no enabled checkbox. Defaults to none.
|
|
123
|
+
*
|
|
124
|
+
* @type {(node: GraphNode) => boolean}
|
|
125
|
+
*/
|
|
126
|
+
isLocked = () => false;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The root of the rendered hierarchy.
|
|
130
|
+
*
|
|
131
|
+
* @type {GraphNode|null}
|
|
132
|
+
*/
|
|
133
|
+
root = null;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The selected node.
|
|
137
|
+
*
|
|
138
|
+
* @type {GraphNode|null}
|
|
139
|
+
*/
|
|
140
|
+
selected = null;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Case-insensitive filter text. Nodes that match, and their ancestors, stay visible.
|
|
144
|
+
*
|
|
145
|
+
* @type {string}
|
|
146
|
+
*/
|
|
147
|
+
filter = '';
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* What the filter text matches: node names, component types or script names.
|
|
151
|
+
*
|
|
152
|
+
* @type {FilterBy}
|
|
153
|
+
*/
|
|
154
|
+
filterBy = 'name';
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The number of nodes in the hierarchy as of the last refresh.
|
|
158
|
+
*
|
|
159
|
+
* @type {number}
|
|
160
|
+
*/
|
|
161
|
+
nodeCount = 0;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The number of entities in the hierarchy as of the last refresh.
|
|
165
|
+
*
|
|
166
|
+
* @type {number}
|
|
167
|
+
*/
|
|
168
|
+
entityCount = 0;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @type {Map<GraphNode, HierarchyEntry>}
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
_entries = new Map();
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @type {WeakSet<GraphNode>}
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
_expanded = new WeakSet();
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @type {Set<GraphNode>}
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
_seen = new Set();
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* The number of nodes below each node, counted on every refresh.
|
|
190
|
+
*
|
|
191
|
+
* @type {Map<GraphNode, number>}
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
_descendants = new Map();
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {HTMLElement} container - The element to render into.
|
|
198
|
+
* @param {(node: GraphNode|null) => void} onSelect - The selection callback.
|
|
199
|
+
*/
|
|
200
|
+
constructor(container, onSelect) {
|
|
201
|
+
this.container = container;
|
|
202
|
+
this.onSelect = onSelect;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Replaces the hierarchy being shown.
|
|
207
|
+
*
|
|
208
|
+
* @param {GraphNode|null} root - The new root.
|
|
209
|
+
*/
|
|
210
|
+
setRoot(root) {
|
|
211
|
+
this.root = root;
|
|
212
|
+
this.container.textContent = '';
|
|
213
|
+
this._entries.clear();
|
|
214
|
+
this._expanded = new WeakSet();
|
|
215
|
+
if (root) {
|
|
216
|
+
this._expanded.add(root);
|
|
217
|
+
}
|
|
218
|
+
this.select(null);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Counts the nodes of a subtree, recording for each node how many are below it, and totals
|
|
223
|
+
* the nodes and entities of the hierarchy on the way.
|
|
224
|
+
*
|
|
225
|
+
* @param {GraphNode} node - The root of the subtree.
|
|
226
|
+
* @returns {number} The number of nodes below it.
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
_countSubtree(node) {
|
|
230
|
+
this.nodeCount++;
|
|
231
|
+
if (node instanceof Entity) this.entityCount++;
|
|
232
|
+
let below = 0;
|
|
233
|
+
for (const child of node.children) below += 1 + this._countSubtree(child);
|
|
234
|
+
this._descendants.set(node, below);
|
|
235
|
+
return below;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Synchronizes the rendered tree with the hierarchy.
|
|
240
|
+
*/
|
|
241
|
+
refresh() {
|
|
242
|
+
this._seen.clear();
|
|
243
|
+
this.nodeCount = 0;
|
|
244
|
+
this.entityCount = 0;
|
|
245
|
+
|
|
246
|
+
const root = this.root;
|
|
247
|
+
if (root) {
|
|
248
|
+
this._descendants.clear();
|
|
249
|
+
this._countSubtree(root);
|
|
250
|
+
|
|
251
|
+
this._visit(root, 0, this.filter.trim().toLowerCase());
|
|
252
|
+
const entry = this._entries.get(root);
|
|
253
|
+
if (entry.el.parentNode !== this.container) {
|
|
254
|
+
this.container.appendChild(entry.el);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
for (const [node, entry] of this._entries) {
|
|
259
|
+
if (!this._seen.has(node)) {
|
|
260
|
+
entry.el.remove();
|
|
261
|
+
this._entries.delete(node);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (this.selected && !this._seen.has(this.selected)) {
|
|
266
|
+
const selected = this.selected;
|
|
267
|
+
const entry = this._entries.get(selected);
|
|
268
|
+
if (!entry) {
|
|
269
|
+
// the node was destroyed or moved into a collapsed subtree
|
|
270
|
+
let alive = false;
|
|
271
|
+
root?.forEach((node) => {
|
|
272
|
+
if (node === selected) alive = true;
|
|
273
|
+
});
|
|
274
|
+
if (!alive) this.select(null);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Selects a node, expanding its ancestors and scrolling it into view.
|
|
281
|
+
*
|
|
282
|
+
* @param {GraphNode|null} node - The node, or null to clear the selection.
|
|
283
|
+
*/
|
|
284
|
+
select(node) {
|
|
285
|
+
const previous = this._entries.get(this.selected);
|
|
286
|
+
previous?.row.classList.remove('pci-selected');
|
|
287
|
+
|
|
288
|
+
this.selected = node;
|
|
289
|
+
|
|
290
|
+
if (node) {
|
|
291
|
+
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
292
|
+
this._expanded.add(parent);
|
|
293
|
+
}
|
|
294
|
+
this.refresh();
|
|
295
|
+
const entry = this._entries.get(node);
|
|
296
|
+
if (entry) {
|
|
297
|
+
entry.row.classList.add('pci-selected');
|
|
298
|
+
entry.row.scrollIntoView?.({ block: 'nearest' });
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
this.onSelect?.(node);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Toggles the expansion of a node.
|
|
307
|
+
*
|
|
308
|
+
* @param {GraphNode} node - The node.
|
|
309
|
+
* @param {boolean} [recursive] - Apply the new state to the whole subtree.
|
|
310
|
+
*/
|
|
311
|
+
toggle(node, recursive = false) {
|
|
312
|
+
const expanded = !this._expanded.has(node);
|
|
313
|
+
const apply = (n) => {
|
|
314
|
+
if (expanded) this._expanded.add(n);
|
|
315
|
+
else this._expanded.delete(n);
|
|
316
|
+
};
|
|
317
|
+
if (recursive) node.forEach(apply);
|
|
318
|
+
else apply(node);
|
|
319
|
+
this.refresh();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Renders a node and, when expanded or filtering, its subtree.
|
|
324
|
+
*
|
|
325
|
+
* @param {GraphNode} node - The node.
|
|
326
|
+
* @param {number} depth - The depth of the node below the root.
|
|
327
|
+
* @param {string} filter - The lower-cased filter text, empty for none.
|
|
328
|
+
* @returns {boolean} Whether the node or one of its descendants matches the filter.
|
|
329
|
+
* @private
|
|
330
|
+
*/
|
|
331
|
+
_visit(node, depth, filter) {
|
|
332
|
+
const entry = this._entries.get(node) ?? this._createEntry(node);
|
|
333
|
+
this._seen.add(node);
|
|
334
|
+
|
|
335
|
+
const isEntity = node instanceof Entity;
|
|
336
|
+
const name = node.name;
|
|
337
|
+
|
|
338
|
+
if (entry.name !== name) {
|
|
339
|
+
entry.name = name;
|
|
340
|
+
entry.nameEl.textContent = name || '(unnamed)';
|
|
341
|
+
}
|
|
342
|
+
if (entry.depth !== depth) {
|
|
343
|
+
entry.depth = depth;
|
|
344
|
+
entry.row.style.paddingLeft = `${depth * 14 + 4}px`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const badges = isEntity ? Object.keys(node.c).join(' ') : '';
|
|
348
|
+
if (entry.badges !== badges) {
|
|
349
|
+
entry.badges = badges;
|
|
350
|
+
entry.badgesEl.textContent = '';
|
|
351
|
+
for (const badge of badges ? badges.split(' ') : []) {
|
|
352
|
+
const badgeEl = el('span', 'pci-badge');
|
|
353
|
+
badgeEl.textContent = badge;
|
|
354
|
+
entry.badgesEl.appendChild(badgeEl);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
entry.row.classList.toggle('pci-disabled', !node.enabled);
|
|
359
|
+
entry.row.classList.toggle('pci-graphnode', !isEntity);
|
|
360
|
+
entry.row.classList.toggle('pci-selected', node === this.selected);
|
|
361
|
+
|
|
362
|
+
// the checkbox shows the node's own flag; the dimming above reflects the whole ancestry
|
|
363
|
+
const own = node._enabled;
|
|
364
|
+
if (entry.toggleEl.checked !== own) entry.toggleEl.checked = own;
|
|
365
|
+
const toggleVisibility = this.isLocked(node) ? 'hidden' : '';
|
|
366
|
+
if (entry.toggleEl.style.visibility !== toggleVisibility) {
|
|
367
|
+
entry.toggleEl.style.visibility = toggleVisibility;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// children are materialized only when shown, or when a filter needs to match them
|
|
371
|
+
const children = node.children;
|
|
372
|
+
const childCount = children.length;
|
|
373
|
+
const expanded = this._expanded.has(node);
|
|
374
|
+
let anyChildMatch = false;
|
|
375
|
+
|
|
376
|
+
if (childCount > 0 && (expanded || filter)) {
|
|
377
|
+
let cursor = entry.childrenEl.firstChild;
|
|
378
|
+
for (let i = 0; i < childCount; i++) {
|
|
379
|
+
const child = children[i];
|
|
380
|
+
if (this._visit(child, depth + 1, filter)) anyChildMatch = true;
|
|
381
|
+
const childEl = this._entries.get(child).el;
|
|
382
|
+
if (childEl !== cursor) {
|
|
383
|
+
entry.childrenEl.insertBefore(childEl, cursor);
|
|
384
|
+
} else {
|
|
385
|
+
cursor = cursor.nextSibling;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
} else if (entry.childrenEl.firstChild) {
|
|
389
|
+
entry.childrenEl.textContent = '';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const selfMatch = !filter || matchesFilter(node, filter, this.filterBy);
|
|
393
|
+
const match = selfMatch || anyChildMatch;
|
|
394
|
+
const open = childCount > 0 && (expanded || (filter && anyChildMatch));
|
|
395
|
+
|
|
396
|
+
this._setDisplay(entry.el, match);
|
|
397
|
+
this._setDisplay(entry.childrenEl, !!open);
|
|
398
|
+
entry.row.classList.toggle('pci-match', !!filter && selfMatch);
|
|
399
|
+
|
|
400
|
+
const arrow = childCount === 0 ? '' : (open ? '▾' : '▸');
|
|
401
|
+
if (entry.arrowEl.textContent !== arrow) entry.arrowEl.textContent = arrow;
|
|
402
|
+
|
|
403
|
+
const count = childCount > 0 ? String(childCount) : '';
|
|
404
|
+
if (entry.countEl.textContent !== count) entry.countEl.textContent = count;
|
|
405
|
+
const total = childCount > 0 ? String(this._descendants.get(node) ?? 0) : '';
|
|
406
|
+
if (entry.totalEl.textContent !== total) entry.totalEl.textContent = total;
|
|
407
|
+
|
|
408
|
+
entry.match = match;
|
|
409
|
+
return match;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* @param {HTMLElement} element - The element.
|
|
414
|
+
* @param {boolean} shown - Whether it is shown.
|
|
415
|
+
* @private
|
|
416
|
+
*/
|
|
417
|
+
_setDisplay(element, shown) {
|
|
418
|
+
const display = shown ? '' : 'none';
|
|
419
|
+
if (element.style.display !== display) element.style.display = display;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* @param {GraphNode} node - The node.
|
|
424
|
+
* @returns {HierarchyEntry} The new entry.
|
|
425
|
+
* @private
|
|
426
|
+
*/
|
|
427
|
+
_createEntry(node) {
|
|
428
|
+
const toggleEl = /** @type {HTMLInputElement} */ (document.createElement('input'));
|
|
429
|
+
toggleEl.type = 'checkbox';
|
|
430
|
+
toggleEl.className = 'pci-toggle';
|
|
431
|
+
setTip(toggleEl, 'Enabled');
|
|
432
|
+
|
|
433
|
+
const entry = {
|
|
434
|
+
el: el('div', 'pci-node'),
|
|
435
|
+
row: el('div', 'pci-row'),
|
|
436
|
+
arrowEl: el('span', 'pci-arrow'),
|
|
437
|
+
toggleEl,
|
|
438
|
+
nameEl: el('span', 'pci-name'),
|
|
439
|
+
badgesEl: el('span', 'pci-badges'),
|
|
440
|
+
countEl: el('span', 'pci-count'),
|
|
441
|
+
totalEl: el('span', 'pci-count pci-count-total'),
|
|
442
|
+
childrenEl: el('div', 'pci-children'),
|
|
443
|
+
name: undefined,
|
|
444
|
+
badges: undefined,
|
|
445
|
+
depth: -1,
|
|
446
|
+
match: true
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
setTip(entry.countEl, 'Children');
|
|
450
|
+
setTip(entry.totalEl, 'All nodes below, however deep');
|
|
451
|
+
entry.row.append(entry.arrowEl, entry.toggleEl, entry.nameEl, entry.badgesEl, entry.countEl, entry.totalEl);
|
|
452
|
+
entry.el.append(entry.row, entry.childrenEl);
|
|
453
|
+
|
|
454
|
+
entry.arrowEl.addEventListener('click', (e) => {
|
|
455
|
+
e.stopPropagation();
|
|
456
|
+
this.toggle(node, e.altKey);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// the checkbox must not select the row or toggle its expansion
|
|
460
|
+
toggleEl.addEventListener('click', e => e.stopPropagation());
|
|
461
|
+
toggleEl.addEventListener('dblclick', e => e.stopPropagation());
|
|
462
|
+
toggleEl.addEventListener('change', () => {
|
|
463
|
+
node.enabled = toggleEl.checked;
|
|
464
|
+
this.refresh();
|
|
465
|
+
this.onToggle?.(node);
|
|
466
|
+
});
|
|
467
|
+
entry.row.addEventListener('click', () => this.select(node));
|
|
468
|
+
entry.row.addEventListener('dblclick', e => this.toggle(node, e.altKey));
|
|
469
|
+
|
|
470
|
+
this._entries.set(node, entry);
|
|
471
|
+
return entry;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export { HierarchyView, filterSuggestions, matchesFilter };
|
package/src/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Quat, Vec3 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { InputController } from './input.js';
|
|
4
|
+
import { Pose } from './pose.js';
|
|
5
|
+
import { damp } from './math.js';
|
|
6
|
+
|
|
7
|
+
/** @import { InputFrame } from './input.js'; */
|
|
8
|
+
|
|
9
|
+
const offset = new Vec3();
|
|
10
|
+
const angles = new Vec3();
|
|
11
|
+
|
|
12
|
+
const forward = new Vec3();
|
|
13
|
+
const right = new Vec3();
|
|
14
|
+
const up = new Vec3();
|
|
15
|
+
|
|
16
|
+
const rotation = new Quat();
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The fly controller. Free flight: `rotate` deltas turn the pose about yaw and pitch, limited by
|
|
20
|
+
* {@link yawRange} and {@link pitchRange}, and `move` deltas translate it along its own right, up
|
|
21
|
+
* and forward axes, so movement follows where the camera looks. Motion is smoothed with
|
|
22
|
+
* {@link rotateDamping} and {@link moveDamping}.
|
|
23
|
+
*
|
|
24
|
+
* @category Input
|
|
25
|
+
* @alpha
|
|
26
|
+
*/
|
|
27
|
+
class FlyController extends InputController {
|
|
28
|
+
/**
|
|
29
|
+
* @type {Pose}
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
_targetPose = new Pose();
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The rotation damping. In the range 0 to 1, where a value of 0 means no damping and 1 means
|
|
36
|
+
* full damping. Default is 0.98.
|
|
37
|
+
*/
|
|
38
|
+
rotateDamping = 0.98;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The movement damping. In the range 0 to 1, where a value of 0 means no damping and 1 means
|
|
42
|
+
* full damping. Default is 0.98.
|
|
43
|
+
*/
|
|
44
|
+
moveDamping = 0.98;
|
|
45
|
+
|
|
46
|
+
set pitchRange(value) {
|
|
47
|
+
this._targetPose.pitchRange.copy(value);
|
|
48
|
+
this._pose.copy(this._targetPose.rotate(Vec3.ZERO));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get pitchRange() {
|
|
52
|
+
return this._targetPose.pitchRange;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set yawRange(value) {
|
|
56
|
+
this._targetPose.yawRange.copy(value);
|
|
57
|
+
this._pose.copy(this._targetPose.rotate(Vec3.ZERO));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get yawRange() {
|
|
61
|
+
return this._targetPose.yawRange;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Pose} pose - The initial pose of the controller.
|
|
66
|
+
* @param {boolean} [smooth] - Whether to smooth the transition.
|
|
67
|
+
*/
|
|
68
|
+
attach(pose, smooth = true) {
|
|
69
|
+
this._targetPose.copy(pose);
|
|
70
|
+
|
|
71
|
+
if (!smooth) {
|
|
72
|
+
this._pose.copy(this._targetPose);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
detach() {
|
|
77
|
+
this._targetPose.copy(this._pose);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {InputFrame<{ move: number[], rotate: number[] }>} frame - The input frame.
|
|
82
|
+
* @param {number} dt - The delta time.
|
|
83
|
+
* @returns {Pose} - The controller pose.
|
|
84
|
+
*/
|
|
85
|
+
update(frame, dt) {
|
|
86
|
+
const { move, rotate } = frame.read();
|
|
87
|
+
|
|
88
|
+
// rotate
|
|
89
|
+
this._targetPose.rotate(angles.set(-rotate[1], -rotate[0], 0));
|
|
90
|
+
|
|
91
|
+
// move
|
|
92
|
+
rotation.setFromEulerAngles(this._pose.angles);
|
|
93
|
+
rotation.transformVector(Vec3.FORWARD, forward);
|
|
94
|
+
rotation.transformVector(Vec3.RIGHT, right);
|
|
95
|
+
rotation.transformVector(Vec3.UP, up);
|
|
96
|
+
offset.set(0, 0, 0);
|
|
97
|
+
offset.add(forward.mulScalar(move[2]));
|
|
98
|
+
offset.add(right.mulScalar(move[0]));
|
|
99
|
+
offset.add(up.mulScalar(move[1]));
|
|
100
|
+
this._targetPose.move(offset);
|
|
101
|
+
|
|
102
|
+
// smoothing
|
|
103
|
+
return this._pose.lerp(
|
|
104
|
+
this._pose,
|
|
105
|
+
this._targetPose,
|
|
106
|
+
damp(this.moveDamping, dt),
|
|
107
|
+
damp(this.rotateDamping, dt)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
destroy() {
|
|
112
|
+
this.detach();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export { FlyController };
|