@threenative/three-native 0.3.10 → 0.3.12

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.
@@ -0,0 +1,500 @@
1
+ /**
2
+ * The browser back end's runtime over a loaded ABI module (PRD-532, PRD-803): one engine context,
3
+ * every call checked, and each call's scratch taken from an arena a scope rewinds.
4
+ */
5
+ import {
6
+ type EngineValue,
7
+ HANDLE,
8
+ type IAbiHelpers,
9
+ type IBrowserRuntime,
10
+ type IEngineRef,
11
+ type IPackedRef,
12
+ KIND,
13
+ type TnAbiModule,
14
+ VALUE,
15
+ gltfOf,
16
+ isRef,
17
+ tslOf,
18
+ } from "./browser-abi-types.js";
19
+ import { SCALARS, TYPED, type TypedArray } from "./browser-marshal.js";
20
+ import { debugTelemetry } from "./debug-telemetry.js";
21
+
22
+ /**
23
+ * Opt-in boundary census for `pnpm profile:wasm-page --calls`: while the page sets
24
+ * `globalThis.__tnCallCounts` to a Map, every engine get, set and invoke counts under
25
+ * "<kind> <type id>.<name>" (`__tnEngineTypes` names the type ids). Off, it costs one global read.
26
+ */
27
+ function countCall(kind: string, self: IEngineRef, name: string): void {
28
+ const counts = (globalThis as { __tnCallCounts?: Map<string, number> }).__tnCallCounts;
29
+ if (counts === undefined) return;
30
+ const key = `${kind} ${self.type}.${name}`;
31
+ counts.set(key, (counts.get(key) ?? 0) + 1);
32
+ }
33
+
34
+ export function createWasmRuntime(abi: TnAbiModule): IBrowserRuntime {
35
+ const debug = debugTelemetry(abi);
36
+ let encoding = "arguments";
37
+ // The heap's views, made again only when the memory grows: Emscripten replaces HEAPU8 then, so one
38
+ // identity test per use stands in for reading two `.buffer`s, which every crossing paid (PRD-748).
39
+ let heap = abi.HEAPU8;
40
+ let heapBytes = heap.byteLength;
41
+ let dataView = new DataView(heap.buffer);
42
+ let words = new Uint32Array(heap.buffer);
43
+ const grown = () => {
44
+ debug?.add("wasmGrowthEvents", 1, "bridge");
45
+ debug?.add("wasmGrowthBytes", Math.max(0, abi.HEAPU8.byteLength - heapBytes), "memory");
46
+ heap = abi.HEAPU8;
47
+ heapBytes = heap.byteLength;
48
+ dataView = new DataView(heap.buffer);
49
+ words = new Uint32Array(heap.buffer);
50
+ };
51
+ const view = () => {
52
+ if (abi.HEAPU8 !== heap) grown();
53
+ return dataView;
54
+ };
55
+ const wordView = () => {
56
+ if (abi.HEAPU8 !== heap) grown();
57
+ return words;
58
+ };
59
+ // Each call frees what it allocated, and only that: a callback can run a nested call.
60
+ // A call's scratch (its handle, arguments, result and diagnostic) comes from one arena that each
61
+ // scope rewinds, a stack as nested calls (a callback inside an invoke) need; a scope that outgrows
62
+ // it falls back to malloc and frees on exit. Every engine call crosses here, many per frame.
63
+ const arenaSize = 64 * 1024;
64
+ const arenaBase = abi._malloc(arenaSize) >>> 0;
65
+ let arenaTop = arenaBase;
66
+ const allocations: number[] = [];
67
+ const alloc = (size: number): number => {
68
+ const aligned = (size + 7) & ~7;
69
+ debug?.add("bridgeScratchBytes", aligned, "bridge");
70
+ let pointer: number;
71
+ if (arenaTop + aligned <= arenaBase + arenaSize) {
72
+ pointer = arenaTop;
73
+ arenaTop += aligned;
74
+ } else {
75
+ // `>>> 0`: the module addresses up to 4 GB, and an export returns a pointer as a signed i32.
76
+ pointer = abi._malloc(aligned) >>> 0;
77
+ allocations.push(pointer);
78
+ debug?.add("bridgeOverflowAllocations", 1, "bridge");
79
+ debug?.add("bridgeOverflowBytes", aligned, "bridge");
80
+ }
81
+ // A call's scratch is a few words (a handle, a value, a diagnostic): word stores beat a fill call.
82
+ // `wordView` first: a `_malloc` above may have grown the memory.
83
+ const w = wordView();
84
+ if (aligned > 64) heap.fill(0, pointer, pointer + aligned);
85
+ else for (let at = pointer >>> 2, end = (pointer + aligned) >>> 2; at < end; at++) w[at] = 0;
86
+ return pointer;
87
+ };
88
+ const scoped = <T>(work: () => T): T => {
89
+ const mark = allocations.length;
90
+ const top = arenaTop;
91
+ try {
92
+ return work();
93
+ } finally {
94
+ while (allocations.length > mark) abi._free(allocations.pop() as number);
95
+ arenaTop = top;
96
+ }
97
+ };
98
+ const string = (text: string): { pointer: number; bytes: number } => {
99
+ const bytes = abi.lengthBytesUTF8(text);
100
+ const pointer = alloc(bytes + 1);
101
+ abi.stringToUTF8(text, pointer, bytes + 1);
102
+ return { pointer, bytes };
103
+ };
104
+ // Member, method and class names: a bounded set, encoded once and kept for the module's life.
105
+ const names = new Map<string, number>();
106
+ const name = (text: string): number => {
107
+ let pointer = names.get(text);
108
+ if (pointer === undefined) {
109
+ const bytes = abi.lengthBytesUTF8(text);
110
+ pointer = abi._malloc(bytes + 1) >>> 0;
111
+ abi.stringToUTF8(text, pointer, bytes + 1);
112
+ names.set(text, pointer);
113
+ }
114
+ return pointer;
115
+ };
116
+ const diagnostic = () => alloc(8);
117
+ const check = (status: number, diag: number, what: string) => {
118
+ if (status === 0) return;
119
+ const message = view().getUint32(diag, true);
120
+ const text = message === 0 ? "" : abi.UTF8ToString(message);
121
+ abi._tn_diagnostic_release(diag);
122
+ throw new Error(`TN_ABI_${status}: ${what}${text ? `: ${text}` : ""}`);
123
+ };
124
+ // A handle is three words in memory: type and context as two halves of the first, then index and
125
+ // generation. A ref made here keeps those words, so writing one back is three stores, no parse.
126
+ const keyOf = (pointer: number): IEngineRef => {
127
+ const v = view();
128
+ const type = v.getUint16(pointer, true);
129
+ const context = v.getUint16(pointer + 2, true);
130
+ const index = v.getUint32(pointer + 4, true);
131
+ const generation = v.getUint32(pointer + 8, true);
132
+ const ref: IPackedRef = {
133
+ key: `${type}:${context}:${index}:${generation}`,
134
+ type,
135
+ w0: (type | (context << 16)) >>> 0,
136
+ w1: index,
137
+ w2: generation,
138
+ };
139
+ return ref;
140
+ };
141
+ const writeHandle = (pointer: number, ref: IEngineRef) => {
142
+ let packed = ref as Partial<IPackedRef>;
143
+ if (packed.w0 === undefined) {
144
+ // A ref some other source made: parse its key once and keep the words on it.
145
+ const [type = 0, context = 0, index = 0, generation = 0] = ref.key.split(":").map(Number);
146
+ packed = Object.isExtensible(ref) ? (ref as IPackedRef) : { ...ref };
147
+ Object.assign(packed, { w0: (type | (context << 16)) >>> 0, w1: index, w2: generation });
148
+ }
149
+ if ((pointer & 3) === 0) {
150
+ const at = pointer >>> 2;
151
+ const w = wordView();
152
+ w[at] = packed.w0 as number;
153
+ w[at + 1] = packed.w1 as number;
154
+ w[at + 2] = packed.w2 as number;
155
+ return;
156
+ }
157
+ const v = view();
158
+ v.setUint32(pointer, packed.w0 as number, true);
159
+ v.setUint32(pointer + 4, packed.w1 as number, true);
160
+ v.setUint32(pointer + 8, packed.w2 as number, true);
161
+ };
162
+ const handleOf = (ref: IEngineRef): number => {
163
+ const pointer = alloc(HANDLE);
164
+ writeHandle(pointer, ref);
165
+ return pointer;
166
+ };
167
+ const writeValue = (pointer: number, value: EngineValue) => {
168
+ const v = view();
169
+ if (value === null) return v.setUint32(pointer, KIND.null, true);
170
+ if (value === undefined) return v.setUint32(pointer, KIND.undefined, true);
171
+ if (typeof value === "number") {
172
+ v.setUint32(pointer, KIND.number, true);
173
+ return v.setFloat64(pointer + 8, value, true);
174
+ }
175
+ if (typeof value === "boolean") {
176
+ v.setUint32(pointer, KIND.bool, true);
177
+ return v.setUint32(pointer + 4, value ? 1 : 0, true);
178
+ }
179
+ if (typeof value === "string") {
180
+ const text = string(value);
181
+ const w = view();
182
+ w.setUint32(pointer, KIND.string, true);
183
+ w.setUint32(pointer + 32, text.pointer, true);
184
+ return w.setBigUint64(pointer + 40, BigInt(text.bytes), true);
185
+ }
186
+ if (isRef(value)) {
187
+ v.setUint32(pointer, KIND.handle, true);
188
+ return writeHandle(pointer + 16, value);
189
+ }
190
+ if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
191
+ // A forwarded typed array (see `toEngine`): one heap copy, its view bounds kept, no boxed list.
192
+ const typed = value as TypedArray;
193
+ debug?.widen(typed, encoding, typed.byteLength);
194
+ const numbers = alloc(Math.max(8, typed.byteLength));
195
+ abi.HEAPU8.set(new Uint8Array(typed.buffer, typed.byteOffset, typed.byteLength), numbers);
196
+ const name = string(typed.constructor.name).pointer;
197
+ const w = view();
198
+ w.setUint32(pointer, KIND.bytes, true);
199
+ w.setUint32(pointer + 32, name, true);
200
+ w.setUint32(pointer + 48, numbers, true);
201
+ return w.setBigUint64(pointer + 40, BigInt(typed.length), true);
202
+ }
203
+ if (!Array.isArray(value)) {
204
+ // A record: count key/value pairs, each key a string value, as the engine returns one.
205
+ const entries = Object.entries(value as Record<string, EngineValue>);
206
+ const children = values(entries.flat());
207
+ const w = view();
208
+ w.setUint32(pointer, KIND.record, true);
209
+ w.setUint32(pointer + 48, children, true);
210
+ return w.setBigUint64(pointer + 40, BigInt(entries.length), true);
211
+ }
212
+ if (value.every((item) => typeof item === "number")) {
213
+ const numbers = alloc(Math.max(8, value.length * 8));
214
+ abi.HEAPF64.set(value as number[], numbers / 8);
215
+ const typed = (value as { [TYPED]?: string })[TYPED];
216
+ const name = typed === undefined ? 0 : string(typed).pointer;
217
+ const w = view();
218
+ w.setUint32(pointer, KIND.numbers, true);
219
+ w.setUint32(pointer + 32, name, true);
220
+ w.setUint32(pointer + 48, numbers, true);
221
+ w.setBigUint64(pointer + 40, BigInt(value.length), true);
222
+ } else {
223
+ const children = values(value);
224
+ const w = view();
225
+ w.setUint32(pointer, KIND.array, true);
226
+ w.setUint32(pointer + 48, children, true);
227
+ w.setBigUint64(pointer + 40, BigInt(value.length), true);
228
+ }
229
+ };
230
+ const values = (args: readonly EngineValue[]): number => {
231
+ const pointer = alloc(Math.max(VALUE, args.length * VALUE));
232
+ args.forEach((arg, i) => writeValue(pointer + i * VALUE, arg));
233
+ return pointer;
234
+ };
235
+ const readValue = (pointer: number): EngineValue => {
236
+ const v = view();
237
+ switch (v.getUint32(pointer, true)) {
238
+ case KIND.undefined:
239
+ return undefined;
240
+ case KIND.number:
241
+ return v.getFloat64(pointer + 8, true);
242
+ case KIND.bool:
243
+ return v.getUint32(pointer + 4, true) !== 0;
244
+ case KIND.string:
245
+ return abi.UTF8ToString(
246
+ v.getUint32(pointer + 32, true),
247
+ Number(v.getBigUint64(pointer + 40, true)),
248
+ );
249
+ case KIND.handle:
250
+ return keyOf(pointer + 16);
251
+ case KIND.array: {
252
+ const at = v.getUint32(pointer + 48, true);
253
+ return Array.from({ length: Number(v.getBigUint64(pointer + 40, true)) }, (_, i) =>
254
+ readValue(at + i * VALUE),
255
+ );
256
+ }
257
+ case KIND.record: {
258
+ const at = v.getUint32(pointer + 48, true);
259
+ return Object.fromEntries(
260
+ Array.from({ length: Number(v.getBigUint64(pointer + 40, true)) }, (_, i) => {
261
+ const key = readValue(at + i * 2 * VALUE);
262
+ if (typeof key !== "string") throw new TypeError("TN_ABI_RECORD_KEY: expected string");
263
+ return [key, readValue(at + (i * 2 + 1) * VALUE)];
264
+ }),
265
+ );
266
+ }
267
+ case KIND.numbers: {
268
+ const at = v.getUint32(pointer + 48, true) / 8;
269
+ return Array.from(
270
+ abi.HEAPF64.subarray(at, at + Number(v.getBigUint64(pointer + 40, true))),
271
+ );
272
+ }
273
+ default:
274
+ return null;
275
+ }
276
+ };
277
+
278
+ // Callbacks: one invoke and one release trampoline in the function table; the context is a
279
+ // handler id, and the engine's release (once per pair) forgets it.
280
+ const handlers = new Map<number, (args: readonly EngineValue[]) => void>();
281
+ let nextHandler = 1;
282
+ let invokeTrampoline = 0;
283
+ let releaseTrampoline = 0;
284
+ const trampolines = () => {
285
+ if (invokeTrampoline !== 0) return;
286
+ invokeTrampoline = abi.addFunction((id, rawArgs, count, rawError, capacity) => {
287
+ // Pointers arrive as signed i32; the module addresses up to 4 GB.
288
+ const args = (rawArgs ?? 0) >>> 0;
289
+ const error = (rawError ?? 0) >>> 0;
290
+ const handler = handlers.get(id ?? 0);
291
+ if (handler === undefined) return 0;
292
+ const decoded: EngineValue[] = [];
293
+ for (let i = 0; i < (count ?? 0); i++) decoded.push(readValue(args + i * VALUE));
294
+ try {
295
+ handler(decoded);
296
+ return 0;
297
+ } catch (thrown) {
298
+ abi.stringToUTF8(
299
+ thrown instanceof Error ? thrown.message : String(thrown),
300
+ error,
301
+ capacity ?? 0,
302
+ );
303
+ return 8; // TN_ERROR_INVALID_STATE: the engine records it and goes on
304
+ }
305
+ }, "iiiiii");
306
+ releaseTrampoline = abi.addFunction((id) => {
307
+ handlers.delete(id ?? 0);
308
+ return undefined;
309
+ }, "vi");
310
+ };
311
+
312
+ // A view over the attribute's storage, used only inside one call: the lease pins the storage and
313
+ // nothing in between can grow the memory and detach the view. A kept view would detach on growth,
314
+ // so the back end keeps JS arrays and copies through this (see defineBrowserClasses).
315
+ const withAttributeView = <T>(self: IEngineRef, use: (view: TypedArray) => T): T =>
316
+ scoped(() => {
317
+ const call = abi._tnw_attribute_view;
318
+ if (call === undefined)
319
+ throw new TypeError("TN_WASM_MODULE: this module exports no attribute views");
320
+ const out = alloc(24);
321
+ const lease = call(handleOf(self), out);
322
+ if (lease === 0) throw new TypeError("TN_NATIVE_UNSUPPORTED array: not an attribute");
323
+ try {
324
+ const v = view();
325
+ const [address, count, scalar] = [0, 8, 16].map((at) =>
326
+ Number(v.getBigUint64(out + at, true)),
327
+ );
328
+ const Typed = SCALARS[scalar ?? -1];
329
+ if (Typed === undefined)
330
+ throw new TypeError(`TN_NATIVE_UNSUPPORTED array: scalar ${String(scalar)}`);
331
+ return use(new Typed(abi.HEAPU8.buffer as ArrayBuffer, address ?? 0, count ?? 0));
332
+ } finally {
333
+ abi._tnw_attribute_view_release?.(lease);
334
+ }
335
+ });
336
+
337
+ const context = scoped(() => {
338
+ const version = alloc(32);
339
+ abi._tn_engine_version(version);
340
+ const contextOut = alloc(4);
341
+ const diag = diagnostic();
342
+ check(abi._tn_context_create(contextOut, version, diag), diag, "tn_context_create");
343
+ return view().getUint32(contextOut, true);
344
+ });
345
+
346
+ return {
347
+ ...(tslOf(abi, context, {
348
+ scoped,
349
+ alloc,
350
+ string,
351
+ diagnostic,
352
+ check,
353
+ handleOf,
354
+ writeHandle,
355
+ view,
356
+ }) ?? {}),
357
+ ...gltfOf(abi, context, { scoped, alloc, keyOf }),
358
+ ...(debug === undefined ? {} : { debugTelemetry: debug }),
359
+ typedArrays: true,
360
+ typeId: (className) => abi._tn_type_id(name(className)),
361
+ construct: (className, args) =>
362
+ scoped(() => {
363
+ const out = alloc(HANDLE);
364
+ const diag = diagnostic();
365
+ check(
366
+ abi._tn_construct(
367
+ context,
368
+ string(className).pointer,
369
+ values(args),
370
+ args.length,
371
+ out,
372
+ diag,
373
+ ),
374
+ diag,
375
+ `new ${className}`,
376
+ );
377
+ return keyOf(out);
378
+ }),
379
+ invoke: (self, method, args) =>
380
+ scoped(() => {
381
+ countCall("call", self, method);
382
+ if (debug !== undefined) encoding = method;
383
+ const out = alloc(VALUE);
384
+ const diag = diagnostic();
385
+ check(
386
+ abi._tn_invoke(handleOf(self), name(method), values(args), args.length, out, diag),
387
+ diag,
388
+ `${method}()`,
389
+ );
390
+ return readValue(out);
391
+ }),
392
+ engineReferences: (refs) =>
393
+ scoped(() => {
394
+ const handles = alloc(Math.max(1, refs.length) * HANDLE);
395
+ refs.forEach((ref, i) => writeHandle(handles + i * HANDLE, ref));
396
+ const out = alloc(Math.max(1, refs.length) * 4);
397
+ abi._tn_object_engine_references(handles, refs.length, out);
398
+ const v = view();
399
+ return refs.map((_, i) => v.getUint32(out + i * 4, true));
400
+ }),
401
+ readByte: (address) => abi.HEAPU8[address] as number,
402
+ readWord: (address) => view().getUint32(address, true),
403
+ writeDouble: (address, value) => {
404
+ abi.HEAPF64[address / 8] = value;
405
+ },
406
+ writeByte: (address, value) => {
407
+ abi.HEAPU8[address] = value;
408
+ },
409
+ heapF64: () => abi.HEAPF64,
410
+ readDoubles: (address, count) => {
411
+ const at = address / 8;
412
+ return count === 1
413
+ ? (abi.HEAPF64[at] as number)
414
+ : Array.from(abi.HEAPF64.subarray(at, at + count));
415
+ },
416
+ get: (self, path) =>
417
+ scoped(() => {
418
+ countCall("get", self, path);
419
+ const out = alloc(VALUE);
420
+ const diag = diagnostic();
421
+ check(abi._tn_get(handleOf(self), name(path), out, diag), diag, `get ${path}`);
422
+ return readValue(out);
423
+ }),
424
+ set: (self, path, value) =>
425
+ scoped(() => {
426
+ countCall("set", self, path);
427
+ if (debug !== undefined) encoding = path;
428
+ // One value written in place: no one-item list per write.
429
+ const pointer = alloc(VALUE);
430
+ writeValue(pointer, value);
431
+ const diag = diagnostic();
432
+ check(abi._tn_set(handleOf(self), name(path), pointer, diag), diag, `set ${path}`);
433
+ }),
434
+ release: (self) =>
435
+ scoped(() => {
436
+ const diag = diagnostic();
437
+ abi._tn_object_release(handleOf(self), diag);
438
+ abi._tn_diagnostic_release(diag);
439
+ }),
440
+ attributeArray: (self, offset, count) =>
441
+ withAttributeView(self, (target) => {
442
+ const from = offset === undefined ? 0 : offset;
443
+ const length = count === undefined ? target.length - from : count;
444
+ if (
445
+ !Number.isSafeInteger(from) ||
446
+ !Number.isSafeInteger(length) ||
447
+ from < 0 ||
448
+ length < 0 ||
449
+ from + length > target.length
450
+ )
451
+ throw new RangeError(
452
+ `TN_NATIVE_ATTRIBUTE_RANGE: [${String(from)}, ${String(length)}) is outside ${String(target.length)} elements`,
453
+ );
454
+ return target.subarray(from, from + length).slice();
455
+ }),
456
+ attributeWrite: (self, array, offset) =>
457
+ withAttributeView(self, (target) => {
458
+ // An omitted offset writes the whole attribute, so the array must be its exact data; an
459
+ // explicit offset (including 0) writes that subrange.
460
+ if (offset === undefined) {
461
+ if (target.length !== array.length)
462
+ throw new RangeError(
463
+ `TN_NATIVE_ATTRIBUTE_LENGTH: attribute.array has ${String(array.length)} elements, the attribute ${String(target.length)}`,
464
+ );
465
+ target.set(array);
466
+ return;
467
+ }
468
+ if (!Number.isSafeInteger(offset) || offset < 0 || offset + array.length > target.length)
469
+ throw new RangeError(
470
+ `TN_NATIVE_ATTRIBUTE_LENGTH: attribute.array has ${String(array.length)} elements at ${String(offset)}, the attribute ${String(target.length)}`,
471
+ );
472
+ target.set(array, offset);
473
+ }),
474
+ setCallback: (self, name, handler) =>
475
+ scoped(() => {
476
+ const diag = diagnostic();
477
+ if (handler === null) {
478
+ check(
479
+ abi._tn_set_callback(handleOf(self), string(name).pointer, 0, 0, 0, diag),
480
+ diag,
481
+ `clear ${name}`,
482
+ );
483
+ return;
484
+ }
485
+ trampolines();
486
+ const id = nextHandler++;
487
+ handlers.set(id, handler);
488
+ const status = abi._tn_set_callback(
489
+ handleOf(self),
490
+ string(name).pointer,
491
+ invokeTrampoline,
492
+ id,
493
+ releaseTrampoline,
494
+ diag,
495
+ );
496
+ if (status !== 0) handlers.delete(id); // a refused pair was never taken
497
+ check(status, diag, `set ${name}`);
498
+ }),
499
+ };
500
+ }
@@ -26,6 +26,9 @@ export class DebugTelemetry {
26
26
  name: string,
27
27
  amount = 1,
28
28
  area = "bridge",
29
+ // Every counter the back end adds keeps this name, including the ones `browser-wasm-runtime.ts`
30
+ // adds since PRD-803 split it out: the split moved code, so the attribution a debug report shows
31
+ // does not move with it.
29
32
  caller = "browser-backend.ts",
30
33
  unit?: string,
31
34
  ): void {
@@ -200,6 +200,7 @@ const FLAGGED_CLASSES = [
200
200
  "NodeMaterial",
201
201
  "MeshBasicNodeMaterial",
202
202
  "MeshStandardNodeMaterial",
203
+ "MeshPhysicalNodeMaterial",
203
204
  "SpriteNodeMaterial",
204
205
  "Texture",
205
206
  "DataTexture",
@@ -227,6 +228,22 @@ const FLAGGED_CLASSES = [
227
228
  "SpotLight",
228
229
  ] as const;
229
230
 
231
+ /**
232
+ * three's `dispose()` on lights and instanced meshes frees a shadow map or the instance textures. The
233
+ * engine frees those with the object, so the call has nothing to release (core's projection mirror
234
+ * and a scene's exit make it). A back end's own `dispose` stays.
235
+ */
236
+ export function defineReleaseNoops(classes: Readonly<Record<string, unknown>>): void {
237
+ for (const name of [
238
+ "BatchedMesh",
239
+ "InstancedMesh",
240
+ ...FLAGGED_CLASSES.filter((n) => n.endsWith("Light")),
241
+ ]) {
242
+ const cls = classes[name] as (new () => { dispose?: () => void }) | undefined;
243
+ if (typeof cls === "function") cls.prototype.dispose ??= () => {};
244
+ }
245
+ }
246
+
230
247
  /**
231
248
  * Puts three's type flags (`isMesh`, `isCamera`, `isLight`, ...) on a back end's scene classes. A
232
249
  * subclass inherits its parent's through the prototype chain, as in three; a missing class is skipped.