@needle-tools/engine 5.1.0-experimental.1 → 5.1.0-experimental.3
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/{needle-engine.bundle-JZXX6OjM.js → needle-engine.bundle-Cp6RtfsD.js} +643 -625
- package/dist/{needle-engine.bundle-CaHKqc30.umd.cjs → needle-engine.bundle-DQE5rl-V.umd.cjs} +85 -85
- package/dist/{needle-engine.bundle-BiCxyTBE.min.js → needle-engine.bundle-EFFJgRPu.min.js} +88 -88
- package/dist/needle-engine.d.ts +22 -22
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/three.js +1 -1
- package/dist/three.min.js +18 -18
- package/dist/three.umd.cjs +29 -29
- package/lib/engine/engine_context.js +2 -2
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_serialization_builtin_serializer.js +21 -3
- package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
- package/lib/engine/js-extensions/RGBAColor.js +2 -2
- package/lib/engine/js-extensions/RGBAColor.js.map +1 -1
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +12 -8
- package/lib/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/engine_context.ts +2 -2
- package/src/engine/engine_serialization_builtin_serializer.ts +17 -3
- package/src/engine/js-extensions/RGBAColor.ts +6 -2
- package/src/engine/physics/workers/mesh-bvh/GenerateMeshBVHWorker.js +11 -8
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +1 -1
- package/dist/generateMeshBVH.worker-DT9A2Hrc.js +0 -1
|
@@ -3,7 +3,7 @@ import 'three/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js';
|
|
|
3
3
|
import type { EffectComposer } from "postprocessing";
|
|
4
4
|
import {
|
|
5
5
|
BufferGeometry, Camera, Color, DepthTexture, Group,
|
|
6
|
-
Material, NearestFilter, NoToneMapping, Object3D, OrthographicCamera,
|
|
6
|
+
Material, NearestFilter, NoToneMapping, Object3D, OrthographicCamera, PCFShadowMap,
|
|
7
7
|
PerspectiveCamera, RGBAFormat, Scene, SRGBColorSpace,
|
|
8
8
|
Texture, WebGLRenderer, type WebGLRendererParameters, WebGLRenderTarget, type WebXRArrayCamera
|
|
9
9
|
} from 'three';
|
|
@@ -632,7 +632,7 @@ export class Context implements IContext {
|
|
|
632
632
|
// // @ts-ignore
|
|
633
633
|
// this.renderer.alpha = false;
|
|
634
634
|
this.renderer.shadowMap.enabled = true;
|
|
635
|
-
this.renderer.shadowMap.type =
|
|
635
|
+
this.renderer.shadowMap.type = PCFShadowMap;
|
|
636
636
|
this.renderer.setSize(this.domWidth, this.domHeight);
|
|
637
637
|
this.renderer.outputColorSpace = SRGBColorSpace;
|
|
638
638
|
|
|
@@ -36,13 +36,27 @@ class ColorSerializer extends TypeSerializer {
|
|
|
36
36
|
}
|
|
37
37
|
onDeserialize(data: any): Color | RGBAColor | void {
|
|
38
38
|
if (data === undefined || data === null) return;
|
|
39
|
+
// Sanitize: Unity serialization can produce "Infinity" strings or non-finite values.
|
|
40
|
+
// Clamp to large/small finite values to preserve the intent (e.g. HDR emissive).
|
|
41
|
+
const sanitize = (v: any, fallback: number) => {
|
|
42
|
+
if (typeof v !== "number") v = parseFloat(v);
|
|
43
|
+
if (Number.isNaN(v)) return fallback;
|
|
44
|
+
if (v === Infinity) return 1e6;
|
|
45
|
+
if (v === -Infinity) return -1e6;
|
|
46
|
+
return v;
|
|
47
|
+
};
|
|
48
|
+
const r = sanitize(data.r, 0);
|
|
49
|
+
const g = sanitize(data.g, 0);
|
|
50
|
+
const b = sanitize(data.b, 0);
|
|
39
51
|
if (data.a !== undefined) {
|
|
40
|
-
|
|
52
|
+
const a = sanitize(data.a, 1);
|
|
53
|
+
return new RGBAColor(r, g, b, a);
|
|
41
54
|
}
|
|
42
55
|
else if (data.alpha !== undefined) {
|
|
43
|
-
|
|
56
|
+
const a = sanitize(data.alpha, 1);
|
|
57
|
+
return new RGBAColor(r, g, b, a);
|
|
44
58
|
}
|
|
45
|
-
return new Color(
|
|
59
|
+
return new Color(r, g, b);
|
|
46
60
|
}
|
|
47
61
|
onSerialize(data: any): any | void {
|
|
48
62
|
if (data === undefined || data === null) return;
|
|
@@ -25,8 +25,12 @@ export class RGBAColor extends Color {
|
|
|
25
25
|
super();
|
|
26
26
|
|
|
27
27
|
if (typeof r === "number" && typeof g === "number" && typeof b === "number") {
|
|
28
|
-
this.
|
|
29
|
-
|
|
28
|
+
this.setRGB(
|
|
29
|
+
Number.isFinite(r) ? r : 0,
|
|
30
|
+
Number.isFinite(g) ? g : 0,
|
|
31
|
+
Number.isFinite(b) ? b : 0
|
|
32
|
+
);
|
|
33
|
+
this.alpha = typeof a === "number" && Number.isFinite(a) ? a : 1;
|
|
30
34
|
} else if (r !== undefined) {
|
|
31
35
|
this.set(r as ColorRepresentation);
|
|
32
36
|
this.alpha = 1;
|
|
@@ -7,15 +7,18 @@ import { WorkerBase } from "three-mesh-bvh/src/workers/utils/WorkerBase.js";
|
|
|
7
7
|
export class GenerateMeshBVHWorker extends WorkerBase {
|
|
8
8
|
|
|
9
9
|
constructor() {
|
|
10
|
-
// Worker loading:
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// The `new URL()` pattern works in Vite 8+ thanks to PR #21434 which correctly rebases
|
|
15
|
-
// relative URL paths inside pre-bundled dependencies. This lets us keep three-mesh-bvh
|
|
16
|
-
// in optimizeDeps (no exclude needed), avoiding duplicate three.js instances.
|
|
10
|
+
// Worker loading: resolve the worker URL via import.meta.resolve so that bare
|
|
11
|
+
// specifiers like 'three-mesh-bvh/...' are correctly resolved through the module
|
|
12
|
+
// system (node_modules) rather than relative to this file's location.
|
|
13
|
+
// Falls back to new URL() + import.meta.url for environments without import.meta.resolve.
|
|
17
14
|
// https://linear.app/needle/issue/NE-6572
|
|
18
|
-
|
|
15
|
+
let workerUrl;
|
|
16
|
+
try {
|
|
17
|
+
workerUrl = import.meta.resolve('three-mesh-bvh/src/workers/generateMeshBVH.worker.js');
|
|
18
|
+
} catch {
|
|
19
|
+
workerUrl = new URL('three-mesh-bvh/src/workers/generateMeshBVH.worker.js', import.meta.url);
|
|
20
|
+
}
|
|
21
|
+
super(new Worker(workerUrl, { type: 'module' }));
|
|
19
22
|
this.name = 'GenerateMeshBVHWorker';
|
|
20
23
|
|
|
21
24
|
}
|
|
@@ -422,7 +422,7 @@ export class PostProcessingHandler {
|
|
|
422
422
|
depthBuffer: inputBuffer.depthBuffer,
|
|
423
423
|
depthTexture: inputBuffer.depthTexture
|
|
424
424
|
? new DepthTexture(inputBuffer.width, inputBuffer.height)
|
|
425
|
-
:
|
|
425
|
+
: null,
|
|
426
426
|
stencilBuffer: inputBuffer.stencilBuffer,
|
|
427
427
|
samples: Math.max(0, this._multisampling),
|
|
428
428
|
minFilter: inputBuffer.texture.minFilter ?? LinearFilter,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(){"use strict";const Wt="183.2";function Ls(f){for(let t=f.length-1;t>=0;--t)if(f[t]>=65535)return!0;return!1}function es(f){return document.createElementNS("http://www.w3.org/1999/xhtml",f)}function is(f){const t=f[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=f[1];e&&e.isStackTrace?f[0]+=" "+e.getLocation():f[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return f}function ut(...f){f=is(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...f)}}function Rt(...f){f=is(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...f)}}class ri{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const s=i[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const Z=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];function Pe(){const f=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Z[f&255]+Z[f>>8&255]+Z[f>>16&255]+Z[f>>24&255]+"-"+Z[t&255]+Z[t>>8&255]+"-"+Z[t>>16&15|64]+Z[t>>24&255]+"-"+Z[e&63|128]+Z[e>>8&255]+"-"+Z[e>>16&255]+Z[e>>24&255]+Z[i&255]+Z[i>>8&255]+Z[i>>16&255]+Z[i>>24&255]).toLowerCase()}function R(f,t,e){return Math.max(t,Math.min(e,f))}function fe(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return f/4294967295;case Uint16Array:return f/65535;case Uint8Array:return f/255;case Int32Array:return Math.max(f/2147483647,-1);case Int16Array:return Math.max(f/32767,-1);case Int8Array:return Math.max(f/127,-1);default:throw new Error("Invalid component type.")}}function j(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return Math.round(f*4294967295);case Uint16Array:return Math.round(f*65535);case Uint8Array:return Math.round(f*255);case Int32Array:return Math.round(f*2147483647);case Int16Array:return Math.round(f*32767);case Int8Array:return Math.round(f*127);default:throw new Error("Invalid component type.")}}class Y{constructor(t=0,e=0){Y.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=R(this.x,t.x,e.x),this.y=R(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=R(this.x,t,e),this.y=R(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(R(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(R(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class de{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],c=i[s+1],h=i[s+2],u=i[s+3],l=n[r+0],d=n[r+1],y=n[r+2],m=n[r+3];if(u!==m||o!==l||c!==d||h!==y){let _=o*l+c*d+h*y+u*m;_<0&&(l=-l,d=-d,y=-y,m=-m,_=-_);let g=1-a;if(_<.9995){const p=Math.acos(_),x=Math.sin(p);g=Math.sin(g*p)/x,a=Math.sin(a*p)/x,o=o*g+l*a,c=c*g+d*a,h=h*g+y*a,u=u*g+m*a}else{o=o*g+l*a,c=c*g+d*a,h=h*g+y*a,u=u*g+m*a;const p=1/Math.sqrt(o*o+c*c+h*h+u*u);o*=p,c*=p,h*=p,u*=p}}t[e]=o,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],c=i[s+2],h=i[s+3],u=n[r],l=n[r+1],d=n[r+2],y=n[r+3];return t[e]=a*y+h*u+o*d-c*l,t[e+1]=o*y+h*l+c*u-a*d,t[e+2]=c*y+h*d+a*l-o*u,t[e+3]=h*y-a*u-o*l-c*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(i/2),h=a(s/2),u=a(n/2),l=o(i/2),d=o(s/2),y=o(n/2);switch(r){case"XYZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"YXZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"ZXY":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"ZYX":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"YZX":this._x=l*h*u+c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u-l*d*y;break;case"XZY":this._x=l*h*u-c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u+l*d*y;break;default:ut("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],c=e[2],h=e[6],u=e[10],l=i+a+u;if(l>0){const d=.5/Math.sqrt(l+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-s)*d}else if(i>a&&i>u){const d=2*Math.sqrt(1+i-a-u);this._w=(h-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+c)/d}else if(a>u){const d=2*Math.sqrt(1+a-i-u);this._w=(n-c)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+u-i-a);this._w=(r-s)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(R(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,c=e._z,h=e._w;return this._x=i*h+r*a+s*c-n*o,this._y=s*h+r*o+n*a-i*c,this._z=n*h+r*c+i*o-s*a,this._w=r*h-i*a-s*o-n*c,this._onChangeCallback(),this}slerp(t,e){let i=t._x,s=t._y,n=t._z,r=t._w,a=this.dot(t);a<0&&(i=-i,s=-s,n=-n,r=-r,a=-a);let o=1-e;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);o=Math.sin(o*c)/h,e=Math.sin(e*c)/h,this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this._onChangeCallback()}else this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class M{constructor(t=0,e=0,i=0){M.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(ss.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(ss.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*s-a*i),h=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*c+r*u-a*h,this.y=i+o*h+a*c-n*u,this.z=s+o*u+n*h-r*c,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=R(this.x,t.x,e.x),this.y=R(this.y,t.y,e.y),this.z=R(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=R(this.x,t,e),this.y=R(this.y,t,e),this.z=R(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(R(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return oi.copy(this).projectOnVector(t),this.sub(oi)}reflect(t){return this.sub(oi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(R(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const oi=new M,ss=new de;class Vt{constructor(t,e,i,s,n,r,a,o,c){Vt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c)}set(t,e,i,s,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],c=i[1],h=i[4],u=i[7],l=i[2],d=i[5],y=i[8],m=s[0],_=s[3],g=s[6],p=s[1],x=s[4],b=s[7],w=s[2],S=s[5],z=s[8];return n[0]=r*m+a*p+o*w,n[3]=r*_+a*x+o*S,n[6]=r*g+a*b+o*z,n[1]=c*m+h*p+u*w,n[4]=c*_+h*x+u*S,n[7]=c*g+h*b+u*z,n[2]=l*m+d*p+y*w,n[5]=l*_+d*x+y*S,n[8]=l*g+d*b+y*z,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return e*r*h-e*a*c-i*n*h+i*a*o+s*n*c-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=h*r-a*c,l=a*o-h*n,d=c*n-r*o,y=e*u+i*l+s*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/y;return t[0]=u*m,t[1]=(s*c-h*i)*m,t[2]=(a*i-s*r)*m,t[3]=l*m,t[4]=(h*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=d*m,t[7]=(i*o-c*e)*m,t[8]=(r*e-i*n)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(i*o,i*c,-i*(o*r+c*a)+r+t,-s*c,s*o,-s*(-c*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(ai.makeScale(t,e)),this}rotate(t){return this.premultiply(ai.makeRotation(-t)),this}translate(t,e){return this.premultiply(ai.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const ai=new Vt;function ci(f){return f<.04045?f*.0773993808:Math.pow(f*.9478672986+.0521327014,2.4)}let Xt;class qs{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Xt===void 0&&(Xt=es("canvas")),Xt.width=t.width,Xt.height=t.height;const s=Xt.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Xt}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=es("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=ci(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(ci(e[i]/255)*255):e[i]=ci(e[i]);return{data:e,width:t.width,height:t.height}}else return ut("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Os=0;class vs{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Os++}),this.uuid=Pe(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayHeight,e.displayWidth,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(hi(s[r].image)):n.push(hi(s[r]))}else n=hi(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function hi(f){return typeof HTMLImageElement<"u"&&f instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&f instanceof ImageBitmap?qs.getDataURL(f):f.data?{data:Array.from(f.data),width:f.width,height:f.height,type:f.data.constructor.name}:(ut("Texture: Unable to serialize Texture."),{})}let Ws=0;const li=new M;class Ut extends ri{constructor(t=Ut.DEFAULT_IMAGE,e=Ut.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,c=Ut.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Ws++}),this.uuid=Pe(),this.name="",this.source=new vs(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Y(0,0),this.repeat=new Y(1,1),this.center=new Y(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Vt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(li).x}get height(){return this.source.getSize(li).y}get depth(){return this.source.getSize(li).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){ut(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const s=this[e];if(s===void 0){ut(`Texture.setValues(): property '${e}' does not exist.`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Ut.DEFAULT_IMAGE=null,Ut.DEFAULT_MAPPING=300,Ut.DEFAULT_ANISOTROPY=4;class ye{constructor(t=0,e=0,i=0,s=1){ye.prototype.isVector4=!0,this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const o=t.elements,c=o[0],h=o[4],u=o[8],l=o[1],d=o[5],y=o[9],m=o[2],_=o[6],g=o[10];if(Math.abs(h-l)<.01&&Math.abs(u-m)<.01&&Math.abs(y-_)<.01){if(Math.abs(h+l)<.1&&Math.abs(u+m)<.1&&Math.abs(y+_)<.1&&Math.abs(c+d+g-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,b=(d+1)/2,w=(g+1)/2,S=(h+l)/4,z=(u+m)/4,A=(y+_)/4;return x>b&&x>w?x<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(x),s=S/i,n=z/i):b>w?b<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(b),i=S/s,n=A/s):w<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(w),i=z/n,s=A/n),this.set(i,s,n,e),this}let p=Math.sqrt((_-y)*(_-y)+(u-m)*(u-m)+(l-h)*(l-h));return Math.abs(p)<.001&&(p=1),this.x=(_-y)/p,this.y=(u-m)/p,this.z=(l-h)/p,this.w=Math.acos((c+d+g-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=R(this.x,t.x,e.x),this.y=R(this.y,t.y,e.y),this.z=R(this.z,t.z,e.z),this.w=R(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=R(this.x,t,e),this.y=R(this.y,t,e),this.z=R(this.z,t,e),this.w=R(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(R(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class O{constructor(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,_){O.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,_)}set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,_){const g=this.elements;return g[0]=t,g[4]=e,g[8]=i,g[12]=s,g[1]=n,g[5]=r,g[9]=a,g[13]=o,g[2]=c,g[6]=h,g[10]=u,g[14]=l,g[3]=d,g[7]=y,g[11]=m,g[15]=_,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new O().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return this.determinant()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinant()===0)return this.identity();const e=this.elements,i=t.elements,s=1/Yt.setFromMatrixColumn(t,0).length(),n=1/Yt.setFromMatrixColumn(t,1).length(),r=1/Yt.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),c=Math.sin(s),h=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=-o*u,e[8]=c,e[1]=d+y*c,e[5]=l-m*c,e[9]=-a*o,e[2]=m-l*c,e[6]=y+d*c,e[10]=r*o}else if(t.order==="YXZ"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l+m*a,e[4]=y*a-d,e[8]=r*c,e[1]=r*u,e[5]=r*h,e[9]=-a,e[2]=d*a-y,e[6]=m+l*a,e[10]=r*o}else if(t.order==="ZXY"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l-m*a,e[4]=-r*u,e[8]=y+d*a,e[1]=d+y*a,e[5]=r*h,e[9]=m-l*a,e[2]=-r*c,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=y*c-d,e[8]=l*c+m,e[1]=o*u,e[5]=m*c+l,e[9]=d*c-y,e[2]=-c,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=m-l*u,e[8]=y*u+d,e[1]=u,e[5]=r*h,e[9]=-a*h,e[2]=-c*h,e[6]=d*u+y,e[10]=l-m*u}else if(t.order==="XZY"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=-u,e[8]=c*h,e[1]=l*u+m,e[5]=r*h,e[9]=d*u-y,e[2]=y*u-d,e[6]=a*h,e[10]=m*u+l}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Xs,t,Ys)}lookAt(t,e,i){const s=this.elements;return K.subVectors(t,e),K.lengthSq()===0&&(K.z=1),K.normalize(),Mt.crossVectors(i,K),Mt.lengthSq()===0&&(Math.abs(i.z)===1?K.x+=1e-4:K.z+=1e-4,K.normalize(),Mt.crossVectors(i,K)),Mt.normalize(),Ce.crossVectors(K,Mt),s[0]=Mt.x,s[4]=Ce.x,s[8]=K.x,s[1]=Mt.y,s[5]=Ce.y,s[9]=K.y,s[2]=Mt.z,s[6]=Ce.z,s[10]=K.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],c=i[12],h=i[1],u=i[5],l=i[9],d=i[13],y=i[2],m=i[6],_=i[10],g=i[14],p=i[3],x=i[7],b=i[11],w=i[15],S=s[0],z=s[4],A=s[8],P=s[12],B=s[1],C=s[5],T=s[9],E=s[13],I=s[2],F=s[6],U=s[10],_t=s[14],Ot=s[3],vt=s[7],It=s[11],Ft=s[15];return n[0]=r*S+a*B+o*I+c*Ot,n[4]=r*z+a*C+o*F+c*vt,n[8]=r*A+a*T+o*U+c*It,n[12]=r*P+a*E+o*_t+c*Ft,n[1]=h*S+u*B+l*I+d*Ot,n[5]=h*z+u*C+l*F+d*vt,n[9]=h*A+u*T+l*U+d*It,n[13]=h*P+u*E+l*_t+d*Ft,n[2]=y*S+m*B+_*I+g*Ot,n[6]=y*z+m*C+_*F+g*vt,n[10]=y*A+m*T+_*U+g*It,n[14]=y*P+m*E+_*_t+g*Ft,n[3]=p*S+x*B+b*I+w*Ot,n[7]=p*z+x*C+b*F+w*vt,n[11]=p*A+x*T+b*U+w*It,n[15]=p*P+x*E+b*_t+w*Ft,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],u=t[6],l=t[10],d=t[14],y=t[3],m=t[7],_=t[11],g=t[15],p=o*d-c*l,x=a*d-c*u,b=a*l-o*u,w=r*d-c*h,S=r*l-o*h,z=r*u-a*h;return e*(m*p-_*x+g*b)-i*(y*p-_*w+g*S)+s*(y*x-m*w+g*z)-n*(y*b-m*S+_*z)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=t[9],l=t[10],d=t[11],y=t[12],m=t[13],_=t[14],g=t[15],p=e*a-i*r,x=e*o-s*r,b=e*c-n*r,w=i*o-s*a,S=i*c-n*a,z=s*c-n*o,A=h*m-u*y,P=h*_-l*y,B=h*g-d*y,C=u*_-l*m,T=u*g-d*m,E=l*g-d*_,I=p*E-x*T+b*C+w*B-S*P+z*A;if(I===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const F=1/I;return t[0]=(a*E-o*T+c*C)*F,t[1]=(s*T-i*E-n*C)*F,t[2]=(m*z-_*S+g*w)*F,t[3]=(l*S-u*z-d*w)*F,t[4]=(o*B-r*E-c*P)*F,t[5]=(e*E-s*B+n*P)*F,t[6]=(_*b-y*z-g*x)*F,t[7]=(h*z-l*b+d*x)*F,t[8]=(r*T-a*B+c*A)*F,t[9]=(i*B-e*T-n*A)*F,t[10]=(y*S-m*b+g*p)*F,t[11]=(u*b-h*S-d*p)*F,t[12]=(a*P-r*C-o*A)*F,t[13]=(e*C-i*P+s*A)*F,t[14]=(m*x-y*w-_*p)*F,t[15]=(h*w-u*x+l*p)*F,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+i,c*a-s*o,c*o+s*a,0,c*a+s*o,h*a+i,h*o-s*r,0,c*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,c=n+n,h=r+r,u=a+a,l=n*c,d=n*h,y=n*u,m=r*h,_=r*u,g=a*u,p=o*c,x=o*h,b=o*u,w=i.x,S=i.y,z=i.z;return s[0]=(1-(m+g))*w,s[1]=(d+b)*w,s[2]=(y-x)*w,s[3]=0,s[4]=(d-b)*S,s[5]=(1-(l+g))*S,s[6]=(_+p)*S,s[7]=0,s[8]=(y+x)*z,s[9]=(_-p)*z,s[10]=(1-(l+m))*z,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];const n=this.determinant();if(n===0)return i.set(1,1,1),e.identity(),this;let r=Yt.set(s[0],s[1],s[2]).length();const a=Yt.set(s[4],s[5],s[6]).length(),o=Yt.set(s[8],s[9],s[10]).length();n<0&&(r=-r),rt.copy(this);const c=1/r,h=1/a,u=1/o;return rt.elements[0]*=c,rt.elements[1]*=c,rt.elements[2]*=c,rt.elements[4]*=h,rt.elements[5]*=h,rt.elements[6]*=h,rt.elements[8]*=u,rt.elements[9]*=u,rt.elements[10]*=u,e.setFromRotationMatrix(rt),i.x=r,i.y=a,i.z=o,this}makePerspective(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2*n/(e-t),u=2*n/(i-s),l=(e+t)/(e-t),d=(i+s)/(i-s);let y,m;if(o)y=n/(r-n),m=r*n/(r-n);else if(a===2e3)y=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)y=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2/(e-t),u=2/(i-s),l=-(e+t)/(e-t),d=-(i+s)/(i-s);let y,m;if(o)y=1/(r-n),m=r/(r-n);else if(a===2e3)y=-2/(r-n),m=-(r+n)/(r-n);else if(a===2001)y=-1/(r-n),m=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=l,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const Yt=new M,rt=new O,Xs=new M(0,0,0),Ys=new M(1,1,1),Mt=new M,Ce=new M,K=new M,ns=new O,rs=new de;class Ee{constructor(t=0,e=0,i=0,s=Ee.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],c=s[5],h=s[9],u=s[2],l=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(R(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(l,c),this._z=0);break;case"YXZ":this._x=Math.asin(-R(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(R(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-R(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(l,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(R(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-R(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(l,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:ut("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ns.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ns,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return rs.setFromEuler(this),this.setFromQuaternion(rs,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ee.DEFAULT_ORDER="XYZ";class Zs{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let $s=0;const os=new M,Zt=new de,ft=new O,Ie=new M,me=new M,Hs=new M,Js=new de,as=new M(1,0,0),cs=new M(0,1,0),hs=new M(0,0,1),ls={type:"added"},Gs={type:"removed"},$t={type:"childadded",child:null},ui={type:"childremoved",child:null};class zt extends ri{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:$s++}),this.uuid=Pe(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=zt.DEFAULT_UP.clone();const t=new M,e=new Ee,i=new de,s=new M(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new O},normalMatrix:{value:new Vt}}),this.matrix=new O,this.matrixWorld=new O,this.matrixAutoUpdate=zt.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=zt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Zs,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Zt.setFromAxisAngle(t,e),this.quaternion.multiply(Zt),this}rotateOnWorldAxis(t,e){return Zt.setFromAxisAngle(t,e),this.quaternion.premultiply(Zt),this}rotateX(t){return this.rotateOnAxis(as,t)}rotateY(t){return this.rotateOnAxis(cs,t)}rotateZ(t){return this.rotateOnAxis(hs,t)}translateOnAxis(t,e){return os.copy(t).applyQuaternion(this.quaternion),this.position.add(os.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(as,t)}translateY(t){return this.translateOnAxis(cs,t)}translateZ(t){return this.translateOnAxis(hs,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(ft.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ie.copy(t):Ie.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),me.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?ft.lookAt(me,Ie,this.up):ft.lookAt(Ie,me,this.up),this.quaternion.setFromRotationMatrix(ft),s&&(ft.extractRotation(s.matrixWorld),Zt.setFromRotationMatrix(ft),this.quaternion.premultiply(Zt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Rt("Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(ls),$t.child=t,this.dispatchEvent($t),$t.child=null):Rt("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Gs),ui.child=t,this.dispatchEvent(ui),ui.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),ft.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),ft.multiply(t.parent.matrixWorld)),t.applyMatrix4(ft),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(ls),$t.child=t,this.dispatchEvent($t),$t.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(me,t,Hs),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(me,Js,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,s=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*i-n[8]*s,n[13]+=i-n[1]*e-n[5]*i-n[9]*s,n[14]+=s-n[2]*e-n[6]*i-n[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e){const i=this.parent;if(t===!0&&i!==null&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.castShadow===!0&&(s.castShadow=!0),this.receiveShadow===!0&&(s.receiveShadow=!0),this.visible===!1&&(s.visible=!1),this.frustumCulled===!1&&(s.frustumCulled=!1),this.renderOrder!==0&&(s.renderOrder=this.renderOrder),this.static!==!1&&(s.static=this.static),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(a=>({...a})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c<h;c++){const u=o[c];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,c=this.material.length;o<c;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),c=r(t.textures),h=r(t.images),u=r(t.shapes),l=r(t.skeletons),d=r(t.animations),y=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),l.length>0&&(i.skeletons=l),d.length>0&&(i.animations=d),y.length>0&&(i.nodes=y)}return i.object=s,i;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),t.pivot!==null&&(this.pivot=t.pivot.clone()),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}}zt.DEFAULT_UP=new M(0,1,0),zt.DEFAULT_MATRIX_AUTO_UPDATE=!0,zt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ot=new M,dt=new M,fi=new M,yt=new M,Ht=new M,Jt=new M,us=new M,di=new M,yi=new M,mi=new M,pi=new ye,xi=new ye,gi=new ye;class et{constructor(t=new M,e=new M,i=new M){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ot.subVectors(t,e),s.cross(ot);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ot.subVectors(s,e),dt.subVectors(i,e),fi.subVectors(t,e);const r=ot.dot(ot),a=ot.dot(dt),o=ot.dot(fi),c=dt.dot(dt),h=dt.dot(fi),u=r*c-a*a;if(u===0)return n.set(0,0,0),null;const l=1/u,d=(c*o-a*h)*l,y=(r*h-a*o)*l;return n.set(1-d-y,y,d)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,yt)===null?!1:yt.x>=0&&yt.y>=0&&yt.x+yt.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,yt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,yt.x),o.addScaledVector(r,yt.y),o.addScaledVector(a,yt.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return pi.setScalar(0),xi.setScalar(0),gi.setScalar(0),pi.fromBufferAttribute(t,e),xi.fromBufferAttribute(t,i),gi.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(pi,n.x),r.addScaledVector(xi,n.y),r.addScaledVector(gi,n.z),r}static isFrontFacing(t,e,i,s){return ot.subVectors(i,e),dt.subVectors(t,e),ot.cross(dt).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return ot.subVectors(this.c,this.b),dt.subVectors(this.a,this.b),ot.cross(dt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return et.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return et.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return et.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return et.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return et.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;Ht.subVectors(s,i),Jt.subVectors(n,i),di.subVectors(t,i);const o=Ht.dot(di),c=Jt.dot(di);if(o<=0&&c<=0)return e.copy(i);yi.subVectors(t,s);const h=Ht.dot(yi),u=Jt.dot(yi);if(h>=0&&u<=h)return e.copy(s);const l=o*u-h*c;if(l<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Ht,r);mi.subVectors(t,n);const d=Ht.dot(mi),y=Jt.dot(mi);if(y>=0&&d<=y)return e.copy(n);const m=d*c-o*y;if(m<=0&&c>=0&&y<=0)return a=c/(c-y),e.copy(i).addScaledVector(Jt,a);const _=h*y-d*u;if(_<=0&&u-h>=0&&d-y>=0)return us.subVectors(n,s),a=(u-h)/(u-h+(d-y)),e.copy(s).addScaledVector(us,a);const g=1/(_+m+l);return r=m*g,a=l*g,e.copy(i).addScaledVector(Ht,r).addScaledVector(Jt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class J{constructor(t=new M(1/0,1/0,1/0),e=new M(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(at.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(at.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=at.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,at):at.fromBufferAttribute(n,r),at.applyMatrix4(t.matrixWorld),this.expandByPoint(at);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Fe.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Fe.copy(i.boundingBox)),Fe.applyMatrix4(t.matrixWorld),this.union(Fe)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,at),at.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(pe),Re.subVectors(this.max,pe),Gt.subVectors(t.a,pe),Qt.subVectors(t.b,pe),jt.subVectors(t.c,pe),At.subVectors(Qt,Gt),St.subVectors(jt,Qt),kt.subVectors(Gt,jt);let e=[0,-At.z,At.y,0,-St.z,St.y,0,-kt.z,kt.y,At.z,0,-At.x,St.z,0,-St.x,kt.z,0,-kt.x,-At.y,At.x,0,-St.y,St.x,0,-kt.y,kt.x,0];return!wi(e,Gt,Qt,jt,Re)||(e=[1,0,0,0,1,0,0,0,1],!wi(e,Gt,Qt,jt,Re))?!1:(Ve.crossVectors(At,St),e=[Ve.x,Ve.y,Ve.z],wi(e,Gt,Qt,jt,Re))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,at).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(at).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(mt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),mt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),mt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),mt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),mt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),mt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),mt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),mt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(mt),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const mt=[new M,new M,new M,new M,new M,new M,new M,new M],at=new M,Fe=new J,Gt=new M,Qt=new M,jt=new M,At=new M,St=new M,kt=new M,pe=new M,Re=new M,Ve=new M,Nt=new M;function wi(f,t,e,i,s){for(let n=0,r=f.length-3;n<=r;n+=3){Nt.fromArray(f,n);const a=s.x*Math.abs(Nt.x)+s.y*Math.abs(Nt.y)+s.z*Math.abs(Nt.z),o=t.dot(Nt),c=e.dot(Nt),h=i.dot(Nt);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const N=new M,Ue=new Y;let Qs=0;class lt{constructor(t,e,i=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:Qs++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Ue.fromBufferAttribute(this,e),Ue.applyMatrix3(t),this.setXY(e,Ue.x,Ue.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.applyMatrix3(t),this.setXYZ(e,N.x,N.y,N.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.applyMatrix4(t),this.setXYZ(e,N.x,N.y,N.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.applyNormalMatrix(t),this.setXYZ(e,N.x,N.y,N.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)N.fromBufferAttribute(this,e),N.transformDirection(t),this.setXYZ(e,N.x,N.y,N.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=fe(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=j(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=fe(e,this.array)),e}setX(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=fe(e,this.array)),e}setY(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=fe(e,this.array)),e}setZ(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=fe(e,this.array)),e}setW(t,e){return this.normalized&&(e=j(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=j(e,this.array),i=j(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=j(e,this.array),i=j(i,this.array),s=j(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=j(e,this.array),i=j(i,this.array),s=j(s,this.array),n=j(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==35044&&(t.usage=this.usage),t}}class js extends lt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Ks extends lt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class tn extends lt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const en=new J,xe=new M,bi=new M;class sn{constructor(t=new M,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):en.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;xe.subVectors(t,this.center);const e=xe.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(xe,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(bi.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(xe.copy(t.center).add(bi)),this.expandByPoint(xe.copy(t.center).sub(bi))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let nn=0;const it=new O,_i=new zt,Kt=new M,tt=new J,ge=new J,v=new M;class Mi extends ri{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:nn++}),this.uuid=Pe(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Ls(t)?Ks:js)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new Vt().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return it.makeRotationFromQuaternion(t),this.applyMatrix4(it),this}rotateX(t){return it.makeRotationX(t),this.applyMatrix4(it),this}rotateY(t){return it.makeRotationY(t),this.applyMatrix4(it),this}rotateZ(t){return it.makeRotationZ(t),this.applyMatrix4(it),this}translate(t,e,i){return it.makeTranslation(t,e,i),this.applyMatrix4(it),this}scale(t,e,i){return it.makeScale(t,e,i),this.applyMatrix4(it),this}lookAt(t){return _i.lookAt(t),_i.updateMatrix(),this.applyMatrix4(_i.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Kt).negate(),this.translate(Kt.x,Kt.y,Kt.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new tn(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&ut("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new J);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Rt("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new M(-1/0,-1/0,-1/0),new M(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];tt.setFromBufferAttribute(n),this.morphTargetsRelative?(v.addVectors(this.boundingBox.min,tt.min),this.boundingBox.expandByPoint(v),v.addVectors(this.boundingBox.max,tt.max),this.boundingBox.expandByPoint(v)):(this.boundingBox.expandByPoint(tt.min),this.boundingBox.expandByPoint(tt.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Rt('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new sn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Rt("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new M,1/0);return}if(t){const i=this.boundingSphere.center;if(tt.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];ge.setFromBufferAttribute(a),this.morphTargetsRelative?(v.addVectors(tt.min,ge.min),tt.expandByPoint(v),v.addVectors(tt.max,ge.max),tt.expandByPoint(v)):(tt.expandByPoint(ge.min),tt.expandByPoint(ge.max))}tt.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)v.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(v));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)v.fromBufferAttribute(a,c),o&&(Kt.fromBufferAttribute(t,c),v.add(Kt)),s=Math.max(s,i.distanceToSquared(v))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&Rt('BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Rt("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new lt(new Float32Array(4*i.count),4));const r=this.getAttribute("tangent"),a=[],o=[];for(let A=0;A<i.count;A++)a[A]=new M,o[A]=new M;const c=new M,h=new M,u=new M,l=new Y,d=new Y,y=new Y,m=new M,_=new M;function g(A,P,B){c.fromBufferAttribute(i,A),h.fromBufferAttribute(i,P),u.fromBufferAttribute(i,B),l.fromBufferAttribute(n,A),d.fromBufferAttribute(n,P),y.fromBufferAttribute(n,B),h.sub(c),u.sub(c),d.sub(l),y.sub(l);const C=1/(d.x*y.y-y.x*d.y);isFinite(C)&&(m.copy(h).multiplyScalar(y.y).addScaledVector(u,-d.y).multiplyScalar(C),_.copy(u).multiplyScalar(d.x).addScaledVector(h,-y.x).multiplyScalar(C),a[A].add(m),a[P].add(m),a[B].add(m),o[A].add(_),o[P].add(_),o[B].add(_))}let p=this.groups;p.length===0&&(p=[{start:0,count:t.count}]);for(let A=0,P=p.length;A<P;++A){const B=p[A],C=B.start,T=B.count;for(let E=C,I=C+T;E<I;E+=3)g(t.getX(E+0),t.getX(E+1),t.getX(E+2))}const x=new M,b=new M,w=new M,S=new M;function z(A){w.fromBufferAttribute(s,A),S.copy(w);const P=a[A];x.copy(P),x.sub(w.multiplyScalar(w.dot(P))).normalize(),b.crossVectors(S,P);const C=b.dot(o[A])<0?-1:1;r.setXYZW(A,x.x,x.y,x.z,C)}for(let A=0,P=p.length;A<P;++A){const B=p[A],C=B.start,T=B.count;for(let E=C,I=C+T;E<I;E+=3)z(t.getX(E+0)),z(t.getX(E+1)),z(t.getX(E+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0)i=new lt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let l=0,d=i.count;l<d;l++)i.setXYZ(l,0,0,0);const s=new M,n=new M,r=new M,a=new M,o=new M,c=new M,h=new M,u=new M;if(t)for(let l=0,d=t.count;l<d;l+=3){const y=t.getX(l+0),m=t.getX(l+1),_=t.getX(l+2);s.fromBufferAttribute(e,y),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,_),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),a.fromBufferAttribute(i,y),o.fromBufferAttribute(i,m),c.fromBufferAttribute(i,_),a.add(h),o.add(h),c.add(h),i.setXYZ(y,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(_,c.x,c.y,c.z)}else for(let l=0,d=e.count;l<d;l+=3)s.fromBufferAttribute(e,l+0),n.fromBufferAttribute(e,l+1),r.fromBufferAttribute(e,l+2),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),i.setXYZ(l+0,h.x,h.y,h.z),i.setXYZ(l+1,h.x,h.y,h.z),i.setXYZ(l+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)v.fromBufferAttribute(t,e),v.normalize(),t.setXYZ(e,v.x,v.y,v.z)}toNonIndexed(){function t(a,o){const c=a.array,h=a.itemSize,u=a.normalized,l=new c.constructor(o.length*h);let d=0,y=0;for(let m=0,_=o.length;m<_;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*h;for(let g=0;g<h;g++)l[y++]=c[d++]}return new lt(l,h,u)}if(this.index===null)return ut("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Mi,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],c=t(o,i);e.setAttribute(a,c)}const n=this.morphAttributes;for(const a in n){const o=[],c=n[a];for(let h=0,u=c.length;h<u;h++){const l=c[h],d=t(l,i);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const c=r[a];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const c=i[o];t.data.attributes[o]=c.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let u=0,l=c.length;u<l;u++){const d=c[u];h.push(d.toJSON(t.data))}h.length>0&&(s[o]=h,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const n=t.morphAttributes;for(const c in n){const h=[],u=n[c];for(let l=0,d=u.length;l<d;l++)h.push(u[l].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let c=0,h=r.length;c<h;c++){const u=r[c];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const pt=new M,zi=new M,ke=new M,Bt=new M,Ai=new M,Ne=new M,Si=new M;class rn{constructor(t=new M,e=new M(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,pt)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=pt.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(pt.copy(this.origin).addScaledVector(this.direction,e),pt.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){zi.copy(t).add(e).multiplyScalar(.5),ke.copy(e).sub(t).normalize(),Bt.copy(this.origin).sub(zi);const n=t.distanceTo(e)*.5,r=-this.direction.dot(ke),a=Bt.dot(this.direction),o=-Bt.dot(ke),c=Bt.lengthSq(),h=Math.abs(1-r*r);let u,l,d,y;if(h>0)if(u=r*o-a,l=r*a-o,y=n*h,u>=0)if(l>=-y)if(l<=y){const m=1/h;u*=m,l*=m,d=u*(u+r*l+2*a)+l*(r*u+l+2*o)+c}else l=n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l=-n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l<=-y?(u=Math.max(0,-(-r*n+a)),l=u>0?-n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c):l<=y?(u=0,l=Math.min(Math.max(-n,-o),n),d=l*(l+2*o)+c):(u=Math.max(0,-(r*n+a)),l=u>0?n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c);else l=r>0?-n:n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(zi).addScaledVector(ke,l),d}intersectSphere(t,e){pt.subVectors(t.center,this.origin);const i=pt.dot(this.direction),s=pt.dot(pt)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,l=this.origin;return c>=0?(i=(t.min.x-l.x)*c,s=(t.max.x-l.x)*c):(i=(t.max.x-l.x)*c,s=(t.min.x-l.x)*c),h>=0?(n=(t.min.y-l.y)*h,r=(t.max.y-l.y)*h):(n=(t.max.y-l.y)*h,r=(t.min.y-l.y)*h),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-l.z)*u,o=(t.max.z-l.z)*u):(a=(t.max.z-l.z)*u,o=(t.min.z-l.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,pt)!==null}intersectTriangle(t,e,i,s,n){Ai.subVectors(e,t),Ne.subVectors(i,t),Si.crossVectors(Ai,Ne);let r=this.direction.dot(Si),a;if(r>0){if(s)return null;a=1}else if(r<0)a=-1,r=-r;else return null;Bt.subVectors(this.origin,t);const o=a*this.direction.dot(Ne.crossVectors(Bt,Ne));if(o<0)return null;const c=a*this.direction.dot(Ai.cross(Bt));if(c<0||o+c>r)return null;const h=-a*Bt.dot(Si);return h<0?null:this.at(h/r,n)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}const Bi=new M,on=new M,an=new Vt;class fs{constructor(t=new M(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=Bi.subVectors(i,e).cross(on.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const i=t.delta(Bi),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const n=-(t.start.dot(this.normal)+this.constant)/s;return n<0||n>1?null:e.copy(t.start).addScaledVector(i,n)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||an.getNormalMatrix(t),s=this.coplanarPoint(Bi).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const ds=new M,De=new M,te=new M,ee=new M,Ti=new M,cn=new M,hn=new M;class xt{constructor(t=new M,e=new M){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){ds.subVectors(t,this.start),De.subVectors(this.end,this.start);const i=De.dot(De);let n=De.dot(ds)/i;return e&&(n=R(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}distanceSqToLine3(t,e=cn,i=hn){const s=10000000000000001e-32;let n,r;const a=this.start,o=t.start,c=this.end,h=t.end;te.subVectors(c,a),ee.subVectors(h,o),Ti.subVectors(a,o);const u=te.dot(te),l=ee.dot(ee),d=ee.dot(Ti);if(u<=s&&l<=s)return e.copy(a),i.copy(o),e.sub(i),e.dot(e);if(u<=s)n=0,r=d/l,r=R(r,0,1);else{const y=te.dot(Ti);if(l<=s)r=0,n=R(-y/u,0,1);else{const m=te.dot(ee),_=u*l-m*m;_!==0?n=R((m*d-y*l)/_,0,1):n=0,r=(m*n+d)/l,r<0?(r=0,n=R(-y/u,0,1)):r>1&&(r=1,n=R((m-y)/u,0,1))}}return e.copy(a).addScaledVector(te,n),i.copy(o).addScaledVector(ee,r),e.distanceToSquared(i)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}if(typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Wt}})),typeof window<"u"){try{self.location.href,window.__THREE__IMPORTS__||(window.__THREE__IMPORTS__=[]),window.__THREE__IMPORTS__.push({url:self.location.href,revision:Wt})}catch{}window.__THREE__?(ut("WARNING: Multiple instances of Three.js being imported. Existing: "+window.__THREE__+", new: "+Wt),console.warn("THREE imports:",window.__THREE__IMPORTS__)):window.__THREE__=Wt}const ys=0,ln=1,un=2,ms=2,Pi=1.25,ps=1,$=32,L=$/4,xs=65535,Le=Math.pow(2,-24),Ci=Symbol("SKIP_GENERATION"),gs={strategy:ys,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ci]:!1};class gt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}gt.prototype.setFromBox=(function(){const f=new M;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){f.x=s.x*o+n.x*(1-o),f.y=s.y*c+n.y*(1-c),f.z=s.z*h+n.z*(1-h);const u=e.dot(f);r=Math.min(u,r),a=Math.max(u,a)}this.min=r,this.max=a}})();const fn=(function(){const f=new M,t=new M,e=new M;return function(s,n,r){const a=s.start,o=f,c=n.start,h=t;e.subVectors(a,c),f.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const u=e.dot(h),l=h.dot(o),d=h.dot(h),y=e.dot(o),_=o.dot(o)*d-l*l;let g,p;_!==0?g=(u*l-y*d)/_:g=0,p=(u+g*l)/d,r.x=g,r.y=p}})(),Ei=(function(){const f=new Y,t=new M,e=new M;return function(s,n,r,a){fn(s,n,f);let o=f.x,c=f.y;if(o>=0&&o<=1&&c>=0&&c<=1){s.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let u;c<0?u=n.start:u=n.end;const l=t,d=e;if(s.closestPointToPoint(u,!0,t),n.closestPointToPoint(h,!0,e),l.distanceToSquared(u)<=d.distanceToSquared(h)){r.copy(l),a.copy(u);return}else{r.copy(h),a.copy(d);return}}}})(),dn=(function(){const f=new M,t=new M,e=new fs,i=new xt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:u}=r;if(i.start=c,i.end=h,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a||(i.start=c,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a)||(i.start=h,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a))return!0;const m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){const g=m.projectPoint(o,t);if(r.containsPoint(g))return!0}return!1}})(),yn=["x","y","z"],wt=1e-15,ws=wt*wt;function st(f){return Math.abs(f)<wt}class ct extends et{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M),this.satBounds=new Array(4).fill().map(()=>new gt),this.points=[this.a,this.b,this.c],this.plane=new fs,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new xt,this.needsUpdate=!0}intersectsSphere(t){return dn(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const c=n[1],h=r[1];c.subVectors(t,e),h.setFromPoints(c,s);const u=n[2],l=r[2];u.subVectors(e,i),l.setFromPoints(u,s);const d=n[3],y=r[3];d.subVectors(i,t),y.setFromPoints(d,s);const m=c.length(),_=u.length(),g=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<wt?_<wt||g<wt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):_<wt?g<wt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):g<wt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ct.prototype.closestPointToSegment=(function(){const f=new M,t=new M,e=new xt;return function(s,n=null,r=null){const{start:a,end:o}=s,c=this.points;let h,u=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;e.start.copy(c[l]),e.end.copy(c[d]),Ei(e,s,f,t),h=f.distanceToSquared(t),h<u&&(u=h,n&&n.copy(f),r&&r.copy(t))}return this.closestPointToPoint(a,f),h=a.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(a)),this.closestPointToPoint(o,f),h=o.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(o)),Math.sqrt(u)}})(),ct.prototype.intersectsTriangle=(function(){const f=new ct,t=new gt,e=new gt,i=new M,s=new M,n=new M,r=new M,a=new xt,o=new xt,c=new M,h=new Y,u=new Y;function l(x,b,w,S){const z=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?z.copy(x.plane.normal):z.copy(b.plane.normal);const A=x.satBounds,P=x.satAxes;for(let T=1;T<4;T++){const E=A[T],I=P[T];if(t.setFromPoints(I,b.points),E.isSeparated(t)||(r.copy(z).cross(I),t.setFromPoints(r,x.points),e.setFromPoints(r,b.points),t.isSeparated(e)))return!1}const B=b.satBounds,C=b.satAxes;for(let T=1;T<4;T++){const E=B[T],I=C[T];if(t.setFromPoints(I,x.points),E.isSeparated(t)||(r.crossVectors(z,I),t.setFromPoints(r,x.points),e.setFromPoints(r,b.points),t.isSeparated(e)))return!1}return w&&(S||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),w.start.set(0,0,0),w.end.set(0,0,0)),!0}function d(x,b,w,S,z,A,P,B,C,T,E){let I=P/(P-B);T.x=S+(z-S)*I,E.start.subVectors(b,x).multiplyScalar(I).add(x),I=P/(P-C),T.y=S+(A-S)*I,E.end.subVectors(w,x).multiplyScalar(I).add(x)}function y(x,b,w,S,z,A,P,B,C,T,E){if(z>0)d(x.c,x.a,x.b,S,b,w,C,P,B,T,E);else if(A>0)d(x.b,x.a,x.c,w,b,S,B,P,C,T,E);else if(B*C>0||P!=0)d(x.a,x.b,x.c,b,w,S,P,B,C,T,E);else if(B!=0)d(x.b,x.a,x.c,w,b,S,B,P,C,T,E);else if(C!=0)d(x.c,x.a,x.b,S,b,w,C,P,B,T,E);else return!0;return!1}function m(x,b,w,S){const z=b.degenerateSegment,A=x.plane.distanceToPoint(z.start),P=x.plane.distanceToPoint(z.end);return st(A)?st(P)?l(x,b,w,S):(w&&(w.start.copy(z.start),w.end.copy(z.start)),x.containsPoint(z.start)):st(P)?(w&&(w.start.copy(z.end),w.end.copy(z.end)),x.containsPoint(z.end)):x.plane.intersectLine(z,i)!=null?(w&&(w.start.copy(i),w.end.copy(i)),x.containsPoint(i)):!1}function _(x,b,w){const S=b.a;return st(x.plane.distanceToPoint(S))&&x.containsPoint(S)?(w&&(w.start.copy(S),w.end.copy(S)),!0):!1}function g(x,b,w){const S=x.degenerateSegment,z=b.a;return S.closestPointToPoint(z,!0,i),z.distanceToSquared(i)<ws?(w&&(w.start.copy(z),w.end.copy(z)),!0):!1}function p(x,b,w,S){if(x.isDegenerateIntoSegment)if(b.isDegenerateIntoSegment){const z=x.degenerateSegment,A=b.degenerateSegment,P=s,B=n;z.delta(P),A.delta(B);const C=i.subVectors(A.start,z.start),T=P.x*B.y-P.y*B.x;if(st(T))return!1;const E=(C.x*B.y-C.y*B.x)/T,I=-(P.x*C.y-P.y*C.x)/T;if(E<0||E>1||I<0||I>1)return!1;const F=z.start.z+P.z*E,U=A.start.z+B.z*I;return st(F-U)?(w&&(w.start.copy(z.start).addScaledVector(P,E),w.end.copy(z.start).addScaledVector(P,E)),!0):!1}else return b.isDegenerateIntoPoint?g(x,b,w):m(b,x,w,S);else{if(x.isDegenerateIntoPoint)return b.isDegenerateIntoPoint?b.a.distanceToSquared(x.a)<ws?(w&&(w.start.copy(x.a),w.end.copy(x.a)),!0):!1:b.isDegenerateIntoSegment?g(b,x,w):_(b,x,w);if(b.isDegenerateIntoPoint)return _(x,b,w);if(b.isDegenerateIntoSegment)return m(x,b,w,S)}}return function(b,w=null,S=!1){this.needsUpdate&&this.update(),b.isExtendedTriangle?b.needsUpdate&&b.update():(f.copy(b),f.update(),b=f);const z=p(this,b,w,S);if(z!==void 0)return z;const A=this.plane,P=b.plane;let B=P.distanceToPoint(this.a),C=P.distanceToPoint(this.b),T=P.distanceToPoint(this.c);st(B)&&(B=0),st(C)&&(C=0),st(T)&&(T=0);const E=B*C,I=B*T;if(E>0&&I>0)return!1;let F=A.distanceToPoint(b.a),U=A.distanceToPoint(b.b),_t=A.distanceToPoint(b.c);st(F)&&(F=0),st(U)&&(U=0),st(_t)&&(_t=0);const Ot=F*U,vt=F*_t;if(Ot>0&&vt>0)return!1;s.copy(A.normal),n.copy(P.normal);const It=s.cross(n);let Ft=0,Ki=Math.abs(It.x);const Ds=Math.abs(It.y);Ds>Ki&&(Ki=Ds,Ft=1),Math.abs(It.z)>Ki&&(Ft=2);const ue=yn[Ft],lr=this.a[ue],ur=this.b[ue],fr=this.c[ue],dr=b.a[ue],yr=b.b[ue],mr=b.c[ue];if(y(this,lr,ur,fr,E,I,B,C,T,h,a))return l(this,b,w,S);if(y(b,dr,yr,mr,Ot,vt,F,U,_t,u,o))return l(this,b,w,S);if(h.y<h.x){const ts=h.y;h.y=h.x,h.x=ts,c.copy(a.start),a.start.copy(a.end),a.end.copy(c)}if(u.y<u.x){const ts=u.y;u.y=u.x,u.x=ts,c.copy(o.start),o.start.copy(o.end),o.end.copy(c)}return h.y<u.x||u.y<h.x?!1:(w&&(u.x>h.x?w.start.copy(o.start):w.start.copy(a.start),u.y<h.y?w.end.copy(o.end):w.end.copy(a.end)),!0)}})(),ct.prototype.distanceToPoint=(function(){const f=new M;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),ct.prototype.distanceToTriangle=(function(){const f=new M,t=new M,e=["a","b","c"],i=new xt,s=new xt;return function(r,a=null,o=null){const c=a||o?i:null;if(this.intersectsTriangle(r,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let u=0;u<3;u++){let l;const d=e[u],y=r[d];this.closestPointToPoint(y,f),l=y.distanceToSquared(f),l<h&&(h=l,a&&a.copy(f),o&&o.copy(y));const m=this[d];r.closestPointToPoint(m,f),l=m.distanceToSquared(f),l<h&&(h=l,a&&a.copy(m),o&&o.copy(f))}for(let u=0;u<3;u++){const l=e[u],d=e[(u+1)%3];i.set(this[l],this[d]);for(let y=0;y<3;y++){const m=e[y],_=e[(y+1)%3];s.set(r[m],r[_]),Ei(i,s,f,t);const g=f.distanceToSquared(t);g<h&&(h=g,a&&a.copy(f),o&&o.copy(t))}}return Math.sqrt(h)}})();class G{constructor(t,e,i){this.isOrientedBox=!0,this.min=new M,this.max=new M,this.matrix=new O,this.invMatrix=new O,this.points=new Array(8).fill().map(()=>new M),this.satAxes=new Array(3).fill().map(()=>new M),this.satBounds=new Array(3).fill().map(()=>new gt),this.alignedSatBounds=new Array(3).fill().map(()=>new gt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}G.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let u=0;u<=1;u++){const l=1*c|2*h|4*u,d=s[l];d.x=c?i.x:e.x,d.y=h?i.y:e.y,d.z=u?i.z:e.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let c=0;c<3;c++){const h=r[c],u=n[c],l=1<<c,d=s[l];h.subVectors(a,d),u.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),G.prototype.intersectsBox=(function(){const f=new gt;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(f.min=i.x,f.max=s.x,a[0].isSeparated(f)||(f.min=i.y,f.max=s.y,a[1].isSeparated(f))||(f.min=i.z,f.max=s.z,a[2].isSeparated(f)))return!1;for(let o=0;o<3;o++){const c=r[o],h=n[o];if(f.setFromBox(c,e),h.isSeparated(f))return!1}return!0}})(),G.prototype.intersectsTriangle=(function(){const f=new ct,t=new Array(3),e=new gt,i=new gt,s=new M;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(f.copy(r),f.update(),r=f);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let l=0;l<3;l++){const d=a[l],y=o[l];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const c=r.satBounds,h=r.satAxes,u=this.points;for(let l=0;l<3;l++){const d=c[l],y=h[l];if(e.setFromPoints(y,u),d.isSeparated(e))return!1}for(let l=0;l<3;l++){const d=o[l];for(let y=0;y<4;y++){const m=h[y];if(s.crossVectors(d,m),e.setFromPoints(s,t),i.setFromPoints(s,u),e.isSeparated(i))return!1}}return!0}})(),G.prototype.closestPointToPoint=(function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),G.prototype.distanceToPoint=(function(){const f=new M;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),G.prototype.distanceToBox=(function(){const f=["x","y","z"],t=new Array(12).fill().map(()=>new xt),e=new Array(12).fill().map(()=>new xt),i=new M,s=new M;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),c&&c.copy(s)),0;const h=a*a,u=r.min,l=r.max,d=this.points;let y=1/0;for(let _=0;_<8;_++){const g=d[_];s.copy(g).clamp(u,l);const p=g.distanceToSquared(s);if(p<y&&(y=p,o&&o.copy(g),c&&c.copy(s),p<h))return Math.sqrt(p)}let m=0;for(let _=0;_<3;_++)for(let g=0;g<=1;g++)for(let p=0;p<=1;p++){const x=(_+1)%3,b=(_+2)%3,w=g<<x|p<<b,S=1<<_|g<<x|p<<b,z=d[w],A=d[S];t[m].set(z,A);const B=f[_],C=f[x],T=f[b],E=e[m],I=E.start,F=E.end;I[B]=u[B],I[C]=g?u[C]:l[C],I[T]=p?u[T]:l[C],F[B]=l[B],F[C]=g?u[C]:l[C],F[T]=p?u[T]:l[C],m++}for(let _=0;_<=1;_++)for(let g=0;g<=1;g++)for(let p=0;p<=1;p++){s.x=_?l.x:u.x,s.y=g?l.y:u.y,s.z=p?l.z:u.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<y&&(y=x,o&&o.copy(i),c&&c.copy(s),x<h))return Math.sqrt(x)}for(let _=0;_<12;_++){const g=t[_];for(let p=0;p<12;p++){const x=e[p];Ei(g,x,i,s);const b=i.distanceToSquared(s);if(b<y&&(y=b,o&&o.copy(i),c&&c.copy(s),b<h))return Math.sqrt(b)}}return Math.sqrt(y)}})();class Ii{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class mn extends Ii{constructor(){super(()=>new ct)}}const nt=new mn,we=new M,Fi=new M;function pn(f,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(f.shapecast({boundsTraverseOrder:h=>(we.copy(t).clamp(h.min,h.max),we.distanceToSquared(t)),intersectsBounds:(h,u,l)=>l<a&&l<r,intersectsTriangle:(h,u)=>{h.closestPointToPoint(t,we);const l=t.distanceToSquared(we);return l<a&&(Fi.copy(we),a=l,o=u),l<n}}),a===1/0)return null;const c=Math.sqrt(a);return e.point?e.point.copy(Fi):e.point=Fi.clone(),e.distance=c,e.faceIndex=o,e}function q(f,t){return t[f+15]===xs}function H(f,t){return t[f+6]}function Q(f,t){return t[f+14]}function W(f){return f+L}function X(f,t){const e=t[f+6];return f+e*L}function Ri(f,t){return t[f+7]}function Fr(f){return f}const qe=parseInt(Wt)>=169,xn=parseInt(Wt)<=161,Dt=new M,Lt=new M,qt=new M,Oe=new Y,ve=new Y,We=new Y,bs=new M,_s=new M,Ms=new M,be=new M;function gn(f,t,e,i,s,n,r,a){let o;if(n===1?o=f.intersectTriangle(i,e,t,!0,s):o=f.intersectTriangle(t,e,i,n!==2,s),o===null)return null;const c=f.origin.distanceTo(s);return c<r||c>a?null:{distance:c,point:s.clone()}}function zs(f,t,e,i,s,n,r,a,o,c,h){Dt.fromBufferAttribute(t,n),Lt.fromBufferAttribute(t,r),qt.fromBufferAttribute(t,a);const u=gn(f,Dt,Lt,qt,be,o,c,h);if(u){if(i){Oe.fromBufferAttribute(i,n),ve.fromBufferAttribute(i,r),We.fromBufferAttribute(i,a),u.uv=new Y;const d=et.getInterpolation(be,Dt,Lt,qt,Oe,ve,We,u.uv);qe||(u.uv=d)}if(s){Oe.fromBufferAttribute(s,n),ve.fromBufferAttribute(s,r),We.fromBufferAttribute(s,a),u.uv1=new Y;const d=et.getInterpolation(be,Dt,Lt,qt,Oe,ve,We,u.uv1);qe||(u.uv1=d),xn&&(u.uv2=u.uv1)}if(e){bs.fromBufferAttribute(e,n),_s.fromBufferAttribute(e,r),Ms.fromBufferAttribute(e,a),u.normal=new M;const d=et.getInterpolation(be,Dt,Lt,qt,bs,_s,Ms,u.normal);u.normal.dot(f.direction)>0&&u.normal.multiplyScalar(-1),qe||(u.normal=d)}const l={a:n,b:r,c:a,normal:new M,materialIndex:0};if(et.getNormal(Dt,Lt,qt,l.normal),u.face=l,u.faceIndex=n,qe){const d=new M;et.getBarycoord(be,Dt,Lt,qt,d),u.barycoord=d}}return u}function As(f){return f&&f.isMaterial?f.side:f}function Xe(f,t,e,i,s,n,r){const a=i*3;let o=a+0,c=a+1,h=a+2;const{index:u,groups:l}=f;f.index&&(o=u.getX(o),c=u.getX(c),h=u.getX(h));const{position:d,normal:y,uv:m,uv1:_}=f.attributes;if(Array.isArray(t)){const g=i*3;for(let p=0,x=l.length;p<x;p++){const{start:b,count:w,materialIndex:S}=l[p];if(g>=b&&g<b+w){const z=As(t[S]),A=zs(e,d,y,m,_,o,c,h,z,n,r);if(A)if(A.faceIndex=i,A.face.materialIndex=S,s)s.push(A);else return A}}}else{const g=As(t),p=zs(e,d,y,m,_,o,c,h,g,n,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function D(f,t,e,i){const s=f.a,n=f.b,r=f.c;let a=t,o=t+1,c=t+2;e&&(a=e.getX(a),o=e.getX(o),c=e.getX(c)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(c),r.y=i.getY(c),r.z=i.getZ(c)}function wn(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++)Xe(o,t,e,h,n,r,a)}function bn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=Xe(a,t,e,u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function _n(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=h,D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function Mn(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(q(m,a)){const _=H(l,r),g=Q(m,a);let p=1/0,x=1/0,b=1/0,w=-1/0,S=-1/0,z=-1/0;for(let A=3*_,P=3*(_+g);A<P;A++){let B=i[A];const C=s.getX(B),T=s.getY(B),E=s.getZ(B);C<p&&(p=C),C>w&&(w=C),T<x&&(x=T),T>S&&(S=T),E<b&&(b=E),E>z&&(z=E)}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==b||o[l+3]!==w||o[l+4]!==S||o[l+5]!==z?(o[l+0]=p,o[l+1]=x,o[l+2]=b,o[l+3]=w,o[l+4]=S,o[l+5]=z,!0):!1}else{const _=W(l),g=X(l,r);let p=y,x=!1,b=!1;if(t){if(!p){const B=_/L+d/$,C=g/L+d/$;x=t.has(B),b=t.has(C),p=!x&&!b}}else x=!0,b=!0;const w=p||x,S=p||b;let z=!1;w&&(z=u(_,d,p));let A=!1;S&&(A=u(g,d,p));const P=z||A;if(P)for(let B=0;B<3;B++){const C=_+B,T=g+B,E=o[C],I=o[C+3],F=o[T],U=o[T+3];o[l+B]=E<F?E:F,o[l+B+3]=I>U?I:U}return P}}}function Tt(f,t,e,i,s){let n,r,a,o,c,h;const u=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,m=e.origin.y,_=e.origin.z;let g=t[f],p=t[f+3],x=t[f+1],b=t[f+3+1],w=t[f+2],S=t[f+3+2];return u>=0?(n=(g-y)*u,r=(p-y)*u):(n=(p-y)*u,r=(g-y)*u),l>=0?(a=(x-m)*l,o=(b-m)*l):(a=(b-m)*l,o=(x-m)*l),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),d>=0?(c=(w-_)*d,h=(S-_)*d):(c=(S-_)*d,h=(w-_)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}class zn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const V=new zn;function An(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++){let l=c?c[h]:h;Xe(o,t,e,l,n,r,a)}}function Sn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=Xe(a,t,e,o?o[u]:u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function Bn(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=e.resolveTriangleIndex(h),D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function Tn(f,t,e,i,s,n,r){V.setBuffer(f._roots[t]),Vi(0,f,e,i,s,n,r),V.clearBuffer()}function Vi(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=V,h=f*2;if(q(h,o)){const l=H(f,c),d=Q(h,o);wn(t,e,i,l,d,s,n,r)}else{const l=W(f);Tt(l,a,i,n,r)&&Vi(l,t,e,i,s,n,r);const d=X(f,c);Tt(d,a,i,n,r)&&Vi(d,t,e,i,s,n,r)}}const Pn=["x","y","z"];function Cn(f,t,e,i,s,n){V.setBuffer(f._roots[t]);const r=Ui(0,f,e,i,s,n);return V.clearBuffer(),r}function Ui(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=V;let c=f*2;if(q(c,a)){const u=H(f,o),l=Q(c,a);return bn(t,e,i,u,l,s,n)}else{const u=Ri(f,o),l=Pn[u],y=i.direction[l]>=0;let m,_;y?(m=W(f),_=X(f,o)):(m=X(f,o),_=W(f));const p=Tt(m,r,i,s,n)?Ui(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[_+u]:w>=r[_+u+3])return p}const b=Tt(_,r,i,s,n)?Ui(_,t,e,i,s,n):null;return p&&b?p.distance<=b.distance?p:b:p||b||null}}function k(f,t,e){return e.min.x=t[f],e.min.y=t[f+1],e.min.z=t[f+2],e.max.x=t[f+3],e.max.y=t[f+4],e.max.z=t[f+5],e}function Ss(f){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=f[i+3]-f[i];s>e&&(e=s,t=i)}return t}function Bs(f,t){t.set(f)}function Ts(f,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=f[n],s=t[n],e[n]=i<s?i:s,i=f[r],s=t[r],e[r]=i>s?i:s}}function Ye(f,t,e){for(let i=0;i<3;i++){const s=t[f+2*i],n=t[f+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function _e(f){const t=f[3]-f[0],e=f[4]-f[1],i=f[5]-f[2];return 2*(t*e+e*i+i*t)}function ki(f){return f.index?f.index.count:f.attributes.position.count}function Ze(f){return ki(f)/3}function En(f,t=ArrayBuffer){return f>65535?new Uint32Array(new t(4*f)):new Uint16Array(new t(2*f))}function In(f,t){if(!f.index){const e=f.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=En(e,i);f.setIndex(new lt(s,1));for(let n=0;n<e;n++)s[n]=n}}function Fn(f,t,e){const i=ki(f)/e,s=t||f.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function Rn(f,t){return f.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Ps(f,t,e){const i=Fn(f,t,e),s=Rn(f,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=ki(f)/e,c=[];for(const l of s){const{offset:d,count:y}=l,m=d,_=isFinite(y)?y:o-d,g=d+_;m<a&&g>r&&(c.push({pos:Math.max(r,m),isStart:!0}),c.push({pos:Math.min(a,g),isStart:!1}))}c.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let h=0,u=null;for(const l of c){const d=l.pos;h!==0&&d!==u&&n.push({offset:u,count:d-u}),h+=l.isStart?1:-1,u=d}return n}const $e=new J,ie=new ct,se=new ct,Me=new O,Cs=new G,He=new G;function Vn(f,t,e,i){V.setBuffer(f._roots[t]);const s=Ni(0,f,e,i);return V.clearBuffer(),s}function Ni(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=V;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Cs.set(e.boundingBox.min,e.boundingBox.max,i),s=Cs),q(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=H(f,a),_=Q(o,r);if(Me.copy(i).invert(),e.boundsTree)return k(f,n,He),He.matrix.copy(Me),He.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>He.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m*3,b=(_+m)*3;x<b;x+=3)if(D(se,x,u,l),se.needsUpdate=!0,p.intersectsTriangle(se))return!0;return!1}});{const g=Ze(e);for(let p=m*3,x=(_+m)*3;p<x;p+=3){D(ie,p,u,l),ie.a.applyMatrix4(Me),ie.b.applyMatrix4(Me),ie.c.applyMatrix4(Me),ie.needsUpdate=!0;for(let b=0,w=g*3;b<w;b+=3)if(D(se,b,d,y),se.needsUpdate=!0,ie.intersectsTriangle(se))return!0}}}else{const h=W(f),u=X(f,a);return k(h,n,$e),!!(s.intersectsBox($e)&&Ni(h,t,e,i,s)||(k(u,n,$e),s.intersectsBox($e)&&Ni(u,t,e,i,s)))}}const Je=new O,Di=new G,ze=new G,Un=new M,kn=new M,Nn=new M,Dn=new M;function Ln(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Di.set(t.boundingBox.min,t.boundingBox.max,e),Di.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=nt.getPrimitive(),d=nt.getPrimitive();let y=Un,m=kn,_=null,g=null;s&&(_=Nn,g=Dn);let p=1/0,x=null,b=null;return Je.copy(e).invert(),ze.matrix.copy(Je),f.shapecast({boundsTraverseOrder:w=>Di.distanceToBox(w),intersectsBounds:(w,S,z)=>z<p&&z<r?(S&&(ze.min.copy(w.min),ze.max.copy(w.max),ze.needsUpdate=!0),!0):!1,intersectsRange:(w,S)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:A=>ze.distanceToBox(A),intersectsBounds:(A,P,B)=>B<p&&B<r,intersectsRange:(A,P)=>{for(let B=A,C=A+P;B<C;B++){D(d,3*B,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let T=w,E=w+S;T<E;T++){D(l,3*T,c,o),l.needsUpdate=!0;const I=l.distanceToTriangle(d,y,_);if(I<p&&(m.copy(y),g&&g.copy(_),p=I,x=T,b=B),I<n)return!0}}}});{const z=Ze(t);for(let A=0,P=z;A<P;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let B=w,C=w+S;B<C;B++){D(l,3*B,c,o),l.needsUpdate=!0;const T=l.distanceToTriangle(d,y,_);if(T<p&&(m.copy(y),g&&g.copy(_),p=T,x=B,b=A),T<n)return!0}}}}}),nt.releasePrimitive(l),nt.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(g):s.point=g.clone(),s.point.applyMatrix4(Je),m.applyMatrix4(Je),s.distance=m.sub(s.point).length(),s.faceIndex=b),i)}function qn(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(q(m,a)){const _=H(l,r),g=Q(m,a);let p=1/0,x=1/0,b=1/0,w=-1/0,S=-1/0,z=-1/0;for(let A=_,P=_+g;A<P;A++){const B=3*f.resolveTriangleIndex(A);for(let C=0;C<3;C++){let T=B+C;T=i?i[T]:T;const E=s.getX(T),I=s.getY(T),F=s.getZ(T);E<p&&(p=E),E>w&&(w=E),I<x&&(x=I),I>S&&(S=I),F<b&&(b=F),F>z&&(z=F)}}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==b||o[l+3]!==w||o[l+4]!==S||o[l+5]!==z?(o[l+0]=p,o[l+1]=x,o[l+2]=b,o[l+3]=w,o[l+4]=S,o[l+5]=z,!0):!1}else{const _=W(l),g=X(l,r);let p=y,x=!1,b=!1;if(t){if(!p){const B=_/L+d/$,C=g/L+d/$;x=t.has(B),b=t.has(C),p=!x&&!b}}else x=!0,b=!0;const w=p||x,S=p||b;let z=!1;w&&(z=u(_,d,p));let A=!1;S&&(A=u(g,d,p));const P=z||A;if(P)for(let B=0;B<3;B++){const C=_+B,T=g+B,E=o[C],I=o[C+3],F=o[T],U=o[T+3];o[l+B]=E<F?E:F,o[l+B+3]=I>U?I:U}return P}}}function On(f,t,e,i,s,n,r){V.setBuffer(f._roots[t]),Li(0,f,e,i,s,n,r),V.clearBuffer()}function Li(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=V,h=f*2;if(q(h,o)){const l=H(f,c),d=Q(h,o);An(t,e,i,l,d,s,n,r)}else{const l=W(f);Tt(l,a,i,n,r)&&Li(l,t,e,i,s,n,r);const d=X(f,c);Tt(d,a,i,n,r)&&Li(d,t,e,i,s,n,r)}}const vn=["x","y","z"];function Wn(f,t,e,i,s,n){V.setBuffer(f._roots[t]);const r=qi(0,f,e,i,s,n);return V.clearBuffer(),r}function qi(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=V;let c=f*2;if(q(c,a)){const u=H(f,o),l=Q(c,a);return Sn(t,e,i,u,l,s,n)}else{const u=Ri(f,o),l=vn[u],y=i.direction[l]>=0;let m,_;y?(m=W(f),_=X(f,o)):(m=X(f,o),_=W(f));const p=Tt(m,r,i,s,n)?qi(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[_+u]:w>=r[_+u+3])return p}const b=Tt(_,r,i,s,n)?qi(_,t,e,i,s,n):null;return p&&b?p.distance<=b.distance?p:b:p||b||null}}const Ge=new J,ne=new ct,re=new ct,Ae=new O,Es=new G,Qe=new G;function Xn(f,t,e,i){V.setBuffer(f._roots[t]);const s=Oi(0,f,e,i);return V.clearBuffer(),s}function Oi(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=V;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Es.set(e.boundingBox.min,e.boundingBox.max,i),s=Es),q(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=H(f,a),_=Q(o,r);if(Ae.copy(i).invert(),e.boundsTree)return k(f,n,Qe),Qe.matrix.copy(Ae),Qe.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>Qe.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m,b=_+m;x<b;x++)if(D(re,3*t.resolveTriangleIndex(x),u,l),re.needsUpdate=!0,p.intersectsTriangle(re))return!0;return!1}});{const g=Ze(e);for(let p=m,x=_+m;p<x;p++){const b=t.resolveTriangleIndex(p);D(ne,3*b,u,l),ne.a.applyMatrix4(Ae),ne.b.applyMatrix4(Ae),ne.c.applyMatrix4(Ae),ne.needsUpdate=!0;for(let w=0,S=g*3;w<S;w+=3)if(D(re,w,d,y),re.needsUpdate=!0,ne.intersectsTriangle(re))return!0}}}else{const h=W(f),u=X(f,a);return k(h,n,Ge),!!(s.intersectsBox(Ge)&&Oi(h,t,e,i,s)||(k(u,n,Ge),s.intersectsBox(Ge)&&Oi(u,t,e,i,s)))}}const je=new O,vi=new G,Se=new G,Yn=new M,Zn=new M,$n=new M,Hn=new M;function Jn(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),vi.set(t.boundingBox.min,t.boundingBox.max,e),vi.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=nt.getPrimitive(),d=nt.getPrimitive();let y=Yn,m=Zn,_=null,g=null;s&&(_=$n,g=Hn);let p=1/0,x=null,b=null;return je.copy(e).invert(),Se.matrix.copy(je),f.shapecast({boundsTraverseOrder:w=>vi.distanceToBox(w),intersectsBounds:(w,S,z)=>z<p&&z<r?(S&&(Se.min.copy(w.min),Se.max.copy(w.max),Se.needsUpdate=!0),!0):!1,intersectsRange:(w,S)=>{if(t.boundsTree){const z=t.boundsTree;return z.shapecast({boundsTraverseOrder:A=>Se.distanceToBox(A),intersectsBounds:(A,P,B)=>B<p&&B<r,intersectsRange:(A,P)=>{for(let B=A,C=A+P;B<C;B++){const T=z.resolveTriangleIndex(B);D(d,3*T,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=w,I=w+S;E<I;E++){const F=f.resolveTriangleIndex(E);D(l,3*F,c,o),l.needsUpdate=!0;const U=l.distanceToTriangle(d,y,_);if(U<p&&(m.copy(y),g&&g.copy(_),p=U,x=E,b=B),U<n)return!0}}}})}else{const z=Ze(t);for(let A=0,P=z;A<P;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let B=w,C=w+S;B<C;B++){const T=f.resolveTriangleIndex(B);D(l,3*T,c,o),l.needsUpdate=!0;const E=l.distanceToTriangle(d,y,_);if(E<p&&(m.copy(y),g&&g.copy(_),p=E,x=B,b=A),E<n)return!0}}}}}),nt.releasePrimitive(l),nt.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(g):s.point=g.clone(),s.point.applyMatrix4(je),m.applyMatrix4(je),s.distance=m.sub(s.point).length(),s.faceIndex=b),i)}function Is(f,t,e){return f===null?null:(f.point.applyMatrix4(t.matrixWorld),f.distance=f.point.distanceTo(e.ray.origin),f.object=t,f)}function Gn(){return typeof SharedArrayBuffer<"u"}function Wi(f,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,u=1/0,l=1/0,d=1/0,y=-1/0,m=-1/0,_=-1/0;const g=f.offset||0;for(let p=(t-g)*6,x=(t+e-g)*6;p<x;p+=6){const b=f[p+0],w=f[p+1],S=b-w,z=b+w;S<n&&(n=S),z>o&&(o=z),b<u&&(u=b),b>y&&(y=b);const A=f[p+2],P=f[p+3],B=A-P,C=A+P;B<r&&(r=B),C>c&&(c=C),A<l&&(l=A),A>m&&(m=A);const T=f[p+4],E=f[p+5],I=T-E,F=T+E;I<a&&(a=I),F>h&&(h=F),T<d&&(d=T),T>_&&(_=T)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=c,i[5]=h,s[0]=u,s[1]=l,s[2]=d,s[3]=y,s[4]=m,s[5]=_}const bt=32,Qn=(f,t)=>f.candidate-t.candidate,Pt=new Array(bt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ke=new Float32Array(6);function jn(f,t,e,i,s,n){let r=-1,a=0;if(n===ys)r=Ss(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===ln)r=Ss(f),r!==-1&&(a=Kn(e,i,s,r));else if(n===un){const o=_e(f);let c=Pi*s;const h=e.offset||0,u=(i-h)*6,l=(i+s-h)*6;for(let d=0;d<3;d++){const y=t[d],g=(t[d+3]-y)/bt;if(s<bt/4){const p=[...Pt];p.length=s;let x=0;for(let w=u;w<l;w+=6,x++){const S=p[x];S.candidate=e[w+2*d],S.count=0;const{bounds:z,leftCacheBounds:A,rightCacheBounds:P}=S;for(let B=0;B<3;B++)P[B]=1/0,P[B+3]=-1/0,A[B]=1/0,A[B+3]=-1/0,z[B]=1/0,z[B+3]=-1/0;Ye(w,e,z)}p.sort(Qn);let b=s;for(let w=0;w<b;w++){const S=p[w];for(;w+1<b&&p[w+1].candidate===S.candidate;)p.splice(w+1,1),b--}for(let w=u;w<l;w+=6){const S=e[w+2*d];for(let z=0;z<b;z++){const A=p[z];S>=A.candidate?Ye(w,e,A.rightCacheBounds):(Ye(w,e,A.leftCacheBounds),A.count++)}}for(let w=0;w<b;w++){const S=p[w],z=S.count,A=s-S.count,P=S.leftCacheBounds,B=S.rightCacheBounds;let C=0;z!==0&&(C=_e(P)/o);let T=0;A!==0&&(T=_e(B)/o);const E=ps+Pi*(C*z+T*A);E<c&&(r=d,c=E,a=S.candidate)}}else{for(let b=0;b<bt;b++){const w=Pt[b];w.count=0,w.candidate=y+g+b*g;const S=w.bounds;for(let z=0;z<3;z++)S[z]=1/0,S[z+3]=-1/0}for(let b=u;b<l;b+=6){let z=~~((e[b+2*d]-y)/g);z>=bt&&(z=bt-1);const A=Pt[z];A.count++,Ye(b,e,A.bounds)}const p=Pt[bt-1];Bs(p.bounds,p.rightCacheBounds);for(let b=bt-2;b>=0;b--){const w=Pt[b],S=Pt[b+1];Ts(w.bounds,S.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let b=0;b<bt-1;b++){const w=Pt[b],S=w.count,z=w.bounds,P=Pt[b+1].rightCacheBounds;S!==0&&(x===0?Bs(z,Ke):Ts(z,Ke,Ke)),x+=S;let B=0,C=0;x!==0&&(B=_e(Ke)/o);const T=s-x;T!==0&&(C=_e(P)/o);const E=ps+Pi*(B*x+C*T);E<c&&(r=d,c=E,a=w.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${n} used.`);return{axis:r,pos:a}}function Kn(f,t,e,i){let s=0;const n=f.offset;for(let r=t,a=t+e;r<a;r++)s+=f[(r-n)*6+i*2];return s/e}class Xi{constructor(){this.boundingData=new Float32Array(6)}}function tr(f,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,c=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+c]<o;)r++;for(;r<=a&&e[(a-h)*6+c]>=o;)a--;if(r<a){for(let u=0;u<t;u++){let l=f[r*t+u];f[r*t+u]=f[a*t+u],f[a*t+u]=l}for(let u=0;u<6;u++){const l=r-h,d=a-h,y=e[l*6+u];e[l*6+u]=e[d*6+u],e[d*6+u]=y}r++,a--}else return r}}let Fs,ti,Yi,Rs;const er=Math.pow(2,32);function Zi(f){return"count"in f?1:1+Zi(f.left)+Zi(f.right)}function ir(f,t,e){return Fs=new Float32Array(e),ti=new Uint32Array(e),Yi=new Uint16Array(e),Rs=new Uint8Array(e),$i(f,t)}function $i(f,t){const e=f/4,i=f/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Fs[e+r]=n[r];if(s)return t.buffer?(Rs.set(new Uint8Array(t.buffer),f),f+t.buffer.byteLength):(ti[e+6]=t.offset,Yi[i+14]=t.count,Yi[i+15]=xs,f+$);{const{left:r,right:a,splitAxis:o}=t,c=f+$;let h=$i(c,r);const u=f/$,d=h/$-u;if(d>er)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return ti[e+6]=d,ti[e+7]=o,$i(h,a)}}function sr(f,t,e,i,s){const{maxDepth:n,verbose:r,maxLeafSize:a,strategy:o,onProgress:c}=s,h=f.primitiveBuffer,u=f.primitiveBufferStride,l=new Float32Array(6);let d=!1;const y=new Xi;return Wi(t,e,i,y.boundingData,l),_(y,e,i,l),y;function m(g){c&&c(g/i)}function _(g,p,x,b=null,w=0){if(!d&&w>=n&&(d=!0,r&&console.warn(`BVH: Max depth of ${n} reached when generating BVH. Consider increasing maxDepth.`)),x<=a||w>=n)return m(p+x),g.offset=p,g.count=x,g;const S=jn(g.boundingData,b,t,p,x,o);if(S.axis===-1)return m(p+x),g.offset=p,g.count=x,g;const z=tr(h,u,t,p,x,S);if(z===p||z===p+x)m(p+x),g.offset=p,g.count=x;else{g.splitAxis=S.axis;const A=new Xi,P=p,B=z-p;g.left=A,Wi(t,P,B,A.boundingData,l),_(A,P,B,l,w+1);const C=new Xi,T=z,E=x-B;g.right=C,Wi(t,T,E,C.boundingData,l),_(C,T,E,l,w+1)}return g}}function nr(f,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=f.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,f.computePrimitiveBounds(r.offset,r.count,a),f._roots=i.map(o=>{const c=sr(f,a,o.offset,o.count,t),h=Zi(c),u=new e($*h);return ir(0,c,u),u})}let Ct,oe;const ae=[],ei=new Ii(()=>new J);function rr(f,t,e,i,s,n){Ct=ei.getPrimitive(),oe=ei.getPrimitive(),ae.push(Ct,oe),V.setBuffer(f._roots[t]);const r=Hi(0,f.geometry,e,i,s,n);V.clearBuffer(),ei.releasePrimitive(Ct),ei.releasePrimitive(oe),ae.pop(),ae.pop();const a=ae.length;return a>0&&(oe=ae[a-1],Ct=ae[a-2]),r}function Hi(f,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=V;let h=f*2;if(q(h,o)){const l=H(f,c),d=Q(h,o);return k(f,a,Ct),i(l,d,!1,r,n+f/L,Ct)}else{let B=function(T){const{uint16Array:E,uint32Array:I}=V;let F=T*2;for(;!q(F,E);)T=W(T),F=T*2;return H(T,I)},C=function(T){const{uint16Array:E,uint32Array:I}=V;let F=T*2;for(;!q(F,E);)T=X(T,I),F=T*2;return H(T,I)+Q(F,E)};const l=W(f),d=X(f,c);let y=l,m=d,_,g,p,x;if(s&&(p=Ct,x=oe,k(y,a,p),k(m,a,x),_=s(p),g=s(x),g<_)){y=d,m=l;const T=_;_=g,g=T,p=x}p||(p=Ct,k(y,a,p));const b=q(y*2,o),w=e(p,b,_,r+1,n+y/L);let S;if(w===ms){const T=B(y),I=C(y)-T;S=i(T,I,!0,r+1,n+y/L,p)}else S=w&&Hi(y,t,e,i,s,n,r+1);if(S)return!0;x=oe,k(m,a,x);const z=q(m*2,o),A=e(x,z,g,r+1,n+m/L);let P;if(A===ms){const T=B(m),I=C(m)-T;P=i(T,I,!0,r+1,n+m/L,x)}else P=A&&Hi(m,t,e,i,s,n,r+1);return!!P}}const Be=new V.constructor,ii=new V.constructor,Et=new Ii(()=>new J),ce=new J,he=new J,Ji=new J,Gi=new J;let Qi=!1;function or(f,t,e,i){if(Qi)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Qi=!0;const s=f._roots,n=t._roots;let r,a=0,o=0;const c=new O().copy(e).invert();for(let h=0,u=s.length;h<u;h++){Be.setBuffer(s[h]),o=0;const l=Et.getPrimitive();k(0,Be.float32Array,l),l.applyMatrix4(c);for(let d=0,y=n.length;d<y&&(ii.setBuffer(n[d]),r=ht(0,0,e,c,i,a,o,0,0,l),ii.clearBuffer(),o+=n[d].byteLength/$,!r);d++);if(Et.releasePrimitive(l),Be.clearBuffer(),a+=s[h].byteLength/$,r)break}return Qi=!1,r}function ht(f,t,e,i,s,n=0,r=0,a=0,o=0,c=null,h=!1){let u,l;h?(u=ii,l=Be):(u=Be,l=ii);const d=u.float32Array,y=u.uint32Array,m=u.uint16Array,_=l.float32Array,g=l.uint32Array,p=l.uint16Array,x=f*2,b=t*2,w=q(x,m),S=q(b,p);let z=!1;if(S&&w)h?z=s(H(t,g),Q(t*2,p),H(f,y),Q(f*2,m),o,r+t/L,a,n+f/L):z=s(H(f,y),Q(f*2,m),H(t,g),Q(t*2,p),a,n+f/L,o,r+t/L);else if(S){const A=Et.getPrimitive();k(t,_,A),A.applyMatrix4(e);const P=W(f),B=X(f,y);k(P,d,ce),k(B,d,he);const C=A.intersectsBox(ce),T=A.intersectsBox(he);z=C&&ht(t,P,i,e,s,r,n,o,a+1,A,!h)||T&&ht(t,B,i,e,s,r,n,o,a+1,A,!h),Et.releasePrimitive(A)}else{const A=W(t),P=X(t,g);k(A,_,Ji),k(P,_,Gi);const B=c.intersectsBox(Ji),C=c.intersectsBox(Gi);if(B&&C)z=ht(f,A,e,i,s,n,r,a,o+1,c,h)||ht(f,P,e,i,s,n,r,a,o+1,c,h);else if(B)if(w)z=ht(f,A,e,i,s,n,r,a,o+1,c,h);else{const T=Et.getPrimitive();T.copy(Ji).applyMatrix4(e);const E=W(f),I=X(f,y);k(E,d,ce),k(I,d,he);const F=T.intersectsBox(ce),U=T.intersectsBox(he);z=F&&ht(A,E,i,e,s,r,n,o,a+1,T,!h)||U&&ht(A,I,i,e,s,r,n,o,a+1,T,!h),Et.releasePrimitive(T)}else if(C)if(w)z=ht(f,P,e,i,s,n,r,a,o+1,c,h);else{const T=Et.getPrimitive();T.copy(Gi).applyMatrix4(e);const E=W(f),I=X(f,y);k(E,d,ce),k(I,d,he);const F=T.intersectsBox(ce),U=T.intersectsBox(he);z=F&&ht(P,E,i,e,s,r,n,o,a+1,T,!h)||U&&ht(P,I,i,e,s,r,n,o,a+1,T,!h),Et.releasePrimitive(T)}}return z}const Vs=new J,le=new Float32Array(6);class ar{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...gs,...t},nr(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0;for(let u=t,l=t+e;u<l;u++){this.writePrimitiveBounds(u,le,0);const[d,y,m,_,g,p]=le;d<n&&(n=d),_>o&&(o=_),y<r&&(r=y),g>c&&(c=g),m<a&&(a=m),p>h&&(h=p)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=c,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,le,0);const[a,o,c,h,u,l]=le,d=(a+h)/2,y=(o+u)/2,m=(c+l)/2,_=(h-a)/2,g=(u-o)/2,p=(l-c)/2,x=(n-s)*6;i[x+0]=d,i[x+1]=_+(Math.abs(d)+_)*Le,i[x+2]=y,i[x+3]=g+(Math.abs(y)+g)*Le,i[x+4]=m,i[x+5]=p+(Math.abs(m)+p)*Le}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/$;for(let c=0;c<o;c++){const h=L*c,u=2*h;q(u,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){const i=this._roots[e],s=new Uint32Array(i),n=new Uint16Array(i);r(0);function r(a,o=0){const c=a*2,h=q(c,n);if(h){const u=s[a+6],l=n[c+14];t(o,h,new Float32Array(i,a*4,6),u,l)}else{const u=W(a),l=X(a,s),d=Ri(a,s);t(o,h,new Float32Array(i,a*4,6),d)||(r(u,o+1),r(l,o+1))}}}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/$;for(let c=o-1;c>=0;c--){const h=c*L,u=h*2;if(q(u,r)){const d=H(h,n),y=Q(u,r);this.writePrimitiveRangeBounds(d,y,le,0),a.set(le,h)}else{const d=W(h),y=X(h,n);for(let m=0;m<3;m++){const _=a[d+m],g=a[d+m+3],p=a[y+m],x=a[y+m+3];a[h+m]=_<p?_:p,a[h+m+3]=g>x?g:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{k(0,new Float32Array(i),Vs),t.union(Vs)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const u=s;s=(l,d,y,m,_)=>u(l,d,y,m,_)?!0:a(l,d,this,n,y,m,r)}else s||(n?s=(u,l,d,y)=>a(u,l,this,n,d,y,r):s=(u,l,d)=>d);let o=!1,c=0;const h=this._roots;for(let u=0,l=h.length;u<l;u++){const d=h[u];if(o=rr(this,u,i,s,e,c),o)break;c+=d.byteLength/$}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return or(this,t,e,s)}}function cr(f,t){const e=f[f.length-1],i=e.offset+e.count>2**16,s=f.reduce((c,h)=>c+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let c=0;c<f.length;c++){const{offset:h,count:u}=f[c];for(let l=0;l<u;l++)a[o+l]=h+l;o+=u}return a}class hr extends ar{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Gn())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...gs,...e},e[Ci]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Ps(e,t.range,i),n=cr(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else In(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new J))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ps(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}const si=new G,ni=new rn,Us=new M,ks=new O,Ns=new M,ji=["getX","getY","getZ"];class Te extends hr{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new Te(e,{...i,[Ci]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const h=new lt(t.index,1,!1);e.setIndex(h)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return a;function o(c){for(let h=0;h<c.length;h++){const u=c[h],l=new Uint32Array(u),d=new Uint16Array(u);for(let y=0,m=u.byteLength/$;y<m;y++){const _=L*y,g=2*_;q(g,d)||(l[_+6]=l[_+6]/L-y)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),e={...e,maxLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,c=(n?n[t]:t)*3;let h=c+0,u=c+1,l=c+2;a&&(h=a[h],u=a[u],l=a[l]);for(let d=0;d<3;d++){const y=r[ji[d]](h),m=r[ji[d]](u),_=r[ji[d]](l);let g=y;m<g&&(g=m),_<g&&(g=_);let p=y;m>p&&(p=m),_>p&&(p=_),e[i+d]=g,e[i+d+3]=p}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=r.array,h=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const l=["getX","getY","getZ"],d=i.offset;for(let y=t,m=t+e;y<m;y++){const g=(n?n[y]:y)*3,p=(y-d)*6;let x=g+0,b=g+1,w=g+2;a&&(x=a[x],b=a[b],w=a[w]),o||(x=x*u+h,b=b*u+h,w=w*u+h);for(let S=0;S<3;S++){let z,A,P;o?(z=r[l[S]](x),A=r[l[S]](b),P=r[l[S]](w)):(z=c[x+S],A=c[b+S],P=c[w+S]);let B=z;A<B&&(B=A),P<B&&(B=P);let C=z;A>C&&(C=A),P>C&&(C=P);const T=(C-B)/2,E=S*2;i[p+E+0]=B+T,i[p+E+1]=T+(Math.abs(B)+T)*Le}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;ks.copy(t.matrixWorld).invert(),ni.copy(e.ray).applyMatrix4(ks),Ns.setFromMatrixScale(t.matrixWorld),Us.copy(ni.direction).multiply(Ns);const n=Us.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(ni,s,r,a);o=Is(o,t,e),o&&i.push(o)}else{const o=this.raycast(ni,s,r,a);for(let c=0,h=o.length;c<h;c++){const u=Is(o[c],t,e);u&&i.push(u)}}return i}refit(t=null){return(this.indirect?qn:Mn)(this,t)}raycast(t,e=0,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?On:Tn;for(let o=0,c=n.length;o<c;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=0,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?Wn:Cn;for(let o=0,c=n.length;o<c;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?Xn:Vn;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=nt.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Bn:_n});return nt.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=nt.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,c=this.indirect?y=>{const m=this.resolveTriangleIndex(y);D(r,m*3,a,o)}:y=>{D(r,y*3,a,o)},h=nt.getPrimitive(),u=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?y=>{const m=t.resolveTriangleIndex(y);D(h,m*3,u,l)}:y=>{D(h,y*3,u,l)};if(n){if(!(t instanceof Te))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const y=(m,_,g,p,x,b,w,S)=>{for(let z=g,A=g+p;z<A;z++){d(z),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let P=m,B=m+_;P<B;P++)if(c(P),r.needsUpdate=!0,n(r,h,P,z,x,b,w,S))return!0}return!1};if(s){const m=s;s=function(_,g,p,x,b,w,S,z){return m(_,g,p,x,b,w,S,z)?!0:y(_,g,p,x,b,w,S,z)}}else s=y}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return si.set(t.min,t.max,e),si.needsUpdate=!0,this.shapecast({intersectsBounds:i=>si.intersectsBox(i),intersectsTriangle:i=>si.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Jn:Ln)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return pn(this,t,e,i,s)}}self.onmessage=({data:f})=>{let t=performance.now();function e(r){r=Math.min(r,1);const a=performance.now();a-t>=10&&r!==1&&(self.postMessage({error:null,serialized:null,position:null,progress:r}),t=a)}const{index:i,position:s,options:n}=f;try{const r=new Mi;if(r.setAttribute("position",new lt(s,3,!1)),i&&r.setIndex(new lt(i,1,!1)),n.includedProgressCallback&&(n.onProgress=e),n.groups){const h=n.groups;for(const u in h){const l=h[u];r.addGroup(l.start,l.count,l.materialIndex)}}const a=new Te(r,n),o=Te.serialize(a,{copyIndexBuffer:!1});let c=[s.buffer,...o.roots];o.index&&c.push(o.index.buffer),c=c.filter(h=>typeof SharedArrayBuffer>"u"||!(h instanceof SharedArrayBuffer)),a._indirectBuffer&&c.push(o.indirectBuffer.buffer),self.postMessage({error:null,serialized:o,position:s,progress:1},c)}catch(r){self.postMessage({error:r,serialized:null,position:null,progress:1})}}})();
|