babylon.quarks 0.23.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -0
- package/dist/babylon.quarks.cjs +1 -1
- package/dist/babylon.quarks.cjs.map +1 -1
- package/dist/babylon.quarks.esm.js +1 -1
- package/dist/babylon.quarks.esm.js.map +1 -1
- package/dist/babylon.quarks.umd.min.js +1 -1
- package/dist/babylon.quarks.umd.min.js.map +1 -1
- package/dist/types/index.d.ts +529 -20
- package/package.json +2 -2
- package/src/BatchedRenderer.ts +146 -2
- package/src/EffectPool.ts +165 -0
- package/src/MeshSurfaceEmitter.ts +4 -4
- package/src/ParticleEmitter.ts +2 -1
- package/src/ParticleSystem.ts +592 -15
- package/src/QuarksUtil.ts +55 -7
- package/src/SpriteBatch.ts +127 -3
- package/src/TrailBatch.ts +49 -12
- package/src/VFXBatch.ts +154 -3
- package/src/index.ts +4 -1
- package/src/instanceSort.ts +121 -0
- package/src/shaders/chunks/fog.ts +127 -0
- package/src/shaders/local_particle_physics_vert.glsl.ts +4 -0
- package/src/shaders/local_particle_physics_vert.wgsl.ts +4 -0
- package/src/shaders/particle_frag.glsl.ts +4 -0
- package/src/shaders/particle_frag.wgsl.ts +4 -0
- package/src/shaders/particle_physics_frag.glsl.ts +4 -0
- package/src/shaders/particle_physics_frag.wgsl.ts +4 -0
- package/src/shaders/particle_vert.glsl.ts +23 -4
- package/src/shaders/particle_vert.wgsl.ts +23 -4
- package/src/shaders/stretched_bb_particle_vert.glsl.ts +17 -0
- package/src/shaders/stretched_bb_particle_vert.wgsl.ts +18 -1
- package/src/shaders/trail_frag.glsl.ts +4 -0
- package/src/shaders/trail_frag.wgsl.ts +4 -0
- package/src/shaders/trail_vert.glsl.ts +4 -0
- package/src/shaders/trail_vert.wgsl.ts +4 -0
package/dist/babylon.quarks.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@babylonjs/core/Buffers/buffer"),e=require("@babylonjs/core/Meshes/transformNode"),i=require("@babylonjs/core/Engines/constants"),s=require("@babylonjs/core/Materials/shaderMaterial"),r=require("@babylonjs/core/Materials/Textures/rawTexture"),n=require("@babylonjs/core/Maths/math.vector"),o=require("@babylonjs/core/Meshes/mesh"),a=require("@babylonjs/core/Meshes/mesh.vertexData"),h=require("@babylonjs/core/Engines/shaderStore"),l=require("@babylonjs/core/Materials/effect"),c=require("@babylonjs/core/Materials/shaderLanguage"),u=require("@babylonjs/core/Maths/math.color"),d=require("@babylonjs/core/Culling/boundingInfo"),p=require("@babylonjs/core/Materials/Textures/texture"),f=require("@babylonjs/core/Materials/PBR/pbrMaterial"),m=require("@babylonjs/core/Materials/standardMaterial");const y=["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"];let v=1234567;const x=Math.PI/180,g=180/Math.PI;function S(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return(y[255&t]+y[t>>8&255]+y[t>>16&255]+y[t>>24&255]+"-"+y[255&e]+y[e>>8&255]+"-"+y[e>>16&15|64]+y[e>>24&255]+"-"+y[63&i|128]+y[i>>8&255]+"-"+y[i>>16&255]+y[i>>24&255]+y[255&s]+y[s>>8&255]+y[s>>16&255]+y[s>>24&255]).toLowerCase()}function w(t,e,i){return Math.max(e,Math.min(i,t))}function b(t,e){return(t%e+e)%e}function M(t,e,i,s,r){return s+(t-e)*(r-s)/(i-e)}function z(t,e,i){return t!==e?(i-t)/(e-t):0}function _(t,e,i){return(1-i)*t+i*e}function T(t,e,i,s){return _(t,e,1-Math.exp(-i*s))}function P(t,e=1){return e-Math.abs(b(t,2*e)-e)}function V(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*(3-2*t)}function O(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*t*(t*(6*t-15)+10)}function C(t,e){return t+Math.floor(Math.random()*(e-t+1))}function A(t,e){return t+Math.random()*(e-t)}function B(t){return t*(.5-Math.random())}function $(t){void 0!==t&&(v=t);let e=v+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}function F(t){return t*x}function E(t){return t*g}function N(t){return!(t&t-1)&&0!==t}function I(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))}function L(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function R(t,e,i,s,r){const n=Math.cos,o=Math.sin,a=n(i/2),h=o(i/2),l=n((e+s)/2),c=o((e+s)/2),u=n((e-s)/2),d=o((e-s)/2),p=n((s-e)/2),f=o((s-e)/2);switch(r){case"XYX":t.set(a*c,h*u,h*d,a*l);break;case"YZY":t.set(h*d,a*c,h*u,a*l);break;case"ZXZ":t.set(h*u,h*d,a*c,a*l);break;case"XZX":t.set(a*c,h*f,h*p,a*l);break;case"YXY":t.set(h*p,a*c,h*f,a*l);break;case"ZYZ":t.set(h*f,h*p,a*c,a*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function U(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function D(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const q={DEG2RAD:x,RAD2DEG:g,generateUUID:S,clamp:w,euclideanModulo:b,mapLinear:M,inverseLerp:z,lerp:_,damp:T,pingpong:P,smoothstep:V,smootherstep:O,randInt:C,randFloat:A,randFloatSpread:B,seededRandom:$,degToRad:F,radToDeg:E,isPowerOfTwo:N,ceilPowerOfTwo:I,floorPowerOfTwo:L,setQuaternionFromProperEuler:R,normalize:D,denormalize:U};class J{constructor(t=0,e=0,i=0,s=1){this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,r,n,o){let a=i[s+0],h=i[s+1],l=i[s+2],c=i[s+3];const u=r[n+0],d=r[n+1],p=r[n+2],f=r[n+3];if(0===o)return t[e+0]=a,t[e+1]=h,t[e+2]=l,void(t[e+3]=c);if(1===o)return t[e+0]=u,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(c!==f||a!==u||h!==d||l!==p){let t=1-o;const e=a*u+h*d+l*p+c*f,i=e>=0?1:-1,s=1-e*e;if(s>Number.EPSILON){const r=Math.sqrt(s),n=Math.atan2(r,e*i);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*i;if(a=a*t+u*r,h=h*t+d*r,l=l*t+p*r,c=c*t+f*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+l*l+c*c);a*=t,h*=t,l*=t,c*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,s,r,n){const o=i[s],a=i[s+1],h=i[s+2],l=i[s+3],c=r[n],u=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+l*c+a*d-h*u,t[e+1]=a*p+l*u+h*c-o*d,t[e+2]=h*p+l*d+o*u-a*c,t[e+3]=l*p-o*c-a*u-h*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 J(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,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(i/2),l=o(s/2),c=o(r/2),u=a(i/2),d=a(s/2),p=a(r/2);switch(n){case"XYZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"YXZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"ZXY":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"ZYX":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"YZX":this._x=u*l*c+h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c-u*d*p;break;case"XZY":this._x=u*l*c-h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c+u*d*p;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&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],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],l=e[6],c=e[10],u=i+o+c;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(n-s)*t}else if(i>o&&i>c){const t=2*Math.sqrt(1+i-o-c);this._w=(l-a)/t,this._x=.25*t,this._y=(s+n)/t,this._z=(r+h)/t}else if(o>c){const t=2*Math.sqrt(1+o-i-c);this._w=(r-h)/t,this._x=(s+n)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+c-i-o);this._w=(n-s)/t,this._x=(r+h)/t,this._y=(a+l)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(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(w(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(0===i)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 0===t?(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,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,l=e._w;return this._x=i*l+n*o+s*h-r*a,this._y=s*l+n*a+r*o-i*h,this._z=r*l+n*h+i*a-s*o,this._w=n*l-i*o-s*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const i=this._x,s=this._y,r=this._z,n=this._w;let o=n*t._w+i*t._x+s*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=i,this._y=s,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*i+e*this._x,this._y=t*s+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),l=Math.atan2(h,o),c=Math.sin((1-e)*l)/h,u=Math.sin(e*l)/h;return this._w=n*c+this._w*u,this._x=i*c+this._x*u,this._y=s*c+this._y*u,this._z=r*c+this._z*u,this._onChangeCallback(),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),r=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),r*Math.sin(e),r*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}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}}J.prototype.isQuaternion=!0;class k{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return void 0===i&&(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 k(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(W.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(W.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[3]*i+r[6]*s,this.y=r[1]*e+r[4]*i+r[7]*s,this.z=r[2]*e+r[5]*i+r[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,r=t.elements,n=1/(r[3]*e+r[7]*i+r[11]*s+r[15]);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}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*s-o*i),l=2*(o*e-r*s),c=2*(r*i-n*e);return this.x=e+a*h+n*c-o*l,this.y=i+a*l+o*h-r*c,this.z=s+a*c+r*l-n*h,this}transformDirection(t){const e=this.x,i=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s,this.y=r[1]*e+r[5]*i+r[9]*s,this.z=r[2]*e+r[6]*i+r[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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}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,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=s*a-r*o,this.y=r*n-i*a,this.z=i*o-s*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Q.copy(this).projectOnVector(t),this.sub(Q)}reflect(t){return this.sub(Q.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(w(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)}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}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,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,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}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}k.prototype.isVector3=!0;const Q=new k,W=new J,G=2e3,j=2001;class Y{constructor(t,e,i,s,r,n,o,a,h,l,c,u,d,p,f,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,i,s,r,n,o,a,h,l,c,u,d,p,f,m)}extractPosition(t){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(t)}multiplyToArray(t,e,i){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(t){return this.makeRotationFromQuaternion(t)}set(t,e,i,s,r,n,o,a,h,l,c,u,d,p,f,m){const y=this.elements;return y[0]=t,y[4]=e,y[8]=i,y[12]=s,y[1]=r,y[5]=n,y[9]=o,y[13]=a,y[2]=h,y[6]=l,y[10]=c,y[14]=u,y[3]=d,y[7]=p,y[11]=f,y[15]=m,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 Y).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 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){const e=this.elements,i=t.elements,s=1/X.setFromMatrixColumn(t,0).length(),r=1/X.setFromMatrixColumn(t,1).length(),n=1/X.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]*r,e[5]=i[5]*r,e[6]=i[6]*r,e[7]=0,e[8]=i[8]*n,e[9]=i[9]*n,e[10]=i[10]*n,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,r=t.z,n=Math.cos(i),o=Math.sin(i),a=Math.cos(s),h=Math.sin(s),l=Math.cos(r),c=Math.sin(r);if("XYZ"===t.order){const t=n*l,i=n*c,s=o*l,r=o*c;e[0]=a*l,e[4]=-a*c,e[8]=h,e[1]=i+s*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=s+i*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*l,i=a*c,s=h*l,r=h*c;e[0]=t+r*o,e[4]=s*o-i,e[8]=n*h,e[1]=n*c,e[5]=n*l,e[9]=-o,e[2]=i*o-s,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*l,i=a*c,s=h*l,r=h*c;e[0]=t-r*o,e[4]=-n*c,e[8]=s+i*o,e[1]=i+s*o,e[5]=n*l,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*l,i=n*c,s=o*l,r=o*c;e[0]=a*l,e[4]=s*h-i,e[8]=t*h+r,e[1]=a*c,e[5]=r*h+t,e[9]=i*h-s,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,i=n*h,s=o*a,r=o*h;e[0]=a*l,e[4]=r-t*c,e[8]=s*c+i,e[1]=c,e[5]=n*l,e[9]=-o*l,e[2]=-h*l,e[6]=i*c+s,e[10]=t-r*c}else if("XZY"===t.order){const t=n*a,i=n*h,s=o*a,r=o*h;e[0]=a*l,e[4]=-c,e[8]=h*l,e[1]=t*c+r,e[5]=n*l,e[9]=i*c-s,e[2]=s*c-i,e[6]=o*l,e[10]=r*c+t}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(H,t,K)}lookAt(t,e,i){const s=this.elements;return it.subVectors(t,e),0===it.lengthSq()&&(it.z=1),it.normalize(),tt.crossVectors(i,it),0===tt.lengthSq()&&(1===Math.abs(i.z)?it.x+=1e-4:it.z+=1e-4,it.normalize(),tt.crossVectors(i,it)),tt.normalize(),et.crossVectors(it,tt),s[0]=tt.x,s[4]=et.x,s[8]=it.x,s[1]=tt.y,s[5]=et.y,s[9]=it.y,s[2]=tt.z,s[6]=et.z,s[10]=it.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,r=this.elements,n=i[0],o=i[4],a=i[8],h=i[12],l=i[1],c=i[5],u=i[9],d=i[13],p=i[2],f=i[6],m=i[10],y=i[14],v=i[3],x=i[7],g=i[11],S=i[15],w=s[0],b=s[4],M=s[8],z=s[12],_=s[1],T=s[5],P=s[9],V=s[13],O=s[2],C=s[6],A=s[10],B=s[14],$=s[3],F=s[7],E=s[11],N=s[15];return r[0]=n*w+o*_+a*O+h*$,r[4]=n*b+o*T+a*C+h*F,r[8]=n*M+o*P+a*A+h*E,r[12]=n*z+o*V+a*B+h*N,r[1]=l*w+c*_+u*O+d*$,r[5]=l*b+c*T+u*C+d*F,r[9]=l*M+c*P+u*A+d*E,r[13]=l*z+c*V+u*B+d*N,r[2]=p*w+f*_+m*O+y*$,r[6]=p*b+f*T+m*C+y*F,r[10]=p*M+f*P+m*A+y*E,r[14]=p*z+f*V+m*B+y*N,r[3]=v*w+x*_+g*O+S*$,r[7]=v*b+x*T+g*C+S*F,r[11]=v*M+x*P+g*A+S*E,r[15]=v*z+x*V+g*B+S*N,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],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],l=t[2],c=t[6],u=t[10],d=t[14];return t[3]*(+r*a*c-s*h*c-r*o*u+i*h*u+s*o*d-i*a*d)+t[7]*(+e*a*d-e*h*u+r*n*u-s*n*d+s*h*l-r*a*l)+t[11]*(+e*h*c-e*o*d-r*n*c+i*n*d+r*o*l-i*h*l)+t[15]*(-s*o*l-e*a*c+e*o*u+s*n*c-i*n*u+i*a*l)}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],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=t[9],u=t[10],d=t[11],p=t[12],f=t[13],m=t[14],y=t[15],v=c*m*h-f*u*h+f*a*d-o*m*d-c*a*y+o*u*y,x=p*u*h-l*m*h-p*a*d+n*m*d+l*a*y-n*u*y,g=l*f*h-p*c*h+p*o*d-n*f*d-l*o*y+n*c*y,S=p*c*a-l*f*a-p*o*u+n*f*u+l*o*m-n*c*m,w=e*v+i*x+s*g+r*S;if(0===w)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const b=1/w;return t[0]=v*b,t[1]=(f*u*r-c*m*r-f*s*d+i*m*d+c*s*y-i*u*y)*b,t[2]=(o*m*r-f*a*r+f*s*h-i*m*h-o*s*y+i*a*y)*b,t[3]=(c*a*r-o*u*r-c*s*h+i*u*h+o*s*d-i*a*d)*b,t[4]=x*b,t[5]=(l*m*r-p*u*r+p*s*d-e*m*d-l*s*y+e*u*y)*b,t[6]=(p*a*r-n*m*r-p*s*h+e*m*h+n*s*y-e*a*y)*b,t[7]=(n*u*r-l*a*r+l*s*h-e*u*h-n*s*d+e*a*d)*b,t[8]=g*b,t[9]=(p*c*r-l*f*r-p*i*d+e*f*d+l*i*y-e*c*y)*b,t[10]=(n*f*r-p*o*r+p*i*h-e*f*h-n*i*y+e*o*y)*b,t[11]=(l*o*r-n*c*r-l*i*h+e*c*h+n*i*d-e*o*d)*b,t[12]=S*b,t[13]=(l*f*s-p*c*s+p*i*u-e*f*u-l*i*m+e*c*m)*b,t[14]=(p*o*s-n*f*s-p*i*a+e*f*a+n*i*m-e*o*m)*b,t[15]=(n*c*s-l*o*s+l*i*a-e*c*a-n*i*u+e*o*u)*b,this}scale(t){const e=this.elements,i=t.x,s=t.y,r=t.z;return e[0]*=i,e[4]*=s,e[8]*=r,e[1]*=i,e[5]*=s,e[9]*=r,e[2]*=i,e[6]*=s,e[10]*=r,e[3]*=i,e[7]*=s,e[11]*=r,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),r=1-i,n=t.x,o=t.y,a=t.z,h=r*n,l=r*o;return this.set(h*n+i,h*o-s*a,h*a+s*o,0,h*o+s*a,l*o+i,l*a-s*n,0,h*a-s*o,l*a+s*n,r*a*a+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,r,n){return this.set(1,i,r,0,t,1,n,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,l=n+n,c=o+o,u=r*h,d=r*l,p=r*c,f=n*l,m=n*c,y=o*c,v=a*h,x=a*l,g=a*c,S=i.x,w=i.y,b=i.z;return s[0]=(1-(f+y))*S,s[1]=(d+g)*S,s[2]=(p-x)*S,s[3]=0,s[4]=(d-g)*w,s[5]=(1-(u+y))*w,s[6]=(m+v)*w,s[7]=0,s[8]=(p+x)*b,s[9]=(m-v)*b,s[10]=(1-(u+f))*b,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;let r=X.set(s[0],s[1],s[2]).length();const n=X.set(s[4],s[5],s[6]).length(),o=X.set(s[8],s[9],s[10]).length();this.determinant()<0&&(r=-r),t.x=s[12],t.y=s[13],t.z=s[14],Z.copy(this);const a=1/r,h=1/n,l=1/o;return Z.elements[0]*=a,Z.elements[1]*=a,Z.elements[2]*=a,Z.elements[4]*=h,Z.elements[5]*=h,Z.elements[6]*=h,Z.elements[8]*=l,Z.elements[9]*=l,Z.elements[10]*=l,e.setFromRotationMatrix(Z),i.x=r,i.y=n,i.z=o,this}makePerspective(t,e,i,s,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),l=2*r/(i-s),c=(e+t)/(e-t),u=(i+s)/(i-s);let d,p;if(o===G)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==j)throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=c,a[12]=0,a[1]=0,a[5]=l,a[9]=u,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,i,s,r,n,o=2e3){const a=this.elements,h=1/(e-t),l=1/(i-s),c=1/(n-r),u=(e+t)*h,d=(i+s)*l;let p,f;if(o===G)p=(n+r)*c,f=-2*c;else{if(o!==j)throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*c,f=-1*c}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-u,a[1]=0,a[5]=2*l,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=f,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<16;t++)if(e[t]!==i[t])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}}Y.prototype.isMatrix4=!0;const X=new k,Z=new Y,H=new k(0,0,0),K=new k(1,1,1),tt=new k,et=new k,it=new k,st=new Y,rt=new J;class nt{constructor(t=0,e=0,i=0,s=nt.DEFAULT_ORDER){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 nt(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,r=s[0],n=s[4],o=s[8],a=s[1],h=s[5],l=s[9],c=s[2],u=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(w(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,h),this._z=0);break;case"YXZ":this._x=Math.asin(-w(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-c,r),this._z=0);break;case"ZXY":this._x=Math.asin(w(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-w(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(w(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-c,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-w(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,d),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===i&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return st.makeRotationFromQuaternion(t),this.setFromRotationMatrix(st,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return rt.setFromEuler(this),this.setFromQuaternion(rt,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],void 0!==t[3]&&(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(t){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}nt.DEFAULT_ORDER="XYZ",nt.prototype.isEuler=!0;class ot{constructor(t,e,i,s,r,n,o,a,h){this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,i,s,r,n,o,a,h)}set(t,e,i,s,r,n,o,a,h){const l=this.elements;return l[0]=t,l[1]=s,l[2]=o,l[3]=e,l[4]=r,l[5]=a,l[6]=i,l[7]=n,l[8]=h,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,r=this.elements,n=i[0],o=i[3],a=i[6],h=i[1],l=i[4],c=i[7],u=i[2],d=i[5],p=i[8],f=s[0],m=s[3],y=s[6],v=s[1],x=s[4],g=s[7],S=s[2],w=s[5],b=s[8];return r[0]=n*f+o*v+a*S,r[3]=n*m+o*x+a*w,r[6]=n*y+o*g+a*b,r[1]=h*f+l*v+c*S,r[4]=h*m+l*x+c*w,r[7]=h*y+l*g+c*b,r[2]=u*f+d*v+p*S,r[5]=u*m+d*x+p*w,r[8]=u*y+d*g+p*b,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],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8];return e*n*l-e*o*h-i*r*l+i*o*a+s*r*h-s*n*a}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=l*n-o*h,u=o*a-l*r,d=h*r-n*a,p=e*c+i*u+s*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=c*f,t[1]=(s*h-l*i)*f,t[2]=(o*i-s*n)*f,t[3]=u*f,t[4]=(l*e-s*a)*f,t[5]=(s*r-o*e)*f,t[6]=d*f,t[7]=(i*a-h*e)*f,t[8]=(n*e-i*r)*f,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,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(i*a,i*h,-i*(a*n+h*o)+n+t,-s*h,s*a,-s*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(at.makeScale(t,e)),this}rotate(t){return this.premultiply(at.makeRotation(-t)),this}translate(t,e){return this.premultiply(at.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 t=0;t<9;t++)if(e[t]!==i[t])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 ot).fromArray(this.elements)}}ot.prototype.isMatrix3=!0;const at=new ot,ht=new Float32Array(4);class lt extends J{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const ct=lt.prototype;ct.data=ht,ct.offset=0,Object.defineProperties(lt.prototype,{_x:{get(){return this.data[this.offset]},set(t){this.data[this.offset]=t}},_y:{get(){return this.data[this.offset+1]},set(t){this.data[this.offset+1]=t}},_z:{get(){return this.data[this.offset+2]},set(t){this.data[this.offset+2]=t}},_w:{get(){return this.data[this.offset+3]},set(t){this.data[this.offset+3]=t}}});class ut{constructor(t=0,e=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 ut(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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}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(0===e)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(w(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}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*i-n*s+t.x,this.y=r*s+n*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}ut.isVector2=!0;const dt=new Float32Array(3);class pt extends k{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const ft=pt.prototype;ft.data=dt,ft.offset=0,Object.defineProperties(pt.prototype,{x:{get(){return this.data[this.offset]},set(t){this.data[this.offset]=t}},y:{get(){return this.data[this.offset+1]},set(t){this.data[this.offset+1]=t}},z:{get(){return this.data[this.offset+2]},set(t){this.data[this.offset+2]=t}}});class mt{constructor(t=0,e=0,i=0,s=1){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 mt(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}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,r=this.w,n=t.elements;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.w=n[3]*e+n[7]*i+n[11]*s+n[15]*r,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,r;const n=.01,o=.1,a=t.elements,h=a[0],l=a[4],c=a[8],u=a[1],d=a[5],p=a[9],f=a[2],m=a[6],y=a[10];if(Math.abs(l-u)<n&&Math.abs(c-f)<n&&Math.abs(p-m)<n){if(Math.abs(l+u)<o&&Math.abs(c+f)<o&&Math.abs(p+m)<o&&Math.abs(h+d+y-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,v=(y+1)/2,x=(l+u)/4,g=(c+f)/4,S=(p+m)/4;return t>a&&t>v?t<n?(i=0,s=.707106781,r=.707106781):(i=Math.sqrt(t),s=x/i,r=g/i):a>v?a<n?(i=.707106781,s=0,r=.707106781):(s=Math.sqrt(a),i=x/s,r=S/s):v<n?(i=.707106781,s=.707106781,r=0):(r=Math.sqrt(v),i=g/r,s=S/r),this.set(i,s,r,e),this}let v=Math.sqrt((m-p)*(m-p)+(c-f)*(c-f)+(u-l)*(u-l));return Math.abs(v)<.001&&(v=1),this.x=(m-p)/v,this.y=(c-f)/v,this.z=(u-l)/v,this.w=Math.acos((h+d+y-1)/2),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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}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}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}}mt.prototype.isVector4=!0;const yt=new Float32Array(4);class vt extends mt{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const xt=vt.prototype;let gt;function St(){return gt}xt.data=yt,xt.offset=0,Object.defineProperties(vt.prototype,{x:{get(){return this.data[this.offset]},set(t){this.data[this.offset]=t}},y:{get(){return this.data[this.offset+1]},set(t){this.data[this.offset+1]=t}},z:{get(){return this.data[this.offset+2]},set(t){this.data[this.offset+2]=t}},w:{get(){return this.data[this.offset+3]},set(t){this.data[this.offset+3]=t}}});class wt{constructor(t,e){this.resolver=t,this.bounce=e,this.type="ApplyCollision",this.tempV=new k}initialize(t){}update(t,e){this.resolver&&this.resolver.resolve(t.position,this.tempV)&&t.velocity.reflect(this.tempV).multiplyScalar(this.bounce)}frameUpdate(t){}toJSON(){return{type:this.type,bounce:this.bounce}}static fromJSON(t){return new wt(St(),t.bounce)}clone(){return new wt(this.resolver,this.bounce)}reset(){}}class bt{constructor(t){this.value=t,this.type="value"}startGen(t){}genValue(t){return this.value}toJSON(){return{type:"ConstantValue",value:this.value}}static fromJSON(t){return new bt(t.value)}clone(){return new bt(this.value)}}class Mt{constructor(t,e){this.a=t,this.b=e,this.indexCount=-1,this.type="value"}startGen(t){this.indexCount=t.length,t.push(Math.random())}genValue(t){return-1===this.indexCount&&this.startGen(t),q.lerp(this.a,this.b,t[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(t){return new Mt(t.a,t.b)}clone(){return new Mt(this.a,this.b)}}class zt{constructor(t,e,i,s){this.p=[t,e,i,s]}genValue(t){const e=this.p,i=t*t,s=1-t,r=s*s;return e[0]*r*s+e[1]*r*t*3+e[2]*s*i*3+e[3]*i*t}derivativeCoefficients(t){const e=[];for(let i=t,s=i.length-1;s>0;s--){const t=[];for(let e=0;e<s;e++){const r=s*(i[e+1]-i[e]);t.push(r)}e.push(t),i=t}return e}getSlope(t){const e=this.derivativeCoefficients(this.p)[0],i=1-t,s=i*t*2,r=t*t;return i*i*e[0]+s*e[1]+r*e[2]}controlCurve(t,e){this.p[1]=t/3+this.p[0],this.p[2]=this.p[3]-e/3}hull(t){let e,i=this.p,s=[],r=0,n=0,o=0;const a=[];for(a[r++]=i[0],a[r++]=i[1],a[r++]=i[2],a[r++]=i[3];i.length>1;){for(s=[],n=0,o=i.length-1;n<o;n++)e=t*i[n]+(1-t)*i[n+1],a[r++]=e,s.push(e);i=s}return a}split(t){const e=this.hull(t);return{left:new zt(e[0],e[4],e[7],e[9]),right:new zt(e[9],e[8],e[6],e[3]),span:e}}clone(){return new zt(this.p[0],this.p[1],this.p[2],this.p[3])}toJSON(){return{p0:this.p[0],p1:this.p[1],p2:this.p[2],p3:this.p[3]}}static fromJSON(t){return new zt(t.p0,t.p1,t.p2,t.p3)}}class _t{constructor(){this.functions=new Array}findFunction(t){const e=this.functions,i=e.length-1;if(i<=0)return 0===i&&t>=e[0][1]&&t<=1?0:-1;let s=0,r=i;for(;s+1<r;){const i=s+r>>1;if(t<e[i][1])r=i-1;else{if(!(t>this.getEndX(i)))return i;s=i+1}}for(let i=s;i<=r;i++)if(t>=e[i][1]&&t<=this.getEndX(i))return i;return-1}getStartX(t){return this.functions[t][1]}setStartX(t,e){t>0&&(this.functions[t][1]=e)}getEndX(t){return t+1<this.functions.length?this.functions[t+1][1]:1}setEndX(t,e){t+1<this.functions.length&&(this.functions[t+1][1]=e)}insertFunction(t,e){const i=this.findFunction(t);this.functions.splice(i+1,0,[e,t])}removeFunction(t){return this.functions.splice(t,1)[0][0]}getFunction(t){return this.functions[t][0]}setFunction(t,e){this.functions[t][0]=e}get numOfFunctions(){return this.functions.length}}class Tt extends _t{constructor(t=[[new zt(0,1/3,1/3*2,1),0]]){super(),this.table=null,this.tableSignature=null,this.type="function",this.functions=t}refreshTable(){const t=this.functions,e=t.length;if(0===e)return this.table=null,void(this.tableSignature=null);const i=5*e;let s=this.tableSignature,r=null===s||s.length!==i;r&&(s=new Float64Array(i));for(let i=0,n=0;i<e;i++,n+=5){const e=t[i][0].p,o=t[i][1];r||(r=s[n]!==e[0]||s[n+1]!==e[1]||s[n+2]!==e[2]||s[n+3]!==e[3]||s[n+4]!==o),r&&(s[n]=e[0],s[n+1]=e[1],s[n+2]=e[2],s[n+3]=e[3],s[n+4]=o)}if(!r&&null!==this.table)return;this.tableSignature=s;const n=Tt.TABLE_SIZE,o=null!==this.table&&this.table.length===n?this.table:new Float32Array(n),a=1/(n-1);for(let t=0;t<n;t++)o[t]=this.genValueExact(t*a);this.table=o}sampledTable(){return this.table}clearTable(){this.table=null,this.tableSignature=null}genValue(t,e=0){const i=this.table;if(null!==i){const t=i.length-1;if(e<=0)return i[0];if(e>=1)return i[t];const s=e*t,r=0|s,n=s-r,o=i[r];return o+(i[r+1]-o)*n}return this.genValueExact(e)}genValueExact(t){const e=this.functions,i=e.length;if(0===i)return 0;const s=this.findFunction(t);if(-1===s)return t<e[0][1]?e[0][0].genValue(0):e[i-1][0].genValue(1);const r=e[s][1],n=(s+1<i?e[s+1][1]:1)-r;return e[s][0].genValue(n>0?(t-r)/n:0)}toSVG(t,e){if(e<1)return"";let i=["M",0,this.functions[0][0].p[0]].join(" ");for(let s=1/e;s<=1;s+=1/e)i=[i,"L",s*t,this.genValue(void 0,s)].join(" ");return i}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([t,e])=>({function:t.toJSON(),start:e}))}}static fromJSON(t){return new Tt(t.functions.map(t=>[zt.fromJSON(t.function),t.start]))}clone(){return new Tt(this.functions.map(([t,e])=>[t.clone(),e]))}startGen(t){}}function Pt(t){switch(t.type){case"ConstantValue":return bt.fromJSON(t);case"IntervalValue":return Mt.fromJSON(t);case"PiecewiseBezier":return Tt.fromJSON(t);default:return new bt(0)}}Tt.TABLE_SIZE=257;class Vt{constructor(t,e){this.axis=t,this.angle=e,this.type="rotation"}startGen(t){this.angle.startGen(t)}genValue(t,e,i,s){return e.setFromAxisAngle(this.axis,this.angle.genValue(t,s)*i)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(t){return new Vt(new k(t.axis.x,t.axis.y,t.axis.z),Pt(t.angle))}clone(){return new Vt(this.axis.clone(),this.angle.clone())}}const Ot=t=>({r:t.x,g:t.y,b:t.z,a:t.w}),Ct=t=>new mt(t.r,t.g,t.b,t.a),At=(t,e)=>{switch(e){case"Vector3":return new k(t.x,t.y,t.z);case"Vector4":return new mt(t.x,t.y,t.z,t.w);case"Color":return new k(t.r,t.g,t.b);default:return t}},Bt=(t,e)=>{switch(e){case"Vector3":return{x:t.x,y:t.y,z:t.z};case"Vector4":return{x:t.x,y:t.y,z:t.z,w:t.w};case"Color":return{r:t.x,g:t.y,b:t.z};default:return t}};class $t{constructor(t,e){this.a=t,this.b=e,this.indexCount=-1,this.type="value"}startGen(t){this.indexCount=t.length,t.push(Math.random())}genColor(t,e){return-1===this.indexCount&&this.startGen(t),e.copy(this.a).lerp(this.b,t[this.indexCount])}toJSON(){return{type:"ColorRange",a:Ot(this.a),b:Ot(this.b)}}static fromJSON(t){return new $t(Ct(t.a),Ct(t.b))}clone(){return new $t(this.a.clone(),this.b.clone())}}class Ft{constructor(t,e){this.subType=e,this.type="function",this.keys=t}findKey(t){const e=this.keys,i=e.length-1;if(i<=0)return 0===i&&t>=e[0][1]&&t<=1?0:-1;if(1===i)return t<e[0][1]||t>1?-1:t<=e[1][1]?0:1;let s=0,r=i;for(;s+1<r;){const i=s+r>>1;if(t<e[i][1])r=i-1;else{if(!(t>this.getEndX(i)))return i;s=i+1}}for(let i=s;i<=r;i++)if(t>=e[i][1]&&t<=this.getEndX(i))return i;return-1}getStartX(t){return this.keys[t][1]}getEndX(t){return t+1<this.keys.length?this.keys[t+1][1]:1}genValue(t,e){const i=this.keys,s=this.findKey(e),r=i.length-1;if("Number"===this.subType){if(-1===s)return i[0][0];if(s>=r)return i[r][0];const t=i[s][1],n=i[s][0],o=i[s+1][1]-t;return(i[s+1][0]-n)*(o>0?(e-t)/o:0)+n}{if(-1===s)return t.copy(i[0][0]);if(s>=r)return t.copy(i[r][0]);const n=i[s][1],o=i[s+1][1]-n;return t.copy(i[s][0]).lerp(i[s+1][0],o>0?(e-n)/o:0)}}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([t,e])=>({value:Bt(t,this.subType),pos:e}))}}static fromJSON(t){return new Ft(t.keys.map(e=>[At(e.value,t.subType),e.pos]),t.subType)}clone(){return"Number"===this.subType?new Ft(this.keys.map(([t,e])=>[t,e]),this.subType):new Ft(this.keys.map(([t,e])=>[t.clone(),e]),this.subType)}}const Et=new mt;class Nt{constructor(t=[[new k(0,0,0),0],[new k(1,1,1),0]],e=[[1,0],[1,1]]){this.table=null,this.tableSignature=null,this.type="function",this.color=new Ft(t,"Color"),this.alpha=new Ft(e,"Number")}refreshTable(){const t=this.color.keys,e=this.alpha.keys,i=4*t.length+2*e.length;let s=this.tableSignature,r=null===s||s.length!==i;r&&(s=new Float64Array(i));let n=0;for(let e=0;e<t.length;e++,n+=4){const i=t[e][0],o=t[e][1];r||(r=s[n]!==i.x||s[n+1]!==i.y||s[n+2]!==i.z||s[n+3]!==o),r&&(s[n]=i.x,s[n+1]=i.y,s[n+2]=i.z,s[n+3]=o)}for(let t=0;t<e.length;t++,n+=2){const i=e[t][0],o=e[t][1];r||(r=s[n]!==i||s[n+1]!==o),r&&(s[n]=i,s[n+1]=o)}if(!r&&null!==this.table)return;this.tableSignature=s;const o=Nt.TABLE_SIZE,a=null!==this.table&&this.table.length===4*o?this.table:new Float32Array(4*o),h=1/(o-1),l=Et;for(let t=0;t<o;t++){this.genColorExact(l,t*h);const e=4*t;a[e]=l.x,a[e+1]=l.y,a[e+2]=l.z,a[e+3]=l.w}this.table=a}sampledTable(){return this.table}clearTable(){this.table=null,this.tableSignature=null}genColor(t,e,i){const s=this.table;if(null!==s){const t=Nt.TABLE_SIZE-1;if(i<=0)return e.x=s[0],e.y=s[1],e.z=s[2],e.w=s[3],e;if(i>=1){const i=4*t;return e.x=s[i],e.y=s[i+1],e.z=s[i+2],e.w=s[i+3],e}const r=i*t,n=0|r,o=r-n,a=4*n,h=a+4;return e.x=s[a]+(s[h]-s[a])*o,e.y=s[a+1]+(s[h+1]-s[a+1])*o,e.z=s[a+2]+(s[h+2]-s[a+2])*o,e.w=s[a+3]+(s[h+3]-s[a+3])*o,e}return this.genColorExact(e,i)}genColorExact(t,e){const i=this.color.keys,s=i.length-1,r=this.color.findKey(e);let n,o,a;if(-1===r||r>=s){const t=i[-1===r?0:s][0];n=t.x,o=t.y,a=t.z}else{const t=i[r][0],s=i[r+1][0],h=i[r][1],l=i[r+1][1]-h,c=l>0?(e-h)/l:0;n=t.x+(s.x-t.x)*c,o=t.y+(s.y-t.y)*c,a=t.z+(s.z-t.z)*c}const h=this.alpha.keys,l=h.length-1,c=this.alpha.findKey(e);let u;if(-1===c||c>=l)u=h[-1===c?0:l][0];else{const t=h[c][1],i=h[c][0],s=h[c+1][1]-t;u=i+(h[c+1][0]-i)*(s>0?(e-t)/s:0)}return t.x=n,t.y=o,t.z=a,t.w=u,t}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(t){if(t.functions){const e=t.functions.map(t=>[$t.fromJSON(t.function).a,t.start]);return t.functions.length>0&&e.push([$t.fromJSON(t.functions[t.functions.length-1].function).b,1]),new Nt(e.map(t=>[new k(t[0].x,t[0].y,t[0].z),t[1]]),e.map(t=>[t[0].w,t[1]]))}{const e=new Nt;return e.alpha=Ft.fromJSON(t.alpha),e.color=Ft.fromJSON(t.color),e}}clone(){const t=new Nt;return t.alpha=this.alpha.clone(),t.color=this.color.clone(),t}startGen(t){}}Nt.TABLE_SIZE=257;class It{constructor(t,e){this.a=t,this.b=e,this.type="value"}startGen(t){}genColor(t,e){const i=Math.random();return e.copy(this.a).lerp(this.b,i)}toJSON(){return{type:"RandomColor",a:Ot(this.a),b:Ot(this.b)}}static fromJSON(t){return new It(Ct(t.a),Ct(t.b))}clone(){return new It(this.a.clone(),this.b.clone())}}const Lt=new mt;class Rt{constructor(t,e){this.indexCount=0,this.type="function",this.gradient1=t,this.gradient2=e}startGen(t){this.indexCount=t.length,t.push(Math.random())}genColor(t,e,i){return this.gradient1.genColor(t,e,i),this.gradient2.genColor(t,Lt,i),t&&void 0!==t[this.indexCount]?e.lerp(Lt,t[this.indexCount]):e.lerp(Lt,Math.random()),e}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(t){return new Rt(Nt.fromJSON(t.gradient1),Nt.fromJSON(t.gradient2))}clone(){return new Rt(this.gradient1.clone(),this.gradient2.clone())}}class Ut{constructor(t){this.color=t,this.type="value"}startGen(t){}genColor(t,e){return e.copy(this.color)}toJSON(){return{type:"ConstantColor",color:Ot(this.color)}}static fromJSON(t){return new Ut(Ct(t.color))}clone(){return new Ut(this.color.clone())}}function Dt(t){switch(t.type){case"ConstantColor":return Ut.fromJSON(t);case"ColorRange":return $t.fromJSON(t);case"RandomColor":return It.fromJSON(t);case"Gradient":return Nt.fromJSON(t);case"RandomColorBetweenGradient":return Rt.fromJSON(t);default:return new Ut(new mt(1,1,1,1))}}class qt{constructor(t,e,i,s){this.angleX=t,this.angleY=e,this.angleZ=i,this.type="rotation",this.eular=new nt(0,0,0,s)}startGen(t){this.angleX.startGen(t),this.angleY.startGen(t),this.angleZ.startGen(t)}genValue(t,e,i,s){return this.eular.set(this.angleX.genValue(t,s)*i,this.angleY.genValue(t,s)*i,this.angleZ.genValue(t,s)*i),e.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(t){return new qt(Pt(t.angleX),Pt(t.angleY),Pt(t.angleZ),t.eulerOrder)}clone(){return new qt(this.angleX,this.angleY,this.angleZ,this.eular.order)}}class Jt{constructor(){this.indexCount=0,this.type="rotation"}startGen(t){let e,i,s,r,n,o;this.indexCount=t.length;do{e=2*Math.random()-1,i=2*Math.random()-1,s=e*e+i*i}while(s>1);do{r=2*Math.random()-1,n=2*Math.random()-1,o=r*r+n*n}while(o>1);const a=Math.sqrt((1-s)/o);t.push(e,i,a*r,a*n)}genValue(t,e,i,s){-1===this.indexCount&&this.startGen(t);const r=this.indexCount;return e.set(t[r],t[r+1],t[r+2],t[r+3]),e}toJSON(){return{type:"RandomQuat"}}static fromJSON(t){return new Jt}clone(){return new Jt}}function kt(t){switch(t.type){case"AxisAngle":return Vt.fromJSON(t);case"Euler":return qt.fromJSON(t);case"RandomQuat":return Jt.fromJSON(t);default:return new Jt}}class Qt{constructor(t,e,i){this.x=t,this.y=e,this.z=i,this.type="vec3function"}startGen(t){this.x.startGen(t),this.y.startGen(t),this.z.startGen(t)}genValue(t,e,i){return e.set(this.x.genValue(t,i),this.y.genValue(t,i),this.z.genValue(t,i))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(t){return new Qt(Pt(t.x),Pt(t.y),Pt(t.z))}clone(){return new Qt(this.x,this.y,this.z)}}function Wt(t){return"Vector3Function"===t.type?Qt.fromJSON(t):new Qt(new bt(0),new bt(0),new bt(0))}function Gt(t){switch(t.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Pt(t);case"AxisAngle":case"RandomQuat":case"Euler":return kt(t);case"Vector3Function":return Wt(t);default:return new bt(0)}}class jt{constructor(t,e){this.direction=t,this.magnitude=e,this.type="ApplyForce",this.memory={data:[],dataCount:0},this.magnitudeValue=this.magnitude.genValue(this.memory)}initialize(t){}update(t,e){const i=this.magnitudeValue*e,s=this.direction,r=t.velocity;r.x+=s.x*i,r.y+=s.y*i,r.z+=s.z*i}updateAll(t,e,i){const s=this.magnitudeValue*i,r=this.direction.x*s,n=this.direction.y*s,o=this.direction.z*s;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const s=e.velocity;s.x+=r,s.y+=n,s.z+=o}}frameUpdate(t){this.magnitudeValue=this.magnitude.genValue(this.memory)}toJSON(){return{type:this.type,direction:[this.direction.x,this.direction.y,this.direction.z],magnitude:this.magnitude.toJSON()}}static fromJSON(t){return new jt(new k(t.direction[0],t.direction[1],t.direction[2]),Pt(t.magnitude??t.force))}clone(){return new jt(this.direction.clone(),this.magnitude.clone())}reset(){}}class Yt{constructor(t=0,e=0,i=new k){this.scaleX=t,this.scaleY=e,this.position=i,this.locations=[]}transform(t,e){t.x=this.locations[e%this.locations.length].x*this.scaleX+this.position.x,t.y=this.locations[e%this.locations.length].y*this.scaleY+this.position.y,t.z=this.position.z}static fromJSON(t){const e=new Yt(t.scaleX,t.scaleY,new k(t.position[0],t.position[1],t.position[2]));return e.locations=t.locations.map(t=>new ut(t.x,t.y)),e}clone(){const t=new Yt(this.scaleX,this.scaleY,this.position.clone());return t.locations=this.locations.map(t=>t.clone()),t}toJSON(){return{scaleX:this.scaleX,scaleY:this.scaleY,position:this.position,locations:this.locations.map(t=>({x:t.x,y:t.y}))}}fromImage(t,e){const i=document.createElement("canvas");i.width=t.width,i.height=t.height;const s=i.getContext("2d");if(!s)return;s.drawImage(t,0,0);const r=s.getImageData(0,0,i.width,i.height,{colorSpace:"srgb"});i.remove(),this.locations.length=0;for(let t=0;t<r.height;t++)for(let i=0;i<r.width;i++)r.data[4*(t*r.width+i)+3]>e&&this.locations.push(new ut(i,r.height-t))}}function Xt(t){return"TextureSequencer"===t.type?Yt.fromJSON(t):new Yt}class Zt{constructor(t){this.type="ApplySequences",this.sequencers=[],this.time=0,this.index=0,this.pCount=0,this.tempV=new k,this.delay=t}initialize(t){t.id=this.pCount,t.dst=new k,t.begin=new k,t.inMotion=!1,this.pCount++}reset(){this.time=0,this.index=0,this.pCount=0}update(t,e){const i=this.sequencers[this.index],s=t.id*this.delay;this.time>=i[0].a+s&&this.time<=i[0].b+s?(t.inMotion||(t.inMotion=!0,t.begin.copy(t.position),i[1].transform(t.dst,t.id)),t.position.lerpVectors(t.begin,t.dst,Zt.BEZIER.genValue((this.time-i[0].a-s)/(i[0].b-i[0].a)))):this.time>i[0].b+s&&(t.inMotion=!1)}frameUpdate(t){for(;this.index+1<this.sequencers.length&&this.time>=this.sequencers[this.index+1][0].a;)this.index++;this.time+=t}appendSequencer(t,e){this.sequencers.push([t,e])}toJSON(){return{type:this.type,delay:this.delay,sequencers:this.sequencers.map(([t,e])=>({range:t.toJSON(),sequencer:e.toJSON()}))}}static fromJSON(t){const e=new Zt(t.delay);return t.sequencers.forEach(t=>{e.sequencers.push([Pt(t.range),Xt(t.sequencer)])}),e}clone(){const t=new Zt(this.delay);return t.sequencers=this.sequencers.map(t=>[t[0].clone(),t[1].clone()]),t}}Zt.BEZIER=new zt(0,0,1,1);class Ht{constructor(t){this.angle=t,this.type="ChangeEmitDirection",this._temp=new k,this._q=new J,this.memory={data:[],dataCount:0}}initialize(t){const e=t.velocity.length();0!=e&&(t.velocity.normalize(),0===t.velocity.x&&0===t.velocity.y?this._temp.set(0,t.velocity.z,0):this._temp.set(-t.velocity.y,t.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(t.velocity),t.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),t.velocity.applyQuaternion(this._q),t.velocity.setLength(e))}update(t,e){}frameUpdate(t){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(t){return new Ht(Pt(t.angle))}clone(){return new Ht(this.angle)}reset(){}}class Kt{constructor(t,e){this.color=t,this.speedRange=e,this.type="ColorBySpeed"}initialize(t){this.color.startGen(t.memory)}update(t,e){const i=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(t.memory,t.color,i),t.color.x*=t.startColor.x,t.color.y*=t.startColor.y,t.color.z*=t.startColor.z,t.color.w*=t.startColor.w}frameUpdate(t){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new Kt(Dt(t.color),Mt.fromJSON(t.speedRange))}clone(){return new Kt(this.color.clone(),this.speedRange.clone())}reset(){}}class te{constructor(t){this.color=t,this.type="ColorOverLife"}initialize(t){this.color.startGen(t.memory)}update(t,e){const i=t.color,s=t.startColor;this.color.genColor(t.memory,i,t.age/t.life),i.x*=s.x,i.y*=s.y,i.z*=s.z,i.w*=s.w}updateAll(t,e,i){const s=this.color;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const r=e.color,n=e.startColor;s.genColor(e.memory,r,e.age/e.life),r.x*=n.x,r.y*=n.y,r.z*=n.z,r.w*=n.w}}frameUpdate(t){this.color.refreshTable?.()}toJSON(){return{type:this.type,color:this.color.toJSON()}}static fromJSON(t){return new te(Dt(t.color))}clone(){return new te(this.color.clone())}reset(){}}function ee(t,e){return Math.floor(Math.random()*(e-t))+t}const ie=new k(0,1,0),se=new k(0,0,0),re=new k(1,1,1),ne=new k(0,0,1);var oe;exports.SubParticleEmitMode=void 0,(oe=exports.SubParticleEmitMode||(exports.SubParticleEmitMode={}))[oe.Death=0]="Death",oe[oe.Birth=1]="Birth",oe[oe.Frame=2]="Frame";class ae{constructor(t,e,i,s=exports.SubParticleEmitMode.Frame,r=1){this.particleSystem=t,this.useVelocityAsBasis=e,this.subParticleSystem=i,this.mode=s,this.emitProbability=r,this.type="EmitSubParticleSystem",this.q_=new J,this.v_=new k,this.v2_=new k,this.subEmissions=new Array,this.spareEmissions=new Array;const n=this.target;n&&(n.onlyUsedByOther=!0)}initialize(t){}update(t,e){(this.mode===exports.SubParticleEmitMode.Frame||this.mode===exports.SubParticleEmitMode.Birth&&0===t.age||this.mode===exports.SubParticleEmitMode.Death&&t.age+e>=t.life)&&this.emit(t,e)}get target(){const t=this.subParticleSystem;if(null!==t&&"object"==typeof t)return t.system}emit(t,e){if(!this.target)return;if(Math.random()>this.emitProbability)return;const i=this.spareEmissions.pop(),s=void 0!==i?i:{burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:new Y,travelDistance:0,particle:void 0,previousWorldPos:void 0};s.burstParticleCount=0,s.burstParticleIndex=0,s.isBursting=!1,s.burstIndex=0,s.burstWaveIndex=0,s.time=0,s.waitEmiting=0,s.travelDistance=0,s.particle=t,s.previousWorldPos=void 0,this.setMatrixFromParticle(s.matrix,t),this.subEmissions.push(s)}frameUpdate(t){const e=this.target;if(e)for(let i=0;i<this.subEmissions.length;i++)if(this.subEmissions[i].time>=e.duration){const t=this.subEmissions[i];t.particle=void 0,this.spareEmissions.push(t),this.subEmissions[i]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,i--}else{const s=this.subEmissions[i];s.particle&&s.particle.age<s.particle.life?this.setMatrixFromParticle(s.matrix,s.particle):s.particle=void 0,e.emit(t,s,s.matrix)}else this.subEmissions.length=0}toJSON(){return{type:this.type,subParticleSystem:"string"==typeof this.subParticleSystem?this.subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(t,e){return new ae(e,t.useVelocityAsBasis,t.subParticleSystem,t.mode,t.emitProbability)}clone(){return new ae(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(t,e){let i;if(void 0===e.rotation||this.useVelocityAsBasis)if(0!==e.velocity.x||0!==e.velocity.y||1!==e.velocity.z&&0!==e.velocity.z){this.v_.copy(ne).cross(e.velocity),this.v2_.copy(e.velocity).cross(this.v_);const i=this.v_.length(),s=this.v2_.length();t.set(this.v_.x/i,this.v2_.x/s,e.velocity.x,e.position.x,this.v_.y/i,this.v2_.y/s,e.velocity.y,e.position.y,this.v_.z/i,this.v2_.z/s,e.velocity.z,e.position.z,0,0,0,1)}else t.set(1,0,0,e.position.x,0,1,0,e.position.y,0,0,1,e.position.z,0,0,0,1);else e.rotation instanceof J?i=e.rotation:(this.q_.setFromAxisAngle(ne,e.rotation),i=this.q_),t.compose(e.position,i,re);this.particleSystem.worldSpace||t.multiplyMatrices(this.particleSystem.emitter.matrixWorld,t)}}class he{initialize(t,e){this.ps=e,this.x.startGen(t.memory),this.y.startGen(t.memory),this.z.startGen(t.memory)}constructor(t,e,i){this.x=t,this.y=e,this.z=i,this.type="ForceOverLife",this._temp=new k,this._tempScale=new k,this._tempQ=new J}update(t,e){this._temp.set(this.x.genValue(t.memory,t.age/t.life),this.y.genValue(t.memory,t.age/t.life),this.z.genValue(t.memory,t.age/t.life)),void 0===this.ps||this.ps.worldSpace||this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),t.velocity.addScaledVector(this._temp,e)}updateAll(t,e,i){const s=this.ps;if(void 0===s)return;const r=this._temp,n=this.x,o=this.y,a=this.z,h=s.worldSpace;for(let s=0;s<e;s++){const e=t[s];if(e.age>=e.life)continue;const l=e.memory,c=e.age/e.life;r.set(n.genValue(l,c),o.genValue(l,c),a.genValue(l,c)),h||r.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(r,i)}}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(t){return new he(Pt(t.x),Pt(t.y),Pt(t.z))}frameUpdate(t){if(this.ps&&!this.ps.worldSpace){const t=this._temp,e=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,e,i),e.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new he(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class le{constructor(t){this.type="FrameOverLife",this.frame=t}get frame(){return this._frame}set frame(t){this._frame=t}initialize(t){this._frame.startGen(t.memory)}update(t,e){t.uvTile=this.sampleFrame(t,t.age/t.life)}updateAll(t,e,i){for(let i=0;i<e;i++){const e=t[i];e.age>=e.life||(e.uvTile=this.sampleFrame(e,e.age/e.life))}}sampleFrame(t,e){return"function"===this._frame.type?this._frame.genValue(t.memory,e):this._frame.genValue(t.memory)}frameUpdate(t){this._frame.refreshTable?.()}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(t){return new le(Pt(t.frame))}clone(){return new le(this.frame.clone())}reset(){}}class ce{constructor(t,e){this.center=t,this.magnitude=e,this.type="GravityForce",this.temp=new k}initialize(t){}update(t,e){const i=t.position.distanceToSquared(this.center);0!==i&&(this.temp.copy(this.center).sub(t.position).normalize(),t.velocity.addScaledVector(this.temp,this.magnitude/i*e))}updateAll(t,e,i){const s=this.center.x,r=this.center.y,n=this.center.z,o=this.magnitude*i;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const a=e.position,h=s-a.x,l=r-a.y,c=n-a.z,u=h*h+l*l+c*c;if(0===u)continue;const d=o/(u*Math.sqrt(u)),p=e.velocity;p.x+=h*d,p.y+=l*d,p.z+=c*d}}frameUpdate(t){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(t){return new ce(new k(t.center[0],t.center[1],t.center[2]),t.magnitude)}clone(){return new ce(this.center.clone(),this.magnitude)}reset(){}}class ue{constructor(t=new bt(1),e="initial"){this.multiplier=t,this.mode=e,this.type="InheritVelocity",this._temp=new k,this._tempPos=new k,this._tempQInv=new J,this._tempScaleInv=new k(1,1,1)}initialize(t,e){this.ps=e,this.multiplier.startGen(t.memory),"initial"===this.mode&&e.emitterVelocity&&(this._temp.copy(e.emitterVelocity),e.worldSpace||(this.decomposeInverse(e),this._temp.multiply(this._tempScaleInv).applyQuaternion(this._tempQInv)),t.velocity.addScaledVector(this._temp,this.multiplier.genValue(t.memory,0)))}frameUpdate(t){this.ps&&!this.ps.worldSpace&&this.decomposeInverse(this.ps)}update(t,e){"current"===this.mode&&void 0!==this.ps&&this.ps.emitterVelocity&&(this._temp.copy(this.ps.emitterVelocity),this.ps.worldSpace||this._temp.multiply(this._tempScaleInv).applyQuaternion(this._tempQInv),t.position.addScaledVector(this._temp,this.multiplier.genValue(t.memory,t.age/t.life)*e))}decomposeInverse(t){t.emitter.matrixWorld.decompose(this._tempPos,this._tempQInv,this._tempScaleInv),this._tempQInv.invert(),this._tempScaleInv.set(1/this._tempScaleInv.x,1/this._tempScaleInv.y,1/this._tempScaleInv.z)}toJSON(){return{type:this.type,multiplier:this.multiplier.toJSON(),mode:this.mode}}static fromJSON(t){return new ue(t.multiplier?Pt(t.multiplier):new bt(1),"current"===t.mode?"current":"initial")}clone(){return new ue(this.multiplier.clone(),this.mode)}reset(){}}class de{initialize(t){this.speed.startGen(t.memory)}constructor(t,e){this.speed=t,this.dampen=e,this.type="LimitSpeedOverLife"}update(t,e){let i=t.velocity.length(),s=this.speed.genValue(t.memory,t.age/t.life);if(i>s){const r=(i-s)/i;t.velocity.multiplyScalar(1-r*this.dampen*e*20)}}updateAll(t,e,i){const s=this.speed,r=this.dampen*i*20;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const n=e.velocity,o=n.length(),a=s.genValue(e.memory,e.age/e.life);o>a&&n.multiplyScalar(1-(o-a)/o*r)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(t){return new de(Pt(t.speed),t.dampen)}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new de(this.speed.clone(),this.dampen)}reset(){}}class pe{constructor(t=64){this.previousVelocity=pe.EMPTY,this.rotationQuaternion=pe.EMPTY,this.angularVelocityQuaternion=pe.EMPTY,this.memory=new Float64Array(0),this.memoryStride=0,this.capacity=Math.max(1,t),this.position=new Float32Array(3*this.capacity),this.previousPosition=new Float32Array(3*this.capacity),this.previousSize=new Float32Array(3*this.capacity),this.previousColor=new Float32Array(4*this.capacity),this.velocity=new Float32Array(3*this.capacity),this.size=new Float32Array(3*this.capacity),this.startSize=new Float32Array(3*this.capacity),this.color=new Float32Array(4*this.capacity),this.startColor=new Float32Array(4*this.capacity),this.scalars=new Float64Array(this.capacity*pe.SCALAR_STRIDE),this.rotation=new Float32Array(this.capacity),this.angularVelocity=new Float32Array(this.capacity),this.uvTile=new Float32Array(this.capacity),this.startSpeed=new Float32Array(this.capacity),this.flip=new Uint8Array(this.capacity)}ensureCapacity(t){if(t<=this.capacity)return!1;let e=this.capacity;for(;e<t;)e*=2;this.position=pe.grow(this.position,3*e),this.previousPosition=pe.grow(this.previousPosition,3*e);const i=this.previousSize===this.size,s=this.previousColor===this.color;if(i||(this.previousSize=pe.grow(this.previousSize,3*e)),this.previousVelocity.length>0&&(this.previousVelocity=pe.grow(this.previousVelocity,3*e)),this.rotationQuaternion.length>0){const t=this.rotationQuaternion.length;this.rotationQuaternion=pe.grow(this.rotationQuaternion,4*e),this.angularVelocityQuaternion=pe.grow(this.angularVelocityQuaternion,4*e);for(let i=t+3;i<4*e;i+=4)this.rotationQuaternion[i]=1,this.angularVelocityQuaternion[i]=1}if(s||(this.previousColor=pe.grow(this.previousColor,4*e)),this.velocity=pe.grow(this.velocity,3*e),this.size=pe.grow(this.size,3*e),this.startSize=pe.grow(this.startSize,3*e),this.color=pe.grow(this.color,4*e),i&&(this.previousSize=this.size),s&&(this.previousColor=this.color),this.startColor=pe.grow(this.startColor,4*e),this.scalars=pe.growDouble(this.scalars,e*pe.SCALAR_STRIDE),this.memoryStride>0){const t=new Float64Array(e*this.memoryStride);t.fill(NaN),t.set(this.memory),this.memory=t}this.rotation=pe.grow(this.rotation,e),this.angularVelocity=pe.grow(this.angularVelocity,e),this.uvTile=pe.grow(this.uvTile,e),this.startSpeed=pe.grow(this.startSpeed,e);const r=new Uint8Array(e);return r.set(this.flip),this.flip=r,this.capacity=e,!0}keepPreviousVelocity(){return!(this.previousVelocity.length>=3*this.capacity)&&(this.previousVelocity=new Float32Array(3*this.capacity),!0)}recordMemory(t,e){const i=e.length;let s=this.memoryStride;if(i>s||this.memory.length<this.capacity*s){s=Math.max(s,i);const t=new Float64Array(this.capacity*s);t.fill(NaN);const e=this.memoryStride,r=this.memory,n=e>0?r.length/e:0;for(let i=0,o=0,a=0;i<n;i++,o+=e,a+=s)for(let i=0;i<e;i++)t[a+i]=r[o+i];this.memory=t,this.memoryStride=s}const r=t*s;for(let t=0;t<s;t++){const s=t<i?e[t]:void 0;this.memory[r+t]="number"==typeof s?s:NaN}}useSizeSnapshot(t){t?this.previousSize===this.size&&(this.previousSize=new Float32Array(this.size)):this.previousSize=this.size}useColorSnapshot(t){t?this.previousColor===this.color&&(this.previousColor=new Float32Array(this.color)):this.previousColor=this.color}ensureQuaternionColumns(){if(this.rotationQuaternion.length>=4*this.capacity)return!1;this.rotationQuaternion=new Float32Array(4*this.capacity),this.angularVelocityQuaternion=new Float32Array(4*this.capacity);for(let t=3;t<this.rotationQuaternion.length;t+=4)this.rotationQuaternion[t]=1,this.angularVelocityQuaternion[t]=1;return!0}swapRows(t,e){if(t===e)return;const i=3*t,s=3*e;pe.swap3(this.position,i,s),pe.swap3(this.previousPosition,i,s),this.previousSize!==this.size&&pe.swap3(this.previousSize,i,s),this.previousVelocity.length>0&&pe.swap3(this.previousVelocity,i,s),pe.swap3(this.velocity,i,s),pe.swap3(this.size,i,s),pe.swap3(this.startSize,i,s);const r=4*t,n=4*e;pe.swap4(this.color,r,n),this.previousColor!==this.color&&pe.swap4(this.previousColor,r,n),pe.swap4(this.startColor,r,n),this.rotationQuaternion.length>0&&(pe.swap4(this.rotationQuaternion,r,n),pe.swap4(this.angularVelocityQuaternion,r,n)),pe.swap3(this.scalars,t*pe.SCALAR_STRIDE,e*pe.SCALAR_STRIDE);const o=this.memoryStride;if(o>0){const i=this.memory;for(let s=0,r=t*o,n=e*o;s<o;s++,r++,n++){const t=i[r];i[r]=i[n],i[n]=t}}pe.swap1(this.rotation,t,e),pe.swap1(this.angularVelocity,t,e),pe.swap1(this.uvTile,t,e),pe.swap1(this.startSpeed,t,e),pe.swap1(this.flip,t,e)}static swap1(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}static growDouble(t,e){const i=new Float64Array(e);return i.set(t),i}static swap3(t,e,i){let s=t[e];t[e]=t[i],t[i]=s,s=t[e+1],t[e+1]=t[i+1],t[i+1]=s,s=t[e+2],t[e+2]=t[i+2],t[i+2]=s}static swap4(t,e,i){pe.swap3(t,e,i);const s=t[e+3];t[e+3]=t[i+3],t[i+3]=s}static grow(t,e){const i=new Float32Array(e);return i.set(t),i}}pe.EMPTY=new Float32Array(0),pe.SCALAR_STRIDE=3,pe.AGE=0,pe.LIFE=1,pe.SPEED_MODIFIER=2;const fe=.5*(Math.sqrt(3)-1),me=(3-Math.sqrt(3))/6,ye=1/3,ve=1/6,xe=(Math.sqrt(5)-1)/4,ge=(5-Math.sqrt(5))/20,Se=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),we=new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);class be{constructor(t=Math.random){const e="function"==typeof t?t:function(t){let e=0,i=0,s=0,r=1;const n=function(){let t=4022871197;return function(e){e=e.toString();for(let i=0;i<e.length;i++){t+=e.charCodeAt(i);let s=.02519603282416938*t;t=s>>>0,s-=t,s*=t,t=s>>>0,s-=t,t+=4294967296*s}return 2.3283064365386963e-10*(t>>>0)}}();e=n(" "),i=n(" "),s=n(" "),e-=n(t),e<0&&(e+=1);i-=n(t),i<0&&(i+=1);s-=n(t),s<0&&(s+=1);return function(){const t=2091639*e+2.3283064365386963e-10*r;return e=i,i=s,s=t-(r=0|t)}}(t);this.p=function(t){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let i=0;i<255;i++){const s=i+~~(t()*(256-i)),r=e[i];e[i]=e[s],e[s]=r}return e}(e),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let t=0;t<512;t++)this.perm[t]=this.p[255&t],this.permMod12[t]=this.perm[t]%12}noise2D(t,e){const i=this.permMod12,s=this.perm;let r=0,n=0,o=0;const a=(t+e)*fe,h=Math.floor(t+a),l=Math.floor(e+a),c=(h+l)*me,u=t-(h-c),d=e-(l-c);let p,f;u>d?(p=1,f=0):(p=0,f=1);const m=u-p+me,y=d-f+me,v=u-1+2*me,x=d-1+2*me,g=255&h,S=255&l;let w=.5-u*u-d*d;if(w>=0){const t=3*i[g+s[S]];w*=w,r=w*w*(Se[t]*u+Se[t+1]*d)}let b=.5-m*m-y*y;if(b>=0){const t=3*i[g+p+s[S+f]];b*=b,n=b*b*(Se[t]*m+Se[t+1]*y)}let M=.5-v*v-x*x;if(M>=0){const t=3*i[g+1+s[S+1]];M*=M,o=M*M*(Se[t]*v+Se[t+1]*x)}return 70*(r+n+o)}noise3D(t,e,i){const s=this.permMod12,r=this.perm;let n,o,a,h;const l=(t+e+i)*ye,c=Math.floor(t+l),u=Math.floor(e+l),d=Math.floor(i+l),p=(c+u+d)*ve,f=t-(c-p),m=e-(u-p),y=i-(d-p);let v,x,g,S,w,b;f>=m?m>=y?(v=1,x=0,g=0,S=1,w=1,b=0):f>=y?(v=1,x=0,g=0,S=1,w=0,b=1):(v=0,x=0,g=1,S=1,w=0,b=1):m<y?(v=0,x=0,g=1,S=0,w=1,b=1):f<y?(v=0,x=1,g=0,S=0,w=1,b=1):(v=0,x=1,g=0,S=1,w=1,b=0);const M=f-v+ve,z=m-x+ve,_=y-g+ve,T=f-S+2*ve,P=m-w+2*ve,V=y-b+2*ve,O=f-1+.5,C=m-1+.5,A=y-1+.5,B=255&c,$=255&u,F=255&d;let E=.6-f*f-m*m-y*y;if(E<0)n=0;else{const t=3*s[B+r[$+r[F]]];E*=E,n=E*E*(Se[t]*f+Se[t+1]*m+Se[t+2]*y)}let N=.6-M*M-z*z-_*_;if(N<0)o=0;else{const t=3*s[B+v+r[$+x+r[F+g]]];N*=N,o=N*N*(Se[t]*M+Se[t+1]*z+Se[t+2]*_)}let I=.6-T*T-P*P-V*V;if(I<0)a=0;else{const t=3*s[B+S+r[$+w+r[F+b]]];I*=I,a=I*I*(Se[t]*T+Se[t+1]*P+Se[t+2]*V)}let L=.6-O*O-C*C-A*A;if(L<0)h=0;else{const t=3*s[B+1+r[$+1+r[F+1]]];L*=L,h=L*L*(Se[t]*O+Se[t+1]*C+Se[t+2]*A)}return 32*(n+o+a+h)}noise4D(t,e,i,s){const r=this.perm;let n,o,a,h,l;const c=(t+e+i+s)*xe,u=Math.floor(t+c),d=Math.floor(e+c),p=Math.floor(i+c),f=Math.floor(s+c),m=(u+d+p+f)*ge,y=t-(u-m),v=e-(d-m),x=i-(p-m),g=s-(f-m);let S=0,w=0,b=0,M=0;y>v?S++:w++,y>x?S++:b++,y>g?S++:M++,v>x?w++:b++,v>g?w++:M++,x>g?b++:M++;const z=S>=3?1:0,_=w>=3?1:0,T=b>=3?1:0,P=M>=3?1:0,V=S>=2?1:0,O=w>=2?1:0,C=b>=2?1:0,A=M>=2?1:0,B=S>=1?1:0,$=w>=1?1:0,F=b>=1?1:0,E=M>=1?1:0,N=y-z+ge,I=v-_+ge,L=x-T+ge,R=g-P+ge,U=y-V+2*ge,D=v-O+2*ge,q=x-C+2*ge,J=g-A+2*ge,k=y-B+3*ge,Q=v-$+3*ge,W=x-F+3*ge,G=g-E+3*ge,j=y-1+4*ge,Y=v-1+4*ge,X=x-1+4*ge,Z=g-1+4*ge,H=255&u,K=255&d,tt=255&p,et=255&f;let it=.6-y*y-v*v-x*x-g*g;if(it<0)n=0;else{const t=r[H+r[K+r[tt+r[et]]]]%32*4;it*=it,n=it*it*(we[t]*y+we[t+1]*v+we[t+2]*x+we[t+3]*g)}let st=.6-N*N-I*I-L*L-R*R;if(st<0)o=0;else{const t=r[H+z+r[K+_+r[tt+T+r[et+P]]]]%32*4;st*=st,o=st*st*(we[t]*N+we[t+1]*I+we[t+2]*L+we[t+3]*R)}let rt=.6-U*U-D*D-q*q-J*J;if(rt<0)a=0;else{const t=r[H+V+r[K+O+r[tt+C+r[et+A]]]]%32*4;rt*=rt,a=rt*rt*(we[t]*U+we[t+1]*D+we[t+2]*q+we[t+3]*J)}let nt=.6-k*k-Q*Q-W*W-G*G;if(nt<0)h=0;else{const t=r[H+B+r[K+$+r[tt+F+r[et+E]]]]%32*4;nt*=nt,h=nt*nt*(we[t]*k+we[t+1]*Q+we[t+2]*W+we[t+3]*G)}let ot=.6-j*j-Y*Y-X*X-Z*Z;if(ot<0)l=0;else{const t=r[H+1+r[K+1+r[tt+1+r[et+1]]]]%32*4;ot*=ot,l=ot*ot*(we[t]*j+we[t+1]*Y+we[t+2]*X+we[t+3]*Z)}return 27*(n+o+a+h+l)}}const Me=100,ze=new Array(Me),_e=new k,Te=new J;function Pe(t){let e=ze[t];return void 0===e&&(e=new be,ze[t]=e),e}class Ve{constructor(t,e,i=new bt(1),s=new bt(0)){this.frequency=t,this.power=e,this.positionAmount=i,this.rotationAmount=s,this.type="Noise",this.duration=0,this._frequency=NaN,this._power=NaN,this._positionAmount=NaN,this._rotationAmount=NaN}initialize(t){const e="number"==typeof t.rotation;let i=t._noiseState;if(void 0===i)return i={lastPos:new k,lastRot:0,lastRotQ:e?null:new J,generatorX:Pe(ee(0,Me)),generatorY:Pe(ee(0,Me)),generatorZ:Pe(ee(0,Me)),generatorW:Pe(ee(0,Me))},void(t._noiseState=i);i.lastPos.set(0,0,0),i.lastRot=0,e?i.lastRotQ=null:null===i.lastRotQ?i.lastRotQ=new J:i.lastRotQ.set(0,0,0,1),i.generatorX=Pe(ee(0,Me)),i.generatorY=Pe(ee(0,Me)),i.generatorZ=Pe(ee(0,Me)),i.generatorW=Pe(ee(0,Me))}static constantOf(t){return t instanceof bt?t.value:NaN}update(t,e){const i=t._noiseState;if(void 0===i)return;const s=t.memory,r=t.age/t.life,n=this._frequency,o=n==n?n:this.frequency.genValue(s,r),a=this._power,h=a==a?a:this.power.genValue(s,r),l=this._positionAmount,c=l==l?l:this.positionAmount.genValue(s,r),u=this._rotationAmount,d=u==u?u:this.rotationAmount.genValue(s,r),p=t.age*o;if(c>0){const e=h*c;t.position.sub(i.lastPos),_e.set(i.generatorX.noise2D(0,p)*e,i.generatorY.noise2D(0,p)*e,i.generatorZ.noise2D(0,p)*e),t.position.add(_e),i.lastPos.copy(_e)}if(d>0){const e=h*d;if("number"==typeof t.rotation){const s=i.generatorW.noise2D(0,p)*Math.PI*e;t.rotation=t.rotation-i.lastRot+s,i.lastRot=s}else if(null!==i.lastRotQ){const s=t.rotation;i.lastRotQ.invert(),s.multiply(i.lastRotQ),Te.set(i.generatorX.noise2D(0,p)*e,i.generatorY.noise2D(0,p)*e,i.generatorZ.noise2D(0,p)*e,i.generatorW.noise2D(0,p)*e).normalize(),s.multiply(Te),i.lastRotQ.copy(Te)}}}updateAll(t,e,i){const s=e>0?t[0].store:void 0;if(void 0===s){for(let s=0;s<e;s++){const e=t[s];e.age<e.life&&this.update(e,i)}return}const r=s.position,n=s.rotation,o=s.scalars,a=pe.SCALAR_STRIDE,h=this._frequency,l=this._power,c=this._positionAmount,u=this._rotationAmount;for(let i=0,s=0,d=0;i<e;i++,s+=3,d+=a){const e=o[d],a=o[d+1];if(e>=a)continue;const p=t[i],f=p._noiseState;if(void 0===f)continue;const m=p.memory,y=e/a,v=h==h?h:this.frequency.genValue(m,y),x=l==l?l:this.power.genValue(m,y),g=c==c?c:this.positionAmount.genValue(m,y),S=u==u?u:this.rotationAmount.genValue(m,y),w=e*v;if(g>0){const t=x*g,e=f.lastPos,i=f.generatorX.noise2D(0,w)*t,n=f.generatorY.noise2D(0,w)*t,o=f.generatorZ.noise2D(0,w)*t;r[s]=Math.fround(r[s]-e.x)+i,r[s+1]=Math.fround(r[s+1]-e.y)+n,r[s+2]=Math.fround(r[s+2]-e.z)+o,e.set(i,n,o)}if(S>0){const t=x*S;if("number"==typeof p.rotation){const e=f.generatorW.noise2D(0,w)*Math.PI*t;n[i]=n[i]-f.lastRot+e,f.lastRot=e}else if(null!==f.lastRotQ){const e=p.rotation;f.lastRotQ.invert(),e.multiply(f.lastRotQ),Te.set(f.generatorX.noise2D(0,w)*t,f.generatorY.noise2D(0,w)*t,f.generatorZ.noise2D(0,w)*t,f.generatorW.noise2D(0,w)*t).normalize(),e.multiply(Te),f.lastRotQ.copy(Te)}}}}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(t){this.duration+=t,this._frequency=Ve.constantOf(this.frequency),this._power=Ve.constantOf(this.power),this._positionAmount=Ve.constantOf(this.positionAmount),this._rotationAmount=Ve.constantOf(this.rotationAmount)}static fromJSON(t){return new Ve(Pt(t.frequency),Pt(t.power),Pt(t.positionAmount),Pt(t.rotationAmount))}clone(){return new Ve(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Oe{constructor(t,e=new k(0,1,0)){this.orbitSpeed=t,this.axis=e,this.type="OrbitOverLife",this.temp=new k,this.rotation=new J}initialize(t){this.orbitSpeed.startGen(t.memory)}update(t,e){this.temp.copy(t.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(t.memory,t.age/t.life)*e),t.position.sub(this.temp),t.position.applyQuaternion(this.rotation),t.position.add(this.temp)}updateAll(t,e,i){const s=this.orbitSpeed,r=this.axis,n=this.temp,o=this.rotation;for(let a=0;a<e;a++){const e=t[a];if(e.age>=e.life)continue;const h=e.position;n.copy(h).projectOnVector(r),o.setFromAxisAngle(r,s.genValue(e.memory,e.age/e.life)*i),h.sub(n),h.applyQuaternion(o),h.add(n)}}frameUpdate(t){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(t){return new Oe(Pt(t.orbitSpeed),t.axis?new k(t.axis[0],t.axis[1],t.axis[2]):void 0)}clone(){return new Oe(this.orbitSpeed.clone())}reset(){}}class Ce{constructor(t){this.angularVelocity=t,this.type="Rotation3DOverLife",this.tempQuat=new J}initialize(t){t.rotation instanceof J&&(t.angularVelocity=new J,this.angularVelocity.startGen(t.memory))}update(t,e){if(t.rotation instanceof J){this.angularVelocity.genValue(t.memory,this.tempQuat,e,t.age/t.life),t.rotation.multiply(this.tempQuat);const i=t.angularVelocity;i instanceof J&&i.copy(this.tempQuat)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new Ce(kt(t.angularVelocity))}frameUpdate(t){}clone(){return new Ce(this.angularVelocity.clone())}reset(){}}class Ae{constructor(t,e){this.angularVelocity=t,this.speedRange=e,this.type="RotationBySpeed",this.tempQuat=new J}initialize(t){"number"==typeof t.rotation&&this.angularVelocity.startGen(t.memory)}update(t,e){if("number"==typeof t.rotation){const i=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a),s=this.angularVelocity.genValue(t.memory,i);t.rotation+=e*s,t.angularVelocity=s}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new Ae(Pt(t.angularVelocity),Mt.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Ae(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Be{constructor(t){this.angularVelocity=t,this.type="RotationOverLife",this.tempQuat=new J}initialize(t){"number"==typeof t.rotation?this.angularVelocity.startGen(t.memory):t.rotation instanceof J&&(this.angularVelocity.startGen(t.memory),t.angularVelocity instanceof J||(t.angularVelocity=new J))}update(t,e){if("number"==typeof t.rotation){const i=this.angularVelocity.genValue(t.memory,t.age/t.life);t.rotation+=e*i,t.angularVelocity=i}else if(t.rotation instanceof J){const i=this.angularVelocity.genValue(t.memory,t.age/t.life);this.turnAboutZ(t,t.rotation,i*e)}}updateAll(t,e,i){const s=this.angularVelocity;for(let r=0;r<e;r++){const e=t[r];if(e.age>=e.life)continue;const n=e.rotation;if("number"==typeof n){const t=s.genValue(e.memory,e.age/e.life);e.rotation=n+i*t,e.angularVelocity=t}else if(n instanceof J){const t=s.genValue(e.memory,e.age/e.life);this.turnAboutZ(e,n,t*i)}}}turnAboutZ(t,e,i){const s=this.tempQuat.setFromAxisAngle(ne,i);e.multiply(s);const r=t.angularVelocity;r instanceof J&&r.copy(s)}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new Be(Pt(t.angularVelocity))}frameUpdate(t){this.angularVelocity.refreshTable?.()}clone(){return new Be(this.angularVelocity.clone())}reset(){}}class $e{initialize(t){this.size.startGen(t.memory)}constructor(t,e){this.size=t,this.speedRange=e,this.type="SizeBySpeed"}update(t){const e=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.size instanceof Qt?this.size.genValue(t.memory,t.size,e).multiply(t.startSize):t.size.copy(t.startSize).multiplyScalar(this.size.genValue(t.memory,e))}toJSON(){return{type:this.type,size:this.size.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new $e(Gt(t.size),Mt.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new $e(this.size.clone(),this.speedRange.clone())}reset(){}}class Fe{constructor(t){this.type="SizeOverLife",this._sizeIsVector3=!1,this.size=t}get size(){return this._size}set size(t){this._size=t,this._sizeIsVector3=t instanceof Qt}initialize(t){this._size.startGen(t.memory)}update(t){const e=t.age/t.life;if(this._sizeIsVector3)this._size.genValue(t.memory,t.size,e).multiply(t.startSize);else{const i=this._size.genValue(t.memory,e),s=t.size,r=t.startSize;s.x=r.x*i,s.y=r.y*i,s.z=r.z*i}}updateAll(t,e,i){if(this._sizeIsVector3){const i=this._size;for(let s=0;s<e;s++){const e=t[s];e.age>=e.life||i.genValue(e.memory,e.size,e.age/e.life).multiply(e.startSize)}return}const s=this._size;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const r=s.genValue(e.memory,e.age/e.life),n=e.size,o=e.startSize;n.x=o.x*r,n.y=o.y*r,n.z=o.z*r}}toJSON(){return{type:this.type,size:this.size.toJSON()}}static fromJSON(t){return new Fe(Gt(t.size))}frameUpdate(t){this._size.refreshTable?.()}clone(){return new Fe(this.size.clone())}reset(){}}class Ee{initialize(t){this.speed.startGen(t.memory)}constructor(t){this.speed=t,this.type="SpeedOverLife"}update(t){t.speedModifier=this.speed.genValue(t.memory,t.age/t.life)}updateAll(t,e,i){const s=this.speed;for(let i=0;i<e;i++){const e=t[i];e.age>=e.life||(e.speedModifier=s.genValue(e.memory,e.age/e.life))}}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(t){return new Ee(Pt(t.speed))}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new Ee(this.speed.clone())}reset(){}}class Ne{constructor(t,e,i,s){this.scale=t,this.octaves=e,this.velocityMultiplier=i,this.timeScale=s,this.type="TurbulenceField",this.generator=new be,this.timeOffset=new k,this.temp=new k,this.temp2=new k,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(t){}update(t,e){const i=t.position.x/this.scale.x,s=t.position.y/this.scale.y,r=t.position.z/this.scale.z;this.temp.set(0,0,0);let n=1;for(let t=0;t<this.octaves;t++)this.temp2.set(this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.x*n)/n,this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.y*n)/n,this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.z*n)/n),this.temp.add(this.temp2),n*=2;this.temp.multiply(this.velocityMultiplier),t.velocity.addScaledVector(this.temp,e)}updateAll(t,e,i){const s=e>0?t[0].store:void 0;if(void 0===s){for(let s=0;s<e;s++){const e=t[s];e.age<e.life&&this.update(e,i)}return}const r=s.position,n=s.velocity,o=s.scalars,a=pe.SCALAR_STRIDE,h=this.generator,l=this.octaves,c=1/this.scale.x,u=1/this.scale.y,d=1/this.scale.z,p=this.velocityMultiplier.x*i,f=this.velocityMultiplier.y*i,m=this.velocityMultiplier.z*i,y=this.timeOffset.x,v=this.timeOffset.y,x=this.timeOffset.z;for(let t=0,i=0,s=0;t<e;t++,i+=3,s+=a){if(o[s]>=o[s+1])continue;const t=r[i]*c,e=r[i+1]*u,a=r[i+2]*d;let g=0,S=0,w=0,b=1;for(let i=0;i<l;i++){const i=t*b,s=e*b,r=a*b;g+=h.noise4D(i,s,r,y*b)/b,S+=h.noise4D(i,s,r,v*b)/b,w+=h.noise4D(i,s,r,x*b)/b,b*=2}n[i]+=g*p,n[i+1]+=S*f,n[i+2]+=w*m}}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(t){this.timeOffset.x+=t*this.timeScale.x,this.timeOffset.y+=t*this.timeScale.y,this.timeOffset.z+=t*this.timeScale.z}static fromJSON(t){return new Ne(new k(t.scale[0],t.scale[1],t.scale[2]),t.octaves,new k(t.velocityMultiplier[0],t.velocityMultiplier[1],t.velocityMultiplier[2]),new k(t.timeScale[0],t.timeScale[1],t.timeScale[2]))}clone(){return new Ne(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const Ie=new k(1,0,0),Le=new k(0,1,0),Re=new k(0,0,1);class Ue{constructor(t=new bt(0),e=new bt(0),i=new bt(0),s=new bt(0),r=new bt(0),n=new bt(0),o="local"){this.linearX=t,this.linearY=e,this.linearZ=i,this.orbitalX=s,this.orbitalY=r,this.orbitalZ=n,this.space=o,this.type="VelocityOverLife",this._temp=new k,this._tempEmitterPos=new k,this._tempQ=new J,this._tempQInv=new J,this._tempScale=new k(1,1,1),this._tempScaleInv=new k(1,1,1),this._tempRot=new J,this._axisX=new k(1,0,0),this._axisY=new k(0,1,0),this._axisZ=new k(0,0,1)}initialize(t,e){this.ps=e,this.linearX.startGen(t.memory),this.linearY.startGen(t.memory),this.linearZ.startGen(t.memory),this.orbitalX.startGen(t.memory),this.orbitalY.startGen(t.memory),this.orbitalZ.startGen(t.memory)}frameUpdate(t){this.ps&&(this.ps.emitter.matrixWorld.decompose(this._tempEmitterPos,this._tempQ,this._tempScale),this._tempQInv.copy(this._tempQ).invert(),this._tempScaleInv.set(1/this._tempScale.x,1/this._tempScale.y,1/this._tempScale.z),this._axisX.copy(Ie),this._axisY.copy(Le),this._axisZ.copy(Re),this.ps.worldSpace&&(this._axisX.applyQuaternion(this._tempQ),this._axisY.applyQuaternion(this._tempQ),this._axisZ.applyQuaternion(this._tempQ)))}update(t,e){const i=t.age/t.life;this._temp.set(this.linearX.genValue(t.memory,i),this.linearY.genValue(t.memory,i),this.linearZ.genValue(t.memory,i));const s=void 0!==this.ps&&this.ps.worldSpace;s&&"local"===this.space?this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ):s||"world"!==this.space||this._temp.multiply(this._tempScaleInv).applyQuaternion(this._tempQInv),t.position.addScaledVector(this._temp,e);const r=this.orbitalX.genValue(t.memory,i)*e,n=this.orbitalY.genValue(t.memory,i)*e,o=this.orbitalZ.genValue(t.memory,i)*e;0===r&&0===n&&0===o||(s&&t.position.sub(this._tempEmitterPos),this.orbit(t.position,this._axisX,r),this.orbit(t.position,this._axisY,n),this.orbit(t.position,this._axisZ,o),s&&t.position.add(this._tempEmitterPos))}orbit(t,e,i){0!==i&&(this._tempRot.setFromAxisAngle(e,i),t.applyQuaternion(this._tempRot))}toJSON(){return{type:this.type,linearX:this.linearX.toJSON(),linearY:this.linearY.toJSON(),linearZ:this.linearZ.toJSON(),orbitalX:this.orbitalX.toJSON(),orbitalY:this.orbitalY.toJSON(),orbitalZ:this.orbitalZ.toJSON(),space:this.space}}static fromJSON(t){const e=t=>t?Pt(t):new bt(0);return new Ue(e(t.linearX),e(t.linearY),e(t.linearZ),e(t.orbitalX),e(t.orbitalY),e(t.orbitalZ),"world"===t.space?"world":"local")}clone(){return new Ue(this.linearX.clone(),this.linearY.clone(),this.linearZ.clone(),this.orbitalX.clone(),this.orbitalY.clone(),this.orbitalZ.clone(),this.space)}reset(){}}class De{constructor(t){this.data=t,this.next=null,this.prev=null}hasPrev(){return null!==this.prev}hasNext(){return null!==this.next}}class qe{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return null===this.head}clear(){this.length=0,this.head=this.tail=null}front(){return null===this.head?null:this.head.data}back(){return null===this.tail?null:this.tail.data}dequeue(){if(this.head){const t=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}}pop(){if(this.tail){const t=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}}queue(t){const e=new De(t);this.tail||(this.tail=e),this.head&&(this.head.prev=e,e.next=this.head),this.head=e,this.length++}push(t){const e=new De(t);this.head||(this.head=e),this.tail&&(this.tail.next=e,e.prev=this.tail),this.tail=e,this.length++}insertBefore(t,e){const i=new De(e);i.next=t,i.prev=t.prev,null!==i.prev&&(i.prev.next=i),i.next.prev=i,t==this.head&&(this.head=i),this.length++}remove(t){if(null===this.head||null===this.tail)return;let e=this.head;for(t===this.head.data&&(this.head=this.head.next),t===this.tail.data&&(this.tail=this.tail.prev);null!==e.next&&e.data!==t;)e=e.next;e.data===t&&(null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.length--)}*values(){let t=this.head;for(;null!==t;)yield t.data,t=t.next}}class Je{get startSpeed(){return this.store.startSpeed[this.storeIndex]}set startSpeed(t){this.store.startSpeed[this.storeIndex]=t}get age(){return this.scalars[this.scalarOffset]}set age(t){this.scalars[this.scalarOffset]=t}get life(){return this.scalars[this.scalarOffset+1]}set life(t){this.scalars[this.scalarOffset+1]=t}get speedModifier(){return this.scalars[this.scalarOffset+2]}set speedModifier(t){this.scalars[this.scalarOffset+2]=t}get angularVelocity(){const t=this.angularVelocityQuaternion;return void 0!==t?t:this.store.angularVelocity[this.storeIndex]}set angularVelocity(t){if("number"==typeof t)this.angularVelocityQuaternion=void 0,this.store.angularVelocity[this.storeIndex]=t;else if(void 0===t)this.angularVelocityQuaternion=void 0,this.store.angularVelocity[this.storeIndex]=0;else{let e=this.angularVelocityQuaternion;void 0===e&&(this.store.ensureQuaternionColumns(),e=new lt(this.store.angularVelocityQuaternion,4*this.storeIndex),this.angularVelocityQuaternion=e),e!==t&&e.copy(t)}}get rotation(){const t=this.rotationQuaternion;return void 0!==t?t:this.store.rotation[this.storeIndex]}set rotation(t){if("number"==typeof t)this.rotationQuaternion=void 0,this.store.rotation[this.storeIndex]=t;else{let e=this.rotationQuaternion;void 0===e&&(this.store.ensureQuaternionColumns(),e=new lt(this.store.rotationQuaternion,4*this.storeIndex),this.rotationQuaternion=e),e!==t&&e.copy(t)}}get uvTile(){return this.store.uvTile[this.storeIndex]}set uvTile(t){this.store.uvTile[this.storeIndex]=t}get flip(){return this.store.flip[this.storeIndex]}set flip(t){this.store.flip[this.storeIndex]=t}constructor(t=new pe(1),e=0){this.rotationQuaternion=void 0,this.angularVelocityQuaternion=void 0,this.memory=[],this.store=t,this.storeIndex=e;const i=3*e,s=4*e;this.position=new pt(t.position,i),this.previousPosition=new pt(t.previousPosition,i),this.previousVelocity=new pt(t.previousVelocity,i),this.velocity=new pt(t.velocity,i),this.size=new pt(t.size,i),this.startSize=new pt(t.startSize,i),this.color=new vt(t.color,s),this.startColor=new vt(t.startColor,s),this.scalars=t.scalars,this.scalarOffset=e*pe.SCALAR_STRIDE,this.size.set(1,1,1),this.startSize.set(1,1,1),this.life=1,this.speedModifier=1}setStoreIndex(t){this.storeIndex=t,this.rebind()}rebind(){const t=this.store,e=3*this.storeIndex,i=4*this.storeIndex;this.position.bind(t.position,e),this.previousPosition.bind(t.previousPosition,e),this.previousVelocity.bind(t.previousVelocity,e),this.velocity.bind(t.velocity,e),this.size.bind(t.size,e),this.startSize.bind(t.startSize,e),this.color.bind(t.color,i),this.startColor.bind(t.startColor,i),this.rotationQuaternion?.bind(t.rotationQuaternion,i),this.angularVelocityQuaternion?.bind(t.angularVelocityQuaternion,i),this.scalars=t.scalars,this.scalarOffset=this.storeIndex*pe.SCALAR_STRIDE}get died(){return this.age>=this.life}reset(){this.memory.length=0}}const ke=new Float32Array(0);class Qe{get startSpeed(){return this.store.startSpeed[this.storeIndex]}set startSpeed(t){this.store.startSpeed[this.storeIndex]=t}get age(){return this.scalars[this.scalarOffset]}set age(t){this.scalars[this.scalarOffset]=t}get life(){return this.scalars[this.scalarOffset+1]}set life(t){this.scalars[this.scalarOffset+1]=t}get speedModifier(){return this.scalars[this.scalarOffset+2]}set speedModifier(t){this.scalars[this.scalarOffset+2]=t}get previous(){return this._previous??(this._previous=new qe)}set previous(t){this._previous=t}get uvTile(){return this.store.uvTile[this.storeIndex]}set uvTile(t){this.store.uvTile[this.storeIndex]=t}constructor(t=new pe(1),e=0){this.length=100,this._previous=void 0,this.historyPositions=ke,this.historySizes=ke,this.historyBaseSizes=ke,this.headWidthScale=1,this.historyColors=ke,this.historyCapacity=0,this.historyHead=0,this.historyCount=0,this.memory=[],this.store=t,this.storeIndex=e;const i=3*e,s=4*e;this.position=new pt(t.position,i),this.previousPosition=new pt(t.previousPosition,i),this.previousVelocity=new pt(t.previousVelocity,i),this.velocity=new pt(t.velocity,i),this.size=new pt(t.size,i),this.startSize=new pt(t.startSize,i),this.color=new vt(t.color,s),this.startColor=new vt(t.startColor,s),this.scalars=t.scalars,this.scalarOffset=e*pe.SCALAR_STRIDE,this.size.set(1,1,1),this.startSize.set(1,1,1),this.life=1,this.speedModifier=1}setStoreIndex(t){this.storeIndex=t,this.rebind()}rebind(){const t=this.store,e=3*this.storeIndex,i=4*this.storeIndex;this.position.bind(t.position,e),this.previousPosition.bind(t.previousPosition,e),this.previousVelocity.bind(t.previousVelocity,e),this.velocity.bind(t.velocity,e),this.size.bind(t.size,e),this.startSize.bind(t.startSize,e),this.color.bind(t.color,i),this.startColor.bind(t.startColor,i),this.scalars=t.scalars,this.scalarOffset=this.storeIndex*pe.SCALAR_STRIDE}ensureHistoryCapacity(t){this.historyCapacity!==t&&(this.historyCapacity=t,this.historyPositions=new Float32Array(3*t),this.historySizes=new Float32Array(t),this.historyBaseSizes=new Float32Array(t),this.historyColors=new Float32Array(4*t),this.historyHead=0,this.historyCount=0)}resetHistory(){this.historyHead=0,this.historyCount=0}getHistoryIndex(t){const e=this.historyCapacity;return(this.historyHead-this.historyCount+e+t)%e}update(){0===this.historyCapacity&&this.ensureHistoryCapacity(Math.max(1,Math.ceil(this.length)));const t=this.historyCapacity,e=this.store,i=this.storeIndex,s=i*pe.SCALAR_STRIDE;if(e.scalars[s+pe.AGE]>e.scalars[s+pe.LIFE])return void(this.historyCount>0&&this.historyCount--);const r=this.historyHead,n=3*r,o=this.historyPositions,a=e.position,h=3*i;o[n]=a[h],o[n+1]=a[h+1],o[n+2]=a[h+2];const l=e.size[h];this.historyBaseSizes[r]=l,this.historySizes[r]=l*this.headWidthScale;const c=4*r,u=this.historyColors,d=e.color,p=4*i;u[c]=d[p],u[c+1]=d[p+1],u[c+2]=d[p+2],u[c+3]=d[p+3],this.historyHead=(r+1)%t,this.historyCount<t&&this.historyCount++}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.headWidthScale=1,this.resetHistory()}}class We{initialize(t){this.width.startGen(t.memory)}constructor(t,e=!1){this.width=t,this.absolute=e,this.type="WidthOverLength"}update(t){if(!(t instanceof Qe))return;const e=t.memory;t.headWidthScale=this.absolute?1:this.width.genValue(e,0);const i=t.historyCount;if(0===i)return;const s=t.historyCapacity,r=t.historySizes,n=t.historyBaseSizes,o=1/t.length,a=this.absolute;let h=t.getHistoryIndex(0);for(let t=0;t<i;t++){const l=this.width.genValue(e,(i-t)*o);r[h]=a?l:n[h]*l,h++,h===s&&(h=0)}}frameUpdate(t){}toJSON(){return{type:this.type,width:this.width.toJSON(),absolute:this.absolute}}static fromJSON(t){return new We(Pt(t.width),t.absolute??!0)}clone(){return new We(this.width.clone(),this.absolute)}reset(){}}const Ge={ApplyForce:{type:"ApplyForce",constructor:jt,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:jt.fromJSON},Noise:{type:"Noise",constructor:Ve,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Ve.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Ne,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Ne.fromJSON},GravityForce:{type:"GravityForce",constructor:ce,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:ce.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:te,params:[["color",["colorFunc"]]],loadJSON:te.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Be,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Be.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Ce,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Ce.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Fe,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Fe.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Kt,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Kt.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Ae,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Ae.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:$e,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:$e.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Ee,params:[["speed",["value","valueFunc"]]],loadJSON:Ee.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:le,params:[["frame",["value","valueFunc"]]],loadJSON:le.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:he,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:he.fromJSON},VelocityOverLife:{type:"VelocityOverLife",constructor:Ue,params:[["linearX",["value","valueFunc"]],["linearY",["value","valueFunc"]],["linearZ",["value","valueFunc"]],["orbitalX",["value","valueFunc"]],["orbitalY",["value","valueFunc"]],["orbitalZ",["value","valueFunc"]],["space",["string"]]],loadJSON:Ue.fromJSON},InheritVelocity:{type:"InheritVelocity",constructor:ue,params:[["multiplier",["value","valueFunc"]],["mode",["string"]]],loadJSON:ue.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Oe,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Oe.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:We,params:[["width",["value","valueFunc"]]],loadJSON:We.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:Ht,params:[["angle",["value"]]],loadJSON:Ht.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:ae,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:ae.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:de,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:de.fromJSON},ApplyCollision:{type:"ApplyCollision",constructor:wt,params:[["bounce",["number"]]],loadJSON:wt.fromJSON}};function je(t,e){return Ge[t.type]?Ge[t.type].loadJSON(t,e):null}const Ye={PiecewiseBezier:Tt,Vector3Function:Qt,Quaternion:J,ConstantValue:bt,Gradient:Nt,Vector4View:vt,AxisAngleGenerator:Vt,IntervalValue:Mt,ColorRange:$t};function Xe(t,e){return`const ${t} = ${e};\n const ${t}_tbl = ${t} instanceof deps.PiecewiseBezier ? ${t}.sampledTable() : null;\n const ${t}_last = ${t}_tbl !== null ? ${t}_tbl.length - 1 : 0;\n const ${t}_const = ${t} instanceof deps.ConstantValue;\n const ${t}_cv = ${t}_const ? ${t}.value : 0;\n const ${t}_iv = ${t} instanceof deps.IntervalValue;\n const ${t}_slot = ${t}_iv ? ${t}.indexCount : -1;\n const ${t}_col = ${t}_slot >= 0 && ${t}_slot < ms;\n const ${t}_a = ${t}_iv ? ${t}.a : 0, ${t}_b = ${t}_iv ? ${t}.b : 0;`}function Ze(t,e,i){return`let ${e};\n if (${t}_tbl !== null) {\n const tt = ${i};\n if (tt <= 0) ${e} = ${t}_tbl[0];\n else if (tt >= 1) ${e} = ${t}_tbl[${t}_last];\n else {\n const x = tt * ${t}_last;\n const ix = x | 0;\n const v0 = ${t}_tbl[ix];\n ${e} = v0 + (${t}_tbl[ix + 1] - v0) * (x - ix);\n }\n } else if (${t}_const) ${e} = ${t}_cv;\n else if (${t}_iv) {\n // The particle's own sample, from the memory column when it holds it.\n let r = ${t}_col ? mem[row * ms + ${t}_slot] : NaN;\n if (r !== r) r = p.memory[${t}_slot];\n ${e} = (1 - r) * ${t}_a + r * ${t}_b;\n } else ${e} = ${t}.genValue(p.memory, ${i});`}function He(t,e){return`const ${t} = ${e};\n const ${t}_tbl = ${t} instanceof deps.Gradient ? ${t}.sampledTable() : null;\n const ${t}_last = ${t}_tbl !== null ? ${t}_tbl.length / 4 - 1 : 0;\n const ${t}_cr = ${t} instanceof deps.ColorRange;\n const ${t}_slot = ${t}_cr ? ${t}.indexCount : -1;\n const ${t}_col = ${t}_slot >= 0 && ${t}_slot < ms;\n // Rounded to float32 as copying the colour into the particle does.\n const ${t}_ax = ${t}_cr ? Math.fround(${t}.a.x) : 0, ${t}_ay = ${t}_cr ? Math.fround(${t}.a.y) : 0;\n const ${t}_az = ${t}_cr ? Math.fround(${t}.a.z) : 0, ${t}_aw = ${t}_cr ? Math.fround(${t}.a.w) : 0;\n const ${t}_bx = ${t}_cr ? ${t}.b.x : 0, ${t}_by = ${t}_cr ? ${t}.b.y : 0;\n const ${t}_bz = ${t}_cr ? ${t}.b.z : 0, ${t}_bw = ${t}_cr ? ${t}.b.w : 0;`}function Ke(t,e){return`if (${t}_tbl !== null) {\n const tt = ${e};\n const tbl = ${t}_tbl;\n let r, g, b, a;\n if (tt <= 0) {\n r = tbl[0]; g = tbl[1]; b = tbl[2]; a = tbl[3];\n } else if (tt >= 1) {\n const o = ${t}_last * 4;\n r = tbl[o]; g = tbl[o + 1]; b = tbl[o + 2]; a = tbl[o + 3];\n } else {\n const x = tt * ${t}_last;\n const ix = x | 0;\n const fr = x - ix;\n const o = ix * 4;\n const nx = o + 4;\n r = tbl[o] + (tbl[nx] - tbl[o]) * fr;\n g = tbl[o + 1] + (tbl[nx + 1] - tbl[o + 1]) * fr;\n b = tbl[o + 2] + (tbl[nx + 2] - tbl[o + 2]) * fr;\n a = tbl[o + 3] + (tbl[nx + 3] - tbl[o + 3]) * fr;\n }\n color[o4] = Math.fround(r) * startColor[o4];\n color[o4 + 1] = Math.fround(g) * startColor[o4 + 1];\n color[o4 + 2] = Math.fround(b) * startColor[o4 + 2];\n color[o4 + 3] = Math.fround(a) * startColor[o4 + 3];\n } else if (${t}_cr) {\n let r = ${t}_col ? mem[row * ms + ${t}_slot] : NaN;\n if (r !== r) r = p.memory[${t}_slot];\n color[o4] = Math.fround(${t}_ax + (${t}_bx - ${t}_ax) * r) * startColor[o4];\n color[o4 + 1] = Math.fround(${t}_ay + (${t}_by - ${t}_ay) * r) * startColor[o4 + 1];\n color[o4 + 2] = Math.fround(${t}_az + (${t}_bz - ${t}_az) * r) * startColor[o4 + 2];\n color[o4 + 3] = Math.fround(${t}_aw + (${t}_bw - ${t}_aw) * r) * startColor[o4 + 3];\n } else {\n ${t}.genColor(p.memory, tmpColor, ${e});\n color[o4] = tmpColor.x * startColor[o4];\n color[o4 + 1] = tmpColor.y * startColor[o4 + 1];\n color[o4 + 2] = tmpColor.z * startColor[o4 + 2];\n color[o4 + 3] = tmpColor.w * startColor[o4 + 3];\n }`}function ti(t,e,i,s,r,n,o){return`{\n const cx = 2 * (${r} * ${i} - ${n} * ${e});\n const cy = 2 * (${n} * ${t} - ${s} * ${i});\n const cz = 2 * (${s} * ${e} - ${r} * ${t});\n const nx = ${t} + ${o} * cx + ${r} * cz - ${n} * cy;\n const ny = ${e} + ${o} * cy + ${n} * cx - ${s} * cz;\n ${i} = ${i} + ${o} * cz + ${s} * cy - ${r} * cx;\n ${t} = nx;\n ${e} = ny;\n }`}function ei(t,e){return`const ${t}_q = ${e};\n const ${t}x = ${t}_q.x, ${t}y = ${t}_q.y, ${t}z = ${t}_q.z, ${t}w = ${t}_q.w;`}function ii(t,e){return`const ${t}_v = ${e};\n const ${t}x = ${t}_v.x, ${t}y = ${t}_v.y, ${t}z = ${t}_v.z;`}function si(t,e,i,s){return`{\n const half = ${t} / 2;\n const sn = Math.sin(half);\n const qx = ${e} * sn, qy = ${i} * sn, qz = ${s} * sn, qw = Math.cos(half);\n ${ti("px","py","pz","qx","qy","qz","qw")}\n px = Math.fround(px); py = Math.fround(py); pz = Math.fround(pz);\n }`}function ri(t,e){switch(t.type){case"ColorOverLife":return{setup:He(`g${e}`,`behaviors[${e}].color`),body:`{${Ke(`g${e}`,"t")}}`};case"SizeOverLife":return{setup:`const g${e} = behaviors[${e}].size;\n const vec3_${e} = g${e} instanceof deps.Vector3Function;\n ${Xe(`sg${e}`,`g${e}`)}`,body:`if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, t).multiply(p.startSize);\n } else {\n ${Ze(`sg${e}`,"v","t")}\n size[o3] = startSize[o3] * v;\n size[o3 + 1] = startSize[o3 + 1] * v;\n size[o3 + 2] = startSize[o3 + 2] * v;\n }`};case"ApplyForce":return{setup:`const b${e} = behaviors[${e}];\n const f${e} = b${e}.magnitudeValue * delta;\n const dx${e} = b${e}.direction.x * f${e};\n const dy${e} = b${e}.direction.y * f${e};\n const dz${e} = b${e}.direction.z * f${e};`,body:`vel[o3] += dx${e}; vel[o3 + 1] += dy${e}; vel[o3 + 2] += dz${e};`};case"RotationOverLife":return{setup:`${Xe(`g${e}`,`behaviors[${e}].angularVelocity`)}\n const rotation_${e} = count > 0 ? particles[0].rotation : undefined;\n const angle_${e} = typeof rotation_${e} === 'number';\n const rq${e} = store.rotationQuaternion, aq${e} = store.angularVelocityQuaternion;\n const quat_${e} = !angle_${e} && rq${e}.length > 0 && rotation_${e} instanceof deps.Quaternion;`,body:`if (angle_${e}) {\n ${Ze(`g${e}`,"rate","t")}\n rot[row] += delta * rate;\n angVel[row] = rate;\n } else if (quat_${e}) {\n ${Ze(`g${e}`,"rate","t")}\n const half = (rate * delta) / 2;\n const qz = Math.sin(half), qw = Math.cos(half);\n const ax = rq${e}[o4], ay = rq${e}[o4 + 1], az = rq${e}[o4 + 2], aw = rq${e}[o4 + 3];\n rq${e}[o4] = ax * qw + ay * qz;\n rq${e}[o4 + 1] = ay * qw - ax * qz;\n rq${e}[o4 + 2] = az * qw + aw * qz;\n rq${e}[o4 + 3] = aw * qw - az * qz;\n aq${e}[o4] = 0; aq${e}[o4 + 1] = 0; aq${e}[o4 + 2] = qz; aq${e}[o4 + 3] = qw;\n }`};case"FrameOverLife":return{setup:Xe(`g${e}`,`behaviors[${e}].frame`),body:`{${Ze(`g${e}`,"v","t")} uvTile[row] = v;}`};case"SpeedOverLife":return{setup:Xe(`g${e}`,`behaviors[${e}].speed`),body:`{${Ze(`g${e}`,"v","t")} scalars[s + 2] = v;}`};case"ForceOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${Xe(`gx${e}`,`b${e}.x`)}\n ${Xe(`gy${e}`,`b${e}.y`)}\n ${Xe(`gz${e}`,`b${e}.z`)}\n const local${e} = b${e}.ps !== undefined && !b${e}.ps.worldSpace;\n ${ii(`sc${e}`,`b${e}._tempScale`)}\n ${ei(`q${e}`,`b${e}._tempQ`)}`,body:`{\n ${Ze(`gx${e}`,"fx","t")}\n ${Ze(`gy${e}`,"fy","t")}\n ${Ze(`gz${e}`,"fz","t")}\n if (local${e}) {\n fx *= sc${e}x; fy *= sc${e}y; fz *= sc${e}z;\n ${ti("fx","fy","fz",`q${e}x`,`q${e}y`,`q${e}z`,`q${e}w`)}\n }\n vel[o3] += fx * delta; vel[o3 + 1] += fy * delta; vel[o3 + 2] += fz * delta;}`};case"LimitSpeedOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${Xe(`g${e}`,`b${e}.speed`)}\n const dampen${e} = b${e}.dampen * delta * 20;`,body:`{const vx = vel[o3], vy = vel[o3 + 1], vz = vel[o3 + 2];\n const speed = Math.sqrt(vx * vx + vy * vy + vz * vz);\n ${Ze(`g${e}`,"limit","t")}\n if (speed > limit) {\n const f = 1 - ((speed - limit) / speed) * dampen${e};\n vel[o3] = vx * f; vel[o3 + 1] = vy * f; vel[o3 + 2] = vz * f;\n }}`};case"GravityForce":return{setup:`const b${e} = behaviors[${e}];\n const cx${e} = b${e}.center.x, cy${e} = b${e}.center.y, cz${e} = b${e}.center.z;\n const gm${e} = b${e}.magnitude * delta;`,body:`{const dx = cx${e} - pos[o3], dy = cy${e} - pos[o3 + 1], dz = cz${e} - pos[o3 + 2];\n const d2 = dx * dx + dy * dy + dz * dz;\n if (d2 > 0) {\n const f = gm${e} / (d2 * Math.sqrt(d2));\n vel[o3] += dx * f; vel[o3 + 1] += dy * f; vel[o3 + 2] += dz * f;\n }}`};case"ColorBySpeed":return{setup:`const b${e} = behaviors[${e}];\n ${He(`g${e}`,`b${e}.color`)}\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};`,body:`{const ts = (startSpeed[row] - lo${e}) / span${e};\n ${Ke(`g${e}`,"ts")}}`};case"SizeBySpeed":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.size;\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};\n const vec3_${e} = g${e} instanceof deps.Vector3Function;\n ${Xe(`sg${e}`,`g${e}`)}`,body:`{const ts = (startSpeed[row] - lo${e}) / span${e};\n if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, ts).multiply(p.startSize);\n } else {\n ${Ze(`sg${e}`,"v","ts")}\n size[o3] = startSize[o3] * v;\n size[o3 + 1] = startSize[o3 + 1] * v;\n size[o3 + 2] = startSize[o3 + 2] * v;\n }}`};case"RotationBySpeed":return{setup:`const b${e} = behaviors[${e}];\n ${Xe(`g${e}`,`b${e}.angularVelocity`)}\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};\n const angle_${e} = count > 0 && typeof particles[0].rotation === 'number';`,body:`if (angle_${e}) {\n const ts = (startSpeed[row] - lo${e}) / span${e};\n ${Ze(`g${e}`,"rate","ts")}\n rot[row] += delta * rate;\n angVel[row] = rate;\n }`};case"OrbitOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${Xe(`g${e}`,`b${e}.orbitSpeed`)}\n ${ii(`ax${e}`,`b${e}.axis`)}\n const alen${e} = ax${e}x * ax${e}x + ax${e}y * ax${e}y + ax${e}z * ax${e}z;\n const chalf${e} = (g${e}_cv * delta) / 2;\n const csn${e} = Math.sin(chalf${e});\n const cqx${e} = ax${e}x * csn${e}, cqy${e} = ax${e}y * csn${e}, cqz${e} = ax${e}z * csn${e};\n const cqw${e} = Math.cos(chalf${e});`,body:`{let px = pos[o3], py = pos[o3 + 1], pz = pos[o3 + 2];\n let tx = 0, ty = 0, tz = 0;\n if (alen${e} !== 0) {\n const f = (ax${e}x * px + ax${e}y * py + ax${e}z * pz) / alen${e};\n tx = ax${e}x * f; ty = ax${e}y * f; tz = ax${e}z * f;\n }\n let qx, qy, qz, qw;\n if (g${e}_const) {\n qx = cqx${e}; qy = cqy${e}; qz = cqz${e}; qw = cqw${e};\n } else {\n ${Ze(`g${e}`,"sp","t")}\n const half = (sp * delta) / 2;\n const sn = Math.sin(half);\n qx = ax${e}x * sn; qy = ax${e}y * sn; qz = ax${e}z * sn; qw = Math.cos(half);\n }\n px = Math.fround(px - tx); py = Math.fround(py - ty); pz = Math.fround(pz - tz);\n ${ti("px","py","pz","qx","qy","qz","qw")}\n pos[o3] = Math.fround(px) + tx;\n pos[o3 + 1] = Math.fround(py) + ty;\n pos[o3 + 2] = Math.fround(pz) + tz;}`};case"Rotation3DOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.angularVelocity;\n const q${e} = b${e}.tempQuat;\n const rq${e} = store.rotationQuaternion, aq${e} = store.angularVelocityQuaternion;\n const quat_${e} = rq${e}.length > 0 && count > 0 && particles[0].rotation instanceof deps.Quaternion;\n const fixed_${e} = g${e} instanceof deps.AxisAngleGenerator && g${e}.angle instanceof deps.ConstantValue;\n let cqx${e} = 0, cqy${e} = 0, cqz${e} = 0, cqw${e} = 1;\n if (fixed_${e}) {\n g${e}.genValue(undefined, q${e}, delta, 0);\n cqx${e} = q${e}.x; cqy${e} = q${e}.y; cqz${e} = q${e}.z; cqw${e} = q${e}.w;\n }`,body:`if (quat_${e}) {\n let qx, qy, qz, qw;\n if (fixed_${e}) {\n qx = cqx${e}; qy = cqy${e}; qz = cqz${e}; qw = cqw${e};\n } else {\n g${e}.genValue(p.memory, q${e}, delta, t);\n qx = q${e}.x; qy = q${e}.y; qz = q${e}.z; qw = q${e}.w;\n }\n const ax = rq${e}[o4], ay = rq${e}[o4 + 1], az = rq${e}[o4 + 2], aw = rq${e}[o4 + 3];\n rq${e}[o4] = ax * qw + aw * qx + ay * qz - az * qy;\n rq${e}[o4 + 1] = ay * qw + aw * qy + az * qx - ax * qz;\n rq${e}[o4 + 2] = az * qw + aw * qz + ax * qy - ay * qx;\n rq${e}[o4 + 3] = aw * qw - ax * qx - ay * qy - az * qz;\n aq${e}[o4] = qx; aq${e}[o4 + 1] = qy; aq${e}[o4 + 2] = qz; aq${e}[o4 + 3] = qw;\n }`};case"VelocityOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${Xe(`lx${e}`,`b${e}.linearX`)}\n ${Xe(`ly${e}`,`b${e}.linearY`)}\n ${Xe(`lz${e}`,`b${e}.linearZ`)}\n ${Xe(`ox${e}`,`b${e}.orbitalX`)}\n ${Xe(`oy${e}`,`b${e}.orbitalY`)}\n ${Xe(`oz${e}`,`b${e}.orbitalZ`)}\n ${ii(`aX${e}`,`b${e}._axisX`)}\n ${ii(`aY${e}`,`b${e}._axisY`)}\n ${ii(`aZ${e}`,`b${e}._axisZ`)}\n ${ii(`pv${e}`,`b${e}._tempEmitterPos`)}\n const world${e} = b${e}.ps !== undefined && b${e}.ps.worldSpace;\n const toWorld${e} = world${e} && b${e}.space === 'local';\n const convert${e} = toWorld${e} || (!world${e} && b${e}.space === 'world');\n ${ii(`sc${e}`,`toWorld${e} ? b${e}._tempScale : b${e}._tempScaleInv`)}\n ${ei(`q${e}`,`toWorld${e} ? b${e}._tempQ : b${e}._tempQInv`)}`,body:`{\n ${Ze(`lx${e}`,"fx","t")}\n ${Ze(`ly${e}`,"fy","t")}\n ${Ze(`lz${e}`,"fz","t")}\n if (convert${e}) {\n fx *= sc${e}x; fy *= sc${e}y; fz *= sc${e}z;\n ${ti("fx","fy","fz",`q${e}x`,`q${e}y`,`q${e}z`,`q${e}w`)}\n }\n let px = Math.fround(pos[o3] + fx * delta);\n let py = Math.fround(pos[o3 + 1] + fy * delta);\n let pz = Math.fround(pos[o3 + 2] + fz * delta);\n ${Ze(`ox${e}`,"rx","t")}\n ${Ze(`oy${e}`,"ry","t")}\n ${Ze(`oz${e}`,"rz","t")}\n rx *= delta; ry *= delta; rz *= delta;\n if (rx !== 0 || ry !== 0 || rz !== 0) {\n if (world${e}) {\n px = Math.fround(px - pv${e}x); py = Math.fround(py - pv${e}y); pz = Math.fround(pz - pv${e}z);\n }\n if (rx !== 0) ${si("rx",`aX${e}x`,`aX${e}y`,`aX${e}z`)}\n if (ry !== 0) ${si("ry",`aY${e}x`,`aY${e}y`,`aY${e}z`)}\n if (rz !== 0) ${si("rz",`aZ${e}x`,`aZ${e}y`,`aZ${e}z`)}\n if (world${e}) {\n px = Math.fround(px + pv${e}x); py = Math.fround(py + pv${e}y); pz = Math.fround(pz + pv${e}z);\n }\n }\n pos[o3] = px; pos[o3 + 1] = py; pos[o3 + 2] = pz;}`};case"InheritVelocity":return{setup:`const b${e} = behaviors[${e}];\n const ps${e} = b${e}.ps;\n const ev${e} = b${e}.mode === 'current' && ps${e} !== undefined ? ps${e}.emitterVelocity : undefined;\n const active${e} = ev${e} !== undefined;\n let ivx${e} = 0, ivy${e} = 0, ivz${e} = 0;\n if (active${e}) {\n ivx${e} = ev${e}.x; ivy${e} = ev${e}.y; ivz${e} = ev${e}.z;\n if (!ps${e}.worldSpace) {\n ${ii(`sc${e}`,`b${e}._tempScaleInv`)}\n ${ei(`q${e}`,`b${e}._tempQInv`)}\n ivx${e} *= sc${e}x; ivy${e} *= sc${e}y; ivz${e} *= sc${e}z;\n ${ti(`ivx${e}`,`ivy${e}`,`ivz${e}`,`q${e}x`,`q${e}y`,`q${e}z`,`q${e}w`)}\n }\n }\n ${Xe(`gm${e}`,`b${e}.multiplier`)}`,body:`if (active${e}) {\n ${Ze(`gm${e}`,"m","t")}\n const f = m * delta;\n pos[o3] += ivx${e} * f; pos[o3 + 1] += ivy${e} * f; pos[o3 + 2] += ivz${e} * f;\n }`};default:return null}}const ni=new Map;function oi(t,e,i){const s=ni.get(i);if(void 0!==s)return s??void 0;const r=function(t,e){const i=`\n if (count === 0) return;\n if (store === undefined) {\n store = particles[0].store;\n if (store === undefined) {\n // Particles of some other implementation, without columns: run the behaviors as they are.\n for (const k of [${e.join(", ")}]) {\n const b = behaviors[k];\n for (let i = 0; i < count; i++) {\n const p = particles[i];\n if (p.age < p.life) b.update(p, delta);\n }\n }\n return;\n }\n }\n const pos = store.position, vel = store.velocity;\n const size = store.size, startSize = store.startSize;\n const color = store.color, startColor = store.startColor;\n const scalars = store.scalars;\n const rot = store.rotation, angVel = store.angularVelocity;\n const uvTile = store.uvTile, startSpeed = store.startSpeed;\n const mem = store.memory, ms = store.memoryStride;\n ${t.map(t=>t.setup).join("\n")}\n // The system keeps particles[i] on row i. Anything else (a hand-built\n // list) is caught by its ends and read through each particle's row.\n const mapped = particles[0].storeIndex !== 0 || particles[count - 1].storeIndex !== count - 1;\n for (let i = 0; i < count; i++) {\n const p = particles[i];\n const row = mapped ? p.storeIndex : i;\n const s = row * 3;\n const age = scalars[s], life = scalars[s + 1];\n if (age >= life) continue;\n const t = age / life;\n const o3 = row * 3, o4 = row * 4;\n ${t.map(t=>t.body).join("\n")}\n }`;try{return new Function("deps",`const tmpColor = new deps.Vector4View(new Float32Array(4), 0);\n return function (behaviors, particles, count, delta, store) {${i}};`)(Ye)}catch(t){return}}(t,e);return ni.set(i,r??null),r}function ai(t){const e=[];let i=[],s=[],r=[],n=0;const o=()=>{if(0===s.length)return;const t=`${n}:${i.map(t=>t.type).join(",")}`,o=oi(s,r,t);if(void 0!==o)e.push({behaviors:i,run:o});else for(const t of i)e.push({behaviors:[t]});i=[],s=[],r=[]};for(let a=0;a<t.length;a++){const h=t[a],l=ri(h,a);null!==l?(0===s.length&&(n=a),i.push(h),s.push(l),r.push(a)):(o(),e.push({behaviors:[h]}))}return o(),e}var hi,li;exports.BoxEmitFrom=void 0,(hi=exports.BoxEmitFrom||(exports.BoxEmitFrom={}))[hi.Volume=0]="Volume",hi[hi.Shell=1]="Shell",hi[hi.Edge=2]="Edge";class ci{constructor(t={}){this.type="box",this._point=[0,0,0],this.width=t.width??1,this.height=t.height??1,this.depth=t.depth??1,this.emitFrom=t.emitFrom??exports.BoxEmitFrom.Volume,this.boxThickness=t.boxThickness?[...t.boxThickness]:[0,0,0]}update(t,e){}initialize(t,e){const i=this._point;for(let t=0;t<3;t++)i[t]=2*Math.random()-1;const s=Math.floor(3*Math.random())%3;this.emitFrom===exports.BoxEmitFrom.Shell?i[s]=this.onSurface(s):this.emitFrom===exports.BoxEmitFrom.Edge&&(i[(s+1)%3]=this.onSurface((s+1)%3),i[(s+2)%3]=this.onSurface((s+2)%3)),t.position.set(i[0]*this.width/2,i[1]*this.height/2,i[2]*this.depth/2),t.velocity.set(0,0,t.startSpeed)}onSurface(t){const e=Math.random()<.5?-1:1,i=this.boxThickness[t];return i<=0||Math.random()<.5?e:e*(1-2*i*Math.random())}toJSON(){return{type:"box",width:this.width,height:this.height,depth:this.depth,emitFrom:this.emitFrom,boxThickness:[...this.boxThickness]}}static fromJSON(t){return new ci({width:t.width,height:t.height,depth:t.depth,emitFrom:t.emitFrom,boxThickness:Array.isArray(t.boxThickness)?t.boxThickness:void 0})}clone(){return new ci({width:this.width,height:this.height,depth:this.depth,emitFrom:this.emitFrom,boxThickness:this.boxThickness})}}function ui(t,e,i,s){let r;switch(exports.EmitterMode.Random===t?e=Math.random():exports.EmitterMode.Burst===t&&s.isBursting&&(e=s.burstParticleIndex/s.burstParticleCount),r=i>0?Math.floor(e/i)*i:e,t){case exports.EmitterMode.Loop:r%=1;break;case exports.EmitterMode.PingPong:r=Math.abs(r%2-1)}return r}exports.EmitterMode=void 0,(li=exports.EmitterMode||(exports.EmitterMode={}))[li.Random=0]="Random",li[li.Loop=1]="Loop",li[li.PingPong=2]="PingPong",li[li.Burst=3]="Burst";class di{constructor(t,e,i){this.position=t??new k,this.rotation=e??new J,this.scale=i??new k(1,1,1)}apply(t){t.position.multiply(this.scale).applyQuaternion(this.rotation).add(this.position);const e=t.velocity,i=e.length();if(0===i)return;e.multiply(this.scale).applyQuaternion(this.rotation);const s=e.length();s>0&&e.multiplyScalar(i/s)}isIdentity(){const{position:t,rotation:e,scale:i}=this;return 0===t.x&&0===t.y&&0===t.z&&0===e.x&&0===e.y&&0===e.z&&1===e.w&&1===i.x&&1===i.y&&1===i.z}toJSON(){const t={},{position:e,rotation:i,scale:s}=this;return 0===e.x&&0===e.y&&0===e.z||(t.position=[e.x,e.y,e.z]),0===i.x&&0===i.y&&0===i.z&&1===i.w||(t.rotation=[i.x,i.y,i.z,i.w]),1===s.x&&1===s.y&&1===s.z||(t.scale=[s.x,s.y,s.z]),t}static fromJSON(t){if(!t)return;const{position:e,rotation:i,scale:s}=t;return new di(e?new k(e[0],e[1],e[2]):void 0,i?new J(i[0],i[1],i[2],i[3]):void 0,s?new k(s[0],s[1],s[2]):void 0)}static toShapeJSON(t){return t&&!t.isIdentity()?{transform:t.toJSON()}:{}}clone(){return new di(this.position.clone(),this.rotation.clone(),this.scale.clone())}}class pi{constructor(t={}){this.type="circle",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[],this.transform=t.transform}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e),s=q.lerp(1-this.thickness,1,Math.random()),r=i*this.arc;t.position.x=Math.cos(r),t.position.y=Math.sin(r),t.position.z=0,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*s),this.transform?.apply(t)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...di.toShapeJSON(this.transform)}}static fromJSON(t){return new pi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,transform:di.fromJSON(t.transform),spread:t.spread})}clone(){return new pi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class fi{constructor(t={}){this.type="cone",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.angle=t.angle??Math.PI/6,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[],this.transform=t.transform}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e),s=q.lerp(1-this.thickness,1,Math.random()),r=i*this.arc,n=Math.sqrt(s),o=Math.sin(r),a=Math.cos(r);t.position.x=n*a,t.position.y=n*o,t.position.z=0;const h=this.angle*n;t.velocity.set(0,0,Math.cos(h)).addScaledVector(t.position,Math.sin(h)).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius),this.transform?.apply(t)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...di.toShapeJSON(this.transform)}}static fromJSON(t){return new fi({radius:t.radius,arc:t.arc,thickness:t.thickness,angle:t.angle,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,transform:di.fromJSON(t.transform),spread:t.spread})}clone(){return new fi({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class mi{constructor(t={}){this.type="donut",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.donutRadius=t.donutRadius??.2*this.radius,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[],this.transform=t.transform,this._m1=new Y}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e),s=Math.random(),r=q.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,o=s*Math.PI*2,a=Math.sin(n),h=Math.cos(n);if(t.position.x=this.radius*h,t.position.y=this.radius*a,t.position.z=0,t.velocity.z=this.donutRadius*r*Math.sin(o),t.velocity.x=this.donutRadius*r*Math.cos(o)*h,t.velocity.y=this.donutRadius*r*Math.cos(o)*a,t.position.add(t.velocity),t.velocity.normalize().multiplyScalar(t.startSpeed),t.rotation instanceof J){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(se,t.velocity,ie),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"donut",radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...di.toShapeJSON(this.transform)}}static fromJSON(t){return new mi({radius:t.radius,arc:t.arc,thickness:t.thickness,donutRadius:t.donutRadius,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,transform:di.fromJSON(t.transform),spread:t.spread})}clone(){return new mi({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class yi{constructor(t={}){this.type="edge",this.currentValue=0,this.radius=t.radius??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[]}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e);t.position.set((2*i-1)*this.radius,0,0),t.velocity.set(0,t.startSpeed,0)}toJSON(){return{type:"edge",radius:this.radius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new yi({radius:t.radius,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,spread:t.spread})}clone(){return new yi({radius:this.radius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class vi{constructor(t={}){this.type="grid",this.width=t.width??1,this.height=t.height??1,this.column=t.column??10,this.row=t.row??10,this.transform=t.transform}initialize(t){const e=Math.floor(Math.random()*this.row),i=Math.floor(Math.random()*this.column);t.position.x=i*this.width/this.column-this.width/2,t.position.y=e*this.height/this.row-this.height/2,t.position.z=0,t.velocity.set(0,0,t.startSpeed),this.transform?.apply(t)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row,...di.toShapeJSON(this.transform)}}static fromJSON(t){return new vi({...t,transform:di.fromJSON(t.transform)})}clone(){return new vi({width:this.width,height:this.height,column:this.column,row:this.row,transform:this.transform?.clone()})}update(t,e){}}class xi{constructor(t={}){this.type="hemisphere",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[],this.transform=t.transform,this._m1=new Y}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e),s=Math.random(),r=q.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,o=Math.acos(s),a=Math.sin(n),h=Math.cos(n),l=Math.sin(o),c=Math.cos(o);if(t.position.x=l*h,t.position.y=l*a,t.position.z=c,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*r),t.rotation instanceof J){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(se,t.position,ie),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...di.toShapeJSON(this.transform)}}static fromJSON(t){return new xi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,transform:di.fromJSON(t.transform),spread:t.spread})}clone(){return new xi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class gi{constructor(t){this.type="point",this._m1=new Y,this.transform=t}update(t,e){}initialize(t){const e=Math.random(),i=Math.random(),s=e*Math.PI*2,r=Math.acos(2*i-1),n=Math.cbrt(Math.random()),o=Math.sin(s),a=Math.cos(s),h=Math.sin(r),l=Math.cos(r);if(t.velocity.x=n*h*a,t.velocity.y=n*h*o,t.velocity.z=n*l,t.velocity.multiplyScalar(t.startSpeed),t.position.setScalar(0),t.rotation instanceof J){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(se,t.velocity,ie),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"point",...di.toShapeJSON(this.transform)}}static fromJSON(t){return new gi(di.fromJSON(t?.transform))}clone(){return new gi(this.transform?.clone())}}class Si{constructor(t={}){this.type="sphere",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[],this.transform=t.transform,this._m1=new Y}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e),s=Math.random(),r=q.lerp(1-this.thickness,1,Math.random()),n=i*this.arc,o=Math.acos(2*s-1),a=Math.sin(n),h=Math.cos(n),l=Math.sin(o),c=Math.cos(o);if(t.position.x=l*h,t.position.y=l*a,t.position.z=c,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*r),t.rotation instanceof J){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(se,t.position,ie),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...di.toShapeJSON(this.transform)}}static fromJSON(t){return new Si({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,transform:di.fromJSON(t.transform),spread:t.spread})}clone(){return new Si({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class wi{constructor(t={}){this.type="rectangle",this.currentValue=0,this.width=t.width??10,this.height=t.height??10,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new bt(1),this.memory=[],this.transform=t.transform,this._m1=new Y}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=ui(this.mode,this.currentValue,this.spread,e)*(2*(this.width+this.height));let s,r;i<this.width?(s=i-this.width/2,r=-this.height/2):i<this.width+this.height?(s=this.width/2,r=i-this.width-this.height/2):i<2*this.width+this.height?(s=this.width/2-(i-this.width-this.height),r=this.height/2):(s=-this.width/2,r=this.height/2-(i-2*this.width-this.height));const n=Math.random(),o=1-this.thickness*n;if(t.position.x=s*o,t.position.y=r*o,t.position.z=0,t.velocity.x=s,t.velocity.y=r,t.velocity.z=0,t.velocity.normalize().multiplyScalar(t.startSpeed),t.rotation instanceof J){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(se,t.velocity,ie),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"rectangle",width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...di.toShapeJSON(this.transform)}}static fromJSON(t){return new wi({width:t.width,height:t.height,thickness:t.thickness,mode:t.mode,speed:t.speed?Pt(t.speed):void 0,transform:di.fromJSON(t.transform),spread:t.spread})}clone(){return new wi({width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}const bi={box:{type:"box",params:[["width",["number"]],["height",["number"]],["depth",["number"]],["emitFrom",["number"]],["boxThickness",["vec3"]]],constructor:ci,loadJSON:ci.fromJSON},circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:pi,loadJSON:pi.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:fi,loadJSON:fi.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:mi,loadJSON:mi.fromJSON},edge:{type:"edge",params:[["radius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:yi,loadJSON:yi.fromJSON},point:{type:"point",params:[],constructor:gi,loadJSON:gi.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Si,loadJSON:Si.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:xi,loadJSON:xi.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:vi,loadJSON:vi.fromJSON},rectangle:{type:"rectangle",params:[["width",["number"]],["height",["number"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:wi,loadJSON:wi.fromJSON}};function Mi(t,e){return bi[t.type].loadJSON(t,e)}const zi=[];function _i(t){if(!zi.find(e=>e.id===t.id)){t.initialize();for(const e of t.emitterShapes)bi[e.type]||(bi[e.type]=e);for(const e of t.behaviors)Ge[e.type]||(Ge[e.type]=e)}}class Ti{get mesh(){return this._mesh}set mesh(e){if(this._mesh=e,!e)return;const i=e.getVerticesData(t.VertexBuffer.PositionKind),s=e.getIndices();if(!i||!s)return;this._positions=new Float32Array(i),this._indices=new Int32Array(s),this._triangleIndexToArea.length=0;let r=0;const n=s.length/3;this._triangleIndexToArea.push(0);const o=new k,a=new k,h=new k;for(let t=0;t<n;t++){const e=s[3*t],n=s[3*t+1],l=s[3*t+2];o.set(i[3*e],i[3*e+1],i[3*e+2]),a.set(i[3*n],i[3*n+1],i[3*n+2]),h.set(i[3*l],i[3*l+1],i[3*l+2]),a.sub(o),h.sub(o);const c=new k;c.crossVectors(a,h),r+=.5*c.length(),this._triangleIndexToArea.push(r)}}constructor(t,e,i){this.type="mesh_surface",this._triangleIndexToArea=[],this._meshReferenceId=e,this.transform=i,t&&(this.mesh=t)}initialize(t){if(!this._positions||!this._indices)return t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed),void this.transform?.apply(t);const e=this._triangleIndexToArea.length-1;let i=0,s=e;const r=Math.random()*this._triangleIndexToArea[e];for(;i+1<s;){const t=Math.floor((i+s)/2);r<this._triangleIndexToArea[t]?s=t:i=t}let n=Math.random(),o=Math.random();n+o>1&&(n=1-n,o=1-o);const a=this._indices[3*i],h=this._indices[3*i+1],l=this._indices[3*i+2],c=this._positions[3*a],u=this._positions[3*a+1],d=this._positions[3*a+2],p=this._positions[3*h]-c,f=this._positions[3*h+1]-u,m=this._positions[3*h+2]-d,y=this._positions[3*l]-c,v=this._positions[3*l+1]-u,x=this._positions[3*l+2]-d;t.position.set(c+p*n+y*o,u+f*n+v*o,d+m*n+x*o);const g=f*x-m*v,S=m*y-p*x,w=p*v-f*y,b=Math.sqrt(g*g+S*S+w*w)||1;t.velocity.set(g/b,S/b,w/b).multiplyScalar(t.startSpeed),this.transform?.apply(t)}toJSON(){return{type:"mesh_surface",mesh:this._mesh?this._mesh.uniqueId?.toString():this._meshReferenceId??"",...di.toShapeJSON(this.transform)}}static fromJSON(t){return new Ti(void 0,t?.mesh,di.fromJSON(t?.transform))}clone(){return new Ti(this._mesh,this._meshReferenceId,this.transform?.clone())}update(t,e){}}const Pi={id:"babylon.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["mesh",["mesh"]]],constructor:Ti,loadJSON:t=>Ti.fromJSON(t)}],behaviors:[]};const Vi={};let Oi=!1;function Ci(){Oi||(Vi.tile_pars_vertex="\n#ifdef UV_TILE\n attribute float uvTile;\n uniform vec2 tileCount;\n\n mat3 makeTileTransform(float tileIndex) {\n float col = mod(tileIndex, tileCount.x);\n float row = (tileCount.y - floor(tileIndex / tileCount.x) - 1.0);\n return mat3(\n 1.0 / tileCount.x, 0.0, 0.0,\n 0.0, 1.0 / tileCount.y, 0.0,\n col / tileCount.x, row / tileCount.y, 1.0\n );\n }\n#else\n mat3 makeTileTransform(float tileIndex) {\n return mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);\n }\n#endif\n\n#if defined(USE_UV)\n varying vec2 vUv;\n #ifdef TILE_BLEND\n varying vec2 vUvNext;\n varying float vUvBlend;\n #endif\n#endif\n",Vi.tile_vertex="\n#ifdef UV_TILE\n mat3 tileTransform = makeTileTransform(floor(uvTile));\n #ifdef TILE_BLEND\n mat3 nextTileTransform = makeTileTransform(ceil(uvTile));\n vUvBlend = fract(uvTile);\n #endif\n#else\n mat3 tileTransform = makeTileTransform(0.0);\n#endif\n\n#if defined(USE_UV)\n vUv = (tileTransform * vec3(uv, 1.0)).xy;\n #if defined(TILE_BLEND) && defined(UV_TILE)\n vUvNext = (nextTileTransform * vec3(uv, 1.0)).xy;\n #endif\n#endif\n",Vi.tile_pars_fragment="\n#if defined(USE_UV)\n varying vec2 vUv;\n #ifdef TILE_BLEND\n varying vec2 vUvNext;\n varying float vUvBlend;\n #endif\n#endif\n",Vi.tile_fragment="\n#ifdef USE_MAP\n vec4 texelColor = texture2D(map, vUv);\n #ifdef TILE_BLEND\n texelColor = mix(texelColor, texture2D(map, vUvNext), vUvBlend);\n #endif\n diffuseColor *= texelColor;\n#endif\n",Vi.soft_pars_vertex="\n#ifdef SOFT_PARTICLES\n varying vec4 projPosition;\n varying float linearDepth;\n#endif\n",Vi.soft_vertex="\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n",Vi.soft_pars_fragment="\n#ifdef SOFT_PARTICLES\n uniform sampler2D depthTexture;\n uniform vec4 projParams;\n uniform vec2 softParams;\n\n varying vec4 projPosition;\n varying float linearDepth;\n\n #define SOFT_NEAR_FADE softParams.x\n #define SOFT_INV_FADE_DISTANCE softParams.y\n\n #define zNear projParams.x\n #define zFar projParams.y\n\n float linearize_depth(float d) {\n return (zFar * zNear) / (zFar - d * (zFar - zNear));\n }\n#endif\n",Vi.soft_fragment="\n#ifdef SOFT_PARTICLES\n\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float viewDepth = linearize_depth(readDepth);\n float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));\n\n gl_FragColor *= softParticlesFade;\n#endif\n",Oi=!0)}var Ai="\nattribute vec3 position;\nattribute vec2 uv;\nattribute vec3 normal;\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 scaledPosition = position * size;\n vec3 rotatedPosition = applyQuaternion(scaledPosition, rotation);\n vec3 rotatedNormal = normalize(applyQuaternion(normal, rotation));\n vec3 localPos = rotatedPosition + offset;\n\n vec4 worldPos = world * vec4(localPos, 1.0);\n vec4 viewPos = view * worldPos;\n gl_Position = projection * viewPos;\n\n vWorldPos = worldPos.xyz;\n vNormal = normalize((world * vec4(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n#else\n vUV = uv;\n#endif\n\n vColor = color;\n}\n",Bi="\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n#ifdef SOFT_PARTICLES\nuniform sampler2D depthTexture;\nuniform vec2 softParams;\nuniform vec4 projParams;\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform float alphaTest;\n#endif\n\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n #ifdef TILE_BLEND\n vec4 texColor2 = texture2D(map, vUV2);\n texColor = mix(texColor, texColor2, vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_COLOR_AS_ALPHA\n baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < alphaTest) discard;\n#else\n if (baseColor.a < 0.01) discard;\n#endif\n\n gl_FragColor = baseColor;\n\n#ifdef SOFT_PARTICLES\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float zNear = projParams.x;\n float zFar = projParams.y;\n float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);\n gl_FragColor *= fade;\n#endif\n}\n",$i="\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifndef MESH_UNLIT\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform vec3 ambientColor;\n#endif\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n#if defined(USE_ENVMAP_ATLAS) || defined(MESH_RIM)\nuniform vec3 eyePosition;\n#endif\n\n#ifdef MESH_RIM\nuniform vec3 rimColor;\nuniform vec2 rimParams;\n#endif\n\n// One 3×2 atlas (px py pz / nx ny nz). Avoids samplerCube and multi-face\n// sampler bindings that raise GL_INVALID_OPERATION on iOS WebKit.\n#ifdef USE_ENVMAP_ATLAS\nuniform sampler2D envAtlas;\nuniform float reflectionLevel;\n\nvec3 sampleEnvAtlas(vec3 r) {\n vec3 a = abs(r);\n vec2 localUV;\n float cellX;\n float cellY;\n // Atlas layout: +X +Y +Z on row 0, -X -Y -Z on row 1.\n if (a.x >= a.y && a.x >= a.z) {\n cellX = 0.0;\n if (r.x >= 0.0) {\n cellY = 0.0;\n localUV = vec2(-r.z, -r.y) / a.x * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2(r.z, -r.y) / a.x * 0.5 + 0.5;\n }\n } else if (a.y >= a.z) {\n cellX = 1.0;\n if (r.y >= 0.0) {\n cellY = 0.0;\n localUV = vec2(r.x, r.z) / a.y * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2(r.x, -r.z) / a.y * 0.5 + 0.5;\n }\n } else {\n cellX = 2.0;\n if (r.z >= 0.0) {\n cellY = 0.0;\n localUV = vec2(r.x, -r.y) / a.z * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2(-r.x, -r.y) / a.z * 0.5 + 0.5;\n }\n }\n vec2 uv = (vec2(cellX, cellY) + clamp(localUV, 0.0, 1.0)) / vec2(3.0, 2.0);\n return texture2D(envAtlas, uv).rgb;\n}\n#endif\n\n#ifdef SOFT_PARTICLES\nuniform sampler2D depthTexture;\nuniform vec2 softParams;\nuniform vec4 projParams;\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform float alphaTest;\n#endif\n\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n #ifdef TILE_BLEND\n vec4 texColor2 = texture2D(map, vUV2);\n texColor = mix(texColor, texColor2, vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < alphaTest) discard;\n#else\n if (baseColor.a < 0.01) discard;\n#endif\n\n vec3 N = normalize(vNormal);\n#ifdef MESH_UNLIT\n vec3 color = baseColor.rgb;\n#else\n vec3 L = normalize(-lightDirection);\n float NdotL = max(dot(N, L), 0.0);\n vec3 litColor = ambientColor + lightColor * NdotL;\n\n vec3 color = baseColor.rgb * litColor;\n#endif\n\n#ifdef USE_ENVMAP_ATLAS\n vec3 viewDir = normalize(vWorldPos - eyePosition);\n vec3 reflectionCoords = reflect(viewDir, N);\n color += sampleEnvAtlas(reflectionCoords) * reflectionLevel;\n#endif\n\n#ifdef MESH_RIM\n // Fresnel: strongest where the surface turns away from the camera.\n vec3 V = normalize(eyePosition - vWorldPos);\n float rim = pow(1.0 - abs(dot(N, V)), rimParams.x) * rimParams.y;\n #ifdef MESH_RIM_MIX\n color = mix(color, rimColor, clamp(rim, 0.0, 1.0));\n #else\n color += rimColor * rim;\n #endif\n#endif\n\n gl_FragColor = vec4(color, baseColor.a);\n\n#ifdef SOFT_PARTICLES\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float zNear = projParams.x;\n float zFar = projParams.y;\n float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);\n gl_FragColor *= fade;\n#endif\n}\n",Fi="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute float rotation;\nattribute float uvTile;\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nuniform mat4 worldViewProjection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n#ifdef PIVOT\n// Quad offset in particle-size units: xy in the quad's plane, z toward the camera.\nuniform vec3 pivot;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvoid main() {\n float c = cos(rotation);\n float s = sin(rotation);\n\n // A negative size mirrors the quad, which is how flipped particles arrive.\n vec2 alignedPosition = position.xy * size.xy;\n#ifdef PIVOT\n // The pivot turns with the particle but is not mirrored with it.\n alignedPosition += pivot.xy * abs(size.xy);\n#endif\n vec2 rotatedPosition;\n rotatedPosition.x = c * alignedPosition.x - s * alignedPosition.y;\n rotatedPosition.y = s * alignedPosition.x + c * alignedPosition.y;\n\n#ifdef HORIZONTAL\n vec4 mvPosition = world * vec4(offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.z -= rotatedPosition.y;\n#ifdef PIVOT\n mvPosition.y += pivot.z * abs(size.x);\n#endif\n mvPosition = view * mvPosition;\n#elif defined(VERTICAL)\n vec4 mvPosition = world * vec4(offset, 1.0);\n mvPosition.y += rotatedPosition.y;\n mvPosition = view * mvPosition;\n mvPosition.x += rotatedPosition.x;\n#else\n vec4 mvPosition = view * world * vec4(offset, 1.0);\n mvPosition.xy += rotatedPosition;\n#endif\n#ifdef PIVOT\n#ifndef HORIZONTAL\n // Toward the camera along its view axis, whichever way the view space\n // faces: anything in front of the camera has the sign of the far side.\n mvPosition.z -= sign(mvPosition.z) * pivot.z * abs(size.x);\n#endif\n#endif\n\n gl_Position = projection * mvPosition;\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n",Ei="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute float rotation;\nattribute float uvTile;\nattribute vec4 velocity;\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nuniform float speedFactor;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n#ifdef PIVOT\n// Streak offset in particle-size units: x from head to tail, y across.\nuniform vec3 pivot;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvoid main() {\n float lengthFactor = velocity.w;\n // A flipped particle arrives with a negative size: the streak keeps its\n // extent and mirrors its texture instead (see quadUV below).\n float avgSize = (abs(size.x) + abs(size.y)) * 0.5;\n vec4 mvPosition = view * world * vec4(offset, 1.0);\n vec3 viewVelocity = mat3(view * world) * velocity.xyz;\n float vlength = length(viewVelocity);\n // Stretch direction is the velocity direction; only a genuinely motionless particle has none.\n // Deriving it via normalize keeps the stretch aligned even when the speed contribution is ~0\n // (e.g. speedFactor 0), instead of collapsing the whole burst onto a fixed screen axis.\n vec3 vdir = vlength > 0.000001 ? viewVelocity / vlength : vec3(0.0, 0.0, 1.0);\n vec3 side = normalize(cross(mvPosition.xyz, vdir));\n mvPosition.xyz += position.y * side * avgSize;\n // Equivalent to viewVelocity * (1.0 + lengthFactor / vlength) for moving particles, but the\n // size-based term (vdir * lengthFactor) survives when the velocity contribution vanishes.\n mvPosition.xyz -= (position.x + 0.5) * (viewVelocity + vdir * lengthFactor) * avgSize;\n#ifdef PIVOT\n // In particle-size units along the quad's own axes: x from head to tail, y across.\n mvPosition.xyz += (pivot.y * side - pivot.x * vdir) * avgSize;\n#endif\n gl_Position = projection * mvPosition;\n vec2 quadUV = vec2(size.x < 0.0 ? 1.0 - uv.x : uv.x, size.y < 0.0 ? 1.0 - uv.y : uv.y);\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = quadUV / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = quadUV / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n #else\n vUV = quadUV;\n #endif\n\n vColor = color;\n}\n",Ni="\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n baseColor *= texColor;\n#endif\n\n if (baseColor.a < 0.01) discard;\n\n gl_FragColor = baseColor;\n}\n",Ii="\nattribute vec3 position;\nattribute vec3 previous;\nattribute vec3 next;\nattribute float side;\nattribute float width;\nattribute vec2 uv;\nattribute vec4 color;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform float lineWidth;\nuniform vec2 resolution;\nuniform float sizeAttenuation;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n\nvec2 fix(vec4 i, float aspect) {\n vec2 res = i.xy / i.w;\n res.x *= aspect;\n return res;\n}\n\nvoid main() {\n float aspect = resolution.x / resolution.y;\n vec4 finalPosition = projection * view * vec4(position, 1.0);\n vec4 prevPos = projection * view * vec4(previous, 1.0);\n vec4 nextPos = projection * view * vec4(next, 1.0);\n\n vec2 currentP = fix(finalPosition, aspect);\n vec2 prevP = fix(prevPos, aspect);\n vec2 nextP = fix(nextPos, aspect);\n\n float w = lineWidth * width;\n vec2 dir;\n if (distance(nextP, currentP) < 0.0001) {\n dir = normalize(currentP - prevP);\n } else if (distance(prevP, currentP) < 0.0001) {\n dir = normalize(nextP - currentP);\n } else {\n vec2 dir1 = normalize(currentP - prevP);\n vec2 dir2 = normalize(nextP - currentP);\n dir = normalize(dir1 + dir2);\n }\n vec4 normal = vec4(-dir.y, dir.x, 0.0, 1.0);\n normal.xy *= 0.5 * w;\n normal *= projection;\n if (sizeAttenuation == 0.0) {\n normal.xy *= finalPosition.w;\n normal.xy /= (vec4(resolution, 0.0, 1.0) * projection).xy;\n }\n finalPosition.xy += normal.xy * side;\n gl_Position = finalPosition;\n vUV = uv;\n vColor = color;\n}\n",Li="\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n\n#ifdef USE_MAP\nvar mapSampler: sampler;\nvar map: texture_2d<f32>;\n#endif\n\n#ifdef SOFT_PARTICLES\nvar depthTextureSampler: sampler;\nvar depthTexture: texture_2d<f32>;\nuniform softParams: vec2f;\nuniform projParams: vec4f;\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform alphaTest: f32;\n#endif\n\n@fragment\nfn main(input: FragmentInputs) -> FragmentOutputs {\n var baseColor = fragmentInputs.vColor;\n\n#ifdef USE_MAP\n var texColor = textureSample(map, mapSampler, fragmentInputs.vUV);\n #ifdef TILE_BLEND\n let texColor2 = textureSample(map, mapSampler, fragmentInputs.vUV2);\n texColor = mix(texColor, texColor2, fragmentInputs.vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_COLOR_AS_ALPHA\n baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < uniforms.alphaTest) { discard; }\n#else\n if (baseColor.a < 0.01) { discard; }\n#endif\n\n#ifdef SOFT_PARTICLES\n var p2 = fragmentInputs.projPosition.xy / fragmentInputs.projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n let readDepth = textureSample(depthTexture, depthTextureSampler, p2).r;\n let zNear = uniforms.projParams.x;\n let zFar = uniforms.projParams.y;\n let viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n let fade = clamp(uniforms.softParams.y * ((viewDepth - uniforms.softParams.x) - fragmentInputs.linearDepth), 0.0, 1.0);\n baseColor *= fade;\n#endif\n\n fragmentOutputs.color = baseColor;\n}\n";function Ri(t){return t.isWebGPU?c.ShaderLanguage.WGSL:c.ShaderLanguage.GLSL}function Ui(t,e,i,s){if(s===c.ShaderLanguage.WGSL)return h.ShaderStore.ShadersStoreWGSL[t+"VertexShader"]=e.wgsl,void(h.ShaderStore.ShadersStoreWGSL[t+"FragmentShader"]=i.wgsl);l.Effect.ShadersStore[t+"VertexShader"]=e.glsl,l.Effect.ShadersStore[t+"FragmentShader"]=i.glsl}var Di;function qi(){return{direction:new n.Vector3(.4,-1,.6),color:new u.Color3(1,1,1),ambient:new u.Color3(.35,.35,.35)}}function Ji(t){if(!t||"object"!=typeof t)return;const e=Array.isArray(t.color)?t.color:[1,1,1],i=(t,e)=>"number"==typeof t&&Number.isFinite(t)?t:e;return{color:[i(e[0],1),i(e[1],1),i(e[2],1)],power:Math.max(.01,i(t.power,2)),strength:Math.max(0,i(t.strength,1)),mode:"mix"===t.mode?"mix":"add"}}function ki(t,e){return t===e||!(!t||!e)&&(t.mode===e.mode&&t.power===e.power&&t.strength===e.strength&&t.color[0]===e.color[0]&&t.color[1]===e.color[1]&&t.color[2]===e.color[2])}exports.RenderMode=void 0,(Di=exports.RenderMode||(exports.RenderMode={}))[Di.BillBoard=0]="BillBoard",Di[Di.StretchedBillBoard=1]="StretchedBillBoard",Di[Di.Mesh=2]="Mesh",Di[Di.Trail=3]="Trail",Di[Di.HorizontalBillBoard=4]="HorizontalBillBoard",Di[Di.VerticalBillBoard=5]="VerticalBillBoard";class Qi{constructor(t,e){this.visibleSystems=[],this.scene=e,this.maxParticles=1e3,this.systems=new Set,this.settings={instancingGeometry:t.instancingGeometry,instancingIndices:t.instancingIndices,instancingUVs:t.instancingUVs,instancingNormals:t.instancingNormals,renderMode:t.renderMode,renderOrder:t.renderOrder,uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softNearFade:t.softNearFade,softFarFade:t.softFarFade,materialBlendMode:t.materialBlendMode,materialTransparent:t.materialTransparent,materialDepthTest:t.materialDepthTest,materialDepthWrite:t.materialDepthWrite,materialAlphaTest:t.materialAlphaTest,texture:t.texture,reflectionTexture:t.reflectionTexture??null,reflectionLevel:t.reflectionLevel??1,reflectionFaces:t.reflectionFaces??null,reflectionAtlas:t.reflectionAtlas??null,pivot:t.pivot?.clone(),layerMask:t.layerMask,lighting:t.lighting,rim:Ji(t.rim)},this.mesh=new o.Mesh("vfxBatch",e),this.mesh.alwaysSelectAsActiveMesh=!0}addSystem(t){this.systems.add(t)}removeSystem(t){this.systems.delete(t)}getVisibleSystems(){const t=this.visibleSystems;let e=0;for(const i of this.systems)i.emitter.visible&&(t[e++]=i);return t.length=e,t}applyDepthTexture(t){const e=this.mesh.material;e&&e instanceof s.ShaderMaterial&&e.setTexture("depthTexture",t)}applyMeshLighting(t){}dispose(){this.mesh.dispose()}}class Wi extends Qi{static whiteTexture(t){let e=Wi.whiteTextureByScene.get(t);return e||(e=r.RawTexture.CreateRGBATexture(new Uint8Array([255,255,255,255]),1,1,t),e.name="quarksMeshWhite",Wi.whiteTextureByScene.set(t,e)),e}constructor(t,e){super(t,e),this.shaderMaterial=null,this.fixedLightDirection=new n.Vector3,this.fixedLightColor=new n.Vector3,this.fixedAmbientColor=new n.Vector3,this.vector_=new k,this.vector2_=new k,this.vector3_=new k,this.quaternion_=new J,this.quaternion2_=new J,this.quaternion3_=new J,this.quaternion4_=new J,this.quaternion5_=new J,this.rotationMat_=new ot,this.rotationMat2_=new ot,this.lastStretchedSpeedFactor=Number.NaN,this.clearedInstanceUploaded=!1,this.storeFixedLighting(qi()),this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new o.Mesh("spriteBatch",this.scene),this.mesh.alwaysSelectAsActiveMesh=!0;const t=new a.VertexData;t.positions=this.settings.instancingGeometry,t.indices=this.settings.instancingIndices;const e=this.settings.instancingGeometry.length/3,i=this.settings.instancingUVs;i&&i.length>=2*e?t.uvs=i:t.uvs=new Float32Array(2*e),this.settings.instancingNormals&&(t.normals=this.settings.instancingNormals),t.applyToMesh(this.mesh,!1),this.buildExpandableBuffers()}disposeExpandableBuffers(){this.offsetVB?.dispose(),this.colorVB?.dispose(),this.sizeVB?.dispose(),this.uvTileVB?.dispose(),this.rotationVB?.dispose(),this.velocityVB?.dispose(),this.velocityVB=void 0,this.velocityBuffer=void 0}buildExpandableBuffers(){const e=this.scene.getEngine();this.offsetBuffer=new Float32Array(3*this.maxParticles),this.offsetVB=new t.VertexBuffer(e,this.offsetBuffer,"offset",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.offsetVB),this.colorBuffer=new Float32Array(4*this.maxParticles),this.colorVB=new t.VertexBuffer(e,this.colorBuffer,"color",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.colorVB),this.sizeBuffer=new Float32Array(3*this.maxParticles),this.sizeVB=new t.VertexBuffer(e,this.sizeBuffer,"size",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.sizeVB),this.uvTileBuffer=new Float32Array(this.maxParticles),this.uvTileVB=new t.VertexBuffer(e,this.uvTileBuffer,"uvTile",!0,!1,1,!0),this.mesh.setVerticesBuffer(this.uvTileVB),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer=new Float32Array(4*this.maxParticles),this.rotationVB=new t.VertexBuffer(e,this.rotationBuffer,"rotation",!0,!1,4,!0)):(this.rotationBuffer=new Float32Array(this.maxParticles),this.rotationVB=new t.VertexBuffer(e,this.rotationBuffer,"rotation",!0,!1,1,!0)),this.mesh.setVerticesBuffer(this.rotationVB),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&(this.velocityBuffer=new Float32Array(4*this.maxParticles),this.velocityVB=new t.VertexBuffer(e,this.velocityBuffer,"velocity",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.velocityVB)),this.mesh.forcedInstanceCount=0,this.mesh.doNotSyncBoundingInfo=!0}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.disposeExpandableBuffers(),this.buildExpandableBuffers()}rebuildMaterial(){const t=`quarksParticle_${this.settings.renderMode}`;this.lastStretchedSpeedFactor=Number.NaN;const e=[];let r,o;this.settings.renderMode===exports.RenderMode.Mesh?(r={glsl:Ai,wgsl:"\nattribute position: vec3f;\nattribute uv: vec2f;\nattribute normal: vec3f;\nattribute offset: vec3f;\nattribute color: vec4f;\nattribute size: vec3f;\nattribute rotation: vec4f;\nattribute uvTile: f32;\n\nuniform world: mat4x4f;\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\n\n#ifdef UV_TILE\nuniform tileCountX: f32;\nuniform tileCountY: f32;\n#endif\n\nvarying vUV: vec2f;\nvarying vColor: vec4f;\nvarying vNormal: vec3f;\nvarying vWorldPos: vec3f;\n\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n\n#ifdef SOFT_PARTICLES\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\nfn applyQuaternion(v: vec3f, q: vec4f) -> vec3f {\n let qVec = q.xyz;\n let qW = q.w;\n let t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let scaledPosition = vertexInputs.position * vertexInputs.size;\n let rotatedPosition = applyQuaternion(scaledPosition, vertexInputs.rotation);\n let rotatedNormal = normalize(applyQuaternion(vertexInputs.normal, vertexInputs.rotation));\n let localPos = rotatedPosition + vertexInputs.offset;\n\n let worldPos = uniforms.world * vec4f(localPos, 1.0);\n let viewPos = uniforms.view * worldPos;\n let clipPosition = uniforms.projection * viewPos;\n vertexOutputs.position = clipPosition;\n\n vertexOutputs.vWorldPos = worldPos.xyz;\n vertexOutputs.vNormal = normalize((uniforms.world * vec4f(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n vertexOutputs.projPosition = clipPosition;\n vertexOutputs.linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n let tc = vec2f(uniforms.tileCountX, uniforms.tileCountY);\n let baseTile = floor(vertexInputs.uvTile);\n let tileU = (baseTile % tc.x) / tc.x;\n let tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV = vertexInputs.uv / tc + vec2f(tileU, tileV);\n #ifdef TILE_BLEND\n let nextTile = ceil(vertexInputs.uvTile);\n let nextU = (nextTile % tc.x) / tc.x;\n let nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV2 = vertexInputs.uv / tc + vec2f(nextU, nextV);\n vertexOutputs.vTileBlend = fract(vertexInputs.uvTile);\n #endif\n#else\n vertexOutputs.vUV = vertexInputs.uv;\n#endif\n\n vertexOutputs.vColor = vertexInputs.color;\n}\n"},o={glsl:$i,wgsl:"\nvarying vUV: vec2f;\nvarying vColor: vec4f;\nvarying vNormal: vec3f;\nvarying vWorldPos: vec3f;\n\n#ifndef MESH_UNLIT\nuniform lightDirection: vec3f;\nuniform lightColor: vec3f;\nuniform ambientColor: vec3f;\n#endif\n\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n\n#ifdef USE_MAP\nvar mapSampler: sampler;\nvar map: texture_2d<f32>;\n#endif\n\n#if defined(USE_ENVMAP_ATLAS) || defined(MESH_RIM)\nuniform eyePosition: vec3f;\n#endif\n\n#ifdef MESH_RIM\nuniform rimColor: vec3f;\nuniform rimParams: vec2f;\n#endif\n\n#ifdef USE_ENVMAP_ATLAS\nvar envAtlasSampler: sampler;\nvar envAtlas: texture_2d<f32>;\nuniform reflectionLevel: f32;\n\nfn sampleEnvAtlas(r: vec3f) -> vec3f {\n let a = abs(r);\n var localUV: vec2f;\n var cellX: f32;\n var cellY: f32;\n if (a.x >= a.y && a.x >= a.z) {\n cellX = 0.0;\n if (r.x >= 0.0) {\n cellY = 0.0;\n localUV = vec2f(-r.z, -r.y) / a.x * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2f(r.z, -r.y) / a.x * 0.5 + 0.5;\n }\n } else if (a.y >= a.z) {\n cellX = 1.0;\n if (r.y >= 0.0) {\n cellY = 0.0;\n localUV = vec2f(r.x, r.z) / a.y * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2f(r.x, -r.z) / a.y * 0.5 + 0.5;\n }\n } else {\n cellX = 2.0;\n if (r.z >= 0.0) {\n cellY = 0.0;\n localUV = vec2f(r.x, -r.y) / a.z * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2f(-r.x, -r.y) / a.z * 0.5 + 0.5;\n }\n }\n let uv = (vec2f(cellX, cellY) + clamp(localUV, vec2f(0.0), vec2f(1.0))) / vec2f(3.0, 2.0);\n return textureSample(envAtlas, envAtlasSampler, uv).rgb;\n}\n#endif\n\n#ifdef SOFT_PARTICLES\nvar depthTextureSampler: sampler;\nvar depthTexture: texture_2d<f32>;\nuniform softParams: vec2f;\nuniform projParams: vec4f;\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform alphaTest: f32;\n#endif\n\n@fragment\nfn main(input: FragmentInputs) -> FragmentOutputs {\n var baseColor = fragmentInputs.vColor;\n\n#ifdef USE_MAP\n var texColor = textureSample(map, mapSampler, fragmentInputs.vUV);\n #ifdef TILE_BLEND\n let texColor2 = textureSample(map, mapSampler, fragmentInputs.vUV2);\n texColor = mix(texColor, texColor2, fragmentInputs.vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < uniforms.alphaTest) { discard; }\n#else\n if (baseColor.a < 0.01) { discard; }\n#endif\n\n let N = normalize(fragmentInputs.vNormal);\n#ifdef MESH_UNLIT\n var color = baseColor.rgb;\n#else\n let L = normalize(-uniforms.lightDirection);\n let NdotL = max(dot(N, L), 0.0);\n let litColor = uniforms.ambientColor + uniforms.lightColor * NdotL;\n\n var color = baseColor.rgb * litColor;\n#endif\n\n#ifdef USE_ENVMAP_ATLAS\n let viewDir = normalize(fragmentInputs.vWorldPos - uniforms.eyePosition);\n let reflectionCoords = reflect(viewDir, N);\n color += sampleEnvAtlas(reflectionCoords) * uniforms.reflectionLevel;\n#endif\n\n#ifdef MESH_RIM\n // Fresnel: strongest where the surface turns away from the camera.\n let V = normalize(uniforms.eyePosition - fragmentInputs.vWorldPos);\n let rimTerm = pow(1.0 - abs(dot(N, V)), uniforms.rimParams.x) * uniforms.rimParams.y;\n #ifdef MESH_RIM_MIX\n color = mix(color, uniforms.rimColor, clamp(rimTerm, 0.0, 1.0));\n #else\n color += uniforms.rimColor * rimTerm;\n #endif\n#endif\n\n var finalColor = vec4f(color, baseColor.a);\n\n#ifdef SOFT_PARTICLES\n var p2 = fragmentInputs.projPosition.xy / fragmentInputs.projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n let readDepth = textureSample(depthTexture, depthTextureSampler, p2).r;\n let zNear = uniforms.projParams.x;\n let zFar = uniforms.projParams.y;\n let viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n let fade = clamp(uniforms.softParams.y * ((viewDepth - uniforms.softParams.x) - fragmentInputs.linearDepth), 0.0, 1.0);\n finalColor *= fade;\n#endif\n\n fragmentOutputs.color = finalColor;\n}\n"}):this.settings.renderMode===exports.RenderMode.StretchedBillBoard?(r={glsl:Ei,wgsl:"\n// Per-vertex attributes\nattribute position: vec3f;\nattribute uv: vec2f;\n\n// Per-instance attributes\nattribute offset: vec3f;\nattribute color: vec4f;\nattribute size: vec3f;\nattribute rotation: f32;\nattribute uvTile: f32;\nattribute velocity: vec4f;\n\n// Uniforms\nuniform world: mat4x4f;\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\nuniform speedFactor: f32;\n\n#ifdef UV_TILE\nuniform tileCountX: f32;\nuniform tileCountY: f32;\n#endif\n\n#ifdef PIVOT\n// Streak offset in particle-size units: x from head to tail, y across.\nuniform pivot: vec3f;\n#endif\n\n// Varyings\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n#ifdef SOFT_PARTICLES\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let lengthFactor = vertexInputs.velocity.w;\n // A flipped particle arrives with a negative size: the streak keeps its\n // extent and mirrors its texture instead (see quadUV below).\n let avgSize = (abs(vertexInputs.size.x) + abs(vertexInputs.size.y)) * 0.5;\n var mvPosition = uniforms.view * uniforms.world * vec4f(vertexInputs.offset, 1.0);\n let viewWorld = uniforms.view * uniforms.world;\n let viewWorld3 = mat3x3f(viewWorld[0].xyz, viewWorld[1].xyz, viewWorld[2].xyz);\n let viewVelocity = viewWorld3 * vertexInputs.velocity.xyz;\n let vlength = length(viewVelocity);\n // Stretch direction is the velocity direction; only a genuinely motionless particle has none.\n // Deriving it via normalize keeps the stretch aligned even when the speed contribution is ~0\n // (e.g. speedFactor 0), instead of collapsing the whole burst onto a fixed screen axis.\n var vdir = vec3f(0.0, 0.0, 1.0);\n if (vlength > 0.000001) {\n vdir = viewVelocity / vlength;\n }\n let side = normalize(cross(mvPosition.xyz, vdir));\n let widthOffset = vertexInputs.position.y * side * avgSize;\n // Equivalent to viewVelocity * (1.0 + lengthFactor / vlength) for moving particles, but the\n // size-based term (vdir * lengthFactor) survives when the velocity contribution vanishes.\n let lengthOffset = (vertexInputs.position.x + 0.5) * (viewVelocity + vdir * lengthFactor) * avgSize;\n var stretched = mvPosition.xyz + widthOffset - lengthOffset;\n#ifdef PIVOT\n // In particle-size units along the quad's own axes: x from head to tail, y across.\n stretched += (uniforms.pivot.y * side - uniforms.pivot.x * vdir) * avgSize;\n#endif\n mvPosition.x = stretched.x;\n mvPosition.y = stretched.y;\n mvPosition.z = stretched.z;\n\n let clipPosition = uniforms.projection * mvPosition;\n vertexOutputs.position = clipPosition;\n let quadUV = select(vertexInputs.uv, 1.0 - vertexInputs.uv, vertexInputs.size.xy < vec2f(0.0));\n#ifdef SOFT_PARTICLES\n vertexOutputs.projPosition = clipPosition;\n vertexOutputs.linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n let tc = vec2f(uniforms.tileCountX, uniforms.tileCountY);\n let baseTile = floor(vertexInputs.uvTile);\n let tileU = (baseTile % tc.x) / tc.x;\n let tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV = quadUV / tc + vec2f(tileU, tileV);\n #ifdef TILE_BLEND\n let nextTile = ceil(vertexInputs.uvTile);\n let nextU = (nextTile % tc.x) / tc.x;\n let nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV2 = quadUV / tc + vec2f(nextU, nextV);\n vertexOutputs.vTileBlend = fract(vertexInputs.uvTile);\n #endif\n #else\n vertexOutputs.vUV = quadUV;\n #endif\n\n vertexOutputs.vColor = vertexInputs.color;\n}\n"},o={glsl:Bi,wgsl:Li}):(r={glsl:Fi,wgsl:"\n// Per-vertex attributes\nattribute position: vec3f;\nattribute uv: vec2f;\n\n// Per-instance attributes\nattribute offset: vec3f;\nattribute color: vec4f;\nattribute size: vec3f;\nattribute rotation: f32;\nattribute uvTile: f32;\n\n// Uniforms\nuniform world: mat4x4f;\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\n\n#ifdef UV_TILE\nuniform tileCountX: f32;\nuniform tileCountY: f32;\n#endif\n\n#ifdef PIVOT\n// Quad offset in particle-size units: xy in the quad's plane, z toward the camera.\nuniform pivot: vec3f;\n#endif\n\n// Varyings\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n#ifdef SOFT_PARTICLES\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let c = cos(vertexInputs.rotation);\n let s = sin(vertexInputs.rotation);\n\n // A negative size mirrors the quad, which is how flipped particles arrive.\n var alignedPosition = vertexInputs.position.xy * vertexInputs.size.xy;\n#ifdef PIVOT\n // The pivot turns with the particle but is not mirrored with it.\n alignedPosition += uniforms.pivot.xy * abs(vertexInputs.size.xy);\n#endif\n let rotatedPosition = vec2f(\n c * alignedPosition.x - s * alignedPosition.y,\n s * alignedPosition.x + c * alignedPosition.y);\n\n#ifdef HORIZONTAL\n var mvPosition = uniforms.world * vec4f(vertexInputs.offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.z -= rotatedPosition.y;\n#ifdef PIVOT\n mvPosition.y += uniforms.pivot.z * abs(vertexInputs.size.x);\n#endif\n mvPosition = uniforms.view * mvPosition;\n#elif defined(VERTICAL)\n var mvPosition = uniforms.world * vec4f(vertexInputs.offset, 1.0);\n mvPosition.y += rotatedPosition.y;\n mvPosition = uniforms.view * mvPosition;\n mvPosition.x += rotatedPosition.x;\n#else\n var mvPosition = uniforms.view * uniforms.world * vec4f(vertexInputs.offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.y += rotatedPosition.y;\n#endif\n#ifdef PIVOT\n#ifndef HORIZONTAL\n // Toward the camera along its view axis, whichever way the view space\n // faces: anything in front of the camera has the sign of the far side.\n mvPosition.z -= sign(mvPosition.z) * uniforms.pivot.z * abs(vertexInputs.size.x);\n#endif\n#endif\n\n let clipPosition = uniforms.projection * mvPosition;\n vertexOutputs.position = clipPosition;\n#ifdef SOFT_PARTICLES\n vertexOutputs.projPosition = clipPosition;\n vertexOutputs.linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n let tc = vec2f(uniforms.tileCountX, uniforms.tileCountY);\n let baseTile = floor(vertexInputs.uvTile);\n let tileU = (baseTile % tc.x) / tc.x;\n let tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV = vertexInputs.uv / tc + vec2f(tileU, tileV);\n #ifdef TILE_BLEND\n let nextTile = ceil(vertexInputs.uvTile);\n let nextU = (nextTile % tc.x) / tc.x;\n let nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV2 = vertexInputs.uv / tc + vec2f(nextU, nextV);\n vertexOutputs.vTileBlend = fract(vertexInputs.uvTile);\n #endif\n #else\n vertexOutputs.vUV = vertexInputs.uv;\n #endif\n\n vertexOutputs.vColor = vertexInputs.color;\n}\n"},o={glsl:Bi,wgsl:Li});const a=this.settings.texture??(this.settings.renderMode===exports.RenderMode.Mesh?Wi.whiteTexture(this.scene):null);a&&e.push("USE_MAP");const h=this.settings.reflectionAtlas;if(this.settings.renderMode===exports.RenderMode.Mesh&&!!h&&!h.isReady()&&h){const t=h.onLoadObservable;t?.addOnce(()=>{this.rebuildMaterial()})}const l=this.settings.renderMode===exports.RenderMode.Mesh&&!!h&&h.isReady();l&&e.push("USE_ENVMAP_ATLAS"),(this.settings.uTileCount>1||this.settings.vTileCount>1)&&e.push("UV_TILE"),this.settings.blendTiles&&e.push("TILE_BLEND"),this.settings.softParticles&&e.push("SOFT_PARTICLES"),this.settings.materialAlphaTest>0&&e.push("USE_ALPHATEST"),this.settings.renderMode===exports.RenderMode.VerticalBillBoard&&e.push("VERTICAL"),this.settings.renderMode===exports.RenderMode.HorizontalBillBoard&&e.push("HORIZONTAL");const c=Wi.takesPivotAndFlip(this.settings.renderMode)?this.settings.pivot:void 0;c&&e.push("PIVOT");const u=this.settings.renderMode===exports.RenderMode.Mesh,d=this.settings.lighting??"fixed",p=u&&"unlit"!==d;u&&!p&&e.push("MESH_UNLIT");const f=u?this.settings.rim:void 0;f&&(e.push("MESH_RIM"),"mix"===f.mode&&e.push("MESH_RIM_MIX"));const m=l||!!f,y=Ri(this.scene.getEngine());Ui(t,r,o,y);const v=["position","uv","offset","color","size","rotation","uvTile"];this.settings.renderMode===exports.RenderMode.Mesh&&v.push("normal"),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&v.push("velocity");const x=["world","view","projection","worldView","worldViewProjection"],g=[];(this.settings.uTileCount>1||this.settings.vTileCount>1)&&(x.push("tileCountX"),x.push("tileCountY")),a&&g.push("map"),l&&(g.push("envAtlas"),x.push("reflectionLevel")),m&&x.push("eyePosition"),f&&(x.push("rimColor"),x.push("rimParams")),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&x.push("speedFactor"),this.settings.softParticles&&(x.push("softParams"),x.push("projParams"),g.push("depthTexture")),this.settings.materialAlphaTest>0&&x.push("alphaTest"),c&&x.push("pivot"),p&&(x.push("lightDirection"),x.push("lightColor"),x.push("ambientColor"));const S=new s.ShaderMaterial(t,this.scene,{vertex:t,fragment:t},{attributes:v,uniforms:x,samplers:g,defines:e,needAlphaBlending:this.settings.materialTransparent,shaderLanguage:y});if(a&&S.setTexture("map",a),l&&h&&(S.setTexture("envAtlas",h),S.setFloat("reflectionLevel",this.settings.reflectionLevel)),f&&(S.setVector3("rimColor",new n.Vector3(f.color[0],f.color[1],f.color[2])),S.setVector2("rimParams",new n.Vector2(f.power,f.strength))),m){const t=new n.Vector3;S.setVector3("eyePosition",t),S.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.copyFrom(e.globalPosition),S.setVector3("eyePosition",t))})}if((this.settings.uTileCount>1||this.settings.vTileCount>1)&&(S.setFloat("tileCountX",this.settings.uTileCount),S.setFloat("tileCountY",this.settings.vTileCount)),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&S.setFloat("speedFactor",this.settings.softNearFade>0?this.settings.softNearFade:1),this.settings.softParticles){S.setVector2("softParams",new n.Vector2(this.settings.softNearFade,1/Math.max(this.settings.softFarFade-this.settings.softNearFade,1e-4)));const t=new n.Vector4(0,0,0,0);S.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.x=e.minZ,t.y=e.maxZ,S.setVector4("projParams",t))})}if(this.settings.materialAlphaTest>0&&S.setFloat("alphaTest",this.settings.materialAlphaTest),c&&S.setVector3("pivot",new n.Vector3(c.x,c.y,c.z)),p&&(this.writeFixedLighting(S),"scene"===d)){const t=new n.Vector3,e=new n.Vector3,i=new n.Vector3;S.onBindObservable.add(()=>{Wi.readSceneLight(this.scene,t,e,i)?(S.setVector3("lightDirection",t),S.setVector3("lightColor",e),S.setVector3("ambientColor",i)):this.writeFixedLighting(S)})}S.backFaceCulling=!1,this.settings.materialTransparent?S.alphaMode=this.settings.materialBlendMode:S.alphaMode=i.Constants.ALPHA_DISABLE,S.needDepthPrePass=this.settings.materialDepthWrite,S.forceDepthWrite=this.settings.materialDepthWrite,S.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=S,this.shaderMaterial=S}applyMeshLighting(t){this.storeFixedLighting(t);const e=this.shaderMaterial;null!==e&&this.settings.renderMode===exports.RenderMode.Mesh&&"unlit"!==this.settings.lighting&&this.writeFixedLighting(e)}storeFixedLighting(t){this.fixedLightDirection.copyFrom(t.direction),this.fixedLightColor.set(t.color.r,t.color.g,t.color.b),this.fixedAmbientColor.set(t.ambient.r,t.ambient.g,t.ambient.b)}writeFixedLighting(t){t.setVector3("lightDirection",this.fixedLightDirection),t.setVector3("lightColor",this.fixedLightColor),t.setVector3("ambientColor",this.fixedAmbientColor)}static readSceneLight(t,e,i,s){const r=t.lights;for(let n=0;n<r.length;n++){const o=r[n],a=o.getClassName();if("DirectionalLight"!==a&&"HemisphericLight"!==a||!o.isEnabled())continue;const h=o.intensity,l=o.diffuse,c=t.ambientColor;i.set(l.r*h,l.g*h,l.b*h),s.set(c.r,c.g,c.b);const u=o.direction;if("DirectionalLight"===a)e.copyFrom(u);else{e.copyFrom(u).scaleInPlace(-1);const t=o.groundColor;t&&(s.x+=t.r*h,s.y+=t.g*h,s.z+=t.b*h)}return!0}return!1}update(){let t=0,e=0;const i=this.settings.renderMode,s=i===exports.RenderMode.Mesh,r=i===exports.RenderMode.StretchedBillBoard,n=Wi.takesPivotAndFlip(i),o=this.getVisibleSystems();for(let t=0;t<o.length;t++)e+=o[t].particleNum;e>this.maxParticles&&this.expandBuffers(e);for(let e=0;e<o.length;e++){const i=o[e],a=i.particleNum;if(0===a)continue;const h=i.particles,l=this.quaternion2_,c=this.vector2_,u=this.vector3_,d=i.worldSpace,p=i.emitter.matrixWorld;if(s&&!d)p.decompose(c,l,u);else{const t=p.elements;u.set(Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]),Math.sqrt(t[4]*t[4]+t[5]*t[5]+t[6]*t[6]),Math.sqrt(t[8]*t[8]+t[9]*t[9]+t[10]*t[10]))}r&&!d&&this.rotationMat_.setFromMatrix4(p);const f=Math.abs(u.x),m=Math.abs(u.y),y=Math.abs(u.z),v=r?i.rendererEmitterSettings:void 0,x=void 0===v||0===v.speedFactor?.001:v.speedFactor,g=v?.lengthFactor??0,S=i.store,w=void 0!==S,b=void 0!==S&&!0!==i.onlyUsedByOther,M=i.simulationResidual??0,z=0===M?0:M/(i.simulationStep??M);w&&(0!==z&&a>0&&S.previousColor!==S.color?Wi.continueColor(this.colorBuffer,4*t,S,a,z):this.colorBuffer.set(S.color.subarray(0,4*a),4*t));let _=!1;if(void 0!==S&&d)0!==z&&a>0?Wi.extrapolate(this.offsetBuffer,3*t,S,a,z):this.offsetBuffer.set(S.position.subarray(0,3*a),3*t),0!==z&&a>0&&S.previousSize!==S.size?Wi.continueVector3(this.sizeBuffer,3*t,S.size,S.previousSize,a,z):this.sizeBuffer.set(S.size.subarray(0,3*a),3*t),_=!0;else if(b&&a>0){const e=3*t,i=e+3*a,s=this.offsetBuffer;0!==z?Wi.extrapolate(s,e,S,a,z):s.set(S.position.subarray(0,3*a),e);const r=p.elements,n=r[0],o=r[1],h=r[2],l=r[3],c=r[4],u=r[5],d=r[6],v=r[7],x=r[8],g=r[9],w=r[10],b=r[11],M=r[12],T=r[13],P=r[14],V=r[15];for(let t=e;t<i;t+=3){const e=s[t],i=s[t+1],r=s[t+2],a=1/(l*e+v*i+b*r+V);s[t]=(n*e+c*i+x*r+M)*a,s[t+1]=(o*e+u*i+g*r+T)*a,s[t+2]=(h*e+d*i+w*r+P)*a}const O=this.sizeBuffer;0!==z&&S.previousSize!==S.size?Wi.continueVector3(O,e,S.size,S.previousSize,a,z):O.set(S.size.subarray(0,3*a),e);for(let t=e;t<i;t+=3)O[t]*=f,O[t+1]*=m,O[t+2]*=y;_=!0}const T=t;if(b&&!s){const e=S;this.uvTileBuffer.set(e.uvTile.subarray(0,a),T);const i=this.rotationBuffer;if(i.set(e.rotation.subarray(0,a),T),0!==M){const t=e.angularVelocity;for(let e=0;e<a;e++)i[T+e]+=t[e]*M}r&&this.velocityBuffer&&Wi.writeVelocities(this.velocityBuffer,4*T,e,a,z,d?null:this.rotationMat_,x,g),t+=a}else if(b&&S.rotationQuaternion.length>0){const e=S;this.uvTileBuffer.set(e.uvTile.subarray(0,a),T),Wi.writeQuaternions(this.rotationBuffer,4*T,e,a,z,d?null:l),t+=a}else for(let e=0;e<a;e++,t++){const i=h[e];if(s){let e=i.rotation;const s=i.angularVelocity;let r;if(0!==z&&s instanceof J&&(e=this.quaternion4_.copy(e).multiply(Wi.partialTurn(s,z,this.quaternion5_))),d)r=e;else{let t;t=i.parentMatrix?this.quaternion3_.setFromRotationMatrix(i.parentMatrix):l,r=this.quaternion_,r.copy(t).multiply(e)}const n=4*t;this.rotationBuffer[n]=r.x,this.rotationBuffer[n+1]=r.y,this.rotationBuffer[n+2]=r.z,this.rotationBuffer[n+3]=r.w}else{const e=i.angularVelocity;this.rotationBuffer[t]=i.rotation+("number"==typeof e?e*M:0)}if(!_){const e=i.position,s=i.previousPosition;let r=e.x+(e.x-s.x)*z,n=e.y+(e.y-s.y)*z,o=e.z+(e.z-s.z)*z;if(!d){const t=(i.parentMatrix??p).elements,e=1/(t[3]*r+t[7]*n+t[11]*o+t[15]),s=(t[0]*r+t[4]*n+t[8]*o+t[12])*e,a=(t[1]*r+t[5]*n+t[9]*o+t[13])*e;o=(t[2]*r+t[6]*n+t[10]*o+t[14])*e,r=s,n=a}const a=3*t;this.offsetBuffer[a]=r,this.offsetBuffer[a+1]=n,this.offsetBuffer[a+2]=o;const h=i.size,l=3*t;d||i.parentMatrix?(this.sizeBuffer[l]=h.x,this.sizeBuffer[l+1]=h.y,this.sizeBuffer[l+2]=h.z):(this.sizeBuffer[l]=h.x*f,this.sizeBuffer[l+1]=h.y*m,this.sizeBuffer[l+2]=h.z*y)}if(!w){const e=i.color,s=4*t;this.colorBuffer[s]=e.x,this.colorBuffer[s+1]=e.y,this.colorBuffer[s+2]=e.z,this.colorBuffer[s+3]=e.w}if(this.uvTileBuffer[t]=i.uvTile,r&&this.velocityBuffer){const e=i.velocity,s=i.previousVelocity,r=e.x+(e.x-s.x)*z,n=e.y+(e.y-s.y)*z,o=e.z+(e.z-s.z)*z;let a=this.vector_;a.set(r,n,o),d||(i.parentMatrix?(this.rotationMat2_.setFromMatrix4(i.parentMatrix),a.applyMatrix3(this.rotationMat2_)):a.applyMatrix3(this.rotationMat_));const h=4*t;this.velocityBuffer[h]=a.x*x,this.velocityBuffer[h+1]=a.y*x,this.velocityBuffer[h+2]=a.z*x,this.velocityBuffer[h+3]=g}}n&&void 0!==i.flip&&(void 0!==S?Wi.applyFlip(this.sizeBuffer,3*T,S.flip,a):Wi.applyFlipFromParticles(this.sizeBuffer,3*T,h,a))}r&&o.length>0&&this.syncStretchedSpeedFactor(o[0]),this.mesh.forcedInstanceCount=t,0!==t?(this.clearedInstanceUploaded=!1,this.offsetVB.update(this.offsetBuffer.subarray(0,3*t)),this.sizeVB.update(this.sizeBuffer.subarray(0,3*t)),this.colorVB.update(this.colorBuffer.subarray(0,4*t)),this.uvTileVB.update(this.uvTileBuffer.subarray(0,t)),this.rotationVB.update(this.rotationBuffer.subarray(0,s?4*t:t)),r&&this.velocityVB&&this.velocityBuffer&&this.velocityVB.update(this.velocityBuffer.subarray(0,4*t))):this.clearedInstanceUploaded||(this.uploadClearedInstance(s,r),this.clearedInstanceUploaded=!0)}syncStretchedSpeedFactor(t){const e=this.shaderMaterial;if(null===e)return;const i=t.rendererEmitterSettings.speedFactor??1,s=0===i?.001:i;s!==this.lastStretchedSpeedFactor&&(e.setFloat("speedFactor",s),this.lastStretchedSpeedFactor=s)}static takesPivotAndFlip(t){return t===exports.RenderMode.BillBoard||t===exports.RenderMode.StretchedBillBoard||t===exports.RenderMode.VerticalBillBoard||t===exports.RenderMode.HorizontalBillBoard}static applyFlip(t,e,i,s){for(let r=0,n=e;r<s;r++,n+=3){const e=i[r];0!==e&&(1&e&&(t[n]=-t[n]),2&e&&(t[n+1]=-t[n+1]))}}static applyFlipFromParticles(t,e,i,s){for(let r=0,n=e;r<s;r++,n+=3){const e=i[r].flip;0!==e&&(1&e&&(t[n]=-t[n]),2&e&&(t[n+1]=-t[n+1]))}}static writeQuaternions(t,e,i,s,r,n){const o=i.rotationQuaternion,a=i.angularVelocityQuaternion,h=null!==n,l=h?n.x:0,c=h?n.y:0,u=h?n.z:0,d=h?n.w:1;for(let i=0,n=0,p=e;i<s;i++,n+=4,p+=4){let e=o[n],i=o[n+1],s=o[n+2],f=o[n+3];if(0!==r){const t=a[n]*r,o=a[n+1]*r,h=a[n+2]*r,l=1+(a[n+3]-1)*r,c=1/Math.sqrt(t*t+o*o+h*h+l*l),u=t*c,d=o*c,p=h*c,m=l*c,y=e*m+f*u+i*p-s*d,v=i*m+f*d+s*u-e*p,x=s*m+f*p+e*d-i*u;f=f*m-e*u-i*d-s*p,e=y,i=v,s=x}if(h){const t=l*f+d*e+c*s-u*i,r=c*f+d*i+u*e-l*s,n=u*f+d*s+l*i-c*e;f=d*f-l*e-c*i-u*s,e=t,i=r,s=n}t[p]=e,t[p+1]=i,t[p+2]=s,t[p+3]=f}}static writeVelocities(t,e,i,s,r,n,o,a){const h=i.velocity,l=i.previousVelocity.length>=3*s?i.previousVelocity:h,c=null!==n?n.elements:null;for(let i=0,n=0,u=e;i<s;i++,n+=3,u+=4){let e=h[n],i=h[n+1],s=h[n+2];if(0!==r&&(e+=(e-l[n])*r,i+=(i-l[n+1])*r,s+=(s-l[n+2])*r),null!==c){const t=c[0]*e+c[3]*i+c[6]*s,r=c[1]*e+c[4]*i+c[7]*s;s=c[2]*e+c[5]*i+c[8]*s,e=t,i=r}t[u]=e*o,t[u+1]=i*o,t[u+2]=s*o,t[u+3]=a}}static partialTurn(t,e,i){const s=t.x*e,r=t.y*e,n=t.z*e,o=1+(t.w-1)*e,a=1/Math.sqrt(s*s+r*r+n*n+o*o);return i.x=s*a,i.y=r*a,i.z=n*a,i.w=o*a,i}static continueVector3(t,e,i,s,r,n){for(let o=0,a=0;o<r;o++,a+=3){const r=i[a]+(i[a]-s[a])*n,o=i[a+1]+(i[a+1]-s[a+1])*n,h=i[a+2]+(i[a+2]-s[a+2])*n;t[e+a]=r>0?r:0,t[e+a+1]=o>0?o:0,t[e+a+2]=h>0?h:0}}static continueColor(t,e,i,s,r){const n=i.color,o=i.previousColor;for(let i=0,a=0;i<s;i++,a+=4){const i=n[a]+(n[a]-o[a])*r,s=n[a+1]+(n[a+1]-o[a+1])*r,h=n[a+2]+(n[a+2]-o[a+2])*r,l=n[a+3]+(n[a+3]-o[a+3])*r;t[e+a]=i>0?i:0,t[e+a+1]=s>0?s:0,t[e+a+2]=h>0?h:0,t[e+a+3]=l>0?l:0}}static extrapolate(t,e,i,s,r){const n=i.position,o=i.previousPosition;for(let i=0,a=0;i<s;i++,a+=3){const i=n[a],s=n[a+1],h=n[a+2];t[e+a]=i+(i-o[a])*r,t[e+a+1]=s+(s-o[a+1])*r,t[e+a+2]=h+(h-o[a+2])*r}}uploadClearedInstance(t,e){this.colorBuffer[3]=0,this.sizeBuffer[0]=0,this.sizeBuffer[1]=0,this.sizeBuffer[2]=0,this.colorVB.update(this.colorBuffer.subarray(0,4)),this.sizeVB.update(this.sizeBuffer.subarray(0,3)),this.offsetVB.update(this.offsetBuffer.subarray(0,3)),this.uvTileVB.update(this.uvTileBuffer.subarray(0,1)),t?this.rotationVB.update(this.rotationBuffer.subarray(0,4)):this.rotationVB.update(this.rotationBuffer.subarray(0,1)),e&&this.velocityVB&&this.velocityBuffer&&this.velocityVB.update(this.velocityBuffer.subarray(0,4))}dispose(){this.mesh.material&&this.mesh.material.dispose(),super.dispose()}}Wi.whiteTextureByScene=new WeakMap;class Gi extends Qi{constructor(t,e){super(t,e),this.drawsNothing=!1,this.vector_=new k,this.vector2_=new k,this.vector3_=new k,this.quaternion_=new J,this.maxParticles=1024,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new o.Mesh("trailBatch",this.scene),this.mesh.alwaysSelectAsActiveMesh=!0,this.buildGeometryBuffers()}buildGeometryBuffers(){this.positionBuffer=new Float32Array(6*this.maxParticles),this.previousBuffer=new Float32Array(6*this.maxParticles),this.nextBuffer=new Float32Array(6*this.maxParticles),this.uvBuffer=new Float32Array(4*this.maxParticles),this.sideBuffer=new Float32Array(2*this.maxParticles),this.widthBuffer=new Float32Array(2*this.maxParticles),this.colorBuffer=new Float32Array(8*this.maxParticles),this.indexBuffer=new Uint32Array(6*this.maxParticles);for(let t=0;t<this.sideBuffer.length;t+=2)this.sideBuffer[t]=1,this.sideBuffer[t+1]=-1;this.positionBuffer[0]=0,this.positionBuffer[1]=0,this.positionBuffer[2]=0,this.positionBuffer[3]=1,this.positionBuffer[4]=0,this.positionBuffer[5]=0,this.positionBuffer[6]=0,this.positionBuffer[7]=1,this.positionBuffer[8]=0,this.positionBuffer[9]=1,this.positionBuffer[10]=1,this.positionBuffer[11]=0,this.indexBuffer[0]=0,this.indexBuffer[1]=1,this.indexBuffer[2]=2,this.indexBuffer[3]=1,this.indexBuffer[4]=3,this.indexBuffer[5]=2,this.mesh.setVerticesData(t.VertexBuffer.PositionKind,this.positionBuffer,!0),this.mesh.setVerticesData(t.VertexBuffer.UVKind,this.uvBuffer,!0),this.mesh.setVerticesData(t.VertexBuffer.ColorKind,this.colorBuffer,!0,4),this.mesh.setIndices(this.indexBuffer,null,!0),this.drawsNothing=!1,this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.mesh.subMeshes[0].indexCount=6);const e=this.scene.getEngine();this.previousVB=new t.VertexBuffer(e,this.previousBuffer,"previous",!0,!1,3,!1),this.nextVB=new t.VertexBuffer(e,this.nextBuffer,"next",!0,!1,3,!1),this.sideVB=new t.VertexBuffer(e,this.sideBuffer,"side",!0,!1,1,!1),this.widthVB=new t.VertexBuffer(e,this.widthBuffer,"width",!0,!1,1,!1),this.mesh.setVerticesBuffer(this.previousVB),this.mesh.setVerticesBuffer(this.nextVB),this.mesh.setVerticesBuffer(this.sideVB),this.mesh.setVerticesBuffer(this.widthVB),this.mesh.doNotSyncBoundingInfo=!0;const i=new n.Vector3(-1e4,-1e4,-1e4),s=new n.Vector3(1e4,1e4,1e4);if(this.mesh.setBoundingInfo(new d.BoundingInfo(i,s)),this.mesh.subMeshes)for(const t of this.mesh.subMeshes)t._boundingInfo=this.mesh.getBoundingInfo()}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.previousVB?.dispose(),this.nextVB?.dispose(),this.sideVB?.dispose(),this.widthVB?.dispose(),this.buildGeometryBuffers()}rebuildMaterial(){const t="quarksTrail",e=[];this.settings.texture&&e.push("USE_MAP");const r=Ri(this.scene.getEngine());Ui(t,{glsl:Ii,wgsl:"\nattribute position: vec3f;\nattribute previous: vec3f;\nattribute next: vec3f;\nattribute side: f32;\nattribute width: f32;\nattribute uv: vec2f;\nattribute color: vec4f;\n\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\nuniform lineWidth: f32;\nuniform resolution: vec2f;\nuniform sizeAttenuation: f32;\n\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n\nfn fix(i: vec4f, aspect: f32) -> vec2f {\n var res = i.xy / i.w;\n res.x *= aspect;\n return res;\n}\n\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let aspect = uniforms.resolution.x / uniforms.resolution.y;\n var finalPosition = uniforms.projection * uniforms.view * vec4f(vertexInputs.position, 1.0);\n let prevPos = uniforms.projection * uniforms.view * vec4f(vertexInputs.previous, 1.0);\n let nextPos = uniforms.projection * uniforms.view * vec4f(vertexInputs.next, 1.0);\n\n let currentP = fix(finalPosition, aspect);\n let prevP = fix(prevPos, aspect);\n let nextP = fix(nextPos, aspect);\n\n let w = uniforms.lineWidth * vertexInputs.width;\n var dir: vec2f;\n if (distance(nextP, currentP) < 0.0001) {\n dir = normalize(currentP - prevP);\n } else if (distance(prevP, currentP) < 0.0001) {\n dir = normalize(nextP - currentP);\n } else {\n let dir1 = normalize(currentP - prevP);\n let dir2 = normalize(nextP - currentP);\n dir = normalize(dir1 + dir2);\n }\n var normal = vec4f(-dir.y, dir.x, 0.0, 1.0);\n normal.x *= 0.5 * w;\n normal.y *= 0.5 * w;\n normal = normal * uniforms.projection;\n if (uniforms.sizeAttenuation == 0.0) {\n let screen = (vec4f(uniforms.resolution, 0.0, 1.0) * uniforms.projection).xy;\n normal.x = normal.x * finalPosition.w / screen.x;\n normal.y = normal.y * finalPosition.w / screen.y;\n }\n finalPosition.x += normal.x * vertexInputs.side;\n finalPosition.y += normal.y * vertexInputs.side;\n\n vertexOutputs.position = finalPosition;\n vertexOutputs.vUV = vertexInputs.uv;\n vertexOutputs.vColor = vertexInputs.color;\n}\n"},{glsl:Ni,wgsl:"\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n\n#ifdef USE_MAP\nvar mapSampler: sampler;\nvar map: texture_2d<f32>;\n#endif\n\n@fragment\nfn main(input: FragmentInputs) -> FragmentOutputs {\n var baseColor = fragmentInputs.vColor;\n\n#ifdef USE_MAP\n let texColor = textureSample(map, mapSampler, fragmentInputs.vUV);\n baseColor *= texColor;\n#endif\n\n if (baseColor.a < 0.01) { discard; }\n\n fragmentOutputs.color = baseColor;\n}\n"},r);const o=[];this.settings.texture&&o.push("map");const a=new s.ShaderMaterial(t,this.scene,{vertex:t,fragment:t},{attributes:["position","previous","next","side","width","uv","color"],uniforms:["world","view","projection","worldViewProjection","lineWidth","resolution","sizeAttenuation"],samplers:o,defines:e,needAlphaBlending:this.settings.materialTransparent,shaderLanguage:r});this.settings.texture&&a.setTexture("map",this.settings.texture);const h=this.scene.getEngine();a.setFloat("lineWidth",1);const l=new n.Vector2(h.getRenderWidth(),h.getRenderHeight());a.setVector2("resolution",l),a.setFloat("sizeAttenuation",1),a.onBindObservable.add(()=>{const t=this.scene.getEngine(),e=t.getRenderWidth(),i=t.getRenderHeight();l.x===e&&l.y===i||(l.x=e,l.y=i,a.setVector2("resolution",l))}),a.backFaceCulling=!1,this.settings.materialTransparent?a.alphaMode=this.settings.materialBlendMode:a.alphaMode=i.Constants.ALPHA_DISABLE,a.needDepthPrePass=this.settings.materialDepthWrite,a.forceDepthWrite=this.settings.materialDepthWrite,a.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=a}static ensureWorldMatrix(t){const e=t.emitter;!e.computeWorldMatrix||e.isSynchronized&&e.isSynchronized()||e.computeWorldMatrix(!0)}update(){let t=0,e=0,i=0;const s=this.getVisibleSystems();for(let t=0;t<s.length;t++){const e=s[t],r=e.particles;for(let t=0;t<e.particleNum;t++){const e=r[t].historyCount;0!==e&&(i+=2*e+2)}}i>this.maxParticles&&this.expandBuffers(i);for(let i=0;i<s.length;i++){const r=s[i];Gi.ensureWorldMatrix(r);const n=this.quaternion_,o=this.vector2_,a=this.vector3_,h=r.emitter.matrixWorld;h.decompose(o,n,a);const l=r.particles,c=r.particleNum,u=this.settings.uTileCount,d=this.settings.vTileCount,p=1/u,f=1/d,m=r.worldSpace,y=(Math.abs(a.x)+Math.abs(a.y)+Math.abs(a.z))/3,v=r.rendererEmitterSettings,x=Boolean(v.uvFromHead),g=Boolean(v.colorFromParticle),S=m||Boolean(v.recordWorldSpace),w=v.followLocalOrigin?0:r.simulationResidual??0,b=0===w?0:w/(r.simulationStep??w);for(let i=0;i<c;i++){const s=l[i],r=s.historyCount;if(0===r)continue;const n=s.historyCapacity,o=s.historyPositions,a=s.historySizes,c=g?s.store.color:s.historyColors,u=4*s.storeIndex,v=s.uvTile%d,w=Math.floor(s.uvTile/d+.001),M=(s.parentMatrix??h).elements,z=M[0],_=M[1],T=M[2],P=M[3],V=M[4],O=M[5],C=M[6],A=M[7],B=M[8],$=M[9],F=M[10],E=M[11],N=M[12],I=M[13],L=M[14],R=M[15],U=1/(0!==b?r:Math.max(1,r-1));let D=s.getHistoryIndex(0),q=o[3*D],J=o[3*D+1],k=o[3*D+2];if(!S){const t=1/(P*q+A*J+E*k+R),e=(z*q+V*J+B*k+N)*t,i=(_*q+O*J+$*k+I)*t;k=(T*q+C*J+F*k+L)*t,q=e,J=i}let Q=q,W=J,G=k;for(let i=0;i<r;i++,t+=2){let h=q,l=J,b=k,M=D;if(i+1<r){M=D+1===n?0:D+1;const t=3*M;if(h=o[t],l=o[t+1],b=o[t+2],!S){const t=1/(P*h+A*l+E*b+R),e=(z*h+V*l+B*b+N)*t,i=(_*h+O*l+$*b+I)*t;b=(T*h+C*l+F*b+L)*t,h=e,l=i}}const j=a[D],Y=g?u:4*D,X=c[Y],Z=c[Y+1],H=c[Y+2],K=c[Y+3],tt=3*t;this.positionBuffer[tt]=q,this.positionBuffer[tt+1]=J,this.positionBuffer[tt+2]=k,this.positionBuffer[tt+3]=q,this.positionBuffer[tt+4]=J,this.positionBuffer[tt+5]=k,this.previousBuffer[tt]=Q,this.previousBuffer[tt+1]=W,this.previousBuffer[tt+2]=G,this.previousBuffer[tt+3]=Q,this.previousBuffer[tt+4]=W,this.previousBuffer[tt+5]=G,this.nextBuffer[tt]=h,this.nextBuffer[tt+1]=l,this.nextBuffer[tt+2]=b,this.nextBuffer[tt+3]=h,this.nextBuffer[tt+4]=l,this.nextBuffer[tt+5]=b,m||s.parentMatrix?(this.widthBuffer[t]=j,this.widthBuffer[t+1]=j):(this.widthBuffer[t]=j*y,this.widthBuffer[t+1]=j*y);const et=2*t,it=i*U,st=((x?1-it:it)+v)*p;this.uvBuffer[et]=st,this.uvBuffer[et+1]=(d-w-1)*f,this.uvBuffer[et+2]=st,this.uvBuffer[et+3]=(d-w)*f;const rt=4*t;this.colorBuffer[rt]=X,this.colorBuffer[rt+1]=Z,this.colorBuffer[rt+2]=H,this.colorBuffer[rt+3]=K,this.colorBuffer[rt+4]=X,this.colorBuffer[rt+5]=Z,this.colorBuffer[rt+6]=H,this.colorBuffer[rt+7]=K,i+1<r&&(this.indexBuffer[3*e]=t,this.indexBuffer[3*e+1]=t+1,this.indexBuffer[3*e+2]=t+2,e++,this.indexBuffer[3*e]=t+2,this.indexBuffer[3*e+1]=t+1,this.indexBuffer[3*e+2]=t+3,e++),Q=q,W=J,G=k,q=h,J=l,k=b,D=M}if(0!==b){const i=s.previousPosition,r=s.position;let n=r.x+(r.x-i.x)*b,o=r.y+(r.y-i.y)*b,a=r.z+(r.z-i.z)*b;const h=t-2,l=this.positionBuffer[3*h],c=this.positionBuffer[3*h+1],u=this.positionBuffer[3*h+2];if(!m){const t=1/(P*n+A*o+E*a+R),e=(z*n+V*o+B*a+N)*t,i=(_*n+O*o+$*a+I)*t;a=(T*n+C*o+F*a+L)*t,n=e,o=i}const g=3*t;this.positionBuffer[g]=n,this.positionBuffer[g+1]=o,this.positionBuffer[g+2]=a,this.positionBuffer[g+3]=n,this.positionBuffer[g+4]=o,this.positionBuffer[g+5]=a,this.previousBuffer[g]=l,this.previousBuffer[g+1]=c,this.previousBuffer[g+2]=u,this.previousBuffer[g+3]=l,this.previousBuffer[g+4]=c,this.previousBuffer[g+5]=u,this.nextBuffer[g]=n,this.nextBuffer[g+1]=o,this.nextBuffer[g+2]=a,this.nextBuffer[g+3]=n,this.nextBuffer[g+4]=o,this.nextBuffer[g+5]=a;const S=3*h;this.nextBuffer[S]=n,this.nextBuffer[S+1]=o,this.nextBuffer[S+2]=a,this.nextBuffer[S+3]=n,this.nextBuffer[S+4]=o,this.nextBuffer[S+5]=a;const M=s.size.x;m||s.parentMatrix?(this.widthBuffer[t]=M,this.widthBuffer[t+1]=M):(this.widthBuffer[t]=M*y,this.widthBuffer[t+1]=M*y);const U=2*t,D=((x?0:1)+v)*p;this.uvBuffer[U]=D,this.uvBuffer[U+1]=(d-w-1)*f,this.uvBuffer[U+2]=D,this.uvBuffer[U+3]=(d-w)*f;const q=s.color,J=4*t;this.colorBuffer[J]=q.x,this.colorBuffer[J+1]=q.y,this.colorBuffer[J+2]=q.z,this.colorBuffer[J+3]=q.w,this.colorBuffer[J+4]=q.x,this.colorBuffer[J+5]=q.y,this.colorBuffer[J+6]=q.z,this.colorBuffer[J+7]=q.w,this.indexBuffer[3*e]=h,this.indexBuffer[3*e+1]=h+1,this.indexBuffer[3*e+2]=t,e++,this.indexBuffer[3*e]=t,this.indexBuffer[3*e+1]=h+1,this.indexBuffer[3*e+2]=t+1,e++,t+=2}}}this.uploadGeometry(t,e)}uploadGeometry(e,i){const s=this.mesh.geometry,r=s?.getIndexBuffer();if(e>0&&i>0){this.mesh.updateVerticesData(t.VertexBuffer.PositionKind,this.positionBuffer.subarray(0,3*e)),this.mesh.updateVerticesData(t.VertexBuffer.UVKind,this.uvBuffer.subarray(0,2*e)),r&&this.scene.getEngine().updateDynamicIndexBuffer(r,this.indexBuffer.subarray(0,3*i),0),this.previousVB.update(this.previousBuffer.subarray(0,3*e)),this.nextVB.update(this.nextBuffer.subarray(0,3*e)),this.widthVB.update(this.widthBuffer.subarray(0,e));const s=this.mesh.getVertexBuffer(t.VertexBuffer.ColorKind);s&&s.update(this.colorBuffer.subarray(0,4*e)),this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.mesh.subMeshes[0].indexCount=3*i,this.mesh.subMeshes[0].verticesCount=e),this.drawsNothing=!1}else this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.drawsNothing||(this.indexBuffer.fill(0,0,6),r&&this.scene.getEngine().updateDynamicIndexBuffer(r,this.indexBuffer.subarray(0,6),0),this.drawsNothing=!0),this.mesh.subMeshes[0].indexCount=6,this.mesh.subMeshes[0].verticesCount=1)}adoptMeshBounds(){const t=this.mesh.getBoundingInfo();for(const e of this.mesh.subMeshes)e._boundingInfo=t}dispose(){this.mesh.material&&this.mesh.material.dispose(),super.dispose()}}class ji extends e.TransformNode{constructor(t,e){super(t,e),this.batches=[],this.systemToBatchIndex=new Map,this.depthTexture=null,this.systems=[],this.orderedSystems=[],this.orderedSystemsStale=!0,this.batchEmptyFrames=[],this.adaptivePerformanceState={enabled:!1,targetFrameMs:16.7,minQuality:.35,maxQuality:1,decreaseStep:.08,increaseStep:.02,currentQuality:1,lastFrameCpuMs:0},this.lastAppliedQuality=Number.NaN,this.meshLighting=qi()}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static equals(t,e){return t.materialBlendMode===e.materialBlendMode&&t.materialTransparent===e.materialTransparent&&t.materialDepthTest===e.materialDepthTest&&t.materialDepthWrite===e.materialDepthWrite&&t.materialAlphaTest===e.materialAlphaTest&&t.texture===e.texture&&t.reflectionTexture===e.reflectionTexture&&t.reflectionLevel===e.reflectionLevel&&function(t,e){if(t===e)return!0;if(!t||!e||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}(t.reflectionFaces,e.reflectionFaces)&&t.reflectionAtlas===e.reflectionAtlas&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layerMask===e.layerMask&&function(t,e){return(t?.x??0)===(e?.x??0)&&(t?.y??0)===(e?.y??0)&&(t?.z??0)===(e?.z??0)}(t.pivot,e.pivot)&&(t.lighting??"fixed")===(e.lighting??"fixed")&&ki(t.rim,e.rim)}addSystem(t){const e=t;e._renderer=this,this.systemToBatchIndex.has(t)||-1!==this.systems.indexOf(t)||(this.systems.push(t),this.orderedSystemsStale=!0),this.adaptivePerformanceState.enabled&&e.setQualityFactor(this.adaptivePerformanceState.currentQuality),this.assignToBatch(e)}assignToBatch(t){const e=t,i=t.getRendererSettings();for(let t=0;t<this.batches.length;t++)if(ji.equals(this.batches[t].settings,i))return this.batches[t].addSystem(e),void this.systemToBatchIndex.set(e,t);let s;const r=this.getScene();switch(i.renderMode){case exports.RenderMode.Trail:s=new Gi(i,r);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:s=new Wi(i,r);break;default:throw new Error(`Unsupported render mode: ${i.renderMode}`)}s.mesh.parent=this,this.depthTexture&&s.applyDepthTexture(this.depthTexture),s.applyMeshLighting(this.meshLighting),s.addSystem(e),this.batches.push(s),this.batchEmptyFrames.push(0),this.systemToBatchIndex.set(e,this.batches.length-1)}deleteSystem(t){const e=this.removeFromBatch(t),i=this.systems.indexOf(t);-1!==i&&(this.systems.splice(i,1),this.orderedSystemsStale=!0);const s=this.orderedSystems.indexOf(t);return-1!==s&&this.orderedSystems.splice(s,1),e}removeFromBatch(t){const e=this.systemToBatchIndex.get(t);return void 0!==e&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t),!0)}updateSystem(t){this.removeFromBatch(t),this.addSystem(t)}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}setMeshLighting(t){const e=this.meshLighting;t.direction&&(e.direction=t.direction.clone()),t.color&&(e.color=t.color.clone()),t.ambient&&(e.ambient=t.ambient.clone());for(const t of this.batches)t.applyMeshLighting(e)}getMeshLighting(){const t=this.meshLighting;return{direction:t.direction.clone(),color:t.color.clone(),ambient:t.ambient.clone()}}configureAdaptivePerformance(t={}){const e=this.adaptivePerformanceState,i=ji.clamp(t.minQuality??e.minQuality,.05,1),s=ji.clamp(t.maxQuality??e.maxQuality,i,1);e.targetFrameMs=Math.max(t.targetFrameMs??e.targetFrameMs,.1),e.minQuality=i,e.maxQuality=s,e.decreaseStep=Math.max(t.decreaseStep??e.decreaseStep,.001),e.increaseStep=Math.max(t.increaseStep??e.increaseStep,.001),e.currentQuality=ji.clamp(e.currentQuality,e.minQuality,e.maxQuality),e.enabled=!0,this.lastAppliedQuality=Number.NaN}disableAdaptivePerformance(t=!0){this.adaptivePerformanceState.enabled=!1,t&&(this.adaptivePerformanceState.currentQuality=this.adaptivePerformanceState.maxQuality,this.applyAdaptiveQuality())}getAdaptivePerformanceState(){return{...this.adaptivePerformanceState}}applyAdaptiveQuality(){const t=this.adaptivePerformanceState.currentQuality;if(t!==this.lastAppliedQuality){for(let e=0;e<this.systems.length;e++)this.systems[e].setQualityFactor(t);this.lastAppliedQuality=t}}_invalidateUpdateOrder(){this.orderedSystemsStale=!0}orderSystems(){if(!this.orderedSystemsStale)return this.orderedSystems;const t=[],e=new Set,i=new Set,s=new Set(this.systems),r=n=>{if(!i.has(n)&&!e.has(n)){e.add(n);for(const t of(t=>{const e=[];for(const i of t.behaviors??[]){if("EmitSubParticleSystem"!==i.type)continue;const t=i.subParticleSystem?.system;void 0!==t&&s.has(t)&&e.push(t)}return e})(n))r(t);e.delete(n),i.add(n),t.push(n)}};for(const t of this.systems)r(t);return t.reverse(),this.orderedSystems=t,this.orderedSystemsStale=!1,t}update(t){const e=this.adaptivePerformanceState,i=e.enabled?performance.now():0;e.enabled&&this.applyAdaptiveQuality();const s=this.orderSystems();for(let e=0;e<s.length;e++){const i=s[e];i.emitter.visible&&i.update(t),s[e]!==i&&e--}this.refreshBatches(),e.enabled&&(e.lastFrameCpuMs=performance.now()-i,e.lastFrameCpuMs>e.targetFrameMs?e.currentQuality=ji.clamp(e.currentQuality-e.decreaseStep,e.minQuality,e.maxQuality):e.currentQuality=ji.clamp(e.currentQuality+e.increaseStep,e.minQuality,e.maxQuality))}refreshBatches(){const t=this.batchEmptyFrames;for(let e=0;e<this.batches.length;e++){const i=this.batches[e];if(i.systems.size>0){t[e]=0,i.update();continue}const s=(t[e]??0)+1;t[e]=s,1===s?i.update():s>ji.EMPTY_BATCH_GRACE_FRAMES&&(this.removeBatch(e),e--)}}removeBatch(t){this.batches[t].dispose(),this.batches.splice(t,1),this.batchEmptyFrames.splice(t,1);for(const[e,i]of this.systemToBatchIndex)i>t&&this.systemToBatchIndex.set(e,i-1)}getBatchRenderStats(){return this.batches.map((t,e)=>{let i=0;const s=[];for(const e of t.systems){const t=e;i+=t.particleNum,s.push(t.emitter.name)}return{batchIndex:e,renderMode:t.settings.renderMode,instanceCount:t.mesh.forcedInstanceCount??0,particleCount:i,systemNames:s}})}dispose(){for(const t of this.batches)t.dispose();this.batches=[],this.batchEmptyFrames.length=0,this.systems.length=0,this.systemToBatchIndex.clear(),super.dispose()}}ji.EMPTY_BATCH_GRACE_FRAMES=120;const Yi=ji,Xi=new WeakMap,Zi=new WeakMap;function Hi(t){if(!t?.isCube)return null;const e=t.files??t._files;return 6===e?.length?e.slice():null}function Ki(t){return Xi.get(t)??null}async function ts(t,e){if("undefined"==typeof document||"undefined"==typeof Image)throw new Error("createEnvAtlasFromFaceUrls requires a DOM Image/canvas environment");const i=await Promise.all(t.map(t=>function(t){return new Promise((e,i)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>e(s),s.onerror=()=>i(new Error(`Failed to load env face ${t}`)),s.src=t})}(t))),s=i[0].width||i[0].naturalWidth;if(!s)throw new Error("Env atlas face image has zero size");const r=document.createElement("canvas");r.width=3*s,r.height=2*s;const n=r.getContext("2d");if(!n)throw new Error("Could not create env atlas canvas");for(let t=0;t<6;t++)n.drawImage(i[t],t%3*s,Math.floor(t/3)*s,s,s);const o=new p.Texture(r.toDataURL("image/jpeg",.92),e,{noMipmap:!0,invertY:!1,samplingMode:p.Texture.LINEAR_LINEAR});return o.name="quarksEnvAtlas",o}const es={createFromFaceUrls:ts};function is(t,e,i){const s=Xi.get(t);if(s)return i(s),s;const r=()=>{const s=Zi.get(t);if(s)return void s.then(t=>{t&&i(t)});const r=Hi(t);if(!r)return;const n=es.createFromFaceUrls(r,e).then(e=>(Xi.set(t,e),Zi.delete(t),i(e),e)).catch(e=>(Zi.delete(t),console.warn("[babylon.quarks] Failed to build env atlas from cubemap faces",e),null));Zi.set(t,n)};if(t.isReady())r();else{const e=t.onLoadObservable;e?e.addOnce(()=>r()):r()}return Xi.get(t)??null}class ss extends m.StandardMaterial{constructor(t,e,i={}){super(t,e),this.isParticleMeshStandardMaterial=!0,Object.assign(this,i)}}class rs extends f.PBRMaterial{constructor(t,e,i={}){super(t,e),this.isParticleMeshPhysicsMaterial=!0,Object.assign(this,i)}}class ns extends e.TransformNode{get matrixWorld(){const t=this.getWorldMatrix(),e=t.updateFlag;if(e===this._matrixWorldFlag)return this._matrixWorld;this._matrixWorldFlag=e;const i=this._matrixWorld.elements,s=t.m;return i[0]=s[0],i[1]=s[1],i[2]=s[2],i[3]=s[3],i[4]=s[4],i[5]=s[5],i[6]=s[6],i[7]=s[7],i[8]=s[8],i[9]=s[9],i[10]=s[10],i[11]=s[11],i[12]=s[12],i[13]=s[13],i[14]=s[14],i[15]=s[15],this._matrixWorld}get visible(){return this.isEnabled()}set visible(t){this.setEnabled(t)}get uuid(){return this.uniqueId.toString()}constructor(t,e){super("particleEmitter",e||void 0),this._matrixWorld=new Y,this._matrixWorldFlag=-1,this.system=t}dispose(){super.dispose()}extractFromCache(t){const e=[];for(const i in t){const s=t[i];s&&"object"==typeof s&&delete s.metadata,e.push(s)}return e}clone(t){const e=this.system.clone().emitter;return e.name=t??this.name,e.position.copyFrom(this.position),e.rotation.copyFrom(this.rotation),e.scaling.copyFrom(this.scaling),this.rotationQuaternion&&(e.rotationQuaternion=this.rotationQuaternion.clone()),e.setEnabled(this.isEnabled()),e}toJSON(t,e={}){return{uuid:this._quarksUUID??this.uniqueId.toString(),type:"ParticleEmitter",name:this.name,position:[this.position.x,this.position.y,this.position.z],rotation:[this.rotation.x,this.rotation.y,this.rotation.z],quaternion:this.rotationQuaternion?[this.rotationQuaternion.x,this.rotationQuaternion.y,this.rotationQuaternion.z,this.rotationQuaternion.w]:void 0,scale:[this.scaling.x,this.scaling.y,this.scaling.z],visible:this.isEnabled(),ps:this.system.toJSON(t,e)}}}function os(t,e){if(e&&e.length>0)return e;const i=t.length/3,s=new Uint32Array(i);for(let t=0;t<i;t++)s[t]=t;return s}const as=new k(0,0,1),hs=new J,ls=new J,cs=new k,us=new k,ds=1/60,ps=new Set(["SizeOverLife","SizeBySpeed"]),fs=new Set(["ColorOverLife","ColorBySpeed"]),ms=new Set(["ApplyForce","Noise","TurbulenceField","GravityForce","RotationOverLife","Rotation3DOverLife","RotationBySpeed","SpeedOverLife","FrameOverLife","ForceOverLife","VelocityOverLife","InheritVelocity","OrbitOverLife","WidthOverLength","ChangeEmitDirection","EmitSubParticleSystem","LimitSpeedOverLife","ApplyCollision"]),ys=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),vs=new Float32Array([0,0,1,0,1,1,0,1]);const xs=new Uint32Array([0,1,2,0,2,3]);function gs(t){const e={};return t?.uvFromHead&&(e.uvFromHead=!0),t?.colorFromParticle&&(e.colorFromParticle=!0),t?.dieWithParticle&&(e.dieWithParticle=!0),t?.recordWorldSpace&&(e.recordWorldSpace=!0),e}class Ss{set time(t){this.emissionState.time=t}get time(){return this.emissionState.time}get isEmitEnded(){return this.emitEnded}hasPendingEmission(){if(this.looping)return!0;if(this.emitEnded)return!1;if(this.onlyUsedByOther)return!1;const t=this.emissionState;if(t.waitEmiting>0)return!0;if(t.burstIndex<this.emissionBursts.length)return!0;if(this.hasPendingBurstWaves(t))return!0;if(t.time>=this.duration)return!1;const e=t.time/this.duration;return this.emissionOverTime.genValue(this.memory,e)>0||this.emissionOverDistance.genValue(this.memory,e)>0}isFinished(){return!this.looping&&(!(this.particleNum>0)&&(!!this.onlyUsedByOther||!this.hasPendingEmission()))}get layers(){return this.layerMaskProxy}get texture(){return this.rendererSettings.texture}set texture(t){this.rendererSettings.texture=t,this.neededToUpdateRender=!0}get material(){return this.materialRef}set material(t){this.materialRef=t,this.applyMaterialSettings(t)}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(t){this.rendererSettings.uTileCount=t,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(t){this.rendererSettings.vTileCount=t,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(t){this.rendererSettings.blendTiles=t,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(t){this.rendererSettings.softParticles=t,this.neededToUpdateRender=!0}get pivot(){return this.rendererSettings.pivot}set pivot(t){this.rendererSettings.pivot=Ss.nonZeroPivot(t),this.neededToUpdateRender=!0}get lighting(){return this.rendererSettings.lighting??"fixed"}set lighting(t){this.rendererSettings.lighting=Ss.validLighting(t),this.neededToUpdateRender=!0}get rim(){return this.rendererSettings.rim}set rim(t){this.rendererSettings.rim=Ji(t),this.neededToUpdateRender=!0}static validLighting(t){return"unlit"===t||"scene"===t?t:"fixed"}static nonZeroPivot(t){return!t||0===t.x&&0===t.y&&0===t.z?void 0:t.clone()}static nonZeroFlip(t){return t&&(t.x>0||t.y>0)?t.clone():void 0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(t){this.rendererSettings.softNearFade=t,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(t){this.rendererSettings.softFarFade=t,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(t){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=t,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.materialBlendMode}set blending(t){this.rendererSettings.materialBlendMode=t,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(t){if(this.rendererSettings.renderMode!==t){let e=!1;switch(this.rendererSettings.renderMode===exports.RenderMode.Trail&&(e=!0),this.rendererSettings.renderMode===exports.RenderMode.Mesh&&(this.startRotation=new bt(0)),t){case exports.RenderMode.Trail:this.rendererEmitterSettings={startLength:new bt(30),followLocalOrigin:!1},e=!0;break;case exports.RenderMode.Mesh:this.rendererEmitterSettings={},this.startRotation=new Vt(new k(0,1,0),new bt(0));break;case exports.RenderMode.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2};break;case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:this.rendererEmitterSettings={}}this.rendererSettings.renderMode=t,e&&(this.restart(),this.particles.length=0),this.neededToUpdateRender=!0}}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(t){this.rendererSettings.renderOrder=t,this.neededToUpdateRender=!0}constructor(t){if(this.store=new pe(64),this.emitterVelocity=new k,this.finishedEventFired=!1,this.startDelayTimeLeft=0,this.tempEmitterPos=new k,this.temp=new k,this.pathMatrix=new Y,this.normalMatrix=new ot,this.memory=[],this.listeners={},this.materialRef=null,this.qualityFactor=1,this.simulationAccumulator=0,this.destroyed=!1,this.fusionSteps=[],this.planChangesSize=!0,this.planChangesColor=!0,this.firstTimeUpdate=!0,this.sceneRef=t.scene,this.layerMaskProxy={mask:t.layerMask??268435455},Object.defineProperty(this.layerMaskProxy,"mask",{enumerable:!0,get:()=>this.rendererSettings.layerMask,set:t=>{this.rendererSettings.layerMask=t,this.neededToUpdateRender=!0}}),this.autoDestroy=t.autoDestroy??!1,this.duration=t.duration??1,this.startDelay=t.startDelay??new bt(0),this.looping=t.looping??!0,this.prewarm=t.prewarm??!1,this.startLife=t.startLife??new bt(5),this.startSpeed=t.startSpeed??new bt(0),this.startRotation=t.startRotation??new bt(0),this.startSize=t.startSize??new bt(1),this.startColor=t.startColor??new Ut(new mt(1,1,1,1)),this.emissionOverTime=t.emissionOverTime??new bt(10),this.emissionOverDistance=t.emissionOverDistance??new bt(0),this.emissionBursts=t.emissionBursts??[],this.maxParticles=t.maxParticles,this.onlyUsedByOther=t.onlyUsedByOther??!1,this.emitterShape=t.shape??new Si,this.behaviors=t.behaviors??[],this.worldSpace=t.worldSpace??!1,this.rendererEmitterSettings=t.rendererEmitterSettings??{},t.renderMode===exports.RenderMode.StretchedBillBoard){const e=this.rendererEmitterSettings;void 0!==t.speedFactor&&(e.speedFactor=t.speedFactor),e.speedFactor=e.speedFactor??0,e.lengthFactor=e.lengthFactor??0}var e;this.rendererSettings={instancingGeometry:t.instancingGeometry??ys,instancingIndices:t.instancingIndices??xs,instancingUVs:t.instancingUVs??(t.instancingGeometry?(e=t.instancingGeometry,new Float32Array(e.length/3*2)):vs),instancingNormals:t.instancingNormals,renderMode:t.renderMode??exports.RenderMode.BillBoard,renderOrder:t.renderOrder??0,uTileCount:t.uTileCount??1,vTileCount:t.vTileCount??1,blendTiles:t.blendTiles??!1,softParticles:t.softParticles??!1,softNearFade:t.softNearFade??0,softFarFade:t.softFarFade??0,materialBlendMode:t.blendMode??i.Constants.ALPHA_ADD,materialTransparent:t.transparent??!0,materialDepthTest:t.depthTest??!0,materialDepthWrite:t.depthWrite??!1,materialAlphaTest:t.alphaTest??0,texture:t.texture??null,reflectionTexture:null,reflectionLevel:1,reflectionFaces:null,reflectionAtlas:null,layerMask:t.layerMask??268435455,pivot:Ss.nonZeroPivot(t.pivot),lighting:Ss.validLighting(t.lighting),rim:Ji(t.rim)},this.flip=Ss.nonZeroFlip(t.flip),this.rendererSettings.renderMode!==exports.RenderMode.Mesh||this.rendererSettings.instancingNormals||(this.rendererSettings.instancingNormals=Ss.createFallbackNormals(this.rendererSettings.instancingGeometry)),this.materialRef=t.material??null,this.applyMaterialSettings(this.materialRef,{blendMode:t.blendMode,transparent:t.transparent,depthTest:t.depthTest,depthWrite:t.depthWrite,alphaTest:t.alphaTest,texture:t.texture,layerMask:t.layerMask}),this.neededToUpdateRender=!0,this.particles=[],this.startTileIndex=t.startTileIndex||new bt(0),this.emitter=new ns(this,t.scene),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.startDelay.startGen(this.memory),this.startDelayTimeLeft=this.startDelay.genValue(this.memory,0),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}applyMaterialSettings(t,e={}){if(!this.rendererSettings)return;const i=void 0!==e.texture?e.texture:t?.albedoTexture??t?.diffuseTexture??t?.emissiveTexture??t?.opacityTexture??t?.baseTexture??this.rendererSettings.texture??null,s=t?.reflectionTexture??t?.environmentTexture??this.rendererSettings.reflectionTexture??null,r="number"==typeof s?.level?s.level:1,n=e.blendMode??("number"==typeof t?.alphaMode?t.alphaMode:this.rendererSettings.materialBlendMode),o=e.transparent??("function"==typeof t?.needAlphaBlending?t.needAlphaBlending():"number"==typeof t?.alpha?t.alpha<1:this.rendererSettings.materialTransparent),a=e.depthTest??("boolean"==typeof t?.disableDepthTest?!t.disableDepthTest:this.rendererSettings.materialDepthTest),h=e.depthWrite??("boolean"==typeof t?.disableDepthWrite?!t.disableDepthWrite:"boolean"==typeof t?.forceDepthWrite?t.forceDepthWrite:this.rendererSettings.materialDepthWrite),l=e.alphaTest??(()=>{const e=t?.transparencyMode,i=1===e||3===e;return i&&"number"==typeof t?.alphaCutOff?t.alphaCutOff:i&&"number"==typeof t?.alphaCutOffValue?t.alphaCutOffValue:t?0:this.rendererSettings.materialAlphaTest})();this.rendererSettings.texture=i,this.rendererSettings.reflectionTexture=s,this.rendererSettings.reflectionLevel="number"==typeof t?.reflectionLevel?t.reflectionLevel:r;let c=t?.reflectionAtlas??e.reflectionAtlas??this.rendererSettings.reflectionAtlas??null;!c&&s?.isCube&&(c=Ki(s),!c&&this.sceneRef&&(is(s,this.sceneRef,e=>{this.rendererSettings.reflectionAtlas!==e&&(this.rendererSettings.reflectionAtlas=e,t&&null==t.reflectionAtlas&&(t.reflectionAtlas=e),this.neededToUpdateRender=!0)}),c=Ki(s))),this.rendererSettings.reflectionAtlas=c,this.rendererSettings.reflectionFaces=6===t?.reflectionFaces?.length?t.reflectionFaces:null,this.rendererSettings.materialBlendMode=n,this.rendererSettings.materialTransparent=o,this.rendererSettings.materialDepthTest=a,this.rendererSettings.materialDepthWrite=h,this.rendererSettings.materialAlphaTest=l,void 0!==e.layerMask&&(this.rendererSettings.layerMask=e.layerMask),this.neededToUpdateRender=!0}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}setQualityFactor(t){this.qualityFactor=Math.max(.1,Math.min(1,t))}rebindParticles(){const t=this.particles;for(let e=0;e<t.length;e++)t[e].rebind()}growParticlePool(t){const e=this.particles.length;this.store.ensureCapacity(e+1)&&this.rebindParticles(),this.particles.push(t?new Qe(this.store,e):new Je(this.store,e))}spawn(t,e,i){const s=cs,r=us;i.decompose(s,hs,r);const n=this.behaviors,o=n.length,a=this.rendererSettings.renderMode,h=a===exports.RenderMode.Trail,l=!h,c=a===exports.RenderMode.Mesh,u="rotation"===this.startRotation.type,d="vec3function"===this.startSize.type,p=e.time/this.duration,f=h?this.rendererEmitterSettings:void 0,m=Boolean(f?.followLocalOrigin);void 0!==this.maxParticles&&(t=Math.min(t,Math.max(0,this.maxParticles-this.particleNum)));for(let s=0;s<t;s++){e.burstParticleIndex=s,this.particleNum++,this.particles.length<this.particleNum&&this.growParticlePool(h);const t=this.particles[this.particleNum-1];if(t.reset(),t.speedModifier=1,this.finishedEventFired=!1,this.startColor.startGen(t.memory),this.startColor.genColor(t.memory,t.startColor,this.emissionState.time),t.color.copy(t.startColor),this.startSpeed.startGen(t.memory),t.startSpeed=this.startSpeed.genValue(t.memory,p),this.startLife.startGen(t.memory),t.life=this.startLife.genValue(t.memory,p),t.age=0,this.startSize.startGen(t.memory),d)this.startSize.genValue(t.memory,t.startSize,p);else{const e=this.startSize.genValue(t.memory,p);t.startSize.set(e,e,e)}if(this.startTileIndex.startGen(t.memory),t.uvTile=this.startTileIndex.genValue(t.memory),t.size.copy(t.startSize),l){const e=t;if(this.startRotation.startGen(t.memory),c)e.rotation instanceof J||(e.rotation=ls),e.angularVelocity instanceof J&&e.angularVelocity.set(0,0,0,1),u?this.startRotation.genValue(t.memory,e.rotation,1,p):e.rotation.setFromAxisAngle(as,this.startRotation.genValue(e.memory,p));else{e.rotation=u?0:this.startRotation.genValue(e.memory,p),e.angularVelocity=0;const t=this.flip;e.flip=void 0===t?0:(Math.random()<t.x?1:0)|(Math.random()<t.y?2:0)}}else if(f){const e=t;f.startLength.startGen(e.memory),e.length=f.startLength.genValue(e.memory,p),e.ensureHistoryCapacity(Math.max(1,Math.ceil(e.length))),e.resetHistory()}if(this.emitterShape.initialize(t,e),h&&m){const e=t;e.localPosition||(e.localPosition=new k),e.localPosition.copy(e.position)}this.worldSpace?(t.position.applyMatrix4(i),t.startSize.multiply(r).abs(),t.size.copy(t.startSize),t.velocity.multiply(r).applyMatrix3(this.normalMatrix),t.rotation&&t.rotation instanceof J&&t.rotation.multiplyQuaternions(hs,t.rotation)):this.onlyUsedByOther&&(t.parentMatrix=i);for(let e=0;e<o;e++)n[e].initialize(t,this);this.store.recordMemory(t.storeIndex,t.memory)}}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this.destroyed||(this.destroyed=!0,this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.fire({type:"destroy",particleSystem:this}))}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.burstWaves=void 0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(t=>t.reset()),this.emitEnded=!1,this.markForDestroy=!1,this.finishedEventFired=!1,this.prewarmed=!1,this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.startDelay.startGen(this.memory),this.startDelayTimeLeft=this.startDelay.genValue(this.memory,0),this.previousEmitterPos=void 0,this.emitterVelocity.set(0,0,0),this.simulationAccumulator=0,this.destroyed=!1}update(t){if(this.paused)return;if(this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.computeWorldMatrix(!0)),!this.looping&&this.finishedEventFired&&0===this.particleNum){t>.1&&(t=.1),this.simulationAccumulator+=t;const e=Math.min(8,Math.max(0,Math.round(this.simulationAccumulator/ds-1e-9)));return void(this.simulationAccumulator-=e*ds)}if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let t=0;t<60*this.duration;t++)this.update(1/60)}t>.1&&(t=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1);const e=this.emitter.matrixWorld.elements;if(this.tempEmitterPos.set(e[12],e[13],e[14]),void 0!==this.previousEmitterPos&&t>0&&this.emitterVelocity.copy(this.tempEmitterPos).sub(this.previousEmitterPos).divideScalar(t),(this.previousEmitterPos??(this.previousEmitterPos=new k)).copy(this.tempEmitterPos),this.startDelayTimeLeft>0&&(!this.prewarm||!this.looping)){if(this.startDelayTimeLeft-=t,this.startDelayTimeLeft>=0)return;t=Math.min(-this.startDelayTimeLeft,.1),this.startDelayTimeLeft=0}this.simulationAccumulator+=t;const i=Math.min(8,Math.max(0,Math.round(this.simulationAccumulator/ds-1e-9)));for(let t=0;t<i;t++)this.simulateStep(ds);this.simulationAccumulator-=i*ds}get simulationStep(){return ds}get simulationResidual(){return this.paused?0:this.simulationAccumulator>ds?ds:this.simulationAccumulator<-ds?-ds:this.simulationAccumulator}behaviorSteps(){const t=this.behaviors,e=this.fusionPlan;if(void 0!==e&&e.length===t.length){let i=!0;for(let s=0;s<t.length;s++)if(e[s]!==t[s]){i=!1;break}if(i)return this.fusionSteps}this.fusionPlan=t.slice(),this.fusionSteps=ai(t);let i=!1,s=!1;for(let e=0;e<t.length;e++){const r=t[e].type;ps.has(r)?i=!0:fs.has(r)?s=!0:ms.has(r)||(i=!0,s=!0)}return this.planChangesSize=i,this.planChangesColor=s,this.fusionSteps}simulateStep(t){this.onlyUsedByOther||this.emit(t,this.emissionState,this.emitter.matrixWorld);const e=this.particles,i=this.behaviors;i.length;const s=this.particleNum,r=this.rendererSettings.renderMode===exports.RenderMode.Trail,n=this.rendererSettings.renderMode===exports.RenderMode.StretchedBillBoard,o=this.store,a=3*s,h=this.behaviorSteps(),l=this.planChangesSize,c=this.planChangesColor;o.useSizeSnapshot(l),o.useColorSnapshot(c),o.previousPosition.set(o.position.subarray(0,a)),l&&o.previousSize.set(o.size.subarray(0,a)),n&&(o.keepPreviousVelocity()&&this.rebindParticles(),o.previousVelocity.set(o.velocity.subarray(0,a))),c&&o.previousColor.set(o.color.subarray(0,4*s)),this.emitterShape.update(this,t);for(let r=0;r<h.length;r++){const n=h[r],o=n.behaviors;for(let e=0;e<o.length;e++)o[e].frameUpdate(t);if(0===s)continue;if(void 0!==n.run){n.run(i,e,s,t,this.store);continue}const a=o[0];if(void 0===a.updateAll)for(let i=0;i<s;i++){const s=e[i];s.age<s.life&&a.update(s,t)}else a.updateAll(e,s,t)}const u=this.hasListeners("particleDied"),d=this.store,p=d.scalars,f=pe.SCALAR_STRIDE;let m=this.particleNum;if(!r){const i=d.position,s=d.velocity,r=d.previousSize,n=d.size,o=d.previousColor,a=d.color,h=l,y=c;for(let l=0;l<m;l++){const c=l*f;let v=p[c+pe.AGE];const x=3*l;if(0===v&&(h&&(r[x]=n[x],r[x+1]=n[x+1],r[x+2]=n[x+2]),y)){const t=4*l;o[t]=a[t],o[t+1]=a[t+1],o[t+2]=a[t+2],o[t+3]=a[t+3]}const g=t*p[c+pe.SPEED_MODIFIER];if(i[x]+=s[x]*g,i[x+1]+=s[x+1]*g,i[x+2]+=s[x+2]*g,v+=t,p[c+pe.AGE]=v,v>=p[c+pe.LIFE]){const t=m-1,i=e[l],s=e[t];e[l]=s,e[t]=i,l!==t&&(d.swapRows(l,t),s.setStoreIndex(l),i.setStoreIndex(t)),m--,l--,u&&this.fire({type:"particleDied",particleSystem:this,particle:i})}}return this.particleNum=m,void this.notifyFinished()}if(s>0){const t=o.previousSize,e=o.size,i=o.previousColor,r=o.color;for(let n=0,o=0,a=0,h=0;n<s;n++,o+=3,a+=4,h+=f)0===p[h+pe.AGE]&&(l&&(t[o]=e[o],t[o+1]=e[o+1],t[o+2]=e[o+2]),c&&(i[a]=r[a],i[a+1]=r[a+1],i[a+2]=r[a+2],i[a+3]=r[a+3]))}if(this.rendererEmitterSettings.followLocalOrigin){const i=this.emitter.matrixWorld;for(let r=0;r<s;r++){const s=e[r];s.localPosition?(s.position.copy(s.localPosition),s.position.applyMatrix4(s.parentMatrix??i)):s.position.addScaledVector(s.velocity,t*s.speedModifier),s.age+=t}}else{const e=d.position,i=d.velocity;for(let r=0,n=0,o=0;r<s;r++,n+=3,o+=f){const s=t*p[o+pe.SPEED_MODIFIER];e[n]+=i[n]*s,e[n+1]+=i[n+1]*s,e[n+2]+=i[n+2]*s,p[o+pe.AGE]+=t}}{const t=this.rendererEmitterSettings,i=t.dieWithParticle,r=t.recordWorldSpace&&!this.worldSpace,n=this.emitter.matrixWorld;for(let t=0;t<s;t++){const s=e[t];if(i&&s.age>=s.life)s.resetHistory();else if(s.update(),r&&s.age<=s.life){const t=(s.historyHead+s.historyCapacity-1)%s.historyCapacity*3,e=s.historyPositions;cs.set(e[t],e[t+1],e[t+2]),cs.applyMatrix4(s.parentMatrix??n),e[t]=cs.x,e[t+1]=cs.y,e[t+2]=cs.z}}}for(let t=0;t<m;t++){const i=e[t],s=t*f;if(p[s+pe.AGE]>=p[s+pe.LIFE]&&0===i.historyCount){const s=m-1,r=e[s];e[t]=r,e[s]=i,t!==s&&(d.swapRows(t,s),r.setStoreIndex(t),i.setStoreIndex(s)),m--,t--,u&&this.fire({type:"particleDied",particleSystem:this,particle:i})}}this.particleNum=m,this.notifyFinished()}notifyFinished(){this.isFinished()&&(this.finishedEventFired||(this.finishedEventFired=!0,this.fire({type:"finished",particleSystem:this})),this.autoDestroy&&(this.markForDestroy=!0,this.dispose()))}static burstWaveCount(t){return t.cycle>=1?Math.floor(t.cycle):1}static burstInterval(t){return t.interval>0?t.interval:0}emitBursts(t,e){const i=this.emissionBursts,s=i.length,r=t.time,n=t.burstWaves??(t.burstWaves=[]);for(;t.burstIndex<s&&i[t.burstIndex].time<=r;)n[t.burstIndex]=0,t.burstIndex++;const o=t.burstIndex;for(let s=0;s<o;s++){const o=i[s],a=Ss.burstWaveCount(o);let h=n[s]??0;if(h>=a)continue;const l=Ss.burstInterval(o);for(;h<a;){const i=o.time+h*l;if(h>0&&i>this.duration){h=a;break}if(i>r)break;t.burstWaveIndex=h,this.fireBurstWave(o,t,e),h++}n[s]=h}}fireBurstWave(t,e,i){if(Math.random()>=t.probability)return;const s=t.count.genValue(this.memory,this.time),r=this.qualityFactor,n=r>=.999?s:Math.floor(s*r);e.isBursting=!0,e.burstParticleCount=n,this.spawn(n,e,i),e.isBursting=!1}hasPendingBurstWaves(t){const e=t.burstWaves;if(void 0===e)return!1;const i=this.emissionBursts;for(let s=0;s<t.burstIndex&&s<i.length;s++){const t=i[s],r=e[s]??0;if(r<Ss.burstWaveCount(t)&&(0===r||t.time+r*Ss.burstInterval(t)<=this.duration))return!0}return!1}spawnAlongPath(t,e,i,s,r,n,o){const a=this.pathMatrix.copy(i),h=i.elements,l=a.elements,c=h[12],u=h[13],d=h[14];for(let i=1;i<=t;i++){const t=i*n-r,h=t<=0?0:t>=o?1:t/o;l[12]=s.x+(c-s.x)*h,l[13]=s.y+(u-s.y)*h,l[14]=s.z+(d-s.z)*h,this.spawn(1,e,a)}}emit(t,e,i){if(e.time>this.duration)if(this.looping){e.time-=this.duration,e.burstIndex=0,void 0!==e.burstWaves&&(e.burstWaves.length=0);for(let t=0;t<this.behaviors.length;t++)this.behaviors[t].reset()}else this.emitEnded||this.onlyUsedByOther||this.endEmit();this.worldSpace&&this.normalMatrix.getNormalMatrix(i);const s=this.emissionBursts.length,r=this.qualityFactor;s>0&&this.emitBursts(e,i);let n=0,o=0,a=0,h=0;const l=e.previousWorldPos;if(!this.emitEnded){const s=e.time/this.duration;if(e.waitEmiting+=t*this.emissionOverTime.genValue(this.memory,s)*r,void 0!==l){this.temp.set(i.elements[12],i.elements[13],i.elements[14]),h=l.distanceTo(this.temp),a=e.travelDistance,e.travelDistance+=h;const t=this.emissionOverDistance.genValue(this.memory,s)*r;if(e.travelDistance*t>0){const i=Math.floor(e.travelDistance*t);e.travelDistance-=i/t,this.worldSpace&&h>0?(n=i,o=1/t):e.waitEmiting+=i}}}const c=Math.floor(e.waitEmiting);c>0&&(this.spawn(c,e,i),e.waitEmiting-=c),n>0&&this.spawnAlongPath(n,e,i,l,a,o,h),void 0===e.previousWorldPos&&(e.previousWorldPos=new k),e.previousWorldPos.set(i.elements[12],i.elements[13],i.elements[14]),e.time+=t}toJSON(t,e={}){const i=void 0===t||"string"==typeof t?{geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}:t,s=this.ensureGeometryMeta(i),r=this.ensureMaterialMeta(i),n=this.toRendererSettingsJSON();return{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,startDelay:this.startDelay.toJSON(),shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(t=>({time:t.time,count:t.count.toJSON(),probability:t.probability,interval:t.interval,cycle:t.cycle})),...void 0!==this.maxParticles?{maxParticles:this.maxParticles}:{},onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:s,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:n,material:r,layers:this.rendererSettings.layerMask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.rendererSettings.uTileCount,vTileCount:this.rendererSettings.vTileCount,blendTiles:this.rendererSettings.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,blending:this.rendererSettings.materialBlendMode,transparent:this.rendererSettings.materialTransparent,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,behaviors:this.behaviors.map(t=>t.toJSON()),worldSpace:this.worldSpace,...this.pivot?{pivot:[this.pivot.x,this.pivot.y,this.pivot.z]}:{},...this.flip?{flip:[this.flip.x,this.flip.y]}:{}}}static fromJSON(t,e,s={},r){const n=Mi(t.shape,e);let o;if(t.renderMode===exports.RenderMode.Trail){const e=t.rendererEmitterSettings;o={startLength:void 0!==e?.startLength?Pt(e.startLength):new bt(30),followLocalOrigin:e?.followLocalOrigin??!1,...gs(e)}}else t.renderMode===exports.RenderMode.StretchedBillBoard?(o={...t.rendererEmitterSettings??{}},void 0!==t.speedFactor&&(o.speedFactor=t.speedFactor)):o={};const a=t.material?e.materials?.[t.material]:void 0,h=a?.texture??t.texture,l="string"==typeof h?e.textures?.[h]??null:h??null,c="string"==typeof t.instancingGeometry?e.geometries?.[t.instancingGeometry]:t.instancingGeometry,u=Ss.resolveGeometryData(c),d=new Ss({scene:r,autoDestroy:t.autoDestroy,looping:t.looping,prewarm:t.prewarm,duration:t.duration,startDelay:t.startDelay?Pt(t.startDelay):void 0,shape:n,startLife:Pt(t.startLife),startSpeed:Pt(t.startSpeed),startRotation:Gt(t.startRotation),startSize:Gt(t.startSize),startColor:Dt(t.startColor),emissionOverTime:Pt(t.emissionOverTime),emissionOverDistance:Pt(t.emissionOverDistance),emissionBursts:t.emissionBursts?.map(t=>({time:t.time,count:"number"==typeof t.count?new bt(t.count):Pt(t.count),probability:t.probability??1,interval:t.interval??.1,cycle:t.cycle??t.cycleCount??1})),maxParticles:"number"==typeof t.maxParticles?t.maxParticles:void 0,onlyUsedByOther:t.onlyUsedByOther,instancingGeometry:u.positions,instancingIndices:u.indices,instancingUVs:u.uvs,instancingNormals:u.normals,renderMode:t.renderMode,rendererEmitterSettings:o,renderOrder:t.renderOrder,texture:l,material:a?.sourceMaterial??a,blendMode:a?.alphaMode??t.blending??i.Constants.ALPHA_ADD,transparent:a?.transparent??t.transparent??!0,depthTest:a?.depthTest??t.depthTest??!0,depthWrite:a?.depthWrite??t.depthWrite??!1,alphaTest:a?.alphaTest??t.alphaTest??0,startTileIndex:"number"==typeof t.startTileIndex?new bt(t.startTileIndex):Pt(t.startTileIndex),uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softFarFade:t.softFarFade,softNearFade:t.softNearFade,behaviors:[],worldSpace:t.worldSpace,layerMask:t.layers,pivot:t.pivot?new k(t.pivot[0]??0,t.pivot[1]??0,t.pivot[2]??0):void 0,flip:t.flip?new ut(t.flip[0]??0,t.flip[1]??0):void 0,lighting:a?.lighting,rim:a?.rim});return d.behaviors=(t.behaviors??[]).map(t=>{const e=je(t,d);return e&&"EmitSubParticleSystem"===e.type&&(s[t.subParticleSystem]=e),e}).filter(t=>null!==t),d}static nextSerializationId(t){return Ss.serializationCounter+=1,`${t}_${Ss.serializationCounter}`}static createFallbackNormals(t){const e=new Float32Array(t.length);for(let t=0;t<e.length;t+=3)e[t]=0,e[t+1]=0,e[t+2]=1;return e}toRendererSettingsJSON(){return this.renderMode===exports.RenderMode.Trail?{startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin,...gs(this.rendererEmitterSettings)}:this.renderMode===exports.RenderMode.StretchedBillBoard?{speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:{}}ensureGeometryMeta(t){const e=Ss.nextSerializationId("quarks_geometry");return t.geometries[e]={uuid:e,type:"QuarksGeometry",positions:Array.from(this.rendererSettings.instancingGeometry),indices:Array.from(this.rendererSettings.instancingIndices),uvs:this.rendererSettings.instancingUVs?Array.from(this.rendererSettings.instancingUVs):void 0,normals:this.rendererSettings.instancingNormals?Array.from(this.rendererSettings.instancingNormals):void 0},e}ensureMaterialMeta(t){const e=this.rendererSettings.texture;let i;e&&(i=Ss.nextSerializationId("quarks_texture"),t.textures[i]=e);const s=this.rendererSettings.reflectionAtlas;let r;s instanceof p.Texture&&(r=Ss.nextSerializationId("quarks_texture"),t.textures[r]=s);const n=Ss.nextSerializationId("quarks_material");return t.materials[n]={uuid:n,type:"QuarksMaterial",transparent:this.rendererSettings.materialTransparent,alphaMode:this.rendererSettings.materialBlendMode,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,texture:i,reflectionAtlas:r,reflectionLevel:this.rendererSettings.reflectionLevel,..."fixed"!==this.lighting?{lighting:this.lighting}:{},...this.rim?{rim:{...this.rim,color:[...this.rim.color]}}:{},sourceMaterial:this.materialRef??void 0},n}static resolveGeometryData(t){if(t?.positions){const e=t.positions instanceof Float32Array?t.positions:new Float32Array(t.positions);return{positions:e,indices:os(e,t.indices instanceof Uint16Array||t.indices instanceof Uint32Array?t.indices:t.indices?new Uint32Array(t.indices):void 0),uvs:t.uvs?t.uvs instanceof Float32Array?t.uvs:new Float32Array(t.uvs):void 0,normals:t.normals?t.normals instanceof Float32Array?t.normals:new Float32Array(t.normals):void 0}}const e=t?.data??t;if(e?.attributes?.position?.array){const t=new Float32Array(e.attributes.position.array);let i;if(e.index?.array){i=new("Uint16Array"===e.index.type?Uint16Array:Uint32Array)(e.index.array)}return{positions:t,indices:os(t,i),uvs:e.attributes.uv?.array?new Float32Array(e.attributes.uv.array):void 0,normals:e.attributes.normal?.array?new Float32Array(e.attributes.normal.array):void 0}}return{positions:ys,indices:xs,uvs:vs}}addBehavior(t){this.behaviors.push(t),this._renderer?._invalidateUpdateOrder()}getRendererSettings(){return this.rendererSettings}addEventListener(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)}removeAllEventListeners(t){this.listeners[t]&&(this.listeners[t]=[])}removeEventListener(t,e){if(this.listeners[t]){const i=this.listeners[t].indexOf(e);-1!==i&&this.listeners[t].splice(i,1)}}hasListeners(t){const e=this.listeners[t];return void 0!==e&&e.length>0}fire(t){const e=this.listeners[t.type];if(void 0!==e)for(let i=0;i<e.length;i++)e[i](t)}clone(){const t=this.behaviors.map(t=>t.clone());let e;return e=this.renderMode===exports.RenderMode.Trail?{startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin,...gs(this.rendererEmitterSettings)}:this.renderMode===exports.RenderMode.StretchedBillBoard?{lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:{},new Ss({autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,startDelay:this.startDelay.clone(),shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:this.emissionBursts.map(t=>({...t})),maxParticles:this.maxParticles,onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,instancingIndices:this.rendererSettings.instancingIndices,instancingUVs:this.rendererSettings.instancingUVs,instancingNormals:this.rendererSettings.instancingNormals,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:e,material:this.materialRef,texture:this.rendererSettings.texture,startTileIndex:this.startTileIndex,uTileCount:this.rendererSettings.uTileCount,vTileCount:this.rendererSettings.vTileCount,blendTiles:this.rendererSettings.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:t,worldSpace:this.worldSpace,blendMode:this.rendererSettings.materialBlendMode,transparent:this.rendererSettings.materialTransparent,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,layerMask:this.rendererSettings.layerMask,pivot:this.pivot,flip:this.flip,lighting:this.lighting,rim:this.rim,scene:this.emitter.getScene()})}}Ss.serializationCounter=0;class ws extends e.TransformNode{constructor(t="QuarksPrefab",e){super(t,e),this.type="QuarksPrefab",this.animationData=[],this.isPlaying=!1,this.currentTime=-1e-5,this.timeScale=1,this.duration=0,this._lastUpdateTimeMs=Date.now(),this._tempAnimationJSON=[]}registerBatchedRenderer(t){this._batchedRenderer=t}addParticleSystemAnimation(t,e=0,i=0,s=!1){const r={startTime:e,duration:i>0?i:t.system.duration,type:"ps",loop:s,target:t};return this.animationData.push(r),this.pause(),this.updateDuration(),r}addThreeAnimation(t,e,i=0,s=e?.duration??0,r=!1,n){const o={startTime:i,duration:s>0?s:e?.duration??0,type:"three",loop:r,target:t,clip:e,clipUUID:n??e?.uuid};return this.animationData.push(o),this.updateDuration(),o}removeAnimation(t){this.animationData.splice(t,1),this.updateDuration()}play(){this.isPlaying||(this.isPlaying=!0,this._lastUpdateTimeMs=Date.now())}pause(){this.isPlaying&&(this.isPlaying=!1,this.animationData.forEach(t=>{"ps"===t.type&&t.target instanceof ns?t.target.system.pause():t.clip?.pause?.()}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(t=>{"ps"===t.type&&t.target instanceof ns?t.target.system.stop():t.clip?.stop?.()})}update(t){if(!this.isPlaying)return;const e=Date.now(),i=t??Math.max((e-this._lastUpdateTimeMs)/1e3,0);this._lastUpdateTimeMs=e;const s=this.currentTime;this.currentTime+=i*this.timeScale,this.currentTime>this.duration?this.stop():this.animationData.forEach(t=>{const e=t.startTime,i=t.startTime+t.duration,r=this.currentTime>=e&&this.currentTime<=i,n=s>=e&&s<=i;if(!r||n){if(!r&&n){if(t.loop&&"ps"===t.type&&t.target instanceof ns)return void t.target.system.restart();"ps"===t.type&&t.target instanceof ns?t.target.system.endEmit():t.loop?t.clip?.play?.():t.clip?.stop?.()}}else"ps"===t.type&&t.target instanceof ns?(t.target.system.restart(),this._batchedRenderer&&this._batchedRenderer.addSystem(t.target.system)):t.clip?.play?.()})}setTime(t){const e=this.currentTime;this.currentTime=t,this.animationData.forEach(i=>{const s=i.startTime,r=i.startTime+i.duration,n=this.currentTime>=s&&this.currentTime<r,o=e>=s&&e<r;!n||o?n||!o?n&&"three"===i.type&&i.clip?.setTime?.(Math.max(t-s,0)):"ps"===i.type&&i.target instanceof ns?i.target.system.endEmit():i.clip?.stop?.():"ps"===i.type&&i.target instanceof ns?i.target.system.restart():i.clip?.play?.()})}getDuration(){return this.duration}resolveReferences(t){const i={},s=t=>{t._quarksUUID&&(i[t._quarksUUID]=t),i[t.uniqueId.toString()]=t;const r=t.getChildren();for(const t of r)t instanceof e.TransformNode&&s(t)};s(t),this._tempAnimationJSON.forEach(t=>{const e=i[t.targetUUID];if("ps"===t.type&&e instanceof ns)this.addParticleSystemAnimation(e,t.startTime,t.duration,t.loop);else if("three"===t.type&&e){const i=this.resolveTimelineClip(e,t.clipUUID);this.addThreeAnimation(e,i,t.startTime,t.duration,t.loop,t.clipUUID)}}),this.updateDuration(),this._tempAnimationJSON=[]}toJSON(){return{type:this.type,name:this.name,animationData:this.animationData.map(t=>({startTime:t.startTime,duration:t.duration,type:t.type,targetUUID:t.target._quarksUUID??t.target.uniqueId.toString(),clipUUID:"three"===t.type?t.clipUUID??t.clip?.uuid:void 0,loop:t.loop}))}}static fromJSON(t,e){const i=new ws(t.name||"QuarksPrefab",e);return Array.isArray(t.animationData)&&(i._tempAnimationJSON=t.animationData.filter(t=>"ps"===t?.type||"three"===t?.type)),i}resolveTimelineClip(t,e){const i=[t.animations,t.animationGroups,t.metadata?.animations,t.metadata?.animationGroups];for(const t of i){if(!Array.isArray(t))continue;if(!e)return t[0];const i=t.find(t=>t?.uuid===e);if(i)return i}}updateDuration(){let t=0;this.animationData.forEach(e=>{const i=e.startTime+e.duration;i>t&&(t=i)}),this.duration=t}}const bs=new WeakMap,Ms=new WeakMap,zs=new WeakMap;function _s(t,e){let i=t.get(e);return void 0===i&&(i=new Map,t.set(e,i)),i}class Ts{constructor(t,e={}){this.scene=t,this.options=e}async load(t){const{json:e,baseUrl:i}=await this.fetchEffectDocument(t);return this.loadFromJSON(e,i)}async loadFromJSON(t,e){const i=e??this.options.baseUrl??"";return await this.resolveResources(t,i),this.parse(t,i)}async loadAll(t,e={}){const i=await Ts.mapPool(t,e.concurrency,async(i,s)=>{try{return await this.fetchEffectDocument(i)}catch(r){if(!e.continueOnError)throw r;return console.warn(`[QuarksLoader] Failed to fetch effect "${i}" (${s+1}/${t.length}):`,r),null}});return this.loadDocuments(i,e)}async loadFromJSONAll(t,e={}){const i=t.map(t=>{if(null!==t&&"object"==typeof t&&"json"in t){const e=t;return{json:e.json,baseUrl:e.baseUrl??this.options.baseUrl??""}}return{json:t,baseUrl:this.options.baseUrl??""}});return this.loadDocuments(i,e)}async resolveResources(t,e=""){await Ts.resolveLinkedResources(t,{baseUrl:e,resolver:this.options.resolver,scene:this.scene})}static async resolveLinkedResources(t,e={}){const i=e.baseUrl??"",s=e.resolver,r=e.scene;await Ts.inlineGeometryEntries(t,async t=>{const e=await Ts.resolveWith(s,t,"geometry",i);return Ts.fetchJsonWith(s,e,r)});const n=Array.isArray(t?.images)?t.images:[];await Promise.all(n.map(async t=>{"string"==typeof t?.url&&t.url&&(t.url=await Ts.resolveWith(s,t.url,"image",i))}))}static async resolveExternalGeometries(t,e){await Ts.inlineGeometryEntries(t,e)}parse(t,e=""){const i={textures:{},geometries:{},materials:{}};t.geometries&&this.parseGeometries(t.geometries,i),t.images&&this.parseImages(t.images,e,i),t.textures&&this.parseTextures(t.textures,i),t.materials&&this.parseMaterials(t.materials,i);const s=this.parseObject(t.object,i);return this.linkReferences(s),s}parseGeometries(t,e){for(const i of t)if("PlaneGeometry"===i.type){const t=(i.width||1)/2,s=(i.height||1)/2;e.geometries[i.uuid]={positions:new Float32Array([-t,-s,0,t,-s,0,t,s,0,-t,s,0]),indices:new Uint32Array([0,1,2,0,2,3]),uvs:new Float32Array([0,0,1,0,1,1,0,1]),normals:new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1])}}else if("SphereGeometry"===i.type)e.geometries[i.uuid]=this.parseSphereGeometry(i);else if("BufferGeometry"===i.type&&i.data){const t=this.parseBufferGeometry(i.data);e.geometries[i.uuid]=t}else"QuarksGeometry"===i.type&&("string"!=typeof i.url||i.positions||console.warn(`[QuarksLoader] Geometry "${i.url}" is an external file; use load(), loadFromJSON(), or resolveResources() before parse().`),e.geometries[i.uuid]=this.share({positions:new Float32Array(i.positions??[]),indices:i.indices?new Uint32Array(i.indices):new Uint32Array(0),uvs:i.uvs?new Float32Array(i.uvs):void 0,normals:i.normals?new Float32Array(i.normals):void 0}))}share(t){if(!1===this.options.shareResources)return t;const e=_s(Ms,this.scene),i=function(t){let e=2166136261,i=2654435769;const s=[t.positions,t.indices,t.uvs,t.normals];let r="";for(const t of s){if(void 0===t){r+="-,";continue}const s=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);r+=s.length+",";for(let t=0;t<s.length;t++)e=Math.imul(e^s[t],16777619),i=Math.imul(i^s[t],1540483477)^i>>>15}return`${r}${(e>>>0).toString(16)}${(i>>>0).toString(16)}`}(t),s=e.get(i);return void 0!==s?s:(e.set(i,t),t)}static clearSharedResources(t){bs.delete(t),Ms.delete(t),zs.delete(t)}static joinUrl(t,e){return/^(data|blob):/i.test(e)||/^[a-z][a-z0-9+.-]*:\/\//i.test(e)||e.startsWith("/")?e:t+e}parseSphereGeometry(t){const e=t.radius??.5,i=Math.max(3,Math.floor(t.widthSegments??16)),s=Math.max(2,Math.floor(t.heightSegments??8)),r=t.phiStart??0,n=t.phiLength??2*Math.PI,o=t.thetaStart??0,a=t.thetaLength??Math.PI,h=[],l=[],c=[],u=[],d=[];let p=0;for(let t=0;t<=s;t++){const u=[],f=t/s,m=o+f*a;for(let t=0;t<=i;t++){const s=t/i,o=r+s*n,a=-e*Math.cos(o)*Math.sin(m),d=e*Math.cos(m),y=e*Math.sin(o)*Math.sin(m);h.push(a,d,y);const v=Math.hypot(a,d,y)||1;l.push(a/v,d/v,y/v),c.push(s,1-f),u.push(p++)}d.push(u)}const f=o<=0,m=o+a>=Math.PI;for(let t=0;t<s;t++)for(let e=0;e<i;e++){const i=d[t][e+1],r=d[t][e],n=d[t+1][e],o=d[t+1][e+1];0===t&&f||u.push(i,r,o),t===s-1&&m||u.push(r,n,o)}const y=h.length/3>65535?new Uint32Array(u):new Uint16Array(u);return{positions:new Float32Array(h),indices:y,uvs:new Float32Array(c),normals:new Float32Array(l)}}parseBufferGeometry(t){let e,i,s=new Float32Array(0),r=new Uint32Array(0);if(t.interleavedBuffers&&t.arrayBuffers){const r={};for(const[e,i]of Object.entries(t.interleavedBuffers)){const s=t.arrayBuffers[i.buffer];if(s){const t=new Float32Array(Array.isArray(s)?this.int32ArrayToFloat32(s):s);r[e]={data:t,stride:i.stride}}}if(t.attributes){if(t.attributes.position?.isInterleavedBufferAttribute){const e=t.attributes.position,i=r[e.data];i&&(s=this.extractInterleavedAttribute(i.data,i.stride,e.offset,e.itemSize))}if(t.attributes.uv?.isInterleavedBufferAttribute){const i=t.attributes.uv,s=r[i.data];s&&(e=this.extractInterleavedAttribute(s.data,s.stride,i.offset,i.itemSize))}if(t.attributes.normal?.isInterleavedBufferAttribute){const e=t.attributes.normal,s=r[e.data];s&&(i=this.extractInterleavedAttribute(s.data,s.stride,e.offset,e.itemSize))}}}else t.attributes&&(t.attributes.position?.array&&(s=new Float32Array(t.attributes.position.array)),t.attributes.uv?.array&&(e=new Float32Array(t.attributes.uv.array)),t.attributes.normal?.array&&(i=new Float32Array(t.attributes.normal.array)));return t.index&&(r="Uint16Array"===t.index.type?new Uint16Array(t.index.array):new Uint32Array(t.index.array)),r=os(s,r),{positions:s,indices:r,uvs:e,normals:i}}extractInterleavedAttribute(t,e,i,s){const r=Math.floor(t.length/e),n=new Float32Array(r*s);for(let o=0;o<r;o++)for(let r=0;r<s;r++)n[o*s+r]=t[o*e+i+r];return n}int32ArrayToFloat32(t){const e=new ArrayBuffer(4*t.length),i=new Int32Array(e);for(let e=0;e<t.length;e++)i[e]=t[e];return new Float32Array(e)}async resolveResourceUrl(t,e,i){return Ts.resolveWith(this.options.resolver,t,e,i)}async fetchEffectDocument(t){const e=this.options.baseUrl||t.substring(0,t.lastIndexOf("/")+1),i=await this.resolveResourceUrl(t,"effect",e);return{json:await Ts.fetchJsonWith(this.options.resolver,i,void 0),baseUrl:e}}async loadDocuments(t,e){const i=t.length;if(0===i)return[];const s=new Array(i),r=new Array(i).fill(!1);let n=0;const o=(t,o)=>{r[t]||(r[t]=!0,s[t]=o,n++,e.onProgress?.(n,i))};await Promise.all(t.map(async(s,r)=>{if(s)try{await this.resolveResources(s.json,s.baseUrl)}catch(s){if(!e.continueOnError)throw s;console.warn(`[QuarksLoader] Failed to resolve resources for effect ${r+1}/${i}:`,s),t[r]=null,o(r,null)}}));for(let s=0;s<i;s++){if(r[s])continue;const n=t[s];if(n)try{o(s,this.parse(n.json,n.baseUrl))}catch(t){if(!e.continueOnError)throw t;console.warn(`[QuarksLoader] Failed to parse effect ${s+1}/${i}:`,t),o(s,null)}else o(s,null)}return s}static async mapPool(t,e,i){if(0===t.length)return[];const s=void 0!==e&&e>0?e:t.length,r=new Array(t.length);let n=0;const o=Math.min(s,t.length);return await Promise.all(Array.from({length:o},()=>(async()=>{for(;n<t.length;){const e=n++;r[e]=await i(t[e],e)}})())),r}static async resolveWith(t,e,i,s){return t?.resolve?t.resolve(e,i,s):Ts.joinUrl(s,e)}static fetchJsonWith(t,e,i){const s=async()=>{if(t?.fetchJson)return t.fetchJson(e);const i=await fetch(e);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()};if(!i)return s();const r=_s(zs,i),n=`json|${e}`;let o=r.get(n);return void 0===o&&(o=s().catch(t=>{throw r.get(n)===o&&r.delete(n),t}),r.set(n,o)),o}static async inlineGeometryEntries(t,e){const i=Array.isArray(t?.geometries)?t.geometries:[];await Promise.all(i.filter(t=>"string"==typeof t?.url&&!t.positions).map(async t=>{try{const i=await e(t.url);for(const e of["positions","indices","uvs","normals"]){const s=i?.[e];void 0!==s&&(t[e]=Array.isArray(s)?s.slice():s)}delete t.url}catch(e){console.warn(`[QuarksLoader] Could not load geometry "${t.url}":`,e)}}))}parseImages(t,e,i){this._images={};for(const i of t)i.url&&Ts.warnIfNotAnImageUrl(i.url),this._images[i.uuid]=i.url?Ts.joinUrl(e,i.url):null}static warnIfNotAnImageUrl(t){/^(data|blob):/i.test(t)||/\.(png|jpe?g|webp|gif|bmp|ktx2?|dds|env|basis)(\?|#|$)/i.test(t)||console.warn(`[QuarksLoader] Image "${t}" does not look like an image; its texture will fail to load. This usually means the effect was exported without embedding that texture.`)}parseTextures(t,e){const i=this._images||{};for(const s of t){const t=i[s.image];if(t){const i=void 0===s.invertY||!!s.invertY,r=!!s.noMipmap,n=!1!==this.options.shareResources,o=n?[i,r,s.samplingMode,s.wrap,s.repeat,s.offset,s.rotation].join("|")+"|"+t:"",a=n?_s(bs,this.scene):void 0,h=a?.get(o);if(void 0!==h){e.textures[s.uuid]=h;continue}const l=new p.Texture(t,this.scene,{noMipmap:r,invertY:i,samplingMode:"number"==typeof s.samplingMode?s.samplingMode:void 0});Array.isArray(s.wrap)&&(l.wrapU=this.mapWrapMode(s.wrap[0]),l.wrapV=this.mapWrapMode(s.wrap[1]??s.wrap[0])),Array.isArray(s.repeat)&&(l.uScale=s.repeat[0]??1,l.vScale=s.repeat[1]??1),Array.isArray(s.offset)&&(l.uOffset=s.offset[0]??0,l.vOffset=s.offset[1]??0),"number"==typeof s.rotation&&(l.wAng=s.rotation),void 0!==a&&(a.set(o,l),l.onDisposeObservable.addOnce(()=>{a.get(o)===l&&a.delete(o)})),e.textures[s.uuid]=l}else e.textures[s.uuid]=null}}mapWrapMode(t){switch(t){case 1001:return p.Texture.CLAMP_ADDRESSMODE;case 1002:return p.Texture.MIRROR_ADDRESSMODE;default:return p.Texture.WRAP_ADDRESSMODE}}parseMaterials(t,e){for(const s of t){const t={uuid:s.uuid,transparent:s.transparent??!0,blending:s.blending??1,side:s.side??2,depthTest:s.depthTest??!0,depthWrite:s.depthWrite??!1,alphaTest:s.alphaTest??0,texture:null},r=s.map??s.texture;r&&(t.texture=e.textures[r]||null);const n=s.reflectionAtlas;if(n&&(t.reflectionAtlas=e.textures[n]||null),"number"==typeof s.reflectionLevel&&(t.reflectionLevel=s.reflectionLevel),"unlit"!==s.lighting&&"fixed"!==s.lighting&&"scene"!==s.lighting||(t.lighting=s.lighting),s.rim&&"object"==typeof s.rim&&(t.rim=s.rim),"number"==typeof s.alphaMode)t.alphaMode=s.alphaMode;else{const e={1:i.Constants.ALPHA_COMBINE,2:i.Constants.ALPHA_ADD,3:i.Constants.ALPHA_SUBTRACT,4:i.Constants.ALPHA_MULTIPLY};t.alphaMode=e[s.blending]||i.Constants.ALPHA_COMBINE}e.materials[s.uuid]=t}}getGeometry(t,e){if(e)return t.geometries[e]}getMaterial(t,e){if(!e)return;const i=Array.isArray(e)?e[0]:e;return t.materials[i]}createPlaceholderNode(t,i){const s=new e.TransformNode(i||t||"node",this.scene);return s.quarksOriginalType=t,s}createMeshNode(t,e){const s=new o.Mesh(t.name||t.type||"mesh",this.scene),r=this.getGeometry(e,t.geometry);if(r&&r.positions.length>0&&r.indices.length>0){const t=new a.VertexData;t.positions=r.positions,t.indices=r.indices,r.uvs&&r.uvs.length>0&&(t.uvs=r.uvs),r.normals&&r.normals.length>0&&(t.normals=r.normals),t.applyToMesh(s,!0)}const n=this.getMaterial(e,t.material);if(n){const t=new m.StandardMaterial(`quarks_loader_material_${n.uuid}`,this.scene);t.alphaMode=n.alphaMode??i.Constants.ALPHA_COMBINE,t.backFaceCulling=2!==n.side,t.alphaCutOff=n.alphaTest??0,t.disableDepthWrite=!n.depthWrite,n.texture&&(t.diffuseTexture=n.texture,t.opacityTexture=n.texture),s.material=t}return s}parseObject(t,i){let s;switch(t.type){case"QuarksPrefab":s=ws.fromJSON(t,this.scene);break;case"ParticleEmitter":if(t.ps){s=this.parseParticleSystem(t.ps,i).emitter;break}s=this.createPlaceholderNode(t.type,t.name);break;case"Mesh":case"SkinnedMesh":case"InstancedMesh":case"BatchedMesh":s=this.createMeshNode(t,i);break;case"Scene":case"Group":case"Object3D":case"PerspectiveCamera":case"OrthographicCamera":case"AmbientLight":case"DirectionalLight":case"PointLight":case"RectAreaLight":case"SpotLight":case"HemisphereLight":case"LightProbe":case"LOD":case"Line":case"LineSegments":case"LineLoop":case"PointCloud":case"Points":case"Sprite":case"Bone":s=this.createPlaceholderNode(t.type,t.name);break;default:s=new e.TransformNode(t.name||t.type||"node",this.scene)}if(t.uuid&&(s._quarksUUID=t.uuid),t.name&&(s.name=t.name),t.matrix){const e=n.Matrix.FromArray(t.matrix),i=new n.Vector3(1,1,1),r=n.Quaternion.Identity(),o=new n.Vector3(0,0,0);e.decompose(i,r,o),s.position.copyFrom(o),s.scaling.copyFrom(i),s.rotationQuaternion=r}else t.position&&s.position.set(t.position[0],t.position[1],t.position[2]),t.scale&&s.scaling.set(t.scale[0],t.scale[1],t.scale[2]),t.quaternion?s.rotationQuaternion=new n.Quaternion(t.quaternion[0],t.quaternion[1],t.quaternion[2],t.quaternion[3]):t.rotation&&s.rotation.set(t.rotation[0],t.rotation[1],t.rotation[2]);if(void 0!==t.visible&&s.setEnabled(t.visible),t.children)for(const e of t.children){this.parseObject(e,i).parent=s}return s}parseParticleSystem(t,e){const i=Ss.fromJSON(t,e,{},this.scene);return i._meshSurfaceReferenceUUID="mesh_surface"===t?.shape?.type?t?.shape?.mesh:void 0,i}linkReferences(t){const i={},s=t=>{t._quarksUUID&&(i[t._quarksUUID]=t);for(const i of t.getChildren())i instanceof e.TransformNode&&s(i)};s(t);const r=s=>{if(s instanceof ws&&s.resolveReferences(t),s instanceof ns){const t=s.system,e=t._meshSurfaceReferenceUUID;if(e&&"mesh_surface"===t.emitterShape.type){const s=i[e];s instanceof o.Mesh&&(t.emitterShape.mesh=s)}for(let e=0;e<t.behaviors.length;e++)if(t.behaviors[e]instanceof ae){const r=t.behaviors[e],n=r.subParticleSystem;if("string"!=typeof n)continue;const o=i[n];o instanceof ns?(r.subParticleSystem=o,o.system.onlyUsedByOther=!0):(r.subParticleSystem=void 0,""!==n&&console.warn(`[QuarksLoader] Emitter "${s.name}" has a sub emitter targeting "${n}", `+(o?"which is not a particle emitter":"which is not in the effect")+"; that sub emitter is skipped."))}}for(const t of s.getChildren())t instanceof e.TransformNode&&r(t)};r(t)}}class Ps{static runOnAllParticleEmitters(t,e){Ps.traverseNode(t,t=>{t instanceof ns&&e(t)})}static addToBatchRenderer(t,e){Ps.runOnAllParticleEmitters(t,t=>{e.addSystem(t.system)})}static play(t){Ps.runOnAllParticleEmitters(t,t=>{t.system.play()})}static stop(t){Ps.runOnAllParticleEmitters(t,t=>{t.system.stop()})}static pause(t){Ps.runOnAllParticleEmitters(t,t=>{t.system.pause()})}static restart(t){Ps.runOnAllParticleEmitters(t,t=>{t.system.restart()})}static setAutoDestroy(t,e){Ps.runOnAllParticleEmitters(t,t=>{t.system.autoDestroy=e})}static endEmit(t){Ps.runOnAllParticleEmitters(t,t=>{t.system.endEmit()})}static isEffectFinished(t){let e=!1,i=!0;return Ps.runOnAllParticleEmitters(t,t=>{e=!0;const s=t.system;s.looping?i=!1:s.isFinished()||(i=!1)}),e&&i}static traverseNode(t,e){e(t);const i=t.getChildren();for(const t of i)Ps.traverseNode(t,e)}}Ci(),_i(Pi),exports.ApplyCollision=wt,exports.ApplyForce=jt,exports.ApplySequences=Zt,exports.AxisAngleGenerator=Vt,exports.BatchedParticleRenderer=Yi,exports.BatchedRenderer=ji,exports.BehaviorFromJSON=je,exports.BehaviorTypes=Ge,exports.Bezier=zt,exports.BoxEmitter=ci,exports.ChangeEmitDirection=Ht,exports.CircleEmitter=pi,exports.ColorBySpeed=Kt,exports.ColorGeneratorFromJSON=Dt,exports.ColorOverLife=te,exports.ColorRange=$t,exports.ConeEmitter=fi,exports.ConstantColor=Ut,exports.ConstantValue=bt,exports.DEG2RAD=x,exports.DonutEmitter=mi,exports.EdgeEmitter=yi,exports.EmitSubParticleSystem=ae,exports.EmitterFromJSON=Mi,exports.EmitterShapes=bi,exports.Euler=nt,exports.EulerGenerator=qt,exports.ForceOverLife=he,exports.FrameOverLife=le,exports.GeneratorFromJSON=Gt,exports.Gradient=Nt,exports.GravityForce=ce,exports.GridEmitter=vi,exports.HemisphereEmitter=xi,exports.InheritVelocity=ue,exports.IntervalValue=Mt,exports.LimitSpeedOverLife=de,exports.MathUtils=q,exports.Matrix3=ot,exports.Matrix4=Y,exports.MeshSurfaceEmitter=Ti,exports.MeshSurfaceEmitterPlugin=Pi,exports.NodeParticle=class{constructor(){this.position=new k,this.velocity=new k,this.age=0,this.life=1,this.size=new k,this.rotation=0,this.color=new mt(1,1,1,1),this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.position.set(0,0,0),this.velocity.set(0,0,0),this.age=0,this.life=1,this.size.set(1,1,1),this.rotation=0,this.color.set(1,1,1,1),this.uvTile=0}},exports.Noise=Ve,exports.OrbitOverLife=Oe,exports.ParticleEmitter=ns,exports.ParticleMeshPhysicsMaterial=rs,exports.ParticleMeshStandardMaterial=ss,exports.ParticleStore=pe,exports.ParticleSystem=Ss,exports.PiecewiseBezier=Tt,exports.PiecewiseFunction=_t,exports.Plugins=zi,exports.PointEmitter=gi,exports.QuarksLoader=Ts,exports.QuarksPrefab=ws,exports.QuarksUtil=Ps,exports.Quaternion=J,exports.QuaternionView=lt,exports.RAD2DEG=g,exports.RandomColor=It,exports.RandomColorBetweenGradient=Rt,exports.RandomQuatGenerator=Jt,exports.RecordState=class{constructor(t,e,i){this.position=t,this.size=e,this.color=i}},exports.RectangleEmitter=wi,exports.Rotation3DOverLife=Ce,exports.RotationBySpeed=Ae,exports.RotationGeneratorFromJSON=kt,exports.RotationOverLife=Be,exports.SequencerFromJSON=Xt,exports.ShapeTransform=di,exports.SizeBySpeed=$e,exports.SizeOverLife=Fe,exports.SpeedOverLife=Ee,exports.SphereEmitter=Si,exports.SpriteBatch=Wi,exports.SpriteParticle=Je,exports.TextureSequencer=Yt,exports.TrailBatch=Gi,exports.TrailParticle=Qe,exports.TurbulenceField=Ne,exports.VFXBatch=Qi,exports.ValueGeneratorFromJSON=Pt,exports.Vector2=ut,exports.Vector3=k,exports.Vector3Function=Qt,exports.Vector3GeneratorFromJSON=Wt,exports.Vector3View=pt,exports.Vector4=mt,exports.Vector4View=vt,exports.VelocityOverLife=Ue,exports.WebGLCoordinateSystem=G,exports.WebGPUCoordinateSystem=j,exports.WidthOverLength=We,exports.cacheEnvAtlas=function(t,e){Xi.set(t,e)},exports.ceilPowerOfTwo=I,exports.clamp=w,exports.createEnvAtlasFromFaceUrls=ts,exports.cubeFaceUrls=Hi,exports.damp=T,exports.defaultMeshLighting=qi,exports.degToRad=F,exports.denormalize=U,exports.ensureEnvAtlasFromCube=is,exports.euclideanModulo=b,exports.floorPowerOfTwo=L,exports.generateUUID=S,exports.getCachedEnvAtlas=Ki,exports.getPhysicsResolver=St,exports.getRegisteredShaderChunks=function(){return Vi},exports.getShaderChunk=function(t){return Vi[t]},exports.getValueFromEmitterMode=ui,exports.inverseLerp=z,exports.isPowerOfTwo=N,exports.lerp=_,exports.loadPlugin=_i,exports.localParticlePhysicsVertShader=Ai,exports.localParticleVertShader="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\n// Uniforms\nuniform mat4 worldViewProjection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 rotatedPosition = applyQuaternion(position * size, rotation);\n vec3 worldPos = rotatedPosition + offset;\n\n gl_Position = worldViewProjection * vec4(worldPos, 1.0);\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n",exports.mapLinear=M,exports.meshRimEqual=ki,exports.normalize=D,exports.normalizeMeshRim=Ji,exports.particleFragShader=Bi,exports.particlePhysicsFragShader=$i,exports.particleVertShader=Fi,exports.pingpong=P,exports.planBehaviorFusion=ai,exports.radToDeg=E,exports.randFloat=A,exports.randFloatSpread=B,exports.randInt=C,exports.registerShaderChunks=Ci,exports.seededRandom=$,exports.setPhysicsResolver=function(t){gt=t},exports.setQuaternionFromProperEuler=R,exports.smootherstep=O,exports.smoothstep=V,exports.stretchedBillboardVertShader=Ei,exports.trailFragShader=Ni,exports.trailVertShader=Ii,exports.unloadPlugin=function(t){const e=zi.find(e=>e.id===t);if(e){for(const t of e.emitterShapes)bi[t.type]&&delete bi[t.type];for(const t of e.behaviors)Ge[t.type]&&delete Ge[t.type]}};
|
|
1
|
+
"use strict";var t=require("@babylonjs/core/Buffers/buffer"),e=require("@babylonjs/core/Maths/math.frustum"),i=require("@babylonjs/core/Maths/math.plane"),s=require("@babylonjs/core/Meshes/transformNode"),r=require("@babylonjs/core/Engines/constants"),n=require("@babylonjs/core/Materials/shaderMaterial"),o=require("@babylonjs/core/Materials/Textures/rawTexture"),a=require("@babylonjs/core/Maths/math.vector"),h=require("@babylonjs/core/Meshes/mesh"),l=require("@babylonjs/core/Meshes/mesh.vertexData"),c=require("@babylonjs/core/Engines/shaderStore"),u=require("@babylonjs/core/Materials/effect"),d=require("@babylonjs/core/Materials/shaderLanguage"),p=require("@babylonjs/core/Culling/boundingInfo"),f=require("@babylonjs/core/Maths/math.color"),m=require("@babylonjs/core/scene"),y=require("@babylonjs/core/Materials/Textures/texture"),v=require("@babylonjs/core/Materials/PBR/pbrMaterial"),g=require("@babylonjs/core/Materials/standardMaterial");let x=null;function S(){return null===x?Math.random():x()}function w(){return x??Math.random}function b(t){const e=w();return x=t,e}function z(t){let e=t>>>0||2654435769;return()=>{e=e+1831565813|0;let t=e;return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),((t^t>>>14)>>>0)/4294967296}}const M=["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"];let _=1234567;const P=Math.PI/180,T=180/Math.PI;function V(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return(M[255&t]+M[t>>8&255]+M[t>>16&255]+M[t>>24&255]+"-"+M[255&e]+M[e>>8&255]+"-"+M[e>>16&15|64]+M[e>>24&255]+"-"+M[63&i|128]+M[i>>8&255]+"-"+M[i>>16&255]+M[i>>24&255]+M[255&s]+M[s>>8&255]+M[s>>16&255]+M[s>>24&255]).toLowerCase()}function O(t,e,i){return Math.max(e,Math.min(i,t))}function C(t,e){return(t%e+e)%e}function F(t,e,i,s,r){return s+(t-e)*(r-s)/(i-e)}function B(t,e,i){return t!==e?(i-t)/(e-t):0}function A(t,e,i){return(1-i)*t+i*e}function $(t,e,i,s){return A(t,e,1-Math.exp(-i*s))}function I(t,e=1){return e-Math.abs(C(t,2*e)-e)}function E(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*(3-2*t)}function N(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*t*(t*(6*t-15)+10)}function L(t,e){return t+Math.floor(S()*(e-t+1))}function R(t,e){return t+S()*(e-t)}function D(t){return t*(.5-S())}function U(t){void 0!==t&&(_=t);let e=_+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}function q(t){return t*P}function k(t){return t*T}function J(t){return!(t&t-1)&&0!==t}function Q(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))}function G(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function W(t,e,i,s,r){const n=Math.cos,o=Math.sin,a=n(i/2),h=o(i/2),l=n((e+s)/2),c=o((e+s)/2),u=n((e-s)/2),d=o((e-s)/2),p=n((s-e)/2),f=o((s-e)/2);switch(r){case"XYX":t.set(a*c,h*u,h*d,a*l);break;case"YZY":t.set(h*d,a*c,h*u,a*l);break;case"ZXZ":t.set(h*u,h*d,a*c,a*l);break;case"XZX":t.set(a*c,h*f,h*p,a*l);break;case"YXY":t.set(h*p,a*c,h*f,a*l);break;case"ZYZ":t.set(h*f,h*p,a*c,a*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function j(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Y(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const X={DEG2RAD:P,RAD2DEG:T,generateUUID:V,clamp:O,euclideanModulo:C,mapLinear:F,inverseLerp:B,lerp:A,damp:$,pingpong:I,smoothstep:E,smootherstep:N,randInt:L,randFloat:R,randFloatSpread:D,seededRandom:U,degToRad:q,radToDeg:k,isPowerOfTwo:J,ceilPowerOfTwo:Q,floorPowerOfTwo:G,setQuaternionFromProperEuler:W,normalize:Y,denormalize:j};class Z{constructor(t=0,e=0,i=0,s=1){this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,r,n,o){let a=i[s+0],h=i[s+1],l=i[s+2],c=i[s+3];const u=r[n+0],d=r[n+1],p=r[n+2],f=r[n+3];if(0===o)return t[e+0]=a,t[e+1]=h,t[e+2]=l,void(t[e+3]=c);if(1===o)return t[e+0]=u,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(c!==f||a!==u||h!==d||l!==p){let t=1-o;const e=a*u+h*d+l*p+c*f,i=e>=0?1:-1,s=1-e*e;if(s>Number.EPSILON){const r=Math.sqrt(s),n=Math.atan2(r,e*i);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*i;if(a=a*t+u*r,h=h*t+d*r,l=l*t+p*r,c=c*t+f*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+l*l+c*c);a*=t,h*=t,l*=t,c*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,s,r,n){const o=i[s],a=i[s+1],h=i[s+2],l=i[s+3],c=r[n],u=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+l*c+a*d-h*u,t[e+1]=a*p+l*u+h*c-o*d,t[e+2]=h*p+l*d+o*u-a*c,t[e+3]=l*p-o*c-a*u-h*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 Z(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,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(i/2),l=o(s/2),c=o(r/2),u=a(i/2),d=a(s/2),p=a(r/2);switch(n){case"XYZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"YXZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"ZXY":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"ZYX":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"YZX":this._x=u*l*c+h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c-u*d*p;break;case"XZY":this._x=u*l*c-h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c+u*d*p;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&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],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],l=e[6],c=e[10],u=i+o+c;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(n-s)*t}else if(i>o&&i>c){const t=2*Math.sqrt(1+i-o-c);this._w=(l-a)/t,this._x=.25*t,this._y=(s+n)/t,this._z=(r+h)/t}else if(o>c){const t=2*Math.sqrt(1+o-i-c);this._w=(r-h)/t,this._x=(s+n)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+c-i-o);this._w=(n-s)/t,this._x=(r+h)/t,this._y=(a+l)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(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(O(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(0===i)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 0===t?(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,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,l=e._w;return this._x=i*l+n*o+s*h-r*a,this._y=s*l+n*a+r*o-i*h,this._z=r*l+n*h+i*a-s*o,this._w=n*l-i*o-s*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const i=this._x,s=this._y,r=this._z,n=this._w;let o=n*t._w+i*t._x+s*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=i,this._y=s,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*i+e*this._x,this._y=t*s+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),l=Math.atan2(h,o),c=Math.sin((1-e)*l)/h,u=Math.sin(e*l)/h;return this._w=n*c+this._w*u,this._x=i*c+this._x*u,this._y=s*c+this._y*u,this._z=r*c+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*S(),e=2*Math.PI*S(),i=S(),s=Math.sqrt(1-i),r=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),r*Math.sin(e),r*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}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}}Z.prototype.isQuaternion=!0;class H{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return void 0===i&&(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 H(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(tt.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(tt.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[3]*i+r[6]*s,this.y=r[1]*e+r[4]*i+r[7]*s,this.z=r[2]*e+r[5]*i+r[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,r=t.elements,n=1/(r[3]*e+r[7]*i+r[11]*s+r[15]);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}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*s-o*i),l=2*(o*e-r*s),c=2*(r*i-n*e);return this.x=e+a*h+n*c-o*l,this.y=i+a*l+o*h-r*c,this.z=s+a*c+r*l-n*h,this}transformDirection(t){const e=this.x,i=this.y,s=this.z,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s,this.y=r[1]*e+r[5]*i+r[9]*s,this.z=r[2]*e+r[6]*i+r[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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}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,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=s*a-r*o,this.y=r*n-i*a,this.z=i*o-s*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return K.copy(this).projectOnVector(t),this.sub(K)}reflect(t){return this.sub(K.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(O(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)}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}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,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,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}random(){return this.x=S(),this.y=S(),this.z=S(),this}randomDirection(){const t=S()*Math.PI*2,e=2*S()-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}H.prototype.isVector3=!0;const K=new H,tt=new Z,et=2e3,it=2001;class st{constructor(t,e,i,s,r,n,o,a,h,l,c,u,d,p,f,m){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,i,s,r,n,o,a,h,l,c,u,d,p,f,m)}extractPosition(t){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(t)}multiplyToArray(t,e,i){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(t){return this.makeRotationFromQuaternion(t)}set(t,e,i,s,r,n,o,a,h,l,c,u,d,p,f,m){const y=this.elements;return y[0]=t,y[4]=e,y[8]=i,y[12]=s,y[1]=r,y[5]=n,y[9]=o,y[13]=a,y[2]=h,y[6]=l,y[10]=c,y[14]=u,y[3]=d,y[7]=p,y[11]=f,y[15]=m,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 st).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 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){const e=this.elements,i=t.elements,s=1/rt.setFromMatrixColumn(t,0).length(),r=1/rt.setFromMatrixColumn(t,1).length(),n=1/rt.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]*r,e[5]=i[5]*r,e[6]=i[6]*r,e[7]=0,e[8]=i[8]*n,e[9]=i[9]*n,e[10]=i[10]*n,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,r=t.z,n=Math.cos(i),o=Math.sin(i),a=Math.cos(s),h=Math.sin(s),l=Math.cos(r),c=Math.sin(r);if("XYZ"===t.order){const t=n*l,i=n*c,s=o*l,r=o*c;e[0]=a*l,e[4]=-a*c,e[8]=h,e[1]=i+s*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=s+i*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*l,i=a*c,s=h*l,r=h*c;e[0]=t+r*o,e[4]=s*o-i,e[8]=n*h,e[1]=n*c,e[5]=n*l,e[9]=-o,e[2]=i*o-s,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*l,i=a*c,s=h*l,r=h*c;e[0]=t-r*o,e[4]=-n*c,e[8]=s+i*o,e[1]=i+s*o,e[5]=n*l,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*l,i=n*c,s=o*l,r=o*c;e[0]=a*l,e[4]=s*h-i,e[8]=t*h+r,e[1]=a*c,e[5]=r*h+t,e[9]=i*h-s,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,i=n*h,s=o*a,r=o*h;e[0]=a*l,e[4]=r-t*c,e[8]=s*c+i,e[1]=c,e[5]=n*l,e[9]=-o*l,e[2]=-h*l,e[6]=i*c+s,e[10]=t-r*c}else if("XZY"===t.order){const t=n*a,i=n*h,s=o*a,r=o*h;e[0]=a*l,e[4]=-c,e[8]=h*l,e[1]=t*c+r,e[5]=n*l,e[9]=i*c-s,e[2]=s*c-i,e[6]=o*l,e[10]=r*c+t}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(ot,t,at)}lookAt(t,e,i){const s=this.elements;return ct.subVectors(t,e),0===ct.lengthSq()&&(ct.z=1),ct.normalize(),ht.crossVectors(i,ct),0===ht.lengthSq()&&(1===Math.abs(i.z)?ct.x+=1e-4:ct.z+=1e-4,ct.normalize(),ht.crossVectors(i,ct)),ht.normalize(),lt.crossVectors(ct,ht),s[0]=ht.x,s[4]=lt.x,s[8]=ct.x,s[1]=ht.y,s[5]=lt.y,s[9]=ct.y,s[2]=ht.z,s[6]=lt.z,s[10]=ct.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,r=this.elements,n=i[0],o=i[4],a=i[8],h=i[12],l=i[1],c=i[5],u=i[9],d=i[13],p=i[2],f=i[6],m=i[10],y=i[14],v=i[3],g=i[7],x=i[11],S=i[15],w=s[0],b=s[4],z=s[8],M=s[12],_=s[1],P=s[5],T=s[9],V=s[13],O=s[2],C=s[6],F=s[10],B=s[14],A=s[3],$=s[7],I=s[11],E=s[15];return r[0]=n*w+o*_+a*O+h*A,r[4]=n*b+o*P+a*C+h*$,r[8]=n*z+o*T+a*F+h*I,r[12]=n*M+o*V+a*B+h*E,r[1]=l*w+c*_+u*O+d*A,r[5]=l*b+c*P+u*C+d*$,r[9]=l*z+c*T+u*F+d*I,r[13]=l*M+c*V+u*B+d*E,r[2]=p*w+f*_+m*O+y*A,r[6]=p*b+f*P+m*C+y*$,r[10]=p*z+f*T+m*F+y*I,r[14]=p*M+f*V+m*B+y*E,r[3]=v*w+g*_+x*O+S*A,r[7]=v*b+g*P+x*C+S*$,r[11]=v*z+g*T+x*F+S*I,r[15]=v*M+g*V+x*B+S*E,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],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],l=t[2],c=t[6],u=t[10],d=t[14];return t[3]*(+r*a*c-s*h*c-r*o*u+i*h*u+s*o*d-i*a*d)+t[7]*(+e*a*d-e*h*u+r*n*u-s*n*d+s*h*l-r*a*l)+t[11]*(+e*h*c-e*o*d-r*n*c+i*n*d+r*o*l-i*h*l)+t[15]*(-s*o*l-e*a*c+e*o*u+s*n*c-i*n*u+i*a*l)}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],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=t[9],u=t[10],d=t[11],p=t[12],f=t[13],m=t[14],y=t[15],v=c*m*h-f*u*h+f*a*d-o*m*d-c*a*y+o*u*y,g=p*u*h-l*m*h-p*a*d+n*m*d+l*a*y-n*u*y,x=l*f*h-p*c*h+p*o*d-n*f*d-l*o*y+n*c*y,S=p*c*a-l*f*a-p*o*u+n*f*u+l*o*m-n*c*m,w=e*v+i*g+s*x+r*S;if(0===w)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const b=1/w;return t[0]=v*b,t[1]=(f*u*r-c*m*r-f*s*d+i*m*d+c*s*y-i*u*y)*b,t[2]=(o*m*r-f*a*r+f*s*h-i*m*h-o*s*y+i*a*y)*b,t[3]=(c*a*r-o*u*r-c*s*h+i*u*h+o*s*d-i*a*d)*b,t[4]=g*b,t[5]=(l*m*r-p*u*r+p*s*d-e*m*d-l*s*y+e*u*y)*b,t[6]=(p*a*r-n*m*r-p*s*h+e*m*h+n*s*y-e*a*y)*b,t[7]=(n*u*r-l*a*r+l*s*h-e*u*h-n*s*d+e*a*d)*b,t[8]=x*b,t[9]=(p*c*r-l*f*r-p*i*d+e*f*d+l*i*y-e*c*y)*b,t[10]=(n*f*r-p*o*r+p*i*h-e*f*h-n*i*y+e*o*y)*b,t[11]=(l*o*r-n*c*r-l*i*h+e*c*h+n*i*d-e*o*d)*b,t[12]=S*b,t[13]=(l*f*s-p*c*s+p*i*u-e*f*u-l*i*m+e*c*m)*b,t[14]=(p*o*s-n*f*s-p*i*a+e*f*a+n*i*m-e*o*m)*b,t[15]=(n*c*s-l*o*s+l*i*a-e*c*a-n*i*u+e*o*u)*b,this}scale(t){const e=this.elements,i=t.x,s=t.y,r=t.z;return e[0]*=i,e[4]*=s,e[8]*=r,e[1]*=i,e[5]*=s,e[9]*=r,e[2]*=i,e[6]*=s,e[10]*=r,e[3]*=i,e[7]*=s,e[11]*=r,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),r=1-i,n=t.x,o=t.y,a=t.z,h=r*n,l=r*o;return this.set(h*n+i,h*o-s*a,h*a+s*o,0,h*o+s*a,l*o+i,l*a-s*n,0,h*a-s*o,l*a+s*n,r*a*a+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,r,n){return this.set(1,i,r,0,t,1,n,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,l=n+n,c=o+o,u=r*h,d=r*l,p=r*c,f=n*l,m=n*c,y=o*c,v=a*h,g=a*l,x=a*c,S=i.x,w=i.y,b=i.z;return s[0]=(1-(f+y))*S,s[1]=(d+x)*S,s[2]=(p-g)*S,s[3]=0,s[4]=(d-x)*w,s[5]=(1-(u+y))*w,s[6]=(m+v)*w,s[7]=0,s[8]=(p+g)*b,s[9]=(m-v)*b,s[10]=(1-(u+f))*b,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;let r=rt.set(s[0],s[1],s[2]).length();const n=rt.set(s[4],s[5],s[6]).length(),o=rt.set(s[8],s[9],s[10]).length();this.determinant()<0&&(r=-r),t.x=s[12],t.y=s[13],t.z=s[14],nt.copy(this);const a=1/r,h=1/n,l=1/o;return nt.elements[0]*=a,nt.elements[1]*=a,nt.elements[2]*=a,nt.elements[4]*=h,nt.elements[5]*=h,nt.elements[6]*=h,nt.elements[8]*=l,nt.elements[9]*=l,nt.elements[10]*=l,e.setFromRotationMatrix(nt),i.x=r,i.y=n,i.z=o,this}makePerspective(t,e,i,s,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),l=2*r/(i-s),c=(e+t)/(e-t),u=(i+s)/(i-s);let d,p;if(o===et)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==it)throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=c,a[12]=0,a[1]=0,a[5]=l,a[9]=u,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,i,s,r,n,o=2e3){const a=this.elements,h=1/(e-t),l=1/(i-s),c=1/(n-r),u=(e+t)*h,d=(i+s)*l;let p,f;if(o===et)p=(n+r)*c,f=-2*c;else{if(o!==it)throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*c,f=-1*c}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-u,a[1]=0,a[5]=2*l,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=f,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<16;t++)if(e[t]!==i[t])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}}st.prototype.isMatrix4=!0;const rt=new H,nt=new st,ot=new H(0,0,0),at=new H(1,1,1),ht=new H,lt=new H,ct=new H,ut=new st,dt=new Z;class pt{constructor(t=0,e=0,i=0,s=pt.DEFAULT_ORDER){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 pt(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,r=s[0],n=s[4],o=s[8],a=s[1],h=s[5],l=s[9],c=s[2],u=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(O(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,h),this._z=0);break;case"YXZ":this._x=Math.asin(-O(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-c,r),this._z=0);break;case"ZXY":this._x=Math.asin(O(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-O(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(O(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-c,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-O(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,d),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===i&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ut.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ut,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return dt.setFromEuler(this),this.setFromQuaternion(dt,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],void 0!==t[3]&&(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(t){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}pt.DEFAULT_ORDER="XYZ",pt.prototype.isEuler=!0;class ft{constructor(t,e,i,s,r,n,o,a,h){this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,i,s,r,n,o,a,h)}set(t,e,i,s,r,n,o,a,h){const l=this.elements;return l[0]=t,l[1]=s,l[2]=o,l[3]=e,l[4]=r,l[5]=a,l[6]=i,l[7]=n,l[8]=h,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,r=this.elements,n=i[0],o=i[3],a=i[6],h=i[1],l=i[4],c=i[7],u=i[2],d=i[5],p=i[8],f=s[0],m=s[3],y=s[6],v=s[1],g=s[4],x=s[7],S=s[2],w=s[5],b=s[8];return r[0]=n*f+o*v+a*S,r[3]=n*m+o*g+a*w,r[6]=n*y+o*x+a*b,r[1]=h*f+l*v+c*S,r[4]=h*m+l*g+c*w,r[7]=h*y+l*x+c*b,r[2]=u*f+d*v+p*S,r[5]=u*m+d*g+p*w,r[8]=u*y+d*x+p*b,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],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8];return e*n*l-e*o*h-i*r*l+i*o*a+s*r*h-s*n*a}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=l*n-o*h,u=o*a-l*r,d=h*r-n*a,p=e*c+i*u+s*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=c*f,t[1]=(s*h-l*i)*f,t[2]=(o*i-s*n)*f,t[3]=u*f,t[4]=(l*e-s*a)*f,t[5]=(s*r-o*e)*f,t[6]=d*f,t[7]=(i*a-h*e)*f,t[8]=(n*e-i*r)*f,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,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(i*a,i*h,-i*(a*n+h*o)+n+t,-s*h,s*a,-s*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(mt.makeScale(t,e)),this}rotate(t){return this.premultiply(mt.makeRotation(-t)),this}translate(t,e){return this.premultiply(mt.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 t=0;t<9;t++)if(e[t]!==i[t])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 ft).fromArray(this.elements)}}ft.prototype.isMatrix3=!0;const mt=new ft,yt=new Float32Array(4);class vt extends Z{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const gt=vt.prototype;gt.data=yt,gt.offset=0,Object.defineProperties(vt.prototype,{_x:{get(){return this.data[this.offset]},set(t){this.data[this.offset]=t}},_y:{get(){return this.data[this.offset+1]},set(t){this.data[this.offset+1]=t}},_z:{get(){return this.data[this.offset+2]},set(t){this.data[this.offset+2]=t}},_w:{get(){return this.data[this.offset+3]},set(t){this.data[this.offset+3]=t}}});class xt{constructor(t=0,e=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 xt(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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}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(0===e)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(O(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}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*i-n*s+t.x,this.y=r*s+n*i+t.y,this}random(){return this.x=S(),this.y=S(),this}*[Symbol.iterator](){yield this.x,yield this.y}}xt.isVector2=!0;const St=new Float32Array(3);class wt extends H{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const bt=wt.prototype;bt.data=St,bt.offset=0,Object.defineProperties(wt.prototype,{x:{get(){return this.data[this.offset]},set(t){this.data[this.offset]=t}},y:{get(){return this.data[this.offset+1]},set(t){this.data[this.offset+1]=t}},z:{get(){return this.data[this.offset+2]},set(t){this.data[this.offset+2]=t}}});class zt{constructor(t=0,e=0,i=0,s=1){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 zt(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}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,r=this.w,n=t.elements;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.w=n[3]*e+n[7]*i+n[11]*s+n[15]*r,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,r;const n=.01,o=.1,a=t.elements,h=a[0],l=a[4],c=a[8],u=a[1],d=a[5],p=a[9],f=a[2],m=a[6],y=a[10];if(Math.abs(l-u)<n&&Math.abs(c-f)<n&&Math.abs(p-m)<n){if(Math.abs(l+u)<o&&Math.abs(c+f)<o&&Math.abs(p+m)<o&&Math.abs(h+d+y-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,v=(y+1)/2,g=(l+u)/4,x=(c+f)/4,S=(p+m)/4;return t>a&&t>v?t<n?(i=0,s=.707106781,r=.707106781):(i=Math.sqrt(t),s=g/i,r=x/i):a>v?a<n?(i=.707106781,s=0,r=.707106781):(s=Math.sqrt(a),i=g/s,r=S/s):v<n?(i=.707106781,s=.707106781,r=0):(r=Math.sqrt(v),i=x/r,s=S/r),this.set(i,s,r,e),this}let v=Math.sqrt((m-p)*(m-p)+(c-f)*(c-f)+(u-l)*(u-l));return Math.abs(v)<.001&&(v=1),this.x=(m-p)/v,this.y=(c-f)/v,this.z=(u-l)/v,this.w=Math.acos((h+d+y-1)/2),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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}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}random(){return this.x=S(),this.y=S(),this.z=S(),this.w=S(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}zt.prototype.isVector4=!0;const Mt=new Float32Array(4);class _t extends zt{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const Pt=_t.prototype;let Tt;function Vt(){return Tt}Pt.data=Mt,Pt.offset=0,Object.defineProperties(_t.prototype,{x:{get(){return this.data[this.offset]},set(t){this.data[this.offset]=t}},y:{get(){return this.data[this.offset+1]},set(t){this.data[this.offset+1]=t}},z:{get(){return this.data[this.offset+2]},set(t){this.data[this.offset+2]=t}},w:{get(){return this.data[this.offset+3]},set(t){this.data[this.offset+3]=t}}});class Ot{constructor(t,e){this.resolver=t,this.bounce=e,this.type="ApplyCollision",this.tempV=new H}initialize(t){}update(t,e){this.resolver&&this.resolver.resolve(t.position,this.tempV)&&t.velocity.reflect(this.tempV).multiplyScalar(this.bounce)}frameUpdate(t){}toJSON(){return{type:this.type,bounce:this.bounce}}static fromJSON(t){return new Ot(Vt(),t.bounce)}clone(){return new Ot(this.resolver,this.bounce)}reset(){}}class Ct{constructor(t){this.value=t,this.type="value"}startGen(t){}genValue(t){return this.value}toJSON(){return{type:"ConstantValue",value:this.value}}static fromJSON(t){return new Ct(t.value)}clone(){return new Ct(this.value)}}class Ft{constructor(t,e){this.a=t,this.b=e,this.indexCount=-1,this.type="value"}startGen(t){this.indexCount=t.length,t.push(S())}genValue(t){return-1===this.indexCount&&this.startGen(t),X.lerp(this.a,this.b,t[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(t){return new Ft(t.a,t.b)}clone(){return new Ft(this.a,this.b)}}class Bt{constructor(t,e,i,s){this.p=[t,e,i,s]}genValue(t){const e=this.p,i=t*t,s=1-t,r=s*s;return e[0]*r*s+e[1]*r*t*3+e[2]*s*i*3+e[3]*i*t}derivativeCoefficients(t){const e=[];for(let i=t,s=i.length-1;s>0;s--){const t=[];for(let e=0;e<s;e++){const r=s*(i[e+1]-i[e]);t.push(r)}e.push(t),i=t}return e}getSlope(t){const e=this.derivativeCoefficients(this.p)[0],i=1-t,s=i*t*2,r=t*t;return i*i*e[0]+s*e[1]+r*e[2]}controlCurve(t,e){this.p[1]=t/3+this.p[0],this.p[2]=this.p[3]-e/3}hull(t){let e,i=this.p,s=[],r=0,n=0,o=0;const a=[];for(a[r++]=i[0],a[r++]=i[1],a[r++]=i[2],a[r++]=i[3];i.length>1;){for(s=[],n=0,o=i.length-1;n<o;n++)e=t*i[n]+(1-t)*i[n+1],a[r++]=e,s.push(e);i=s}return a}split(t){const e=this.hull(t);return{left:new Bt(e[0],e[4],e[7],e[9]),right:new Bt(e[9],e[8],e[6],e[3]),span:e}}clone(){return new Bt(this.p[0],this.p[1],this.p[2],this.p[3])}toJSON(){return{p0:this.p[0],p1:this.p[1],p2:this.p[2],p3:this.p[3]}}static fromJSON(t){return new Bt(t.p0,t.p1,t.p2,t.p3)}}class At{constructor(){this.functions=new Array}findFunction(t){const e=this.functions,i=e.length-1;if(i<=0)return 0===i&&t>=e[0][1]&&t<=1?0:-1;let s=0,r=i;for(;s+1<r;){const i=s+r>>1;if(t<e[i][1])r=i-1;else{if(!(t>this.getEndX(i)))return i;s=i+1}}for(let i=s;i<=r;i++)if(t>=e[i][1]&&t<=this.getEndX(i))return i;return-1}getStartX(t){return this.functions[t][1]}setStartX(t,e){t>0&&(this.functions[t][1]=e)}getEndX(t){return t+1<this.functions.length?this.functions[t+1][1]:1}setEndX(t,e){t+1<this.functions.length&&(this.functions[t+1][1]=e)}insertFunction(t,e){const i=this.findFunction(t);this.functions.splice(i+1,0,[e,t])}removeFunction(t){return this.functions.splice(t,1)[0][0]}getFunction(t){return this.functions[t][0]}setFunction(t,e){this.functions[t][0]=e}get numOfFunctions(){return this.functions.length}}class $t extends At{constructor(t=[[new Bt(0,1/3,1/3*2,1),0]]){super(),this.table=null,this.tableSignature=null,this.type="function",this.functions=t}refreshTable(){const t=this.functions,e=t.length;if(0===e)return this.table=null,void(this.tableSignature=null);const i=5*e;let s=this.tableSignature,r=null===s||s.length!==i;r&&(s=new Float64Array(i));for(let i=0,n=0;i<e;i++,n+=5){const e=t[i][0].p,o=t[i][1];r||(r=s[n]!==e[0]||s[n+1]!==e[1]||s[n+2]!==e[2]||s[n+3]!==e[3]||s[n+4]!==o),r&&(s[n]=e[0],s[n+1]=e[1],s[n+2]=e[2],s[n+3]=e[3],s[n+4]=o)}if(!r&&null!==this.table)return;this.tableSignature=s;const n=$t.TABLE_SIZE,o=null!==this.table&&this.table.length===n?this.table:new Float32Array(n),a=1/(n-1);for(let t=0;t<n;t++)o[t]=this.genValueExact(t*a);this.table=o}sampledTable(){return this.table}clearTable(){this.table=null,this.tableSignature=null}genValue(t,e=0){const i=this.table;if(null!==i){const t=i.length-1;if(e<=0)return i[0];if(e>=1)return i[t];const s=e*t,r=0|s,n=s-r,o=i[r];return o+(i[r+1]-o)*n}return this.genValueExact(e)}genValueExact(t){const e=this.functions,i=e.length;if(0===i)return 0;const s=this.findFunction(t);if(-1===s)return t<e[0][1]?e[0][0].genValue(0):e[i-1][0].genValue(1);const r=e[s][1],n=(s+1<i?e[s+1][1]:1)-r;return e[s][0].genValue(n>0?(t-r)/n:0)}toSVG(t,e){if(e<1)return"";let i=["M",0,this.functions[0][0].p[0]].join(" ");for(let s=1/e;s<=1;s+=1/e)i=[i,"L",s*t,this.genValue(void 0,s)].join(" ");return i}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([t,e])=>({function:t.toJSON(),start:e}))}}static fromJSON(t){return new $t(t.functions.map(t=>[Bt.fromJSON(t.function),t.start]))}clone(){return new $t(this.functions.map(([t,e])=>[t.clone(),e]))}startGen(t){}}function It(t){switch(t.type){case"ConstantValue":return Ct.fromJSON(t);case"IntervalValue":return Ft.fromJSON(t);case"PiecewiseBezier":return $t.fromJSON(t);default:return new Ct(0)}}$t.TABLE_SIZE=257;class Et{constructor(t,e){this.axis=t,this.angle=e,this.type="rotation"}startGen(t){this.angle.startGen(t)}genValue(t,e,i,s){return e.setFromAxisAngle(this.axis,this.angle.genValue(t,s)*i)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(t){return new Et(new H(t.axis.x,t.axis.y,t.axis.z),It(t.angle))}clone(){return new Et(this.axis.clone(),this.angle.clone())}}const Nt=t=>({r:t.x,g:t.y,b:t.z,a:t.w}),Lt=t=>new zt(t.r,t.g,t.b,t.a),Rt=(t,e)=>{switch(e){case"Vector3":return new H(t.x,t.y,t.z);case"Vector4":return new zt(t.x,t.y,t.z,t.w);case"Color":return new H(t.r,t.g,t.b);default:return t}},Dt=(t,e)=>{switch(e){case"Vector3":return{x:t.x,y:t.y,z:t.z};case"Vector4":return{x:t.x,y:t.y,z:t.z,w:t.w};case"Color":return{r:t.x,g:t.y,b:t.z};default:return t}};class Ut{constructor(t,e){this.a=t,this.b=e,this.indexCount=-1,this.type="value"}startGen(t){this.indexCount=t.length,t.push(S())}genColor(t,e){return-1===this.indexCount&&this.startGen(t),e.copy(this.a).lerp(this.b,t[this.indexCount])}toJSON(){return{type:"ColorRange",a:Nt(this.a),b:Nt(this.b)}}static fromJSON(t){return new Ut(Lt(t.a),Lt(t.b))}clone(){return new Ut(this.a.clone(),this.b.clone())}}class qt{constructor(t,e){this.subType=e,this.type="function",this.keys=t}findKey(t){const e=this.keys,i=e.length-1;if(i<=0)return 0===i&&t>=e[0][1]&&t<=1?0:-1;if(1===i)return t<e[0][1]||t>1?-1:t<=e[1][1]?0:1;let s=0,r=i;for(;s+1<r;){const i=s+r>>1;if(t<e[i][1])r=i-1;else{if(!(t>this.getEndX(i)))return i;s=i+1}}for(let i=s;i<=r;i++)if(t>=e[i][1]&&t<=this.getEndX(i))return i;return-1}getStartX(t){return this.keys[t][1]}getEndX(t){return t+1<this.keys.length?this.keys[t+1][1]:1}genValue(t,e){const i=this.keys,s=this.findKey(e),r=i.length-1;if("Number"===this.subType){if(-1===s)return i[0][0];if(s>=r)return i[r][0];const t=i[s][1],n=i[s][0],o=i[s+1][1]-t;return(i[s+1][0]-n)*(o>0?(e-t)/o:0)+n}{if(-1===s)return t.copy(i[0][0]);if(s>=r)return t.copy(i[r][0]);const n=i[s][1],o=i[s+1][1]-n;return t.copy(i[s][0]).lerp(i[s+1][0],o>0?(e-n)/o:0)}}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([t,e])=>({value:Dt(t,this.subType),pos:e}))}}static fromJSON(t){return new qt(t.keys.map(e=>[Rt(e.value,t.subType),e.pos]),t.subType)}clone(){return"Number"===this.subType?new qt(this.keys.map(([t,e])=>[t,e]),this.subType):new qt(this.keys.map(([t,e])=>[t.clone(),e]),this.subType)}}const kt=new zt;class Jt{constructor(t=[[new H(0,0,0),0],[new H(1,1,1),0]],e=[[1,0],[1,1]]){this.table=null,this.tableSignature=null,this.type="function",this.color=new qt(t,"Color"),this.alpha=new qt(e,"Number")}refreshTable(){const t=this.color.keys,e=this.alpha.keys,i=4*t.length+2*e.length;let s=this.tableSignature,r=null===s||s.length!==i;r&&(s=new Float64Array(i));let n=0;for(let e=0;e<t.length;e++,n+=4){const i=t[e][0],o=t[e][1];r||(r=s[n]!==i.x||s[n+1]!==i.y||s[n+2]!==i.z||s[n+3]!==o),r&&(s[n]=i.x,s[n+1]=i.y,s[n+2]=i.z,s[n+3]=o)}for(let t=0;t<e.length;t++,n+=2){const i=e[t][0],o=e[t][1];r||(r=s[n]!==i||s[n+1]!==o),r&&(s[n]=i,s[n+1]=o)}if(!r&&null!==this.table)return;this.tableSignature=s;const o=Jt.TABLE_SIZE,a=null!==this.table&&this.table.length===4*o?this.table:new Float32Array(4*o),h=1/(o-1),l=kt;for(let t=0;t<o;t++){this.genColorExact(l,t*h);const e=4*t;a[e]=l.x,a[e+1]=l.y,a[e+2]=l.z,a[e+3]=l.w}this.table=a}sampledTable(){return this.table}clearTable(){this.table=null,this.tableSignature=null}genColor(t,e,i){const s=this.table;if(null!==s){const t=Jt.TABLE_SIZE-1;if(i<=0)return e.x=s[0],e.y=s[1],e.z=s[2],e.w=s[3],e;if(i>=1){const i=4*t;return e.x=s[i],e.y=s[i+1],e.z=s[i+2],e.w=s[i+3],e}const r=i*t,n=0|r,o=r-n,a=4*n,h=a+4;return e.x=s[a]+(s[h]-s[a])*o,e.y=s[a+1]+(s[h+1]-s[a+1])*o,e.z=s[a+2]+(s[h+2]-s[a+2])*o,e.w=s[a+3]+(s[h+3]-s[a+3])*o,e}return this.genColorExact(e,i)}genColorExact(t,e){const i=this.color.keys,s=i.length-1,r=this.color.findKey(e);let n,o,a;if(-1===r||r>=s){const t=i[-1===r?0:s][0];n=t.x,o=t.y,a=t.z}else{const t=i[r][0],s=i[r+1][0],h=i[r][1],l=i[r+1][1]-h,c=l>0?(e-h)/l:0;n=t.x+(s.x-t.x)*c,o=t.y+(s.y-t.y)*c,a=t.z+(s.z-t.z)*c}const h=this.alpha.keys,l=h.length-1,c=this.alpha.findKey(e);let u;if(-1===c||c>=l)u=h[-1===c?0:l][0];else{const t=h[c][1],i=h[c][0],s=h[c+1][1]-t;u=i+(h[c+1][0]-i)*(s>0?(e-t)/s:0)}return t.x=n,t.y=o,t.z=a,t.w=u,t}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(t){if(t.functions){const e=t.functions.map(t=>[Ut.fromJSON(t.function).a,t.start]);return t.functions.length>0&&e.push([Ut.fromJSON(t.functions[t.functions.length-1].function).b,1]),new Jt(e.map(t=>[new H(t[0].x,t[0].y,t[0].z),t[1]]),e.map(t=>[t[0].w,t[1]]))}{const e=new Jt;return e.alpha=qt.fromJSON(t.alpha),e.color=qt.fromJSON(t.color),e}}clone(){const t=new Jt;return t.alpha=this.alpha.clone(),t.color=this.color.clone(),t}startGen(t){}}Jt.TABLE_SIZE=257;class Qt{constructor(t,e){this.a=t,this.b=e,this.type="value"}startGen(t){}genColor(t,e){const i=S();return e.copy(this.a).lerp(this.b,i)}toJSON(){return{type:"RandomColor",a:Nt(this.a),b:Nt(this.b)}}static fromJSON(t){return new Qt(Lt(t.a),Lt(t.b))}clone(){return new Qt(this.a.clone(),this.b.clone())}}const Gt=new zt;class Wt{constructor(t,e){this.indexCount=0,this.type="function",this.gradient1=t,this.gradient2=e}startGen(t){this.indexCount=t.length,t.push(S())}genColor(t,e,i){return this.gradient1.genColor(t,e,i),this.gradient2.genColor(t,Gt,i),t&&void 0!==t[this.indexCount]?e.lerp(Gt,t[this.indexCount]):e.lerp(Gt,S()),e}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(t){return new Wt(Jt.fromJSON(t.gradient1),Jt.fromJSON(t.gradient2))}clone(){return new Wt(this.gradient1.clone(),this.gradient2.clone())}}class jt{constructor(t){this.color=t,this.type="value"}startGen(t){}genColor(t,e){return e.copy(this.color)}toJSON(){return{type:"ConstantColor",color:Nt(this.color)}}static fromJSON(t){return new jt(Lt(t.color))}clone(){return new jt(this.color.clone())}}function Yt(t){switch(t.type){case"ConstantColor":return jt.fromJSON(t);case"ColorRange":return Ut.fromJSON(t);case"RandomColor":return Qt.fromJSON(t);case"Gradient":return Jt.fromJSON(t);case"RandomColorBetweenGradient":return Wt.fromJSON(t);default:return new jt(new zt(1,1,1,1))}}class Xt{constructor(t,e,i,s){this.angleX=t,this.angleY=e,this.angleZ=i,this.type="rotation",this.eular=new pt(0,0,0,s)}startGen(t){this.angleX.startGen(t),this.angleY.startGen(t),this.angleZ.startGen(t)}genValue(t,e,i,s){return this.eular.set(this.angleX.genValue(t,s)*i,this.angleY.genValue(t,s)*i,this.angleZ.genValue(t,s)*i),e.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(t){return new Xt(It(t.angleX),It(t.angleY),It(t.angleZ),t.eulerOrder)}clone(){return new Xt(this.angleX,this.angleY,this.angleZ,this.eular.order)}}class Zt{constructor(){this.indexCount=0,this.type="rotation"}startGen(t){let e,i,s,r,n,o;this.indexCount=t.length;do{e=2*S()-1,i=2*S()-1,s=e*e+i*i}while(s>1);do{r=2*S()-1,n=2*S()-1,o=r*r+n*n}while(o>1);const a=Math.sqrt((1-s)/o);t.push(e,i,a*r,a*n)}genValue(t,e,i,s){-1===this.indexCount&&this.startGen(t);const r=this.indexCount;return e.set(t[r],t[r+1],t[r+2],t[r+3]),e}toJSON(){return{type:"RandomQuat"}}static fromJSON(t){return new Zt}clone(){return new Zt}}function Ht(t){switch(t.type){case"AxisAngle":return Et.fromJSON(t);case"Euler":return Xt.fromJSON(t);case"RandomQuat":return Zt.fromJSON(t);default:return new Zt}}class Kt{constructor(t,e,i){this.x=t,this.y=e,this.z=i,this.type="vec3function"}startGen(t){this.x.startGen(t),this.y.startGen(t),this.z.startGen(t)}genValue(t,e,i){return e.set(this.x.genValue(t,i),this.y.genValue(t,i),this.z.genValue(t,i))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(t){return new Kt(It(t.x),It(t.y),It(t.z))}clone(){return new Kt(this.x,this.y,this.z)}}function te(t){return"Vector3Function"===t.type?Kt.fromJSON(t):new Kt(new Ct(0),new Ct(0),new Ct(0))}function ee(t){switch(t.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return It(t);case"AxisAngle":case"RandomQuat":case"Euler":return Ht(t);case"Vector3Function":return te(t);default:return new Ct(0)}}class ie{constructor(t,e){this.direction=t,this.magnitude=e,this.type="ApplyForce",this.memory={data:[],dataCount:0},this.magnitudeValue=this.magnitude.genValue(this.memory)}initialize(t){}update(t,e){const i=this.magnitudeValue*e,s=this.direction,r=t.velocity;r.x+=s.x*i,r.y+=s.y*i,r.z+=s.z*i}updateAll(t,e,i){const s=this.magnitudeValue*i,r=this.direction.x*s,n=this.direction.y*s,o=this.direction.z*s;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const s=e.velocity;s.x+=r,s.y+=n,s.z+=o}}frameUpdate(t){this.magnitudeValue=this.magnitude.genValue(this.memory)}toJSON(){return{type:this.type,direction:[this.direction.x,this.direction.y,this.direction.z],magnitude:this.magnitude.toJSON()}}static fromJSON(t){return new ie(new H(t.direction[0],t.direction[1],t.direction[2]),It(t.magnitude??t.force))}clone(){return new ie(this.direction.clone(),this.magnitude.clone())}reset(){}}class se{constructor(t=0,e=0,i=new H){this.scaleX=t,this.scaleY=e,this.position=i,this.locations=[]}transform(t,e){t.x=this.locations[e%this.locations.length].x*this.scaleX+this.position.x,t.y=this.locations[e%this.locations.length].y*this.scaleY+this.position.y,t.z=this.position.z}static fromJSON(t){const e=new se(t.scaleX,t.scaleY,new H(t.position[0],t.position[1],t.position[2]));return e.locations=t.locations.map(t=>new xt(t.x,t.y)),e}clone(){const t=new se(this.scaleX,this.scaleY,this.position.clone());return t.locations=this.locations.map(t=>t.clone()),t}toJSON(){return{scaleX:this.scaleX,scaleY:this.scaleY,position:this.position,locations:this.locations.map(t=>({x:t.x,y:t.y}))}}fromImage(t,e){const i=document.createElement("canvas");i.width=t.width,i.height=t.height;const s=i.getContext("2d");if(!s)return;s.drawImage(t,0,0);const r=s.getImageData(0,0,i.width,i.height,{colorSpace:"srgb"});i.remove(),this.locations.length=0;for(let t=0;t<r.height;t++)for(let i=0;i<r.width;i++)r.data[4*(t*r.width+i)+3]>e&&this.locations.push(new xt(i,r.height-t))}}function re(t){return"TextureSequencer"===t.type?se.fromJSON(t):new se}class ne{constructor(t){this.type="ApplySequences",this.sequencers=[],this.time=0,this.index=0,this.pCount=0,this.tempV=new H,this.delay=t}initialize(t){t.id=this.pCount,t.dst=new H,t.begin=new H,t.inMotion=!1,this.pCount++}reset(){this.time=0,this.index=0,this.pCount=0}update(t,e){const i=this.sequencers[this.index];if(void 0===i)return;const s=t.id*this.delay;this.time>=i[0].a+s&&this.time<=i[0].b+s?(t.inMotion||(t.inMotion=!0,t.begin.copy(t.position),i[1].transform(t.dst,t.id)),t.position.lerpVectors(t.begin,t.dst,ne.BEZIER.genValue((this.time-i[0].a-s)/(i[0].b-i[0].a)))):this.time>i[0].b+s&&(t.inMotion=!1)}frameUpdate(t){for(;this.index+1<this.sequencers.length&&this.time>=this.sequencers[this.index+1][0].a;)this.index++;this.time+=t}appendSequencer(t,e){this.sequencers.push([t,e])}toJSON(){return{type:this.type,delay:this.delay,sequencers:this.sequencers.map(([t,e])=>({range:t.toJSON(),sequencer:e.toJSON()}))}}static fromJSON(t){const e=new ne(t.delay);return t.sequencers.forEach(t=>{e.sequencers.push([It(t.range),re(t.sequencer)])}),e}clone(){const t=new ne(this.delay);return t.sequencers=this.sequencers.map(t=>[t[0].clone(),t[1].clone()]),t}}ne.BEZIER=new Bt(0,0,1,1);class oe{constructor(t){this.angle=t,this.type="ChangeEmitDirection",this._temp=new H,this._q=new Z,this.memory={data:[],dataCount:0}}initialize(t){const e=t.velocity.length();0!=e&&(t.velocity.normalize(),0===t.velocity.x&&0===t.velocity.y?this._temp.set(0,t.velocity.z,0):this._temp.set(-t.velocity.y,t.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(t.velocity),t.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,S()*Math.PI*2),t.velocity.applyQuaternion(this._q),t.velocity.setLength(e))}update(t,e){}frameUpdate(t){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(t){return new oe(It(t.angle))}clone(){return new oe(this.angle)}reset(){}}class ae{constructor(t,e){this.color=t,this.speedRange=e,this.type="ColorBySpeed"}initialize(t){this.color.startGen(t.memory)}update(t,e){const i=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(t.memory,t.color,i),t.color.x*=t.startColor.x,t.color.y*=t.startColor.y,t.color.z*=t.startColor.z,t.color.w*=t.startColor.w}frameUpdate(t){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new ae(Yt(t.color),Ft.fromJSON(t.speedRange))}clone(){return new ae(this.color.clone(),this.speedRange.clone())}reset(){}}class he{constructor(t){this.color=t,this.type="ColorOverLife"}initialize(t){this.color.startGen(t.memory)}update(t,e){const i=t.color,s=t.startColor;this.color.genColor(t.memory,i,t.age/t.life),i.x*=s.x,i.y*=s.y,i.z*=s.z,i.w*=s.w}updateAll(t,e,i){const s=this.color;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const r=e.color,n=e.startColor;s.genColor(e.memory,r,e.age/e.life),r.x*=n.x,r.y*=n.y,r.z*=n.z,r.w*=n.w}}frameUpdate(t){this.color.refreshTable?.()}toJSON(){return{type:this.type,color:this.color.toJSON()}}static fromJSON(t){return new he(Yt(t.color))}clone(){return new he(this.color.clone())}reset(){}}function le(t,e){return Math.floor(S()*(e-t))+t}const ce=new H(0,1,0),ue=new H(0,0,0),de=new H(1,1,1),pe=new H(0,0,1);var fe;exports.SubParticleEmitMode=void 0,(fe=exports.SubParticleEmitMode||(exports.SubParticleEmitMode={}))[fe.Death=0]="Death",fe[fe.Birth=1]="Birth",fe[fe.Frame=2]="Frame";const me={color:1,size:2,rotation:4,lifetime:8};function ye(t){let e=0;for(const i of t)e|=me[i]??0;return e}class ve{constructor(t,e,i,s=exports.SubParticleEmitMode.Frame,r=1,n=[]){this.particleSystem=t,this.useVelocityAsBasis=e,this.subParticleSystem=i,this.mode=s,this.emitProbability=r,this.inherit=n,this.type="EmitSubParticleSystem",this.q_=new Z,this.v_=new H,this.v2_=new H,this.subEmissions=new Array,this.spareEmissions=new Array;const o=this.target;o&&(o.onlyUsedByOther=!0)}initialize(t){}update(t,e){(this.mode===exports.SubParticleEmitMode.Frame||this.mode===exports.SubParticleEmitMode.Birth&&0===t.age||this.mode===exports.SubParticleEmitMode.Death&&t.age+e>=t.life)&&this.emit(t,e)}get target(){const t=this.subParticleSystem;if(null!==t&&"object"==typeof t)return t.system}emit(t,e){if(!this.target)return;if(S()>this.emitProbability)return;const i=this.spareEmissions.pop(),s=void 0!==i?i:{burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:new st,travelDistance:0,particle:void 0,previousWorldPos:void 0};s.burstParticleCount=0,s.burstParticleIndex=0,s.isBursting=!1,s.burstIndex=0,s.burstWaveIndex=0,s.time=0,s.waitEmiting=0,s.travelDistance=0,s.particle=t,s.inherit=ye(this.inherit),s.previousWorldPos=void 0,this.setMatrixFromParticle(s.matrix,t),this.subEmissions.push(s)}frameUpdate(t){const e=this.target;if(e)for(let i=0;i<this.subEmissions.length;i++)if(this.subEmissions[i].time>=e.duration){const t=this.subEmissions[i];t.particle=void 0,this.spareEmissions.push(t),this.subEmissions[i]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,i--}else{const s=this.subEmissions[i];s.particle&&s.particle.age<s.particle.life?this.setMatrixFromParticle(s.matrix,s.particle):s.particle=void 0,e.emit(t,s,s.matrix)}else this.subEmissions.length=0}toJSON(){return{type:this.type,subParticleSystem:"string"==typeof this.subParticleSystem?this.subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability,...this.inherit.length>0?{inherit:this.inherit.slice()}:{}}}static fromJSON(t,e){return new ve(e,t.useVelocityAsBasis,t.subParticleSystem,t.mode,t.emitProbability,ve.validInherit(t.inherit))}clone(){return new ve(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability,this.inherit.slice())}reset(){}static validInherit(t){return Array.isArray(t)?t.filter(t=>t in me):[]}setMatrixFromParticle(t,e){let i;if(void 0===e.rotation||this.useVelocityAsBasis)if(0!==e.velocity.x||0!==e.velocity.y||1!==e.velocity.z&&0!==e.velocity.z){this.v_.copy(pe).cross(e.velocity),this.v2_.copy(e.velocity).cross(this.v_);const i=this.v_.length(),s=this.v2_.length();t.set(this.v_.x/i,this.v2_.x/s,e.velocity.x,e.position.x,this.v_.y/i,this.v2_.y/s,e.velocity.y,e.position.y,this.v_.z/i,this.v2_.z/s,e.velocity.z,e.position.z,0,0,0,1)}else t.set(1,0,0,e.position.x,0,1,0,e.position.y,0,0,1,e.position.z,0,0,0,1);else e.rotation instanceof Z?i=e.rotation:(this.q_.setFromAxisAngle(pe,e.rotation),i=this.q_),t.compose(e.position,i,de);this.particleSystem.worldSpace||t.multiplyMatrices(this.particleSystem.emitter.matrixWorld,t)}}class ge{initialize(t,e){this.ps=e,this.x.startGen(t.memory),this.y.startGen(t.memory),this.z.startGen(t.memory)}constructor(t,e,i){this.x=t,this.y=e,this.z=i,this.type="ForceOverLife",this._temp=new H,this._tempScale=new H,this._tempQ=new Z}update(t,e){this._temp.set(this.x.genValue(t.memory,t.age/t.life),this.y.genValue(t.memory,t.age/t.life),this.z.genValue(t.memory,t.age/t.life)),void 0===this.ps||this.ps.worldSpace||this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),t.velocity.addScaledVector(this._temp,e)}updateAll(t,e,i){const s=this.ps;if(void 0===s)return;const r=this._temp,n=this.x,o=this.y,a=this.z,h=s.worldSpace;for(let s=0;s<e;s++){const e=t[s];if(e.age>=e.life)continue;const l=e.memory,c=e.age/e.life;r.set(n.genValue(l,c),o.genValue(l,c),a.genValue(l,c)),h||r.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(r,i)}}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(t){return new ge(It(t.x),It(t.y),It(t.z))}frameUpdate(t){if(this.ps&&!this.ps.worldSpace){const t=this._temp,e=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,e,i),e.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new ge(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class xe{constructor(t){this.type="FrameOverLife",this.frame=t}get frame(){return this._frame}set frame(t){this._frame=t}initialize(t){this._frame.startGen(t.memory)}update(t,e){t.uvTile=this.sampleFrame(t,t.age/t.life)}updateAll(t,e,i){for(let i=0;i<e;i++){const e=t[i];e.age>=e.life||(e.uvTile=this.sampleFrame(e,e.age/e.life))}}sampleFrame(t,e){return"function"===this._frame.type?this._frame.genValue(t.memory,e):this._frame.genValue(t.memory)}frameUpdate(t){this._frame.refreshTable?.()}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(t){return new xe(It(t.frame))}clone(){return new xe(this.frame.clone())}reset(){}}class Se{constructor(t,e){this.center=t,this.magnitude=e,this.type="GravityForce",this.temp=new H}initialize(t){}update(t,e){const i=t.position.distanceToSquared(this.center);0!==i&&(this.temp.copy(this.center).sub(t.position).normalize(),t.velocity.addScaledVector(this.temp,this.magnitude/i*e))}updateAll(t,e,i){const s=this.center.x,r=this.center.y,n=this.center.z,o=this.magnitude*i;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const a=e.position,h=s-a.x,l=r-a.y,c=n-a.z,u=h*h+l*l+c*c;if(0===u)continue;const d=o/(u*Math.sqrt(u)),p=e.velocity;p.x+=h*d,p.y+=l*d,p.z+=c*d}}frameUpdate(t){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(t){return new Se(new H(t.center[0],t.center[1],t.center[2]),t.magnitude)}clone(){return new Se(this.center.clone(),this.magnitude)}reset(){}}class we{constructor(t=new Ct(1),e="initial"){this.multiplier=t,this.mode=e,this.type="InheritVelocity",this._temp=new H,this._tempPos=new H,this._tempQInv=new Z,this._tempScaleInv=new H(1,1,1)}initialize(t,e){this.ps=e,this.multiplier.startGen(t.memory),"initial"===this.mode&&e.emitterVelocity&&(this._temp.copy(e.emitterVelocity),e.worldSpace||(this.decomposeInverse(e),this._temp.multiply(this._tempScaleInv).applyQuaternion(this._tempQInv)),t.velocity.addScaledVector(this._temp,this.multiplier.genValue(t.memory,0)))}frameUpdate(t){this.ps&&!this.ps.worldSpace&&this.decomposeInverse(this.ps)}update(t,e){"current"===this.mode&&void 0!==this.ps&&this.ps.emitterVelocity&&(this._temp.copy(this.ps.emitterVelocity),this.ps.worldSpace||this._temp.multiply(this._tempScaleInv).applyQuaternion(this._tempQInv),t.position.addScaledVector(this._temp,this.multiplier.genValue(t.memory,t.age/t.life)*e))}decomposeInverse(t){t.emitter.matrixWorld.decompose(this._tempPos,this._tempQInv,this._tempScaleInv),this._tempQInv.invert(),this._tempScaleInv.set(1/this._tempScaleInv.x,1/this._tempScaleInv.y,1/this._tempScaleInv.z)}toJSON(){return{type:this.type,multiplier:this.multiplier.toJSON(),mode:this.mode}}static fromJSON(t){return new we(t.multiplier?It(t.multiplier):new Ct(1),"current"===t.mode?"current":"initial")}clone(){return new we(this.multiplier.clone(),this.mode)}reset(){}}class be{initialize(t){this.speed.startGen(t.memory)}constructor(t,e){this.speed=t,this.dampen=e,this.type="LimitSpeedOverLife"}update(t,e){let i=t.velocity.length(),s=this.speed.genValue(t.memory,t.age/t.life);if(i>s){const r=(i-s)/i;t.velocity.multiplyScalar(1-r*this.dampen*e*20)}}updateAll(t,e,i){const s=this.speed,r=this.dampen*i*20;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const n=e.velocity,o=n.length(),a=s.genValue(e.memory,e.age/e.life);o>a&&n.multiplyScalar(1-(o-a)/o*r)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(t){return new be(It(t.speed),t.dampen)}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new be(this.speed.clone(),this.dampen)}reset(){}}class ze{constructor(t=64){this.previousVelocity=ze.EMPTY,this.rotationQuaternion=ze.EMPTY,this.angularVelocityQuaternion=ze.EMPTY,this.memory=new Float64Array(0),this.memoryStride=0,this.capacity=Math.max(1,t),this.position=new Float32Array(3*this.capacity),this.previousPosition=new Float32Array(3*this.capacity),this.previousSize=new Float32Array(3*this.capacity),this.previousColor=new Float32Array(4*this.capacity),this.velocity=new Float32Array(3*this.capacity),this.size=new Float32Array(3*this.capacity),this.startSize=new Float32Array(3*this.capacity),this.color=new Float32Array(4*this.capacity),this.startColor=new Float32Array(4*this.capacity),this.scalars=new Float64Array(this.capacity*ze.SCALAR_STRIDE),this.rotation=new Float32Array(this.capacity),this.angularVelocity=new Float32Array(this.capacity),this.uvTile=new Float32Array(this.capacity),this.startSpeed=new Float32Array(this.capacity),this.flip=new Uint8Array(this.capacity)}ensureCapacity(t){if(t<=this.capacity)return!1;let e=this.capacity;for(;e<t;)e*=2;this.position=ze.grow(this.position,3*e),this.previousPosition=ze.grow(this.previousPosition,3*e);const i=this.previousSize===this.size,s=this.previousColor===this.color;if(i||(this.previousSize=ze.grow(this.previousSize,3*e)),this.previousVelocity.length>0&&(this.previousVelocity=ze.grow(this.previousVelocity,3*e)),this.rotationQuaternion.length>0){const t=this.rotationQuaternion.length;this.rotationQuaternion=ze.grow(this.rotationQuaternion,4*e),this.angularVelocityQuaternion=ze.grow(this.angularVelocityQuaternion,4*e);for(let i=t+3;i<4*e;i+=4)this.rotationQuaternion[i]=1,this.angularVelocityQuaternion[i]=1}if(s||(this.previousColor=ze.grow(this.previousColor,4*e)),this.velocity=ze.grow(this.velocity,3*e),this.size=ze.grow(this.size,3*e),this.startSize=ze.grow(this.startSize,3*e),this.color=ze.grow(this.color,4*e),i&&(this.previousSize=this.size),s&&(this.previousColor=this.color),this.startColor=ze.grow(this.startColor,4*e),this.scalars=ze.growDouble(this.scalars,e*ze.SCALAR_STRIDE),this.memoryStride>0){const t=new Float64Array(e*this.memoryStride);t.fill(NaN),t.set(this.memory),this.memory=t}this.rotation=ze.grow(this.rotation,e),this.angularVelocity=ze.grow(this.angularVelocity,e),this.uvTile=ze.grow(this.uvTile,e),this.startSpeed=ze.grow(this.startSpeed,e);const r=new Uint8Array(e);return r.set(this.flip),this.flip=r,this.capacity=e,!0}keepPreviousVelocity(){return!(this.previousVelocity.length>=3*this.capacity)&&(this.previousVelocity=new Float32Array(3*this.capacity),!0)}recordMemory(t,e){const i=e.length;let s=this.memoryStride;if(i>s||this.memory.length<this.capacity*s){s=Math.max(s,i);const t=new Float64Array(this.capacity*s);t.fill(NaN);const e=this.memoryStride,r=this.memory,n=e>0?r.length/e:0;for(let i=0,o=0,a=0;i<n;i++,o+=e,a+=s)for(let i=0;i<e;i++)t[a+i]=r[o+i];this.memory=t,this.memoryStride=s}const r=t*s;for(let t=0;t<s;t++){const s=t<i?e[t]:void 0;this.memory[r+t]="number"==typeof s?s:NaN}}useSizeSnapshot(t){t?this.previousSize===this.size&&(this.previousSize=new Float32Array(this.size)):this.previousSize=this.size}useColorSnapshot(t){t?this.previousColor===this.color&&(this.previousColor=new Float32Array(this.color)):this.previousColor=this.color}ensureQuaternionColumns(){if(this.rotationQuaternion.length>=4*this.capacity)return!1;this.rotationQuaternion=new Float32Array(4*this.capacity),this.angularVelocityQuaternion=new Float32Array(4*this.capacity);for(let t=3;t<this.rotationQuaternion.length;t+=4)this.rotationQuaternion[t]=1,this.angularVelocityQuaternion[t]=1;return!0}swapRows(t,e){if(t===e)return;const i=3*t,s=3*e;ze.swap3(this.position,i,s),ze.swap3(this.previousPosition,i,s),this.previousSize!==this.size&&ze.swap3(this.previousSize,i,s),this.previousVelocity.length>0&&ze.swap3(this.previousVelocity,i,s),ze.swap3(this.velocity,i,s),ze.swap3(this.size,i,s),ze.swap3(this.startSize,i,s);const r=4*t,n=4*e;ze.swap4(this.color,r,n),this.previousColor!==this.color&&ze.swap4(this.previousColor,r,n),ze.swap4(this.startColor,r,n),this.rotationQuaternion.length>0&&(ze.swap4(this.rotationQuaternion,r,n),ze.swap4(this.angularVelocityQuaternion,r,n)),ze.swap3(this.scalars,t*ze.SCALAR_STRIDE,e*ze.SCALAR_STRIDE);const o=this.memoryStride;if(o>0){const i=this.memory;for(let s=0,r=t*o,n=e*o;s<o;s++,r++,n++){const t=i[r];i[r]=i[n],i[n]=t}}ze.swap1(this.rotation,t,e),ze.swap1(this.angularVelocity,t,e),ze.swap1(this.uvTile,t,e),ze.swap1(this.startSpeed,t,e),ze.swap1(this.flip,t,e)}static swap1(t,e,i){const s=t[e];t[e]=t[i],t[i]=s}static growDouble(t,e){const i=new Float64Array(e);return i.set(t),i}static swap3(t,e,i){let s=t[e];t[e]=t[i],t[i]=s,s=t[e+1],t[e+1]=t[i+1],t[i+1]=s,s=t[e+2],t[e+2]=t[i+2],t[i+2]=s}static swap4(t,e,i){ze.swap3(t,e,i);const s=t[e+3];t[e+3]=t[i+3],t[i+3]=s}static grow(t,e){const i=new Float32Array(e);return i.set(t),i}}ze.EMPTY=new Float32Array(0),ze.SCALAR_STRIDE=3,ze.AGE=0,ze.LIFE=1,ze.SPEED_MODIFIER=2;const Me=.5*(Math.sqrt(3)-1),_e=(3-Math.sqrt(3))/6,Pe=1/3,Te=1/6,Ve=(Math.sqrt(5)-1)/4,Oe=(5-Math.sqrt(5))/20,Ce=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),Fe=new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);class Be{constructor(t=e){const e="function"==typeof t?t:function(t){let e=0,i=0,s=0,r=1;const n=function(){let t=4022871197;return function(e){e=e.toString();for(let i=0;i<e.length;i++){t+=e.charCodeAt(i);let s=.02519603282416938*t;t=s>>>0,s-=t,s*=t,t=s>>>0,s-=t,t+=4294967296*s}return 2.3283064365386963e-10*(t>>>0)}}();e=n(" "),i=n(" "),s=n(" "),e-=n(t),e<0&&(e+=1);i-=n(t),i<0&&(i+=1);s-=n(t),s<0&&(s+=1);return function(){const t=2091639*e+2.3283064365386963e-10*r;return e=i,i=s,s=t-(r=0|t)}}(t);this.p=function(t){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let i=0;i<255;i++){const s=i+~~(t()*(256-i)),r=e[i];e[i]=e[s],e[s]=r}return e}(e),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let t=0;t<512;t++)this.perm[t]=this.p[255&t],this.permMod12[t]=this.perm[t]%12}noise2D(t,e){const i=this.permMod12,s=this.perm;let r=0,n=0,o=0;const a=(t+e)*Me,h=Math.floor(t+a),l=Math.floor(e+a),c=(h+l)*_e,u=t-(h-c),d=e-(l-c);let p,f;u>d?(p=1,f=0):(p=0,f=1);const m=u-p+_e,y=d-f+_e,v=u-1+2*_e,g=d-1+2*_e,x=255&h,S=255&l;let w=.5-u*u-d*d;if(w>=0){const t=3*i[x+s[S]];w*=w,r=w*w*(Ce[t]*u+Ce[t+1]*d)}let b=.5-m*m-y*y;if(b>=0){const t=3*i[x+p+s[S+f]];b*=b,n=b*b*(Ce[t]*m+Ce[t+1]*y)}let z=.5-v*v-g*g;if(z>=0){const t=3*i[x+1+s[S+1]];z*=z,o=z*z*(Ce[t]*v+Ce[t+1]*g)}return 70*(r+n+o)}noise3D(t,e,i){const s=this.permMod12,r=this.perm;let n,o,a,h;const l=(t+e+i)*Pe,c=Math.floor(t+l),u=Math.floor(e+l),d=Math.floor(i+l),p=(c+u+d)*Te,f=t-(c-p),m=e-(u-p),y=i-(d-p);let v,g,x,S,w,b;f>=m?m>=y?(v=1,g=0,x=0,S=1,w=1,b=0):f>=y?(v=1,g=0,x=0,S=1,w=0,b=1):(v=0,g=0,x=1,S=1,w=0,b=1):m<y?(v=0,g=0,x=1,S=0,w=1,b=1):f<y?(v=0,g=1,x=0,S=0,w=1,b=1):(v=0,g=1,x=0,S=1,w=1,b=0);const z=f-v+Te,M=m-g+Te,_=y-x+Te,P=f-S+2*Te,T=m-w+2*Te,V=y-b+2*Te,O=f-1+.5,C=m-1+.5,F=y-1+.5,B=255&c,A=255&u,$=255&d;let I=.6-f*f-m*m-y*y;if(I<0)n=0;else{const t=3*s[B+r[A+r[$]]];I*=I,n=I*I*(Ce[t]*f+Ce[t+1]*m+Ce[t+2]*y)}let E=.6-z*z-M*M-_*_;if(E<0)o=0;else{const t=3*s[B+v+r[A+g+r[$+x]]];E*=E,o=E*E*(Ce[t]*z+Ce[t+1]*M+Ce[t+2]*_)}let N=.6-P*P-T*T-V*V;if(N<0)a=0;else{const t=3*s[B+S+r[A+w+r[$+b]]];N*=N,a=N*N*(Ce[t]*P+Ce[t+1]*T+Ce[t+2]*V)}let L=.6-O*O-C*C-F*F;if(L<0)h=0;else{const t=3*s[B+1+r[A+1+r[$+1]]];L*=L,h=L*L*(Ce[t]*O+Ce[t+1]*C+Ce[t+2]*F)}return 32*(n+o+a+h)}noise4D(t,e,i,s){const r=this.perm;let n,o,a,h,l;const c=(t+e+i+s)*Ve,u=Math.floor(t+c),d=Math.floor(e+c),p=Math.floor(i+c),f=Math.floor(s+c),m=(u+d+p+f)*Oe,y=t-(u-m),v=e-(d-m),g=i-(p-m),x=s-(f-m);let S=0,w=0,b=0,z=0;y>v?S++:w++,y>g?S++:b++,y>x?S++:z++,v>g?w++:b++,v>x?w++:z++,g>x?b++:z++;const M=S>=3?1:0,_=w>=3?1:0,P=b>=3?1:0,T=z>=3?1:0,V=S>=2?1:0,O=w>=2?1:0,C=b>=2?1:0,F=z>=2?1:0,B=S>=1?1:0,A=w>=1?1:0,$=b>=1?1:0,I=z>=1?1:0,E=y-M+Oe,N=v-_+Oe,L=g-P+Oe,R=x-T+Oe,D=y-V+2*Oe,U=v-O+2*Oe,q=g-C+2*Oe,k=x-F+2*Oe,J=y-B+3*Oe,Q=v-A+3*Oe,G=g-$+3*Oe,W=x-I+3*Oe,j=y-1+4*Oe,Y=v-1+4*Oe,X=g-1+4*Oe,Z=x-1+4*Oe,H=255&u,K=255&d,tt=255&p,et=255&f;let it=.6-y*y-v*v-g*g-x*x;if(it<0)n=0;else{const t=r[H+r[K+r[tt+r[et]]]]%32*4;it*=it,n=it*it*(Fe[t]*y+Fe[t+1]*v+Fe[t+2]*g+Fe[t+3]*x)}let st=.6-E*E-N*N-L*L-R*R;if(st<0)o=0;else{const t=r[H+M+r[K+_+r[tt+P+r[et+T]]]]%32*4;st*=st,o=st*st*(Fe[t]*E+Fe[t+1]*N+Fe[t+2]*L+Fe[t+3]*R)}let rt=.6-D*D-U*U-q*q-k*k;if(rt<0)a=0;else{const t=r[H+V+r[K+O+r[tt+C+r[et+F]]]]%32*4;rt*=rt,a=rt*rt*(Fe[t]*D+Fe[t+1]*U+Fe[t+2]*q+Fe[t+3]*k)}let nt=.6-J*J-Q*Q-G*G-W*W;if(nt<0)h=0;else{const t=r[H+B+r[K+A+r[tt+$+r[et+I]]]]%32*4;nt*=nt,h=nt*nt*(Fe[t]*J+Fe[t+1]*Q+Fe[t+2]*G+Fe[t+3]*W)}let ot=.6-j*j-Y*Y-X*X-Z*Z;if(ot<0)l=0;else{const t=r[H+1+r[K+1+r[tt+1+r[et+1]]]]%32*4;ot*=ot,l=ot*ot*(Fe[t]*j+Fe[t+1]*Y+Fe[t+2]*X+Fe[t+3]*Z)}return 27*(n+o+a+h+l)}}const Ae=100,$e=new Array(Ae),Ie=new H,Ee=new Z;function Ne(t){let e=$e[t];return void 0===e&&(e=new Be(t),$e[t]=e),e}class Le{constructor(t,e,i=new Ct(1),s=new Ct(0),r=new Ct(0),n){this.frequency=t,this.power=e,this.positionAmount=i,this.rotationAmount=s,this.scrollSpeed=r,this.remap=n,this.type="Noise",this.duration=0,this.scrollOffset=0,this.scrollMemory=[],this._frequency=NaN,this._power=NaN,this._positionAmount=NaN,this._rotationAmount=NaN,this.scrollSpeed.startGen(this.scrollMemory)}sample(t,e,i){const s=t.noise2D(0,e),r=this.remap;return void 0===r?s:r.genValue(i,.5*(s+1))}initialize(t){const e="number"==typeof t.rotation;let i=t._noiseState;if(void 0===i)return i={lastPos:new H,lastRot:0,lastRotQ:e?null:new Z,generatorX:Ne(le(0,Ae)),generatorY:Ne(le(0,Ae)),generatorZ:Ne(le(0,Ae)),generatorW:Ne(le(0,Ae))},void(t._noiseState=i);i.lastPos.set(0,0,0),i.lastRot=0,e?i.lastRotQ=null:null===i.lastRotQ?i.lastRotQ=new Z:i.lastRotQ.set(0,0,0,1),i.generatorX=Ne(le(0,Ae)),i.generatorY=Ne(le(0,Ae)),i.generatorZ=Ne(le(0,Ae)),i.generatorW=Ne(le(0,Ae))}static constantOf(t){return t instanceof Ct?t.value:NaN}update(t,e){const i=t._noiseState;if(void 0===i)return;const s=t.memory,r=t.age/t.life,n=this._frequency,o=n==n?n:this.frequency.genValue(s,r),a=this._power,h=a==a?a:this.power.genValue(s,r),l=this._positionAmount,c=l==l?l:this.positionAmount.genValue(s,r),u=this._rotationAmount,d=u==u?u:this.rotationAmount.genValue(s,r),p=t.age*o+this.scrollOffset;if(c>0){const e=h*c;t.position.sub(i.lastPos),Ie.set(this.sample(i.generatorX,p,s)*e,this.sample(i.generatorY,p,s)*e,this.sample(i.generatorZ,p,s)*e),t.position.add(Ie),i.lastPos.copy(Ie)}if(d>0){const e=h*d;if("number"==typeof t.rotation){const r=this.sample(i.generatorW,p,s)*Math.PI*e;t.rotation=t.rotation-i.lastRot+r,i.lastRot=r}else if(null!==i.lastRotQ){const r=t.rotation;i.lastRotQ.invert(),r.multiply(i.lastRotQ),Ee.set(this.sample(i.generatorX,p,s)*e,this.sample(i.generatorY,p,s)*e,this.sample(i.generatorZ,p,s)*e,this.sample(i.generatorW,p,s)*e).normalize(),r.multiply(Ee),i.lastRotQ.copy(Ee)}}}updateAll(t,e,i){const s=e>0?t[0].store:void 0;if(void 0===s){for(let s=0;s<e;s++){const e=t[s];e.age<e.life&&this.update(e,i)}return}const r=s.position,n=s.rotation,o=s.scalars,a=ze.SCALAR_STRIDE,h=this._frequency,l=this._power,c=this._positionAmount,u=this._rotationAmount;for(let i=0,s=0,d=0;i<e;i++,s+=3,d+=a){const e=o[d],a=o[d+1];if(e>=a)continue;const p=t[i],f=p._noiseState;if(void 0===f)continue;const m=p.memory,y=e/a,v=h==h?h:this.frequency.genValue(m,y),g=l==l?l:this.power.genValue(m,y),x=c==c?c:this.positionAmount.genValue(m,y),S=u==u?u:this.rotationAmount.genValue(m,y),w=e*v+this.scrollOffset;if(x>0){const t=g*x,e=f.lastPos,i=this.sample(f.generatorX,w,m)*t,n=this.sample(f.generatorY,w,m)*t,o=this.sample(f.generatorZ,w,m)*t;r[s]=Math.fround(r[s]-e.x)+i,r[s+1]=Math.fround(r[s+1]-e.y)+n,r[s+2]=Math.fround(r[s+2]-e.z)+o,e.set(i,n,o)}if(S>0){const t=g*S;if("number"==typeof p.rotation){const e=this.sample(f.generatorW,w,m)*Math.PI*t;n[i]=n[i]-f.lastRot+e,f.lastRot=e}else if(null!==f.lastRotQ){const e=p.rotation;f.lastRotQ.invert(),e.multiply(f.lastRotQ),Ee.set(this.sample(f.generatorX,w,m)*t,this.sample(f.generatorY,w,m)*t,this.sample(f.generatorZ,w,m)*t,this.sample(f.generatorW,w,m)*t).normalize(),e.multiply(Ee),f.lastRotQ.copy(Ee)}}}}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON(),scrollSpeed:this.scrollSpeed.toJSON(),...void 0!==this.remap?{remap:this.remap.toJSON()}:{}}}frameUpdate(t){this.duration+=t,this.scrollOffset+=this.scrollSpeed.genValue(this.scrollMemory,0)*t,this._frequency=Le.constantOf(this.frequency),this._power=Le.constantOf(this.power),this._positionAmount=Le.constantOf(this.positionAmount),this._rotationAmount=Le.constantOf(this.rotationAmount)}static fromJSON(t){return new Le(It(t.frequency),It(t.power),It(t.positionAmount),It(t.rotationAmount),t.scrollSpeed?It(t.scrollSpeed):new Ct(0),t.remap?It(t.remap):void 0)}clone(){return new Le(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone(),this.scrollSpeed.clone(),this.remap?.clone())}reset(){this.scrollOffset=0}}class Re{constructor(t,e=new H(0,1,0)){this.orbitSpeed=t,this.axis=e,this.type="OrbitOverLife",this.temp=new H,this.rotation=new Z}initialize(t){this.orbitSpeed.startGen(t.memory)}update(t,e){this.temp.copy(t.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(t.memory,t.age/t.life)*e),t.position.sub(this.temp),t.position.applyQuaternion(this.rotation),t.position.add(this.temp)}updateAll(t,e,i){const s=this.orbitSpeed,r=this.axis,n=this.temp,o=this.rotation;for(let a=0;a<e;a++){const e=t[a];if(e.age>=e.life)continue;const h=e.position;n.copy(h).projectOnVector(r),o.setFromAxisAngle(r,s.genValue(e.memory,e.age/e.life)*i),h.sub(n),h.applyQuaternion(o),h.add(n)}}frameUpdate(t){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(t){return new Re(It(t.orbitSpeed),t.axis?new H(t.axis[0],t.axis[1],t.axis[2]):void 0)}clone(){return new Re(this.orbitSpeed.clone())}reset(){}}class De{constructor(t){this.angularVelocity=t,this.type="Rotation3DOverLife",this.tempQuat=new Z}initialize(t){t.rotation instanceof Z&&(t.angularVelocity=new Z,this.angularVelocity.startGen(t.memory))}update(t,e){if(t.rotation instanceof Z){this.angularVelocity.genValue(t.memory,this.tempQuat,e,t.age/t.life),t.rotation.multiply(this.tempQuat);const i=t.angularVelocity;i instanceof Z&&i.copy(this.tempQuat)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new De(Ht(t.angularVelocity))}frameUpdate(t){}clone(){return new De(this.angularVelocity.clone())}reset(){}}class Ue{constructor(t,e){this.angularVelocity=t,this.speedRange=e,this.type="RotationBySpeed",this.tempQuat=new Z}initialize(t){"number"==typeof t.rotation&&this.angularVelocity.startGen(t.memory)}update(t,e){if("number"==typeof t.rotation){const i=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a),s=this.angularVelocity.genValue(t.memory,i);t.rotation+=e*s,t.angularVelocity=s}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new Ue(It(t.angularVelocity),Ft.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Ue(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class qe{constructor(t){this.angularVelocity=t,this.type="RotationOverLife",this.tempQuat=new Z}initialize(t){"number"==typeof t.rotation?this.angularVelocity.startGen(t.memory):t.rotation instanceof Z&&(this.angularVelocity.startGen(t.memory),t.angularVelocity instanceof Z||(t.angularVelocity=new Z))}update(t,e){if("number"==typeof t.rotation){const i=this.angularVelocity.genValue(t.memory,t.age/t.life);t.rotation+=e*i,t.angularVelocity=i}else if(t.rotation instanceof Z){const i=this.angularVelocity.genValue(t.memory,t.age/t.life);this.turnAboutZ(t,t.rotation,i*e)}}updateAll(t,e,i){const s=this.angularVelocity;for(let r=0;r<e;r++){const e=t[r];if(e.age>=e.life)continue;const n=e.rotation;if("number"==typeof n){const t=s.genValue(e.memory,e.age/e.life);e.rotation=n+i*t,e.angularVelocity=t}else if(n instanceof Z){const t=s.genValue(e.memory,e.age/e.life);this.turnAboutZ(e,n,t*i)}}}turnAboutZ(t,e,i){const s=this.tempQuat.setFromAxisAngle(pe,i);e.multiply(s);const r=t.angularVelocity;r instanceof Z&&r.copy(s)}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new qe(It(t.angularVelocity))}frameUpdate(t){this.angularVelocity.refreshTable?.()}clone(){return new qe(this.angularVelocity.clone())}reset(){}}class ke{initialize(t){this.size.startGen(t.memory)}constructor(t,e){this.size=t,this.speedRange=e,this.type="SizeBySpeed"}update(t){const e=(t.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.size instanceof Kt?this.size.genValue(t.memory,t.size,e).multiply(t.startSize):t.size.copy(t.startSize).multiplyScalar(this.size.genValue(t.memory,e))}toJSON(){return{type:this.type,size:this.size.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(t){return new ke(ee(t.size),Ft.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new ke(this.size.clone(),this.speedRange.clone())}reset(){}}class Je{constructor(t){this.type="SizeOverLife",this._sizeIsVector3=!1,this.size=t}get size(){return this._size}set size(t){this._size=t,this._sizeIsVector3=t instanceof Kt}initialize(t){this._size.startGen(t.memory)}update(t){const e=t.age/t.life;if(this._sizeIsVector3)this._size.genValue(t.memory,t.size,e).multiply(t.startSize);else{const i=this._size.genValue(t.memory,e),s=t.size,r=t.startSize;s.x=r.x*i,s.y=r.y*i,s.z=r.z*i}}updateAll(t,e,i){if(this._sizeIsVector3){const i=this._size;for(let s=0;s<e;s++){const e=t[s];e.age>=e.life||i.genValue(e.memory,e.size,e.age/e.life).multiply(e.startSize)}return}const s=this._size;for(let i=0;i<e;i++){const e=t[i];if(e.age>=e.life)continue;const r=s.genValue(e.memory,e.age/e.life),n=e.size,o=e.startSize;n.x=o.x*r,n.y=o.y*r,n.z=o.z*r}}toJSON(){return{type:this.type,size:this.size.toJSON()}}static fromJSON(t){return new Je(ee(t.size))}frameUpdate(t){this._size.refreshTable?.()}clone(){return new Je(this.size.clone())}reset(){}}class Qe{initialize(t){this.speed.startGen(t.memory)}constructor(t){this.speed=t,this.type="SpeedOverLife"}update(t){t.speedModifier=this.speed.genValue(t.memory,t.age/t.life)}updateAll(t,e,i){const s=this.speed;for(let i=0;i<e;i++){const e=t[i];e.age>=e.life||(e.speedModifier=s.genValue(e.memory,e.age/e.life))}}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(t){return new Qe(It(t.speed))}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new Qe(this.speed.clone())}reset(){}}class Ge{constructor(t,e,i,s){this.scale=t,this.octaves=e,this.velocityMultiplier=i,this.timeScale=s,this.type="TurbulenceField",this.generator=new Be(S),this.timeOffset=new H,this.temp=new H,this.temp2=new H,this.timeOffset.x=S()/this.scale.x*this.timeScale.x,this.timeOffset.y=S()/this.scale.y*this.timeScale.y,this.timeOffset.z=S()/this.scale.z*this.timeScale.z}initialize(t){}update(t,e){const i=t.position.x/this.scale.x,s=t.position.y/this.scale.y,r=t.position.z/this.scale.z;this.temp.set(0,0,0);let n=1;for(let t=0;t<this.octaves;t++)this.temp2.set(this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.x*n)/n,this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.y*n)/n,this.generator.noise4D(i*n,s*n,r*n,this.timeOffset.z*n)/n),this.temp.add(this.temp2),n*=2;this.temp.multiply(this.velocityMultiplier),t.velocity.addScaledVector(this.temp,e)}updateAll(t,e,i){const s=e>0?t[0].store:void 0;if(void 0===s){for(let s=0;s<e;s++){const e=t[s];e.age<e.life&&this.update(e,i)}return}const r=s.position,n=s.velocity,o=s.scalars,a=ze.SCALAR_STRIDE,h=this.generator,l=this.octaves,c=1/this.scale.x,u=1/this.scale.y,d=1/this.scale.z,p=this.velocityMultiplier.x*i,f=this.velocityMultiplier.y*i,m=this.velocityMultiplier.z*i,y=this.timeOffset.x,v=this.timeOffset.y,g=this.timeOffset.z;for(let t=0,i=0,s=0;t<e;t++,i+=3,s+=a){if(o[s]>=o[s+1])continue;const t=r[i]*c,e=r[i+1]*u,a=r[i+2]*d;let x=0,S=0,w=0,b=1;for(let i=0;i<l;i++){const i=t*b,s=e*b,r=a*b;x+=h.noise4D(i,s,r,y*b)/b,S+=h.noise4D(i,s,r,v*b)/b,w+=h.noise4D(i,s,r,g*b)/b,b*=2}n[i]+=x*p,n[i+1]+=S*f,n[i+2]+=w*m}}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(t){this.timeOffset.x+=t*this.timeScale.x,this.timeOffset.y+=t*this.timeScale.y,this.timeOffset.z+=t*this.timeScale.z}static fromJSON(t){return new Ge(new H(t.scale[0],t.scale[1],t.scale[2]),t.octaves,new H(t.velocityMultiplier[0],t.velocityMultiplier[1],t.velocityMultiplier[2]),new H(t.timeScale[0],t.timeScale[1],t.timeScale[2]))}clone(){return new Ge(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const We=new H(1,0,0),je=new H(0,1,0),Ye=new H(0,0,1);class Xe{constructor(t=new Ct(0),e=new Ct(0),i=new Ct(0),s=new Ct(0),r=new Ct(0),n=new Ct(0),o="local",a=new Ct(0),h=new H){this.linearX=t,this.linearY=e,this.linearZ=i,this.orbitalX=s,this.orbitalY=r,this.orbitalZ=n,this.space=o,this.radial=a,this.orbitalOffset=h,this.type="VelocityOverLife",this._temp=new H,this._tempEmitterPos=new H,this._tempQ=new Z,this._tempQInv=new Z,this._tempScale=new H(1,1,1),this._tempScaleInv=new H(1,1,1),this._tempRot=new Z,this._axisX=new H(1,0,0),this._axisY=new H(0,1,0),this._axisZ=new H(0,0,1),this._center=new H}initialize(t,e){this.ps=e,this.linearX.startGen(t.memory),this.linearY.startGen(t.memory),this.linearZ.startGen(t.memory),this.orbitalX.startGen(t.memory),this.orbitalY.startGen(t.memory),this.orbitalZ.startGen(t.memory),this.radial.startGen(t.memory)}frameUpdate(t){this.ps&&(this.ps.emitter.matrixWorld.decompose(this._tempEmitterPos,this._tempQ,this._tempScale),this._tempQInv.copy(this._tempQ).invert(),this._tempScaleInv.set(1/this._tempScale.x,1/this._tempScale.y,1/this._tempScale.z),this._axisX.copy(We),this._axisY.copy(je),this._axisZ.copy(Ye),this._center.copy(this.orbitalOffset),this.ps.worldSpace&&(this._axisX.applyQuaternion(this._tempQ),this._axisY.applyQuaternion(this._tempQ),this._axisZ.applyQuaternion(this._tempQ),this._center.multiply(this._tempScale).applyQuaternion(this._tempQ).add(this._tempEmitterPos)))}update(t,e){const i=t.age/t.life;this._temp.set(this.linearX.genValue(t.memory,i),this.linearY.genValue(t.memory,i),this.linearZ.genValue(t.memory,i));const s=void 0!==this.ps&&this.ps.worldSpace;s&&"local"===this.space?this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ):s||"world"!==this.space||this._temp.multiply(this._tempScaleInv).applyQuaternion(this._tempQInv),t.position.addScaledVector(this._temp,e);const r=this.radial.genValue(t.memory,i);if(0!==r){this._temp.copy(t.position).sub(this._center);const i=this._temp.length();i>0&&t.position.addScaledVector(this._temp,r*e/i)}const n=this.orbitalX.genValue(t.memory,i)*e,o=this.orbitalY.genValue(t.memory,i)*e,a=this.orbitalZ.genValue(t.memory,i)*e;0===n&&0===o&&0===a||(t.position.sub(this._center),this.orbit(t.position,this._axisX,n),this.orbit(t.position,this._axisY,o),this.orbit(t.position,this._axisZ,a),t.position.add(this._center))}orbit(t,e,i){0!==i&&(this._tempRot.setFromAxisAngle(e,i),t.applyQuaternion(this._tempRot))}toJSON(){return{type:this.type,linearX:this.linearX.toJSON(),linearY:this.linearY.toJSON(),linearZ:this.linearZ.toJSON(),orbitalX:this.orbitalX.toJSON(),orbitalY:this.orbitalY.toJSON(),orbitalZ:this.orbitalZ.toJSON(),space:this.space,radial:this.radial.toJSON(),orbitalOffset:[this.orbitalOffset.x,this.orbitalOffset.y,this.orbitalOffset.z]}}static fromJSON(t){const e=t=>t?It(t):new Ct(0);return new Xe(e(t.linearX),e(t.linearY),e(t.linearZ),e(t.orbitalX),e(t.orbitalY),e(t.orbitalZ),"world"===t.space?"world":"local",e(t.radial),Array.isArray(t.orbitalOffset)?new H(t.orbitalOffset[0]??0,t.orbitalOffset[1]??0,t.orbitalOffset[2]??0):new H)}clone(){return new Xe(this.linearX.clone(),this.linearY.clone(),this.linearZ.clone(),this.orbitalX.clone(),this.orbitalY.clone(),this.orbitalZ.clone(),this.space,this.radial.clone(),this.orbitalOffset.clone())}reset(){}}class Ze{constructor(t){this.data=t,this.next=null,this.prev=null}hasPrev(){return null!==this.prev}hasNext(){return null!==this.next}}class He{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return null===this.head}clear(){this.length=0,this.head=this.tail=null}front(){return null===this.head?null:this.head.data}back(){return null===this.tail?null:this.tail.data}dequeue(){if(this.head){const t=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}}pop(){if(this.tail){const t=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}}queue(t){const e=new Ze(t);this.tail||(this.tail=e),this.head&&(this.head.prev=e,e.next=this.head),this.head=e,this.length++}push(t){const e=new Ze(t);this.head||(this.head=e),this.tail&&(this.tail.next=e,e.prev=this.tail),this.tail=e,this.length++}insertBefore(t,e){const i=new Ze(e);i.next=t,i.prev=t.prev,null!==i.prev&&(i.prev.next=i),i.next.prev=i,t==this.head&&(this.head=i),this.length++}remove(t){if(null===this.head||null===this.tail)return;let e=this.head;for(t===this.head.data&&(this.head=this.head.next),t===this.tail.data&&(this.tail=this.tail.prev);null!==e.next&&e.data!==t;)e=e.next;e.data===t&&(null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.length--)}*values(){let t=this.head;for(;null!==t;)yield t.data,t=t.next}}class Ke{get startSpeed(){return this.store.startSpeed[this.storeIndex]}set startSpeed(t){this.store.startSpeed[this.storeIndex]=t}get age(){return this.scalars[this.scalarOffset]}set age(t){this.scalars[this.scalarOffset]=t}get life(){return this.scalars[this.scalarOffset+1]}set life(t){this.scalars[this.scalarOffset+1]=t}get speedModifier(){return this.scalars[this.scalarOffset+2]}set speedModifier(t){this.scalars[this.scalarOffset+2]=t}get angularVelocity(){const t=this.angularVelocityQuaternion;return void 0!==t?t:this.store.angularVelocity[this.storeIndex]}set angularVelocity(t){if("number"==typeof t)this.angularVelocityQuaternion=void 0,this.store.angularVelocity[this.storeIndex]=t;else if(void 0===t)this.angularVelocityQuaternion=void 0,this.store.angularVelocity[this.storeIndex]=0;else{let e=this.angularVelocityQuaternion;void 0===e&&(this.store.ensureQuaternionColumns(),e=new vt(this.store.angularVelocityQuaternion,4*this.storeIndex),this.angularVelocityQuaternion=e),e!==t&&e.copy(t)}}get rotation(){const t=this.rotationQuaternion;return void 0!==t?t:this.store.rotation[this.storeIndex]}set rotation(t){if("number"==typeof t)this.rotationQuaternion=void 0,this.store.rotation[this.storeIndex]=t;else{let e=this.rotationQuaternion;void 0===e&&(this.store.ensureQuaternionColumns(),e=new vt(this.store.rotationQuaternion,4*this.storeIndex),this.rotationQuaternion=e),e!==t&&e.copy(t)}}get uvTile(){return this.store.uvTile[this.storeIndex]}set uvTile(t){this.store.uvTile[this.storeIndex]=t}get flip(){return this.store.flip[this.storeIndex]}set flip(t){this.store.flip[this.storeIndex]=t}constructor(t=new ze(1),e=0){this.rotationQuaternion=void 0,this.angularVelocityQuaternion=void 0,this.memory=[],this.store=t,this.storeIndex=e;const i=3*e,s=4*e;this.position=new wt(t.position,i),this.previousPosition=new wt(t.previousPosition,i),this.previousVelocity=new wt(t.previousVelocity,i),this.velocity=new wt(t.velocity,i),this.size=new wt(t.size,i),this.startSize=new wt(t.startSize,i),this.color=new _t(t.color,s),this.startColor=new _t(t.startColor,s),this.scalars=t.scalars,this.scalarOffset=e*ze.SCALAR_STRIDE,this.size.set(1,1,1),this.startSize.set(1,1,1),this.life=1,this.speedModifier=1}setStoreIndex(t){this.storeIndex=t,this.rebind()}rebind(){const t=this.store,e=3*this.storeIndex,i=4*this.storeIndex;this.position.bind(t.position,e),this.previousPosition.bind(t.previousPosition,e),this.previousVelocity.bind(t.previousVelocity,e),this.velocity.bind(t.velocity,e),this.size.bind(t.size,e),this.startSize.bind(t.startSize,e),this.color.bind(t.color,i),this.startColor.bind(t.startColor,i),this.rotationQuaternion?.bind(t.rotationQuaternion,i),this.angularVelocityQuaternion?.bind(t.angularVelocityQuaternion,i),this.scalars=t.scalars,this.scalarOffset=this.storeIndex*ze.SCALAR_STRIDE}get died(){return this.age>=this.life}reset(){this.memory.length=0}}const ti=new Float32Array(0);class ei{get startSpeed(){return this.store.startSpeed[this.storeIndex]}set startSpeed(t){this.store.startSpeed[this.storeIndex]=t}get age(){return this.scalars[this.scalarOffset]}set age(t){this.scalars[this.scalarOffset]=t}get life(){return this.scalars[this.scalarOffset+1]}set life(t){this.scalars[this.scalarOffset+1]=t}get speedModifier(){return this.scalars[this.scalarOffset+2]}set speedModifier(t){this.scalars[this.scalarOffset+2]=t}get previous(){return this._previous??(this._previous=new He)}set previous(t){this._previous=t}get uvTile(){return this.store.uvTile[this.storeIndex]}set uvTile(t){this.store.uvTile[this.storeIndex]=t}constructor(t=new ze(1),e=0){this.length=100,this._previous=void 0,this.historyPositions=ti,this.historySizes=ti,this.historyBaseSizes=ti,this.headWidthScale=1,this.historyColors=ti,this.historyCapacity=0,this.historyHead=0,this.historyCount=0,this.memory=[],this.store=t,this.storeIndex=e;const i=3*e,s=4*e;this.position=new wt(t.position,i),this.previousPosition=new wt(t.previousPosition,i),this.previousVelocity=new wt(t.previousVelocity,i),this.velocity=new wt(t.velocity,i),this.size=new wt(t.size,i),this.startSize=new wt(t.startSize,i),this.color=new _t(t.color,s),this.startColor=new _t(t.startColor,s),this.scalars=t.scalars,this.scalarOffset=e*ze.SCALAR_STRIDE,this.size.set(1,1,1),this.startSize.set(1,1,1),this.life=1,this.speedModifier=1}setStoreIndex(t){this.storeIndex=t,this.rebind()}rebind(){const t=this.store,e=3*this.storeIndex,i=4*this.storeIndex;this.position.bind(t.position,e),this.previousPosition.bind(t.previousPosition,e),this.previousVelocity.bind(t.previousVelocity,e),this.velocity.bind(t.velocity,e),this.size.bind(t.size,e),this.startSize.bind(t.startSize,e),this.color.bind(t.color,i),this.startColor.bind(t.startColor,i),this.scalars=t.scalars,this.scalarOffset=this.storeIndex*ze.SCALAR_STRIDE}ensureHistoryCapacity(t){this.historyCapacity!==t&&(this.historyCapacity=t,this.historyPositions=new Float32Array(3*t),this.historySizes=new Float32Array(t),this.historyBaseSizes=new Float32Array(t),this.historyColors=new Float32Array(4*t),this.historyHead=0,this.historyCount=0)}resetHistory(){this.historyHead=0,this.historyCount=0}getHistoryIndex(t){const e=this.historyCapacity;return(this.historyHead-this.historyCount+e+t)%e}update(){0===this.historyCapacity&&this.ensureHistoryCapacity(Math.max(1,Math.ceil(this.length)));const t=this.historyCapacity,e=this.store,i=this.storeIndex,s=i*ze.SCALAR_STRIDE;if(e.scalars[s+ze.AGE]>e.scalars[s+ze.LIFE])return void(this.historyCount>0&&this.historyCount--);const r=this.historyHead,n=3*r,o=this.historyPositions,a=e.position,h=3*i;o[n]=a[h],o[n+1]=a[h+1],o[n+2]=a[h+2];const l=e.size[h];this.historyBaseSizes[r]=l,this.historySizes[r]=l*this.headWidthScale;const c=4*r,u=this.historyColors,d=e.color,p=4*i;u[c]=d[p],u[c+1]=d[p+1],u[c+2]=d[p+2],u[c+3]=d[p+3],this.historyHead=(r+1)%t,this.historyCount<t&&this.historyCount++}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.headWidthScale=1,this.resetHistory()}}class ii{initialize(t){this.width.startGen(t.memory)}constructor(t,e=!1){this.width=t,this.absolute=e,this.type="WidthOverLength"}update(t){if(!(t instanceof ei))return;const e=t.memory;t.headWidthScale=this.absolute?1:this.width.genValue(e,0);const i=t.historyCount;if(0===i)return;const s=t.historyCapacity,r=t.historySizes,n=t.historyBaseSizes,o=1/t.length,a=this.absolute;let h=t.getHistoryIndex(0);for(let t=0;t<i;t++){const l=this.width.genValue(e,(i-t)*o);r[h]=a?l:n[h]*l,h++,h===s&&(h=0)}}frameUpdate(t){}toJSON(){return{type:this.type,width:this.width.toJSON(),absolute:this.absolute}}static fromJSON(t){return new ii(It(t.width),t.absolute??!0)}clone(){return new ii(this.width.clone(),this.absolute)}reset(){}}const si={ApplyForce:{type:"ApplyForce",constructor:ie,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:ie.fromJSON},Noise:{type:"Noise",constructor:Le,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Le.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Ge,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Ge.fromJSON},GravityForce:{type:"GravityForce",constructor:Se,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Se.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:he,params:[["color",["colorFunc"]]],loadJSON:he.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:qe,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:qe.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:De,params:[["angularVelocity",["rotationFunc"]]],loadJSON:De.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Je,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Je.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:ae,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:ae.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Ue,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Ue.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:ke,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:ke.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Qe,params:[["speed",["value","valueFunc"]]],loadJSON:Qe.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:xe,params:[["frame",["value","valueFunc"]]],loadJSON:xe.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:ge,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:ge.fromJSON},VelocityOverLife:{type:"VelocityOverLife",constructor:Xe,params:[["linearX",["value","valueFunc"]],["linearY",["value","valueFunc"]],["linearZ",["value","valueFunc"]],["orbitalX",["value","valueFunc"]],["orbitalY",["value","valueFunc"]],["orbitalZ",["value","valueFunc"]],["space",["string"]]],loadJSON:Xe.fromJSON},InheritVelocity:{type:"InheritVelocity",constructor:we,params:[["multiplier",["value","valueFunc"]],["mode",["string"]]],loadJSON:we.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Re,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Re.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:ii,params:[["width",["value","valueFunc"]]],loadJSON:ii.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:oe,params:[["angle",["value"]]],loadJSON:oe.fromJSON},ApplySequences:{type:"ApplySequences",constructor:ne,params:[["delay",["number"]]],loadJSON:ne.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:ve,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:ve.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:be,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:be.fromJSON},ApplyCollision:{type:"ApplyCollision",constructor:Ot,params:[["bounce",["number"]]],loadJSON:Ot.fromJSON}};function ri(t,e){return si[t.type]?si[t.type].loadJSON(t,e):null}const ni={PiecewiseBezier:$t,Vector3Function:Kt,Quaternion:Z,ConstantValue:Ct,Gradient:Jt,Vector4View:_t,AxisAngleGenerator:Et,IntervalValue:Ft,ColorRange:Ut};function oi(t,e){return`const ${t} = ${e};\n const ${t}_tbl = ${t} instanceof deps.PiecewiseBezier ? ${t}.sampledTable() : null;\n const ${t}_last = ${t}_tbl !== null ? ${t}_tbl.length - 1 : 0;\n const ${t}_const = ${t} instanceof deps.ConstantValue;\n const ${t}_cv = ${t}_const ? ${t}.value : 0;\n const ${t}_iv = ${t} instanceof deps.IntervalValue;\n const ${t}_slot = ${t}_iv ? ${t}.indexCount : -1;\n const ${t}_col = ${t}_slot >= 0 && ${t}_slot < ms;\n const ${t}_a = ${t}_iv ? ${t}.a : 0, ${t}_b = ${t}_iv ? ${t}.b : 0;`}function ai(t,e,i){return`let ${e};\n if (${t}_tbl !== null) {\n const tt = ${i};\n if (tt <= 0) ${e} = ${t}_tbl[0];\n else if (tt >= 1) ${e} = ${t}_tbl[${t}_last];\n else {\n const x = tt * ${t}_last;\n const ix = x | 0;\n const v0 = ${t}_tbl[ix];\n ${e} = v0 + (${t}_tbl[ix + 1] - v0) * (x - ix);\n }\n } else if (${t}_const) ${e} = ${t}_cv;\n else if (${t}_iv) {\n // The particle's own sample, from the memory column when it holds it.\n let r = ${t}_col ? mem[row * ms + ${t}_slot] : NaN;\n if (r !== r) r = p.memory[${t}_slot];\n ${e} = (1 - r) * ${t}_a + r * ${t}_b;\n } else ${e} = ${t}.genValue(p.memory, ${i});`}function hi(t,e){return`const ${t} = ${e};\n const ${t}_tbl = ${t} instanceof deps.Gradient ? ${t}.sampledTable() : null;\n const ${t}_last = ${t}_tbl !== null ? ${t}_tbl.length / 4 - 1 : 0;\n const ${t}_cr = ${t} instanceof deps.ColorRange;\n const ${t}_slot = ${t}_cr ? ${t}.indexCount : -1;\n const ${t}_col = ${t}_slot >= 0 && ${t}_slot < ms;\n // Rounded to float32 as copying the colour into the particle does.\n const ${t}_ax = ${t}_cr ? Math.fround(${t}.a.x) : 0, ${t}_ay = ${t}_cr ? Math.fround(${t}.a.y) : 0;\n const ${t}_az = ${t}_cr ? Math.fround(${t}.a.z) : 0, ${t}_aw = ${t}_cr ? Math.fround(${t}.a.w) : 0;\n const ${t}_bx = ${t}_cr ? ${t}.b.x : 0, ${t}_by = ${t}_cr ? ${t}.b.y : 0;\n const ${t}_bz = ${t}_cr ? ${t}.b.z : 0, ${t}_bw = ${t}_cr ? ${t}.b.w : 0;`}function li(t,e){return`if (${t}_tbl !== null) {\n const tt = ${e};\n const tbl = ${t}_tbl;\n let r, g, b, a;\n if (tt <= 0) {\n r = tbl[0]; g = tbl[1]; b = tbl[2]; a = tbl[3];\n } else if (tt >= 1) {\n const o = ${t}_last * 4;\n r = tbl[o]; g = tbl[o + 1]; b = tbl[o + 2]; a = tbl[o + 3];\n } else {\n const x = tt * ${t}_last;\n const ix = x | 0;\n const fr = x - ix;\n const o = ix * 4;\n const nx = o + 4;\n r = tbl[o] + (tbl[nx] - tbl[o]) * fr;\n g = tbl[o + 1] + (tbl[nx + 1] - tbl[o + 1]) * fr;\n b = tbl[o + 2] + (tbl[nx + 2] - tbl[o + 2]) * fr;\n a = tbl[o + 3] + (tbl[nx + 3] - tbl[o + 3]) * fr;\n }\n color[o4] = Math.fround(r) * startColor[o4];\n color[o4 + 1] = Math.fround(g) * startColor[o4 + 1];\n color[o4 + 2] = Math.fround(b) * startColor[o4 + 2];\n color[o4 + 3] = Math.fround(a) * startColor[o4 + 3];\n } else if (${t}_cr) {\n let r = ${t}_col ? mem[row * ms + ${t}_slot] : NaN;\n if (r !== r) r = p.memory[${t}_slot];\n color[o4] = Math.fround(${t}_ax + (${t}_bx - ${t}_ax) * r) * startColor[o4];\n color[o4 + 1] = Math.fround(${t}_ay + (${t}_by - ${t}_ay) * r) * startColor[o4 + 1];\n color[o4 + 2] = Math.fround(${t}_az + (${t}_bz - ${t}_az) * r) * startColor[o4 + 2];\n color[o4 + 3] = Math.fround(${t}_aw + (${t}_bw - ${t}_aw) * r) * startColor[o4 + 3];\n } else {\n ${t}.genColor(p.memory, tmpColor, ${e});\n color[o4] = tmpColor.x * startColor[o4];\n color[o4 + 1] = tmpColor.y * startColor[o4 + 1];\n color[o4 + 2] = tmpColor.z * startColor[o4 + 2];\n color[o4 + 3] = tmpColor.w * startColor[o4 + 3];\n }`}function ci(t,e,i,s,r,n,o){return`{\n const cx = 2 * (${r} * ${i} - ${n} * ${e});\n const cy = 2 * (${n} * ${t} - ${s} * ${i});\n const cz = 2 * (${s} * ${e} - ${r} * ${t});\n const nx = ${t} + ${o} * cx + ${r} * cz - ${n} * cy;\n const ny = ${e} + ${o} * cy + ${n} * cx - ${s} * cz;\n ${i} = ${i} + ${o} * cz + ${s} * cy - ${r} * cx;\n ${t} = nx;\n ${e} = ny;\n }`}function ui(t,e){return`const ${t}_q = ${e};\n const ${t}x = ${t}_q.x, ${t}y = ${t}_q.y, ${t}z = ${t}_q.z, ${t}w = ${t}_q.w;`}function di(t,e){return`const ${t}_v = ${e};\n const ${t}x = ${t}_v.x, ${t}y = ${t}_v.y, ${t}z = ${t}_v.z;`}function pi(t,e,i,s){return`{\n const half = ${t} / 2;\n const sn = Math.sin(half);\n const qx = ${e} * sn, qy = ${i} * sn, qz = ${s} * sn, qw = Math.cos(half);\n ${ci("px","py","pz","qx","qy","qz","qw")}\n px = Math.fround(px); py = Math.fround(py); pz = Math.fround(pz);\n }`}function fi(t,e){switch(t.type){case"ColorOverLife":return{setup:hi(`g${e}`,`behaviors[${e}].color`),body:`{${li(`g${e}`,"t")}}`};case"SizeOverLife":return{setup:`const g${e} = behaviors[${e}].size;\n const vec3_${e} = g${e} instanceof deps.Vector3Function;\n ${oi(`sg${e}`,`g${e}`)}`,body:`if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, t).multiply(p.startSize);\n } else {\n ${ai(`sg${e}`,"v","t")}\n size[o3] = startSize[o3] * v;\n size[o3 + 1] = startSize[o3 + 1] * v;\n size[o3 + 2] = startSize[o3 + 2] * v;\n }`};case"ApplyForce":return{setup:`const b${e} = behaviors[${e}];\n const f${e} = b${e}.magnitudeValue * delta;\n const dx${e} = b${e}.direction.x * f${e};\n const dy${e} = b${e}.direction.y * f${e};\n const dz${e} = b${e}.direction.z * f${e};`,body:`vel[o3] += dx${e}; vel[o3 + 1] += dy${e}; vel[o3 + 2] += dz${e};`};case"RotationOverLife":return{setup:`${oi(`g${e}`,`behaviors[${e}].angularVelocity`)}\n const rotation_${e} = count > 0 ? particles[0].rotation : undefined;\n const angle_${e} = typeof rotation_${e} === 'number';\n const rq${e} = store.rotationQuaternion, aq${e} = store.angularVelocityQuaternion;\n const quat_${e} = !angle_${e} && rq${e}.length > 0 && rotation_${e} instanceof deps.Quaternion;`,body:`if (angle_${e}) {\n ${ai(`g${e}`,"rate","t")}\n rot[row] += delta * rate;\n angVel[row] = rate;\n } else if (quat_${e}) {\n ${ai(`g${e}`,"rate","t")}\n const half = (rate * delta) / 2;\n const qz = Math.sin(half), qw = Math.cos(half);\n const ax = rq${e}[o4], ay = rq${e}[o4 + 1], az = rq${e}[o4 + 2], aw = rq${e}[o4 + 3];\n rq${e}[o4] = ax * qw + ay * qz;\n rq${e}[o4 + 1] = ay * qw - ax * qz;\n rq${e}[o4 + 2] = az * qw + aw * qz;\n rq${e}[o4 + 3] = aw * qw - az * qz;\n aq${e}[o4] = 0; aq${e}[o4 + 1] = 0; aq${e}[o4 + 2] = qz; aq${e}[o4 + 3] = qw;\n }`};case"FrameOverLife":return{setup:oi(`g${e}`,`behaviors[${e}].frame`),body:`{${ai(`g${e}`,"v","t")} uvTile[row] = v;}`};case"SpeedOverLife":return{setup:oi(`g${e}`,`behaviors[${e}].speed`),body:`{${ai(`g${e}`,"v","t")} scalars[s + 2] = v;}`};case"ForceOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${oi(`gx${e}`,`b${e}.x`)}\n ${oi(`gy${e}`,`b${e}.y`)}\n ${oi(`gz${e}`,`b${e}.z`)}\n const local${e} = b${e}.ps !== undefined && !b${e}.ps.worldSpace;\n ${di(`sc${e}`,`b${e}._tempScale`)}\n ${ui(`q${e}`,`b${e}._tempQ`)}`,body:`{\n ${ai(`gx${e}`,"fx","t")}\n ${ai(`gy${e}`,"fy","t")}\n ${ai(`gz${e}`,"fz","t")}\n if (local${e}) {\n fx *= sc${e}x; fy *= sc${e}y; fz *= sc${e}z;\n ${ci("fx","fy","fz",`q${e}x`,`q${e}y`,`q${e}z`,`q${e}w`)}\n }\n vel[o3] += fx * delta; vel[o3 + 1] += fy * delta; vel[o3 + 2] += fz * delta;}`};case"LimitSpeedOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${oi(`g${e}`,`b${e}.speed`)}\n const dampen${e} = b${e}.dampen * delta * 20;`,body:`{const vx = vel[o3], vy = vel[o3 + 1], vz = vel[o3 + 2];\n const speed = Math.sqrt(vx * vx + vy * vy + vz * vz);\n ${ai(`g${e}`,"limit","t")}\n if (speed > limit) {\n const f = 1 - ((speed - limit) / speed) * dampen${e};\n vel[o3] = vx * f; vel[o3 + 1] = vy * f; vel[o3 + 2] = vz * f;\n }}`};case"GravityForce":return{setup:`const b${e} = behaviors[${e}];\n const cx${e} = b${e}.center.x, cy${e} = b${e}.center.y, cz${e} = b${e}.center.z;\n const gm${e} = b${e}.magnitude * delta;`,body:`{const dx = cx${e} - pos[o3], dy = cy${e} - pos[o3 + 1], dz = cz${e} - pos[o3 + 2];\n const d2 = dx * dx + dy * dy + dz * dz;\n if (d2 > 0) {\n const f = gm${e} / (d2 * Math.sqrt(d2));\n vel[o3] += dx * f; vel[o3 + 1] += dy * f; vel[o3 + 2] += dz * f;\n }}`};case"ColorBySpeed":return{setup:`const b${e} = behaviors[${e}];\n ${hi(`g${e}`,`b${e}.color`)}\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};`,body:`{const ts = (startSpeed[row] - lo${e}) / span${e};\n ${li(`g${e}`,"ts")}}`};case"SizeBySpeed":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.size;\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};\n const vec3_${e} = g${e} instanceof deps.Vector3Function;\n ${oi(`sg${e}`,`g${e}`)}`,body:`{const ts = (startSpeed[row] - lo${e}) / span${e};\n if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, ts).multiply(p.startSize);\n } else {\n ${ai(`sg${e}`,"v","ts")}\n size[o3] = startSize[o3] * v;\n size[o3 + 1] = startSize[o3 + 1] * v;\n size[o3 + 2] = startSize[o3 + 2] * v;\n }}`};case"RotationBySpeed":return{setup:`const b${e} = behaviors[${e}];\n ${oi(`g${e}`,`b${e}.angularVelocity`)}\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};\n const angle_${e} = count > 0 && typeof particles[0].rotation === 'number';`,body:`if (angle_${e}) {\n const ts = (startSpeed[row] - lo${e}) / span${e};\n ${ai(`g${e}`,"rate","ts")}\n rot[row] += delta * rate;\n angVel[row] = rate;\n }`};case"OrbitOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${oi(`g${e}`,`b${e}.orbitSpeed`)}\n ${di(`ax${e}`,`b${e}.axis`)}\n const alen${e} = ax${e}x * ax${e}x + ax${e}y * ax${e}y + ax${e}z * ax${e}z;\n const chalf${e} = (g${e}_cv * delta) / 2;\n const csn${e} = Math.sin(chalf${e});\n const cqx${e} = ax${e}x * csn${e}, cqy${e} = ax${e}y * csn${e}, cqz${e} = ax${e}z * csn${e};\n const cqw${e} = Math.cos(chalf${e});`,body:`{let px = pos[o3], py = pos[o3 + 1], pz = pos[o3 + 2];\n let tx = 0, ty = 0, tz = 0;\n if (alen${e} !== 0) {\n const f = (ax${e}x * px + ax${e}y * py + ax${e}z * pz) / alen${e};\n tx = ax${e}x * f; ty = ax${e}y * f; tz = ax${e}z * f;\n }\n let qx, qy, qz, qw;\n if (g${e}_const) {\n qx = cqx${e}; qy = cqy${e}; qz = cqz${e}; qw = cqw${e};\n } else {\n ${ai(`g${e}`,"sp","t")}\n const half = (sp * delta) / 2;\n const sn = Math.sin(half);\n qx = ax${e}x * sn; qy = ax${e}y * sn; qz = ax${e}z * sn; qw = Math.cos(half);\n }\n px = Math.fround(px - tx); py = Math.fround(py - ty); pz = Math.fround(pz - tz);\n ${ci("px","py","pz","qx","qy","qz","qw")}\n pos[o3] = Math.fround(px) + tx;\n pos[o3 + 1] = Math.fround(py) + ty;\n pos[o3 + 2] = Math.fround(pz) + tz;}`};case"Rotation3DOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.angularVelocity;\n const q${e} = b${e}.tempQuat;\n const rq${e} = store.rotationQuaternion, aq${e} = store.angularVelocityQuaternion;\n const quat_${e} = rq${e}.length > 0 && count > 0 && particles[0].rotation instanceof deps.Quaternion;\n const fixed_${e} = g${e} instanceof deps.AxisAngleGenerator && g${e}.angle instanceof deps.ConstantValue;\n let cqx${e} = 0, cqy${e} = 0, cqz${e} = 0, cqw${e} = 1;\n if (fixed_${e}) {\n g${e}.genValue(undefined, q${e}, delta, 0);\n cqx${e} = q${e}.x; cqy${e} = q${e}.y; cqz${e} = q${e}.z; cqw${e} = q${e}.w;\n }`,body:`if (quat_${e}) {\n let qx, qy, qz, qw;\n if (fixed_${e}) {\n qx = cqx${e}; qy = cqy${e}; qz = cqz${e}; qw = cqw${e};\n } else {\n g${e}.genValue(p.memory, q${e}, delta, t);\n qx = q${e}.x; qy = q${e}.y; qz = q${e}.z; qw = q${e}.w;\n }\n const ax = rq${e}[o4], ay = rq${e}[o4 + 1], az = rq${e}[o4 + 2], aw = rq${e}[o4 + 3];\n rq${e}[o4] = ax * qw + aw * qx + ay * qz - az * qy;\n rq${e}[o4 + 1] = ay * qw + aw * qy + az * qx - ax * qz;\n rq${e}[o4 + 2] = az * qw + aw * qz + ax * qy - ay * qx;\n rq${e}[o4 + 3] = aw * qw - ax * qx - ay * qy - az * qz;\n aq${e}[o4] = qx; aq${e}[o4 + 1] = qy; aq${e}[o4 + 2] = qz; aq${e}[o4 + 3] = qw;\n }`};case"VelocityOverLife":return{setup:`const b${e} = behaviors[${e}];\n ${oi(`lx${e}`,`b${e}.linearX`)}\n ${oi(`ly${e}`,`b${e}.linearY`)}\n ${oi(`lz${e}`,`b${e}.linearZ`)}\n ${oi(`ox${e}`,`b${e}.orbitalX`)}\n ${oi(`oy${e}`,`b${e}.orbitalY`)}\n ${oi(`oz${e}`,`b${e}.orbitalZ`)}\n ${di(`aX${e}`,`b${e}._axisX`)}\n ${di(`aY${e}`,`b${e}._axisY`)}\n ${di(`aZ${e}`,`b${e}._axisZ`)}\n ${di(`pv${e}`,`b${e}._tempEmitterPos`)}\n const world${e} = b${e}.ps !== undefined && b${e}.ps.worldSpace;\n const toWorld${e} = world${e} && b${e}.space === 'local';\n const convert${e} = toWorld${e} || (!world${e} && b${e}.space === 'world');\n ${di(`sc${e}`,`toWorld${e} ? b${e}._tempScale : b${e}._tempScaleInv`)}\n ${ui(`q${e}`,`toWorld${e} ? b${e}._tempQ : b${e}._tempQInv`)}`,body:`{\n ${ai(`lx${e}`,"fx","t")}\n ${ai(`ly${e}`,"fy","t")}\n ${ai(`lz${e}`,"fz","t")}\n if (convert${e}) {\n fx *= sc${e}x; fy *= sc${e}y; fz *= sc${e}z;\n ${ci("fx","fy","fz",`q${e}x`,`q${e}y`,`q${e}z`,`q${e}w`)}\n }\n let px = Math.fround(pos[o3] + fx * delta);\n let py = Math.fround(pos[o3 + 1] + fy * delta);\n let pz = Math.fround(pos[o3 + 2] + fz * delta);\n ${ai(`ox${e}`,"rx","t")}\n ${ai(`oy${e}`,"ry","t")}\n ${ai(`oz${e}`,"rz","t")}\n rx *= delta; ry *= delta; rz *= delta;\n if (rx !== 0 || ry !== 0 || rz !== 0) {\n if (world${e}) {\n px = Math.fround(px - pv${e}x); py = Math.fround(py - pv${e}y); pz = Math.fround(pz - pv${e}z);\n }\n if (rx !== 0) ${pi("rx",`aX${e}x`,`aX${e}y`,`aX${e}z`)}\n if (ry !== 0) ${pi("ry",`aY${e}x`,`aY${e}y`,`aY${e}z`)}\n if (rz !== 0) ${pi("rz",`aZ${e}x`,`aZ${e}y`,`aZ${e}z`)}\n if (world${e}) {\n px = Math.fround(px + pv${e}x); py = Math.fround(py + pv${e}y); pz = Math.fround(pz + pv${e}z);\n }\n }\n pos[o3] = px; pos[o3 + 1] = py; pos[o3 + 2] = pz;}`};case"InheritVelocity":return{setup:`const b${e} = behaviors[${e}];\n const ps${e} = b${e}.ps;\n const ev${e} = b${e}.mode === 'current' && ps${e} !== undefined ? ps${e}.emitterVelocity : undefined;\n const active${e} = ev${e} !== undefined;\n let ivx${e} = 0, ivy${e} = 0, ivz${e} = 0;\n if (active${e}) {\n ivx${e} = ev${e}.x; ivy${e} = ev${e}.y; ivz${e} = ev${e}.z;\n if (!ps${e}.worldSpace) {\n ${di(`sc${e}`,`b${e}._tempScaleInv`)}\n ${ui(`q${e}`,`b${e}._tempQInv`)}\n ivx${e} *= sc${e}x; ivy${e} *= sc${e}y; ivz${e} *= sc${e}z;\n ${ci(`ivx${e}`,`ivy${e}`,`ivz${e}`,`q${e}x`,`q${e}y`,`q${e}z`,`q${e}w`)}\n }\n }\n ${oi(`gm${e}`,`b${e}.multiplier`)}`,body:`if (active${e}) {\n ${ai(`gm${e}`,"m","t")}\n const f = m * delta;\n pos[o3] += ivx${e} * f; pos[o3 + 1] += ivy${e} * f; pos[o3 + 2] += ivz${e} * f;\n }`};default:return null}}const mi=new Map;function yi(t,e,i){const s=mi.get(i);if(void 0!==s)return s??void 0;const r=function(t,e){const i=`\n if (count === 0) return;\n if (store === undefined) {\n store = particles[0].store;\n if (store === undefined) {\n // Particles of some other implementation, without columns: run the behaviors as they are.\n for (const k of [${e.join(", ")}]) {\n const b = behaviors[k];\n for (let i = 0; i < count; i++) {\n const p = particles[i];\n if (p.age < p.life) b.update(p, delta);\n }\n }\n return;\n }\n }\n const pos = store.position, vel = store.velocity;\n const size = store.size, startSize = store.startSize;\n const color = store.color, startColor = store.startColor;\n const scalars = store.scalars;\n const rot = store.rotation, angVel = store.angularVelocity;\n const uvTile = store.uvTile, startSpeed = store.startSpeed;\n const mem = store.memory, ms = store.memoryStride;\n ${t.map(t=>t.setup).join("\n")}\n // The system keeps particles[i] on row i. Anything else (a hand-built\n // list) is caught by its ends and read through each particle's row.\n const mapped = particles[0].storeIndex !== 0 || particles[count - 1].storeIndex !== count - 1;\n for (let i = 0; i < count; i++) {\n const p = particles[i];\n const row = mapped ? p.storeIndex : i;\n const s = row * 3;\n const age = scalars[s], life = scalars[s + 1];\n if (age >= life) continue;\n const t = age / life;\n const o3 = row * 3, o4 = row * 4;\n ${t.map(t=>t.body).join("\n")}\n }`;try{return new Function("deps",`const tmpColor = new deps.Vector4View(new Float32Array(4), 0);\n return function (behaviors, particles, count, delta, store) {${i}};`)(ni)}catch(t){return}}(t,e);return mi.set(i,r??null),r}function vi(t){const e=[];let i=[],s=[],r=[],n=0;const o=()=>{if(0===s.length)return;const t=`${n}:${i.map(t=>t.type).join(",")}`,o=yi(s,r,t);if(void 0!==o)e.push({behaviors:i,run:o});else for(const t of i)e.push({behaviors:[t]});i=[],s=[],r=[]};for(let a=0;a<t.length;a++){const h=t[a],l=fi(h,a);null!==l?(0===s.length&&(n=a),i.push(h),s.push(l),r.push(a)):(o(),e.push({behaviors:[h]}))}return o(),e}var gi,xi;exports.BoxEmitFrom=void 0,(gi=exports.BoxEmitFrom||(exports.BoxEmitFrom={}))[gi.Volume=0]="Volume",gi[gi.Shell=1]="Shell",gi[gi.Edge=2]="Edge";class Si{constructor(t={}){this.type="box",this._point=[0,0,0],this.width=t.width??1,this.height=t.height??1,this.depth=t.depth??1,this.emitFrom=t.emitFrom??exports.BoxEmitFrom.Volume,this.boxThickness=t.boxThickness?[...t.boxThickness]:[0,0,0]}update(t,e){}initialize(t,e){const i=this._point;for(let t=0;t<3;t++)i[t]=2*S()-1;const s=Math.floor(3*S())%3;this.emitFrom===exports.BoxEmitFrom.Shell?i[s]=this.onSurface(s):this.emitFrom===exports.BoxEmitFrom.Edge&&(i[(s+1)%3]=this.onSurface((s+1)%3),i[(s+2)%3]=this.onSurface((s+2)%3)),t.position.set(i[0]*this.width/2,i[1]*this.height/2,i[2]*this.depth/2),t.velocity.set(0,0,t.startSpeed)}onSurface(t){const e=S()<.5?-1:1,i=this.boxThickness[t];return i<=0||S()<.5?e:e*(1-2*i*S())}toJSON(){return{type:"box",width:this.width,height:this.height,depth:this.depth,emitFrom:this.emitFrom,boxThickness:[...this.boxThickness]}}static fromJSON(t){return new Si({width:t.width,height:t.height,depth:t.depth,emitFrom:t.emitFrom,boxThickness:Array.isArray(t.boxThickness)?t.boxThickness:void 0})}clone(){return new Si({width:this.width,height:this.height,depth:this.depth,emitFrom:this.emitFrom,boxThickness:this.boxThickness})}}function wi(t,e,i,s){let r;switch(exports.EmitterMode.Random===t?e=S():exports.EmitterMode.Burst===t&&s.isBursting&&(e=s.burstParticleIndex/s.burstParticleCount),r=i>0?Math.floor(e/i)*i:e,t){case exports.EmitterMode.Loop:r%=1;break;case exports.EmitterMode.PingPong:r=Math.abs(r%2-1)}return r}exports.EmitterMode=void 0,(xi=exports.EmitterMode||(exports.EmitterMode={}))[xi.Random=0]="Random",xi[xi.Loop=1]="Loop",xi[xi.PingPong=2]="PingPong",xi[xi.Burst=3]="Burst";class bi{constructor(t,e,i){this.position=t??new H,this.rotation=e??new Z,this.scale=i??new H(1,1,1)}apply(t){t.position.multiply(this.scale).applyQuaternion(this.rotation).add(this.position);const e=t.velocity,i=e.length();if(0===i)return;e.multiply(this.scale).applyQuaternion(this.rotation);const s=e.length();s>0&&e.multiplyScalar(i/s)}isIdentity(){const{position:t,rotation:e,scale:i}=this;return 0===t.x&&0===t.y&&0===t.z&&0===e.x&&0===e.y&&0===e.z&&1===e.w&&1===i.x&&1===i.y&&1===i.z}toJSON(){const t={},{position:e,rotation:i,scale:s}=this;return 0===e.x&&0===e.y&&0===e.z||(t.position=[e.x,e.y,e.z]),0===i.x&&0===i.y&&0===i.z&&1===i.w||(t.rotation=[i.x,i.y,i.z,i.w]),1===s.x&&1===s.y&&1===s.z||(t.scale=[s.x,s.y,s.z]),t}static fromJSON(t){if(!t)return;const{position:e,rotation:i,scale:s}=t;return new bi(e?new H(e[0],e[1],e[2]):void 0,i?new Z(i[0],i[1],i[2],i[3]):void 0,s?new H(s[0],s[1],s[2]):void 0)}static toShapeJSON(t){return t&&!t.isIdentity()?{transform:t.toJSON()}:{}}clone(){return new bi(this.position.clone(),this.rotation.clone(),this.scale.clone())}}class zi{constructor(t={}){this.type="circle",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[],this.transform=t.transform}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e),s=X.lerp(1-this.thickness,1,S()),r=i*this.arc;t.position.x=Math.cos(r),t.position.y=Math.sin(r),t.position.z=0,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*s),this.transform?.apply(t)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new zi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?It(t.speed):void 0,transform:bi.fromJSON(t.transform),spread:t.spread})}clone(){return new zi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class Mi{constructor(t={}){this.type="cone",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.angle=t.angle??Math.PI/6,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[],this.transform=t.transform}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e),s=X.lerp(1-this.thickness,1,S()),r=i*this.arc,n=Math.sqrt(s),o=Math.sin(r),a=Math.cos(r);t.position.x=n*a,t.position.y=n*o,t.position.z=0;const h=this.angle*n;t.velocity.set(0,0,Math.cos(h)).addScaledVector(t.position,Math.sin(h)).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius),this.transform?.apply(t)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Mi({radius:t.radius,arc:t.arc,thickness:t.thickness,angle:t.angle,mode:t.mode,speed:t.speed?It(t.speed):void 0,transform:bi.fromJSON(t.transform),spread:t.spread})}clone(){return new Mi({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class _i{constructor(t={}){this.type="donut",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.donutRadius=t.donutRadius??.2*this.radius,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[],this.transform=t.transform,this._m1=new st}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e),s=S(),r=X.lerp(1-this.thickness,1,S()),n=i*this.arc,o=s*Math.PI*2,a=Math.sin(n),h=Math.cos(n);if(t.position.x=this.radius*h,t.position.y=this.radius*a,t.position.z=0,t.velocity.z=this.donutRadius*r*Math.sin(o),t.velocity.x=this.donutRadius*r*Math.cos(o)*h,t.velocity.y=this.donutRadius*r*Math.cos(o)*a,t.position.add(t.velocity),t.velocity.normalize().multiplyScalar(t.startSpeed),t.rotation instanceof Z){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(ue,t.velocity,ce),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"donut",radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new _i({radius:t.radius,arc:t.arc,thickness:t.thickness,donutRadius:t.donutRadius,mode:t.mode,speed:t.speed?It(t.speed):void 0,transform:bi.fromJSON(t.transform),spread:t.spread})}clone(){return new _i({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class Pi{constructor(t={}){this.type="edge",this.currentValue=0,this.radius=t.radius??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[]}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e);t.position.set((2*i-1)*this.radius,0,0),t.velocity.set(0,t.startSpeed,0)}toJSON(){return{type:"edge",radius:this.radius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new Pi({radius:t.radius,mode:t.mode,speed:t.speed?It(t.speed):void 0,spread:t.spread})}clone(){return new Pi({radius:this.radius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ti{constructor(t={}){this.type="grid",this.width=t.width??1,this.height=t.height??1,this.column=t.column??10,this.row=t.row??10,this.transform=t.transform}initialize(t){const e=Math.floor(S()*this.row),i=Math.floor(S()*this.column);t.position.x=i*this.width/this.column-this.width/2,t.position.y=e*this.height/this.row-this.height/2,t.position.z=0,t.velocity.set(0,0,t.startSpeed),this.transform?.apply(t)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row,...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Ti({...t,transform:bi.fromJSON(t.transform)})}clone(){return new Ti({width:this.width,height:this.height,column:this.column,row:this.row,transform:this.transform?.clone()})}update(t,e){}}class Vi{constructor(t={}){this.type="hemisphere",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[],this.transform=t.transform,this._m1=new st}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e),s=S(),r=X.lerp(1-this.thickness,1,S()),n=i*this.arc,o=Math.acos(s),a=Math.sin(n),h=Math.cos(n),l=Math.sin(o),c=Math.cos(o);if(t.position.x=l*h,t.position.y=l*a,t.position.z=c,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*r),t.rotation instanceof Z){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(ue,t.position,ce),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Vi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?It(t.speed):void 0,transform:bi.fromJSON(t.transform),spread:t.spread})}clone(){return new Vi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class Oi{constructor(t){this.type="point",this._m1=new st,this.transform=t}update(t,e){}initialize(t){const e=S(),i=S(),s=e*Math.PI*2,r=Math.acos(2*i-1),n=Math.cbrt(S()),o=Math.sin(s),a=Math.cos(s),h=Math.sin(r),l=Math.cos(r);if(t.velocity.x=n*h*a,t.velocity.y=n*h*o,t.velocity.z=n*l,t.velocity.multiplyScalar(t.startSpeed),t.position.setScalar(0),t.rotation instanceof Z){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(ue,t.velocity,ce),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"point",...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Oi(bi.fromJSON(t?.transform))}clone(){return new Oi(this.transform?.clone())}}class Ci{constructor(t={}){this.type="sphere",this.currentValue=0,this.radius=t.radius??10,this.arc=t.arc??2*Math.PI,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[],this.transform=t.transform,this._m1=new st}update(t,e){exports.EmitterMode.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e),s=S(),r=X.lerp(1-this.thickness,1,S()),n=i*this.arc,o=Math.acos(2*s-1),a=Math.sin(n),h=Math.cos(n),l=Math.sin(o),c=Math.cos(o);if(t.position.x=l*h,t.position.y=l*a,t.position.z=c,t.velocity.copy(t.position).multiplyScalar(t.startSpeed),t.position.multiplyScalar(this.radius*r),t.rotation instanceof Z){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(ue,t.position,ce),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Ci({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?It(t.speed):void 0,transform:bi.fromJSON(t.transform),spread:t.spread})}clone(){return new Ci({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class Fi{constructor(t={}){this.type="rectangle",this.currentValue=0,this.width=t.width??10,this.height=t.height??10,this.thickness=t.thickness??1,this.mode=t.mode??exports.EmitterMode.Random,this.spread=t.spread??0,this.speed=t.speed??new Ct(1),this.memory=[],this.transform=t.transform,this._m1=new st}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=wi(this.mode,this.currentValue,this.spread,e);S();const s=i*(2*(this.width+this.height));let r,n;s<this.width?(r=s-this.width/2,n=-this.height/2):s<this.width+this.height?(r=this.width/2,n=s-this.width-this.height/2):s<2*this.width+this.height?(r=this.width/2-(s-this.width-this.height),n=this.height/2):(r=-this.width/2,n=this.height/2-(s-2*this.width-this.height));const o=S(),a=1-this.thickness*o;if(t.position.x=r*a,t.position.y=n*a,t.position.z=0,t.velocity.x=r,t.velocity.y=n,t.velocity.z=0,t.velocity.normalize().multiplyScalar(t.startSpeed),t.rotation instanceof Z){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(ue,t.velocity,ce),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"rectangle",width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON(),...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Fi({width:t.width,height:t.height,thickness:t.thickness,mode:t.mode,speed:t.speed?It(t.speed):void 0,transform:bi.fromJSON(t.transform),spread:t.spread})}clone(){return new Fi({width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}const Bi={box:{type:"box",params:[["width",["number"]],["height",["number"]],["depth",["number"]],["emitFrom",["number"]],["boxThickness",["vec3"]]],constructor:Si,loadJSON:Si.fromJSON},circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:zi,loadJSON:zi.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Mi,loadJSON:Mi.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:_i,loadJSON:_i.fromJSON},edge:{type:"edge",params:[["radius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Pi,loadJSON:Pi.fromJSON},point:{type:"point",params:[],constructor:Oi,loadJSON:Oi.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Ci,loadJSON:Ci.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Vi,loadJSON:Vi.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:Ti,loadJSON:Ti.fromJSON},rectangle:{type:"rectangle",params:[["width",["number"]],["height",["number"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:Fi,loadJSON:Fi.fromJSON}};function Ai(t,e){return Bi[t.type].loadJSON(t,e)}const $i=[];function Ii(t){if(!$i.find(e=>e.id===t.id)){t.initialize();for(const e of t.emitterShapes)Bi[e.type]||(Bi[e.type]=e);for(const e of t.behaviors)si[e.type]||(si[e.type]=e)}}class Ei{get mesh(){return this._mesh}set mesh(e){if(this._mesh=e,!e)return;const i=e.getVerticesData(t.VertexBuffer.PositionKind),s=e.getIndices();if(!i||!s)return;this._positions=new Float32Array(i),this._indices=new Int32Array(s),this._triangleIndexToArea.length=0;let r=0;const n=s.length/3;this._triangleIndexToArea.push(0);const o=new H,a=new H,h=new H;for(let t=0;t<n;t++){const e=s[3*t],n=s[3*t+1],l=s[3*t+2];o.set(i[3*e],i[3*e+1],i[3*e+2]),a.set(i[3*n],i[3*n+1],i[3*n+2]),h.set(i[3*l],i[3*l+1],i[3*l+2]),a.sub(o),h.sub(o);const c=new H;c.crossVectors(a,h),r+=.5*c.length(),this._triangleIndexToArea.push(r)}}constructor(t,e,i){this.type="mesh_surface",this._triangleIndexToArea=[],this._meshReferenceId=e,this.transform=i,t&&(this.mesh=t)}initialize(t){if(!this._positions||!this._indices)return t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed),void this.transform?.apply(t);const e=this._triangleIndexToArea.length-1;let i=0,s=e;const r=S()*this._triangleIndexToArea[e];for(;i+1<s;){const t=Math.floor((i+s)/2);r<this._triangleIndexToArea[t]?s=t:i=t}let n=S(),o=S();n+o>1&&(n=1-n,o=1-o);const a=this._indices[3*i],h=this._indices[3*i+1],l=this._indices[3*i+2],c=this._positions[3*a],u=this._positions[3*a+1],d=this._positions[3*a+2],p=this._positions[3*h]-c,f=this._positions[3*h+1]-u,m=this._positions[3*h+2]-d,y=this._positions[3*l]-c,v=this._positions[3*l+1]-u,g=this._positions[3*l+2]-d;t.position.set(c+p*n+y*o,u+f*n+v*o,d+m*n+g*o);const x=f*g-m*v,w=m*y-p*g,b=p*v-f*y,z=Math.sqrt(x*x+w*w+b*b)||1;t.velocity.set(x/z,w/z,b/z).multiplyScalar(t.startSpeed),this.transform?.apply(t)}toJSON(){return{type:"mesh_surface",mesh:this._mesh?this._mesh.uniqueId?.toString():this._meshReferenceId??"",...bi.toShapeJSON(this.transform)}}static fromJSON(t){return new Ei(void 0,t?.mesh,bi.fromJSON(t?.transform))}clone(){return new Ei(this._mesh,this._meshReferenceId,this.transform?.clone())}update(t,e){}}const Ni={id:"babylon.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["mesh",["mesh"]]],constructor:Ei,loadJSON:t=>Ei.fromJSON(t)}],behaviors:[]};const Li={};let Ri=!1;function Di(){Ri||(Li.tile_pars_vertex="\n#ifdef UV_TILE\n attribute float uvTile;\n uniform vec2 tileCount;\n\n mat3 makeTileTransform(float tileIndex) {\n float col = mod(tileIndex, tileCount.x);\n float row = (tileCount.y - floor(tileIndex / tileCount.x) - 1.0);\n return mat3(\n 1.0 / tileCount.x, 0.0, 0.0,\n 0.0, 1.0 / tileCount.y, 0.0,\n col / tileCount.x, row / tileCount.y, 1.0\n );\n }\n#else\n mat3 makeTileTransform(float tileIndex) {\n return mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);\n }\n#endif\n\n#if defined(USE_UV)\n varying vec2 vUv;\n #ifdef TILE_BLEND\n varying vec2 vUvNext;\n varying float vUvBlend;\n #endif\n#endif\n",Li.tile_vertex="\n#ifdef UV_TILE\n mat3 tileTransform = makeTileTransform(floor(uvTile));\n #ifdef TILE_BLEND\n mat3 nextTileTransform = makeTileTransform(ceil(uvTile));\n vUvBlend = fract(uvTile);\n #endif\n#else\n mat3 tileTransform = makeTileTransform(0.0);\n#endif\n\n#if defined(USE_UV)\n vUv = (tileTransform * vec3(uv, 1.0)).xy;\n #if defined(TILE_BLEND) && defined(UV_TILE)\n vUvNext = (nextTileTransform * vec3(uv, 1.0)).xy;\n #endif\n#endif\n",Li.tile_pars_fragment="\n#if defined(USE_UV)\n varying vec2 vUv;\n #ifdef TILE_BLEND\n varying vec2 vUvNext;\n varying float vUvBlend;\n #endif\n#endif\n",Li.tile_fragment="\n#ifdef USE_MAP\n vec4 texelColor = texture2D(map, vUv);\n #ifdef TILE_BLEND\n texelColor = mix(texelColor, texture2D(map, vUvNext), vUvBlend);\n #endif\n diffuseColor *= texelColor;\n#endif\n",Li.soft_pars_vertex="\n#ifdef SOFT_PARTICLES\n varying vec4 projPosition;\n varying float linearDepth;\n#endif\n",Li.soft_vertex="\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n",Li.soft_pars_fragment="\n#ifdef SOFT_PARTICLES\n uniform sampler2D depthTexture;\n uniform vec4 projParams;\n uniform vec2 softParams;\n\n varying vec4 projPosition;\n varying float linearDepth;\n\n #define SOFT_NEAR_FADE softParams.x\n #define SOFT_INV_FADE_DISTANCE softParams.y\n\n #define zNear projParams.x\n #define zFar projParams.y\n\n float linearize_depth(float d) {\n return (zFar * zNear) / (zFar - d * (zFar - zNear));\n }\n#endif\n",Li.soft_fragment="\n#ifdef SOFT_PARTICLES\n\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float viewDepth = linearize_depth(readDepth);\n float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));\n\n gl_FragColor *= softParticlesFade;\n#endif\n",Ri=!0)}const Ui="\n#ifdef FOG\nvarying vec3 vFogDistance;\n#endif\n";function qi(t){return`\n#ifdef FOG\n vFogDistance = ${t};\n#endif\n`}const ki="\n#ifdef FOG\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\n\nfloat quarksFogFactor() {\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n float fogDistance = length(vFogDistance);\n if (vFogInfos.x == 3.0) {\n fogCoeff = (fogEnd - fogDistance) / (fogEnd - fogStart);\n } else if (vFogInfos.x == 1.0) {\n fogCoeff = exp(-fogDistance * fogDensity);\n } else if (vFogInfos.x == 2.0) {\n fogCoeff = exp(-fogDistance * fogDistance * fogDensity * fogDensity);\n }\n return clamp(fogCoeff, 0.0, 1.0);\n}\n#endif\n";function Ji(t){return`\n#ifdef FOG\n {\n float fogFactor = quarksFogFactor();\n#ifdef FOG_ADDITIVE\n ${t} *= fogFactor;\n#else\n ${t} = mix(vFogColor, ${t}, fogFactor);\n#endif\n }\n#endif\n`}const Qi="\n#ifdef FOG\nvarying vFogDistance: vec3f;\n#endif\n";function Gi(t){return`\n#ifdef FOG\n vertexOutputs.vFogDistance = ${t};\n#endif\n`}const Wi="\n#ifdef FOG\nuniform vFogInfos: vec4f;\nuniform vFogColor: vec3f;\nvarying vFogDistance: vec3f;\n\nfn quarksFog(rgb: vec3f, fogDistanceVector: vec3f) -> vec3f {\n var fogCoeff = 1.0;\n let fogStart = uniforms.vFogInfos.y;\n let fogEnd = uniforms.vFogInfos.z;\n let fogDensity = uniforms.vFogInfos.w;\n let fogDistance = length(fogDistanceVector);\n if (uniforms.vFogInfos.x == 3.0) {\n fogCoeff = (fogEnd - fogDistance) / (fogEnd - fogStart);\n } else if (uniforms.vFogInfos.x == 1.0) {\n fogCoeff = exp(-fogDistance * fogDensity);\n } else if (uniforms.vFogInfos.x == 2.0) {\n fogCoeff = exp(-fogDistance * fogDistance * fogDensity * fogDensity);\n }\n let fogFactor = clamp(fogCoeff, 0.0, 1.0);\n#ifdef FOG_ADDITIVE\n return rgb * fogFactor;\n#else\n return mix(uniforms.vFogColor, rgb, fogFactor);\n#endif\n}\n#endif\n";function ji(t){return`\n#ifdef FOG\n ${t} = vec4f(quarksFog(${t}.rgb, fragmentInputs.vFogDistance), ${t}.a);\n#endif\n`}var Yi=`\nattribute vec3 position;\nattribute vec2 uv;\nattribute vec3 normal;\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\n${Ui}\nvoid main() {\n vec3 scaledPosition = position * size;\n vec3 rotatedPosition = applyQuaternion(scaledPosition, rotation);\n vec3 rotatedNormal = normalize(applyQuaternion(normal, rotation));\n vec3 localPos = rotatedPosition + offset;\n\n vec4 worldPos = world * vec4(localPos, 1.0);\n vec4 viewPos = view * worldPos;\n gl_Position = projection * viewPos;\n${qi("viewPos.xyz")}\n\n vWorldPos = worldPos.xyz;\n vNormal = normalize((world * vec4(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n#else\n vUV = uv;\n#endif\n\n vColor = color;\n}\n`,Xi=`\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n#ifdef SOFT_PARTICLES\nuniform sampler2D depthTexture;\nuniform vec2 softParams;\nuniform vec4 projParams;\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform float alphaTest;\n#endif\n\n${ki}\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n #ifdef TILE_BLEND\n vec4 texColor2 = texture2D(map, vUV2);\n texColor = mix(texColor, texColor2, vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_COLOR_AS_ALPHA\n baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < alphaTest) discard;\n#else\n if (baseColor.a < 0.01) discard;\n#endif\n\n${Ji("baseColor.rgb")}\n gl_FragColor = baseColor;\n\n#ifdef SOFT_PARTICLES\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float zNear = projParams.x;\n float zFar = projParams.y;\n float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);\n gl_FragColor *= fade;\n#endif\n}\n`,Zi=`\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifndef MESH_UNLIT\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform vec3 ambientColor;\n#endif\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n#if defined(USE_ENVMAP_ATLAS) || defined(MESH_RIM)\nuniform vec3 eyePosition;\n#endif\n\n#ifdef MESH_RIM\nuniform vec3 rimColor;\nuniform vec2 rimParams;\n#endif\n\n// One 3×2 atlas (px py pz / nx ny nz). Avoids samplerCube and multi-face\n// sampler bindings that raise GL_INVALID_OPERATION on iOS WebKit.\n#ifdef USE_ENVMAP_ATLAS\nuniform sampler2D envAtlas;\nuniform float reflectionLevel;\n\nvec3 sampleEnvAtlas(vec3 r) {\n vec3 a = abs(r);\n vec2 localUV;\n float cellX;\n float cellY;\n // Atlas layout: +X +Y +Z on row 0, -X -Y -Z on row 1.\n if (a.x >= a.y && a.x >= a.z) {\n cellX = 0.0;\n if (r.x >= 0.0) {\n cellY = 0.0;\n localUV = vec2(-r.z, -r.y) / a.x * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2(r.z, -r.y) / a.x * 0.5 + 0.5;\n }\n } else if (a.y >= a.z) {\n cellX = 1.0;\n if (r.y >= 0.0) {\n cellY = 0.0;\n localUV = vec2(r.x, r.z) / a.y * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2(r.x, -r.z) / a.y * 0.5 + 0.5;\n }\n } else {\n cellX = 2.0;\n if (r.z >= 0.0) {\n cellY = 0.0;\n localUV = vec2(r.x, -r.y) / a.z * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2(-r.x, -r.y) / a.z * 0.5 + 0.5;\n }\n }\n vec2 uv = (vec2(cellX, cellY) + clamp(localUV, 0.0, 1.0)) / vec2(3.0, 2.0);\n return texture2D(envAtlas, uv).rgb;\n}\n#endif\n\n#ifdef SOFT_PARTICLES\nuniform sampler2D depthTexture;\nuniform vec2 softParams;\nuniform vec4 projParams;\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform float alphaTest;\n#endif\n\n${ki}\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n #ifdef TILE_BLEND\n vec4 texColor2 = texture2D(map, vUV2);\n texColor = mix(texColor, texColor2, vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < alphaTest) discard;\n#else\n if (baseColor.a < 0.01) discard;\n#endif\n\n vec3 N = normalize(vNormal);\n#ifdef MESH_UNLIT\n vec3 color = baseColor.rgb;\n#else\n vec3 L = normalize(-lightDirection);\n float NdotL = max(dot(N, L), 0.0);\n vec3 litColor = ambientColor + lightColor * NdotL;\n\n vec3 color = baseColor.rgb * litColor;\n#endif\n\n#ifdef USE_ENVMAP_ATLAS\n vec3 viewDir = normalize(vWorldPos - eyePosition);\n vec3 reflectionCoords = reflect(viewDir, N);\n color += sampleEnvAtlas(reflectionCoords) * reflectionLevel;\n#endif\n\n#ifdef MESH_RIM\n // Fresnel: strongest where the surface turns away from the camera.\n vec3 V = normalize(eyePosition - vWorldPos);\n float rim = pow(1.0 - abs(dot(N, V)), rimParams.x) * rimParams.y;\n #ifdef MESH_RIM_MIX\n color = mix(color, rimColor, clamp(rim, 0.0, 1.0));\n #else\n color += rimColor * rim;\n #endif\n#endif\n\n${Ji("color")}\n gl_FragColor = vec4(color, baseColor.a);\n\n#ifdef SOFT_PARTICLES\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float zNear = projParams.x;\n float zFar = projParams.y;\n float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);\n gl_FragColor *= fade;\n#endif\n}\n`,Hi=`\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute float rotation;\nattribute float uvTile;\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nuniform mat4 worldViewProjection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n#ifdef PIVOT\n// Quad offset in particle-size units: xy in the quad's plane, z toward the camera.\nuniform vec3 pivot;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef SIZE_LIMITS\n// Smallest and largest size a particle may have on screen, as fractions of the viewport height.\nuniform vec2 sizeLimits;\n#endif\n${Ui}\nvoid main() {\n float c = cos(rotation);\n float s = sin(rotation);\n\n#ifdef SIZE_LIMITS\n // The particle's size on screen as a fraction of the viewport height, held\n // between the limits; a perspective projection divides by the view depth.\n vec4 limitCenter = view * world * vec4(offset, 1.0);\n float limitDepth = abs(projection[2][3]) > 0.0 ? abs(limitCenter.z) : 1.0;\n float screenSize = max(abs(size.x), abs(size.y)) * projection[1][1] / (2.0 * limitDepth);\n float sizeScale = screenSize > 0.0 ? clamp(screenSize, sizeLimits.x, sizeLimits.y) / screenSize : 1.0;\n vec3 limitedSize = size * sizeScale;\n#else\n vec3 limitedSize = size;\n#endif\n // A negative size mirrors the quad, which is how flipped particles arrive.\n vec2 alignedPosition = position.xy * limitedSize.xy;\n#ifdef PIVOT\n // The pivot turns with the particle but is not mirrored with it.\n alignedPosition += pivot.xy * abs(limitedSize.xy);\n#endif\n vec2 rotatedPosition;\n rotatedPosition.x = c * alignedPosition.x - s * alignedPosition.y;\n rotatedPosition.y = s * alignedPosition.x + c * alignedPosition.y;\n\n#ifdef HORIZONTAL\n vec4 mvPosition = world * vec4(offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.z -= rotatedPosition.y;\n#ifdef PIVOT\n mvPosition.y += pivot.z * abs(limitedSize.x);\n#endif\n mvPosition = view * mvPosition;\n#elif defined(VERTICAL)\n vec4 mvPosition = world * vec4(offset, 1.0);\n mvPosition.y += rotatedPosition.y;\n mvPosition = view * mvPosition;\n mvPosition.x += rotatedPosition.x;\n#else\n vec4 mvPosition = view * world * vec4(offset, 1.0);\n mvPosition.xy += rotatedPosition;\n#endif\n#ifdef PIVOT\n#ifndef HORIZONTAL\n // Toward the camera along its view axis, whichever way the view space\n // faces: anything in front of the camera has the sign of the far side.\n mvPosition.z -= sign(mvPosition.z) * pivot.z * abs(limitedSize.x);\n#endif\n#endif\n\n gl_Position = projection * mvPosition;\n${qi("mvPosition.xyz")}\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n`,Ki=`\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute float rotation;\nattribute float uvTile;\nattribute vec4 velocity;\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nuniform float speedFactor;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n#ifdef PIVOT\n// Streak offset in particle-size units: x from head to tail, y across.\nuniform vec3 pivot;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef SIZE_LIMITS\n// Smallest and largest size a particle may have on screen, as fractions of the viewport height.\nuniform vec2 sizeLimits;\n#endif\n${Ui}\nvoid main() {\n float lengthFactor = velocity.w;\n // A flipped particle arrives with a negative size: the streak keeps its\n // extent and mirrors its texture instead (see quadUV below).\n float avgSize = (abs(size.x) + abs(size.y)) * 0.5;\n vec4 mvPosition = view * world * vec4(offset, 1.0);\n#ifdef SIZE_LIMITS\n // The streak's width on screen as a fraction of the viewport height, held\n // between the limits; a perspective projection divides by the view depth.\n float limitDepth = abs(projection[2][3]) > 0.0 ? abs(mvPosition.z) : 1.0;\n float screenSize = avgSize * projection[1][1] / (2.0 * limitDepth);\n if (screenSize > 0.0) {\n avgSize *= clamp(screenSize, sizeLimits.x, sizeLimits.y) / screenSize;\n }\n#endif\n vec3 viewVelocity = mat3(view * world) * velocity.xyz;\n float vlength = length(viewVelocity);\n // Stretch direction is the velocity direction; only a genuinely motionless particle has none.\n // Deriving it via normalize keeps the stretch aligned even when the speed contribution is ~0\n // (e.g. speedFactor 0), instead of collapsing the whole burst onto a fixed screen axis.\n vec3 vdir = vlength > 0.000001 ? viewVelocity / vlength : vec3(0.0, 0.0, 1.0);\n vec3 side = normalize(cross(mvPosition.xyz, vdir));\n mvPosition.xyz += position.y * side * avgSize;\n // Equivalent to viewVelocity * (1.0 + lengthFactor / vlength) for moving particles, but the\n // size-based term (vdir * lengthFactor) survives when the velocity contribution vanishes.\n mvPosition.xyz -= (position.x + 0.5) * (viewVelocity + vdir * lengthFactor) * avgSize;\n#ifdef PIVOT\n // In particle-size units along the quad's own axes: x from head to tail, y across.\n mvPosition.xyz += (pivot.y * side - pivot.x * vdir) * avgSize;\n#endif\n gl_Position = projection * mvPosition;\n${qi("mvPosition.xyz")}\n vec2 quadUV = vec2(size.x < 0.0 ? 1.0 - uv.x : uv.x, size.y < 0.0 ? 1.0 - uv.y : uv.y);\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = quadUV / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = quadUV / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n #else\n vUV = quadUV;\n #endif\n\n vColor = color;\n}\n`,ts=`\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n${ki}\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n baseColor *= texColor;\n#endif\n\n if (baseColor.a < 0.01) discard;\n\n${Ji("baseColor.rgb")}\n gl_FragColor = baseColor;\n}\n`,es=`\nattribute vec3 position;\nattribute vec3 previous;\nattribute vec3 next;\nattribute float side;\nattribute float width;\nattribute vec2 uv;\nattribute vec4 color;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform float lineWidth;\nuniform vec2 resolution;\nuniform float sizeAttenuation;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n\nvec2 fix(vec4 i, float aspect) {\n vec2 res = i.xy / i.w;\n res.x *= aspect;\n return res;\n}\n\n${Ui}\nvoid main() {\n float aspect = resolution.x / resolution.y;\n vec4 finalPosition = projection * view * vec4(position, 1.0);\n vec4 prevPos = projection * view * vec4(previous, 1.0);\n vec4 nextPos = projection * view * vec4(next, 1.0);\n\n vec2 currentP = fix(finalPosition, aspect);\n vec2 prevP = fix(prevPos, aspect);\n vec2 nextP = fix(nextPos, aspect);\n\n float w = lineWidth * width;\n vec2 dir;\n if (distance(nextP, currentP) < 0.0001) {\n dir = normalize(currentP - prevP);\n } else if (distance(prevP, currentP) < 0.0001) {\n dir = normalize(nextP - currentP);\n } else {\n vec2 dir1 = normalize(currentP - prevP);\n vec2 dir2 = normalize(nextP - currentP);\n dir = normalize(dir1 + dir2);\n }\n vec4 normal = vec4(-dir.y, dir.x, 0.0, 1.0);\n normal.xy *= 0.5 * w;\n normal *= projection;\n if (sizeAttenuation == 0.0) {\n normal.xy *= finalPosition.w;\n normal.xy /= (vec4(resolution, 0.0, 1.0) * projection).xy;\n }\n finalPosition.xy += normal.xy * side;\n gl_Position = finalPosition;\n${qi("(view * vec4(position, 1.0)).xyz")}\n vUV = uv;\n vColor = color;\n}\n`;const is=2048,ss=2047;class rs{constructor(t){this.counts=new Uint32Array(is),this.floatView=new Float32Array(1),this.uintView=new Uint32Array(this.floatView.buffer),this.keys=new Uint32Array(t),this.orderA=new Uint32Array(t),this.orderB=new Uint32Array(t)}ensure(t){this.keys.length<t&&(this.keys=new Uint32Array(t),this.orderA=new Uint32Array(t),this.orderB=new Uint32Array(t))}floatKey(t,e){this.floatView[0]=t;const i=this.uintView[0];return e?~i>>>0:i}}var ns=`\nattribute position: vec3f;\nattribute uv: vec2f;\nattribute normal: vec3f;\nattribute offset: vec3f;\nattribute color: vec4f;\nattribute size: vec3f;\nattribute rotation: vec4f;\nattribute uvTile: f32;\n\nuniform world: mat4x4f;\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\n\n#ifdef UV_TILE\nuniform tileCountX: f32;\nuniform tileCountY: f32;\n#endif\n\nvarying vUV: vec2f;\nvarying vColor: vec4f;\nvarying vNormal: vec3f;\nvarying vWorldPos: vec3f;\n\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n\n#ifdef SOFT_PARTICLES\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\nfn applyQuaternion(v: vec3f, q: vec4f) -> vec3f {\n let qVec = q.xyz;\n let qW = q.w;\n let t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\n${Qi}\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let scaledPosition = vertexInputs.position * vertexInputs.size;\n let rotatedPosition = applyQuaternion(scaledPosition, vertexInputs.rotation);\n let rotatedNormal = normalize(applyQuaternion(vertexInputs.normal, vertexInputs.rotation));\n let localPos = rotatedPosition + vertexInputs.offset;\n\n let worldPos = uniforms.world * vec4f(localPos, 1.0);\n let viewPos = uniforms.view * worldPos;\n let clipPosition = uniforms.projection * viewPos;\n vertexOutputs.position = clipPosition;\n${Gi("viewPos.xyz")}\n\n vertexOutputs.vWorldPos = worldPos.xyz;\n vertexOutputs.vNormal = normalize((uniforms.world * vec4f(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n vertexOutputs.projPosition = clipPosition;\n vertexOutputs.linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n let tc = vec2f(uniforms.tileCountX, uniforms.tileCountY);\n let baseTile = floor(vertexInputs.uvTile);\n let tileU = (baseTile % tc.x) / tc.x;\n let tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV = vertexInputs.uv / tc + vec2f(tileU, tileV);\n #ifdef TILE_BLEND\n let nextTile = ceil(vertexInputs.uvTile);\n let nextU = (nextTile % tc.x) / tc.x;\n let nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV2 = vertexInputs.uv / tc + vec2f(nextU, nextV);\n vertexOutputs.vTileBlend = fract(vertexInputs.uvTile);\n #endif\n#else\n vertexOutputs.vUV = vertexInputs.uv;\n#endif\n\n vertexOutputs.vColor = vertexInputs.color;\n}\n`,os=`\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n\n#ifdef USE_MAP\nvar mapSampler: sampler;\nvar map: texture_2d<f32>;\n#endif\n\n#ifdef SOFT_PARTICLES\nvar depthTextureSampler: sampler;\nvar depthTexture: texture_2d<f32>;\nuniform softParams: vec2f;\nuniform projParams: vec4f;\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform alphaTest: f32;\n#endif\n\n${Wi}\n@fragment\nfn main(input: FragmentInputs) -> FragmentOutputs {\n var baseColor = fragmentInputs.vColor;\n\n#ifdef USE_MAP\n var texColor = textureSample(map, mapSampler, fragmentInputs.vUV);\n #ifdef TILE_BLEND\n let texColor2 = textureSample(map, mapSampler, fragmentInputs.vUV2);\n texColor = mix(texColor, texColor2, fragmentInputs.vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_COLOR_AS_ALPHA\n baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < uniforms.alphaTest) { discard; }\n#else\n if (baseColor.a < 0.01) { discard; }\n#endif\n\n#ifdef SOFT_PARTICLES\n var p2 = fragmentInputs.projPosition.xy / fragmentInputs.projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n let readDepth = textureSample(depthTexture, depthTextureSampler, p2).r;\n let zNear = uniforms.projParams.x;\n let zFar = uniforms.projParams.y;\n let viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n let fade = clamp(uniforms.softParams.y * ((viewDepth - uniforms.softParams.x) - fragmentInputs.linearDepth), 0.0, 1.0);\n baseColor *= fade;\n#endif\n\n${ji("baseColor")}\n fragmentOutputs.color = baseColor;\n}\n`,as=`\nvarying vUV: vec2f;\nvarying vColor: vec4f;\nvarying vNormal: vec3f;\nvarying vWorldPos: vec3f;\n\n#ifndef MESH_UNLIT\nuniform lightDirection: vec3f;\nuniform lightColor: vec3f;\nuniform ambientColor: vec3f;\n#endif\n\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n\n#ifdef USE_MAP\nvar mapSampler: sampler;\nvar map: texture_2d<f32>;\n#endif\n\n#if defined(USE_ENVMAP_ATLAS) || defined(MESH_RIM)\nuniform eyePosition: vec3f;\n#endif\n\n#ifdef MESH_RIM\nuniform rimColor: vec3f;\nuniform rimParams: vec2f;\n#endif\n\n#ifdef USE_ENVMAP_ATLAS\nvar envAtlasSampler: sampler;\nvar envAtlas: texture_2d<f32>;\nuniform reflectionLevel: f32;\n\nfn sampleEnvAtlas(r: vec3f) -> vec3f {\n let a = abs(r);\n var localUV: vec2f;\n var cellX: f32;\n var cellY: f32;\n if (a.x >= a.y && a.x >= a.z) {\n cellX = 0.0;\n if (r.x >= 0.0) {\n cellY = 0.0;\n localUV = vec2f(-r.z, -r.y) / a.x * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2f(r.z, -r.y) / a.x * 0.5 + 0.5;\n }\n } else if (a.y >= a.z) {\n cellX = 1.0;\n if (r.y >= 0.0) {\n cellY = 0.0;\n localUV = vec2f(r.x, r.z) / a.y * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2f(r.x, -r.z) / a.y * 0.5 + 0.5;\n }\n } else {\n cellX = 2.0;\n if (r.z >= 0.0) {\n cellY = 0.0;\n localUV = vec2f(r.x, -r.y) / a.z * 0.5 + 0.5;\n } else {\n cellY = 1.0;\n localUV = vec2f(-r.x, -r.y) / a.z * 0.5 + 0.5;\n }\n }\n let uv = (vec2f(cellX, cellY) + clamp(localUV, vec2f(0.0), vec2f(1.0))) / vec2f(3.0, 2.0);\n return textureSample(envAtlas, envAtlasSampler, uv).rgb;\n}\n#endif\n\n#ifdef SOFT_PARTICLES\nvar depthTextureSampler: sampler;\nvar depthTexture: texture_2d<f32>;\nuniform softParams: vec2f;\nuniform projParams: vec4f;\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform alphaTest: f32;\n#endif\n\n${Wi}\n@fragment\nfn main(input: FragmentInputs) -> FragmentOutputs {\n var baseColor = fragmentInputs.vColor;\n\n#ifdef USE_MAP\n var texColor = textureSample(map, mapSampler, fragmentInputs.vUV);\n #ifdef TILE_BLEND\n let texColor2 = textureSample(map, mapSampler, fragmentInputs.vUV2);\n texColor = mix(texColor, texColor2, fragmentInputs.vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < uniforms.alphaTest) { discard; }\n#else\n if (baseColor.a < 0.01) { discard; }\n#endif\n\n let N = normalize(fragmentInputs.vNormal);\n#ifdef MESH_UNLIT\n var color = baseColor.rgb;\n#else\n let L = normalize(-uniforms.lightDirection);\n let NdotL = max(dot(N, L), 0.0);\n let litColor = uniforms.ambientColor + uniforms.lightColor * NdotL;\n\n var color = baseColor.rgb * litColor;\n#endif\n\n#ifdef USE_ENVMAP_ATLAS\n let viewDir = normalize(fragmentInputs.vWorldPos - uniforms.eyePosition);\n let reflectionCoords = reflect(viewDir, N);\n color += sampleEnvAtlas(reflectionCoords) * uniforms.reflectionLevel;\n#endif\n\n#ifdef MESH_RIM\n // Fresnel: strongest where the surface turns away from the camera.\n let V = normalize(uniforms.eyePosition - fragmentInputs.vWorldPos);\n let rimTerm = pow(1.0 - abs(dot(N, V)), uniforms.rimParams.x) * uniforms.rimParams.y;\n #ifdef MESH_RIM_MIX\n color = mix(color, uniforms.rimColor, clamp(rimTerm, 0.0, 1.0));\n #else\n color += uniforms.rimColor * rimTerm;\n #endif\n#endif\n\n var finalColor = vec4f(color, baseColor.a);\n\n#ifdef SOFT_PARTICLES\n var p2 = fragmentInputs.projPosition.xy / fragmentInputs.projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n let readDepth = textureSample(depthTexture, depthTextureSampler, p2).r;\n let zNear = uniforms.projParams.x;\n let zFar = uniforms.projParams.y;\n let viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n let fade = clamp(uniforms.softParams.y * ((viewDepth - uniforms.softParams.x) - fragmentInputs.linearDepth), 0.0, 1.0);\n finalColor *= fade;\n#endif\n\n${ji("finalColor")}\n fragmentOutputs.color = finalColor;\n}\n`,hs=`\n// Per-vertex attributes\nattribute position: vec3f;\nattribute uv: vec2f;\n\n// Per-instance attributes\nattribute offset: vec3f;\nattribute color: vec4f;\nattribute size: vec3f;\nattribute rotation: f32;\nattribute uvTile: f32;\n\n// Uniforms\nuniform world: mat4x4f;\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\n\n#ifdef UV_TILE\nuniform tileCountX: f32;\nuniform tileCountY: f32;\n#endif\n\n#ifdef PIVOT\n// Quad offset in particle-size units: xy in the quad's plane, z toward the camera.\nuniform pivot: vec3f;\n#endif\n\n// Varyings\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n#ifdef SOFT_PARTICLES\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n#ifdef SIZE_LIMITS\n// Smallest and largest size a particle may have on screen, as fractions of the viewport height.\nuniform sizeLimits: vec2f;\n#endif\n${Qi}\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let c = cos(vertexInputs.rotation);\n let s = sin(vertexInputs.rotation);\n\n#ifdef SIZE_LIMITS\n // The particle's size on screen as a fraction of the viewport height, held\n // between the limits; a perspective projection divides by the view depth.\n let limitCenter = uniforms.view * uniforms.world * vec4f(vertexInputs.offset, 1.0);\n let limitDepth = select(1.0, abs(limitCenter.z), abs(uniforms.projection[2][3]) > 0.0);\n let screenSize = max(abs(vertexInputs.size.x), abs(vertexInputs.size.y)) * uniforms.projection[1][1] / (2.0 * limitDepth);\n let sizeScale = select(1.0, clamp(screenSize, uniforms.sizeLimits.x, uniforms.sizeLimits.y) / screenSize, screenSize > 0.0);\n let limitedSize = vertexInputs.size * sizeScale;\n#else\n let limitedSize = vertexInputs.size;\n#endif\n // A negative size mirrors the quad, which is how flipped particles arrive.\n var alignedPosition = vertexInputs.position.xy * limitedSize.xy;\n#ifdef PIVOT\n // The pivot turns with the particle but is not mirrored with it.\n alignedPosition += uniforms.pivot.xy * abs(limitedSize.xy);\n#endif\n let rotatedPosition = vec2f(\n c * alignedPosition.x - s * alignedPosition.y,\n s * alignedPosition.x + c * alignedPosition.y);\n\n#ifdef HORIZONTAL\n var mvPosition = uniforms.world * vec4f(vertexInputs.offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.z -= rotatedPosition.y;\n#ifdef PIVOT\n mvPosition.y += uniforms.pivot.z * abs(limitedSize.x);\n#endif\n mvPosition = uniforms.view * mvPosition;\n#elif defined(VERTICAL)\n var mvPosition = uniforms.world * vec4f(vertexInputs.offset, 1.0);\n mvPosition.y += rotatedPosition.y;\n mvPosition = uniforms.view * mvPosition;\n mvPosition.x += rotatedPosition.x;\n#else\n var mvPosition = uniforms.view * uniforms.world * vec4f(vertexInputs.offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.y += rotatedPosition.y;\n#endif\n#ifdef PIVOT\n#ifndef HORIZONTAL\n // Toward the camera along its view axis, whichever way the view space\n // faces: anything in front of the camera has the sign of the far side.\n mvPosition.z -= sign(mvPosition.z) * uniforms.pivot.z * abs(limitedSize.x);\n#endif\n#endif\n\n let clipPosition = uniforms.projection * mvPosition;\n vertexOutputs.position = clipPosition;\n${Gi("mvPosition.xyz")}\n#ifdef SOFT_PARTICLES\n vertexOutputs.projPosition = clipPosition;\n vertexOutputs.linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n let tc = vec2f(uniforms.tileCountX, uniforms.tileCountY);\n let baseTile = floor(vertexInputs.uvTile);\n let tileU = (baseTile % tc.x) / tc.x;\n let tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV = vertexInputs.uv / tc + vec2f(tileU, tileV);\n #ifdef TILE_BLEND\n let nextTile = ceil(vertexInputs.uvTile);\n let nextU = (nextTile % tc.x) / tc.x;\n let nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV2 = vertexInputs.uv / tc + vec2f(nextU, nextV);\n vertexOutputs.vTileBlend = fract(vertexInputs.uvTile);\n #endif\n #else\n vertexOutputs.vUV = vertexInputs.uv;\n #endif\n\n vertexOutputs.vColor = vertexInputs.color;\n}\n`;function ls(t){return t.isWebGPU?d.ShaderLanguage.WGSL:d.ShaderLanguage.GLSL}function cs(t,e,i,s){if(s===d.ShaderLanguage.WGSL)return c.ShaderStore.ShadersStoreWGSL[t+"VertexShader"]=e.wgsl,void(c.ShaderStore.ShadersStoreWGSL[t+"FragmentShader"]=i.wgsl);u.Effect.ShadersStore[t+"VertexShader"]=e.glsl,u.Effect.ShadersStore[t+"FragmentShader"]=i.glsl}var us,ds=`\n// Per-vertex attributes\nattribute position: vec3f;\nattribute uv: vec2f;\n\n// Per-instance attributes\nattribute offset: vec3f;\nattribute color: vec4f;\nattribute size: vec3f;\nattribute rotation: f32;\nattribute uvTile: f32;\nattribute velocity: vec4f;\n\n// Uniforms\nuniform world: mat4x4f;\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\nuniform speedFactor: f32;\n\n#ifdef UV_TILE\nuniform tileCountX: f32;\nuniform tileCountY: f32;\n#endif\n\n#ifdef PIVOT\n// Streak offset in particle-size units: x from head to tail, y across.\nuniform pivot: vec3f;\n#endif\n\n// Varyings\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n#ifdef TILE_BLEND\nvarying vUV2: vec2f;\nvarying vTileBlend: f32;\n#endif\n#ifdef SOFT_PARTICLES\nvarying projPosition: vec4f;\nvarying linearDepth: f32;\n#endif\n\n#ifdef SIZE_LIMITS\n// Smallest and largest size a particle may have on screen, as fractions of the viewport height.\nuniform sizeLimits: vec2f;\n#endif\n${Qi}\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let lengthFactor = vertexInputs.velocity.w;\n // A flipped particle arrives with a negative size: the streak keeps its\n // extent and mirrors its texture instead (see quadUV below).\n var avgSize = (abs(vertexInputs.size.x) + abs(vertexInputs.size.y)) * 0.5;\n var mvPosition = uniforms.view * uniforms.world * vec4f(vertexInputs.offset, 1.0);\n#ifdef SIZE_LIMITS\n // The streak's width on screen as a fraction of the viewport height, held\n // between the limits; a perspective projection divides by the view depth.\n let limitDepth = select(1.0, abs(mvPosition.z), abs(uniforms.projection[2][3]) > 0.0);\n let screenSize = avgSize * uniforms.projection[1][1] / (2.0 * limitDepth);\n if (screenSize > 0.0) {\n avgSize *= clamp(screenSize, uniforms.sizeLimits.x, uniforms.sizeLimits.y) / screenSize;\n }\n#endif\n let viewWorld = uniforms.view * uniforms.world;\n let viewWorld3 = mat3x3f(viewWorld[0].xyz, viewWorld[1].xyz, viewWorld[2].xyz);\n let viewVelocity = viewWorld3 * vertexInputs.velocity.xyz;\n let vlength = length(viewVelocity);\n // Stretch direction is the velocity direction; only a genuinely motionless particle has none.\n // Deriving it via normalize keeps the stretch aligned even when the speed contribution is ~0\n // (e.g. speedFactor 0), instead of collapsing the whole burst onto a fixed screen axis.\n var vdir = vec3f(0.0, 0.0, 1.0);\n if (vlength > 0.000001) {\n vdir = viewVelocity / vlength;\n }\n let side = normalize(cross(mvPosition.xyz, vdir));\n let widthOffset = vertexInputs.position.y * side * avgSize;\n // Equivalent to viewVelocity * (1.0 + lengthFactor / vlength) for moving particles, but the\n // size-based term (vdir * lengthFactor) survives when the velocity contribution vanishes.\n let lengthOffset = (vertexInputs.position.x + 0.5) * (viewVelocity + vdir * lengthFactor) * avgSize;\n var stretched = mvPosition.xyz + widthOffset - lengthOffset;\n#ifdef PIVOT\n // In particle-size units along the quad's own axes: x from head to tail, y across.\n stretched += (uniforms.pivot.y * side - uniforms.pivot.x * vdir) * avgSize;\n#endif\n mvPosition.x = stretched.x;\n mvPosition.y = stretched.y;\n mvPosition.z = stretched.z;\n\n let clipPosition = uniforms.projection * mvPosition;\n vertexOutputs.position = clipPosition;\n${Gi("mvPosition.xyz")}\n let quadUV = select(vertexInputs.uv, 1.0 - vertexInputs.uv, vertexInputs.size.xy < vec2f(0.0));\n#ifdef SOFT_PARTICLES\n vertexOutputs.projPosition = clipPosition;\n vertexOutputs.linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n let tc = vec2f(uniforms.tileCountX, uniforms.tileCountY);\n let baseTile = floor(vertexInputs.uvTile);\n let tileU = (baseTile % tc.x) / tc.x;\n let tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV = quadUV / tc + vec2f(tileU, tileV);\n #ifdef TILE_BLEND\n let nextTile = ceil(vertexInputs.uvTile);\n let nextU = (nextTile % tc.x) / tc.x;\n let nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vertexOutputs.vUV2 = quadUV / tc + vec2f(nextU, nextV);\n vertexOutputs.vTileBlend = fract(vertexInputs.uvTile);\n #endif\n #else\n vertexOutputs.vUV = quadUV;\n #endif\n\n vertexOutputs.vColor = vertexInputs.color;\n}\n`;function ps(){return{direction:new a.Vector3(.4,-1,.6),color:new f.Color3(1,1,1),ambient:new f.Color3(.35,.35,.35)}}function fs(t){if(!t||"object"!=typeof t)return;const e=Array.isArray(t.color)?t.color:[1,1,1],i=(t,e)=>"number"==typeof t&&Number.isFinite(t)?t:e;return{color:[i(e[0],1),i(e[1],1),i(e[2],1)],power:Math.max(.01,i(t.power,2)),strength:Math.max(0,i(t.strength,1)),mode:"mix"===t.mode?"mix":"add"}}function ms(t,e){return t===e||!(!t||!e)&&(t.mode===e.mode&&t.power===e.power&&t.strength===e.strength&&t.color[0]===e.color[0]&&t.color[1]===e.color[1]&&t.color[2]===e.color[2])}exports.RenderMode=void 0,(us=exports.RenderMode||(exports.RenderMode={}))[us.BillBoard=0]="BillBoard",us[us.StretchedBillBoard=1]="StretchedBillBoard",us[us.Mesh=2]="Mesh",us[us.Trail=3]="Trail",us[us.HorizontalBillBoard=4]="HorizontalBillBoard",us[us.VerticalBillBoard=5]="VerticalBillBoard";class ys{constructor(t,e){this.visibleSystems=[],this.boundsMin_=new H,this.boundsMax_=new H,this.scene=e,this.maxParticles=1e3,this.systems=new Set,this.settings={instancingGeometry:t.instancingGeometry,instancingIndices:t.instancingIndices,instancingUVs:t.instancingUVs,instancingNormals:t.instancingNormals,renderMode:t.renderMode,renderOrder:t.renderOrder,uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softNearFade:t.softNearFade,softFarFade:t.softFarFade,materialBlendMode:t.materialBlendMode,materialTransparent:t.materialTransparent,materialDepthTest:t.materialDepthTest,materialDepthWrite:t.materialDepthWrite,materialAlphaTest:t.materialAlphaTest,texture:t.texture,reflectionTexture:t.reflectionTexture??null,reflectionLevel:t.reflectionLevel??1,reflectionFaces:t.reflectionFaces??null,reflectionAtlas:t.reflectionAtlas??null,pivot:t.pivot?.clone(),sortMode:t.sortMode??"none",minParticleSize:t.minParticleSize??0,maxParticleSize:t.maxParticleSize??1/0,layerMask:t.layerMask,renderingGroupId:t.renderingGroupId??0,applyFog:t.applyFog??!0,lighting:t.lighting,rim:fs(t.rim)},this.mesh=new h.Mesh("vfxBatch",e),this.configureMesh()}configureMesh(){const t=this.mesh;t.alwaysSelectAsActiveMesh=!0,t.doNotSyncBoundingInfo=!0,t.setBoundingInfo(new p.BoundingInfo(a.Vector3.Zero(),a.Vector3.Zero())),t.layerMask=this.settings.layerMask,t.renderingGroupId=this.settings.renderingGroupId,t.alphaIndex=this.settings.renderOrder,t.applyFog=!1}refreshBoundingInfo(){const t=this.boundsMin_,e=this.boundsMax_;let i=1/0,s=1/0,r=1/0,n=-1/0,o=-1/0,a=-1/0,h=!1;const l=this.visibleSystems;for(let c=0;c<l.length;c++){const u=l[c];if(0!==u.particleNum&&"function"==typeof u.getWorldBounds){if(!u.getWorldBounds(t,e))return void(this.mesh.alwaysSelectAsActiveMesh=!0);h=!0,t.x<i&&(i=t.x),t.y<s&&(s=t.y),t.z<r&&(r=t.z),e.x>n&&(n=e.x),e.y>o&&(o=e.y),e.z>a&&(a=e.z)}}if(!h)return;const c=this.mesh.getBoundingInfo(),u=c.minimum,d=c.maximum;u.x===i&&u.y===s&&u.z===r&&d.x===n&&d.y===o&&d.z===a||(u.set(i,s,r),d.set(n,o,a),c.reConstruct(u,d)),this.mesh.alwaysSelectAsActiveMesh=!1}fogDefines(){if(!this.settings.applyFog)return[];return this.settings.materialTransparent&&(this.settings.materialBlendMode===r.Constants.ALPHA_ADD||this.settings.materialBlendMode===r.Constants.ALPHA_ONEONE)?["FOG","FOG_ADDITIVE"]:["FOG"]}bindFog(t){if(!this.settings.applyFog)return;const e=this.scene;t.onBindObservable.add(()=>{const i=t.getEffect();if(!i)return;const s=e.fogEnabled?e.fogMode:m.Scene.FOGMODE_NONE;i.setFloat4("vFogInfos",s,e.fogStart,e.fogEnd,e.fogDensity),i.setColor3("vFogColor",e.fogColor)})}addSystem(t){this.systems.add(t)}removeSystem(t){this.systems.delete(t)}getVisibleSystems(){const t=this.visibleSystems;let e=0;for(const i of this.systems)i.emitter.visible&&!0!==i.culled&&(t[e++]=i);return t.length=e,t}applyDepthTexture(t){const e=this.mesh.material;e&&e instanceof n.ShaderMaterial&&e.setTexture("depthTexture",t)}applyMeshLighting(t){}dispose(){this.mesh.dispose()}}ys.FOG_UNIFORMS=["vFogInfos","vFogColor"];class vs extends ys{static whiteTexture(t){let e=vs.whiteTextureByScene.get(t);return e||(e=o.RawTexture.CreateRGBATexture(new Uint8Array([255,255,255,255]),1,1,t),e.name="quarksMeshWhite",vs.whiteTextureByScene.set(t,e)),e}constructor(t,e){super(t,e),this.shaderMaterial=null,this.fixedLightDirection=new a.Vector3,this.fixedLightColor=new a.Vector3,this.fixedAmbientColor=new a.Vector3,this.gatherScratch=[],this.vector_=new H,this.vector2_=new H,this.vector3_=new H,this.quaternion_=new Z,this.quaternion2_=new Z,this.quaternion3_=new Z,this.quaternion4_=new Z,this.quaternion5_=new Z,this.rotationMat_=new ft,this.rotationMat2_=new ft,this.lastStretchedSpeedFactor=Number.NaN,this.clearedInstanceUploaded=!1,this.storeFixedLighting(ps()),this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new h.Mesh("spriteBatch",this.scene),this.configureMesh();const t=new l.VertexData;t.positions=this.settings.instancingGeometry,t.indices=this.settings.instancingIndices;const e=this.settings.instancingGeometry.length/3,i=this.settings.instancingUVs;i&&i.length>=2*e?t.uvs=i:t.uvs=new Float32Array(2*e),this.settings.instancingNormals&&(t.normals=this.settings.instancingNormals),t.applyToMesh(this.mesh,!1),this.buildExpandableBuffers()}disposeExpandableBuffers(){this.offsetVB?.dispose(),this.colorVB?.dispose(),this.sizeVB?.dispose(),this.uvTileVB?.dispose(),this.rotationVB?.dispose(),this.velocityVB?.dispose(),this.velocityVB=void 0,this.velocityBuffer=void 0}buildExpandableBuffers(){const e=this.scene.getEngine();this.offsetBuffer=new Float32Array(3*this.maxParticles),this.offsetVB=new t.VertexBuffer(e,this.offsetBuffer,"offset",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.offsetVB),this.colorBuffer=new Float32Array(4*this.maxParticles),this.colorVB=new t.VertexBuffer(e,this.colorBuffer,"color",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.colorVB),this.sizeBuffer=new Float32Array(3*this.maxParticles),this.sizeVB=new t.VertexBuffer(e,this.sizeBuffer,"size",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.sizeVB),this.uvTileBuffer=new Float32Array(this.maxParticles),this.uvTileVB=new t.VertexBuffer(e,this.uvTileBuffer,"uvTile",!0,!1,1,!0),this.mesh.setVerticesBuffer(this.uvTileVB),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer=new Float32Array(4*this.maxParticles),this.rotationVB=new t.VertexBuffer(e,this.rotationBuffer,"rotation",!0,!1,4,!0)):(this.rotationBuffer=new Float32Array(this.maxParticles),this.rotationVB=new t.VertexBuffer(e,this.rotationBuffer,"rotation",!0,!1,1,!0)),this.mesh.setVerticesBuffer(this.rotationVB),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&(this.velocityBuffer=new Float32Array(4*this.maxParticles),this.velocityVB=new t.VertexBuffer(e,this.velocityBuffer,"velocity",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.velocityVB)),this.mesh.forcedInstanceCount=0,this.mesh.doNotSyncBoundingInfo=!0}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.disposeExpandableBuffers(),this.buildExpandableBuffers(),this.sortScratch=void 0,this.gatherScratch.length=0}sizeLimits(){const{minParticleSize:t,maxParticleSize:e}=this.settings;return vs.takesPivotAndFlip(this.settings.renderMode)?t<=0&&e===1/0?null:new a.Vector2(Math.max(0,t),Math.min(e,1e9)):null}sortInstances(t,e,i){if(t<2)return;const s=this.sortScratch??(this.sortScratch=new rs(this.maxParticles));s.ensure(t);const r=s.keys,n=this.settings.sortMode;if("distance"===n){const e=this.scene.activeCameras?.[0]??this.scene.activeCamera;if(!e)return;const i=e.globalPosition,n=i.x,o=i.y,a=i.z,h=this.offsetBuffer;for(let e=0,i=0;e<t;e++,i+=3){const t=h[i]-n,l=h[i+1]-o,c=h[i+2]-a;r[e]=s.floatKey(t*t+l*l+c*c,!0)}}else{const e="youngestInFront"===n,i=this.visibleSystems;let o=0;for(let t=0;t<i.length;t++){const n=i[t],a=n.particleNum,h=n.store;if(0===a)continue;if(void 0===h){const t=n.particles;for(let i=0;i<a;i++)r[o++]=s.floatKey(t[i].age,e);continue}const l=h.scalars,c=ze.SCALAR_STRIDE;for(let t=0,i=ze.AGE;t<a;t++,i+=c)r[o++]=s.floatKey(l[i],e)}if(o!==t)return}const o=function(t,e){const i=t.keys,s=t.counts;let r=t.orderA,n=t.orderB;for(let t=0;t<e;t++)r[t]=t;for(let t=0;t<32;t+=11){s.fill(0);for(let n=0;n<e;n++)s[i[r[n]]>>>t&ss]++;if(s[i[r[0]]>>>t&ss]===e)continue;let o=0;for(let t=0;t<is;t++){const e=s[t];s[t]=o,o+=e}for(let o=0;o<e;o++){const e=r[o];n[s[i[e]>>>t&ss]++]=e}const a=r;r=n,n=a}return r}(s,t);this.offsetBuffer=this.gatherInto(0,this.offsetBuffer,o,t,3),this.sizeBuffer=this.gatherInto(1,this.sizeBuffer,o,t,3),this.colorBuffer=this.gatherInto(2,this.colorBuffer,o,t,4),this.uvTileBuffer=this.gatherInto(3,this.uvTileBuffer,o,t,1),this.rotationBuffer=this.gatherInto(4,this.rotationBuffer,o,t,e?4:1),i&&this.velocityBuffer&&(this.velocityBuffer=this.gatherInto(5,this.velocityBuffer,o,t,4))}gatherInto(t,e,i,s,r){let n=this.gatherScratch[t];return void 0!==n&&n.length===e.length||(n=new Float32Array(e.length)),function(t,e,i,s,r){if(1===r)for(let r=0;r<s;r++)e[r]=t[i[r]];else if(3===r)for(let r=0,n=0;r<s;r++,n+=3){const s=3*i[r];e[n]=t[s],e[n+1]=t[s+1],e[n+2]=t[s+2]}else if(4===r)for(let r=0,n=0;r<s;r++,n+=4){const s=4*i[r];e[n]=t[s],e[n+1]=t[s+1],e[n+2]=t[s+2],e[n+3]=t[s+3]}else for(let n=0;n<s;n++){const s=i[n]*r,o=n*r;for(let i=0;i<r;i++)e[o+i]=t[s+i]}}(e,n,i,s,r),this.gatherScratch[t]=e,n}rebuildMaterial(){const t=`quarksParticle_${this.settings.renderMode}`;this.lastStretchedSpeedFactor=Number.NaN;const e=this.fogDefines();let i,s;this.settings.renderMode===exports.RenderMode.Mesh?(i={glsl:Yi,wgsl:ns},s={glsl:Zi,wgsl:as}):this.settings.renderMode===exports.RenderMode.StretchedBillBoard?(i={glsl:Ki,wgsl:ds},s={glsl:Xi,wgsl:os}):(i={glsl:Hi,wgsl:hs},s={glsl:Xi,wgsl:os});const o=this.settings.texture??(this.settings.renderMode===exports.RenderMode.Mesh?vs.whiteTexture(this.scene):null);o&&e.push("USE_MAP");const h=this.settings.reflectionAtlas;if(this.settings.renderMode===exports.RenderMode.Mesh&&!!h&&!h.isReady()&&h){const t=h.onLoadObservable;t?.addOnce(()=>{this.rebuildMaterial()})}const l=this.settings.renderMode===exports.RenderMode.Mesh&&!!h&&h.isReady();l&&e.push("USE_ENVMAP_ATLAS"),(this.settings.uTileCount>1||this.settings.vTileCount>1)&&e.push("UV_TILE"),this.settings.blendTiles&&e.push("TILE_BLEND"),this.settings.softParticles&&e.push("SOFT_PARTICLES"),this.settings.materialAlphaTest>0&&e.push("USE_ALPHATEST"),this.settings.renderMode===exports.RenderMode.VerticalBillBoard&&e.push("VERTICAL"),this.settings.renderMode===exports.RenderMode.HorizontalBillBoard&&e.push("HORIZONTAL");const c=vs.takesPivotAndFlip(this.settings.renderMode)?this.settings.pivot:void 0;c&&e.push("PIVOT");const u=this.sizeLimits();u&&e.push("SIZE_LIMITS");const d=this.settings.renderMode===exports.RenderMode.Mesh,p=this.settings.lighting??"fixed",f=d&&"unlit"!==p;d&&!f&&e.push("MESH_UNLIT");const m=d?this.settings.rim:void 0;m&&(e.push("MESH_RIM"),"mix"===m.mode&&e.push("MESH_RIM_MIX"));const y=l||!!m,v=ls(this.scene.getEngine());cs(t,i,s,v);const g=["position","uv","offset","color","size","rotation","uvTile"];this.settings.renderMode===exports.RenderMode.Mesh&&g.push("normal"),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&g.push("velocity");const x=["world","view","projection","worldView","worldViewProjection",...ys.FOG_UNIFORMS],S=[];(this.settings.uTileCount>1||this.settings.vTileCount>1)&&(x.push("tileCountX"),x.push("tileCountY")),o&&S.push("map"),l&&(S.push("envAtlas"),x.push("reflectionLevel")),y&&x.push("eyePosition"),m&&(x.push("rimColor"),x.push("rimParams")),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&x.push("speedFactor"),this.settings.softParticles&&(x.push("softParams"),x.push("projParams"),S.push("depthTexture")),this.settings.materialAlphaTest>0&&x.push("alphaTest"),c&&x.push("pivot"),u&&x.push("sizeLimits"),f&&(x.push("lightDirection"),x.push("lightColor"),x.push("ambientColor"));const w=new n.ShaderMaterial(t,this.scene,{vertex:t,fragment:t},{attributes:g,uniforms:x,samplers:S,defines:e,needAlphaBlending:this.settings.materialTransparent,shaderLanguage:v});if(o&&w.setTexture("map",o),l&&h&&(w.setTexture("envAtlas",h),w.setFloat("reflectionLevel",this.settings.reflectionLevel)),m&&(w.setVector3("rimColor",new a.Vector3(m.color[0],m.color[1],m.color[2])),w.setVector2("rimParams",new a.Vector2(m.power,m.strength))),y){const t=new a.Vector3;w.setVector3("eyePosition",t),w.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.copyFrom(e.globalPosition),w.setVector3("eyePosition",t))})}if((this.settings.uTileCount>1||this.settings.vTileCount>1)&&(w.setFloat("tileCountX",this.settings.uTileCount),w.setFloat("tileCountY",this.settings.vTileCount)),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&w.setFloat("speedFactor",this.settings.softNearFade>0?this.settings.softNearFade:1),this.settings.softParticles){w.setVector2("softParams",new a.Vector2(this.settings.softNearFade,1/Math.max(this.settings.softFarFade-this.settings.softNearFade,1e-4)));const t=new a.Vector4(0,0,0,0);w.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.x=e.minZ,t.y=e.maxZ,w.setVector4("projParams",t))})}if(this.settings.materialAlphaTest>0&&w.setFloat("alphaTest",this.settings.materialAlphaTest),c&&w.setVector3("pivot",new a.Vector3(c.x,c.y,c.z)),u&&w.setVector2("sizeLimits",u),f&&(this.writeFixedLighting(w),"scene"===p)){const t=new a.Vector3,e=new a.Vector3,i=new a.Vector3;w.onBindObservable.add(()=>{vs.readSceneLight(this.scene,t,e,i)?(w.setVector3("lightDirection",t),w.setVector3("lightColor",e),w.setVector3("ambientColor",i)):this.writeFixedLighting(w)})}this.bindFog(w),w.backFaceCulling=!1,this.settings.materialTransparent?w.alphaMode=this.settings.materialBlendMode:w.alphaMode=r.Constants.ALPHA_DISABLE,w.needDepthPrePass=this.settings.materialDepthWrite,w.forceDepthWrite=this.settings.materialDepthWrite,w.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=w,this.shaderMaterial=w}applyMeshLighting(t){this.storeFixedLighting(t);const e=this.shaderMaterial;null!==e&&this.settings.renderMode===exports.RenderMode.Mesh&&"unlit"!==this.settings.lighting&&this.writeFixedLighting(e)}storeFixedLighting(t){this.fixedLightDirection.copyFrom(t.direction),this.fixedLightColor.set(t.color.r,t.color.g,t.color.b),this.fixedAmbientColor.set(t.ambient.r,t.ambient.g,t.ambient.b)}writeFixedLighting(t){t.setVector3("lightDirection",this.fixedLightDirection),t.setVector3("lightColor",this.fixedLightColor),t.setVector3("ambientColor",this.fixedAmbientColor)}static readSceneLight(t,e,i,s){const r=t.lights;for(let n=0;n<r.length;n++){const o=r[n],a=o.getClassName();if("DirectionalLight"!==a&&"HemisphericLight"!==a||!o.isEnabled())continue;const h=o.intensity,l=o.diffuse,c=t.ambientColor;i.set(l.r*h,l.g*h,l.b*h),s.set(c.r,c.g,c.b);const u=o.direction;if("DirectionalLight"===a)e.copyFrom(u);else{e.copyFrom(u).scaleInPlace(-1);const t=o.groundColor;t&&(s.x+=t.r*h,s.y+=t.g*h,s.z+=t.b*h)}return!0}return!1}update(){let t=0,e=0;const i=this.settings.renderMode,s=i===exports.RenderMode.Mesh,r=i===exports.RenderMode.StretchedBillBoard,n=vs.takesPivotAndFlip(i),o=this.getVisibleSystems();for(let t=0;t<o.length;t++)e+=o[t].particleNum;e>this.maxParticles&&this.expandBuffers(e);for(let e=0;e<o.length;e++){const i=o[e],a=i.particleNum;if(0===a)continue;const h=i.particles,l=this.quaternion2_,c=this.vector2_,u=this.vector3_,d=i.worldSpace,p=i.emitter.matrixWorld;if(s&&!d)p.decompose(c,l,u);else{const t=p.elements;u.set(Math.sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]),Math.sqrt(t[4]*t[4]+t[5]*t[5]+t[6]*t[6]),Math.sqrt(t[8]*t[8]+t[9]*t[9]+t[10]*t[10]))}r&&!d&&this.rotationMat_.setFromMatrix4(p);const f=Math.abs(u.x),m=Math.abs(u.y),y=Math.abs(u.z),v=r?i.rendererEmitterSettings:void 0,g=void 0===v||0===v.speedFactor?.001:v.speedFactor,x=v?.lengthFactor??0,S=i.store,w=void 0!==S,b=void 0!==S&&!0!==i.onlyUsedByOther,z=i.simulationResidual??0,M=0===z?0:z/(i.simulationStep??z);w&&(0!==M&&a>0&&S.previousColor!==S.color?vs.continueColor(this.colorBuffer,4*t,S,a,M):this.colorBuffer.set(S.color.subarray(0,4*a),4*t));let _=!1;if(void 0!==S&&d)0!==M&&a>0?vs.extrapolate(this.offsetBuffer,3*t,S,a,M):this.offsetBuffer.set(S.position.subarray(0,3*a),3*t),0!==M&&a>0&&S.previousSize!==S.size?vs.continueVector3(this.sizeBuffer,3*t,S.size,S.previousSize,a,M):this.sizeBuffer.set(S.size.subarray(0,3*a),3*t),_=!0;else if(b&&a>0){const e=3*t,i=e+3*a,s=this.offsetBuffer;0!==M?vs.extrapolate(s,e,S,a,M):s.set(S.position.subarray(0,3*a),e);const r=p.elements,n=r[0],o=r[1],h=r[2],l=r[3],c=r[4],u=r[5],d=r[6],v=r[7],g=r[8],x=r[9],w=r[10],b=r[11],z=r[12],P=r[13],T=r[14],V=r[15];for(let t=e;t<i;t+=3){const e=s[t],i=s[t+1],r=s[t+2],a=1/(l*e+v*i+b*r+V);s[t]=(n*e+c*i+g*r+z)*a,s[t+1]=(o*e+u*i+x*r+P)*a,s[t+2]=(h*e+d*i+w*r+T)*a}const O=this.sizeBuffer;0!==M&&S.previousSize!==S.size?vs.continueVector3(O,e,S.size,S.previousSize,a,M):O.set(S.size.subarray(0,3*a),e);for(let t=e;t<i;t+=3)O[t]*=f,O[t+1]*=m,O[t+2]*=y;_=!0}const P=t;if(b&&!s){const e=S;this.uvTileBuffer.set(e.uvTile.subarray(0,a),P);const i=this.rotationBuffer;if(i.set(e.rotation.subarray(0,a),P),0!==z){const t=e.angularVelocity;for(let e=0;e<a;e++)i[P+e]+=t[e]*z}r&&this.velocityBuffer&&vs.writeVelocities(this.velocityBuffer,4*P,e,a,M,d?null:this.rotationMat_,g,x),t+=a}else if(b&&S.rotationQuaternion.length>0){const e=S;this.uvTileBuffer.set(e.uvTile.subarray(0,a),P),vs.writeQuaternions(this.rotationBuffer,4*P,e,a,M,d?null:l),t+=a}else for(let e=0;e<a;e++,t++){const i=h[e];if(s){let e=i.rotation;const s=i.angularVelocity;let r;if(0!==M&&s instanceof Z&&(e=this.quaternion4_.copy(e).multiply(vs.partialTurn(s,M,this.quaternion5_))),d)r=e;else{let t;t=i.parentMatrix?this.quaternion3_.setFromRotationMatrix(i.parentMatrix):l,r=this.quaternion_,r.copy(t).multiply(e)}const n=4*t;this.rotationBuffer[n]=r.x,this.rotationBuffer[n+1]=r.y,this.rotationBuffer[n+2]=r.z,this.rotationBuffer[n+3]=r.w}else{const e=i.angularVelocity;this.rotationBuffer[t]=i.rotation+("number"==typeof e?e*z:0)}if(!_){const e=i.position,s=i.previousPosition;let r=e.x+(e.x-s.x)*M,n=e.y+(e.y-s.y)*M,o=e.z+(e.z-s.z)*M;if(!d){const t=(i.parentMatrix??p).elements,e=1/(t[3]*r+t[7]*n+t[11]*o+t[15]),s=(t[0]*r+t[4]*n+t[8]*o+t[12])*e,a=(t[1]*r+t[5]*n+t[9]*o+t[13])*e;o=(t[2]*r+t[6]*n+t[10]*o+t[14])*e,r=s,n=a}const a=3*t;this.offsetBuffer[a]=r,this.offsetBuffer[a+1]=n,this.offsetBuffer[a+2]=o;const h=i.size,l=3*t;d||i.parentMatrix?(this.sizeBuffer[l]=h.x,this.sizeBuffer[l+1]=h.y,this.sizeBuffer[l+2]=h.z):(this.sizeBuffer[l]=h.x*f,this.sizeBuffer[l+1]=h.y*m,this.sizeBuffer[l+2]=h.z*y)}if(!w){const e=i.color,s=4*t;this.colorBuffer[s]=e.x,this.colorBuffer[s+1]=e.y,this.colorBuffer[s+2]=e.z,this.colorBuffer[s+3]=e.w}if(this.uvTileBuffer[t]=i.uvTile,r&&this.velocityBuffer){const e=i.velocity,s=i.previousVelocity,r=e.x+(e.x-s.x)*M,n=e.y+(e.y-s.y)*M,o=e.z+(e.z-s.z)*M;let a=this.vector_;a.set(r,n,o),d||(i.parentMatrix?(this.rotationMat2_.setFromMatrix4(i.parentMatrix),a.applyMatrix3(this.rotationMat2_)):a.applyMatrix3(this.rotationMat_));const h=4*t;this.velocityBuffer[h]=a.x*g,this.velocityBuffer[h+1]=a.y*g,this.velocityBuffer[h+2]=a.z*g,this.velocityBuffer[h+3]=x}}n&&void 0!==i.flip&&(void 0!==S?vs.applyFlip(this.sizeBuffer,3*P,S.flip,a):vs.applyFlipFromParticles(this.sizeBuffer,3*P,h,a))}r&&o.length>0&&this.syncStretchedSpeedFactor(o[0]),this.mesh.forcedInstanceCount=t,this.refreshBoundingInfo(),0!==t?(this.clearedInstanceUploaded=!1,"none"!==this.settings.sortMode&&this.sortInstances(t,s,r),this.offsetVB.update(this.offsetBuffer.subarray(0,3*t)),this.sizeVB.update(this.sizeBuffer.subarray(0,3*t)),this.colorVB.update(this.colorBuffer.subarray(0,4*t)),this.uvTileVB.update(this.uvTileBuffer.subarray(0,t)),this.rotationVB.update(this.rotationBuffer.subarray(0,s?4*t:t)),r&&this.velocityVB&&this.velocityBuffer&&this.velocityVB.update(this.velocityBuffer.subarray(0,4*t))):this.clearedInstanceUploaded||(this.uploadClearedInstance(s,r),this.clearedInstanceUploaded=!0)}syncStretchedSpeedFactor(t){const e=this.shaderMaterial;if(null===e)return;const i=t.rendererEmitterSettings.speedFactor??1,s=0===i?.001:i;s!==this.lastStretchedSpeedFactor&&(e.setFloat("speedFactor",s),this.lastStretchedSpeedFactor=s)}static takesPivotAndFlip(t){return t===exports.RenderMode.BillBoard||t===exports.RenderMode.StretchedBillBoard||t===exports.RenderMode.VerticalBillBoard||t===exports.RenderMode.HorizontalBillBoard}static applyFlip(t,e,i,s){for(let r=0,n=e;r<s;r++,n+=3){const e=i[r];0!==e&&(1&e&&(t[n]=-t[n]),2&e&&(t[n+1]=-t[n+1]))}}static applyFlipFromParticles(t,e,i,s){for(let r=0,n=e;r<s;r++,n+=3){const e=i[r].flip;0!==e&&(1&e&&(t[n]=-t[n]),2&e&&(t[n+1]=-t[n+1]))}}static writeQuaternions(t,e,i,s,r,n){const o=i.rotationQuaternion,a=i.angularVelocityQuaternion,h=null!==n,l=h?n.x:0,c=h?n.y:0,u=h?n.z:0,d=h?n.w:1;for(let i=0,n=0,p=e;i<s;i++,n+=4,p+=4){let e=o[n],i=o[n+1],s=o[n+2],f=o[n+3];if(0!==r){const t=a[n]*r,o=a[n+1]*r,h=a[n+2]*r,l=1+(a[n+3]-1)*r,c=1/Math.sqrt(t*t+o*o+h*h+l*l),u=t*c,d=o*c,p=h*c,m=l*c,y=e*m+f*u+i*p-s*d,v=i*m+f*d+s*u-e*p,g=s*m+f*p+e*d-i*u;f=f*m-e*u-i*d-s*p,e=y,i=v,s=g}if(h){const t=l*f+d*e+c*s-u*i,r=c*f+d*i+u*e-l*s,n=u*f+d*s+l*i-c*e;f=d*f-l*e-c*i-u*s,e=t,i=r,s=n}t[p]=e,t[p+1]=i,t[p+2]=s,t[p+3]=f}}static writeVelocities(t,e,i,s,r,n,o,a){const h=i.velocity,l=i.previousVelocity.length>=3*s?i.previousVelocity:h,c=null!==n?n.elements:null;for(let i=0,n=0,u=e;i<s;i++,n+=3,u+=4){let e=h[n],i=h[n+1],s=h[n+2];if(0!==r&&(e+=(e-l[n])*r,i+=(i-l[n+1])*r,s+=(s-l[n+2])*r),null!==c){const t=c[0]*e+c[3]*i+c[6]*s,r=c[1]*e+c[4]*i+c[7]*s;s=c[2]*e+c[5]*i+c[8]*s,e=t,i=r}t[u]=e*o,t[u+1]=i*o,t[u+2]=s*o,t[u+3]=a}}static partialTurn(t,e,i){const s=t.x*e,r=t.y*e,n=t.z*e,o=1+(t.w-1)*e,a=1/Math.sqrt(s*s+r*r+n*n+o*o);return i.x=s*a,i.y=r*a,i.z=n*a,i.w=o*a,i}static continueVector3(t,e,i,s,r,n){for(let o=0,a=0;o<r;o++,a+=3){const r=i[a]+(i[a]-s[a])*n,o=i[a+1]+(i[a+1]-s[a+1])*n,h=i[a+2]+(i[a+2]-s[a+2])*n;t[e+a]=r>0?r:0,t[e+a+1]=o>0?o:0,t[e+a+2]=h>0?h:0}}static continueColor(t,e,i,s,r){const n=i.color,o=i.previousColor;for(let i=0,a=0;i<s;i++,a+=4){const i=n[a]+(n[a]-o[a])*r,s=n[a+1]+(n[a+1]-o[a+1])*r,h=n[a+2]+(n[a+2]-o[a+2])*r,l=n[a+3]+(n[a+3]-o[a+3])*r;t[e+a]=i>0?i:0,t[e+a+1]=s>0?s:0,t[e+a+2]=h>0?h:0,t[e+a+3]=l>0?l:0}}static extrapolate(t,e,i,s,r){const n=i.position,o=i.previousPosition;for(let i=0,a=0;i<s;i++,a+=3){const i=n[a],s=n[a+1],h=n[a+2];t[e+a]=i+(i-o[a])*r,t[e+a+1]=s+(s-o[a+1])*r,t[e+a+2]=h+(h-o[a+2])*r}}uploadClearedInstance(t,e){this.colorBuffer[3]=0,this.sizeBuffer[0]=0,this.sizeBuffer[1]=0,this.sizeBuffer[2]=0,this.colorVB.update(this.colorBuffer.subarray(0,4)),this.sizeVB.update(this.sizeBuffer.subarray(0,3)),this.offsetVB.update(this.offsetBuffer.subarray(0,3)),this.uvTileVB.update(this.uvTileBuffer.subarray(0,1)),t?this.rotationVB.update(this.rotationBuffer.subarray(0,4)):this.rotationVB.update(this.rotationBuffer.subarray(0,1)),e&&this.velocityVB&&this.velocityBuffer&&this.velocityVB.update(this.velocityBuffer.subarray(0,4))}dispose(){this.mesh.material&&this.mesh.material.dispose(),super.dispose()}}vs.whiteTextureByScene=new WeakMap;var gs=`\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n\n#ifdef USE_MAP\nvar mapSampler: sampler;\nvar map: texture_2d<f32>;\n#endif\n\n${Wi}\n@fragment\nfn main(input: FragmentInputs) -> FragmentOutputs {\n var baseColor = fragmentInputs.vColor;\n\n#ifdef USE_MAP\n let texColor = textureSample(map, mapSampler, fragmentInputs.vUV);\n baseColor *= texColor;\n#endif\n\n if (baseColor.a < 0.01) { discard; }\n\n${ji("baseColor")}\n fragmentOutputs.color = baseColor;\n}\n`,xs=`\nattribute position: vec3f;\nattribute previous: vec3f;\nattribute next: vec3f;\nattribute side: f32;\nattribute width: f32;\nattribute uv: vec2f;\nattribute color: vec4f;\n\nuniform view: mat4x4f;\nuniform projection: mat4x4f;\nuniform lineWidth: f32;\nuniform resolution: vec2f;\nuniform sizeAttenuation: f32;\n\nvarying vUV: vec2f;\nvarying vColor: vec4f;\n\nfn fix(i: vec4f, aspect: f32) -> vec2f {\n var res = i.xy / i.w;\n res.x *= aspect;\n return res;\n}\n\n${Qi}\n@vertex\nfn main(input: VertexInputs) -> FragmentInputs {\n let aspect = uniforms.resolution.x / uniforms.resolution.y;\n var finalPosition = uniforms.projection * uniforms.view * vec4f(vertexInputs.position, 1.0);\n let prevPos = uniforms.projection * uniforms.view * vec4f(vertexInputs.previous, 1.0);\n let nextPos = uniforms.projection * uniforms.view * vec4f(vertexInputs.next, 1.0);\n\n let currentP = fix(finalPosition, aspect);\n let prevP = fix(prevPos, aspect);\n let nextP = fix(nextPos, aspect);\n\n let w = uniforms.lineWidth * vertexInputs.width;\n var dir: vec2f;\n if (distance(nextP, currentP) < 0.0001) {\n dir = normalize(currentP - prevP);\n } else if (distance(prevP, currentP) < 0.0001) {\n dir = normalize(nextP - currentP);\n } else {\n let dir1 = normalize(currentP - prevP);\n let dir2 = normalize(nextP - currentP);\n dir = normalize(dir1 + dir2);\n }\n var normal = vec4f(-dir.y, dir.x, 0.0, 1.0);\n normal.x *= 0.5 * w;\n normal.y *= 0.5 * w;\n normal = normal * uniforms.projection;\n if (uniforms.sizeAttenuation == 0.0) {\n let screen = (vec4f(uniforms.resolution, 0.0, 1.0) * uniforms.projection).xy;\n normal.x = normal.x * finalPosition.w / screen.x;\n normal.y = normal.y * finalPosition.w / screen.y;\n }\n finalPosition.x += normal.x * vertexInputs.side;\n finalPosition.y += normal.y * vertexInputs.side;\n\n vertexOutputs.position = finalPosition;\n${Gi("(uniforms.view * vec4f(vertexInputs.position, 1.0)).xyz")}\n vertexOutputs.vUV = vertexInputs.uv;\n vertexOutputs.vColor = vertexInputs.color;\n}\n`;class Ss extends ys{constructor(t,e){super(t,e),this.drawsNothing=!1,this.vector_=new H,this.vector2_=new H,this.vector3_=new H,this.quaternion_=new Z,this.maxParticles=1024,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new h.Mesh("trailBatch",this.scene),this.configureMesh(),this.buildGeometryBuffers()}buildGeometryBuffers(){this.positionBuffer=new Float32Array(6*this.maxParticles),this.previousBuffer=new Float32Array(6*this.maxParticles),this.nextBuffer=new Float32Array(6*this.maxParticles),this.uvBuffer=new Float32Array(4*this.maxParticles),this.sideBuffer=new Float32Array(2*this.maxParticles),this.widthBuffer=new Float32Array(2*this.maxParticles),this.colorBuffer=new Float32Array(8*this.maxParticles),this.indexBuffer=new Uint32Array(6*this.maxParticles);for(let t=0;t<this.sideBuffer.length;t+=2)this.sideBuffer[t]=1,this.sideBuffer[t+1]=-1;this.positionBuffer[0]=0,this.positionBuffer[1]=0,this.positionBuffer[2]=0,this.positionBuffer[3]=1,this.positionBuffer[4]=0,this.positionBuffer[5]=0,this.positionBuffer[6]=0,this.positionBuffer[7]=1,this.positionBuffer[8]=0,this.positionBuffer[9]=1,this.positionBuffer[10]=1,this.positionBuffer[11]=0,this.indexBuffer[0]=0,this.indexBuffer[1]=1,this.indexBuffer[2]=2,this.indexBuffer[3]=1,this.indexBuffer[4]=3,this.indexBuffer[5]=2,this.mesh.setVerticesData(t.VertexBuffer.PositionKind,this.positionBuffer,!0),this.mesh.setVerticesData(t.VertexBuffer.UVKind,this.uvBuffer,!0),this.mesh.setVerticesData(t.VertexBuffer.ColorKind,this.colorBuffer,!0,4),this.mesh.setIndices(this.indexBuffer,null,!0),this.drawsNothing=!1,this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.mesh.subMeshes[0].indexCount=6);const e=this.scene.getEngine();this.previousVB=new t.VertexBuffer(e,this.previousBuffer,"previous",!0,!1,3,!1),this.nextVB=new t.VertexBuffer(e,this.nextBuffer,"next",!0,!1,3,!1),this.sideVB=new t.VertexBuffer(e,this.sideBuffer,"side",!0,!1,1,!1),this.widthVB=new t.VertexBuffer(e,this.widthBuffer,"width",!0,!1,1,!1),this.mesh.setVerticesBuffer(this.previousVB),this.mesh.setVerticesBuffer(this.nextVB),this.mesh.setVerticesBuffer(this.sideVB),this.mesh.setVerticesBuffer(this.widthVB),this.mesh.subMeshes&&this.adoptMeshBounds()}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.previousVB?.dispose(),this.nextVB?.dispose(),this.sideVB?.dispose(),this.widthVB?.dispose(),this.buildGeometryBuffers()}rebuildMaterial(){const t="quarksTrail",e=this.fogDefines();this.settings.texture&&e.push("USE_MAP");const i=ls(this.scene.getEngine());cs(t,{glsl:es,wgsl:xs},{glsl:ts,wgsl:gs},i);const s=["world","view","projection","worldViewProjection","lineWidth","resolution","sizeAttenuation",...ys.FOG_UNIFORMS],o=[];this.settings.texture&&o.push("map");const h=new n.ShaderMaterial(t,this.scene,{vertex:t,fragment:t},{attributes:["position","previous","next","side","width","uv","color"],uniforms:s,samplers:o,defines:e,needAlphaBlending:this.settings.materialTransparent,shaderLanguage:i});this.settings.texture&&h.setTexture("map",this.settings.texture);const l=this.scene.getEngine();h.setFloat("lineWidth",1);const c=new a.Vector2(l.getRenderWidth(),l.getRenderHeight());h.setVector2("resolution",c),h.setFloat("sizeAttenuation",1),h.onBindObservable.add(()=>{const t=this.scene.getEngine(),e=t.getRenderWidth(),i=t.getRenderHeight();c.x===e&&c.y===i||(c.x=e,c.y=i,h.setVector2("resolution",c))}),this.bindFog(h),h.backFaceCulling=!1,this.settings.materialTransparent?h.alphaMode=this.settings.materialBlendMode:h.alphaMode=r.Constants.ALPHA_DISABLE,h.needDepthPrePass=this.settings.materialDepthWrite,h.forceDepthWrite=this.settings.materialDepthWrite,h.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=h}static ensureWorldMatrix(t){const e=t.emitter;!e.computeWorldMatrix||e.isSynchronized&&e.isSynchronized()||e.computeWorldMatrix(!0)}update(){let t=0,e=0,i=0;const s=this.getVisibleSystems();for(let t=0;t<s.length;t++){const e=s[t],r=e.particles;for(let t=0;t<e.particleNum;t++){const e=r[t].historyCount;0!==e&&(i+=2*e+2)}}i>this.maxParticles&&this.expandBuffers(i);for(let i=0;i<s.length;i++){const r=s[i],n=t;Ss.ensureWorldMatrix(r);const o=this.quaternion_,a=this.vector2_,h=this.vector3_,l=r.emitter.matrixWorld;l.decompose(a,o,h);const c=r.particles,u=r.particleNum,d=this.settings.uTileCount,p=this.settings.vTileCount,f=1/d,m=1/p,y=r.worldSpace,v=(Math.abs(h.x)+Math.abs(h.y)+Math.abs(h.z))/3,g=r.rendererEmitterSettings,x=Boolean(g.uvFromHead),S=Boolean(g.colorFromParticle),w=y||Boolean(g.recordWorldSpace),b=g.followLocalOrigin?0:r.simulationResidual??0,z=0===b?0:b/(r.simulationStep??b);for(let i=0;i<u;i++){const s=c[i],r=s.historyCount;if(0===r)continue;const n=s.historyCapacity,o=s.historyPositions,a=s.historySizes,h=S?s.store.color:s.historyColors,u=4*s.storeIndex,d=s.uvTile%p,g=Math.floor(s.uvTile/p+.001),b=(s.parentMatrix??l).elements,M=b[0],_=b[1],P=b[2],T=b[3],V=b[4],O=b[5],C=b[6],F=b[7],B=b[8],A=b[9],$=b[10],I=b[11],E=b[12],N=b[13],L=b[14],R=b[15],D=1/(0!==z?r:Math.max(1,r-1));let U=s.getHistoryIndex(0),q=o[3*U],k=o[3*U+1],J=o[3*U+2];if(!w){const t=1/(T*q+F*k+I*J+R),e=(M*q+V*k+B*J+E)*t,i=(_*q+O*k+A*J+N)*t;J=(P*q+C*k+$*J+L)*t,q=e,k=i}let Q=q,G=k,W=J;for(let i=0;i<r;i++,t+=2){let l=q,c=k,b=J,z=U;if(i+1<r){z=U+1===n?0:U+1;const t=3*z;if(l=o[t],c=o[t+1],b=o[t+2],!w){const t=1/(T*l+F*c+I*b+R),e=(M*l+V*c+B*b+E)*t,i=(_*l+O*c+A*b+N)*t;b=(P*l+C*c+$*b+L)*t,l=e,c=i}}const j=a[U],Y=S?u:4*U,X=h[Y],Z=h[Y+1],H=h[Y+2],K=h[Y+3],tt=3*t;this.positionBuffer[tt]=q,this.positionBuffer[tt+1]=k,this.positionBuffer[tt+2]=J,this.positionBuffer[tt+3]=q,this.positionBuffer[tt+4]=k,this.positionBuffer[tt+5]=J,this.previousBuffer[tt]=Q,this.previousBuffer[tt+1]=G,this.previousBuffer[tt+2]=W,this.previousBuffer[tt+3]=Q,this.previousBuffer[tt+4]=G,this.previousBuffer[tt+5]=W,this.nextBuffer[tt]=l,this.nextBuffer[tt+1]=c,this.nextBuffer[tt+2]=b,this.nextBuffer[tt+3]=l,this.nextBuffer[tt+4]=c,this.nextBuffer[tt+5]=b,y||s.parentMatrix?(this.widthBuffer[t]=j,this.widthBuffer[t+1]=j):(this.widthBuffer[t]=j*v,this.widthBuffer[t+1]=j*v);const et=2*t,it=i*D,st=((x?1-it:it)+d)*f;this.uvBuffer[et]=st,this.uvBuffer[et+1]=(p-g-1)*m,this.uvBuffer[et+2]=st,this.uvBuffer[et+3]=(p-g)*m;const rt=4*t;this.colorBuffer[rt]=X,this.colorBuffer[rt+1]=Z,this.colorBuffer[rt+2]=H,this.colorBuffer[rt+3]=K,this.colorBuffer[rt+4]=X,this.colorBuffer[rt+5]=Z,this.colorBuffer[rt+6]=H,this.colorBuffer[rt+7]=K,i+1<r&&(this.indexBuffer[3*e]=t,this.indexBuffer[3*e+1]=t+1,this.indexBuffer[3*e+2]=t+2,e++,this.indexBuffer[3*e]=t+2,this.indexBuffer[3*e+1]=t+1,this.indexBuffer[3*e+2]=t+3,e++),Q=q,G=k,W=J,q=l,k=c,J=b,U=z}if(0!==z){const i=s.previousPosition,r=s.position;let n=r.x+(r.x-i.x)*z,o=r.y+(r.y-i.y)*z,a=r.z+(r.z-i.z)*z;const h=t-2,l=this.positionBuffer[3*h],c=this.positionBuffer[3*h+1],u=this.positionBuffer[3*h+2];if(!y){const t=1/(T*n+F*o+I*a+R),e=(M*n+V*o+B*a+E)*t,i=(_*n+O*o+A*a+N)*t;a=(P*n+C*o+$*a+L)*t,n=e,o=i}const S=3*t;this.positionBuffer[S]=n,this.positionBuffer[S+1]=o,this.positionBuffer[S+2]=a,this.positionBuffer[S+3]=n,this.positionBuffer[S+4]=o,this.positionBuffer[S+5]=a,this.previousBuffer[S]=l,this.previousBuffer[S+1]=c,this.previousBuffer[S+2]=u,this.previousBuffer[S+3]=l,this.previousBuffer[S+4]=c,this.previousBuffer[S+5]=u,this.nextBuffer[S]=n,this.nextBuffer[S+1]=o,this.nextBuffer[S+2]=a,this.nextBuffer[S+3]=n,this.nextBuffer[S+4]=o,this.nextBuffer[S+5]=a;const w=3*h;this.nextBuffer[w]=n,this.nextBuffer[w+1]=o,this.nextBuffer[w+2]=a,this.nextBuffer[w+3]=n,this.nextBuffer[w+4]=o,this.nextBuffer[w+5]=a;const b=s.size.x;y||s.parentMatrix?(this.widthBuffer[t]=b,this.widthBuffer[t+1]=b):(this.widthBuffer[t]=b*v,this.widthBuffer[t+1]=b*v);const D=2*t,U=((x?0:1)+d)*f;this.uvBuffer[D]=U,this.uvBuffer[D+1]=(p-g-1)*m,this.uvBuffer[D+2]=U,this.uvBuffer[D+3]=(p-g)*m;const q=s.color,k=4*t;this.colorBuffer[k]=q.x,this.colorBuffer[k+1]=q.y,this.colorBuffer[k+2]=q.z,this.colorBuffer[k+3]=q.w,this.colorBuffer[k+4]=q.x,this.colorBuffer[k+5]=q.y,this.colorBuffer[k+6]=q.z,this.colorBuffer[k+7]=q.w,this.indexBuffer[3*e]=h,this.indexBuffer[3*e+1]=h+1,this.indexBuffer[3*e+2]=t,e++,this.indexBuffer[3*e]=t,this.indexBuffer[3*e+1]=h+1,this.indexBuffer[3*e+2]=t+1,e++,t+=2}}this.measureSystemBounds(r,n,t)}this.refreshBoundingInfo(),this.uploadGeometry(t,e)}measureSystemBounds(t,e,i){if(i<=e||"function"!=typeof t.setWorldBounds)return;const s=this.positionBuffer;let r=1/0,n=1/0,o=1/0,a=-1/0,h=-1/0,l=-1/0;for(let t=3*e,c=3*i;t<c;t+=6){const e=s[t],i=s[t+1],c=s[t+2];e<r&&(r=e),e>a&&(a=e),i<n&&(n=i),i>h&&(h=i),c<o&&(o=c),c>l&&(l=c)}const c=this.widthBuffer;let u=0;for(let t=e;t<i;t+=2){const e=c[t];e>u&&(u=e)}t.setWorldBounds(r,n,o,a,h,l,u)}uploadGeometry(e,i){const s=this.mesh.geometry,r=s?.getIndexBuffer();if(e>0&&i>0){this.mesh.updateVerticesData(t.VertexBuffer.PositionKind,this.positionBuffer.subarray(0,3*e)),this.mesh.updateVerticesData(t.VertexBuffer.UVKind,this.uvBuffer.subarray(0,2*e)),r&&this.scene.getEngine().updateDynamicIndexBuffer(r,this.indexBuffer.subarray(0,3*i),0),this.previousVB.update(this.previousBuffer.subarray(0,3*e)),this.nextVB.update(this.nextBuffer.subarray(0,3*e)),this.widthVB.update(this.widthBuffer.subarray(0,e));const s=this.mesh.getVertexBuffer(t.VertexBuffer.ColorKind);s&&s.update(this.colorBuffer.subarray(0,4*e)),this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.mesh.subMeshes[0].indexCount=3*i,this.mesh.subMeshes[0].verticesCount=e),this.drawsNothing=!1}else this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.drawsNothing||(this.indexBuffer.fill(0,0,6),r&&this.scene.getEngine().updateDynamicIndexBuffer(r,this.indexBuffer.subarray(0,6),0),this.drawsNothing=!0),this.mesh.subMeshes[0].indexCount=6,this.mesh.subMeshes[0].verticesCount=1)}adoptMeshBounds(){const t=this.mesh.getBoundingInfo();for(const e of this.mesh.subMeshes)e._boundingInfo=t}dispose(){this.mesh.material&&this.mesh.material.dispose(),super.dispose()}}class ws extends s.TransformNode{constructor(t,e){super(t,e),this.batches=[],this.systemToBatchIndex=new Map,this.depthTexture=null,this.systems=[],this.orderedSystems=[],this.orderedSystemsStale=!0,this.batchEmptyFrames=[],this.adaptivePerformanceState={enabled:!1,targetFrameMs:16.7,minQuality:.35,maxQuality:1,decreaseStep:.08,increaseStep:.02,currentQuality:1,lastFrameCpuMs:0},this.lastAppliedQuality=Number.NaN,this.meshLighting=ps(),this.cullingEnabled=!0,this.catchUpBudgetMs=2,this.simulationBudgetMs=1/0,this.frustumPlanes=[],this.boundsMin=new H,this.boundsMax=new H}collectFrustumPlanes(){const t=this.getScene(),s=this.frustumPlanes,r=t.activeCameras,n=t.activeCamera,o=r&&r.length>0?r:n?[n]:[],a=6*o.length;for(;s.length<a;)s.push(new i.Plane(0,0,0,0));s.length=a;for(let t=0;t<o.length;t++){const i=o[t];i.getViewMatrix(),i.getProjectionMatrix();const r=i.getTransformationMatrix(),n=0===t?s:s.slice(6*t,6*t+6);if(e.Frustum.GetPlanesToRef(r,n),0!==t)for(let e=0;e<6;e++)s[6*t+e]=n[e]}return s}isSystemInView(t,e){const i=this.boundsMin,s=this.boundsMax;if(!t.getWorldBounds(i,s))return!0;for(let t=0;t<e.length;t+=6){let r=!0;for(let n=t;n<t+6;n++){const t=e[n],o=t.normal,a=o.x>=0?s.x:i.x,h=o.y>=0?s.y:i.y,l=o.z>=0?s.z:i.z;if(o.x*a+o.y*h+o.z*l+t.d<0){r=!1;break}}if(r)return!0}return!1}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static equals(t,e){return t.materialBlendMode===e.materialBlendMode&&t.materialTransparent===e.materialTransparent&&t.materialDepthTest===e.materialDepthTest&&t.materialDepthWrite===e.materialDepthWrite&&t.materialAlphaTest===e.materialAlphaTest&&t.texture===e.texture&&t.reflectionTexture===e.reflectionTexture&&t.reflectionLevel===e.reflectionLevel&&function(t,e){if(t===e)return!0;if(!t||!e||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}(t.reflectionFaces,e.reflectionFaces)&&t.reflectionAtlas===e.reflectionAtlas&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layerMask===e.layerMask&&t.renderingGroupId===e.renderingGroupId&&t.applyFog===e.applyFog&&function(t,e){return(t?.x??0)===(e?.x??0)&&(t?.y??0)===(e?.y??0)&&(t?.z??0)===(e?.z??0)}(t.pivot,e.pivot)&&t.sortMode===(e.sortMode??"none")&&t.minParticleSize===(e.minParticleSize??0)&&t.maxParticleSize===(e.maxParticleSize??1/0)&&(t.lighting??"fixed")===(e.lighting??"fixed")&&ms(t.rim,e.rim)}addSystem(t){const e=t;e._renderer=this,this.systemToBatchIndex.has(t)||-1!==this.systems.indexOf(t)||(this.systems.push(t),this.orderedSystemsStale=!0),this.adaptivePerformanceState.enabled&&e.setQualityFactor(this.adaptivePerformanceState.currentQuality),this.assignToBatch(e)}assignToBatch(t){const e=t,i=t.getRendererSettings();for(let t=0;t<this.batches.length;t++)if(ws.equals(this.batches[t].settings,i))return this.batches[t].addSystem(e),void this.systemToBatchIndex.set(e,t);let s;const r=this.getScene();switch(i.renderMode){case exports.RenderMode.Trail:s=new Ss(i,r);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:s=new vs(i,r);break;default:throw new Error(`Unsupported render mode: ${i.renderMode}`)}s.mesh.parent=this,this.depthTexture&&s.applyDepthTexture(this.depthTexture),s.applyMeshLighting(this.meshLighting),s.addSystem(e),this.batches.push(s),this.batchEmptyFrames.push(0),this.systemToBatchIndex.set(e,this.batches.length-1)}deleteSystem(t){const e=this.removeFromBatch(t),i=this.systems.indexOf(t);-1!==i&&(this.systems.splice(i,1),this.orderedSystemsStale=!0);const s=this.orderedSystems.indexOf(t);return-1!==s&&this.orderedSystems.splice(s,1),e}removeFromBatch(t){const e=this.systemToBatchIndex.get(t);return void 0!==e&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t),!0)}updateSystem(t){this.removeFromBatch(t),this.addSystem(t)}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}setMeshLighting(t){const e=this.meshLighting;t.direction&&(e.direction=t.direction.clone()),t.color&&(e.color=t.color.clone()),t.ambient&&(e.ambient=t.ambient.clone());for(const t of this.batches)t.applyMeshLighting(e)}getMeshLighting(){const t=this.meshLighting;return{direction:t.direction.clone(),color:t.color.clone(),ambient:t.ambient.clone()}}configureAdaptivePerformance(t={}){const e=this.adaptivePerformanceState,i=ws.clamp(t.minQuality??e.minQuality,.05,1),s=ws.clamp(t.maxQuality??e.maxQuality,i,1);e.targetFrameMs=Math.max(t.targetFrameMs??e.targetFrameMs,.1),e.minQuality=i,e.maxQuality=s,e.decreaseStep=Math.max(t.decreaseStep??e.decreaseStep,.001),e.increaseStep=Math.max(t.increaseStep??e.increaseStep,.001),e.currentQuality=ws.clamp(e.currentQuality,e.minQuality,e.maxQuality),e.enabled=!0,this.lastAppliedQuality=Number.NaN}disableAdaptivePerformance(t=!0){this.adaptivePerformanceState.enabled=!1,t&&(this.adaptivePerformanceState.currentQuality=this.adaptivePerformanceState.maxQuality,this.applyAdaptiveQuality())}getAdaptivePerformanceState(){return{...this.adaptivePerformanceState}}applyAdaptiveQuality(){const t=this.adaptivePerformanceState.currentQuality;if(t!==this.lastAppliedQuality){for(let e=0;e<this.systems.length;e++)this.systems[e].setQualityFactor(t);this.lastAppliedQuality=t}}_invalidateUpdateOrder(){this.orderedSystemsStale=!0}orderSystems(){if(!this.orderedSystemsStale)return this.orderedSystems;const t=[],e=new Set,i=new Set,s=new Set(this.systems),r=n=>{if(!i.has(n)&&!e.has(n)){e.add(n);for(const t of(t=>{const e=[];for(const i of t.behaviors??[]){if("EmitSubParticleSystem"!==i.type)continue;const t=i.subParticleSystem?.system;void 0!==t&&s.has(t)&&e.push(t)}return e})(n))r(t);e.delete(n),i.add(n),t.push(n)}};for(const t of this.systems)r(t);return t.reverse(),this.orderedSystems=t,this.orderedSystemsStale=!1,t}update(t){const e=this.adaptivePerformanceState,i=e.enabled?performance.now():0;e.enabled&&this.applyAdaptiveQuality();const s=this.orderSystems(),r=this.cullingEnabled?this.collectFrustumPlanes():null,n=this.simulationBudgetMs!==1/0||this.catchUpBudgetMs!==1/0?performance.now():0,o=this.simulationBudgetMs===1/0?1/0:n+this.simulationBudgetMs,a=this.catchUpBudgetMs===1/0?1/0:n+this.catchUpBudgetMs;for(let e=0;e<s.length;e++){const i=s[e];i.emitter.visible&&(i.culled=null!==r&&r.length>0&&"always"!==i.cullingMode&&!0!==i.onlyUsedByOther&&!this.isSystemInView(i,r),i.update(t,o,a)),s[e]!==i&&e--}this.refreshBatches(),e.enabled&&(e.lastFrameCpuMs=performance.now()-i,e.lastFrameCpuMs>e.targetFrameMs?e.currentQuality=ws.clamp(e.currentQuality-e.decreaseStep,e.minQuality,e.maxQuality):e.currentQuality=ws.clamp(e.currentQuality+e.increaseStep,e.minQuality,e.maxQuality))}refreshBatches(){const t=this.batchEmptyFrames;for(let e=0;e<this.batches.length;e++){const i=this.batches[e];if(i.systems.size>0){t[e]=0,i.update();continue}const s=(t[e]??0)+1;t[e]=s,1===s?i.update():s>ws.EMPTY_BATCH_GRACE_FRAMES&&(this.removeBatch(e),e--)}}removeBatch(t){this.batches[t].dispose(),this.batches.splice(t,1),this.batchEmptyFrames.splice(t,1);for(const[e,i]of this.systemToBatchIndex)i>t&&this.systemToBatchIndex.set(e,i-1)}getBatchRenderStats(){return this.batches.map((t,e)=>{let i=0;const s=[];for(const e of t.systems){const t=e;i+=t.particleNum,s.push(t.emitter.name)}return{batchIndex:e,renderMode:t.settings.renderMode,instanceCount:t.mesh.forcedInstanceCount??0,particleCount:i,systemNames:s}})}dispose(){for(const t of this.batches)t.dispose();this.batches=[],this.batchEmptyFrames.length=0,this.systems.length=0,this.systemToBatchIndex.clear(),super.dispose()}}ws.EMPTY_BATCH_GRACE_FRAMES=120;const bs=ws;class zs extends s.TransformNode{get matrixWorld(){const t=this.getWorldMatrix(),e=t.updateFlag;if(e===this._matrixWorldFlag)return this._matrixWorld;this._matrixWorldFlag=e;const i=this._matrixWorld.elements,s=t.m;return i[0]=s[0],i[1]=s[1],i[2]=s[2],i[3]=s[3],i[4]=s[4],i[5]=s[5],i[6]=s[6],i[7]=s[7],i[8]=s[8],i[9]=s[9],i[10]=s[10],i[11]=s[11],i[12]=s[12],i[13]=s[13],i[14]=s[14],i[15]=s[15],this._matrixWorld}get visible(){return this.isEnabled()}set visible(t){this.setEnabled(t)}get uuid(){return this.uniqueId.toString()}constructor(t,e){super("particleEmitter",e||void 0),this._matrixWorld=new st,this._matrixWorldFlag=-1,this.system=t}dispose(){super.dispose()}extractFromCache(t){const e=[];for(const i in t){const s=t[i];s&&"object"==typeof s&&delete s.metadata,e.push(s)}return e}clone(t){const e=this.system.clone().emitter;return e.name=t??this.name,e.position.copyFrom(this.position),e.rotation.copyFrom(this.rotation),e.scaling.copyFrom(this.scaling),this.rotationQuaternion&&(e.rotationQuaternion=this.rotationQuaternion.clone()),e.setEnabled(this.isEnabled(!1)),e}toJSON(t,e={}){return{uuid:this._quarksUUID??this.uniqueId.toString(),type:"ParticleEmitter",name:this.name,position:[this.position.x,this.position.y,this.position.z],rotation:[this.rotation.x,this.rotation.y,this.rotation.z],quaternion:this.rotationQuaternion?[this.rotationQuaternion.x,this.rotationQuaternion.y,this.rotationQuaternion.z,this.rotationQuaternion.w]:void 0,scale:[this.scaling.x,this.scaling.y,this.scaling.z],visible:this.isEnabled(),ps:this.system.toJSON(t,e)}}}class Ms{static runOnAllParticleEmitters(t,e){Ms.traverseNode(t,t=>{t instanceof zs&&e(t)})}static addToBatchRenderer(t,e){Ms.runOnAllParticleEmitters(t,t=>{e.addSystem(t.system)})}static play(t){Ms.runOnAllParticleEmitters(t,t=>{t.system.play()})}static stop(t){Ms.runOnAllParticleEmitters(t,t=>{t.system.stop()})}static pause(t){Ms.runOnAllParticleEmitters(t,t=>{t.system.pause()})}static restart(t){Ms.runOnAllParticleEmitters(t,t=>{t.system.restart()})}static setAutoDestroy(t,e){Ms.runOnAllParticleEmitters(t,t=>{t.system.autoDestroy=e})}static endEmit(t){Ms.runOnAllParticleEmitters(t,t=>{t.system.endEmit()})}static isEffectFinished(t){let e=!1,i=!0;return Ms.runOnAllParticleEmitters(t,t=>{e=!0,t.system.isFinished()||(i=!1)}),e&&i}static instantiate(t,e){const i=new Map,r=(t,e,n)=>{let o;if(t instanceof zs)o=t.clone(n),i.set(t,o);else{if(!(t instanceof s.TransformNode))return null;o=new s.TransformNode(n??t.name,t.getScene()),o.position.copyFrom(t.position),o.rotation.copyFrom(t.rotation),o.scaling.copyFrom(t.scaling),t.rotationQuaternion&&(o.rotationQuaternion=t.rotationQuaternion.clone()),o.setEnabled(t.isEnabled(!1))}o.parent=e;for(const e of t.getChildren())r(e,o);return o},n=r(t,null,e);for(const t of i.values())for(const e of t.system.behaviors)if(e instanceof ve){const t=i.get(e.subParticleSystem);void 0!==t&&(e.subParticleSystem=t)}return n}static traverseNode(t,e){e(t);const i=t.getChildren();for(const t of i)Ms.traverseNode(t,e)}}const _s=new WeakMap,Ps=new WeakMap;function Ts(t){if(!t?.isCube)return null;const e=t.files??t._files;return 6===e?.length?e.slice():null}function Vs(t){return _s.get(t)??null}async function Os(t,e){if("undefined"==typeof document||"undefined"==typeof Image)throw new Error("createEnvAtlasFromFaceUrls requires a DOM Image/canvas environment");const i=await Promise.all(t.map(t=>function(t){return new Promise((e,i)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>e(s),s.onerror=()=>i(new Error(`Failed to load env face ${t}`)),s.src=t})}(t))),s=i[0].width||i[0].naturalWidth;if(!s)throw new Error("Env atlas face image has zero size");const r=document.createElement("canvas");r.width=3*s,r.height=2*s;const n=r.getContext("2d");if(!n)throw new Error("Could not create env atlas canvas");for(let t=0;t<6;t++)n.drawImage(i[t],t%3*s,Math.floor(t/3)*s,s,s);const o=new y.Texture(r.toDataURL("image/jpeg",.92),e,{noMipmap:!0,invertY:!1,samplingMode:y.Texture.LINEAR_LINEAR});return o.name="quarksEnvAtlas",o}const Cs={createFromFaceUrls:Os};function Fs(t,e,i){const s=_s.get(t);if(s)return i(s),s;const r=()=>{const s=Ps.get(t);if(s)return void s.then(t=>{t&&i(t)});const r=Ts(t);if(!r)return;const n=Cs.createFromFaceUrls(r,e).then(e=>(_s.set(t,e),Ps.delete(t),i(e),e)).catch(e=>(Ps.delete(t),console.warn("[babylon.quarks] Failed to build env atlas from cubemap faces",e),null));Ps.set(t,n)};if(t.isReady())r();else{const e=t.onLoadObservable;e?e.addOnce(()=>r()):r()}return _s.get(t)??null}class Bs extends g.StandardMaterial{constructor(t,e,i={}){super(t,e),this.isParticleMeshStandardMaterial=!0,Object.assign(this,i)}}class As extends v.PBRMaterial{constructor(t,e,i={}){super(t,e),this.isParticleMeshPhysicsMaterial=!0,Object.assign(this,i)}}function $s(t,e){if(e&&e.length>0)return e;const i=t.length/3,s=new Uint32Array(i);for(let t=0;t<i;t++)s[t]=t;return s}const Is=new H(0,0,1),Es=new Z,Ns=new Z,Ls=new H,Rs=new H,Ds=1/60,Us=new Set(["SizeOverLife","SizeBySpeed"]),qs=new Set(["ColorOverLife","ColorBySpeed"]),ks=new Set(["ApplyForce","Noise","TurbulenceField","GravityForce","RotationOverLife","Rotation3DOverLife","RotationBySpeed","SpeedOverLife","FrameOverLife","ForceOverLife","VelocityOverLife","InheritVelocity","OrbitOverLife","WidthOverLength","ChangeEmitDirection","EmitSubParticleSystem","LimitSpeedOverLife","ApplyCollision"]),Js=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),Qs=new Float32Array([0,0,1,0,1,1,0,1]);const Gs=new Uint32Array([0,1,2,0,2,3]);function Ws(t){const e={};return t?.uvFromHead&&(e.uvFromHead=!0),t?.colorFromParticle&&(e.colorFromParticle=!0),t?.dieWithParticle&&(e.dieWithParticle=!0),t?.recordWorldSpace&&(e.recordWorldSpace=!0),e}class js{set time(t){this.emissionState.time=t}get time(){return this.emissionState.time}get isEmitEnded(){return this.emitEnded}hasPendingEmission(){if(this.looping)return!0;if(this.emitEnded)return!1;if(this.onlyUsedByOther)return!1;const t=this.emissionState;if(t.waitEmiting>0)return!0;if(t.burstIndex<this.emissionBursts.length)return!0;if(this.hasPendingBurstWaves(t))return!0;if(t.time>=this.duration)return!1;const e=t.time/this.duration;return this.emissionOverTime.genValue(this.memory,e)>0||this.emissionOverDistance.genValue(this.memory,e)>0}isFinished(){return!(this.particleNum>0)&&(!!this.onlyUsedByOther||(this.looping?this.emitEnded:!this.hasPendingEmission()))}get layers(){return this.layerMaskProxy}get texture(){return this.rendererSettings.texture}set texture(t){this.rendererSettings.texture=t,this.neededToUpdateRender=!0}get material(){return this.materialRef}set material(t){this.materialRef=t,this.applyMaterialSettings(t)}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(t){this.rendererSettings.uTileCount=t,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(t){this.rendererSettings.vTileCount=t,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(t){this.rendererSettings.blendTiles=t,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(t){this.rendererSettings.softParticles=t,this.neededToUpdateRender=!0}get sortMode(){return this.rendererSettings.sortMode}set sortMode(t){this.rendererSettings.sortMode=js.validSortMode(t),this.neededToUpdateRender=!0}get minParticleSize(){return this.rendererSettings.minParticleSize}set minParticleSize(t){this.rendererSettings.minParticleSize=Math.max(0,t),this.neededToUpdateRender=!0}get maxParticleSize(){return this.rendererSettings.maxParticleSize}set maxParticleSize(t){this.rendererSettings.maxParticleSize=t>0?t:1/0,this.neededToUpdateRender=!0}get pivot(){return this.rendererSettings.pivot}set pivot(t){this.rendererSettings.pivot=js.nonZeroPivot(t),this.neededToUpdateRender=!0}get lighting(){return this.rendererSettings.lighting??"fixed"}set lighting(t){this.rendererSettings.lighting=js.validLighting(t),this.neededToUpdateRender=!0}get rim(){return this.rendererSettings.rim}set rim(t){this.rendererSettings.rim=fs(t),this.neededToUpdateRender=!0}static validLighting(t){return"unlit"===t||"scene"===t?t:"fixed"}static validSortMode(t){return"distance"===t||"oldestInFront"===t||"youngestInFront"===t?t:"none"}static validCullingMode(t){return"pause"===t||"pauseAndCatchUp"===t?t:"always"}static nonZeroPivot(t){return!t||0===t.x&&0===t.y&&0===t.z?void 0:t.clone()}static nonZeroFlip(t){return t&&(t.x>0||t.y>0)?t.clone():void 0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(t){this.rendererSettings.softNearFade=t,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(t){this.rendererSettings.softFarFade=t,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(t){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=t,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.materialBlendMode}set blending(t){this.rendererSettings.materialBlendMode=t,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(t){if(this.rendererSettings.renderMode!==t){let e=!1;switch(this.rendererSettings.renderMode===exports.RenderMode.Trail&&(e=!0),this.rendererSettings.renderMode===exports.RenderMode.Mesh&&(this.startRotation=new Ct(0)),t){case exports.RenderMode.Trail:this.rendererEmitterSettings={startLength:new Ct(30),followLocalOrigin:!1},e=!0;break;case exports.RenderMode.Mesh:this.rendererEmitterSettings={},this.startRotation=new Et(new H(0,1,0),new Ct(0));break;case exports.RenderMode.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2};break;case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:this.rendererEmitterSettings={}}this.rendererSettings.renderMode=t,e&&(this.restart(),this.particles.length=0),this.neededToUpdateRender=!0}}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(t){this.rendererSettings.renderOrder=t,this.neededToUpdateRender=!0}get renderingGroupId(){return this.rendererSettings.renderingGroupId}set renderingGroupId(t){this.rendererSettings.renderingGroupId=t,this.neededToUpdateRender=!0}get applyFog(){return this.rendererSettings.applyFog}set applyFog(t){this.rendererSettings.applyFog=t,this.neededToUpdateRender=!0}get seed(){return this.seedValue}set seed(t){this.seedValue=t,this.rng=void 0===t?void 0:z(t)}constructor(t){if(this.store=new ze(64),this.emitterVelocity=new H,this.finishedEventFired=!1,this.startDelayTimeLeft=0,this.tempEmitterPos=new H,this.temp=new H,this.pathMatrix=new st,this.normalMatrix=new ft,this.memory=[],this.listeners={},this.materialRef=null,this.qualityFactor=1,this.simulationAccumulator=0,this.destroyed=!1,this.fusionSteps=[],this.planChangesSize=!0,this.planChangesColor=!0,this.playbackSpeed=1,this.cullingMode="always",this.alignToDirection=!1,this.culled=!1,this.pendingCatchUp=0,this.boundsMin=new H,this.boundsMax=new H,this.boundsPadding=0,this.boundsValid=!1,this.stepsSinceBounds=0,this.boundsMaxSize=0,this.boundsMaxSpeedSq=0,this.boundsInWorld=!1,this.geometryRadius=1,this.firstTimeUpdate=!0,this.sceneRef=t.scene,this.layerMaskProxy={mask:t.layerMask??268435455},Object.defineProperty(this.layerMaskProxy,"mask",{enumerable:!0,get:()=>this.rendererSettings.layerMask,set:t=>{this.rendererSettings.layerMask=t,this.neededToUpdateRender=!0}}),this.autoDestroy=t.autoDestroy??!1,this.duration=t.duration??1,this.startDelay=t.startDelay??new Ct(0),this.looping=t.looping??!0,this.prewarm=t.prewarm??!1,this.startLife=t.startLife??new Ct(5),this.startSpeed=t.startSpeed??new Ct(0),this.startRotation=t.startRotation??new Ct(0),this.startSize=t.startSize??new Ct(1),this.startColor=t.startColor??new jt(new zt(1,1,1,1)),this.emissionOverTime=t.emissionOverTime??new Ct(10),this.emissionOverDistance=t.emissionOverDistance??new Ct(0),this.emissionBursts=t.emissionBursts??[],this.maxParticles=t.maxParticles,this.onlyUsedByOther=t.onlyUsedByOther??!1,this.emitterShape=t.shape??new Ci,this.behaviors=t.behaviors??[],this.worldSpace=t.worldSpace??!1,this.rendererEmitterSettings=t.rendererEmitterSettings??{},t.renderMode===exports.RenderMode.StretchedBillBoard){const e=this.rendererEmitterSettings;void 0!==t.speedFactor&&(e.speedFactor=t.speedFactor),e.speedFactor=e.speedFactor??0,e.lengthFactor=e.lengthFactor??0}var e;this.rendererSettings={instancingGeometry:t.instancingGeometry??Js,instancingIndices:t.instancingIndices??Gs,instancingUVs:t.instancingUVs??(t.instancingGeometry?(e=t.instancingGeometry,new Float32Array(e.length/3*2)):Qs),instancingNormals:t.instancingNormals,renderMode:t.renderMode??exports.RenderMode.BillBoard,renderOrder:t.renderOrder??0,uTileCount:t.uTileCount??1,vTileCount:t.vTileCount??1,blendTiles:t.blendTiles??!1,softParticles:t.softParticles??!1,softNearFade:t.softNearFade??0,softFarFade:t.softFarFade??0,materialBlendMode:t.blendMode??r.Constants.ALPHA_ADD,materialTransparent:t.transparent??!0,materialDepthTest:t.depthTest??!0,materialDepthWrite:t.depthWrite??!1,materialAlphaTest:t.alphaTest??0,texture:t.texture??null,reflectionTexture:null,reflectionLevel:1,reflectionFaces:null,reflectionAtlas:null,layerMask:t.layerMask??268435455,pivot:js.nonZeroPivot(t.pivot),sortMode:js.validSortMode(t.sortMode),minParticleSize:Math.max(0,t.minParticleSize??0),maxParticleSize:t.maxParticleSize??1/0,renderingGroupId:t.renderingGroupId??0,applyFog:t.applyFog??!0,lighting:js.validLighting(t.lighting),rim:fs(t.rim)},this.flip=js.nonZeroFlip(t.flip),this.playbackSpeed=t.playbackSpeed??1,this.cullingMode=t.cullingMode??"always",this.alignToDirection=!0===t.alignToDirection,this.seed=t.seed,this.rendererSettings.renderMode!==exports.RenderMode.Mesh||this.rendererSettings.instancingNormals||(this.rendererSettings.instancingNormals=js.createFallbackNormals(this.rendererSettings.instancingGeometry)),this.materialRef=t.material??null,this.applyMaterialSettings(this.materialRef,{blendMode:t.blendMode,transparent:t.transparent,depthTest:t.depthTest,depthWrite:t.depthWrite,alphaTest:t.alphaTest,texture:t.texture,layerMask:t.layerMask}),this.neededToUpdateRender=!0,this.particles=[],this.startTileIndex=t.startTileIndex||new Ct(0),this.emitter=new zs(this,t.scene),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.startDelay.startGen(this.memory),this.startDelayTimeLeft=this.startDelay.genValue(this.memory,0),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}applyMaterialSettings(t,e={}){if(!this.rendererSettings)return;const i=void 0!==e.texture?e.texture:t?.albedoTexture??t?.diffuseTexture??t?.emissiveTexture??t?.opacityTexture??t?.baseTexture??this.rendererSettings.texture??null,s=t?.reflectionTexture??t?.environmentTexture??this.rendererSettings.reflectionTexture??null,r="number"==typeof s?.level?s.level:1,n=e.blendMode??("number"==typeof t?.alphaMode?t.alphaMode:this.rendererSettings.materialBlendMode),o=e.transparent??("function"==typeof t?.needAlphaBlending?t.needAlphaBlending():"number"==typeof t?.alpha?t.alpha<1:this.rendererSettings.materialTransparent),a=e.depthTest??("boolean"==typeof t?.disableDepthTest?!t.disableDepthTest:this.rendererSettings.materialDepthTest),h=e.depthWrite??("boolean"==typeof t?.disableDepthWrite?!t.disableDepthWrite:"boolean"==typeof t?.forceDepthWrite?t.forceDepthWrite:this.rendererSettings.materialDepthWrite),l=e.alphaTest??(()=>{const e=t?.transparencyMode,i=1===e||3===e;return i&&"number"==typeof t?.alphaCutOff?t.alphaCutOff:i&&"number"==typeof t?.alphaCutOffValue?t.alphaCutOffValue:t?0:this.rendererSettings.materialAlphaTest})();this.rendererSettings.texture=i,this.rendererSettings.reflectionTexture=s,this.rendererSettings.reflectionLevel="number"==typeof t?.reflectionLevel?t.reflectionLevel:r;let c=t?.reflectionAtlas??e.reflectionAtlas??this.rendererSettings.reflectionAtlas??null;!c&&s?.isCube&&(c=Vs(s),!c&&this.sceneRef&&(Fs(s,this.sceneRef,e=>{this.rendererSettings.reflectionAtlas!==e&&(this.rendererSettings.reflectionAtlas=e,t&&null==t.reflectionAtlas&&(t.reflectionAtlas=e),this.neededToUpdateRender=!0)}),c=Vs(s))),this.rendererSettings.reflectionAtlas=c,this.rendererSettings.reflectionFaces=6===t?.reflectionFaces?.length?t.reflectionFaces:null,this.rendererSettings.materialBlendMode=n,this.rendererSettings.materialTransparent=o,this.rendererSettings.materialDepthTest=a,this.rendererSettings.materialDepthWrite=h,this.rendererSettings.materialAlphaTest=l,void 0!==e.layerMask&&(this.rendererSettings.layerMask=e.layerMask),this.neededToUpdateRender=!0}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}setQualityFactor(t){this.qualityFactor=Math.max(.1,Math.min(1,t))}rebindParticles(){const t=this.particles;for(let e=0;e<t.length;e++)t[e].rebind()}growParticlePool(t){const e=this.particles.length;this.store.ensureCapacity(e+1)&&this.rebindParticles(),this.particles.push(t?new ei(this.store,e):new Ke(this.store,e))}spawn(t,e,i){const s=Ls,r=Rs;i.decompose(s,Es,r);const n=this.behaviors,o=n.length,a=this.rendererSettings.renderMode,h=a===exports.RenderMode.Trail,l=!h,c=a===exports.RenderMode.Mesh,u="rotation"===this.startRotation.type,d="vec3function"===this.startSize.type,p=e.time/this.duration,f=h?this.rendererEmitterSettings:void 0,m=Boolean(f?.followLocalOrigin);void 0!==this.maxParticles&&(t=Math.min(t,Math.max(0,this.maxParticles-this.particleNum)));for(let s=0;s<t;s++){e.burstParticleIndex=s,this.particleNum++,this.particles.length<this.particleNum&&this.growParticlePool(h);const t=this.particles[this.particleNum-1];if(t.reset(),t.speedModifier=1,this.finishedEventFired=!1,this.startColor.startGen(t.memory),this.startColor.genColor(t.memory,t.startColor,this.emissionState.time),t.color.copy(t.startColor),this.startSpeed.startGen(t.memory),t.startSpeed=this.startSpeed.genValue(t.memory,p),this.startLife.startGen(t.memory),t.life=this.startLife.genValue(t.memory,p),t.age=0,this.startSize.startGen(t.memory),d)this.startSize.genValue(t.memory,t.startSize,p);else{const e=this.startSize.genValue(t.memory,p);t.startSize.set(e,e,e)}if(this.startTileIndex.startGen(t.memory),t.uvTile=this.startTileIndex.genValue(t.memory),t.size.copy(t.startSize),l){const e=t;if(this.startRotation.startGen(t.memory),c)e.rotation instanceof Z||(e.rotation=Ns),e.angularVelocity instanceof Z&&e.angularVelocity.set(0,0,0,1),u?this.startRotation.genValue(t.memory,e.rotation,1,p):e.rotation.setFromAxisAngle(Is,this.startRotation.genValue(e.memory,p));else{e.rotation=u?0:this.startRotation.genValue(e.memory,p),e.angularVelocity=0;const t=this.flip;e.flip=void 0===t?0:(S()<t.x?1:0)|(S()<t.y?2:0)}}else if(f){const e=t;f.startLength.startGen(e.memory),e.length=f.startLength.genValue(e.memory,p),e.ensureHistoryCapacity(Math.max(1,Math.ceil(e.length))),e.resetHistory()}this.emitterShape.initialize(t,e),this.alignToDirection&&l&&this.alignParticleToDirection(t,c);const a=e.particle,y=e.inherit;if(void 0!==a&&void 0!==y&&0!==y&&this.inheritFromParent(t,a,y,l),h&&m){const e=t;e.localPosition||(e.localPosition=new H),e.localPosition.copy(e.position)}this.worldSpace?(t.position.applyMatrix4(i),t.startSize.multiply(r).abs(),t.size.copy(t.startSize),t.velocity.multiply(r).applyMatrix3(this.normalMatrix),t.rotation&&t.rotation instanceof Z&&t.rotation.multiplyQuaternions(Es,t.rotation)):this.onlyUsedByOther&&(t.parentMatrix=i);for(let e=0;e<o;e++)n[e].initialize(t,this);this.store.recordMemory(t.storeIndex,t.memory)}}alignParticleToDirection(t,e){const i=t.velocity,s=i.x*i.x+i.y*i.y+i.z*i.z;if(0!==s)if(e){const e=t.rotation;Ls.copy(i).divideScalar(Math.sqrt(s)),Es.setFromUnitVectors(Is,Ls),e.multiplyQuaternions(Es,e)}else 0===i.x&&0===i.y||(t.rotation=t.rotation+Math.atan2(-i.x,i.y))}inheritFromParent(t,e,i,s){if(i&me.color&&(t.startColor.multiply(e.color),t.color.copy(t.startColor)),i&me.size&&(t.startSize.multiply(e.size),t.size.copy(t.startSize)),i&me.rotation&&s){const i=t,s=e.rotation;"number"==typeof i.rotation?"number"==typeof s&&(i.rotation+=s):s instanceof Z&&i.rotation.multiplyQuaternions(s,i.rotation)}i&me.lifetime&&e.life>0&&(t.life*=Math.max(0,1-e.age/e.life))}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this.destroyed||(this.destroyed=!0,this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.fire({type:"destroy",particleSystem:this}))}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.boundsValid=!1,this.pendingCatchUp=0,void 0!==this.seedValue&&(this.rng=z(this.seedValue)),this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.burstWaves=void 0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(t=>t.reset()),this.emitEnded=!1,this.markForDestroy=!1,this.finishedEventFired=!1,this.prewarmed=!1,this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.startDelay.startGen(this.memory),this.startDelayTimeLeft=this.startDelay.genValue(this.memory,0),this.previousEmitterPos=void 0,this.emitterVelocity.set(0,0,0),this.simulationAccumulator=0,this.destroyed=!1}update(t,e=1/0,i){if(this.paused)return;if(t*=this.playbackSpeed,this.culled)return void("pauseAndCatchUp"===this.cullingMode&&(this.pendingCatchUp=Math.min(2,this.pendingCatchUp+t)));if(this.pendingCatchUp>0&&this.catchUp(i??performance.now()+js.catchUpBudgetMs),this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.computeWorldMatrix(!0)),!this.looping&&this.finishedEventFired&&0===this.particleNum){t>.1&&(t=.1),this.simulationAccumulator+=t;const e=Math.min(8,Math.max(0,Math.round(this.simulationAccumulator/Ds-1e-9)));return void(this.simulationAccumulator-=e*Ds)}if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let t=0;t<60*this.duration;t++)this.update(1/60)}t>.1&&(t=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1);const s=this.emitter.matrixWorld.elements;if(this.tempEmitterPos.set(s[12],s[13],s[14]),void 0!==this.previousEmitterPos&&t>0&&this.emitterVelocity.copy(this.tempEmitterPos).sub(this.previousEmitterPos).divideScalar(t),(this.previousEmitterPos??(this.previousEmitterPos=new H)).copy(this.tempEmitterPos),this.startDelayTimeLeft>0&&(!this.prewarm||!this.looping)){if(this.startDelayTimeLeft-=t,this.startDelayTimeLeft>=0)return;t=Math.min(-this.startDelayTimeLeft,.1),this.startDelayTimeLeft=0}this.simulationAccumulator+=t;const r=Math.min(8,Math.max(0,Math.round(this.simulationAccumulator/Ds-1e-9)));for(let t=0;t<r&&(this.simulateStep(Ds),!(e!==1/0&&t+1<r&&performance.now()>=e));t++);this.simulationAccumulator-=r*Ds}catchUp(t){let e=Math.floor(this.pendingCatchUp/Ds);for(this.pendingCatchUp=0;e-- >0&&(this.simulateStep(Ds),!(e>0&&performance.now()>=t)););}storeBounds(t,e,i,s,r,n,o,a,h,l){if(0===t)return void(this.boundsValid=!1);this.stepsSinceBounds=e?0:this.stepsSinceBounds+1,this.boundsMaxSize=h,this.boundsMaxSpeedSq=l;const c=Math.sqrt(l),u=this.rendererSettings.renderMode;let d=c*Ds*(this.stepsSinceBounds+1);if(u===exports.RenderMode.Mesh)d+=h*this.meshGeometryRadius();else if(u===exports.RenderMode.StretchedBillBoard){const t=this.rendererEmitterSettings;d+=h*(1+(t.lengthFactor??0)+c*(t.speedFactor??0))}else{const t=this.rendererSettings.pivot;d+=h*(.75+(void 0===t?0:Math.abs(t.x)+Math.abs(t.y)+Math.abs(t.z)))}this.boundsMin.set(i,s,r),this.boundsMax.set(n,o,a),this.boundsPadding=d,this.boundsInWorld=this.worldSpace,this.boundsValid=!0}meshGeometryRadius(){const t=this.rendererSettings.instancingGeometry;if(t!==this.geometryRadiusFor){let e=0;for(let i=0;i+2<t.length;i+=3){const s=t[i]*t[i]+t[i+1]*t[i+1]+t[i+2]*t[i+2];s>e&&(e=s)}this.geometryRadius=Math.sqrt(e),this.geometryRadiusFor=t}return this.geometryRadius}getWorldBounds(t,e){if(!this.boundsValid)return!1;const i=this.boundsMin,s=this.boundsMax;if(this.boundsInWorld){const r=this.boundsPadding;return t.set(i.x-r,i.y-r,i.z-r),e.set(s.x+r,s.y+r,s.z+r),!0}const r=this.emitter.matrixWorld.elements,n=Math.sqrt(Math.max(r[0]*r[0]+r[1]*r[1]+r[2]*r[2],r[4]*r[4]+r[5]*r[5]+r[6]*r[6],r[8]*r[8]+r[9]*r[9]+r[10]*r[10])),o=this.boundsPadding*n;let a=1/0,h=1/0,l=1/0,c=-1/0,u=-1/0,d=-1/0;for(let t=0;t<8;t++){const e=1&t?s.x:i.x,n=2&t?s.y:i.y,o=4&t?s.z:i.z,p=1/(r[3]*e+r[7]*n+r[11]*o+r[15]),f=(r[0]*e+r[4]*n+r[8]*o+r[12])*p,m=(r[1]*e+r[5]*n+r[9]*o+r[13])*p,y=(r[2]*e+r[6]*n+r[10]*o+r[14])*p;f<a&&(a=f),f>c&&(c=f),m<h&&(h=m),m>u&&(u=m),y<l&&(l=y),y>d&&(d=y)}return t.set(a-o,h-o,l-o),e.set(c+o,u+o,d+o),!0}setWorldBounds(t,e,i,s,r,n,o){this.boundsMin.set(t,e,i),this.boundsMax.set(s,r,n),this.boundsPadding=o,this.boundsInWorld=!0,this.boundsValid=!0}get simulationStep(){return Ds}get simulationResidual(){return this.paused?0:this.simulationAccumulator>Ds?Ds:this.simulationAccumulator<-Ds?-Ds:this.simulationAccumulator}behaviorSteps(){const t=this.behaviors,e=this.fusionPlan;if(void 0!==e&&e.length===t.length){let i=!0;for(let s=0;s<t.length;s++)if(e[s]!==t[s]){i=!1;break}if(i)return this.fusionSteps}this.fusionPlan=t.slice(),this.fusionSteps=vi(t);let i=!1,s=!1;for(let e=0;e<t.length;e++){const r=t[e].type;Us.has(r)?i=!0:qs.has(r)?s=!0:ks.has(r)||(i=!0,s=!0)}return this.planChangesSize=i,this.planChangesColor=s,this.fusionSteps}simulateStep(t){const e=this.rng;if(void 0===e)return void this.stepOnce(t);const i=b(e);try{this.stepOnce(t)}finally{b(i)}}stepOnce(t){this.onlyUsedByOther||this.emit(t,this.emissionState,this.emitter.matrixWorld);const e=this.particles,i=this.behaviors;i.length;const s=this.particleNum,r=this.rendererSettings.renderMode===exports.RenderMode.Trail,n=this.rendererSettings.renderMode===exports.RenderMode.StretchedBillBoard,o=this.store,a=3*s,h=this.behaviorSteps(),l=this.planChangesSize,c=this.planChangesColor;o.useSizeSnapshot(l),o.useColorSnapshot(c),o.previousPosition.set(o.position.subarray(0,a)),l&&o.previousSize.set(o.size.subarray(0,a)),n&&(o.keepPreviousVelocity()&&this.rebindParticles(),o.previousVelocity.set(o.velocity.subarray(0,a))),c&&o.previousColor.set(o.color.subarray(0,4*s)),this.emitterShape.update(this,t);for(let r=0;r<h.length;r++){const n=h[r],o=n.behaviors;for(let e=0;e<o.length;e++)o[e].frameUpdate(t);if(0===s)continue;if(void 0!==n.run){n.run(i,e,s,t,this.store);continue}const a=o[0];if(void 0===a.updateAll)for(let i=0;i<s;i++){const s=e[i];s.age<s.life&&a.update(s,t)}else a.updateAll(e,s,t)}const u=this.hasListeners("particleDied"),d=this.store,p=d.scalars,f=ze.SCALAR_STRIDE;let m=this.particleNum;if(!r){const i=d.position,s=d.velocity,r=d.previousSize,n=d.size,o=d.previousColor,a=d.color,h=l,y=c,v=this.stepsSinceBounds>=4||!this.boundsValid,g=this.boundsMin,x=this.boundsMax;let S=v?1/0:g.x,w=v?1/0:g.y,b=v?1/0:g.z,z=v?-1/0:x.x,M=v?-1/0:x.y,_=v?-1/0:x.z,P=v?0:this.boundsMaxSize,T=v?0:this.boundsMaxSpeedSq;for(let l=0;l<m;l++){const c=l*f;let g=p[c+ze.AGE];const x=3*l,V=v||0===g;if(0===g&&(h&&(r[x]=n[x],r[x+1]=n[x+1],r[x+2]=n[x+2]),y)){const t=4*l;o[t]=a[t],o[t+1]=a[t+1],o[t+2]=a[t+2],o[t+3]=a[t+3]}const O=t*p[c+ze.SPEED_MODIFIER],C=s[x],F=s[x+1],B=s[x+2],A=i[x]+C*O,$=i[x+1]+F*O,I=i[x+2]+B*O;if(i[x]=A,i[x+1]=$,i[x+2]=I,V&&(S=Math.min(S,A),z=Math.max(z,A),w=Math.min(w,$),M=Math.max(M,$),b=Math.min(b,I),_=Math.max(_,I),P=Math.max(P,Math.max(n[x],Math.max(n[x+1],n[x+2])))),T=Math.max(T,C*C+F*F+B*B),g+=t,p[c+ze.AGE]=g,g>=p[c+ze.LIFE]){const t=m-1,i=e[l],s=e[t];e[l]=s,e[t]=i,l!==t&&(d.swapRows(l,t),s.setStoreIndex(l),i.setStoreIndex(t)),m--,l--,u&&this.fire({type:"particleDied",particleSystem:this,particle:i})}}return this.particleNum=m,this.storeBounds(m,v,S,w,b,z,M,_,P,T),void this.notifyFinished()}if(s>0){const t=o.previousSize,e=o.size,i=o.previousColor,r=o.color;for(let n=0,o=0,a=0,h=0;n<s;n++,o+=3,a+=4,h+=f)0===p[h+ze.AGE]&&(l&&(t[o]=e[o],t[o+1]=e[o+1],t[o+2]=e[o+2]),c&&(i[a]=r[a],i[a+1]=r[a+1],i[a+2]=r[a+2],i[a+3]=r[a+3]))}if(this.rendererEmitterSettings.followLocalOrigin){const i=this.emitter.matrixWorld;for(let r=0;r<s;r++){const s=e[r];s.localPosition?(s.position.copy(s.localPosition),s.position.applyMatrix4(s.parentMatrix??i)):s.position.addScaledVector(s.velocity,t*s.speedModifier),s.age+=t}}else{const e=d.position,i=d.velocity;for(let r=0,n=0,o=0;r<s;r++,n+=3,o+=f){const s=t*p[o+ze.SPEED_MODIFIER];e[n]+=i[n]*s,e[n+1]+=i[n+1]*s,e[n+2]+=i[n+2]*s,p[o+ze.AGE]+=t}}{const t=this.rendererEmitterSettings,i=t.dieWithParticle,r=t.recordWorldSpace&&!this.worldSpace,n=this.emitter.matrixWorld;for(let t=0;t<s;t++){const s=e[t];if(i&&s.age>=s.life)s.resetHistory();else if(s.update(),r&&s.age<=s.life){const t=(s.historyHead+s.historyCapacity-1)%s.historyCapacity*3,e=s.historyPositions;Ls.set(e[t],e[t+1],e[t+2]),Ls.applyMatrix4(s.parentMatrix??n),e[t]=Ls.x,e[t+1]=Ls.y,e[t+2]=Ls.z}}}for(let t=0;t<m;t++){const i=e[t],s=t*f;if(p[s+ze.AGE]>=p[s+ze.LIFE]&&0===i.historyCount){const s=m-1,r=e[s];e[t]=r,e[s]=i,t!==s&&(d.swapRows(t,s),r.setStoreIndex(t),i.setStoreIndex(s)),m--,t--,u&&this.fire({type:"particleDied",particleSystem:this,particle:i})}}this.particleNum=m,this.notifyFinished()}notifyFinished(){this.isFinished()&&(this.finishedEventFired||(this.finishedEventFired=!0,this.fire({type:"finished",particleSystem:this})),this.autoDestroy&&(this.markForDestroy=!0,this.dispose()))}static burstWaveCount(t){return t.cycle>=1?Math.floor(t.cycle):1}static burstInterval(t){return t.interval>0?t.interval:0}emitBursts(t,e){const i=this.emissionBursts,s=i.length,r=t.time,n=t.burstWaves??(t.burstWaves=[]);for(;t.burstIndex<s&&i[t.burstIndex].time<=r;)n[t.burstIndex]=0,t.burstIndex++;const o=t.burstIndex;for(let s=0;s<o;s++){const o=i[s],a=js.burstWaveCount(o);let h=n[s]??0;if(h>=a)continue;const l=js.burstInterval(o);for(;h<a;){const i=o.time+h*l;if(h>0&&i>this.duration){h=a;break}if(i>r)break;t.burstWaveIndex=h,this.fireBurstWave(o,t,e),h++}n[s]=h}}fireBurstWave(t,e,i){if(S()>=t.probability)return;const s=t.count.genValue(this.memory,this.time),r=this.qualityFactor,n=r>=.999?s:Math.floor(s*r);e.isBursting=!0,e.burstParticleCount=n,this.spawn(n,e,i),e.isBursting=!1}hasPendingBurstWaves(t){const e=t.burstWaves;if(void 0===e)return!1;const i=this.emissionBursts;for(let s=0;s<t.burstIndex&&s<i.length;s++){const t=i[s],r=e[s]??0;if(r<js.burstWaveCount(t)&&(0===r||t.time+r*js.burstInterval(t)<=this.duration))return!0}return!1}spawnAlongPath(t,e,i,s,r,n,o){const a=this.pathMatrix.copy(i),h=i.elements,l=a.elements,c=h[12],u=h[13],d=h[14];for(let i=1;i<=t;i++){const t=i*n-r,h=t<=0?0:t>=o?1:t/o;l[12]=s.x+(c-s.x)*h,l[13]=s.y+(u-s.y)*h,l[14]=s.z+(d-s.z)*h,this.spawn(1,e,a)}}emit(t,e,i){if(e.time>this.duration)if(this.looping){e.time-=this.duration,e.burstIndex=0,void 0!==e.burstWaves&&(e.burstWaves.length=0);for(let t=0;t<this.behaviors.length;t++)this.behaviors[t].reset()}else this.emitEnded||this.onlyUsedByOther||this.endEmit();this.worldSpace&&this.normalMatrix.getNormalMatrix(i);const s=this.emissionBursts.length,r=this.qualityFactor;s>0&&this.emitBursts(e,i);let n=0,o=0,a=0,h=0;const l=e.previousWorldPos;if(!this.emitEnded){const s=e.time/this.duration;if(e.waitEmiting+=t*this.emissionOverTime.genValue(this.memory,s)*r,void 0!==l){this.temp.set(i.elements[12],i.elements[13],i.elements[14]),h=l.distanceTo(this.temp),a=e.travelDistance,e.travelDistance+=h;const t=this.emissionOverDistance.genValue(this.memory,s)*r;if(e.travelDistance*t>0){const i=Math.floor(e.travelDistance*t);e.travelDistance-=i/t,this.worldSpace&&h>0?(n=i,o=1/t):e.waitEmiting+=i}}}const c=Math.floor(e.waitEmiting);c>0&&(this.spawn(c,e,i),e.waitEmiting-=c),n>0&&this.spawnAlongPath(n,e,i,l,a,o,h),void 0===e.previousWorldPos&&(e.previousWorldPos=new H),e.previousWorldPos.set(i.elements[12],i.elements[13],i.elements[14]),e.time+=t}toJSON(t,e={}){const i=void 0===t||"string"==typeof t?{geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}:t,s=this.ensureGeometryMeta(i),r=this.ensureMaterialMeta(i),n=this.toRendererSettingsJSON();return{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,startDelay:this.startDelay.toJSON(),shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(t=>({time:t.time,count:t.count.toJSON(),probability:t.probability,interval:t.interval,cycle:t.cycle})),...void 0!==this.maxParticles?{maxParticles:this.maxParticles}:{},onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:s,renderMode:this.renderMode,renderOrder:this.renderOrder,...0!==this.renderingGroupId?{renderingGroupId:this.renderingGroupId}:{},...this.applyFog?{}:{applyFog:!1},...1!==this.playbackSpeed?{playbackSpeed:this.playbackSpeed}:{},..."always"!==this.cullingMode?{cullingMode:this.cullingMode}:{},...void 0!==this.seedValue?{seed:this.seedValue}:{},..."none"!==this.sortMode?{sortMode:this.sortMode}:{},...this.alignToDirection?{alignToDirection:!0}:{},...this.minParticleSize>0?{minParticleSize:this.minParticleSize}:{},...this.maxParticleSize!==1/0?{maxParticleSize:this.maxParticleSize}:{},rendererEmitterSettings:n,material:r,layers:this.rendererSettings.layerMask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.rendererSettings.uTileCount,vTileCount:this.rendererSettings.vTileCount,blendTiles:this.rendererSettings.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,blending:this.rendererSettings.materialBlendMode,transparent:this.rendererSettings.materialTransparent,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,behaviors:this.behaviors.map(t=>t.toJSON()),worldSpace:this.worldSpace,...this.pivot?{pivot:[this.pivot.x,this.pivot.y,this.pivot.z]}:{},...this.flip?{flip:[this.flip.x,this.flip.y]}:{}}}static fromJSON(t,e,i={},s){const n=Ai(t.shape,e);let o;if(t.renderMode===exports.RenderMode.Trail){const e=t.rendererEmitterSettings;o={startLength:void 0!==e?.startLength?It(e.startLength):new Ct(30),followLocalOrigin:e?.followLocalOrigin??!1,...Ws(e)}}else t.renderMode===exports.RenderMode.StretchedBillBoard?(o={...t.rendererEmitterSettings??{}},void 0!==t.speedFactor&&(o.speedFactor=t.speedFactor)):o={};const a=t.material?e.materials?.[t.material]:void 0,h=a?.texture??t.texture,l="string"==typeof h?e.textures?.[h]??null:h??null,c="string"==typeof t.instancingGeometry?e.geometries?.[t.instancingGeometry]:t.instancingGeometry,u=js.resolveGeometryData(c),d=new js({scene:s,autoDestroy:t.autoDestroy,looping:t.looping,prewarm:t.prewarm,duration:t.duration,startDelay:t.startDelay?It(t.startDelay):void 0,shape:n,startLife:It(t.startLife),startSpeed:It(t.startSpeed),startRotation:ee(t.startRotation),startSize:ee(t.startSize),startColor:Yt(t.startColor),emissionOverTime:It(t.emissionOverTime),emissionOverDistance:It(t.emissionOverDistance),emissionBursts:t.emissionBursts?.map(t=>({time:t.time,count:"number"==typeof t.count?new Ct(t.count):It(t.count),probability:t.probability??1,interval:t.interval??.1,cycle:t.cycle??t.cycleCount??1})),maxParticles:"number"==typeof t.maxParticles?t.maxParticles:void 0,onlyUsedByOther:t.onlyUsedByOther,instancingGeometry:u.positions,instancingIndices:u.indices,instancingUVs:u.uvs,instancingNormals:u.normals,renderMode:t.renderMode,rendererEmitterSettings:o,renderOrder:t.renderOrder,renderingGroupId:"number"==typeof t.renderingGroupId?t.renderingGroupId:void 0,applyFog:!1!==t.applyFog,playbackSpeed:"number"==typeof t.playbackSpeed?t.playbackSpeed:void 0,cullingMode:js.validCullingMode(t.cullingMode),seed:"number"==typeof t.seed?t.seed:void 0,sortMode:js.validSortMode(t.sortMode),alignToDirection:!0===t.alignToDirection,minParticleSize:"number"==typeof t.minParticleSize?t.minParticleSize:void 0,maxParticleSize:"number"==typeof t.maxParticleSize?t.maxParticleSize:void 0,texture:l,material:a?.sourceMaterial??a,blendMode:a?.alphaMode??t.blending??r.Constants.ALPHA_ADD,transparent:a?.transparent??t.transparent??!0,depthTest:a?.depthTest??t.depthTest??!0,depthWrite:a?.depthWrite??t.depthWrite??!1,alphaTest:a?.alphaTest??t.alphaTest??0,startTileIndex:"number"==typeof t.startTileIndex?new Ct(t.startTileIndex):It(t.startTileIndex),uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softFarFade:t.softFarFade,softNearFade:t.softNearFade,behaviors:[],worldSpace:t.worldSpace,layerMask:t.layers,pivot:t.pivot?new H(t.pivot[0]??0,t.pivot[1]??0,t.pivot[2]??0):void 0,flip:t.flip?new xt(t.flip[0]??0,t.flip[1]??0):void 0,lighting:a?.lighting,rim:a?.rim});return d.behaviors=(t.behaviors??[]).map(t=>{const e=ri(t,d);return e&&"EmitSubParticleSystem"===e.type&&(i[t.subParticleSystem]=e),e}).filter(t=>null!==t),d}static nextSerializationId(t){return js.serializationCounter+=1,`${t}_${js.serializationCounter}`}static createFallbackNormals(t){const e=new Float32Array(t.length);for(let t=0;t<e.length;t+=3)e[t]=0,e[t+1]=0,e[t+2]=1;return e}toRendererSettingsJSON(){return this.renderMode===exports.RenderMode.Trail?{startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin,...Ws(this.rendererEmitterSettings)}:this.renderMode===exports.RenderMode.StretchedBillBoard?{speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:{}}ensureGeometryMeta(t){const e=js.nextSerializationId("quarks_geometry");return t.geometries[e]={uuid:e,type:"QuarksGeometry",positions:Array.from(this.rendererSettings.instancingGeometry),indices:Array.from(this.rendererSettings.instancingIndices),uvs:this.rendererSettings.instancingUVs?Array.from(this.rendererSettings.instancingUVs):void 0,normals:this.rendererSettings.instancingNormals?Array.from(this.rendererSettings.instancingNormals):void 0},e}ensureMaterialMeta(t){const e=this.rendererSettings.texture;let i;e&&(i=js.nextSerializationId("quarks_texture"),t.textures[i]=e);const s=this.rendererSettings.reflectionAtlas;let r;s instanceof y.Texture&&(r=js.nextSerializationId("quarks_texture"),t.textures[r]=s);const n=js.nextSerializationId("quarks_material");return t.materials[n]={uuid:n,type:"QuarksMaterial",transparent:this.rendererSettings.materialTransparent,alphaMode:this.rendererSettings.materialBlendMode,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,texture:i,reflectionAtlas:r,reflectionLevel:this.rendererSettings.reflectionLevel,..."fixed"!==this.lighting?{lighting:this.lighting}:{},...this.rim?{rim:{...this.rim,color:[...this.rim.color]}}:{},sourceMaterial:this.materialRef??void 0},n}static resolveGeometryData(t){if(t?.positions){const e=t.positions instanceof Float32Array?t.positions:new Float32Array(t.positions);return{positions:e,indices:$s(e,t.indices instanceof Uint16Array||t.indices instanceof Uint32Array?t.indices:t.indices?new Uint32Array(t.indices):void 0),uvs:t.uvs?t.uvs instanceof Float32Array?t.uvs:new Float32Array(t.uvs):void 0,normals:t.normals?t.normals instanceof Float32Array?t.normals:new Float32Array(t.normals):void 0}}const e=t?.data??t;if(e?.attributes?.position?.array){const t=new Float32Array(e.attributes.position.array);let i;if(e.index?.array){i=new("Uint16Array"===e.index.type?Uint16Array:Uint32Array)(e.index.array)}return{positions:t,indices:$s(t,i),uvs:e.attributes.uv?.array?new Float32Array(e.attributes.uv.array):void 0,normals:e.attributes.normal?.array?new Float32Array(e.attributes.normal.array):void 0}}return{positions:Js,indices:Gs,uvs:Qs}}addBehavior(t){this.behaviors.push(t),this._renderer?._invalidateUpdateOrder()}getRendererSettings(){return this.rendererSettings}addEventListener(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)}removeAllEventListeners(t){this.listeners[t]&&(this.listeners[t]=[])}removeEventListener(t,e){if(this.listeners[t]){const i=this.listeners[t].indexOf(e);-1!==i&&this.listeners[t].splice(i,1)}}hasListeners(t){const e=this.listeners[t];return void 0!==e&&e.length>0}fire(t){const e=this.listeners[t.type];if(void 0!==e)for(let i=0;i<e.length;i++)e[i](t)}clone(){const t=this.behaviors.map(t=>t.clone());let e;e=this.renderMode===exports.RenderMode.Trail?{startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin,...Ws(this.rendererEmitterSettings)}:this.renderMode===exports.RenderMode.StretchedBillBoard?{lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:{};const i=new js({autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,startDelay:this.startDelay.clone(),shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:this.emissionBursts.map(t=>({...t})),maxParticles:this.maxParticles,onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,instancingIndices:this.rendererSettings.instancingIndices,instancingUVs:this.rendererSettings.instancingUVs,instancingNormals:this.rendererSettings.instancingNormals,renderMode:this.renderMode,renderOrder:this.renderOrder,renderingGroupId:this.renderingGroupId,applyFog:this.applyFog,playbackSpeed:this.playbackSpeed,cullingMode:this.cullingMode,seed:this.seedValue,sortMode:this.sortMode,alignToDirection:this.alignToDirection,minParticleSize:this.minParticleSize,maxParticleSize:this.maxParticleSize,rendererEmitterSettings:e,material:this.materialRef,texture:this.rendererSettings.texture,startTileIndex:this.startTileIndex,uTileCount:this.rendererSettings.uTileCount,vTileCount:this.rendererSettings.vTileCount,blendTiles:this.rendererSettings.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:t,worldSpace:this.worldSpace,blendMode:this.rendererSettings.materialBlendMode,transparent:this.rendererSettings.materialTransparent,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,layerMask:this.rendererSettings.layerMask,pivot:this.pivot,flip:this.flip,lighting:this.lighting,rim:this.rim,scene:this.emitter.getScene()});for(const e of t)e instanceof ve&&(e.particleSystem=i);return i}}js.serializationCounter=0,js.catchUpBudgetMs=2;class Ys extends s.TransformNode{constructor(t="QuarksPrefab",e){super(t,e),this.type="QuarksPrefab",this.animationData=[],this.isPlaying=!1,this.currentTime=-1e-5,this.timeScale=1,this.duration=0,this._lastUpdateTimeMs=Date.now(),this._tempAnimationJSON=[]}registerBatchedRenderer(t){this._batchedRenderer=t}addParticleSystemAnimation(t,e=0,i=0,s=!1){const r={startTime:e,duration:i>0?i:t.system.duration,type:"ps",loop:s,target:t};return this.animationData.push(r),this.pause(),this.updateDuration(),r}addThreeAnimation(t,e,i=0,s=e?.duration??0,r=!1,n){const o={startTime:i,duration:s>0?s:e?.duration??0,type:"three",loop:r,target:t,clip:e,clipUUID:n??e?.uuid};return this.animationData.push(o),this.updateDuration(),o}removeAnimation(t){this.animationData.splice(t,1),this.updateDuration()}play(){this.isPlaying||(this.isPlaying=!0,this._lastUpdateTimeMs=Date.now())}pause(){this.isPlaying&&(this.isPlaying=!1,this.animationData.forEach(t=>{"ps"===t.type&&t.target instanceof zs?t.target.system.pause():t.clip?.pause?.()}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(t=>{"ps"===t.type&&t.target instanceof zs?t.target.system.stop():t.clip?.stop?.()})}update(t){if(!this.isPlaying)return;const e=Date.now(),i=t??Math.max((e-this._lastUpdateTimeMs)/1e3,0);this._lastUpdateTimeMs=e;const s=this.currentTime;this.currentTime+=i*this.timeScale,this.currentTime>this.duration?this.stop():this.animationData.forEach(t=>{const e=t.startTime,i=t.startTime+t.duration,r=this.currentTime>=e&&this.currentTime<=i,n=s>=e&&s<=i;if(!r||n){if(!r&&n){if(t.loop&&"ps"===t.type&&t.target instanceof zs)return void t.target.system.restart();"ps"===t.type&&t.target instanceof zs?t.target.system.endEmit():t.loop?t.clip?.play?.():t.clip?.stop?.()}}else"ps"===t.type&&t.target instanceof zs?(t.target.system.restart(),this._batchedRenderer&&this._batchedRenderer.addSystem(t.target.system)):t.clip?.play?.()})}setTime(t){const e=this.currentTime;this.currentTime=t,this.animationData.forEach(i=>{const s=i.startTime,r=i.startTime+i.duration,n=this.currentTime>=s&&this.currentTime<r,o=e>=s&&e<r;!n||o?n||!o?n&&"three"===i.type&&i.clip?.setTime?.(Math.max(t-s,0)):"ps"===i.type&&i.target instanceof zs?i.target.system.endEmit():i.clip?.stop?.():"ps"===i.type&&i.target instanceof zs?i.target.system.restart():i.clip?.play?.()})}getDuration(){return this.duration}resolveReferences(t){const e={},i=t=>{t._quarksUUID&&(e[t._quarksUUID]=t),e[t.uniqueId.toString()]=t;const r=t.getChildren();for(const t of r)t instanceof s.TransformNode&&i(t)};i(t),this._tempAnimationJSON.forEach(t=>{const i=e[t.targetUUID];if("ps"===t.type&&i instanceof zs)this.addParticleSystemAnimation(i,t.startTime,t.duration,t.loop);else if("three"===t.type&&i){const e=this.resolveTimelineClip(i,t.clipUUID);this.addThreeAnimation(i,e,t.startTime,t.duration,t.loop,t.clipUUID)}}),this.updateDuration(),this._tempAnimationJSON=[]}toJSON(){return{type:this.type,name:this.name,animationData:this.animationData.map(t=>({startTime:t.startTime,duration:t.duration,type:t.type,targetUUID:t.target._quarksUUID??t.target.uniqueId.toString(),clipUUID:"three"===t.type?t.clipUUID??t.clip?.uuid:void 0,loop:t.loop}))}}static fromJSON(t,e){const i=new Ys(t.name||"QuarksPrefab",e);return Array.isArray(t.animationData)&&(i._tempAnimationJSON=t.animationData.filter(t=>"ps"===t?.type||"three"===t?.type)),i}resolveTimelineClip(t,e){const i=[t.animations,t.animationGroups,t.metadata?.animations,t.metadata?.animationGroups];for(const t of i){if(!Array.isArray(t))continue;if(!e)return t[0];const i=t.find(t=>t?.uuid===e);if(i)return i}}updateDuration(){let t=0;this.animationData.forEach(e=>{const i=e.startTime+e.duration;i>t&&(t=i)}),this.duration=t}}const Xs=new WeakMap,Zs=new WeakMap,Hs=new WeakMap;function Ks(t,e){let i=t.get(e);return void 0===i&&(i=new Map,t.set(e,i)),i}class tr{constructor(t,e={}){this.scene=t,this.options=e}async load(t){const{json:e,baseUrl:i}=await this.fetchEffectDocument(t);return this.loadFromJSON(e,i)}async loadFromJSON(t,e){const i=e??this.options.baseUrl??"";return await this.resolveResources(t,i),this.parse(t,i)}async loadAll(t,e={}){const i=await tr.mapPool(t,e.concurrency,async(i,s)=>{try{return await this.fetchEffectDocument(i)}catch(r){if(!e.continueOnError)throw r;return console.warn(`[QuarksLoader] Failed to fetch effect "${i}" (${s+1}/${t.length}):`,r),null}});return this.loadDocuments(i,e)}async loadFromJSONAll(t,e={}){const i=t.map(t=>{if(null!==t&&"object"==typeof t&&"json"in t){const e=t;return{json:e.json,baseUrl:e.baseUrl??this.options.baseUrl??""}}return{json:t,baseUrl:this.options.baseUrl??""}});return this.loadDocuments(i,e)}async resolveResources(t,e=""){await tr.resolveLinkedResources(t,{baseUrl:e,resolver:this.options.resolver,scene:this.scene})}static async resolveLinkedResources(t,e={}){const i=e.baseUrl??"",s=e.resolver,r=e.scene;await tr.inlineGeometryEntries(t,async t=>{const e=await tr.resolveWith(s,t,"geometry",i);return tr.fetchJsonWith(s,e,r)});const n=Array.isArray(t?.images)?t.images:[];await Promise.all(n.map(async t=>{"string"==typeof t?.url&&t.url&&(t.url=await tr.resolveWith(s,t.url,"image",i))}))}static async resolveExternalGeometries(t,e){await tr.inlineGeometryEntries(t,e)}parse(t,e=""){const i={textures:{},geometries:{},materials:{}};t.geometries&&this.parseGeometries(t.geometries,i),t.images&&this.parseImages(t.images,e,i),t.textures&&this.parseTextures(t.textures,i),t.materials&&this.parseMaterials(t.materials,i);const s=this.parseObject(t.object,i);return this.linkReferences(s),s}parseGeometries(t,e){for(const i of t)if("PlaneGeometry"===i.type){const t=(i.width||1)/2,s=(i.height||1)/2;e.geometries[i.uuid]={positions:new Float32Array([-t,-s,0,t,-s,0,t,s,0,-t,s,0]),indices:new Uint32Array([0,1,2,0,2,3]),uvs:new Float32Array([0,0,1,0,1,1,0,1]),normals:new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1])}}else if("SphereGeometry"===i.type)e.geometries[i.uuid]=this.parseSphereGeometry(i);else if("BufferGeometry"===i.type&&i.data){const t=this.parseBufferGeometry(i.data);e.geometries[i.uuid]=t}else"QuarksGeometry"===i.type&&("string"!=typeof i.url||i.positions||console.warn(`[QuarksLoader] Geometry "${i.url}" is an external file; use load(), loadFromJSON(), or resolveResources() before parse().`),e.geometries[i.uuid]=this.share({positions:new Float32Array(i.positions??[]),indices:i.indices?new Uint32Array(i.indices):new Uint32Array(0),uvs:i.uvs?new Float32Array(i.uvs):void 0,normals:i.normals?new Float32Array(i.normals):void 0}))}share(t){if(!1===this.options.shareResources)return t;const e=Ks(Zs,this.scene),i=function(t){let e=2166136261,i=2654435769;const s=[t.positions,t.indices,t.uvs,t.normals];let r="";for(const t of s){if(void 0===t){r+="-,";continue}const s=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);r+=s.length+",";for(let t=0;t<s.length;t++)e=Math.imul(e^s[t],16777619),i=Math.imul(i^s[t],1540483477)^i>>>15}return`${r}${(e>>>0).toString(16)}${(i>>>0).toString(16)}`}(t),s=e.get(i);return void 0!==s?s:(e.set(i,t),t)}static clearSharedResources(t){Xs.delete(t),Zs.delete(t),Hs.delete(t)}static joinUrl(t,e){return/^(data|blob):/i.test(e)||/^[a-z][a-z0-9+.-]*:\/\//i.test(e)||e.startsWith("/")?e:t+e}parseSphereGeometry(t){const e=t.radius??.5,i=Math.max(3,Math.floor(t.widthSegments??16)),s=Math.max(2,Math.floor(t.heightSegments??8)),r=t.phiStart??0,n=t.phiLength??2*Math.PI,o=t.thetaStart??0,a=t.thetaLength??Math.PI,h=[],l=[],c=[],u=[],d=[];let p=0;for(let t=0;t<=s;t++){const u=[],f=t/s,m=o+f*a;for(let t=0;t<=i;t++){const s=t/i,o=r+s*n,a=-e*Math.cos(o)*Math.sin(m),d=e*Math.cos(m),y=e*Math.sin(o)*Math.sin(m);h.push(a,d,y);const v=Math.hypot(a,d,y)||1;l.push(a/v,d/v,y/v),c.push(s,1-f),u.push(p++)}d.push(u)}const f=o<=0,m=o+a>=Math.PI;for(let t=0;t<s;t++)for(let e=0;e<i;e++){const i=d[t][e+1],r=d[t][e],n=d[t+1][e],o=d[t+1][e+1];0===t&&f||u.push(i,r,o),t===s-1&&m||u.push(r,n,o)}const y=h.length/3>65535?new Uint32Array(u):new Uint16Array(u);return{positions:new Float32Array(h),indices:y,uvs:new Float32Array(c),normals:new Float32Array(l)}}parseBufferGeometry(t){let e,i,s=new Float32Array(0),r=new Uint32Array(0);if(t.interleavedBuffers&&t.arrayBuffers){const r={};for(const[e,i]of Object.entries(t.interleavedBuffers)){const s=t.arrayBuffers[i.buffer];if(s){const t=new Float32Array(Array.isArray(s)?this.int32ArrayToFloat32(s):s);r[e]={data:t,stride:i.stride}}}if(t.attributes){if(t.attributes.position?.isInterleavedBufferAttribute){const e=t.attributes.position,i=r[e.data];i&&(s=this.extractInterleavedAttribute(i.data,i.stride,e.offset,e.itemSize))}if(t.attributes.uv?.isInterleavedBufferAttribute){const i=t.attributes.uv,s=r[i.data];s&&(e=this.extractInterleavedAttribute(s.data,s.stride,i.offset,i.itemSize))}if(t.attributes.normal?.isInterleavedBufferAttribute){const e=t.attributes.normal,s=r[e.data];s&&(i=this.extractInterleavedAttribute(s.data,s.stride,e.offset,e.itemSize))}}}else t.attributes&&(t.attributes.position?.array&&(s=new Float32Array(t.attributes.position.array)),t.attributes.uv?.array&&(e=new Float32Array(t.attributes.uv.array)),t.attributes.normal?.array&&(i=new Float32Array(t.attributes.normal.array)));return t.index&&(r="Uint16Array"===t.index.type?new Uint16Array(t.index.array):new Uint32Array(t.index.array)),r=$s(s,r),{positions:s,indices:r,uvs:e,normals:i}}extractInterleavedAttribute(t,e,i,s){const r=Math.floor(t.length/e),n=new Float32Array(r*s);for(let o=0;o<r;o++)for(let r=0;r<s;r++)n[o*s+r]=t[o*e+i+r];return n}int32ArrayToFloat32(t){const e=new ArrayBuffer(4*t.length),i=new Int32Array(e);for(let e=0;e<t.length;e++)i[e]=t[e];return new Float32Array(e)}async resolveResourceUrl(t,e,i){return tr.resolveWith(this.options.resolver,t,e,i)}async fetchEffectDocument(t){const e=this.options.baseUrl||t.substring(0,t.lastIndexOf("/")+1),i=await this.resolveResourceUrl(t,"effect",e);return{json:await tr.fetchJsonWith(this.options.resolver,i,void 0),baseUrl:e}}async loadDocuments(t,e){const i=t.length;if(0===i)return[];const s=new Array(i),r=new Array(i).fill(!1);let n=0;const o=(t,o)=>{r[t]||(r[t]=!0,s[t]=o,n++,e.onProgress?.(n,i))};await Promise.all(t.map(async(s,r)=>{if(s)try{await this.resolveResources(s.json,s.baseUrl)}catch(s){if(!e.continueOnError)throw s;console.warn(`[QuarksLoader] Failed to resolve resources for effect ${r+1}/${i}:`,s),t[r]=null,o(r,null)}}));for(let s=0;s<i;s++){if(r[s])continue;const n=t[s];if(n)try{o(s,this.parse(n.json,n.baseUrl))}catch(t){if(!e.continueOnError)throw t;console.warn(`[QuarksLoader] Failed to parse effect ${s+1}/${i}:`,t),o(s,null)}else o(s,null)}return s}static async mapPool(t,e,i){if(0===t.length)return[];const s=void 0!==e&&e>0?e:t.length,r=new Array(t.length);let n=0;const o=Math.min(s,t.length);return await Promise.all(Array.from({length:o},()=>(async()=>{for(;n<t.length;){const e=n++;r[e]=await i(t[e],e)}})())),r}static async resolveWith(t,e,i,s){return t?.resolve?t.resolve(e,i,s):tr.joinUrl(s,e)}static fetchJsonWith(t,e,i){const s=async()=>{if(t?.fetchJson)return t.fetchJson(e);const i=await fetch(e);if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()};if(!i)return s();const r=Ks(Hs,i),n=`json|${e}`;let o=r.get(n);return void 0===o&&(o=s().catch(t=>{throw r.get(n)===o&&r.delete(n),t}),r.set(n,o)),o}static async inlineGeometryEntries(t,e){const i=Array.isArray(t?.geometries)?t.geometries:[];await Promise.all(i.filter(t=>"string"==typeof t?.url&&!t.positions).map(async t=>{try{const i=await e(t.url);for(const e of["positions","indices","uvs","normals"]){const s=i?.[e];void 0!==s&&(t[e]=Array.isArray(s)?s.slice():s)}delete t.url}catch(e){console.warn(`[QuarksLoader] Could not load geometry "${t.url}":`,e)}}))}parseImages(t,e,i){this._images={};for(const i of t)i.url&&tr.warnIfNotAnImageUrl(i.url),this._images[i.uuid]=i.url?tr.joinUrl(e,i.url):null}static warnIfNotAnImageUrl(t){/^(data|blob):/i.test(t)||/\.(png|jpe?g|webp|gif|bmp|ktx2?|dds|env|basis)(\?|#|$)/i.test(t)||console.warn(`[QuarksLoader] Image "${t}" does not look like an image; its texture will fail to load. This usually means the effect was exported without embedding that texture.`)}parseTextures(t,e){const i=this._images||{};for(const s of t){const t=i[s.image];if(t){const i=void 0===s.invertY||!!s.invertY,r=!!s.noMipmap,n=!1!==this.options.shareResources,o=n?[i,r,s.samplingMode,s.wrap,s.repeat,s.offset,s.rotation].join("|")+"|"+t:"",a=n?Ks(Xs,this.scene):void 0,h=a?.get(o);if(void 0!==h){e.textures[s.uuid]=h;continue}const l=new y.Texture(t,this.scene,{noMipmap:r,invertY:i,samplingMode:"number"==typeof s.samplingMode?s.samplingMode:void 0});Array.isArray(s.wrap)&&(l.wrapU=this.mapWrapMode(s.wrap[0]),l.wrapV=this.mapWrapMode(s.wrap[1]??s.wrap[0])),Array.isArray(s.repeat)&&(l.uScale=s.repeat[0]??1,l.vScale=s.repeat[1]??1),Array.isArray(s.offset)&&(l.uOffset=s.offset[0]??0,l.vOffset=s.offset[1]??0),"number"==typeof s.rotation&&(l.wAng=s.rotation),void 0!==a&&(a.set(o,l),l.onDisposeObservable.addOnce(()=>{a.get(o)===l&&a.delete(o)})),e.textures[s.uuid]=l}else e.textures[s.uuid]=null}}mapWrapMode(t){switch(t){case 1001:return y.Texture.CLAMP_ADDRESSMODE;case 1002:return y.Texture.MIRROR_ADDRESSMODE;default:return y.Texture.WRAP_ADDRESSMODE}}parseMaterials(t,e){for(const i of t){const t={uuid:i.uuid,transparent:i.transparent??!0,blending:i.blending??1,side:i.side??2,depthTest:i.depthTest??!0,depthWrite:i.depthWrite??!1,alphaTest:i.alphaTest??0,texture:null},s=i.map??i.texture;s&&(t.texture=e.textures[s]||null);const n=i.reflectionAtlas;if(n&&(t.reflectionAtlas=e.textures[n]||null),"number"==typeof i.reflectionLevel&&(t.reflectionLevel=i.reflectionLevel),"unlit"!==i.lighting&&"fixed"!==i.lighting&&"scene"!==i.lighting||(t.lighting=i.lighting),i.rim&&"object"==typeof i.rim&&(t.rim=i.rim),"number"==typeof i.alphaMode)t.alphaMode=i.alphaMode;else{const e={1:r.Constants.ALPHA_COMBINE,2:r.Constants.ALPHA_ADD,3:r.Constants.ALPHA_SUBTRACT,4:r.Constants.ALPHA_MULTIPLY};t.alphaMode=e[i.blending]||r.Constants.ALPHA_COMBINE}e.materials[i.uuid]=t}}getGeometry(t,e){if(e)return t.geometries[e]}getMaterial(t,e){if(!e)return;const i=Array.isArray(e)?e[0]:e;return t.materials[i]}createPlaceholderNode(t,e){const i=new s.TransformNode(e||t||"node",this.scene);return i.quarksOriginalType=t,i}createMeshNode(t,e){const i=new h.Mesh(t.name||t.type||"mesh",this.scene),s=this.getGeometry(e,t.geometry);if(s&&s.positions.length>0&&s.indices.length>0){const t=new l.VertexData;t.positions=s.positions,t.indices=s.indices,s.uvs&&s.uvs.length>0&&(t.uvs=s.uvs),s.normals&&s.normals.length>0&&(t.normals=s.normals),t.applyToMesh(i,!0)}const n=this.getMaterial(e,t.material);if(n){const t=new g.StandardMaterial(`quarks_loader_material_${n.uuid}`,this.scene);t.alphaMode=n.alphaMode??r.Constants.ALPHA_COMBINE,t.backFaceCulling=2!==n.side,t.alphaCutOff=n.alphaTest??0,t.disableDepthWrite=!n.depthWrite,n.texture&&(t.diffuseTexture=n.texture,t.opacityTexture=n.texture),i.material=t}return i}parseObject(t,e){let i;switch(t.type){case"QuarksPrefab":i=Ys.fromJSON(t,this.scene);break;case"ParticleEmitter":if(t.ps){i=this.parseParticleSystem(t.ps,e).emitter;break}i=this.createPlaceholderNode(t.type,t.name);break;case"Mesh":case"SkinnedMesh":case"InstancedMesh":case"BatchedMesh":i=this.createMeshNode(t,e);break;case"Scene":case"Group":case"Object3D":case"PerspectiveCamera":case"OrthographicCamera":case"AmbientLight":case"DirectionalLight":case"PointLight":case"RectAreaLight":case"SpotLight":case"HemisphereLight":case"LightProbe":case"LOD":case"Line":case"LineSegments":case"LineLoop":case"PointCloud":case"Points":case"Sprite":case"Bone":i=this.createPlaceholderNode(t.type,t.name);break;default:i=new s.TransformNode(t.name||t.type||"node",this.scene)}if(t.uuid&&(i._quarksUUID=t.uuid),t.name&&(i.name=t.name),t.matrix){const e=a.Matrix.FromArray(t.matrix),s=new a.Vector3(1,1,1),r=a.Quaternion.Identity(),n=new a.Vector3(0,0,0);e.decompose(s,r,n),i.position.copyFrom(n),i.scaling.copyFrom(s),i.rotationQuaternion=r}else t.position&&i.position.set(t.position[0],t.position[1],t.position[2]),t.scale&&i.scaling.set(t.scale[0],t.scale[1],t.scale[2]),t.quaternion?i.rotationQuaternion=new a.Quaternion(t.quaternion[0],t.quaternion[1],t.quaternion[2],t.quaternion[3]):t.rotation&&i.rotation.set(t.rotation[0],t.rotation[1],t.rotation[2]);if(void 0!==t.visible&&i.setEnabled(t.visible),t.children)for(const s of t.children){this.parseObject(s,e).parent=i}return i}parseParticleSystem(t,e){const i=js.fromJSON(t,e,{},this.scene);return i._meshSurfaceReferenceUUID="mesh_surface"===t?.shape?.type?t?.shape?.mesh:void 0,i}linkReferences(t){const e={},i=t=>{t._quarksUUID&&(e[t._quarksUUID]=t);for(const e of t.getChildren())e instanceof s.TransformNode&&i(e)};i(t);const r=i=>{if(i instanceof Ys&&i.resolveReferences(t),i instanceof zs){const t=i.system,s=t._meshSurfaceReferenceUUID;if(s&&"mesh_surface"===t.emitterShape.type){const i=e[s];i instanceof h.Mesh&&(t.emitterShape.mesh=i)}for(let s=0;s<t.behaviors.length;s++)if(t.behaviors[s]instanceof ve){const r=t.behaviors[s],n=r.subParticleSystem;if("string"!=typeof n)continue;const o=e[n];o instanceof zs?(r.subParticleSystem=o,o.system.onlyUsedByOther=!0):(r.subParticleSystem=void 0,""!==n&&console.warn(`[QuarksLoader] Emitter "${i.name}" has a sub emitter targeting "${n}", `+(o?"which is not a particle emitter":"which is not in the effect")+"; that sub emitter is skipped."))}}for(const t of i.getChildren())t instanceof s.TransformNode&&r(t)};r(t)}}Di(),Ii(Ni),exports.ApplyCollision=Ot,exports.ApplyForce=ie,exports.ApplySequences=ne,exports.AxisAngleGenerator=Et,exports.BatchedParticleRenderer=bs,exports.BatchedRenderer=ws,exports.BehaviorFromJSON=ri,exports.BehaviorTypes=si,exports.Bezier=Bt,exports.BoxEmitter=Si,exports.ChangeEmitDirection=oe,exports.CircleEmitter=zi,exports.ColorBySpeed=ae,exports.ColorGeneratorFromJSON=Yt,exports.ColorOverLife=he,exports.ColorRange=Ut,exports.ConeEmitter=Mi,exports.ConstantColor=jt,exports.ConstantValue=Ct,exports.DEG2RAD=P,exports.DonutEmitter=_i,exports.EdgeEmitter=Pi,exports.EffectPool=class{constructor(t,e){this.template=t,this.options=e,this.idle=[],this.playing=new Set,this.systemsOf=new Map,this.disposed=!1,this.onSystemFinished=t=>{const e=t.particleSystem;for(const t of this.playing){const i=this.systemsOf.get(t);if(void 0!==i&&i.includes(e))return void(Ms.isEffectFinished(t)&&this.release(t))}};for(let t=0;t<(e.prewarm??0);t++){const t=this.makeCopy();if(null===t)break;this.idle.push(t)}}get activeCount(){return this.playing.size}get idleCount(){return this.idle.length}acquire(t,e=null){if(this.disposed)return null;const i=this.idle.pop()??this.makeCopy();return null===i?null:(i.parent=e,void 0!==t&&i.position.copyFrom(t),i.setEnabled(!0),this.playing.add(i),Ms.restart(i),Ms.play(i),i)}stop(t){this.playing.has(t)&&Ms.endEmit(t)}release(t){this.playing.delete(t)&&(Ms.stop(t),t.setEnabled(!1),t.parent=null,this.disposed||this.idle.push(t))}dispose(){this.disposed=!0;for(const t of[...this.playing,...this.idle])this.playing.delete(t),this.disposeCopy(t);this.idle.length=0}makeCopy(){if(this.idle.length+this.playing.size>=(this.options.maxSize??1/0))return null;const t=Ms.instantiate(this.template),e=[];return Ms.runOnAllParticleEmitters(t,t=>{const i=t.system;i.autoDestroy=!1,i.addEventListener("finished",this.onSystemFinished),e.push(i)}),this.systemsOf.set(t,e),Ms.addToBatchRenderer(t,this.options.renderer),t.setEnabled(!1),t.parent=null,t}disposeCopy(t){const e=this.systemsOf.get(t)??[];for(const t of e)t.removeEventListener("finished",this.onSystemFinished),this.options.renderer.deleteSystem(t),t.dispose();this.systemsOf.delete(t),t.dispose()}},exports.EmitSubParticleSystem=ve,exports.EmitterFromJSON=Ai,exports.EmitterShapes=Bi,exports.Euler=pt,exports.EulerGenerator=Xt,exports.ForceOverLife=ge,exports.FrameOverLife=xe,exports.GeneratorFromJSON=ee,exports.Gradient=Jt,exports.GravityForce=Se,exports.GridEmitter=Ti,exports.HemisphereEmitter=Vi,exports.InheritVelocity=we,exports.IntervalValue=Ft,exports.LimitSpeedOverLife=be,exports.MathUtils=X,exports.Matrix3=ft,exports.Matrix4=st,exports.MeshSurfaceEmitter=Ei,exports.MeshSurfaceEmitterPlugin=Ni,exports.NodeParticle=class{constructor(){this.position=new H,this.velocity=new H,this.age=0,this.life=1,this.size=new H,this.rotation=0,this.color=new zt(1,1,1,1),this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.position.set(0,0,0),this.velocity.set(0,0,0),this.age=0,this.life=1,this.size.set(1,1,1),this.rotation=0,this.color.set(1,1,1,1),this.uvTile=0}},exports.Noise=Le,exports.OrbitOverLife=Re,exports.ParticleEmitter=zs,exports.ParticleMeshPhysicsMaterial=As,exports.ParticleMeshStandardMaterial=Bs,exports.ParticleStore=ze,exports.ParticleSystem=js,exports.PiecewiseBezier=$t,exports.PiecewiseFunction=At,exports.Plugins=$i,exports.PointEmitter=Oi,exports.QuarksLoader=tr,exports.QuarksPrefab=Ys,exports.QuarksUtil=Ms,exports.Quaternion=Z,exports.QuaternionView=vt,exports.RAD2DEG=T,exports.RandomColor=Qt,exports.RandomColorBetweenGradient=Wt,exports.RandomQuatGenerator=Zt,exports.RecordState=class{constructor(t,e,i){this.position=t,this.size=e,this.color=i}},exports.RectangleEmitter=Fi,exports.Rotation3DOverLife=De,exports.RotationBySpeed=Ue,exports.RotationGeneratorFromJSON=Ht,exports.RotationOverLife=qe,exports.SequencerFromJSON=re,exports.ShapeTransform=bi,exports.SizeBySpeed=ke,exports.SizeOverLife=Je,exports.SpeedOverLife=Qe,exports.SphereEmitter=Ci,exports.SpriteBatch=vs,exports.SpriteParticle=Ke,exports.SubEmitterInheritMask=me,exports.TextureSequencer=se,exports.TrailBatch=Ss,exports.TrailParticle=ei,exports.TurbulenceField=Ge,exports.VFXBatch=ys,exports.ValueGeneratorFromJSON=It,exports.Vector2=xt,exports.Vector3=H,exports.Vector3Function=Kt,exports.Vector3GeneratorFromJSON=te,exports.Vector3View=wt,exports.Vector4=zt,exports.Vector4View=_t,exports.VelocityOverLife=Xe,exports.WebGLCoordinateSystem=et,exports.WebGPUCoordinateSystem=it,exports.WidthOverLength=ii,exports.cacheEnvAtlas=function(t,e){_s.set(t,e)},exports.ceilPowerOfTwo=Q,exports.clamp=O,exports.createEnvAtlasFromFaceUrls=Os,exports.createSeededRandom=z,exports.cubeFaceUrls=Ts,exports.damp=$,exports.defaultMeshLighting=ps,exports.degToRad=q,exports.denormalize=j,exports.ensureEnvAtlasFromCube=Fs,exports.euclideanModulo=C,exports.floorPowerOfTwo=G,exports.generateUUID=V,exports.getCachedEnvAtlas=Vs,exports.getPhysicsResolver=Vt,exports.getRandomSource=w,exports.getRegisteredShaderChunks=function(){return Li},exports.getShaderChunk=function(t){return Li[t]},exports.getValueFromEmitterMode=wi,exports.inverseLerp=B,exports.isPowerOfTwo=J,exports.lerp=A,exports.loadPlugin=Ii,exports.localParticlePhysicsVertShader=Yi,exports.localParticleVertShader="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\n// Uniforms\nuniform mat4 worldViewProjection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 rotatedPosition = applyQuaternion(position * size, rotation);\n vec3 worldPos = rotatedPosition + offset;\n\n gl_Position = worldViewProjection * vec4(worldPos, 1.0);\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n",exports.mapLinear=F,exports.meshRimEqual=ms,exports.normalize=Y,exports.normalizeMeshRim=fs,exports.particleFragShader=Xi,exports.particlePhysicsFragShader=Zi,exports.particleVertShader=Hi,exports.pingpong=I,exports.planBehaviorFusion=vi,exports.radToDeg=k,exports.randFloat=R,exports.randFloatSpread=D,exports.randInt=L,exports.random=S,exports.registerShaderChunks=Di,exports.seededRandom=U,exports.setPhysicsResolver=function(t){Tt=t},exports.setQuaternionFromProperEuler=W,exports.setRandomSource=b,exports.smootherstep=N,exports.smoothstep=E,exports.stretchedBillboardVertShader=Ki,exports.subEmitterInheritMask=ye,exports.trailFragShader=ts,exports.trailVertShader=es,exports.unloadPlugin=function(t){const e=$i.find(e=>e.id===t);if(e){for(const t of e.emitterShapes)Bi[t.type]&&delete Bi[t.type];for(const t of e.behaviors)si[t.type]&&delete si[t.type]}},exports.withRandomSource=function(t,e){const i=b(t);try{return e()}finally{b(i)}};
|
|
2
2
|
//# sourceMappingURL=babylon.quarks.cjs.map
|