@threenative/three-native 0.0.0-stage → 0.3.5

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -2
  3. package/package.json +42 -3
  4. package/src/addons/buffer-geometry-utils.ts +14 -0
  5. package/src/addons/data-utils.ts +63 -0
  6. package/src/addons/decal-geometry.ts +25 -0
  7. package/src/addons/decal.ts +218 -0
  8. package/src/addons/gltf-loader-web.ts +323 -0
  9. package/src/addons/hdr-loader.ts +71 -0
  10. package/src/addons/hdr.ts +139 -0
  11. package/src/addons/lut-cube-loader-web.ts +17 -0
  12. package/src/addons/lut-cube-loader.ts +149 -0
  13. package/src/addons/merge-geometries.ts +374 -0
  14. package/src/addons/mesh-bvh-webgpu.ts +13 -0
  15. package/src/addons/mesh-bvh.ts +50 -0
  16. package/src/addons/post-effects-web.ts +22 -0
  17. package/src/addons/post-effects.ts +173 -0
  18. package/src/audio.ts +564 -0
  19. package/src/blend-mode.ts +33 -0
  20. package/src/browser-backend.ts +2156 -0
  21. package/src/browser-entry.ts +305 -0
  22. package/src/browser-math.ts +448 -0
  23. package/src/browser-renderer.ts +527 -0
  24. package/src/browser-tsl.ts +650 -0
  25. package/src/catalog.ts +497 -0
  26. package/src/fixture-format.ts +721 -0
  27. package/src/fixture-native.ts +426 -0
  28. package/src/fixture-protocol.ts +315 -0
  29. package/src/math-utils.ts +65 -0
  30. package/src/object-surface.ts +250 -0
  31. package/src/pass-node.ts +286 -0
  32. package/src/property-binding.ts +93 -0
  33. package/src/quad-mesh.ts +54 -0
  34. package/src/reflector.ts +89 -0
  35. package/src/refused.ts +27 -0
  36. package/src/render-target.ts +107 -0
  37. package/src/rtt.ts +158 -0
  38. package/src/shadow-map.ts +21 -0
  39. package/src/storage.ts +206 -0
  40. package/src/texture-sources.ts +252 -0
  41. package/src/tsl-extras.ts +51 -0
  42. package/src/tsl-struct.ts +20 -0
  43. package/src/tsl-uniforms.ts +234 -0
  44. package/src/update-ranges.ts +109 -0
  45. package/src/wgsl-fn.ts +55 -0
