@motionscript/browser 0.1.0-alpha.0 → 0.1.0-alpha.10
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/CHANGELOG.md +187 -0
- package/NOTICE +49 -0
- package/README.md +96 -24
- package/dist/asset-bytes.d.ts +14 -5
- package/dist/asset-bytes.d.ts.map +1 -1
- package/dist/asset-bytes.js +23 -5
- package/dist/asset-bytes.js.map +1 -1
- package/dist/audio/bus-graph.d.ts +12 -3
- package/dist/audio/bus-graph.d.ts.map +1 -1
- package/dist/audio/bus-graph.js +35 -31
- package/dist/audio/bus-graph.js.map +1 -1
- package/dist/audio/effect-graph.d.ts +62 -0
- package/dist/audio/effect-graph.d.ts.map +1 -0
- package/dist/audio/effect-graph.js +234 -0
- package/dist/audio/effect-graph.js.map +1 -0
- package/dist/audio/index.d.ts.map +1 -1
- package/dist/audio/index.js +2 -3
- package/dist/audio/index.js.map +1 -1
- package/dist/audio/loop-region.d.ts +31 -0
- package/dist/audio/loop-region.d.ts.map +1 -0
- package/dist/audio/loop-region.js +43 -0
- package/dist/audio/loop-region.js.map +1 -0
- package/dist/audio/mixer.d.ts +4 -4
- package/dist/audio/mixer.d.ts.map +1 -1
- package/dist/audio/mixer.js +43 -44
- package/dist/audio/mixer.js.map +1 -1
- package/dist/audio/player.d.ts +15 -9
- package/dist/audio/player.d.ts.map +1 -1
- package/dist/audio/player.js +60 -69
- package/dist/audio/player.js.map +1 -1
- package/dist/browser/THIRD_PARTY_LICENSES.txt +784 -0
- package/dist/browser/audio.js +1 -1
- package/dist/browser/chunks/chunk-F3AZKPHU.js +2 -0
- package/dist/browser/chunks/chunk-F3AZKPHU.js.map +7 -0
- package/dist/browser/chunks/chunk-KLXMRKTL.js +2 -0
- package/dist/browser/chunks/chunk-L5UFQACH.js +163 -0
- package/dist/browser/chunks/chunk-L5UFQACH.js.map +7 -0
- package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js +14 -0
- package/dist/browser/chunks/mediabunny-mp3-encoder-ZCIHVVTJ.js.map +7 -0
- package/dist/browser/index.js +52 -1490
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/manifest.json +21 -4
- package/dist/browser/ms_renderer_bg.wasm +0 -0
- package/dist/concat.d.ts +33 -7
- package/dist/concat.d.ts.map +1 -1
- package/dist/concat.js +117 -72
- package/dist/concat.js.map +1 -1
- package/dist/deliver.d.ts +10 -0
- package/dist/deliver.d.ts.map +1 -0
- package/dist/deliver.js +22 -0
- package/dist/deliver.js.map +1 -0
- package/dist/dynamic-nodes.d.ts.map +1 -1
- package/dist/dynamic-nodes.js +9 -12
- package/dist/dynamic-nodes.js.map +1 -1
- package/dist/engine.d.ts +43 -15
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +58 -36
- package/dist/engine.js.map +1 -1
- package/dist/export-audio.d.ts +36 -0
- package/dist/export-audio.d.ts.map +1 -0
- package/dist/export-audio.js +56 -0
- package/dist/export-audio.js.map +1 -0
- package/dist/exporter.d.ts +134 -15
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +135 -90
- package/dist/exporter.js.map +1 -1
- package/dist/formats.d.ts +36 -0
- package/dist/formats.d.ts.map +1 -0
- package/dist/formats.js +83 -0
- package/dist/formats.js.map +1 -0
- package/dist/frame-loop.d.ts +190 -0
- package/dist/frame-loop.d.ts.map +1 -0
- package/dist/frame-loop.js +304 -0
- package/dist/frame-loop.js.map +1 -0
- package/dist/index.d.ts +12 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -47
- package/dist/index.js.map +1 -1
- package/dist/mix-timeline-audio.d.ts +7 -7
- package/dist/mix-timeline-audio.d.ts.map +1 -1
- package/dist/mix-timeline-audio.js +11 -14
- package/dist/mix-timeline-audio.js.map +1 -1
- package/dist/parallel/export-parallel.d.ts +32 -0
- package/dist/parallel/export-parallel.d.ts.map +1 -0
- package/dist/parallel/export-parallel.js +114 -0
- package/dist/parallel/export-parallel.js.map +1 -0
- package/dist/parallel/governor.d.ts +57 -0
- package/dist/parallel/governor.d.ts.map +1 -0
- package/dist/parallel/governor.js +79 -0
- package/dist/parallel/governor.js.map +1 -0
- package/dist/parallel/lane.d.ts +45 -0
- package/dist/parallel/lane.d.ts.map +1 -0
- package/dist/parallel/lane.js +2 -0
- package/dist/parallel/lane.js.map +1 -0
- package/dist/parallel/lanes.d.ts +20 -0
- package/dist/parallel/lanes.d.ts.map +1 -0
- package/dist/parallel/lanes.js +152 -0
- package/dist/parallel/lanes.js.map +1 -0
- package/dist/parallel/plan.d.ts +23 -0
- package/dist/parallel/plan.d.ts.map +1 -0
- package/dist/parallel/plan.js +30 -0
- package/dist/parallel/plan.js.map +1 -0
- package/dist/parallel/run-lanes.d.ts +38 -0
- package/dist/parallel/run-lanes.d.ts.map +1 -0
- package/dist/parallel/run-lanes.js +164 -0
- package/dist/parallel/run-lanes.js.map +1 -0
- package/dist/parallel/session.d.ts +9 -0
- package/dist/parallel/session.d.ts.map +1 -0
- package/dist/parallel/session.js +79 -0
- package/dist/parallel/session.js.map +1 -0
- package/dist/renderer.d.ts +22 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +23 -0
- package/dist/renderer.js.map +1 -0
- package/dist/screenshot.d.ts +6 -6
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +4 -5
- package/dist/screenshot.js.map +1 -1
- package/dist/still.d.ts +32 -24
- package/dist/still.d.ts.map +1 -1
- package/dist/still.js +54 -54
- package/dist/still.js.map +1 -1
- package/dist/ticker.d.ts +41 -9
- package/dist/ticker.d.ts.map +1 -1
- package/dist/ticker.js +113 -41
- package/dist/ticker.js.map +1 -1
- package/package.json +11 -10
- package/dist/audio/filter-graph.d.ts +0 -58
- package/dist/audio/filter-graph.d.ts.map +0 -1
- package/dist/audio/filter-graph.js +0 -235
- package/dist/audio/filter-graph.js.map +0 -1
- package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js +0 -2
- package/dist/browser/chunks/GLTFLoader-PGXD4V5B.js.map +0 -7
- package/dist/browser/chunks/SkeletonUtils-XYDMTGTM.js +0 -2
- package/dist/browser/chunks/chunk-CTLBXZSU.js +0 -4119
- package/dist/browser/chunks/chunk-CTLBXZSU.js.map +0 -7
- package/dist/browser/chunks/chunk-FQ32PDIU.js +0 -2
- package/dist/browser/chunks/chunk-FQ32PDIU.js.map +0 -7
- package/dist/browser/chunks/chunk-FY3BTKY4.js +0 -2
- package/dist/browser/chunks/chunk-FY3BTKY4.js.map +0 -7
- package/dist/browser/chunks/chunk-NSFLRI4P.js +0 -2
- package/dist/browser/chunks/chunk-NSFLRI4P.js.map +0 -7
- package/dist/browser/chunks/three.module-Z4EOVUWF.js +0 -2
- package/dist/browser/chunks/three.module-Z4EOVUWF.js.map +0 -7
- package/dist/decode/image-levels.d.ts +0 -137
- package/dist/decode/image-levels.d.ts.map +0 -1
- package/dist/decode/image-levels.js +0 -477
- package/dist/decode/image-levels.js.map +0 -1
- package/dist/decode/levels.d.ts +0 -37
- package/dist/decode/levels.d.ts.map +0 -1
- package/dist/decode/levels.js +0 -68
- package/dist/decode/levels.js.map +0 -1
- package/dist/decode/video-levels.d.ts +0 -37
- package/dist/decode/video-levels.d.ts.map +0 -1
- package/dist/decode/video-levels.js +0 -95
- package/dist/decode/video-levels.js.map +0 -1
- package/dist/getter.d.ts +0 -10
- package/dist/getter.d.ts.map +0 -1
- package/dist/getter.js +0 -38
- package/dist/getter.js.map +0 -1
- package/dist/measure-context.d.ts +0 -12
- package/dist/measure-context.d.ts.map +0 -1
- package/dist/measure-context.js +0 -12
- package/dist/measure-context.js.map +0 -1
- package/dist/output.d.ts +0 -7
- package/dist/output.d.ts.map +0 -1
- package/dist/output.js +0 -6
- package/dist/output.js.map +0 -1
- package/dist/render-context.d.ts +0 -30
- package/dist/render-context.d.ts.map +0 -1
- package/dist/render-context.js +0 -55
- package/dist/render-context.js.map +0 -1
- package/dist/storage-adapter.d.ts +0 -367
- package/dist/storage-adapter.d.ts.map +0 -1
- package/dist/storage-adapter.js +0 -1278
- package/dist/storage-adapter.js.map +0 -1
- package/dist/three/renderer.d.ts +0 -48
- package/dist/three/renderer.d.ts.map +0 -1
- package/dist/three/renderer.js +0 -177
- package/dist/three/renderer.js.map +0 -1
- /package/dist/browser/chunks/{SkeletonUtils-XYDMTGTM.js.map → chunk-KLXMRKTL.js.map} +0 -0
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { isCurve, sourceTimeAtSceneElapsed } from "@motionscript/core";
|
|
2
|
-
/**
|
|
3
|
-
* How many sample points per second to bake an eased curve segment into for
|
|
4
|
-
* `setValueCurveAtTime`. 200/s (≈ every 5ms) is smooth to the ear and cheap.
|
|
5
|
-
*/
|
|
6
|
-
const CURVE_SAMPLES_PER_SECOND = 200;
|
|
7
|
-
/**
|
|
8
|
-
* Apply a (possibly time-varying) {@link Param} to a Web Audio {@link AudioParam}.
|
|
9
|
-
*
|
|
10
|
-
* - **number** → set once (today's behavior; zero scheduling overhead).
|
|
11
|
-
* - **Curve** → resolve against `clipDuration` and schedule each segment:
|
|
12
|
-
* - linear segments via `setValueAtTime` + `linearRampToValueAtTime`,
|
|
13
|
-
* - eased segments baked into a `Float32Array` via `setValueCurveAtTime`.
|
|
14
|
-
*
|
|
15
|
-
* `elapsed` (scene-seconds already played when a mid-clip seek starts the source)
|
|
16
|
-
* shifts the schedule back by `elapsed` so "now" reads the curve's value at the
|
|
17
|
-
* clip's *current* position, not its start. A `clamp(v)` hook lets a param keep a
|
|
18
|
-
* valid range (e.g. echo mix 0–1) at every sampled point.
|
|
19
|
-
*/
|
|
20
|
-
function applyParam(ctx, audioParam, param, startTime, clipDuration, elapsed, clamp = (v) => v) {
|
|
21
|
-
// Coerce to a finite value before touching an AudioParam — the platform throws
|
|
22
|
-
// on NaN/Infinity. Falls back to the current param value (never undefined here).
|
|
23
|
-
const finite = (v) => {
|
|
24
|
-
const c = clamp(v);
|
|
25
|
-
return Number.isFinite(c) ? c : audioParam.value;
|
|
26
|
-
};
|
|
27
|
-
if (!isCurve(param)) {
|
|
28
|
-
audioParam.value = finite(param);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
// A non-finite clip length yields no usable schedule; hold the curve's start value.
|
|
32
|
-
if (!Number.isFinite(clipDuration) || clipDuration <= 0) {
|
|
33
|
-
audioParam.value = finite(param.staticValue(audioParam.value));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const base = startTime - elapsed; // map curve t=0 to here so seeks line up
|
|
37
|
-
const resolved = param.resolve(clipDuration, audioParam.value);
|
|
38
|
-
if (resolved.length === 0)
|
|
39
|
-
return;
|
|
40
|
-
// Anchor the starting value at `startTime` (the seek point) so there is no
|
|
41
|
-
// jump from the param's default before the first scheduled segment runs.
|
|
42
|
-
const startValue = param.sampleAt(Math.max(0, elapsed), clipDuration, audioParam.value);
|
|
43
|
-
audioParam.setValueAtTime(finite(startValue), startTime);
|
|
44
|
-
for (const seg of resolved) {
|
|
45
|
-
const segStart = base + seg.startTime;
|
|
46
|
-
const segEnd = base + seg.endTime;
|
|
47
|
-
// Skip segments wholly in the past relative to the seek point, or any with a
|
|
48
|
-
// non-finite boundary (degenerate resolve) that would throw on schedule.
|
|
49
|
-
if (segEnd <= startTime || !Number.isFinite(segStart) || !Number.isFinite(segEnd))
|
|
50
|
-
continue;
|
|
51
|
-
const span = seg.endTime - seg.startTime;
|
|
52
|
-
if (span <= 0) {
|
|
53
|
-
audioParam.setValueAtTime(finite(seg.to), Math.max(segStart, startTime));
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (seg.isLinear) {
|
|
57
|
-
audioParam.setValueAtTime(finite(seg.from), Math.max(segStart, startTime));
|
|
58
|
-
audioParam.linearRampToValueAtTime(finite(seg.to), segEnd);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
const count = Math.max(2, Math.ceil(span * CURVE_SAMPLES_PER_SECOND));
|
|
62
|
-
const samples = new Float32Array(count);
|
|
63
|
-
for (let i = 0; i < count; i++) {
|
|
64
|
-
const local = i / (count - 1);
|
|
65
|
-
samples[i] = finite(seg.from + (seg.to - seg.from) * seg.ease(local));
|
|
66
|
-
}
|
|
67
|
-
// setValueCurveAtTime can't start in the past; clamp the start forward.
|
|
68
|
-
const curveStart = Math.max(segStart, startTime);
|
|
69
|
-
const curveDur = segEnd - curveStart;
|
|
70
|
-
if (curveDur > 0)
|
|
71
|
-
audioParam.setValueCurveAtTime(samples, curveStart, curveDur);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Builds the Web Audio graph for a clip's filter chain, returning the node to
|
|
77
|
-
* connect downstream. Shared by live playback ({@link WebAudioSink}) and
|
|
78
|
-
* offline export (`mixAudio`) so both paths sound identical.
|
|
79
|
-
*
|
|
80
|
-
* Filters apply in array order (index 0 closest to the source). `speed` filters
|
|
81
|
-
* are intentionally ignored here — they're realized via `source.playbackRate`
|
|
82
|
-
* by the caller (and affect timeline scheduling), not as a graph node.
|
|
83
|
-
*
|
|
84
|
-
* `startTime` is the AudioContext time the source starts; `clipDuration` is the
|
|
85
|
-
* clip's scene-time length; `elapsed` is scene-seconds already played at a mid-clip
|
|
86
|
-
* seek (0 for a clean start). These let curve-valued params schedule and align.
|
|
87
|
-
*
|
|
88
|
-
* Pass the already-created `source` so its `playbackRate` can be set by the
|
|
89
|
-
* caller; this function only wires nodes *after* the source.
|
|
90
|
-
*/
|
|
91
|
-
export function buildAudioFilterGraph(ctx, source, filters, startTime = ctx.currentTime, clipDuration = 0, elapsed = 0) {
|
|
92
|
-
const nodes = [];
|
|
93
|
-
const oscillators = [];
|
|
94
|
-
let cursor = source;
|
|
95
|
-
const series = (node) => {
|
|
96
|
-
cursor.connect(node);
|
|
97
|
-
nodes.push(node);
|
|
98
|
-
cursor = node;
|
|
99
|
-
};
|
|
100
|
-
const apply = (p, v, clamp) => applyParam(ctx, p, v, startTime, clipDuration, elapsed, clamp);
|
|
101
|
-
for (const filter of filters) {
|
|
102
|
-
switch (filter.type) {
|
|
103
|
-
case "gain": {
|
|
104
|
-
const gain = ctx.createGain();
|
|
105
|
-
apply(gain.gain, filter.value);
|
|
106
|
-
series(gain);
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
case "highpass":
|
|
110
|
-
case "lowpass": {
|
|
111
|
-
const biquad = ctx.createBiquadFilter();
|
|
112
|
-
biquad.type = filter.type === "highpass" ? "highpass" : "lowpass";
|
|
113
|
-
apply(biquad.frequency, filter.frequency);
|
|
114
|
-
if (filter.q !== undefined)
|
|
115
|
-
apply(biquad.Q, filter.q);
|
|
116
|
-
series(biquad);
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
case "tremolo": {
|
|
120
|
-
// Carrier gain whose value is modulated by an LFO. With depth d the
|
|
121
|
-
// carrier base = (1 - d/2) and the LFO swing gain = d/2. The clamp
|
|
122
|
-
// hook applies these transforms whether depth is scalar or a curve.
|
|
123
|
-
const carrier = ctx.createGain();
|
|
124
|
-
const lfo = ctx.createOscillator();
|
|
125
|
-
const lfoDepth = ctx.createGain();
|
|
126
|
-
apply(carrier.gain, filter.depth, (d) => 1 - clamp01(d) / 2);
|
|
127
|
-
apply(lfoDepth.gain, filter.depth, (d) => clamp01(d) / 2);
|
|
128
|
-
apply(lfo.frequency, filter.rate);
|
|
129
|
-
lfo.connect(lfoDepth);
|
|
130
|
-
lfoDepth.connect(carrier.gain);
|
|
131
|
-
nodes.push(lfoDepth);
|
|
132
|
-
oscillators.push(lfo);
|
|
133
|
-
series(carrier);
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
case "echo": {
|
|
137
|
-
// Dry + wet split. The wet path is a delay with feedback; both sum
|
|
138
|
-
// into a merge node that becomes the new cursor.
|
|
139
|
-
const split = cursor;
|
|
140
|
-
const merge = ctx.createGain();
|
|
141
|
-
const dry = ctx.createGain();
|
|
142
|
-
apply(dry.gain, filter.mix ?? 0.5, (m) => 1 - clamp01(m));
|
|
143
|
-
split.connect(dry);
|
|
144
|
-
dry.connect(merge);
|
|
145
|
-
// Delay buffer must accommodate the max delay; size from the static value.
|
|
146
|
-
const maxDelay = staticOf(filter.delay);
|
|
147
|
-
const delay = ctx.createDelay(Math.max(1, maxDelay + 1));
|
|
148
|
-
apply(delay.delayTime, filter.delay);
|
|
149
|
-
const feedbackGain = ctx.createGain();
|
|
150
|
-
apply(feedbackGain.gain, filter.feedback, (f) => Math.max(0, Math.min(0.99, f)));
|
|
151
|
-
const wet = ctx.createGain();
|
|
152
|
-
apply(wet.gain, filter.mix ?? 0.5, (m) => clamp01(m));
|
|
153
|
-
split.connect(delay);
|
|
154
|
-
delay.connect(feedbackGain);
|
|
155
|
-
feedbackGain.connect(delay); // feedback loop
|
|
156
|
-
delay.connect(wet);
|
|
157
|
-
wet.connect(merge);
|
|
158
|
-
nodes.push(dry, delay, feedbackGain, wet, merge);
|
|
159
|
-
cursor = merge;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
case "speed":
|
|
163
|
-
// Realized via source.playbackRate by the caller; no graph node.
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return { output: cursor, nodes, oscillators };
|
|
168
|
-
}
|
|
169
|
-
/** Clamp to [0, 1]. */
|
|
170
|
-
function clamp01(v) {
|
|
171
|
-
return Math.max(0, Math.min(1, v));
|
|
172
|
-
}
|
|
173
|
-
/** The static/representative number of a param (number itself, or curve's t=0 value). */
|
|
174
|
-
function staticOf(p) {
|
|
175
|
-
return isCurve(p) ? p.staticValue(0) : p;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Net *constant* playback-rate multiplier from any scalar `speed` filters in the
|
|
179
|
-
* chain (product of all), defaulting to 1. Curve-valued speeds contribute 1 here
|
|
180
|
-
* and are scheduled separately by {@link applySpeedToPlaybackRate}. Mirrors
|
|
181
|
-
* `Sound.effectiveSpeed()` so the renderer applies the same rate the core timeline
|
|
182
|
-
* reserved time for.
|
|
183
|
-
*/
|
|
184
|
-
export function effectiveSpeed(filters) {
|
|
185
|
-
if (!filters)
|
|
186
|
-
return 1;
|
|
187
|
-
let speed = 1;
|
|
188
|
-
for (const f of filters) {
|
|
189
|
-
if (f.type === "speed" && !isCurve(f.value) && f.value > 0)
|
|
190
|
-
speed *= f.value;
|
|
191
|
-
}
|
|
192
|
-
return speed;
|
|
193
|
-
}
|
|
194
|
-
/** The first curve-valued `speed` filter in the chain, if any. */
|
|
195
|
-
export function speedCurveOf(filters) {
|
|
196
|
-
if (!filters)
|
|
197
|
-
return undefined;
|
|
198
|
-
for (const f of filters) {
|
|
199
|
-
if (f.type === "speed" && isCurve(f.value))
|
|
200
|
-
return f.value;
|
|
201
|
-
}
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Schedule a time-varying speed curve onto an `AudioBufferSourceNode.playbackRate`.
|
|
206
|
-
*
|
|
207
|
-
* The curve is authored over **source time** (rate as a function of how far through
|
|
208
|
-
* the source we've played). `setValueAtTime`/`linearRampToValueAtTime` schedule in
|
|
209
|
-
* **context time**, so we walk scene-time forward in small steps, convert each to a
|
|
210
|
-
* source-time offset via the integral inverse, read the curve there, and lay down a
|
|
211
|
-
* value point at the matching context time. `scalar` folds in any constant speed
|
|
212
|
-
* filters (they scale the whole rate uniformly).
|
|
213
|
-
*
|
|
214
|
-
* `elapsed` is scene-seconds already played at a mid-clip seek, so the schedule
|
|
215
|
-
* starts at the seek point and aligns the playbackRate to the clip's true position.
|
|
216
|
-
*/
|
|
217
|
-
export function applySpeedToPlaybackRate(rate, curve, sourceLength, sceneDuration, scalar, startTime, elapsed) {
|
|
218
|
-
if (!curve)
|
|
219
|
-
return;
|
|
220
|
-
const step = 1 / CURVE_SAMPLES_PER_SECOND; // scene-time sampling step
|
|
221
|
-
let scene = Math.max(0, elapsed);
|
|
222
|
-
// Seed the value exactly at the seek point.
|
|
223
|
-
const seedSrc = sourceTimeAtSceneElapsed(curve, sourceLength, scene);
|
|
224
|
-
rate.setValueAtTime(Math.max(1e-4, curve.sampleAt(seedSrc, sourceLength, 1) * scalar), startTime);
|
|
225
|
-
for (let s = scene + step; s <= sceneDuration + step; s += step) {
|
|
226
|
-
const clampedScene = Math.min(s, sceneDuration);
|
|
227
|
-
const srcT = sourceTimeAtSceneElapsed(curve, sourceLength, clampedScene);
|
|
228
|
-
const value = Math.max(1e-4, curve.sampleAt(srcT, sourceLength, 1) * scalar);
|
|
229
|
-
const ctxTime = startTime + (clampedScene - scene);
|
|
230
|
-
rate.linearRampToValueAtTime(value, ctxTime);
|
|
231
|
-
if (clampedScene >= sceneDuration)
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
//# sourceMappingURL=filter-graph.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter-graph.js","sourceRoot":"","sources":["../../src/audio/filter-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAkB/F;;;GAGG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,SAAS,UAAU,CACf,GAAqB,EACrB,UAAsB,EACtB,KAAY,EACZ,SAAiB,EACjB,YAAoB,EACpB,OAAe,EACf,QAA+B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEvC,+EAA+E;IAC/E,iFAAiF;IACjF,MAAM,MAAM,GAAG,CAAC,CAAS,EAAU,EAAE;QACjC,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;IACrD,CAAC,CAAC;IAEF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,UAAU,CAAC,KAAK,GAAG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CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QAC7E,MAAM,OAAO,GAAG,SAAS,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC;QACnD,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC7C,IAAI,YAAY,IAAI,aAAa;YAAE,MAAM;IAC7C,CAAC;AACL,CAAC","sourcesContent":["import { AudioFilterItem, Param, isCurve, sourceTimeAtSceneElapsed } from \"@motionscript/core\";\n\n/**\n * Result of building an audio-filter graph for one source.\n *\n * - `output` is the last node in the chain; connect it downstream (e.g. to the\n * per-request gain node).\n * - `nodes` are every intermediate node, so callers can `disconnect()` them on\n * teardown.\n * - `oscillators` are LFOs (from `tremolo`) the caller must `start()` — and may\n * `stop()` — alongside the source, since oscillators need an explicit start.\n */\nexport interface AudioFilterGraph {\n output: AudioNode;\n nodes: AudioNode[];\n oscillators: OscillatorNode[];\n}\n\n/**\n * How many sample points per second to bake an eased curve segment into for\n * `setValueCurveAtTime`. 200/s (≈ every 5ms) is smooth to the ear and cheap.\n */\nconst CURVE_SAMPLES_PER_SECOND = 200;\n\n/**\n * Apply a (possibly time-varying) {@link Param} to a Web Audio {@link AudioParam}.\n *\n * - **number** → set once (today's behavior; zero scheduling overhead).\n * - **Curve** → resolve against `clipDuration` and schedule each segment:\n * - linear segments via `setValueAtTime` + `linearRampToValueAtTime`,\n * - eased segments baked into a `Float32Array` via `setValueCurveAtTime`.\n *\n * `elapsed` (scene-seconds already played when a mid-clip seek starts the source)\n * shifts the schedule back by `elapsed` so \"now\" reads the curve's value at the\n * clip's *current* position, not its start. A `clamp(v)` hook lets a param keep a\n * valid range (e.g. echo mix 0–1) at every sampled point.\n */\nfunction applyParam(\n ctx: BaseAudioContext,\n audioParam: AudioParam,\n param: Param,\n startTime: number,\n clipDuration: number,\n elapsed: number,\n clamp: (v: number) => number = (v) => v,\n): void {\n // Coerce to a finite value before touching an AudioParam — the platform throws\n // on NaN/Infinity. Falls back to the current param value (never undefined here).\n const finite = (v: number): number => {\n const c = clamp(v);\n return Number.isFinite(c) ? c : audioParam.value;\n };\n\n if (!isCurve(param)) {\n audioParam.value = finite(param);\n return;\n }\n\n // A non-finite clip length yields no usable schedule; hold the curve's start value.\n if (!Number.isFinite(clipDuration) || clipDuration <= 0) {\n audioParam.value = finite(param.staticValue(audioParam.value));\n return;\n }\n\n const base = startTime - elapsed; // map curve t=0 to here so seeks line up\n const resolved = param.resolve(clipDuration, audioParam.value);\n if (resolved.length === 0) return;\n\n // Anchor the starting value at `startTime` (the seek point) so there is no\n // jump from the param's default before the first scheduled segment runs.\n const startValue = param.sampleAt(Math.max(0, elapsed), clipDuration, audioParam.value);\n audioParam.setValueAtTime(finite(startValue), startTime);\n\n for (const seg of resolved) {\n const segStart = base + seg.startTime;\n const segEnd = base + seg.endTime;\n // Skip segments wholly in the past relative to the seek point, or any with a\n // non-finite boundary (degenerate resolve) that would throw on schedule.\n if (segEnd <= startTime || !Number.isFinite(segStart) || !Number.isFinite(segEnd)) continue;\n\n const span = seg.endTime - seg.startTime;\n\n if (span <= 0) {\n audioParam.setValueAtTime(finite(seg.to), Math.max(segStart, startTime));\n continue;\n }\n\n if (seg.isLinear) {\n audioParam.setValueAtTime(finite(seg.from), Math.max(segStart, startTime));\n audioParam.linearRampToValueAtTime(finite(seg.to), segEnd);\n } else {\n const count = Math.max(2, Math.ceil(span * CURVE_SAMPLES_PER_SECOND));\n const samples = new Float32Array(count);\n for (let i = 0; i < count; i++) {\n const local = i / (count - 1);\n samples[i] = finite(seg.from + (seg.to - seg.from) * seg.ease(local));\n }\n // setValueCurveAtTime can't start in the past; clamp the start forward.\n const curveStart = Math.max(segStart, startTime);\n const curveDur = segEnd - curveStart;\n if (curveDur > 0) audioParam.setValueCurveAtTime(samples, curveStart, curveDur);\n }\n }\n}\n\n/**\n * Builds the Web Audio graph for a clip's filter chain, returning the node to\n * connect downstream. Shared by live playback ({@link WebAudioSink}) and\n * offline export (`mixAudio`) so both paths sound identical.\n *\n * Filters apply in array order (index 0 closest to the source). `speed` filters\n * are intentionally ignored here — they're realized via `source.playbackRate`\n * by the caller (and affect timeline scheduling), not as a graph node.\n *\n * `startTime` is the AudioContext time the source starts; `clipDuration` is the\n * clip's scene-time length; `elapsed` is scene-seconds already played at a mid-clip\n * seek (0 for a clean start). These let curve-valued params schedule and align.\n *\n * Pass the already-created `source` so its `playbackRate` can be set by the\n * caller; this function only wires nodes *after* the source.\n */\nexport function buildAudioFilterGraph(\n ctx: BaseAudioContext,\n source: AudioNode,\n filters: readonly AudioFilterItem[],\n startTime: number = ctx.currentTime,\n clipDuration: number = 0,\n elapsed: number = 0,\n): AudioFilterGraph {\n const nodes: AudioNode[] = [];\n const oscillators: OscillatorNode[] = [];\n let cursor: AudioNode = source;\n\n const series = (node: AudioNode): void => {\n cursor.connect(node);\n nodes.push(node);\n cursor = node;\n };\n\n const apply = (p: AudioParam, v: Param, clamp?: (n: number) => number): void =>\n applyParam(ctx, p, v, startTime, clipDuration, elapsed, clamp);\n\n for (const filter of filters) {\n switch (filter.type) {\n case \"gain\": {\n const gain = ctx.createGain();\n apply(gain.gain, filter.value);\n series(gain);\n break;\n }\n case \"highpass\":\n case \"lowpass\": {\n const biquad = ctx.createBiquadFilter();\n biquad.type = filter.type === \"highpass\" ? \"highpass\" : \"lowpass\";\n apply(biquad.frequency, filter.frequency);\n if (filter.q !== undefined) apply(biquad.Q, filter.q);\n series(biquad);\n break;\n }\n case \"tremolo\": {\n // Carrier gain whose value is modulated by an LFO. With depth d the\n // carrier base = (1 - d/2) and the LFO swing gain = d/2. The clamp\n // hook applies these transforms whether depth is scalar or a curve.\n const carrier = ctx.createGain();\n const lfo = ctx.createOscillator();\n const lfoDepth = ctx.createGain();\n\n apply(carrier.gain, filter.depth, (d) => 1 - clamp01(d) / 2);\n apply(lfoDepth.gain, filter.depth, (d) => clamp01(d) / 2);\n apply(lfo.frequency, filter.rate);\n\n lfo.connect(lfoDepth);\n lfoDepth.connect(carrier.gain);\n\n nodes.push(lfoDepth);\n oscillators.push(lfo);\n series(carrier);\n break;\n }\n case \"echo\": {\n // Dry + wet split. The wet path is a delay with feedback; both sum\n // into a merge node that becomes the new cursor.\n const split = cursor;\n const merge = ctx.createGain();\n\n const dry = ctx.createGain();\n apply(dry.gain, filter.mix ?? 0.5, (m) => 1 - clamp01(m));\n split.connect(dry);\n dry.connect(merge);\n\n // Delay buffer must accommodate the max delay; size from the static value.\n const maxDelay = staticOf(filter.delay);\n const delay = ctx.createDelay(Math.max(1, maxDelay + 1));\n apply(delay.delayTime, filter.delay);\n const feedbackGain = ctx.createGain();\n apply(feedbackGain.gain, filter.feedback, (f) => Math.max(0, Math.min(0.99, f)));\n const wet = ctx.createGain();\n apply(wet.gain, filter.mix ?? 0.5, (m) => clamp01(m));\n\n split.connect(delay);\n delay.connect(feedbackGain);\n feedbackGain.connect(delay); // feedback loop\n delay.connect(wet);\n wet.connect(merge);\n\n nodes.push(dry, delay, feedbackGain, wet, merge);\n cursor = merge;\n break;\n }\n case \"speed\":\n // Realized via source.playbackRate by the caller; no graph node.\n break;\n }\n }\n\n return { output: cursor, nodes, oscillators };\n}\n\n/** Clamp to [0, 1]. */\nfunction clamp01(v: number): number {\n return Math.max(0, Math.min(1, v));\n}\n\n/** The static/representative number of a param (number itself, or curve's t=0 value). */\nfunction staticOf(p: Param): number {\n return isCurve(p) ? p.staticValue(0) : p;\n}\n\n/**\n * Net *constant* playback-rate multiplier from any scalar `speed` filters in the\n * chain (product of all), defaulting to 1. Curve-valued speeds contribute 1 here\n * and are scheduled separately by {@link applySpeedToPlaybackRate}. Mirrors\n * `Sound.effectiveSpeed()` so the renderer applies the same rate the core timeline\n * reserved time for.\n */\nexport function effectiveSpeed(filters: readonly AudioFilterItem[] | undefined): number {\n if (!filters) return 1;\n let speed = 1;\n for (const f of filters) {\n if (f.type === \"speed\" && !isCurve(f.value) && f.value > 0) speed *= f.value;\n }\n return speed;\n}\n\n/** The first curve-valued `speed` filter in the chain, if any. */\nexport function speedCurveOf(filters: readonly AudioFilterItem[] | undefined) {\n if (!filters) return undefined;\n for (const f of filters) {\n if (f.type === \"speed\" && isCurve(f.value)) return f.value;\n }\n return undefined;\n}\n\n/**\n * Schedule a time-varying speed curve onto an `AudioBufferSourceNode.playbackRate`.\n *\n * The curve is authored over **source time** (rate as a function of how far through\n * the source we've played). `setValueAtTime`/`linearRampToValueAtTime` schedule in\n * **context time**, so we walk scene-time forward in small steps, convert each to a\n * source-time offset via the integral inverse, read the curve there, and lay down a\n * value point at the matching context time. `scalar` folds in any constant speed\n * filters (they scale the whole rate uniformly).\n *\n * `elapsed` is scene-seconds already played at a mid-clip seek, so the schedule\n * starts at the seek point and aligns the playbackRate to the clip's true position.\n */\nexport function applySpeedToPlaybackRate(\n rate: AudioParam,\n curve: ReturnType<typeof speedCurveOf>,\n sourceLength: number,\n sceneDuration: number,\n scalar: number,\n startTime: number,\n elapsed: number,\n): void {\n if (!curve) return;\n const step = 1 / CURVE_SAMPLES_PER_SECOND; // scene-time sampling step\n let scene = Math.max(0, elapsed);\n // Seed the value exactly at the seek point.\n const seedSrc = sourceTimeAtSceneElapsed(curve, sourceLength, scene);\n rate.setValueAtTime(Math.max(1e-4, curve.sampleAt(seedSrc, sourceLength, 1) * scalar), startTime);\n\n for (let s = scene + step; s <= sceneDuration + step; s += step) {\n const clampedScene = Math.min(s, sceneDuration);\n const srcT = sourceTimeAtSceneElapsed(curve, sourceLength, clampedScene);\n const value = Math.max(1e-4, curve.sampleAt(srcT, sourceLength, 1) * scalar);\n const ctxTime = startTime + (clampedScene - scene);\n rate.linearRampToValueAtTime(value, ctxTime);\n if (clampedScene >= sceneDuration) break;\n }\n}\n"]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{c as bt}from"./chunk-FQ32PDIU.js";import{$d as rt,$f as Rt,Ed as tt,Gd as G,Gf as de,If as he,Kb as Qe,Kf as pe,Lb as te,Lf as mt,Pf as gt,Qd as nt,Qf as me,Rd as ae,Sd as ce,Tb as $e,Td as ue,Ub as V,Ud as Y,Vb as F,Wf as Tt,Zd as P,_d as st,_f as At,ae as it,ag as yt,bc as k,bg as Et,cc as M,ce as ot,cg as _t,dd as et,de as le,ed as ne,ee as at,fd as se,gd as N,id as re,ig as B,je as ct,ke as ut,l as Xe,ld as ie,le as lt,me as ft,mg as xt,n as Ve,ne as dt,nf as fe,oa as j,oe as ht,of as S,pa as qe,qa as Ye,ra as $,sa as We,td as z,ua as Ze,wa as X,wd as oe,xa as Je,xd as q,yf as pt,yg as wt,za as ee,zd as O}from"./chunk-CTLBXZSU.js";import"./chunk-FY3BTKY4.js";function ge(f,t){if(t===$e)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),f;if(t===F||t===V){let e=f.getIndex();if(e===null){let i=[],a=f.getAttribute("position");if(a!==void 0){for(let o=0;o<a.count;o++)i.push(o);f.setIndex(i),e=f.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),f}let s=e.count-2,n=[];if(t===F)for(let i=1;i<=s;i++)n.push(e.getX(0)),n.push(e.getX(i)),n.push(e.getX(i+1));else for(let i=0;i<s;i++)i%2===0?(n.push(e.getX(i)),n.push(e.getX(i+1)),n.push(e.getX(i+2))):(n.push(e.getX(i+2)),n.push(e.getX(i+1)),n.push(e.getX(i)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");let r=f.clone();return r.setIndex(n),r.clearGroups(),r}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),f}var St=class extends gt{constructor(t){super(t),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new xe(e)}),this.register(function(e){return new we(e)}),this.register(function(e){return new ve(e)}),this.register(function(e){return new He(e)}),this.register(function(e){return new ke(e)}),this.register(function(e){return new Se(e)}),this.register(function(e){return new Me(e)}),this.register(function(e){return new Ie(e)}),this.register(function(e){return new Ne(e)}),this.register(function(e){return new _e(e)}),this.register(function(e){return new Le(e)}),this.register(function(e){return new be(e)}),this.register(function(e){return new Ce(e)}),this.register(function(e){return new Oe(e)}),this.register(function(e){return new ye(e)}),this.register(function(e){return new W(e,g.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new W(e,g.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new Pe(e)})}load(t,e,s,n){let r=this,i;if(this.resourcePath!=="")i=this.resourcePath;else if(this.path!==""){let c=B.extractUrlBase(t);i=B.resolveURL(c,this.path)}else i=B.extractUrlBase(t);this.manager.itemStart(t);let a=function(c){n?n(c):console.error(c),r.manager.itemError(t),r.manager.itemEnd(t)},o=new me(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,function(c){try{r.parse(c,i,function(u){e(u),r.manager.itemEnd(t)},a)}catch(u){a(u)}},s,a)}setDRACOLoader(t){return this.dracoLoader=t,this}setKTX2Loader(t){return this.ktx2Loader=t,this}setMeshoptDecoder(t){return this.meshoptDecoder=t,this}register(t){return this.pluginCallbacks.indexOf(t)===-1&&this.pluginCallbacks.push(t),this}unregister(t){return this.pluginCallbacks.indexOf(t)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(t),1),this}parse(t,e,s,n){let r,i={},a={},o=new TextDecoder;if(typeof t=="string")r=JSON.parse(t);else if(t instanceof ArrayBuffer)if(o.decode(new Uint8Array(t,0,4))===Ot){try{i[g.KHR_BINARY_GLTF]=new Be(t)}catch(l){n&&n(l);return}r=JSON.parse(i[g.KHR_BINARY_GLTF].content)}else r=JSON.parse(o.decode(t));else r=t;if(r.asset===void 0||r.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}let c=new je(r,{path:e||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){let l=this.pluginCallbacks[u](c);l.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[l.name]=l,i[l.name]=!0}if(r.extensionsUsed)for(let u=0;u<r.extensionsUsed.length;++u){let l=r.extensionsUsed[u],d=r.extensionsRequired||[];switch(l){case g.KHR_MATERIALS_UNLIT:i[l]=new Ee;break;case g.KHR_DRACO_MESH_COMPRESSION:i[l]=new De(r,this.dracoLoader);break;case g.KHR_TEXTURE_TRANSFORM:i[l]=new Ue;break;case g.KHR_MESH_QUANTIZATION:i[l]=new Fe;break;default:d.indexOf(l)>=0&&a[l]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+l+'".')}}c.setExtensions(i),c.setPlugins(a),c.parse(s,n)}parseAsync(t,e){let s=this;return new Promise(function(n,r){s.parse(t,e,n,r)})}};function Ct(){let f={};return{get:function(t){return f[t]},add:function(t,e){f[t]=e},remove:function(t){delete f[t]},removeAll:function(){f={}}}}function _(f,t,e){let s=f.json.materials[t];return s.extensions&&s.extensions[e]?s.extensions[e]:null}var g={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",KHR_MESHOPT_COMPRESSION:"KHR_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"},ye=class{constructor(t){this.parser=t,this.name=g.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let t=this.parser,e=this.parser.json.nodes||[];for(let s=0,n=e.length;s<n;s++){let r=e[s];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&t._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(t){let e=this.parser,s="light:"+t,n=e.cache.get(s);if(n)return n;let r=e.json,o=((r.extensions&&r.extensions[this.name]||{}).lights||[])[t],c,u=new O(16777215);o.color!==void 0&&u.setRGB(o.color[0],o.color[1],o.color[2],M);let l=o.range!==void 0?o.range:0;switch(o.type){case"directional":c=new _t(u),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new yt(u),c.distance=l;break;case"spot":c=new Rt(u),c.distance=l,o.spot=o.spot||{},o.spot.innerConeAngle=o.spot.innerConeAngle!==void 0?o.spot.innerConeAngle:0,o.spot.outerConeAngle=o.spot.outerConeAngle!==void 0?o.spot.outerConeAngle:Math.PI/4,c.angle=o.spot.outerConeAngle,c.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+o.type)}return c.position.set(0,0,0),I(c,o),o.intensity!==void 0&&(c.intensity=o.intensity),c.name=e.createUniqueName(o.name||"light_"+t),n=Promise.resolve(c),e.cache.add(s,n),n}getDependency(t,e){if(t==="light")return this._loadLight(e)}createNodeAttachment(t){let e=this,s=this.parser,r=s.json.nodes[t],a=(r.extensions&&r.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(o){return s._getNodeRef(e.cache,a,o)})}},Ee=class{constructor(){this.name=g.KHR_MATERIALS_UNLIT}getMaterialType(){return P}extendParams(t,e,s){let n=[];t.color=new O(1,1,1),t.opacity=1;let r=e.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){let i=r.baseColorFactor;t.color.setRGB(i[0],i[1],i[2],M),t.opacity=i[3]}r.baseColorTexture!==void 0&&n.push(s.assignTexture(t,"map",r.baseColorTexture,k))}return Promise.all(n)}},_e=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);return s===null||s.emissiveStrength!==void 0&&(e.emissiveIntensity=s.emissiveStrength),Promise.resolve()}},xe=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];if(s.clearcoatFactor!==void 0&&(e.clearcoat=s.clearcoatFactor),s.clearcoatTexture!==void 0&&n.push(this.parser.assignTexture(e,"clearcoatMap",s.clearcoatTexture)),s.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=s.clearcoatRoughnessFactor),s.clearcoatRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(e,"clearcoatRoughnessMap",s.clearcoatRoughnessTexture)),s.clearcoatNormalTexture!==void 0&&(n.push(this.parser.assignTexture(e,"clearcoatNormalMap",s.clearcoatNormalTexture)),s.clearcoatNormalTexture.scale!==void 0)){let r=s.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new ne(r,r)}return Promise.all(n)}},we=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_DISPERSION}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);return s===null||(e.dispersion=s.dispersion!==void 0?s.dispersion:0),Promise.resolve()}},be=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_IRIDESCENCE}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return s.iridescenceFactor!==void 0&&(e.iridescence=s.iridescenceFactor),s.iridescenceTexture!==void 0&&n.push(this.parser.assignTexture(e,"iridescenceMap",s.iridescenceTexture)),s.iridescenceIor!==void 0&&(e.iridescenceIOR=s.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),s.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=s.iridescenceThicknessMinimum),s.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=s.iridescenceThicknessMaximum),s.iridescenceThicknessTexture!==void 0&&n.push(this.parser.assignTexture(e,"iridescenceThicknessMap",s.iridescenceThicknessTexture)),Promise.all(n)}},Se=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_SHEEN}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];if(e.sheenColor=new O(0,0,0),e.sheenRoughness=0,e.sheen=1,s.sheenColorFactor!==void 0){let r=s.sheenColorFactor;e.sheenColor.setRGB(r[0],r[1],r[2],M)}return s.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=s.sheenRoughnessFactor),s.sheenColorTexture!==void 0&&n.push(this.parser.assignTexture(e,"sheenColorMap",s.sheenColorTexture,k)),s.sheenRoughnessTexture!==void 0&&n.push(this.parser.assignTexture(e,"sheenRoughnessMap",s.sheenRoughnessTexture)),Promise.all(n)}},Me=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return s.transmissionFactor!==void 0&&(e.transmission=s.transmissionFactor),s.transmissionTexture!==void 0&&n.push(this.parser.assignTexture(e,"transmissionMap",s.transmissionTexture)),Promise.all(n)}},Ie=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_VOLUME}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];e.thickness=s.thicknessFactor!==void 0?s.thicknessFactor:0,s.thicknessTexture!==void 0&&n.push(this.parser.assignTexture(e,"thicknessMap",s.thicknessTexture)),e.attenuationDistance=s.attenuationDistance||1/0;let r=s.attenuationColor||[1,1,1];return e.attenuationColor=new O().setRGB(r[0],r[1],r[2],M),Promise.all(n)}},Ne=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_IOR}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);return s===null||(e.ior=s.ior!==void 0?s.ior:1.5,e.ior===0&&(e.ior=1e3)),Promise.resolve()}},Le=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_SPECULAR}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];e.specularIntensity=s.specularFactor!==void 0?s.specularFactor:1,s.specularTexture!==void 0&&n.push(this.parser.assignTexture(e,"specularIntensityMap",s.specularTexture));let r=s.specularColorFactor||[1,1,1];return e.specularColor=new O().setRGB(r[0],r[1],r[2],M),s.specularColorTexture!==void 0&&n.push(this.parser.assignTexture(e,"specularColorMap",s.specularColorTexture,k)),Promise.all(n)}},Oe=class{constructor(t){this.parser=t,this.name=g.EXT_MATERIALS_BUMP}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return e.bumpScale=s.bumpFactor!==void 0?s.bumpFactor:1,s.bumpTexture!==void 0&&n.push(this.parser.assignTexture(e,"bumpMap",s.bumpTexture)),Promise.all(n)}},Ce=class{constructor(t){this.parser=t,this.name=g.KHR_MATERIALS_ANISOTROPY}getMaterialType(t){return _(this.parser,t,this.name)!==null?S:null}extendMaterialParams(t,e){let s=_(this.parser,t,this.name);if(s===null)return Promise.resolve();let n=[];return s.anisotropyStrength!==void 0&&(e.anisotropy=s.anisotropyStrength),s.anisotropyRotation!==void 0&&(e.anisotropyRotation=s.anisotropyRotation),s.anisotropyTexture!==void 0&&n.push(this.parser.assignTexture(e,"anisotropyMap",s.anisotropyTexture)),Promise.all(n)}},ve=class{constructor(t){this.parser=t,this.name=g.KHR_TEXTURE_BASISU}loadTexture(t){let e=this.parser,s=e.json,n=s.textures[t];if(!n.extensions||!n.extensions[this.name])return null;let r=n.extensions[this.name],i=e.options.ktx2Loader;if(!i){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return e.loadTextureImage(t,r.source,i)}},He=class{constructor(t){this.parser=t,this.name=g.EXT_TEXTURE_WEBP}loadTexture(t){let e=this.name,s=this.parser,n=s.json,r=n.textures[t];if(!r.extensions||!r.extensions[e])return null;let i=r.extensions[e],a=n.images[i.source],o=s.textureLoader;if(a.uri){let c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(t,i.source,o)}},ke=class{constructor(t){this.parser=t,this.name=g.EXT_TEXTURE_AVIF}loadTexture(t){let e=this.name,s=this.parser,n=s.json,r=n.textures[t];if(!r.extensions||!r.extensions[e])return null;let i=r.extensions[e],a=n.images[i.source],o=s.textureLoader;if(a.uri){let c=s.options.manager.getHandler(a.uri);c!==null&&(o=c)}return s.loadTextureImage(t,i.source,o)}},W=class{constructor(t,e){this.name=e,this.parser=t}loadBufferView(t){let e=this.parser.json,s=e.bufferViews[t];if(s.extensions&&s.extensions[this.name]){let n=s.extensions[this.name],r=this.parser.getDependency("buffer",n.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(e.extensionsRequired&&e.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return r.then(function(a){let o=n.byteOffset||0,c=n.byteLength||0,u=n.count,l=n.byteStride,d=new Uint8Array(a,o,c);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(u,l,d,n.mode,n.filter).then(function(h){return h.buffer}):i.ready.then(function(){let h=new ArrayBuffer(u*l);return i.decodeGltfBuffer(new Uint8Array(h),u,l,d,n.mode,n.filter),h})})}else return null}},Pe=class{constructor(t){this.name=g.EXT_MESH_GPU_INSTANCING,this.parser=t}createNodeMesh(t){let e=this.parser.json,s=e.nodes[t];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;let n=e.meshes[s.mesh];for(let c of n.primitives)if(c.mode!==w.TRIANGLES&&c.mode!==w.TRIANGLE_STRIP&&c.mode!==w.TRIANGLE_FAN&&c.mode!==void 0)return null;let i=s.extensions[this.name].attributes,a=[],o={};for(let c in i)a.push(this.parser.getDependency("accessor",i[c]).then(u=>(o[c]=u,o[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(t)),Promise.all(a).then(c=>{let u=c.pop(),l=u.isGroup?u.children:[u],d=c[0].count,h=[];for(let p of l){let A=new z,m=new N,T=new se,E=new N(1,1,1),y=new at(p.geometry,p.material,d);for(let R=0;R<d;R++)o.TRANSLATION&&m.fromBufferAttribute(o.TRANSLATION,R),o.ROTATION&&T.fromBufferAttribute(o.ROTATION,R),o.SCALE&&E.fromBufferAttribute(o.SCALE,R),y.setMatrixAt(R,A.compose(m,T,E));for(let R in o)if(R==="_COLOR_0"){let x=o[R];y.instanceColor=new le(x.array,x.itemSize,x.normalized)}else R!=="TRANSLATION"&&R!=="ROTATION"&&R!=="SCALE"&&p.geometry.setAttribute(R,o[R]);oe.prototype.copy.call(y,p),this.parser.assignFinalMaterial(y),h.push(y)}return u.isGroup?(u.clear(),u.add(...h),u):h[0]}))}},Ot="glTF",K=12,Mt={JSON:1313821514,BIN:5130562},Be=class{constructor(t){this.name=g.KHR_BINARY_GLTF,this.content=null,this.body=null;let e=new DataView(t,0,K),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(t.slice(0,4))),version:e.getUint32(4,!0),length:e.getUint32(8,!0)},this.header.magic!==Ot)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");let n=this.header.length-K,r=new DataView(t,K),i=0;for(;i<n;){let a=r.getUint32(i,!0);i+=4;let o=r.getUint32(i,!0);if(i+=4,o===Mt.JSON){let c=new Uint8Array(t,K+i,a);this.content=s.decode(c)}else if(o===Mt.BIN){let c=K+i;this.body=t.slice(c,c+a)}i+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}},De=class{constructor(t,e){if(!e)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=g.KHR_DRACO_MESH_COMPRESSION,this.json=t,this.dracoLoader=e,this.dracoLoader.preload()}decodePrimitive(t,e){let s=this.json,n=this.dracoLoader,r=t.extensions[this.name].bufferView,i=t.extensions[this.name].attributes,a={},o={},c={};for(let u in i){let l=Ge[u]||u.toLowerCase();a[l]=i[u]}for(let u in t.attributes){let l=Ge[u]||u.toLowerCase();if(i[u]!==void 0){let d=s.accessors[t.attributes[u]],h=D[d.componentType];c[l]=h.name,o[l]=d.normalized===!0}}return e.getDependency("bufferView",r).then(function(u){return new Promise(function(l,d){n.decodeDracoFile(u,function(h){for(let p in h.attributes){let A=h.attributes[p],m=o[p];m!==void 0&&(A.normalized=m)}l(h)},a,c,M,d)})})}},Ue=class{constructor(){this.name=g.KHR_TEXTURE_TRANSFORM}extendTexture(t,e){return(e.texCoord===void 0||e.texCoord===t.channel)&&e.offset===void 0&&e.rotation===void 0&&e.scale===void 0||(t=t.clone(),e.texCoord!==void 0&&(t.channel=e.texCoord),e.offset!==void 0&&t.offset.fromArray(e.offset),e.rotation!==void 0&&(t.rotation=e.rotation),e.scale!==void 0&&t.repeat.fromArray(e.scale),t.needsUpdate=!0),t}},Fe=class{constructor(){this.name=g.KHR_MESH_QUANTIZATION}},Z=class extends pt{constructor(t,e,s,n){super(t,e,s,n)}copySampleValue_(t){let e=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=t*n*3+n;for(let i=0;i!==n;i++)e[i]=s[r+i];return e}interpolate_(t,e,s,n){let r=this.resultBuffer,i=this.sampleValues,a=this.valueSize,o=a*2,c=a*3,u=n-e,l=(s-e)/u,d=l*l,h=d*l,p=t*c,A=p-c,m=-2*h+3*d,T=h-d,E=1-m,y=T-d+l;for(let R=0;R!==a;R++){let x=i[A+R+a],L=i[A+R+o]*u,b=i[p+R+a],U=i[p+R]*u;r[R]=E*x+y*L+m*b+T*U}return r}},vt=new se,ze=class extends Z{interpolate_(t,e,s,n){let r=super.interpolate_(t,e,s,n);return vt.fromArray(r).normalize().toArray(r),r}},w={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},D={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},It={9728:$,9729:X,9984:We,9985:Je,9986:Ze,9987:ee},Nt={33071:qe,33648:Ye,10497:j},Te={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ge={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},C={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Ht={CUBICSPLINE:void 0,LINEAR:te,STEP:Qe},Ae={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function kt(f){return f.DefaultMaterial===void 0&&(f.DefaultMaterial=new fe({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:Xe})),f.DefaultMaterial}function v(f,t,e){for(let s in e.extensions)f[s]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[s]=e.extensions[s])}function I(f,t){t.extras!==void 0&&(typeof t.extras=="object"?Object.assign(f.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function Pt(f,t,e){let s=!1,n=!1,r=!1;for(let c=0,u=t.length;c<u;c++){let l=t[c];if(l.POSITION!==void 0&&(s=!0),l.NORMAL!==void 0&&(n=!0),l.COLOR_0!==void 0&&(r=!0),s&&n&&r)break}if(!s&&!n&&!r)return Promise.resolve(f);let i=[],a=[],o=[];for(let c=0,u=t.length;c<u;c++){let l=t[c];if(s){let d=l.POSITION!==void 0?e.getDependency("accessor",l.POSITION):f.attributes.position;i.push(d)}if(n){let d=l.NORMAL!==void 0?e.getDependency("accessor",l.NORMAL):f.attributes.normal;a.push(d)}if(r){let d=l.COLOR_0!==void 0?e.getDependency("accessor",l.COLOR_0):f.attributes.color;o.push(d)}}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(o)]).then(function(c){let u=c[0],l=c[1],d=c[2];return s&&(f.morphAttributes.position=u),n&&(f.morphAttributes.normal=l),r&&(f.morphAttributes.color=d),f.morphTargetsRelative=!0,f})}function Bt(f,t){if(f.updateMorphTargets(),t.weights!==void 0)for(let e=0,s=t.weights.length;e<s;e++)f.morphTargetInfluences[e]=t.weights[e];if(t.extras&&Array.isArray(t.extras.targetNames)){let e=t.extras.targetNames;if(f.morphTargetInfluences.length===e.length){f.morphTargetDictionary={};for(let s=0,n=e.length;s<n;s++)f.morphTargetDictionary[e[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function Dt(f){let t,e=f.extensions&&f.extensions[g.KHR_DRACO_MESH_COMPRESSION];if(e?t="draco:"+e.bufferView+":"+e.indices+":"+Re(e.attributes):t=f.indices+":"+Re(f.attributes)+":"+f.mode,f.targets!==void 0)for(let s=0,n=f.targets.length;s<n;s++)t+=":"+Re(f.targets[s]);return t}function Re(f){let t="",e=Object.keys(f).sort();for(let s=0,n=e.length;s<n;s++)t+=e[s]+":"+f[e[s]]+";";return t}function Ke(f){switch(f){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Ut(f){return f.search(/\.jpe?g($|\?)/i)>0||f.search(/^data\:image\/jpeg/)===0?"image/jpeg":f.search(/\.webp($|\?)/i)>0||f.search(/^data\:image\/webp/)===0?"image/webp":f.search(/\.ktx2($|\?)/i)>0||f.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}var Ft=new z,je=class{constructor(t={},e={}){this.json=t,this.extensions={},this.plugins={},this.options=e,this.cache=new Ct,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=-1,r=!1,i=-1;if(typeof navigator<"u"&&typeof navigator.userAgent<"u"){let a=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(a)===!0;let o=a.match(/Version\/(\d+)/);n=s&&o?parseInt(o[1],10):-1,r=a.indexOf("Firefox")>-1,i=r?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||r&&i<98?this.textureLoader=new Tt(this.options.manager):this.textureLoader=new xt(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new me(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(t){this.extensions=t}setPlugins(t){this.plugins=t}parse(t,e){let s=this,n=this.json,r=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(i){return i._markDefs&&i._markDefs()}),Promise.all(this._invokeAll(function(i){return i.beforeRoot&&i.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(i){let a={scene:i[0][n.scene||0],scenes:i[0],animations:i[1],cameras:i[2],asset:n.asset,parser:s,userData:{}};return v(r,a,n),I(a,n),Promise.all(s._invokeAll(function(o){return o.afterRoot&&o.afterRoot(a)})).then(function(){for(let o of a.scenes)o.updateMatrixWorld();t(a)})}).catch(e)}_markDefs(){let t=this.json.nodes||[],e=this.json.skins||[],s=this.json.meshes||[];for(let n=0,r=e.length;n<r;n++){let i=e[n].joints;for(let a=0,o=i.length;a<o;a++)t[i[a]].isBone=!0}for(let n=0,r=t.length;n<r;n++){let i=t[n];i.mesh!==void 0&&(this._addNodeRef(this.meshCache,i.mesh),i.skin!==void 0&&(s[i.mesh].isSkinnedMesh=!0)),i.camera!==void 0&&this._addNodeRef(this.cameraCache,i.camera)}}_addNodeRef(t,e){e!==void 0&&(t.refs[e]===void 0&&(t.refs[e]=t.uses[e]=0),t.refs[e]++)}_getNodeRef(t,e,s){if(t.refs[e]<=1)return s;let n=s.clone(),r=(i,a)=>{let o=this.associations.get(i);o!=null&&this.associations.set(a,o);for(let[c,u]of i.children.entries())r(u,a.children[c])};return r(s,n),n.name+="_instance_"+t.uses[e]++,n}_invokeOne(t){let e=Object.values(this.plugins);e.push(this);for(let s=0;s<e.length;s++){let n=t(e[s]);if(n)return n}return null}_invokeAll(t){let e=Object.values(this.plugins);e.unshift(this);let s=[];for(let n=0;n<e.length;n++){let r=t(e[n]);r&&s.push(r)}return s}getDependency(t,e){let s=t+":"+e,n=this.cache.get(s);if(!n){switch(t){case"scene":n=this.loadScene(e);break;case"node":n=this._invokeOne(function(r){return r.loadNode&&r.loadNode(e)});break;case"mesh":n=this._invokeOne(function(r){return r.loadMesh&&r.loadMesh(e)});break;case"accessor":n=this.loadAccessor(e);break;case"bufferView":n=this._invokeOne(function(r){return r.loadBufferView&&r.loadBufferView(e)});break;case"buffer":n=this.loadBuffer(e);break;case"material":n=this._invokeOne(function(r){return r.loadMaterial&&r.loadMaterial(e)});break;case"texture":n=this._invokeOne(function(r){return r.loadTexture&&r.loadTexture(e)});break;case"skin":n=this.loadSkin(e);break;case"animation":n=this._invokeOne(function(r){return r.loadAnimation&&r.loadAnimation(e)});break;case"camera":n=this.loadCamera(e);break;default:if(n=this._invokeOne(function(r){return r!=this&&r.getDependency&&r.getDependency(t,e)}),!n)throw new Error("Unknown type: "+t);break}this.cache.add(s,n)}return n}getDependencies(t){let e=this.cache.get(t);if(!e){let s=this,n=this.json[t+(t==="mesh"?"es":"s")]||[];e=Promise.all(n.map(function(r,i){return s.getDependency(t,i)})),this.cache.add(t,e)}return e}loadBuffer(t){let e=this.json.buffers[t],s=this.fileLoader;if(e.type&&e.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+e.type+" buffer type is not supported.");if(e.uri===void 0&&t===0)return Promise.resolve(this.extensions[g.KHR_BINARY_GLTF].body);let n=this.options;return new Promise(function(r,i){s.load(B.resolveURL(e.uri,n.path),r,void 0,function(){i(new Error('THREE.GLTFLoader: Failed to load buffer "'+e.uri+'".'))})})}loadBufferView(t){let e=this.json.bufferViews[t];return this.getDependency("buffer",e.buffer).then(function(s){let n=e.byteLength||0,r=e.byteOffset||0;return s.slice(r,r+n)})}loadAccessor(t){let e=this,s=this.json,n=this.json.accessors[t];if(n.bufferView===void 0&&n.sparse===void 0){let i=Te[n.type],a=D[n.componentType],o=n.normalized===!0,c=new a(n.count*i);return Promise.resolve(new G(c,i,o))}let r=[];return n.bufferView!==void 0?r.push(this.getDependency("bufferView",n.bufferView)):r.push(null),n.sparse!==void 0&&(r.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(r).then(function(i){let a=i[0],o=Te[n.type],c=D[n.componentType],u=c.BYTES_PER_ELEMENT,l=u*o,d=n.byteOffset||0,h=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,p=n.normalized===!0,A,m;if(h&&h!==l){let T=Math.floor(d/h),E="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+T+":"+n.count,y=e.cache.get(E);y||(A=new c(a,T*h,n.count*h/u),y=new ce(A,h/u),e.cache.add(E,y)),m=new ue(y,o,d%h/u,p)}else a===null?A=new c(n.count*o):A=new c(a,d,n.count*o),m=new G(A,o,p);if(n.sparse!==void 0){let T=Te.SCALAR,E=D[n.sparse.indices.componentType],y=n.sparse.indices.byteOffset||0,R=n.sparse.values.byteOffset||0,x=new E(i[1],y,n.sparse.count*T),L=new c(i[2],R,n.sparse.count*o);a!==null&&(m=new G(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let b=0,U=x.length;b<U;b++){let H=x[b];if(m.setX(H,L[b*o]),o>=2&&m.setY(H,L[b*o+1]),o>=3&&m.setZ(H,L[b*o+2]),o>=4&&m.setW(H,L[b*o+3]),o>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}m.normalized=p}return m})}loadTexture(t){let e=this.json,s=this.options,r=e.textures[t].source,i=e.images[r],a=this.textureLoader;if(i.uri){let o=s.manager.getHandler(i.uri);o!==null&&(a=o)}return this.loadTextureImage(t,r,a)}loadTextureImage(t,e,s){let n=this,r=this.json,i=r.textures[t],a=r.images[e],o=(a.uri||a.bufferView)+":"+i.sampler;if(this.textureCache[o])return this.textureCache[o];let c=this.loadImageSource(e,s).then(function(u){u.flipY=!1,u.name=i.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);let d=(r.samplers||{})[i.sampler]||{};return u.magFilter=It[d.magFilter]||X,u.minFilter=It[d.minFilter]||ee,u.wrapS=Nt[d.wrapS]||j,u.wrapT=Nt[d.wrapT]||j,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==$&&u.minFilter!==X,n.associations.set(u,{textures:t}),u}).catch(function(){return null});return this.textureCache[o]=c,c}loadImageSource(t,e){let s=this,n=this.json,r=this.options;if(this.sourceCache[t]!==void 0)return this.sourceCache[t].then(l=>l.clone());let i=n.images[t],a=self.URL||self.webkitURL,o=i.uri||"",c=!1;if(i.bufferView!==void 0)o=s.getDependency("bufferView",i.bufferView).then(function(l){c=!0;let d=new Blob([l],{type:i.mimeType});return o=a.createObjectURL(d),o});else if(i.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");let u=Promise.resolve(o).then(function(l){return new Promise(function(d,h){let p=d;e.isImageBitmapLoader===!0&&(p=function(A){let m=new ie(A);m.needsUpdate=!0,d(m)}),e.load(B.resolveURL(l,r.path),p,void 0,h)})}).then(function(l){return c===!0&&a.revokeObjectURL(o),I(l,i),l.userData.mimeType=i.mimeType||Ut(i.uri),l}).catch(function(l){throw console.error("THREE.GLTFLoader: Couldn't load texture",o),l});return this.sourceCache[t]=u,u}assignTexture(t,e,s,n){let r=this;return this.getDependency("texture",s.index).then(function(i){if(!i)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(i=i.clone(),i.channel=s.texCoord),r.extensions[g.KHR_TEXTURE_TRANSFORM]){let a=s.extensions!==void 0?s.extensions[g.KHR_TEXTURE_TRANSFORM]:void 0;if(a){let o=r.associations.get(i);i=r.extensions[g.KHR_TEXTURE_TRANSFORM].extendTexture(i,a),r.associations.set(i,o)}}return n!==void 0&&(i.colorSpace=n),t[e]=i,i})}assignFinalMaterial(t){let e=t.geometry,s=t.material,n=e.attributes.tangent===void 0,r=e.attributes.color!==void 0,i=e.attributes.normal===void 0;if(t.isPoints){let a="PointsMaterial:"+s.uuid,o=this.cache.get(a);o||(o=new dt,Y.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,o.sizeAttenuation=!1,this.cache.add(a,o)),s=o}else if(t.isLine){let a="LineBasicMaterial:"+s.uuid,o=this.cache.get(a);o||(o=new ct,Y.prototype.copy.call(o,s),o.color.copy(s.color),o.map=s.map,this.cache.add(a,o)),s=o}if(n||r||i){let a="ClonedMaterial:"+s.uuid+":";n&&(a+="derivative-tangents:"),r&&(a+="vertex-colors:"),i&&(a+="flat-shading:");let o=this.cache.get(a);o||(o=s.clone(),r&&(o.vertexColors=!0),i&&(o.flatShading=!0),n&&(o.normalScale&&(o.normalScale.y*=-1),o.clearcoatNormalScale&&(o.clearcoatNormalScale.y*=-1)),this.cache.add(a,o),this.associations.set(o,this.associations.get(s))),s=o}t.material=s}getMaterialType(){return fe}loadMaterial(t){let e=this,s=this.json,n=this.extensions,r=s.materials[t],i,a={},o=r.extensions||{},c=[];if(o[g.KHR_MATERIALS_UNLIT]){let l=n[g.KHR_MATERIALS_UNLIT];i=l.getMaterialType(),c.push(l.extendParams(a,r,e))}else{let l=r.pbrMetallicRoughness||{};if(a.color=new O(1,1,1),a.opacity=1,Array.isArray(l.baseColorFactor)){let d=l.baseColorFactor;a.color.setRGB(d[0],d[1],d[2],M),a.opacity=d[3]}l.baseColorTexture!==void 0&&c.push(e.assignTexture(a,"map",l.baseColorTexture,k)),a.metalness=l.metallicFactor!==void 0?l.metallicFactor:1,a.roughness=l.roughnessFactor!==void 0?l.roughnessFactor:1,l.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(a,"metalnessMap",l.metallicRoughnessTexture)),c.push(e.assignTexture(a,"roughnessMap",l.metallicRoughnessTexture))),i=this._invokeOne(function(d){return d.getMaterialType&&d.getMaterialType(t)}),c.push(Promise.all(this._invokeAll(function(d){return d.extendMaterialParams&&d.extendMaterialParams(t,a)})))}r.doubleSided===!0&&(a.side=Ve);let u=r.alphaMode||Ae.OPAQUE;if(u===Ae.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===Ae.MASK&&(a.alphaTest=r.alphaCutoff!==void 0?r.alphaCutoff:.5)),r.normalTexture!==void 0&&i!==P&&(c.push(e.assignTexture(a,"normalMap",r.normalTexture)),a.normalScale=new ne(1,1),r.normalTexture.scale!==void 0)){let l=r.normalTexture.scale;a.normalScale.set(l,l)}if(r.occlusionTexture!==void 0&&i!==P&&(c.push(e.assignTexture(a,"aoMap",r.occlusionTexture)),r.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=r.occlusionTexture.strength)),r.emissiveFactor!==void 0&&i!==P){let l=r.emissiveFactor;a.emissive=new O().setRGB(l[0],l[1],l[2],M)}return r.emissiveTexture!==void 0&&i!==P&&c.push(e.assignTexture(a,"emissiveMap",r.emissiveTexture,k)),Promise.all(c).then(function(){let l=new i(a);return r.name&&(l.name=r.name),I(l,r),e.associations.set(l,{materials:t}),r.extensions&&v(n,l,r),l})}createUniqueName(t){let e=wt.sanitizeNodeName(t||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(t){let e=this,s=this.extensions,n=this.primitiveCache;function r(a){return s[g.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,e).then(function(o){return Lt(o,a,e)})}let i=[];for(let a=0,o=t.length;a<o;a++){let c=t[a],u=Dt(c),l=n[u];if(l)i.push(l.promise);else{let d;c.extensions&&c.extensions[g.KHR_DRACO_MESH_COMPRESSION]?d=r(c):d=Lt(new ae,c,e),n[u]={primitive:c,promise:d},i.push(d)}}return Promise.all(i)}loadMesh(t){let e=this,s=this.json,n=this.extensions,r=s.meshes[t],i=r.primitives,a=[];for(let o=0,c=i.length;o<c;o++){let u=i[o].material===void 0?kt(this.cache):this.getDependency("material",i[o].material);a.push(u)}return a.push(e.loadGeometries(i)),Promise.all(a).then(function(o){let c=o.slice(0,o.length-1),u=o[o.length-1],l=[];for(let h=0,p=u.length;h<p;h++){let A=u[h],m=i[h],T,E=c[h];if(m.mode===w.TRIANGLES||m.mode===w.TRIANGLE_STRIP||m.mode===w.TRIANGLE_FAN||m.mode===void 0)T=r.isSkinnedMesh===!0?new rt(A,E):new st(A,E),T.isSkinnedMesh===!0&&T.normalizeSkinWeights(),m.mode===w.TRIANGLE_STRIP?T.geometry=ge(T.geometry,V):m.mode===w.TRIANGLE_FAN&&(T.geometry=ge(T.geometry,F));else if(m.mode===w.LINES)T=new lt(A,E);else if(m.mode===w.LINE_STRIP)T=new ut(A,E);else if(m.mode===w.LINE_LOOP)T=new ft(A,E);else if(m.mode===w.POINTS)T=new ht(A,E);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+m.mode);Object.keys(T.geometry.morphAttributes).length>0&&Bt(T,r),T.name=e.createUniqueName(r.name||"mesh_"+t),I(T,r),m.extensions&&v(n,T,m),e.assignFinalMaterial(T),l.push(T)}for(let h=0,p=l.length;h<p;h++)e.associations.set(l[h],{meshes:t,primitives:h});if(l.length===1)return r.extensions&&v(n,l[0],r),l[0];let d=new q;r.extensions&&v(n,d,r),e.associations.set(d,{meshes:t});for(let h=0,p=l.length;h<p;h++)d.add(l[h]);return d})}loadCamera(t){let e,s=this.json.cameras[t],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?e=new At(et.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(e=new Et(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(e.name=this.createUniqueName(s.name)),I(e,s),Promise.resolve(e)}loadSkin(t){let e=this.json.skins[t],s=[];for(let n=0,r=e.joints.length;n<r;n++)s.push(this._loadNodeShallow(e.joints[n]));return e.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",e.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){let r=n.pop(),i=n,a=[],o=[];for(let c=0,u=i.length;c<u;c++){let l=i[c];if(l){a.push(l);let d=new z;r!==null&&d.fromArray(r.array,c*16),o.push(d)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',e.joints[c])}return new ot(a,o)})}loadAnimation(t){let e=this.json,s=this,n=e.animations[t],r=n.name?n.name:"animation_"+t,i=[],a=[],o=[],c=[],u=[];for(let l=0,d=n.channels.length;l<d;l++){let h=n.channels[l],p=n.samplers[h.sampler],A=h.target,m=A.node,T=n.parameters!==void 0?n.parameters[p.input]:p.input,E=n.parameters!==void 0?n.parameters[p.output]:p.output;A.node!==void 0&&(i.push(this.getDependency("node",m)),a.push(this.getDependency("accessor",T)),o.push(this.getDependency("accessor",E)),c.push(p),u.push(A))}return Promise.all([Promise.all(i),Promise.all(a),Promise.all(o),Promise.all(c),Promise.all(u)]).then(function(l){let d=l[0],h=l[1],p=l[2],A=l[3],m=l[4],T=[];for(let y=0,R=d.length;y<R;y++){let x=d[y],L=h[y],b=p[y],U=A[y],H=m[y];if(x===void 0)continue;x.updateMatrix&&x.updateMatrix();let J=s._createAnimationTracks(x,L,b,U,H);if(J)for(let Q=0;Q<J.length;Q++)T.push(J[Q])}let E=new mt(r,void 0,T);return I(E,n),E})}createNodeMesh(t){let e=this.json,s=this,n=e.nodes[t];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(r){let i=s._getNodeRef(s.meshCache,n.mesh,r);return n.weights!==void 0&&i.traverse(function(a){if(a.isMesh)for(let o=0,c=n.weights.length;o<c;o++)a.morphTargetInfluences[o]=n.weights[o]}),i})}loadNode(t){let e=this.json,s=this,n=e.nodes[t],r=s._loadNodeShallow(t),i=[],a=n.children||[];for(let c=0,u=a.length;c<u;c++)i.push(s.getDependency("node",a[c]));let o=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([r,Promise.all(i),o]).then(function(c){let u=c[0],l=c[1],d=c[2];d!==null&&u.traverse(function(h){h.isSkinnedMesh&&h.bind(d,Ft)});for(let h=0,p=l.length;h<p;h++)u.add(l[h]);if(u.userData.pivot!==void 0&&l.length>0){let h=u.userData.pivot,p=l[0];u.pivot=new N().fromArray(h),u.position.x-=h[0],u.position.y-=h[1],u.position.z-=h[2],p.position.set(0,0,0),delete u.userData.pivot}return u})}_loadNodeShallow(t){let e=this.json,s=this.extensions,n=this;if(this.nodeCache[t]!==void 0)return this.nodeCache[t];let r=e.nodes[t],i=r.name?n.createUniqueName(r.name):"",a=[],o=n._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(t)});return o&&a.push(o),r.camera!==void 0&&a.push(n.getDependency("camera",r.camera).then(function(c){return n._getNodeRef(n.cameraCache,r.camera,c)})),n._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(t)}).forEach(function(c){a.push(c)}),this.nodeCache[t]=Promise.all(a).then(function(c){let u;if(r.isBone===!0?u=new it:c.length>1?u=new q:c.length===1?u=c[0]:u=new oe,u!==c[0])for(let l=0,d=c.length;l<d;l++)u.add(c[l]);if(r.name&&(u.userData.name=r.name,u.name=i),I(u,r),r.extensions&&v(s,u,r),r.matrix!==void 0){let l=new z;l.fromArray(r.matrix),u.applyMatrix4(l)}else r.translation!==void 0&&u.position.fromArray(r.translation),r.rotation!==void 0&&u.quaternion.fromArray(r.rotation),r.scale!==void 0&&u.scale.fromArray(r.scale);if(!n.associations.has(u))n.associations.set(u,{});else if(r.mesh!==void 0&&n.meshCache.refs[r.mesh]>1){let l=n.associations.get(u);n.associations.set(u,{...l})}return n.associations.get(u).nodes=t,u}),this.nodeCache[t]}loadScene(t){let e=this.extensions,s=this.json.scenes[t],n=this,r=new q;s.name&&(r.name=n.createUniqueName(s.name)),I(r,s),s.extensions&&v(e,r,s);let i=s.nodes||[],a=[];for(let o=0,c=i.length;o<c;o++)a.push(n.getDependency("node",i[o]));return Promise.all(a).then(function(o){for(let u=0,l=o.length;u<l;u++){let d=o[u];d.parent!==null?r.add(bt(d)):r.add(d)}let c=u=>{let l=new Map;for(let[d,h]of n.associations)(d instanceof Y||d instanceof ie)&&l.set(d,h);return u.traverse(d=>{let h=n.associations.get(d);h!=null&&l.set(d,h)}),l};return n.associations=c(r),r})}_createAnimationTracks(t,e,s,n,r){let i=[],a=t.name?t.name:t.uuid,o=[];function c(h){h.morphTargetInfluences&&o.push(h.name?h.name:h.uuid)}C[r.path]===C.weights?(c(t),t.isGroup&&t.children.forEach(c)):o.push(a);let u;switch(C[r.path]){case C.weights:u=de;break;case C.rotation:u=he;break;case C.translation:case C.scale:u=pe;break;default:s.itemSize===1?u=de:u=pe;break}let l=n.interpolation!==void 0?Ht[n.interpolation]:te,d=this._getArrayFromAccessor(s);for(let h=0,p=o.length;h<p;h++){let A=new u(o[h]+"."+C[r.path],e.array,d,l);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(A),i.push(A)}return i}_getArrayFromAccessor(t){let e=t.array;if(t.normalized){let s=Ke(e.constructor),n=new Float32Array(e.length);for(let r=0,i=e.length;r<i;r++)n[r]=e[r]*s;e=n}return e}_createCubicSplineTrackInterpolant(t){t.createInterpolant=function(s){let n=this instanceof he?ze:Z;return new n(this.times,this.values,this.getValueSize()/3,s)},t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function zt(f,t,e){let s=t.attributes,n=new tt;if(s.POSITION!==void 0){let a=e.json.accessors[s.POSITION],o=a.min,c=a.max;if(o!==void 0&&c!==void 0){if(n.set(new N(o[0],o[1],o[2]),new N(c[0],c[1],c[2])),a.normalized){let u=Ke(D[a.componentType]);n.min.multiplyScalar(u),n.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;let r=t.targets;if(r!==void 0){let a=new N,o=new N;for(let c=0,u=r.length;c<u;c++){let l=r[c];if(l.POSITION!==void 0){let d=e.json.accessors[l.POSITION],h=d.min,p=d.max;if(h!==void 0&&p!==void 0){if(o.setX(Math.max(Math.abs(h[0]),Math.abs(p[0]))),o.setY(Math.max(Math.abs(h[1]),Math.abs(p[1]))),o.setZ(Math.max(Math.abs(h[2]),Math.abs(p[2]))),d.normalized){let A=Ke(D[d.componentType]);o.multiplyScalar(A)}a.max(o)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(a)}f.boundingBox=n;let i=new nt;n.getCenter(i.center),i.radius=n.min.distanceTo(n.max)/2,f.boundingSphere=i}function Lt(f,t,e){let s=t.attributes,n=[];function r(i,a){return e.getDependency("accessor",i).then(function(o){f.setAttribute(a,o)})}for(let i in s){let a=Ge[i]||i.toLowerCase();a in f.attributes||n.push(r(s[i],a))}if(t.indices!==void 0&&!f.index){let i=e.getDependency("accessor",t.indices).then(function(a){f.setIndex(a)});n.push(i)}return re.workingColorSpace!==M&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${re.workingColorSpace}" not supported.`),I(f,t),zt(f,t,e),Promise.all(n).then(function(){return t.targets!==void 0?Pt(f,t.targets,e):f})}export{St as GLTFLoader};
|
|
2
|
-
//# sourceMappingURL=GLTFLoader-PGXD4V5B.js.map
|