@guoquan.net/flow-engine 0.1.2 → 0.1.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/dist/flow.es.js CHANGED
@@ -1,11 +1,465 @@
1
- import * as i from "three";
2
- import { WebGPURenderer as g } from "three/webgpu";
3
- import { OrbitControls as y } from "three/examples/jsm/controls/OrbitControls.js";
4
- import { GLTFLoader as f } from "three/examples/jsm/loaders/GLTFLoader.js";
5
- class M {
1
+ import * as n from "three";
2
+ import { Controls as v, Vector3 as _, MOUSE as b, TOUCH as y, Quaternion as T, Spherical as S, Vector2 as m, Ray as x, Plane as N, MathUtils as I } from "three";
3
+ import { WebGPURenderer as j } from "three/webgpu";
4
+ import { GLTFLoader as k } from "three/examples/jsm/loaders/GLTFLoader.js";
5
+ const L = { type: "change" }, A = { type: "start" }, R = { type: "end" }, E = new x(), C = new N(), H = Math.cos(70 * I.DEG2RAD), d = new _(), p = 2 * Math.PI, l = {
6
+ NONE: -1,
7
+ ROTATE: 0,
8
+ DOLLY: 1,
9
+ PAN: 2,
10
+ TOUCH_ROTATE: 3,
11
+ TOUCH_PAN: 4,
12
+ TOUCH_DOLLY_PAN: 5,
13
+ TOUCH_DOLLY_ROTATE: 6
14
+ }, D = 1e-6;
15
+ class U extends v {
16
+ /**
17
+ * Constructs a new controls instance.
18
+ *
19
+ * @param {Object3D} object - The object that is managed by the controls.
20
+ * @param {?HTMLElement} domElement - The HTML element used for event listeners.
21
+ */
22
+ constructor(t, e = null) {
23
+ super(t, e), this.state = l.NONE, this.target = new _(), this.cursor = new _(), this.minDistance = 0, this.maxDistance = 1 / 0, this.minZoom = 0, this.maxZoom = 1 / 0, this.minTargetRadius = 0, this.maxTargetRadius = 1 / 0, this.minPolarAngle = 0, this.maxPolarAngle = Math.PI, this.minAzimuthAngle = -1 / 0, this.maxAzimuthAngle = 1 / 0, this.enableDamping = !1, this.dampingFactor = 0.05, this.enableZoom = !0, this.zoomSpeed = 1, this.enableRotate = !0, this.rotateSpeed = 1, this.keyRotateSpeed = 1, this.enablePan = !0, this.panSpeed = 1, this.screenSpacePanning = !0, this.keyPanSpeed = 7, this.zoomToCursor = !1, this.autoRotate = !1, this.autoRotateSpeed = 2, this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }, this.mouseButtons = { LEFT: b.ROTATE, MIDDLE: b.DOLLY, RIGHT: b.PAN }, this.touches = { ONE: y.ROTATE, TWO: y.DOLLY_PAN }, this.target0 = this.target.clone(), this.position0 = this.object.position.clone(), this.zoom0 = this.object.zoom, this._domElementKeyEvents = null, this._lastPosition = new _(), this._lastQuaternion = new T(), this._lastTargetPosition = new _(), this._quat = new T().setFromUnitVectors(t.up, new _(0, 1, 0)), this._quatInverse = this._quat.clone().invert(), this._spherical = new S(), this._sphericalDelta = new S(), this._scale = 1, this._panOffset = new _(), this._rotateStart = new m(), this._rotateEnd = new m(), this._rotateDelta = new m(), this._panStart = new m(), this._panEnd = new m(), this._panDelta = new m(), this._dollyStart = new m(), this._dollyEnd = new m(), this._dollyDelta = new m(), this._dollyDirection = new _(), this._mouse = new m(), this._performCursorZoom = !1, this._pointers = [], this._pointerPositions = {}, this._controlActive = !1, this._onPointerMove = F.bind(this), this._onPointerDown = Y.bind(this), this._onPointerUp = z.bind(this), this._onContextMenu = X.bind(this), this._onMouseWheel = W.bind(this), this._onKeyDown = Z.bind(this), this._onTouchStart = B.bind(this), this._onTouchMove = Q.bind(this), this._onMouseDown = G.bind(this), this._onMouseMove = K.bind(this), this._interceptControlDown = V.bind(this), this._interceptControlUp = q.bind(this), this.domElement !== null && this.connect(this.domElement), this.update();
24
+ }
25
+ connect(t) {
26
+ super.connect(t), this.domElement.addEventListener("pointerdown", this._onPointerDown), this.domElement.addEventListener("pointercancel", this._onPointerUp), this.domElement.addEventListener("contextmenu", this._onContextMenu), this.domElement.addEventListener("wheel", this._onMouseWheel, { passive: !1 }), this.domElement.getRootNode().addEventListener("keydown", this._interceptControlDown, { passive: !0, capture: !0 }), this.domElement.style.touchAction = "none";
27
+ }
28
+ disconnect() {
29
+ this.domElement.removeEventListener("pointerdown", this._onPointerDown), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.domElement.removeEventListener("pointercancel", this._onPointerUp), this.domElement.removeEventListener("wheel", this._onMouseWheel), this.domElement.removeEventListener("contextmenu", this._onContextMenu), this.stopListenToKeyEvents(), this.domElement.getRootNode().removeEventListener("keydown", this._interceptControlDown, { capture: !0 }), this.domElement.style.touchAction = "auto";
30
+ }
31
+ dispose() {
32
+ this.disconnect();
33
+ }
34
+ /**
35
+ * Get the current vertical rotation, in radians.
36
+ *
37
+ * @return {number} The current vertical rotation, in radians.
38
+ */
39
+ getPolarAngle() {
40
+ return this._spherical.phi;
41
+ }
42
+ /**
43
+ * Get the current horizontal rotation, in radians.
44
+ *
45
+ * @return {number} The current horizontal rotation, in radians.
46
+ */
47
+ getAzimuthalAngle() {
48
+ return this._spherical.theta;
49
+ }
50
+ /**
51
+ * Returns the distance from the camera to the target.
52
+ *
53
+ * @return {number} The distance from the camera to the target.
54
+ */
55
+ getDistance() {
56
+ return this.object.position.distanceTo(this.target);
57
+ }
58
+ /**
59
+ * Adds key event listeners to the given DOM element.
60
+ * `window` is a recommended argument for using this method.
61
+ *
62
+ * @param {HTMLElement} domElement - The DOM element
63
+ */
64
+ listenToKeyEvents(t) {
65
+ t.addEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = t;
66
+ }
67
+ /**
68
+ * Removes the key event listener previously defined with `listenToKeyEvents()`.
69
+ */
70
+ stopListenToKeyEvents() {
71
+ this._domElementKeyEvents !== null && (this._domElementKeyEvents.removeEventListener("keydown", this._onKeyDown), this._domElementKeyEvents = null);
72
+ }
73
+ /**
74
+ * Save the current state of the controls. This can later be recovered with `reset()`.
75
+ */
76
+ saveState() {
77
+ this.target0.copy(this.target), this.position0.copy(this.object.position), this.zoom0 = this.object.zoom;
78
+ }
79
+ /**
80
+ * Reset the controls to their state from either the last time the `saveState()`
81
+ * was called, or the initial state.
82
+ */
83
+ reset() {
84
+ this.target.copy(this.target0), this.object.position.copy(this.position0), this.object.zoom = this.zoom0, this.object.updateProjectionMatrix(), this.dispatchEvent(L), this.update(), this.state = l.NONE;
85
+ }
86
+ update(t = null) {
87
+ const e = this.object.position;
88
+ d.copy(e).sub(this.target), d.applyQuaternion(this._quat), this._spherical.setFromVector3(d), this.autoRotate && this.state === l.NONE && this._rotateLeft(this._getAutoRotationAngle(t)), this.enableDamping ? (this._spherical.theta += this._sphericalDelta.theta * this.dampingFactor, this._spherical.phi += this._sphericalDelta.phi * this.dampingFactor) : (this._spherical.theta += this._sphericalDelta.theta, this._spherical.phi += this._sphericalDelta.phi);
89
+ let i = this.minAzimuthAngle, s = this.maxAzimuthAngle;
90
+ isFinite(i) && isFinite(s) && (i < -Math.PI ? i += p : i > Math.PI && (i -= p), s < -Math.PI ? s += p : s > Math.PI && (s -= p), i <= s ? this._spherical.theta = Math.max(i, Math.min(s, this._spherical.theta)) : this._spherical.theta = this._spherical.theta > (i + s) / 2 ? Math.max(i, this._spherical.theta) : Math.min(s, this._spherical.theta)), this._spherical.phi = Math.max(this.minPolarAngle, Math.min(this.maxPolarAngle, this._spherical.phi)), this._spherical.makeSafe(), this.enableDamping === !0 ? this.target.addScaledVector(this._panOffset, this.dampingFactor) : this.target.add(this._panOffset), this.target.sub(this.cursor), this.target.clampLength(this.minTargetRadius, this.maxTargetRadius), this.target.add(this.cursor);
91
+ let a = !1;
92
+ if (this.zoomToCursor && this._performCursorZoom || this.object.isOrthographicCamera)
93
+ this._spherical.radius = this._clampDistance(this._spherical.radius);
94
+ else {
95
+ const r = this._spherical.radius;
96
+ this._spherical.radius = this._clampDistance(this._spherical.radius * this._scale), a = r != this._spherical.radius;
97
+ }
98
+ if (d.setFromSpherical(this._spherical), d.applyQuaternion(this._quatInverse), e.copy(this.target).add(d), this.object.lookAt(this.target), this.enableDamping === !0 ? (this._sphericalDelta.theta *= 1 - this.dampingFactor, this._sphericalDelta.phi *= 1 - this.dampingFactor, this._panOffset.multiplyScalar(1 - this.dampingFactor)) : (this._sphericalDelta.set(0, 0, 0), this._panOffset.set(0, 0, 0)), this.zoomToCursor && this._performCursorZoom) {
99
+ let r = null;
100
+ if (this.object.isPerspectiveCamera) {
101
+ const h = d.length();
102
+ r = this._clampDistance(h * this._scale);
103
+ const c = h - r;
104
+ this.object.position.addScaledVector(this._dollyDirection, c), this.object.updateMatrixWorld(), a = !!c;
105
+ } else if (this.object.isOrthographicCamera) {
106
+ const h = new _(this._mouse.x, this._mouse.y, 0);
107
+ h.unproject(this.object);
108
+ const c = this.object.zoom;
109
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), this.object.updateProjectionMatrix(), a = c !== this.object.zoom;
110
+ const f = new _(this._mouse.x, this._mouse.y, 0);
111
+ f.unproject(this.object), this.object.position.sub(f).add(h), this.object.updateMatrixWorld(), r = d.length();
112
+ } else
113
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."), this.zoomToCursor = !1;
114
+ r !== null && (this.screenSpacePanning ? this.target.set(0, 0, -1).transformDirection(this.object.matrix).multiplyScalar(r).add(this.object.position) : (E.origin.copy(this.object.position), E.direction.set(0, 0, -1).transformDirection(this.object.matrix), Math.abs(this.object.up.dot(E.direction)) < H ? this.object.lookAt(this.target) : (C.setFromNormalAndCoplanarPoint(this.object.up, this.target), E.intersectPlane(C, this.target))));
115
+ } else if (this.object.isOrthographicCamera) {
116
+ const r = this.object.zoom;
117
+ this.object.zoom = Math.max(this.minZoom, Math.min(this.maxZoom, this.object.zoom / this._scale)), r !== this.object.zoom && (this.object.updateProjectionMatrix(), a = !0);
118
+ }
119
+ return this._scale = 1, this._performCursorZoom = !1, a || this._lastPosition.distanceToSquared(this.object.position) > D || 8 * (1 - this._lastQuaternion.dot(this.object.quaternion)) > D || this._lastTargetPosition.distanceToSquared(this.target) > D ? (this.dispatchEvent(L), this._lastPosition.copy(this.object.position), this._lastQuaternion.copy(this.object.quaternion), this._lastTargetPosition.copy(this.target), !0) : !1;
120
+ }
121
+ _getAutoRotationAngle(t) {
122
+ return t !== null ? p / 60 * this.autoRotateSpeed * t : p / 60 / 60 * this.autoRotateSpeed;
123
+ }
124
+ _getZoomScale(t) {
125
+ const e = Math.abs(t * 0.01);
126
+ return Math.pow(0.95, this.zoomSpeed * e);
127
+ }
128
+ _rotateLeft(t) {
129
+ this._sphericalDelta.theta -= t;
130
+ }
131
+ _rotateUp(t) {
132
+ this._sphericalDelta.phi -= t;
133
+ }
134
+ _panLeft(t, e) {
135
+ d.setFromMatrixColumn(e, 0), d.multiplyScalar(-t), this._panOffset.add(d);
136
+ }
137
+ _panUp(t, e) {
138
+ this.screenSpacePanning === !0 ? d.setFromMatrixColumn(e, 1) : (d.setFromMatrixColumn(e, 0), d.crossVectors(this.object.up, d)), d.multiplyScalar(t), this._panOffset.add(d);
139
+ }
140
+ // deltaX and deltaY are in pixels; right and down are positive
141
+ _pan(t, e) {
142
+ const i = this.domElement;
143
+ if (this.object.isPerspectiveCamera) {
144
+ const s = this.object.position;
145
+ d.copy(s).sub(this.target);
146
+ let a = d.length();
147
+ a *= Math.tan(this.object.fov / 2 * Math.PI / 180), this._panLeft(2 * t * a / i.clientHeight, this.object.matrix), this._panUp(2 * e * a / i.clientHeight, this.object.matrix);
148
+ } else this.object.isOrthographicCamera ? (this._panLeft(t * (this.object.right - this.object.left) / this.object.zoom / i.clientWidth, this.object.matrix), this._panUp(e * (this.object.top - this.object.bottom) / this.object.zoom / i.clientHeight, this.object.matrix)) : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."), this.enablePan = !1);
149
+ }
150
+ _dollyOut(t) {
151
+ this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale /= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
152
+ }
153
+ _dollyIn(t) {
154
+ this.object.isPerspectiveCamera || this.object.isOrthographicCamera ? this._scale *= t : (console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."), this.enableZoom = !1);
155
+ }
156
+ _updateZoomParameters(t, e) {
157
+ if (!this.zoomToCursor)
158
+ return;
159
+ this._performCursorZoom = !0;
160
+ const i = this.domElement.getBoundingClientRect(), s = t - i.left, a = e - i.top, r = i.width, h = i.height;
161
+ this._mouse.x = s / r * 2 - 1, this._mouse.y = -(a / h) * 2 + 1, this._dollyDirection.set(this._mouse.x, this._mouse.y, 1).unproject(this.object).sub(this.object.position).normalize();
162
+ }
163
+ _clampDistance(t) {
164
+ return Math.max(this.minDistance, Math.min(this.maxDistance, t));
165
+ }
166
+ //
167
+ // event callbacks - update the object state
168
+ //
169
+ _handleMouseDownRotate(t) {
170
+ this._rotateStart.set(t.clientX, t.clientY);
171
+ }
172
+ _handleMouseDownDolly(t) {
173
+ this._updateZoomParameters(t.clientX, t.clientX), this._dollyStart.set(t.clientX, t.clientY);
174
+ }
175
+ _handleMouseDownPan(t) {
176
+ this._panStart.set(t.clientX, t.clientY);
177
+ }
178
+ _handleMouseMoveRotate(t) {
179
+ this._rotateEnd.set(t.clientX, t.clientY), this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
180
+ const e = this.domElement;
181
+ this._rotateLeft(p * this._rotateDelta.x / e.clientHeight), this._rotateUp(p * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd), this.update();
182
+ }
183
+ _handleMouseMoveDolly(t) {
184
+ this._dollyEnd.set(t.clientX, t.clientY), this._dollyDelta.subVectors(this._dollyEnd, this._dollyStart), this._dollyDelta.y > 0 ? this._dollyOut(this._getZoomScale(this._dollyDelta.y)) : this._dollyDelta.y < 0 && this._dollyIn(this._getZoomScale(this._dollyDelta.y)), this._dollyStart.copy(this._dollyEnd), this.update();
185
+ }
186
+ _handleMouseMovePan(t) {
187
+ this._panEnd.set(t.clientX, t.clientY), this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd), this.update();
188
+ }
189
+ _handleMouseWheel(t) {
190
+ this._updateZoomParameters(t.clientX, t.clientY), t.deltaY < 0 ? this._dollyIn(this._getZoomScale(t.deltaY)) : t.deltaY > 0 && this._dollyOut(this._getZoomScale(t.deltaY)), this.update();
191
+ }
192
+ _handleKeyDown(t) {
193
+ let e = !1;
194
+ switch (t.code) {
195
+ case this.keys.UP:
196
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, this.keyPanSpeed), e = !0;
197
+ break;
198
+ case this.keys.BOTTOM:
199
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateUp(-p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(0, -this.keyPanSpeed), e = !0;
200
+ break;
201
+ case this.keys.LEFT:
202
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(this.keyPanSpeed, 0), e = !0;
203
+ break;
204
+ case this.keys.RIGHT:
205
+ t.ctrlKey || t.metaKey || t.shiftKey ? this.enableRotate && this._rotateLeft(-p * this.keyRotateSpeed / this.domElement.clientHeight) : this.enablePan && this._pan(-this.keyPanSpeed, 0), e = !0;
206
+ break;
207
+ }
208
+ e && (t.preventDefault(), this.update());
209
+ }
210
+ _handleTouchStartRotate(t) {
211
+ if (this._pointers.length === 1)
212
+ this._rotateStart.set(t.pageX, t.pageY);
213
+ else {
214
+ const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
215
+ this._rotateStart.set(i, s);
216
+ }
217
+ }
218
+ _handleTouchStartPan(t) {
219
+ if (this._pointers.length === 1)
220
+ this._panStart.set(t.pageX, t.pageY);
221
+ else {
222
+ const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
223
+ this._panStart.set(i, s);
224
+ }
225
+ }
226
+ _handleTouchStartDolly(t) {
227
+ const e = this._getSecondPointerPosition(t), i = t.pageX - e.x, s = t.pageY - e.y, a = Math.sqrt(i * i + s * s);
228
+ this._dollyStart.set(0, a);
229
+ }
230
+ _handleTouchStartDollyPan(t) {
231
+ this.enableZoom && this._handleTouchStartDolly(t), this.enablePan && this._handleTouchStartPan(t);
232
+ }
233
+ _handleTouchStartDollyRotate(t) {
234
+ this.enableZoom && this._handleTouchStartDolly(t), this.enableRotate && this._handleTouchStartRotate(t);
235
+ }
236
+ _handleTouchMoveRotate(t) {
237
+ if (this._pointers.length == 1)
238
+ this._rotateEnd.set(t.pageX, t.pageY);
239
+ else {
240
+ const i = this._getSecondPointerPosition(t), s = 0.5 * (t.pageX + i.x), a = 0.5 * (t.pageY + i.y);
241
+ this._rotateEnd.set(s, a);
242
+ }
243
+ this._rotateDelta.subVectors(this._rotateEnd, this._rotateStart).multiplyScalar(this.rotateSpeed);
244
+ const e = this.domElement;
245
+ this._rotateLeft(p * this._rotateDelta.x / e.clientHeight), this._rotateUp(p * this._rotateDelta.y / e.clientHeight), this._rotateStart.copy(this._rotateEnd);
246
+ }
247
+ _handleTouchMovePan(t) {
248
+ if (this._pointers.length === 1)
249
+ this._panEnd.set(t.pageX, t.pageY);
250
+ else {
251
+ const e = this._getSecondPointerPosition(t), i = 0.5 * (t.pageX + e.x), s = 0.5 * (t.pageY + e.y);
252
+ this._panEnd.set(i, s);
253
+ }
254
+ this._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed), this._pan(this._panDelta.x, this._panDelta.y), this._panStart.copy(this._panEnd);
255
+ }
256
+ _handleTouchMoveDolly(t) {
257
+ const e = this._getSecondPointerPosition(t), i = t.pageX - e.x, s = t.pageY - e.y, a = Math.sqrt(i * i + s * s);
258
+ this._dollyEnd.set(0, a), this._dollyDelta.set(0, Math.pow(this._dollyEnd.y / this._dollyStart.y, this.zoomSpeed)), this._dollyOut(this._dollyDelta.y), this._dollyStart.copy(this._dollyEnd);
259
+ const r = (t.pageX + e.x) * 0.5, h = (t.pageY + e.y) * 0.5;
260
+ this._updateZoomParameters(r, h);
261
+ }
262
+ _handleTouchMoveDollyPan(t) {
263
+ this.enableZoom && this._handleTouchMoveDolly(t), this.enablePan && this._handleTouchMovePan(t);
264
+ }
265
+ _handleTouchMoveDollyRotate(t) {
266
+ this.enableZoom && this._handleTouchMoveDolly(t), this.enableRotate && this._handleTouchMoveRotate(t);
267
+ }
268
+ // pointers
269
+ _addPointer(t) {
270
+ this._pointers.push(t.pointerId);
271
+ }
272
+ _removePointer(t) {
273
+ delete this._pointerPositions[t.pointerId];
274
+ for (let e = 0; e < this._pointers.length; e++)
275
+ if (this._pointers[e] == t.pointerId) {
276
+ this._pointers.splice(e, 1);
277
+ return;
278
+ }
279
+ }
280
+ _isTrackingPointer(t) {
281
+ for (let e = 0; e < this._pointers.length; e++)
282
+ if (this._pointers[e] == t.pointerId) return !0;
283
+ return !1;
284
+ }
285
+ _trackPointer(t) {
286
+ let e = this._pointerPositions[t.pointerId];
287
+ e === void 0 && (e = new m(), this._pointerPositions[t.pointerId] = e), e.set(t.pageX, t.pageY);
288
+ }
289
+ _getSecondPointerPosition(t) {
290
+ const e = t.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];
291
+ return this._pointerPositions[e];
292
+ }
293
+ //
294
+ _customWheelEvent(t) {
295
+ const e = t.deltaMode, i = {
296
+ clientX: t.clientX,
297
+ clientY: t.clientY,
298
+ deltaY: t.deltaY
299
+ };
300
+ switch (e) {
301
+ case 1:
302
+ i.deltaY *= 16;
303
+ break;
304
+ case 2:
305
+ i.deltaY *= 100;
306
+ break;
307
+ }
308
+ return t.ctrlKey && !this._controlActive && (i.deltaY *= 10), i;
309
+ }
310
+ }
311
+ function Y(o) {
312
+ this.enabled !== !1 && (this._pointers.length === 0 && (this.domElement.setPointerCapture(o.pointerId), this.domElement.ownerDocument.addEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.addEventListener("pointerup", this._onPointerUp)), !this._isTrackingPointer(o) && (this._addPointer(o), o.pointerType === "touch" ? this._onTouchStart(o) : this._onMouseDown(o)));
313
+ }
314
+ function F(o) {
315
+ this.enabled !== !1 && (o.pointerType === "touch" ? this._onTouchMove(o) : this._onMouseMove(o));
316
+ }
317
+ function z(o) {
318
+ switch (this._removePointer(o), this._pointers.length) {
319
+ case 0:
320
+ this.domElement.releasePointerCapture(o.pointerId), this.domElement.ownerDocument.removeEventListener("pointermove", this._onPointerMove), this.domElement.ownerDocument.removeEventListener("pointerup", this._onPointerUp), this.dispatchEvent(R), this.state = l.NONE;
321
+ break;
322
+ case 1:
323
+ const t = this._pointers[0], e = this._pointerPositions[t];
324
+ this._onTouchStart({ pointerId: t, pageX: e.x, pageY: e.y });
325
+ break;
326
+ }
327
+ }
328
+ function G(o) {
329
+ let t;
330
+ switch (o.button) {
331
+ case 0:
332
+ t = this.mouseButtons.LEFT;
333
+ break;
334
+ case 1:
335
+ t = this.mouseButtons.MIDDLE;
336
+ break;
337
+ case 2:
338
+ t = this.mouseButtons.RIGHT;
339
+ break;
340
+ default:
341
+ t = -1;
342
+ }
343
+ switch (t) {
344
+ case b.DOLLY:
345
+ if (this.enableZoom === !1) return;
346
+ this._handleMouseDownDolly(o), this.state = l.DOLLY;
347
+ break;
348
+ case b.ROTATE:
349
+ if (o.ctrlKey || o.metaKey || o.shiftKey) {
350
+ if (this.enablePan === !1) return;
351
+ this._handleMouseDownPan(o), this.state = l.PAN;
352
+ } else {
353
+ if (this.enableRotate === !1) return;
354
+ this._handleMouseDownRotate(o), this.state = l.ROTATE;
355
+ }
356
+ break;
357
+ case b.PAN:
358
+ if (o.ctrlKey || o.metaKey || o.shiftKey) {
359
+ if (this.enableRotate === !1) return;
360
+ this._handleMouseDownRotate(o), this.state = l.ROTATE;
361
+ } else {
362
+ if (this.enablePan === !1) return;
363
+ this._handleMouseDownPan(o), this.state = l.PAN;
364
+ }
365
+ break;
366
+ default:
367
+ this.state = l.NONE;
368
+ }
369
+ this.state !== l.NONE && this.dispatchEvent(A);
370
+ }
371
+ function K(o) {
372
+ switch (this.state) {
373
+ case l.ROTATE:
374
+ if (this.enableRotate === !1) return;
375
+ this._handleMouseMoveRotate(o);
376
+ break;
377
+ case l.DOLLY:
378
+ if (this.enableZoom === !1) return;
379
+ this._handleMouseMoveDolly(o);
380
+ break;
381
+ case l.PAN:
382
+ if (this.enablePan === !1) return;
383
+ this._handleMouseMovePan(o);
384
+ break;
385
+ }
386
+ }
387
+ function W(o) {
388
+ this.enabled === !1 || this.enableZoom === !1 || this.state !== l.NONE || (o.preventDefault(), this.dispatchEvent(A), this._handleMouseWheel(this._customWheelEvent(o)), this.dispatchEvent(R));
389
+ }
390
+ function Z(o) {
391
+ this.enabled !== !1 && this._handleKeyDown(o);
392
+ }
393
+ function B(o) {
394
+ switch (this._trackPointer(o), this._pointers.length) {
395
+ case 1:
396
+ switch (this.touches.ONE) {
397
+ case y.ROTATE:
398
+ if (this.enableRotate === !1) return;
399
+ this._handleTouchStartRotate(o), this.state = l.TOUCH_ROTATE;
400
+ break;
401
+ case y.PAN:
402
+ if (this.enablePan === !1) return;
403
+ this._handleTouchStartPan(o), this.state = l.TOUCH_PAN;
404
+ break;
405
+ default:
406
+ this.state = l.NONE;
407
+ }
408
+ break;
409
+ case 2:
410
+ switch (this.touches.TWO) {
411
+ case y.DOLLY_PAN:
412
+ if (this.enableZoom === !1 && this.enablePan === !1) return;
413
+ this._handleTouchStartDollyPan(o), this.state = l.TOUCH_DOLLY_PAN;
414
+ break;
415
+ case y.DOLLY_ROTATE:
416
+ if (this.enableZoom === !1 && this.enableRotate === !1) return;
417
+ this._handleTouchStartDollyRotate(o), this.state = l.TOUCH_DOLLY_ROTATE;
418
+ break;
419
+ default:
420
+ this.state = l.NONE;
421
+ }
422
+ break;
423
+ default:
424
+ this.state = l.NONE;
425
+ }
426
+ this.state !== l.NONE && this.dispatchEvent(A);
427
+ }
428
+ function Q(o) {
429
+ switch (this._trackPointer(o), this.state) {
430
+ case l.TOUCH_ROTATE:
431
+ if (this.enableRotate === !1) return;
432
+ this._handleTouchMoveRotate(o), this.update();
433
+ break;
434
+ case l.TOUCH_PAN:
435
+ if (this.enablePan === !1) return;
436
+ this._handleTouchMovePan(o), this.update();
437
+ break;
438
+ case l.TOUCH_DOLLY_PAN:
439
+ if (this.enableZoom === !1 && this.enablePan === !1) return;
440
+ this._handleTouchMoveDollyPan(o), this.update();
441
+ break;
442
+ case l.TOUCH_DOLLY_ROTATE:
443
+ if (this.enableZoom === !1 && this.enableRotate === !1) return;
444
+ this._handleTouchMoveDollyRotate(o), this.update();
445
+ break;
446
+ default:
447
+ this.state = l.NONE;
448
+ }
449
+ }
450
+ function X(o) {
451
+ this.enabled !== !1 && o.preventDefault();
452
+ }
453
+ function V(o) {
454
+ o.key === "Control" && (this._controlActive = !0, this.domElement.getRootNode().addEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
455
+ }
456
+ function q(o) {
457
+ o.key === "Control" && (this._controlActive = !1, this.domElement.getRootNode().removeEventListener("keyup", this._interceptControlUp, { passive: !0, capture: !0 }));
458
+ }
459
+ class $ {
6
460
  loader;
7
461
  constructor() {
8
- this.loader = new f();
462
+ this.loader = new k();
9
463
  }
10
464
  /**
11
465
  * 加载数字人
@@ -18,16 +472,16 @@ class M {
18
472
  const e = await fetch(t);
19
473
  if (!e.ok)
20
474
  throw new Error(`Failed to load config: ${e.statusText}`);
21
- const o = await e.json(), n = t.substring(0, t.lastIndexOf("/") + 1) + o.modelSrc;
22
- console.log(`[Flow] Config loaded. Loading model from: ${n}`);
23
- let r, s = [];
475
+ const i = await e.json(), a = t.substring(0, t.lastIndexOf("/") + 1) + i.modelSrc;
476
+ console.log(`[Flow] Config loaded. Loading model from: ${a}`);
477
+ let r, h = [];
24
478
  try {
25
- const l = await this.loader.loadAsync(n);
26
- r = l.scene, s = l.animations || [];
27
- } catch (l) {
28
- console.warn(`[Flow] Failed to load 3D model at ${n}. Using fallback placeholder.`, l), r = this.createFallbackAvatar();
479
+ const c = await this.loader.loadAsync(a);
480
+ r = c.scene, h = c.animations || [];
481
+ } catch (c) {
482
+ console.warn(`[Flow] Failed to load 3D model at ${a}. Using fallback placeholder.`, c), r = this.createFallbackAvatar();
29
483
  }
30
- return this.applyConfig(r, o), { model: r, config: o, animations: s };
484
+ return this.applyConfig(r, i), { model: r, config: i, animations: h };
31
485
  } catch (e) {
32
486
  throw console.error("[Flow] Error loading avatar:", e), e;
33
487
  }
@@ -36,8 +490,8 @@ class M {
36
490
  * 应用配置到模型
37
491
  */
38
492
  applyConfig(t, e) {
39
- e.scale && t.scale.setScalar(e.scale), e.initialPosition && t.position.set(...e.initialPosition), t.traverse((o) => {
40
- o.isMesh && (o.castShadow = !0, o.receiveShadow = !0);
493
+ e.scale && t.scale.setScalar(e.scale), e.initialPosition && t.position.set(...e.initialPosition), t.traverse((i) => {
494
+ i.isMesh && (i.castShadow = !0, i.receiveShadow = !0);
41
495
  });
42
496
  }
43
497
  /**
@@ -45,67 +499,67 @@ class M {
45
499
  * 生成一个简单的机器人形状
46
500
  */
47
501
  createFallbackAvatar() {
48
- const t = new i.Group(), e = new i.MeshStandardMaterial({
502
+ const t = new n.Group(), e = new n.MeshStandardMaterial({
49
503
  color: 54015,
50
504
  roughness: 0.3,
51
505
  metalness: 0.8
52
- }), o = new i.BoxGeometry(0.8, 0.9, 0.8), a = new i.Mesh(o, e);
53
- a.position.y = 1.5, a.name = "Head", t.add(a);
54
- const n = new i.SphereGeometry(0.1), r = new i.MeshBasicMaterial({ color: 16777215 }), s = new i.Mesh(n, r);
55
- s.position.set(-0.2, 1.5, 0.4), t.add(s);
56
- const l = new i.Mesh(n, r);
57
- l.position.set(0.2, 1.5, 0.4), t.add(l);
58
- const d = new i.CylinderGeometry(0.6, 0.4, 1.5, 8), c = new i.Mesh(d, e);
59
- c.position.y = 0.5, c.name = "Body", t.add(c);
60
- const h = new i.CapsuleGeometry(0.15, 1), p = new i.Mesh(h, e);
61
- p.position.set(-0.9, 0.8, 0), p.rotation.z = Math.PI / 4, p.name = "LeftArm", t.add(p);
62
- const w = new i.Mesh(h, e);
63
- return w.position.set(0.9, 0.8, 0), w.rotation.z = -Math.PI / 4, w.name = "RightArm", t.add(w), t;
64
- }
65
- }
66
- class S {
506
+ }), i = new n.BoxGeometry(0.8, 0.9, 0.8), s = new n.Mesh(i, e);
507
+ s.position.y = 1.5, s.name = "Head", t.add(s);
508
+ const a = new n.SphereGeometry(0.1), r = new n.MeshBasicMaterial({ color: 16777215 }), h = new n.Mesh(a, r);
509
+ h.position.set(-0.2, 1.5, 0.4), t.add(h);
510
+ const c = new n.Mesh(a, r);
511
+ c.position.set(0.2, 1.5, 0.4), t.add(c);
512
+ const f = new n.CylinderGeometry(0.6, 0.4, 1.5, 8), g = new n.Mesh(f, e);
513
+ g.position.y = 0.5, g.name = "Body", t.add(g);
514
+ const w = new n.CapsuleGeometry(0.15, 1), P = new n.Mesh(w, e);
515
+ P.position.set(-0.9, 0.8, 0), P.rotation.z = Math.PI / 4, P.name = "LeftArm", t.add(P);
516
+ const M = new n.Mesh(w, e);
517
+ return M.position.set(0.9, 0.8, 0), M.rotation.z = -Math.PI / 4, M.name = "RightArm", t.add(M), t;
518
+ }
519
+ }
520
+ class J {
67
521
  loader;
68
522
  constructor() {
69
- this.loader = new f();
523
+ this.loader = new k();
70
524
  }
71
525
  async load(t) {
72
526
  try {
73
527
  const e = await fetch(t);
74
528
  if (!e.ok) throw new Error("Failed to load stage config");
75
- const o = await e.json();
76
- let a, n = [];
77
- if (o.modelSrc) {
78
- const s = t.substring(0, t.lastIndexOf("/") + 1) + o.modelSrc, l = await this.loader.loadAsync(s);
79
- a = l.scene, n = l.animations || [];
529
+ const i = await e.json();
530
+ let s, a = [];
531
+ if (i.modelSrc) {
532
+ const h = t.substring(0, t.lastIndexOf("/") + 1) + i.modelSrc, c = await this.loader.loadAsync(h);
533
+ s = c.scene, a = c.animations || [];
80
534
  } else
81
- a = this.createProceduralStage();
82
- return this.applyConfig(a, o), { model: a, config: o, animations: n };
535
+ s = this.createProceduralStage();
536
+ return this.applyConfig(s, i), { model: s, config: i, animations: a };
83
537
  } catch (e) {
84
538
  throw console.error("[Flow] Stage load error:", e), e;
85
539
  }
86
540
  }
87
541
  applyConfig(t, e) {
88
- e.scale && t.scale.setScalar(e.scale), e.position && t.position.set(...e.position), e.rotation && t.rotation.set(...e.rotation), t.traverse((o) => {
89
- o.isMesh && (o.receiveShadow = !0, o.castShadow = !0);
542
+ e.scale && t.scale.setScalar(e.scale), e.position && t.position.set(...e.position), e.rotation && t.rotation.set(...e.rotation), t.traverse((i) => {
543
+ i.isMesh && (i.receiveShadow = !0, i.castShadow = !0);
90
544
  });
91
545
  }
92
546
  /**
93
547
  * Generates a cool Sci-Fi Podium if no model is provided
94
548
  */
95
549
  createProceduralStage() {
96
- const t = new i.Group(), e = new i.CylinderGeometry(2, 2.2, 0.2, 32), o = new i.MeshStandardMaterial({ color: 2236962, roughness: 0.2, metalness: 0.8 }), a = new i.Mesh(e, o);
97
- a.position.y = -0.1, t.add(a);
98
- const n = new i.TorusGeometry(1.8, 0.05, 16, 100), r = new i.MeshBasicMaterial({ color: 54015 }), s = new i.Mesh(n, r);
99
- s.rotation.x = -Math.PI / 2, s.position.y = 0.01, t.add(s);
100
- const l = new i.BoxGeometry(0.5, 0.05, 0.5);
101
- for (let d = 0; d < 4; d++) {
102
- const c = new i.Mesh(l, o), h = d / 4 * Math.PI * 2;
103
- c.position.set(Math.cos(h) * 2.5, 0, Math.sin(h) * 2.5), c.lookAt(0, 0, 0), t.add(c);
550
+ const t = new n.Group(), e = new n.CylinderGeometry(2, 2.2, 0.2, 32), i = new n.MeshStandardMaterial({ color: 2236962, roughness: 0.2, metalness: 0.8 }), s = new n.Mesh(e, i);
551
+ s.position.y = -0.1, t.add(s);
552
+ const a = new n.TorusGeometry(1.8, 0.05, 16, 100), r = new n.MeshBasicMaterial({ color: 54015 }), h = new n.Mesh(a, r);
553
+ h.rotation.x = -Math.PI / 2, h.position.y = 0.01, t.add(h);
554
+ const c = new n.BoxGeometry(0.5, 0.05, 0.5);
555
+ for (let f = 0; f < 4; f++) {
556
+ const g = new n.Mesh(c, i), w = f / 4 * Math.PI * 2;
557
+ g.position.set(Math.cos(w) * 2.5, 0, Math.sin(w) * 2.5), g.lookAt(0, 0, 0), t.add(g);
104
558
  }
105
559
  return t;
106
560
  }
107
561
  }
108
- class u {
562
+ class O {
109
563
  mixer;
110
564
  clips;
111
565
  states = {};
@@ -113,14 +567,14 @@ class u {
113
567
  currentState = null;
114
568
  defaultState = "idle";
115
569
  constructor(t, e) {
116
- this.mixer = new i.AnimationMixer(t), this.clips = e, this.mixer.addEventListener("finished", this.onFinished.bind(this));
570
+ this.mixer = new n.AnimationMixer(t), this.clips = e, this.mixer.addEventListener("finished", this.onFinished.bind(this));
117
571
  }
118
572
  /**
119
573
  * Initialize with configuration
120
574
  */
121
575
  init(t) {
122
- this.defaultState = t.defaultState, this.states = t.states, Object.entries(this.states).forEach(([e, o]) => {
123
- this.findClip(o.clipName) || console.warn(`[AnimationController] Clip "${o.clipName}" for state "${e}" not found.`);
576
+ this.defaultState = t.defaultState, this.states = t.states, Object.entries(this.states).forEach(([e, i]) => {
577
+ this.findClip(i.clipName) || console.warn(`[AnimationController] Clip "${i.clipName}" for state "${e}" not found.`);
124
578
  }), this.play(this.defaultState);
125
579
  }
126
580
  /**
@@ -133,40 +587,173 @@ class u {
133
587
  * Play a state
134
588
  */
135
589
  play(t, e = !1) {
136
- const o = this.states[t];
137
- if (!o) {
590
+ const i = this.states[t];
591
+ if (!i) {
138
592
  console.warn(`[AnimationController] State "${t}" not defined.`);
139
593
  return;
140
594
  }
141
- const a = this.findClip(o.clipName);
142
- if (!a || this.currentState === t && !e) return;
143
- const n = this.mixer.clipAction(a);
144
- n.setLoop(o.loop ? i.LoopRepeat : i.LoopOnce, o.loop ? 1 / 0 : 1), n.clampWhenFinished = !o.loop, n.timeScale = o.timeScale ?? 1;
145
- const r = o.fadeDuration ?? 0.3;
595
+ const s = this.findClip(i.clipName);
596
+ if (!s || this.currentState === t && !e) return;
597
+ const a = this.mixer.clipAction(s);
598
+ a.setLoop(i.loop ? n.LoopRepeat : n.LoopOnce, i.loop ? 1 / 0 : 1), a.clampWhenFinished = !i.loop, a.timeScale = i.timeScale ?? 1;
599
+ const r = i.fadeDuration ?? 0.3;
146
600
  if (this.currentState) {
147
- const s = this.activeActions.get(this.currentState);
148
- s && s !== n ? (s.fadeOut(r), n.reset(), n.fadeIn(r), n.play()) : n.reset().play();
601
+ const h = this.activeActions.get(this.currentState);
602
+ h && h !== a ? (h.fadeOut(r), a.reset(), a.fadeIn(r), a.play()) : a.reset().play();
149
603
  } else
150
- n.reset().play();
151
- this.activeActions.set(t, n), this.currentState = t, console.log(`[Anim] Transition to: ${t} (Loop: ${o.loop})`);
604
+ a.reset().play();
605
+ this.activeActions.set(t, a), this.currentState = t, console.log(`[Anim] Transition to: ${t} (Loop: ${i.loop})`);
152
606
  }
153
607
  onFinished(t) {
154
608
  if (this.currentState && this.activeActions.get(this.currentState) === t.action) {
155
- const e = this.states[this.currentState], o = () => {
609
+ const e = this.states[this.currentState], i = () => {
156
610
  e && e.next ? this.play(e.next) : !e.loop && this.currentState !== this.defaultState && this.play(this.defaultState);
157
611
  };
158
- e.holdDuration && e.holdDuration > 0 ? setTimeout(o, e.holdDuration * 1e3) : o();
612
+ e.holdDuration && e.holdDuration > 0 ? setTimeout(i, e.holdDuration * 1e3) : i();
159
613
  }
160
614
  }
161
615
  /**
162
616
  * Finds an animation clip by name using exact, case-insensitive, or fuzzy matching.
163
617
  */
164
618
  findClip(t) {
165
- let e = this.clips.find((o) => o.name === t);
166
- return e || (e = this.clips.find((o) => o.name.toLowerCase() === t.toLowerCase())), e || (e = this.clips.find((o) => o.name.toLowerCase().includes(t.toLowerCase()))), e;
619
+ let e = this.clips.find((i) => i.name === t);
620
+ return e || (e = this.clips.find((i) => i.name.toLowerCase() === t.toLowerCase())), e || (e = this.clips.find((i) => i.name.toLowerCase().includes(t.toLowerCase()))), e;
167
621
  }
168
622
  }
169
- class L {
623
+ const u = {
624
+ IDLE: "IDLE",
625
+ TRACKING: "TRACKING",
626
+ HOLDING: "HOLDING"
627
+ }, tt = 5, et = 1.5, it = Number.EPSILON;
628
+ class st {
629
+ raycaster = new n.Raycaster();
630
+ mouse = new n.Vector2();
631
+ // State Machine
632
+ state = u.IDLE;
633
+ stateTimer = 0;
634
+ // Core Data
635
+ lookAtTarget = new n.Vector3();
636
+ // Desired World Target
637
+ currentLookAt = new n.Vector3();
638
+ // Smoothed World Target (For debug visualization)
639
+ activePlane = new n.Plane(new n.Vector3(0, 0, 1), -2.5);
640
+ planeCenter = new n.Vector3(0, 1.5, 2.5);
641
+ // Visual center of the plane
642
+ // Physics / Math Helpers
643
+ lookAtProxy = new n.Object3D();
644
+ // Reusable temporaries to reduce GC
645
+ _targetQuat = new n.Quaternion();
646
+ _dummyVec = new n.Vector3();
647
+ _offsetQuat = new n.Quaternion();
648
+ _parentWorldQuat = new n.Quaternion();
649
+ // V6 Architecture: Persistent State Tracker
650
+ outputQuaternion = null;
651
+ weight = 0;
652
+ // Legacy debug value
653
+ // Dependencies
654
+ container;
655
+ camera;
656
+ getHeadBone;
657
+ getConfig;
658
+ getModels;
659
+ // Bound event handlers
660
+ boundOnPointerDown;
661
+ boundOnPointerMove;
662
+ boundOnPointerUp;
663
+ constructor(t, e, i, s, a) {
664
+ this.container = t, this.camera = e, this.getHeadBone = i, this.getConfig = s, this.getModels = a, this.boundOnPointerDown = this.onPointerDown.bind(this), this.boundOnPointerMove = this.onPointerMove.bind(this), this.boundOnPointerUp = this.onPointerUp.bind(this), this.container.addEventListener("pointerdown", this.boundOnPointerDown), this.container.addEventListener("pointermove", this.boundOnPointerMove), window.addEventListener("pointerup", this.boundOnPointerUp);
665
+ }
666
+ update(t, e) {
667
+ const i = this.getHeadBone(), s = this.getConfig();
668
+ if (!i || !s || s.lookAt?.enabled === !1) return;
669
+ const a = i.quaternion.clone();
670
+ this.outputQuaternion || (this.outputQuaternion = a.clone()), this.updateState(t, s);
671
+ const r = this.state === u.TRACKING || this.state === u.HOLDING;
672
+ r ? (this.calculateLookAtRotation(i, s, this._targetQuat), this.weight = 1) : (this._targetQuat.copy(a), this.weight = 0);
673
+ const h = s.lookAt?.damping ?? tt, c = 1 - Math.exp(-h * e);
674
+ this.outputQuaternion.slerp(this._targetQuat, c), i.quaternion.copy(this.outputQuaternion), r && this.currentLookAt.lerp(this.lookAtTarget, c);
675
+ }
676
+ calculateLookAtRotation(t, e, i) {
677
+ const s = this._dummyVec;
678
+ t.getWorldPosition(s), this.lookAtProxy.position.copy(s), this.lookAtProxy.lookAt(this.lookAtTarget), this.lookAtProxy.updateMatrixWorld();
679
+ const a = e.lookAt?.rotationOffset || [0, 0, 0];
680
+ this._offsetQuat.setFromEuler(new n.Euler(...a));
681
+ const r = this.lookAtProxy.quaternion.multiply(this._offsetQuat), h = t.parent;
682
+ if (h) {
683
+ h.getWorldQuaternion(this._parentWorldQuat);
684
+ const c = this._parentWorldQuat.invert();
685
+ i.copy(c.multiply(r));
686
+ } else
687
+ i.copy(r);
688
+ }
689
+ updateState(t, e) {
690
+ const i = e.lookAt?.holdDuration ?? 2e3;
691
+ switch (this.state) {
692
+ case u.TRACKING:
693
+ this.calculateLookAtTarget();
694
+ break;
695
+ case u.HOLDING:
696
+ t - this.stateTimer > i && (this.state = u.IDLE, console.log("[Flow] LookAt: Holding finished, releasing to animation."));
697
+ break;
698
+ }
699
+ }
700
+ onPointerDown(t) {
701
+ this.updateMouse(t);
702
+ const e = this.getHeadBone();
703
+ if (e) {
704
+ const i = new n.Vector3();
705
+ e.getWorldPosition(i);
706
+ const s = this.camera.position.clone(), a = new n.Vector3().subVectors(s, i), r = new n.Vector3();
707
+ if (a.lengthSq() < 1e-6) {
708
+ const c = this.camera;
709
+ "getWorldDirection" in c && typeof c.getWorldDirection == "function" ? (c.getWorldDirection(r), r.negate()) : r.set(0, 0, 1);
710
+ } else
711
+ r.copy(a).normalize();
712
+ const h = r.clone().multiplyScalar(et);
713
+ this.planeCenter.copy(i).add(h), this.activePlane.setFromNormalAndCoplanarPoint(r, this.planeCenter);
714
+ }
715
+ this.state = u.TRACKING, this.calculateLookAtTarget(), this.outputQuaternion || this.currentLookAt.copy(this.lookAtTarget);
716
+ }
717
+ onPointerMove(t) {
718
+ this.state === u.TRACKING && this.updateMouse(t);
719
+ }
720
+ onPointerUp() {
721
+ this.state === u.TRACKING && (this.state = u.HOLDING, this.stateTimer = performance.now());
722
+ }
723
+ updateMouse(t) {
724
+ const e = this.container.getBoundingClientRect();
725
+ this.mouse.x = (t.clientX - e.left) / e.width * 2 - 1, this.mouse.y = -((t.clientY - e.top) / e.height) * 2 + 1;
726
+ }
727
+ calculateLookAtTarget() {
728
+ this.raycaster.setFromCamera(this.mouse, this.camera);
729
+ const t = this.getModels().filter((i) => !!i);
730
+ if (t.length > 0) {
731
+ const i = this.raycaster.intersectObjects(t, !0);
732
+ if (i.length > 0) {
733
+ this.lookAtTarget.copy(i[0].point);
734
+ return;
735
+ }
736
+ }
737
+ const e = this._dummyVec;
738
+ this.activePlane.normal.lengthSq() > it && this.raycaster.ray.intersectPlane(this.activePlane, e) && this.lookAtTarget.copy(e);
739
+ }
740
+ getDebugInfo() {
741
+ return {
742
+ isEngaged: this.state !== u.IDLE,
743
+ currentLookAt: this.currentLookAt,
744
+ activePlane: this.activePlane,
745
+ planeCenter: this.planeCenter,
746
+ weight: this.weight
747
+ };
748
+ }
749
+ interrupt() {
750
+ this.state = u.IDLE;
751
+ }
752
+ dispose() {
753
+ this.container.removeEventListener("pointerdown", this.boundOnPointerDown), this.container.removeEventListener("pointermove", this.boundOnPointerMove), window.removeEventListener("pointerup", this.boundOnPointerUp);
754
+ }
755
+ }
756
+ class rt {
170
757
  container;
171
758
  scene;
172
759
  camera;
@@ -177,77 +764,115 @@ class L {
177
764
  stageLoader;
178
765
  avatarModel = null;
179
766
  stageModel = null;
767
+ headBone = null;
180
768
  animController = null;
181
769
  stageAnimController = null;
770
+ // Components
771
+ lookAtProcessor;
772
+ currentAvatarConfig = null;
773
+ // Debug Helpers
774
+ isDebug = !1;
775
+ debugTargetMesh = null;
776
+ debugPlaneMesh = null;
182
777
  constructor(t) {
183
778
  const e = document.getElementById(t);
184
779
  if (!e) throw new Error(`Container #${t} not found`);
185
- this.container = e, this.clock = new i.Clock(), this.loader = new M(), this.stageLoader = new S(), this.scene = new i.Scene(), this.scene.background = new i.Color(1710618), this.scene.fog = new i.Fog(1710618, 10, 50), this.camera = new i.PerspectiveCamera(
780
+ this.container = e, this.clock = new n.Clock(), this.loader = new $(), this.stageLoader = new J(), this.scene = new n.Scene(), this.scene.background = new n.Color(1710618), this.scene.fog = new n.Fog(1710618, 10, 50), this.camera = new n.PerspectiveCamera(
186
781
  45,
187
782
  window.innerWidth / window.innerHeight,
188
783
  0.1,
189
784
  100
190
- ), this.camera.position.set(0, 1.5, 5), this.renderer = new g({ antialias: !0, alpha: !0 }), this.renderer.setSize(window.innerWidth, window.innerHeight), this.renderer.setPixelRatio(window.devicePixelRatio), this.container.appendChild(this.renderer.domElement), this.setupLights(), this.controls = new y(this.camera, this.renderer.domElement), this.controls.enableDamping = !0, this.controls.target.set(0, 1, 0), window.addEventListener("resize", this.onWindowResize.bind(this)), this.renderer.setAnimationLoop(this.animate.bind(this));
785
+ ), this.camera.position.set(0, 1.5, 5), this.renderer = new j({ antialias: !0, alpha: !0 }), this.renderer.setSize(window.innerWidth, window.innerHeight), this.renderer.setPixelRatio(window.devicePixelRatio), this.container.appendChild(this.renderer.domElement), this.setupLights(), this.controls = new U(this.camera, this.renderer.domElement), this.controls.enableDamping = !0, this.controls.target.set(0, 1, 0), this.lookAtProcessor = new st(
786
+ this.container,
787
+ this.camera,
788
+ () => this.headBone,
789
+ () => this.currentAvatarConfig,
790
+ () => {
791
+ const i = [];
792
+ return this.avatarModel && i.push(this.avatarModel), this.stageModel && i.push(this.stageModel), i;
793
+ }
794
+ ), window.addEventListener("resize", this.onWindowResize.bind(this)), this.renderer.setAnimationLoop(this.animate.bind(this));
191
795
  }
192
796
  setupLights() {
193
- const t = new i.AmbientLight(16777215, 0.6);
797
+ const t = new n.AmbientLight(16777215, 0.6);
194
798
  this.scene.add(t);
195
- const e = new i.DirectionalLight(16777215, 1);
799
+ const e = new n.DirectionalLight(16777215, 1);
196
800
  e.position.set(5, 10, 7), e.castShadow = !0, this.scene.add(e);
197
- const o = new i.SpotLight(54015, 5);
198
- o.position.set(-5, 5, -5), o.lookAt(0, 1, 0), this.scene.add(o);
801
+ const i = new n.SpotLight(54015, 5);
802
+ i.position.set(-5, 5, -5), i.lookAt(0, 1, 0), this.scene.add(i);
199
803
  }
200
804
  /**
201
805
  * Load an avatar by config URL
202
806
  */
203
807
  async loadAvatar(t) {
204
808
  this.avatarModel && this.scene.remove(this.avatarModel);
205
- const { model: e, config: o, animations: a } = await this.loader.load(t);
206
- if (this.avatarModel = e, this.scene.add(this.avatarModel), a.length > 0) {
207
- this.animController = new u(this.avatarModel, a);
208
- const n = o.animations || {
809
+ const { model: e, config: i, animations: s } = await this.loader.load(t);
810
+ this.avatarModel = e, this.currentAvatarConfig = i, this.scene.add(this.avatarModel);
811
+ const a = i.lookAt?.headBoneName || "Head";
812
+ if (this.headBone = this.avatarModel.getObjectByName(a) || null, this.headBone || this.avatarModel.traverse((r) => {
813
+ !this.headBone && r.name.toLowerCase().includes("head") && (this.headBone = r);
814
+ }), s.length > 0) {
815
+ this.animController = new O(this.avatarModel, s);
816
+ const r = i.animations || {
209
817
  defaultState: "idle",
210
818
  states: {
211
819
  idle: { clipName: "Idle", loop: !0 },
820
+ walk: { clipName: "Walking", loop: !0 },
212
821
  wave: { clipName: "Wave", loop: !1, next: "idle" },
213
822
  dance: { clipName: "Dance", loop: !1, next: "idle" },
214
- bow: { clipName: "Bow", loop: !1, next: "idle" },
215
- walk: { clipName: "Walking", loop: !0 }
823
+ bow: { clipName: "Bow", loop: !1, next: "idle" }
216
824
  }
217
825
  };
218
- this.animController.init(n);
826
+ this.animController.init(r);
219
827
  }
220
- console.log(`[Flow] Avatar "${o.name}" loaded successfully.`);
828
+ console.log(`[Flow] Avatar "${i.name}" loaded.`);
221
829
  }
222
830
  /**
223
831
  * Load a stage (podium/scene) by config URL
224
832
  */
225
833
  async loadStage(t) {
226
834
  this.stageModel && this.scene.remove(this.stageModel);
227
- const { model: e, config: o, animations: a } = await this.stageLoader.load(t);
228
- this.stageModel = e, this.scene.add(this.stageModel), a.length > 0 && o.animations && (this.stageAnimController = new u(this.stageModel, a), this.stageAnimController.init(o.animations)), console.log(`[Flow] Stage "${o.name}" loaded successfully.`);
835
+ const { model: e, config: i, animations: s } = await this.stageLoader.load(t);
836
+ this.stageModel = e, this.scene.add(this.stageModel), s.length > 0 && i.animations && (this.stageAnimController = new O(this.stageModel, s), this.stageAnimController.init(i.animations));
837
+ }
838
+ setDebug(t) {
839
+ this.isDebug = t, t ? this.createDebugHelpers() : this.removeDebugHelpers();
840
+ }
841
+ createDebugHelpers() {
842
+ if (this.debugTargetMesh || (this.debugTargetMesh = new n.Mesh(
843
+ new n.SphereGeometry(0.1, 8, 8),
844
+ new n.MeshBasicMaterial({ color: 16711680, wireframe: !0, depthTest: !1 })
845
+ ), this.debugTargetMesh.renderOrder = 999, this.scene.add(this.debugTargetMesh)), !this.debugPlaneMesh) {
846
+ const t = new n.GridHelper(5, 10, 65280, 34816);
847
+ t.material.transparent = !0, t.material.opacity = 0.5, t.rotateX(Math.PI / 2), this.debugPlaneMesh = t, this.scene.add(this.debugPlaneMesh);
848
+ }
849
+ }
850
+ updateDebugHelpers() {
851
+ if (!this.isDebug || !this.lookAtProcessor) return;
852
+ const t = this.lookAtProcessor.getDebugInfo(), e = !!(t.planeCenter && t.activePlane);
853
+ if (this.debugTargetMesh && (this.debugTargetMesh.position.copy(t.currentLookAt), this.debugTargetMesh.visible = t.isEngaged), this.debugPlaneMesh && (this.debugPlaneMesh.visible = e, e)) {
854
+ this.debugPlaneMesh.position.copy(t.planeCenter);
855
+ const i = t.activePlane.normal, s = this.debugPlaneMesh.position.clone().add(i);
856
+ this.debugPlaneMesh.lookAt(s), this.debugPlaneMesh.rotateX(Math.PI / 2);
857
+ }
858
+ }
859
+ removeDebugHelpers() {
860
+ this.debugTargetMesh && (this.scene.remove(this.debugTargetMesh), this.debugTargetMesh = null), this.debugPlaneMesh && (this.scene.remove(this.debugPlaneMesh), this.debugPlaneMesh = null);
229
861
  }
230
862
  onWindowResize() {
231
863
  this.camera.aspect = window.innerWidth / window.innerHeight, this.camera.updateProjectionMatrix(), this.renderer.setSize(window.innerWidth, window.innerHeight);
232
864
  }
233
- // State
234
865
  isAutoRotate = !1;
235
- /**
236
- * Play a specific action
237
- */
238
866
  playAction(t) {
239
- if (console.log(`[FlowEngine] Playing action: ${t}`), this.animController) {
240
- this.animController.play(t.toLowerCase());
241
- return;
242
- }
867
+ this.lookAtProcessor.interrupt(), this.animController && this.animController.play(t.toLowerCase());
243
868
  }
244
869
  animate(t) {
245
870
  const e = this.clock.getDelta();
246
- this.avatarModel && this.animController && this.animController.update(e), this.stageModel && this.stageAnimController && this.stageAnimController.update(e), this.controls.autoRotate = this.isAutoRotate, this.controls.update(), this.renderer.render(this.scene, this.camera);
871
+ this.avatarModel && (this.animController && this.animController.update(e), this.lookAtProcessor.update(t, e)), this.updateDebugHelpers(), this.stageModel && this.stageAnimController && this.stageAnimController.update(e), this.controls.autoRotate = this.isAutoRotate, this.controls.update(), this.renderer.render(this.scene, this.camera);
247
872
  }
248
873
  }
249
874
  export {
250
- u as AnimationController,
251
- M as AvatarLoader,
252
- L as FlowEngine
875
+ O as AnimationController,
876
+ $ as AvatarLoader,
877
+ rt as FlowEngine
253
878
  };