package/src/audio.ts ADDED
@@ -0,0 +1,564 @@
1
+ // Ported from three.js r185 (three@0.185.1). The MIT License, Copyright © 2010-2026 three.js authors.
2
+ /**
3
+ * three's audio classes (`AudioListener`, `Audio`, `PositionalAudio`, `AudioLoader`) over an
4
+ * engine's own `Object3D`, for both back ends: the browser-JS one and the V8 facade.
5
+ *
6
+ * Upstream's classes are plain JS over WebAudio, but they extend upstream `Object3D`, so the
7
+ * engine's scene graph cannot hold them (`camera.add(listener)` would pass a foreign object) and
8
+ * `voice instanceof Object3D` is false. These are the same classes, ported from three r185, with
9
+ * the engine's `Object3D` as the base. One difference is structural: upstream pushes positions to
10
+ * WebAudio from `updateMatrixWorld`, which three's renderer calls from JS each frame. The engine
11
+ * updates world matrices natively, so the host calls `updateAudio()` once per frame instead.
12
+ */
13
+
14
+ interface IAudioVector3 {
15
+ x: number;
16
+ y: number;
17
+ z: number;
18
+ set(x: number, y: number, z: number): IAudioVector3;
19
+ applyQuaternion(quaternion: object): IAudioVector3;
20
+ }
21
+
22
+ interface IAudioObject3D {
23
+ readonly parent: object | null;
24
+ readonly matrixWorld: { decompose(position: object, quaternion: object, scale: object): unknown };
25
+ updateMatrixWorld(force?: boolean): void;
26
+ updateWorldMatrix(updateParents: boolean, updateChildren: boolean): void;
27
+ copy(source: object, recursive?: boolean): unknown;
28
+ }
29
+
30
+ /** What one engine supplies: its classes, and how `AudioLoader` reads a URL's bytes. */
31
+ export interface IAudioEngine {
32
+ // quality-allow: three's PascalCase class name passed in engine constructor map.
33
+ // biome-ignore lint/style/useNamingConvention: three's class name, so a back end passes its class map.
34
+ readonly Object3D: new () => IAudioObject3D;
35
+ // quality-allow: three's PascalCase class name passed in engine constructor map.
36
+ // biome-ignore lint/style/useNamingConvention: see Object3D.
37
+ readonly Vector3: new () => IAudioVector3;
38
+ // quality-allow: three's PascalCase class name passed in engine constructor map.
39
+ // biome-ignore lint/style/useNamingConvention: see Object3D.
40
+ readonly Quaternion: new () => object;
41
+ readonly read: (url: string) => Promise<ArrayBuffer>;
42
+ }
43
+
44
+ interface IRamped {
45
+ linearRampToValueAtTime(value: number, endTime: number): unknown;
46
+ }
47
+ interface ILegacyListener {
48
+ positionX?: IRamped;
49
+ setPosition(x: number, y: number, z: number): void;
50
+ setOrientation(x: number, y: number, z: number, ux: number, uy: number, uz: number): void;
51
+ }
52
+
53
+ export function defineAudioClasses(engine: IAudioEngine) {
54
+ const { Object3D, Vector3, Quaternion } = engine;
55
+ const position = new Vector3();
56
+ const quaternion = new Quaternion();
57
+ const scale = new Vector3();
58
+ const forward = new Vector3();
59
+ const up = new Vector3();
60
+ // An attached audio object is held strongly, since the native scene graph does not keep a JS
61
+ // wrapper (or its WebAudio nodes) alive; a detached one only weakly, so dropping it frees it.
62
+ type Tracked = { sync(refresh?: boolean): void } & IAudioObject3D;
63
+ const attached = new Set<Tracked>();
64
+ const detached = new Set<WeakRef<Tracked>>();
65
+ const warn = (message: string) => console.warn(`Audio: ${message}`);
66
+ const setType = (target: object, type: string) =>
67
+ Object.defineProperty(target, "type", { value: type, writable: true, configurable: true });
68
+
69
+ let shared: BaseAudioContext | undefined;
70
+ // Upstream's AudioContext is a class of two statics; the same two calls on a plain object.
71
+ const AudioContext = {
72
+ getContext(): BaseAudioContext {
73
+ if (shared === undefined) {
74
+ // quality-allow: webkitAudioContext is the legacy Safari global prefix missing from standard DOM types.
75
+ const host = globalThis as unknown as Record<
76
+ string,
77
+ (new () => BaseAudioContext) | undefined
78
+ >;
79
+ const Context = host.AudioContext ?? host.webkitAudioContext;
80
+ if (Context === undefined)
81
+ throw new Error("TN_AUDIO_CONTEXT_MISSING: this host has no WebAudio AudioContext");
82
+ shared = new Context();
83
+ }
84
+ return shared;
85
+ },
86
+ setContext(value: BaseAudioContext): void {
87
+ shared = value;
88
+ },
89
+ };
90
+
91
+ class AudioListener extends Object3D {
92
+ context = AudioContext.getContext();
93
+ gain = this.context.createGain();
94
+ filter: AudioNode | null = null;
95
+ timeDelta = 0;
96
+ #last: number | undefined;
97
+
98
+ constructor() {
99
+ super();
100
+ setType(this, "AudioListener");
101
+ this.gain.connect(this.context.destination);
102
+ detached.add(new WeakRef(this));
103
+ }
104
+ getInput(): GainNode {
105
+ return this.gain;
106
+ }
107
+ removeFilter(): this {
108
+ if (this.filter !== null) {
109
+ this.gain.disconnect(this.filter);
110
+ this.filter.disconnect(this.context.destination);
111
+ this.gain.connect(this.context.destination);
112
+ this.filter = null;
113
+ }
114
+ return this;
115
+ }
116
+ getFilter(): AudioNode | null {
117
+ return this.filter;
118
+ }
119
+ setFilter(value: AudioNode): this {
120
+ if (this.filter !== null) {
121
+ this.gain.disconnect(this.filter);
122
+ this.filter.disconnect(this.context.destination);
123
+ } else {
124
+ this.gain.disconnect(this.context.destination);
125
+ }
126
+ this.filter = value;
127
+ this.gain.connect(this.filter);
128
+ this.filter.connect(this.context.destination);
129
+ return this;
130
+ }
131
+ getMasterVolume(): number {
132
+ return this.gain.gain.value;
133
+ }
134
+ setMasterVolume(value: number): this {
135
+ this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
136
+ return this;
137
+ }
138
+ override updateMatrixWorld(force?: boolean): void {
139
+ super.updateMatrixWorld(force);
140
+ this.sync();
141
+ }
142
+ /** Pushes the world pose to WebAudio; `refresh` first brings the native world matrix up to date. */
143
+ sync(refresh = false): void {
144
+ if (refresh) this.updateWorldMatrix(true, false);
145
+ const now = globalThis.performance.now();
146
+ this.timeDelta = this.#last === undefined ? 0 : (now - this.#last) / 1000;
147
+ this.#last = now;
148
+ // quality-allow: WebAudio AudioListener differences between standard AudioParam and legacy setPosition/orientation.
149
+ const listener = this.context.listener as unknown as ILegacyListener &
150
+ Record<string, IRamped>;
151
+ this.matrixWorld.decompose(position, quaternion, scale);
152
+ forward.set(0, 0, -1).applyQuaternion(quaternion);
153
+ up.set(0, 1, 0).applyQuaternion(quaternion);
154
+ if (listener.positionX) {
155
+ const end = this.context.currentTime + this.timeDelta;
156
+ const ramp = (name: string, value: number) =>
157
+ listener[name]?.linearRampToValueAtTime(value, end);
158
+ ramp("positionX", position.x);
159
+ ramp("positionY", position.y);
160
+ ramp("positionZ", position.z);
161
+ ramp("forwardX", forward.x);
162
+ ramp("forwardY", forward.y);
163
+ ramp("forwardZ", forward.z);
164
+ ramp("upX", up.x);
165
+ ramp("upY", up.y);
166
+ ramp("upZ", up.z);
167
+ } else {
168
+ listener.setPosition(position.x, position.y, position.z);
169
+ listener.setOrientation(forward.x, forward.y, forward.z, up.x, up.y, up.z);
170
+ }
171
+ }
172
+ }
173
+
174
+ class Audio<TNode extends AudioNode = GainNode> extends Object3D {
175
+ readonly listener: AudioListener;
176
+ readonly context: BaseAudioContext;
177
+ gain: GainNode;
178
+ autoplay = false;
179
+ buffer: AudioBuffer | null = null;
180
+ detune = 0;
181
+ loop = false;
182
+ loopStart = 0;
183
+ loopEnd = 0;
184
+ offset = 0;
185
+ duration: number | undefined = undefined;
186
+ playbackRate = 1;
187
+ isPlaying = false;
188
+ hasPlaybackControl = true;
189
+ source: AudioScheduledSourceNode | AudioNode | null = null;
190
+ sourceType = "empty";
191
+ filters: AudioNode[] = [];
192
+ _startedAt = 0;
193
+ _progress = 0;
194
+ _connected = false;
195
+
196
+ constructor(listener: AudioListener) {
197
+ super();
198
+ setType(this, "Audio");
199
+ this.listener = listener;
200
+ this.context = listener.context;
201
+ this.gain = this.context.createGain();
202
+ this.gain.connect(listener.getInput());
203
+ detached.add(new WeakRef(this));
204
+ }
205
+ getOutput(): TNode {
206
+ // quality-allow: Audio.gain is GainNode which bridges to TNode (defaulting to GainNode or subtype).
207
+ return this.gain as unknown as TNode;
208
+ }
209
+ setNodeSource(audioNode: AudioNode): this {
210
+ this.hasPlaybackControl = false;
211
+ this.sourceType = "audioNode";
212
+ this.source = audioNode;
213
+ this.connect();
214
+ return this;
215
+ }
216
+ setMediaElementSource(mediaElement: HTMLMediaElement): this {
217
+ this.hasPlaybackControl = false;
218
+ this.sourceType = "mediaNode";
219
+ this.source = (this.context as globalThis.AudioContext).createMediaElementSource(
220
+ mediaElement,
221
+ );
222
+ this.connect();
223
+ return this;
224
+ }
225
+ setMediaStreamSource(mediaStream: MediaStream): this {
226
+ this.hasPlaybackControl = false;
227
+ this.sourceType = "mediaStreamNode";
228
+ this.source = (this.context as globalThis.AudioContext).createMediaStreamSource(mediaStream);
229
+ this.connect();
230
+ return this;
231
+ }
232
+ setBuffer(audioBuffer: AudioBuffer): this {
233
+ this.buffer = audioBuffer;
234
+ this.sourceType = "buffer";
235
+ if (this.autoplay) this.play();
236
+ return this;
237
+ }
238
+ play(delay = 0): this | undefined {
239
+ if (this.isPlaying) {
240
+ warn("Audio is already playing.");
241
+ return undefined;
242
+ }
243
+ if (!this.hasPlaybackControl) {
244
+ warn("this Audio has no playback control.");
245
+ return undefined;
246
+ }
247
+ this._startedAt = this.context.currentTime + delay;
248
+ const source = this.context.createBufferSource();
249
+ source.buffer = this.buffer;
250
+ source.loop = this.loop;
251
+ source.loopStart = this.loopStart;
252
+ source.loopEnd = this.loopEnd;
253
+ source.onended = this.onEnded.bind(this);
254
+ source.start(this._startedAt, this._progress + this.offset, this.duration);
255
+ this.isPlaying = true;
256
+ this.source = source;
257
+ this.setDetune(this.detune);
258
+ this.setPlaybackRate(this.playbackRate);
259
+ return this.connect();
260
+ }
261
+ pause(): this | undefined {
262
+ if (!this.hasPlaybackControl) {
263
+ warn("this Audio has no playback control.");
264
+ return undefined;
265
+ }
266
+ if (this.isPlaying) {
267
+ this._progress +=
268
+ Math.max(this.context.currentTime - this._startedAt, 0) * this.playbackRate;
269
+ if (this.loop)
270
+ this._progress = this._progress % (this.duration || (this.buffer?.duration ?? 1));
271
+ const source = this.source as AudioScheduledSourceNode;
272
+ source.stop();
273
+ source.onended = null;
274
+ this.isPlaying = false;
275
+ }
276
+ return this;
277
+ }
278
+ stop(delay = 0): this | undefined {
279
+ if (!this.hasPlaybackControl) {
280
+ warn("this Audio has no playback control.");
281
+ return undefined;
282
+ }
283
+ this._progress = 0;
284
+ if (this.source !== null) {
285
+ const source = this.source as AudioScheduledSourceNode;
286
+ source.stop(this.context.currentTime + delay);
287
+ source.onended = null;
288
+ }
289
+ this.isPlaying = false;
290
+ return this;
291
+ }
292
+ connect(): this {
293
+ const source = this.source as AudioNode;
294
+ if (this.filters.length > 0) {
295
+ source.connect(this.filters[0] as AudioNode);
296
+ for (let i = 1; i < this.filters.length; i++)
297
+ (this.filters[i - 1] as AudioNode).connect(this.filters[i] as AudioNode);
298
+ (this.filters.at(-1) as AudioNode).connect(this.getOutput());
299
+ } else {
300
+ source.connect(this.getOutput());
301
+ }
302
+ this._connected = true;
303
+ return this;
304
+ }
305
+ disconnect(): this | undefined {
306
+ if (!this._connected) return undefined;
307
+ const source = this.source as AudioNode;
308
+ if (this.filters.length > 0) {
309
+ source.disconnect(this.filters[0] as AudioNode);
310
+ for (let i = 1; i < this.filters.length; i++)
311
+ (this.filters[i - 1] as AudioNode).disconnect(this.filters[i] as AudioNode);
312
+ (this.filters.at(-1) as AudioNode).disconnect(this.getOutput());
313
+ } else {
314
+ source.disconnect(this.getOutput());
315
+ }
316
+ this._connected = false;
317
+ return this;
318
+ }
319
+ getFilters(): AudioNode[] {
320
+ return this.filters;
321
+ }
322
+ setFilters(value?: AudioNode[] | null): this {
323
+ if (this._connected) {
324
+ this.disconnect();
325
+ this.filters = (value ?? []).slice();
326
+ this.connect();
327
+ } else {
328
+ this.filters = (value ?? []).slice();
329
+ }
330
+ return this;
331
+ }
332
+ setDetune(value: number): this {
333
+ this.detune = value;
334
+ const source = this.source as AudioBufferSourceNode | null;
335
+ if (this.isPlaying && source?.detune !== undefined)
336
+ source.detune.setTargetAtTime(this.detune, this.context.currentTime, 0.01);
337
+ return this;
338
+ }
339
+ getDetune(): number {
340
+ return this.detune;
341
+ }
342
+ getFilter(): AudioNode | undefined {
343
+ return this.getFilters()[0];
344
+ }
345
+ setFilter(filter?: AudioNode | null): this {
346
+ return this.setFilters(filter ? [filter] : []);
347
+ }
348
+ setPlaybackRate(value: number): this | undefined {
349
+ if (!this.hasPlaybackControl) {
350
+ warn("this Audio has no playback control.");
351
+ return undefined;
352
+ }
353
+ this.playbackRate = value;
354
+ if (this.isPlaying)
355
+ (this.source as AudioBufferSourceNode).playbackRate.setTargetAtTime(
356
+ this.playbackRate,
357
+ this.context.currentTime,
358
+ 0.01,
359
+ );
360
+ return this;
361
+ }
362
+ getPlaybackRate(): number {
363
+ return this.playbackRate;
364
+ }
365
+ onEnded(): void {
366
+ this.isPlaying = false;
367
+ this._progress = 0;
368
+ }
369
+ getLoop(): boolean {
370
+ if (!this.hasPlaybackControl) {
371
+ warn("this Audio has no playback control.");
372
+ return false;
373
+ }
374
+ return this.loop;
375
+ }
376
+ setLoop(value: boolean): this | undefined {
377
+ if (!this.hasPlaybackControl) {
378
+ warn("this Audio has no playback control.");
379
+ return undefined;
380
+ }
381
+ this.loop = value;
382
+ if (this.isPlaying) (this.source as AudioBufferSourceNode).loop = this.loop;
383
+ return this;
384
+ }
385
+ setLoopStart(value: number): this {
386
+ this.loopStart = value;
387
+ return this;
388
+ }
389
+ setLoopEnd(value: number): this {
390
+ this.loopEnd = value;
391
+ return this;
392
+ }
393
+ getVolume(): number {
394
+ return this.gain.gain.value;
395
+ }
396
+ setVolume(value: number): this {
397
+ this.gain.gain.setTargetAtTime(value, this.context.currentTime, 0.01);
398
+ return this;
399
+ }
400
+ override copy(source: Audio<TNode>, recursive?: boolean): this {
401
+ super.copy(source, recursive);
402
+ if (source.sourceType !== "buffer") {
403
+ warn("Audio source type cannot be copied.");
404
+ return this;
405
+ }
406
+ this.autoplay = source.autoplay;
407
+ this.buffer = source.buffer;
408
+ this.detune = source.detune;
409
+ this.loop = source.loop;
410
+ this.loopStart = source.loopStart;
411
+ this.loopEnd = source.loopEnd;
412
+ this.offset = source.offset;
413
+ this.duration = source.duration;
414
+ this.playbackRate = source.playbackRate;
415
+ this.hasPlaybackControl = source.hasPlaybackControl;
416
+ this.sourceType = source.sourceType;
417
+ this.filters = source.filters.slice();
418
+ return this;
419
+ }
420
+ clone(recursive?: boolean): this {
421
+ const Self = this.constructor as new (listener: AudioListener) => this;
422
+ return new Self(this.listener).copy(this, recursive);
423
+ }
424
+ /** Upstream `Audio` sets no position; only `PositionalAudio` has one to push. */
425
+ sync(_refresh?: boolean): void {}
426
+ }
427
+
428
+ const orientation = new Vector3();
429
+ type LegacyPanner = PannerNode & {
430
+ setPosition(x: number, y: number, z: number): void;
431
+ setOrientation(x: number, y: number, z: number): void;
432
+ };
433
+
434
+ class PositionalAudio extends Audio<PannerNode> {
435
+ panner: PannerNode;
436
+
437
+ constructor(listener: AudioListener) {
438
+ super(listener);
439
+ setType(this, "PositionalAudio");
440
+ this.panner = this.context.createPanner();
441
+ this.panner.panningModel = "HRTF";
442
+ this.panner.connect(this.gain);
443
+ }
444
+ override connect(): this {
445
+ super.connect();
446
+ this.panner.connect(this.gain);
447
+ return this;
448
+ }
449
+ override disconnect(): this | undefined {
450
+ super.disconnect();
451
+ this.panner.disconnect(this.gain);
452
+ return this;
453
+ }
454
+ override getOutput(): PannerNode {
455
+ return this.panner;
456
+ }
457
+ getRefDistance(): number {
458
+ return this.panner.refDistance;
459
+ }
460
+ setRefDistance(value: number): this {
461
+ this.panner.refDistance = value;
462
+ return this;
463
+ }
464
+ getRolloffFactor(): number {
465
+ return this.panner.rolloffFactor;
466
+ }
467
+ setRolloffFactor(value: number): this {
468
+ this.panner.rolloffFactor = value;
469
+ return this;
470
+ }
471
+ getDistanceModel(): DistanceModelType {
472
+ return this.panner.distanceModel;
473
+ }
474
+ setDistanceModel(value: DistanceModelType): this {
475
+ this.panner.distanceModel = value;
476
+ return this;
477
+ }
478
+ getMaxDistance(): number {
479
+ return this.panner.maxDistance;
480
+ }
481
+ setMaxDistance(value: number): this {
482
+ this.panner.maxDistance = value;
483
+ return this;
484
+ }
485
+ setDirectionalCone(
486
+ coneInnerAngle: number,
487
+ coneOuterAngle: number,
488
+ coneOuterGain: number,
489
+ ): this {
490
+ this.panner.coneInnerAngle = coneInnerAngle;
491
+ this.panner.coneOuterAngle = coneOuterAngle;
492
+ this.panner.coneOuterGain = coneOuterGain;
493
+ return this;
494
+ }
495
+ override updateMatrixWorld(force?: boolean): void {
496
+ super.updateMatrixWorld(force);
497
+ this.sync();
498
+ }
499
+ override sync(refresh = false): void {
500
+ if (this.hasPlaybackControl && !this.isPlaying) return;
501
+ if (refresh) this.updateWorldMatrix(true, false);
502
+ this.matrixWorld.decompose(position, quaternion, scale);
503
+ orientation.set(0, 0, 1).applyQuaternion(quaternion);
504
+ const panner = this.panner as LegacyPanner;
505
+ if (panner.positionX) {
506
+ const end = this.context.currentTime + this.listener.timeDelta;
507
+ panner.positionX.linearRampToValueAtTime(position.x, end);
508
+ panner.positionY.linearRampToValueAtTime(position.y, end);
509
+ panner.positionZ.linearRampToValueAtTime(position.z, end);
510
+ panner.orientationX.linearRampToValueAtTime(orientation.x, end);
511
+ panner.orientationY.linearRampToValueAtTime(orientation.y, end);
512
+ panner.orientationZ.linearRampToValueAtTime(orientation.z, end);
513
+ } else {
514
+ panner.setPosition(position.x, position.y, position.z);
515
+ panner.setOrientation(orientation.x, orientation.y, orientation.z);
516
+ }
517
+ }
518
+ }
519
+
520
+ class AudioLoader {
521
+ path = "";
522
+ setPath(path: string): this {
523
+ this.path = path;
524
+ return this;
525
+ }
526
+ load(
527
+ url: string,
528
+ onLoad: (buffer: AudioBuffer) => void,
529
+ _onProgress?: unknown,
530
+ onError?: (error: unknown) => void,
531
+ ): void {
532
+ this.loadAsync(url).then(onLoad, (error: unknown) => {
533
+ if (onError) onError(error);
534
+ else console.error(error);
535
+ });
536
+ }
537
+ async loadAsync(url: string): Promise<AudioBuffer> {
538
+ const bytes = await engine.read(this.path + url);
539
+ return AudioContext.getContext().decodeAudioData(bytes.slice(0));
540
+ }
541
+ }
542
+
543
+ /** Pushes every attached listener and voice to WebAudio; the host calls this once per frame. */
544
+ function updateAudio(): void {
545
+ for (const reference of detached) {
546
+ const object = reference.deref();
547
+ if (object === undefined) detached.delete(reference);
548
+ else if (object.parent) {
549
+ detached.delete(reference);
550
+ attached.add(object);
551
+ }
552
+ }
553
+ for (const object of attached) {
554
+ if (!object.parent) {
555
+ attached.delete(object);
556
+ detached.add(new WeakRef(object));
557
+ continue;
558
+ }
559
+ object.sync(true);
560
+ }
561
+ }
562
+
563
+ return { AudioContext, AudioListener, Audio, PositionalAudio, AudioLoader, updateAudio };
564
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * three/webgpu's `BlendMode`: the per-output blending record `mrt(...).setBlendMode(name, mode)` takes
3
+ * (renderers/common/BlendMode.js, r185). The engine's scene pass keeps the material's own blending on
4
+ * every target (pass-node.ts), so this is data only, with three's defaults and its `copy`/`clone`.
5
+ */
6
+ const NORMAL_BLENDING = 1;
7
+ const ADD_EQUATION = 100;
8
+ const SRC_ALPHA_FACTOR = 204;
9
+ const ONE_MINUS_SRC_ALPHA_FACTOR = 205;
10
+
11
+ export class BlendMode {
12
+ blending: number;
13
+ blendSrc = SRC_ALPHA_FACTOR;
14
+ blendDst = ONE_MINUS_SRC_ALPHA_FACTOR;
15
+ blendEquation = ADD_EQUATION;
16
+ blendSrcAlpha: number | null = null;
17
+ blendDstAlpha: number | null = null;
18
+ blendEquationAlpha: number | null = null;
19
+ premultiplyAlpha = false;
20
+
21
+ constructor(blending = NORMAL_BLENDING) {
22
+ this.blending = blending;
23
+ }
24
+
25
+ copy(source: BlendMode): this {
26
+ Object.assign(this, source);
27
+ return this;
28
+ }
29
+
30
+ clone(): BlendMode {
31
+ return new BlendMode().copy(this);
32
+ }
33
+ }