babylon.quarks 0.19.0 → 0.20.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.
@@ -1,2 +1,2 @@
1
- import{VertexBuffer as t}from"@babylonjs/core/Buffers/buffer";import{TransformNode as e}from"@babylonjs/core/Meshes/transformNode";import{Constants as i}from"@babylonjs/core/Engines/constants";import{ShaderMaterial as s}from"@babylonjs/core/Materials/shaderMaterial";import{RawTexture as r}from"@babylonjs/core/Materials/Textures/rawTexture";import{Vector3 as n,Vector2 as o,Vector4 as a,Matrix as h,Quaternion as l}from"@babylonjs/core/Maths/math.vector";import{Mesh as c}from"@babylonjs/core/Meshes/mesh";import{VertexData as u}from"@babylonjs/core/Meshes/mesh.vertexData";import{ShaderStore as d}from"@babylonjs/core/Engines/shaderStore";import{Effect as m}from"@babylonjs/core/Materials/effect";import{ShaderLanguage as p}from"@babylonjs/core/Materials/shaderLanguage";import{BoundingInfo as f}from"@babylonjs/core/Culling/boundingInfo";import{Texture as y}from"@babylonjs/core/Materials/Textures/texture";import{PBRMaterial as v}from"@babylonjs/core/Materials/PBR/pbrMaterial";import{StandardMaterial as g}from"@babylonjs/core/Materials/standardMaterial";const x=["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 S=1234567;const w=Math.PI/180,b=180/Math.PI;function z(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return(x[255&t]+x[t>>8&255]+x[t>>16&255]+x[t>>24&255]+"-"+x[255&e]+x[e>>8&255]+"-"+x[e>>16&15|64]+x[e>>24&255]+"-"+x[63&i|128]+x[i>>8&255]+"-"+x[i>>16&255]+x[i>>24&255]+x[255&s]+x[s>>8&255]+x[s>>16&255]+x[s>>24&255]).toLowerCase()}function M(t,e,i){return Math.max(e,Math.min(i,t))}function _(t,e){return(t%e+e)%e}function T(t,e,i,s,r){return s+(t-e)*(r-s)/(i-e)}function P(t,e,i){return t!==e?(i-t)/(e-t):0}function V(t,e,i){return(1-i)*t+i*e}function B(t,e,i,s){return V(t,e,1-Math.exp(-i*s))}function O(t,e=1){return e-Math.abs(_(t,2*e)-e)}function A(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*(3-2*t)}function C(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*t*(t*(6*t-15)+10)}function F(t,e){return t+Math.floor(Math.random()*(e-t+1))}function N(t,e){return t+Math.random()*(e-t)}function I(t){return t*(.5-Math.random())}function E(t){void 0!==t&&(S=t);let e=S+=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 D(t){return t*w}function U(t){return t*b}function L(t){return!(t&t-1)&&0!==t}function R(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))}function $(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function J(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),m=n((s-e)/2),p=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*p,h*m,a*l);break;case"YXY":t.set(h*m,a*c,h*p,a*l);break;case"ZYZ":t.set(h*p,h*m,a*c,a*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function k(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 q(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:w,RAD2DEG:b,generateUUID:z,clamp:M,euclideanModulo:_,mapLinear:T,inverseLerp:P,lerp:V,damp:B,pingpong:O,smoothstep:A,smootherstep:C,randInt:F,randFloat:N,randFloatSpread:I,seededRandom:E,degToRad:D,radToDeg:U,isPowerOfTwo:L,ceilPowerOfTwo:R,floorPowerOfTwo:$,setQuaternionFromProperEuler:J,normalize:q,denormalize:k};class G{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],m=r[n+2],p=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]=m,void(t[e+3]=p);if(c!==p||a!==u||h!==d||l!==m){let t=1-o;const e=a*u+h*d+l*m+c*p,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+m*r,c=c*t+p*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],m=r[n+3];return t[e]=o*m+l*c+a*d-h*u,t[e+1]=a*m+l*u+h*c-o*d,t[e+2]=h*m+l*d+o*u-a*c,t[e+3]=l*m-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 G(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),m=a(r/2);switch(n){case"XYZ":this._x=u*l*c+h*d*m,this._y=h*d*c-u*l*m,this._z=h*l*m+u*d*c,this._w=h*l*c-u*d*m;break;case"YXZ":this._x=u*l*c+h*d*m,this._y=h*d*c-u*l*m,this._z=h*l*m-u*d*c,this._w=h*l*c+u*d*m;break;case"ZXY":this._x=u*l*c-h*d*m,this._y=h*d*c+u*l*m,this._z=h*l*m+u*d*c,this._w=h*l*c-u*d*m;break;case"ZYX":this._x=u*l*c-h*d*m,this._y=h*d*c+u*l*m,this._z=h*l*m-u*d*c,this._w=h*l*c+u*d*m;break;case"YZX":this._x=u*l*c+h*d*m,this._y=h*d*c+u*l*m,this._z=h*l*m-u*d*c,this._w=h*l*c-u*d*m;break;case"XZY":this._x=u*l*c-h*d*m,this._y=h*d*c-u*l*m,this._z=h*l*m+u*d*c,this._w=h*l*c+u*d*m;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(M(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}}G.prototype.isQuaternion=!0;class W{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 W(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(Y.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Y.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 j.copy(this).projectOnVector(t),this.sub(j)}reflect(t){return this.sub(j.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(M(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}}W.prototype.isVector3=!0;const j=new W,Y=new G,X=2e3,Z=2001;class H{constructor(t,e,i,s,r,n,o,a,h,l,c,u,d,m,p,f){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,m,p,f)}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,m,p,f){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]=m,y[11]=p,y[15]=f,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 H).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/K.setFromMatrixColumn(t,0).length(),r=1/K.setFromMatrixColumn(t,1).length(),n=1/K.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(et,t,it)}lookAt(t,e,i){const s=this.elements;return nt.subVectors(t,e),0===nt.lengthSq()&&(nt.z=1),nt.normalize(),st.crossVectors(i,nt),0===st.lengthSq()&&(1===Math.abs(i.z)?nt.x+=1e-4:nt.z+=1e-4,nt.normalize(),st.crossVectors(i,nt)),st.normalize(),rt.crossVectors(nt,st),s[0]=st.x,s[4]=rt.x,s[8]=nt.x,s[1]=st.y,s[5]=rt.y,s[9]=nt.y,s[2]=st.z,s[6]=rt.z,s[10]=nt.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],m=i[2],p=i[6],f=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],T=s[5],P=s[9],V=s[13],B=s[2],O=s[6],A=s[10],C=s[14],F=s[3],N=s[7],I=s[11],E=s[15];return r[0]=n*w+o*_+a*B+h*F,r[4]=n*b+o*T+a*O+h*N,r[8]=n*z+o*P+a*A+h*I,r[12]=n*M+o*V+a*C+h*E,r[1]=l*w+c*_+u*B+d*F,r[5]=l*b+c*T+u*O+d*N,r[9]=l*z+c*P+u*A+d*I,r[13]=l*M+c*V+u*C+d*E,r[2]=m*w+p*_+f*B+y*F,r[6]=m*b+p*T+f*O+y*N,r[10]=m*z+p*P+f*A+y*I,r[14]=m*M+p*V+f*C+y*E,r[3]=v*w+g*_+x*B+S*F,r[7]=v*b+g*T+x*O+S*N,r[11]=v*z+g*P+x*A+S*I,r[15]=v*M+g*V+x*C+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],m=t[12],p=t[13],f=t[14],y=t[15],v=c*f*h-p*u*h+p*a*d-o*f*d-c*a*y+o*u*y,g=m*u*h-l*f*h-m*a*d+n*f*d+l*a*y-n*u*y,x=l*p*h-m*c*h+m*o*d-n*p*d-l*o*y+n*c*y,S=m*c*a-l*p*a-m*o*u+n*p*u+l*o*f-n*c*f,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]=(p*u*r-c*f*r-p*s*d+i*f*d+c*s*y-i*u*y)*b,t[2]=(o*f*r-p*a*r+p*s*h-i*f*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*f*r-m*u*r+m*s*d-e*f*d-l*s*y+e*u*y)*b,t[6]=(m*a*r-n*f*r-m*s*h+e*f*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]=(m*c*r-l*p*r-m*i*d+e*p*d+l*i*y-e*c*y)*b,t[10]=(n*p*r-m*o*r+m*i*h-e*p*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*p*s-m*c*s+m*i*u-e*p*u-l*i*f+e*c*f)*b,t[14]=(m*o*s-n*p*s-m*i*a+e*p*a+n*i*f-e*o*f)*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,m=r*c,p=n*l,f=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-(p+y))*S,s[1]=(d+x)*S,s[2]=(m-g)*S,s[3]=0,s[4]=(d-x)*w,s[5]=(1-(u+y))*w,s[6]=(f+v)*w,s[7]=0,s[8]=(m+g)*b,s[9]=(f-v)*b,s[10]=(1-(u+p))*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=K.set(s[0],s[1],s[2]).length();const n=K.set(s[4],s[5],s[6]).length(),o=K.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],tt.copy(this);const a=1/r,h=1/n,l=1/o;return tt.elements[0]*=a,tt.elements[1]*=a,tt.elements[2]*=a,tt.elements[4]*=h,tt.elements[5]*=h,tt.elements[6]*=h,tt.elements[8]*=l,tt.elements[9]*=l,tt.elements[10]*=l,e.setFromRotationMatrix(tt),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,m;if(o===X)d=-(n+r)/(n-r),m=-2*n*r/(n-r);else{if(o!==Z)throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),m=-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]=m,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 m,p;if(o===X)m=(n+r)*c,p=-2*c;else{if(o!==Z)throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);m=r*c,p=-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]=p,a[14]=-m,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}}H.prototype.isMatrix4=!0;const K=new W,tt=new H,et=new W(0,0,0),it=new W(1,1,1),st=new W,rt=new W,nt=new W,ot=new H,at=new G;class ht{constructor(t=0,e=0,i=0,s=ht.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 ht(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(M(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(-M(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(M(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(-M(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(M(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(-M(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 ot.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ot,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return at.setFromEuler(this),this.setFromQuaternion(at,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}}ht.DEFAULT_ORDER="XYZ",ht.prototype.isEuler=!0;class lt{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],m=i[8],p=s[0],f=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*p+o*v+a*S,r[3]=n*f+o*g+a*w,r[6]=n*y+o*x+a*b,r[1]=h*p+l*v+c*S,r[4]=h*f+l*g+c*w,r[7]=h*y+l*x+c*b,r[2]=u*p+d*v+m*S,r[5]=u*f+d*g+m*w,r[8]=u*y+d*x+m*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,m=e*c+i*u+s*d;if(0===m)return this.set(0,0,0,0,0,0,0,0,0);const p=1/m;return t[0]=c*p,t[1]=(s*h-l*i)*p,t[2]=(o*i-s*n)*p,t[3]=u*p,t[4]=(l*e-s*a)*p,t[5]=(s*r-o*e)*p,t[6]=d*p,t[7]=(i*a-h*e)*p,t[8]=(n*e-i*r)*p,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(ct.makeScale(t,e)),this}rotate(t){return this.premultiply(ct.makeRotation(-t)),this}translate(t,e){return this.premultiply(ct.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 lt).fromArray(this.elements)}}lt.prototype.isMatrix3=!0;const ct=new lt;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(M(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 mt extends W{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const pt=mt.prototype;pt.data=dt,pt.offset=0,Object.defineProperties(mt.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 ft{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 ft(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],m=a[9],p=a[2],f=a[6],y=a[10];if(Math.abs(l-u)<n&&Math.abs(c-p)<n&&Math.abs(m-f)<n){if(Math.abs(l+u)<o&&Math.abs(c+p)<o&&Math.abs(m+f)<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+p)/4,S=(m+f)/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((f-m)*(f-m)+(c-p)*(c-p)+(u-l)*(u-l));return Math.abs(v)<.001&&(v=1),this.x=(f-m)/v,this.y=(c-p)/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}}ft.prototype.isVector4=!0;const yt=new Float32Array(4);class vt extends ft{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const gt=vt.prototype;let xt;function St(t){xt=t}function wt(){return xt}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 bt{constructor(t,e){this.resolver=t,this.bounce=e,this.type="ApplyCollision",this.tempV=new W}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 bt(wt(),t.bounce)}clone(){return new bt(this.resolver,this.bounce)}reset(){}}class zt{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 zt(t.value)}clone(){return new zt(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 _t{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 _t(e[0],e[4],e[7],e[9]),right:new _t(e[9],e[8],e[6],e[3]),span:e}}clone(){return new _t(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 _t(t.p0,t.p1,t.p2,t.p3)}}class Tt{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 Pt extends Tt{constructor(t=[[new _t(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 Float32Array(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=Pt.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}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 Pt(t.functions.map(t=>[_t.fromJSON(t.function),t.start]))}clone(){return new Pt(this.functions.map(([t,e])=>[t.clone(),e]))}startGen(t){}}function Vt(t){switch(t.type){case"ConstantValue":return zt.fromJSON(t);case"IntervalValue":return Mt.fromJSON(t);case"PiecewiseBezier":return Pt.fromJSON(t);default:return new zt(0)}}Pt.TABLE_SIZE=257;class Bt{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 Bt(new W(t.axis.x,t.axis.y,t.axis.z),Vt(t.angle))}clone(){return new Bt(this.axis.clone(),this.angle.clone())}}const Ot=t=>({r:t.x,g:t.y,b:t.z,a:t.w}),At=t=>new ft(t.r,t.g,t.b,t.a),Ct=(t,e)=>{switch(e){case"Vector3":return new W(t.x,t.y,t.z);case"Vector4":return new ft(t.x,t.y,t.z,t.w);case"Color":return new W(t.r,t.g,t.b);default:return t}},Ft=(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 Nt{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 Nt(At(t.a),At(t.b))}clone(){return new Nt(this.a.clone(),this.b.clone())}}class It{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:Ft(t,this.subType),pos:e}))}}static fromJSON(t){return new It(t.keys.map(e=>[Ct(e.value,t.subType),e.pos]),t.subType)}clone(){return"Number"===this.subType?new It(this.keys.map(([t,e])=>[t,e]),this.subType):new It(this.keys.map(([t,e])=>[t.clone(),e]),this.subType)}}const Et=new ft;class Dt{constructor(t=[[new W(0,0,0),0],[new W(1,1,1),0]],e=[[1,0],[1,1]]){this.table=null,this.tableSignature=null,this.type="function",this.color=new It(t,"Color"),this.alpha=new It(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 Float32Array(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=Dt.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}clearTable(){this.table=null,this.tableSignature=null}genColor(t,e,i){const s=this.table;if(null!==s){const t=Dt.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=>[Nt.fromJSON(t.function).a,t.start]);return t.functions.length>0&&e.push([Nt.fromJSON(t.functions[t.functions.length-1].function).b,1]),new Dt(e.map(t=>[new W(t[0].x,t[0].y,t[0].z),t[1]]),e.map(t=>[t[0].w,t[1]]))}{const e=new Dt;return e.alpha=It.fromJSON(t.alpha),e.color=It.fromJSON(t.color),e}}clone(){const t=new Dt;return t.alpha=this.alpha.clone(),t.color=this.color.clone(),t}startGen(t){}}Dt.TABLE_SIZE=257;class Ut{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 Ut(At(t.a),At(t.b))}clone(){return new Ut(this.a.clone(),this.b.clone())}}const Lt=new ft;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(Dt.fromJSON(t.gradient1),Dt.fromJSON(t.gradient2))}clone(){return new Rt(this.gradient1.clone(),this.gradient2.clone())}}class $t{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 $t(At(t.color))}clone(){return new $t(this.color.clone())}}function Jt(t){switch(t.type){case"ConstantColor":return $t.fromJSON(t);case"ColorRange":return Nt.fromJSON(t);case"RandomColor":return Ut.fromJSON(t);case"Gradient":return Dt.fromJSON(t);case"RandomColorBetweenGradient":return Rt.fromJSON(t);default:return new $t(new ft(1,1,1,1))}}class kt{constructor(t,e,i,s){this.angleX=t,this.angleY=e,this.angleZ=i,this.type="rotation",this.eular=new ht(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 kt(Vt(t.angleX),Vt(t.angleY),Vt(t.angleZ),t.eulerOrder)}clone(){return new kt(this.angleX,this.angleY,this.angleZ,this.eular.order)}}class qt{constructor(){this.indexCount=0,this.type="rotation"}startGen(t){let e,i,s,r,n,o;this.indexCount=t.length,t.push(new G);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[this.indexCount].set(e,i,a*r,a*n)}genValue(t,e,i,s){return-1===this.indexCount&&this.startGen(t),e.copy(t[this.indexCount]),e}toJSON(){return{type:"RandomQuat"}}static fromJSON(t){return new qt}clone(){return new qt}}function Qt(t){switch(t.type){case"AxisAngle":return Bt.fromJSON(t);case"Euler":return kt.fromJSON(t);case"RandomQuat":return qt.fromJSON(t);default:return new qt}}class Gt{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 Gt(Vt(t.x),Vt(t.y),Vt(t.z))}clone(){return new Gt(this.x,this.y,this.z)}}function Wt(t){return"Vector3Function"===t.type?Gt.fromJSON(t):new Gt(new zt(0),new zt(0),new zt(0))}function jt(t){switch(t.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Vt(t);case"AxisAngle":case"RandomQuat":case"Euler":return Qt(t);case"Vector3Function":return Wt(t);default:return new zt(0)}}class Yt{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 Yt(new W(t.direction[0],t.direction[1],t.direction[2]),Vt(t.magnitude??t.force))}clone(){return new Yt(this.direction.clone(),this.magnitude.clone())}reset(){}}class Xt{constructor(t=0,e=0,i=new W){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 Xt(t.scaleX,t.scaleY,new W(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 Xt(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 Zt(t){return"TextureSequencer"===t.type?Xt.fromJSON(t):new Xt}class Ht{constructor(t){this.type="ApplySequences",this.sequencers=[],this.time=0,this.index=0,this.pCount=0,this.tempV=new W,this.delay=t}initialize(t){t.id=this.pCount,t.dst=new W,t.begin=new W,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,Ht.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 Ht(t.delay);return t.sequencers.forEach(t=>{e.sequencers.push([Vt(t.range),Zt(t.sequencer)])}),e}clone(){const t=new Ht(this.delay);return t.sequencers=this.sequencers.map(t=>[t[0].clone(),t[1].clone()]),t}}Ht.BEZIER=new _t(0,0,1,1);class Kt{constructor(t){this.angle=t,this.type="ChangeEmitDirection",this._temp=new W,this._q=new G,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 Kt(Vt(t.angle))}clone(){return new Kt(this.angle)}reset(){}}class te{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 te(Jt(t.color),Mt.fromJSON(t.speedRange))}clone(){return new te(this.color.clone(),this.speedRange.clone())}reset(){}}class ee{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 ee(Jt(t.color))}clone(){return new ee(this.color.clone())}reset(){}}function ie(t,e){return Math.floor(Math.random()*(e-t))+t}const se=new W(0,1,0),re=new W(0,0,0),ne=new W(1,1,1),oe=new W(0,0,1);var ae;!function(t){t[t.Death=0]="Death",t[t.Birth=1]="Birth",t[t.Frame=2]="Frame"}(ae||(ae={}));class he{constructor(t,e,i,s=ae.Frame,r=1){this.particleSystem=t,this.useVelocityAsBasis=e,this.subParticleSystem=i,this.mode=s,this.emitProbability=r,this.type="EmitSubParticleSystem",this.q_=new G,this.v_=new W,this.v2_=new W,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(t){}update(t,e){(this.mode===ae.Frame||this.mode===ae.Birth&&0===t.age||this.mode===ae.Death&&t.age+e>=t.life)&&this.emit(t,e)}emit(t,e){if(!this.subParticleSystem)return;if(Math.random()>this.emitProbability)return;const i=new H;this.setMatrixFromParticle(i,t),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:i,travelDistance:0,particle:t})}frameUpdate(t){if(this.subParticleSystem)for(let e=0;e<this.subEmissions.length;e++)if(this.subEmissions[e].time>=this.subParticleSystem.system.duration)this.subEmissions[e]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,e--;else{const i=this.subEmissions[e];i.particle&&i.particle.age<i.particle.life?this.setMatrixFromParticle(i.matrix,i.particle):i.particle=void 0,this.subParticleSystem.system.emit(t,i,i.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(t,e){return new he(e,t.useVelocityAsBasis,t.subParticleSystem,t.mode,t.emitProbability)}clone(){return new he(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(oe).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 G?i=e.rotation:(this.q_.setFromAxisAngle(oe,e.rotation),i=this.q_),t.compose(e.position,i,ne);this.particleSystem.worldSpace||t.multiplyMatrices(this.particleSystem.emitter.matrixWorld,t)}}class le{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 W,this._tempScale=new W,this._tempQ=new G}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 le(Vt(t.x),Vt(t.y),Vt(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 le(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class ce{constructor(t){this.type="FrameOverLife",this._frameIsBezier=!1,this.frame=t}get frame(){return this._frame}set frame(t){this._frame=t,this._frameIsBezier=t instanceof Pt}initialize(t){this._frame.startGen(t.memory)}update(t,e){this._frameIsBezier&&(t.uvTile=this._frame.genValue(t.memory,t.age/t.life))}updateAll(t,e,i){if(!this._frameIsBezier)return;const s=this._frame;for(let i=0;i<e;i++){const e=t[i];e.age>=e.life||(e.uvTile=s.genValue(e.memory,e.age/e.life))}}frameUpdate(t){this._frame.refreshTable?.()}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(t){return new ce(Vt(t.frame))}clone(){return new ce(this.frame.clone())}reset(){}}class ue{constructor(t,e){this.center=t,this.magnitude=e,this.type="GravityForce",this.temp=new W}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)),m=e.velocity;m.x+=h*d,m.y+=l*d,m.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 ue(new W(t.center[0],t.center[1],t.center[2]),t.magnitude)}clone(){return new ue(this.center.clone(),this.magnitude)}reset(){}}class de{constructor(t=new zt(1),e="initial"){this.multiplier=t,this.mode=e,this.type="InheritVelocity",this._temp=new W,this._tempPos=new W,this._tempQInv=new G,this._tempScaleInv=new W(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 de(t.multiplier?Vt(t.multiplier):new zt(1),"current"===t.mode?"current":"initial")}clone(){return new de(this.multiplier.clone(),this.mode)}reset(){}}class me{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 me(Vt(t.speed),t.dampen)}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new me(this.speed.clone(),this.dampen)}reset(){}}const pe=.5*(Math.sqrt(3)-1),fe=(3-Math.sqrt(3))/6,ye=1/3,ve=1/6,ge=(Math.sqrt(5)-1)/4,xe=(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)*pe,h=Math.floor(t+a),l=Math.floor(e+a),c=(h+l)*fe,u=t-(h-c),d=e-(l-c);let m,p;u>d?(m=1,p=0):(m=0,p=1);const f=u-m+fe,y=d-p+fe,v=u-1+2*fe,g=d-1+2*fe,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*(Se[t]*u+Se[t+1]*d)}let b=.5-f*f-y*y;if(b>=0){const t=3*i[x+m+s[S+p]];b*=b,n=b*b*(Se[t]*f+Se[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*(Se[t]*v+Se[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)*ye,c=Math.floor(t+l),u=Math.floor(e+l),d=Math.floor(i+l),m=(c+u+d)*ve,p=t-(c-m),f=e-(u-m),y=i-(d-m);let v,g,x,S,w,b;p>=f?f>=y?(v=1,g=0,x=0,S=1,w=1,b=0):p>=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):f<y?(v=0,g=0,x=1,S=0,w=1,b=1):p<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=p-v+ve,M=f-g+ve,_=y-x+ve,T=p-S+2*ve,P=f-w+2*ve,V=y-b+2*ve,B=p-1+.5,O=f-1+.5,A=y-1+.5,C=255&c,F=255&u,N=255&d;let I=.6-p*p-f*f-y*y;if(I<0)n=0;else{const t=3*s[C+r[F+r[N]]];I*=I,n=I*I*(Se[t]*p+Se[t+1]*f+Se[t+2]*y)}let E=.6-z*z-M*M-_*_;if(E<0)o=0;else{const t=3*s[C+v+r[F+g+r[N+x]]];E*=E,o=E*E*(Se[t]*z+Se[t+1]*M+Se[t+2]*_)}let D=.6-T*T-P*P-V*V;if(D<0)a=0;else{const t=3*s[C+S+r[F+w+r[N+b]]];D*=D,a=D*D*(Se[t]*T+Se[t+1]*P+Se[t+2]*V)}let U=.6-B*B-O*O-A*A;if(U<0)h=0;else{const t=3*s[C+1+r[F+1+r[N+1]]];U*=U,h=U*U*(Se[t]*B+Se[t+1]*O+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)*ge,u=Math.floor(t+c),d=Math.floor(e+c),m=Math.floor(i+c),p=Math.floor(s+c),f=(u+d+m+p)*xe,y=t-(u-f),v=e-(d-f),g=i-(m-f),x=s-(p-f);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,T=b>=3?1:0,P=z>=3?1:0,V=S>=2?1:0,B=w>=2?1:0,O=b>=2?1:0,A=z>=2?1:0,C=S>=1?1:0,F=w>=1?1:0,N=b>=1?1:0,I=z>=1?1:0,E=y-M+xe,D=v-_+xe,U=g-T+xe,L=x-P+xe,R=y-V+2*xe,$=v-B+2*xe,J=g-O+2*xe,k=x-A+2*xe,q=y-C+3*xe,Q=v-F+3*xe,G=g-N+3*xe,W=x-I+3*xe,j=y-1+4*xe,Y=v-1+4*xe,X=g-1+4*xe,Z=x-1+4*xe,H=255&u,K=255&d,tt=255&m,et=255&p;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*(we[t]*y+we[t+1]*v+we[t+2]*g+we[t+3]*x)}let st=.6-E*E-D*D-U*U-L*L;if(st<0)o=0;else{const t=r[H+M+r[K+_+r[tt+T+r[et+P]]]]%32*4;st*=st,o=st*st*(we[t]*E+we[t+1]*D+we[t+2]*U+we[t+3]*L)}let rt=.6-R*R-$*$-J*J-k*k;if(rt<0)a=0;else{const t=r[H+V+r[K+B+r[tt+O+r[et+A]]]]%32*4;rt*=rt,a=rt*rt*(we[t]*R+we[t+1]*$+we[t+2]*J+we[t+3]*k)}let nt=.6-q*q-Q*Q-G*G-W*W;if(nt<0)h=0;else{const t=r[H+C+r[K+F+r[tt+N+r[et+I]]]]%32*4;nt*=nt,h=nt*nt*(we[t]*q+we[t+1]*Q+we[t+2]*G+we[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*(we[t]*j+we[t+1]*Y+we[t+2]*X+we[t+3]*Z)}return 27*(n+o+a+h+l)}}const ze=100,Me=new Array(ze),_e=new W,Te=new G;function Pe(t){let e=Me[t];return void 0===e&&(e=new be,Me[t]=e),e}class Ve{constructor(t,e,i=new zt(1),s=new zt(0)){this.frequency=t,this.power=e,this.positionAmount=i,this.rotationAmount=s,this.type="Noise",this.duration=0}initialize(t){const e="number"==typeof t.rotation;let i=t._noiseState;if(void 0===i)return i={lastPos:new W,lastRot:0,lastRotQ:e?null:new G,generatorX:Pe(ie(0,ze)),generatorY:Pe(ie(0,ze)),generatorZ:Pe(ie(0,ze)),generatorW:Pe(ie(0,ze))},void(t._noiseState=i);i.lastPos.set(0,0,0),i.lastRot=0,e?i.lastRotQ=null:null===i.lastRotQ?i.lastRotQ=new G:i.lastRotQ.set(0,0,0,1),i.generatorX=Pe(ie(0,ze)),i.generatorY=Pe(ie(0,ze)),i.generatorZ=Pe(ie(0,ze)),i.generatorW=Pe(ie(0,ze))}update(t,e){const i=t._noiseState;if(void 0===i)return;const s=t.memory,r=t.age/t.life,n=this.frequency.genValue(s,r),o=this.power.genValue(s,r),a=this.positionAmount.genValue(s,r),h=this.rotationAmount.genValue(s,r),l=t.age*n;if(a>0){const e=o*a;t.position.sub(i.lastPos),_e.set(i.generatorX.noise2D(0,l)*e,i.generatorY.noise2D(0,l)*e,i.generatorZ.noise2D(0,l)*e),t.position.add(_e),i.lastPos.copy(_e)}if(h>0){const e=o*h;if("number"==typeof t.rotation){const s=i.generatorW.noise2D(0,l)*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,l)*e,i.generatorY.noise2D(0,l)*e,i.generatorZ.noise2D(0,l)*e,i.generatorW.noise2D(0,l)*e).normalize(),s.multiply(Te),i.lastRotQ.copy(Te)}}}updateAll(t,e,i){for(let s=0;s<e;s++){const e=t[s];e.age<e.life&&this.update(e,i)}}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}static fromJSON(t){return new Ve(Vt(t.frequency),Vt(t.power),Vt(t.positionAmount),Vt(t.rotationAmount))}clone(){return new Ve(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Be{constructor(t,e=new W(0,1,0)){this.orbitSpeed=t,this.axis=e,this.type="OrbitOverLife",this.temp=new W,this.rotation=new G}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 Be(Vt(t.orbitSpeed),t.axis?new W(t.axis[0],t.axis[1],t.axis[2]):void 0)}clone(){return new Be(this.orbitSpeed.clone())}reset(){}}class Oe{constructor(t){this.angularVelocity=t,this.type="Rotation3DOverLife",this.tempQuat=new G}initialize(t){t.rotation instanceof G&&(t.angularVelocity=new G,this.angularVelocity.startGen(t.memory))}update(t,e){if(t.rotation instanceof G){this.angularVelocity.genValue(t.memory,this.tempQuat,e,t.age/t.life),t.rotation.multiply(this.tempQuat);const i=t.angularVelocity;i instanceof G&&i.copy(this.tempQuat)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new Oe(Qt(t.angularVelocity))}frameUpdate(t){}clone(){return new Oe(this.angularVelocity.clone())}reset(){}}class Ae{constructor(t,e){this.angularVelocity=t,this.speedRange=e,this.type="RotationBySpeed",this.tempQuat=new G}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(Vt(t.angularVelocity),Mt.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Ae(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Ce{constructor(t){this.angularVelocity=t,this.type="RotationOverLife"}initialize(t){"number"==typeof t.rotation&&this.angularVelocity.startGen(t.memory)}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}}updateAll(t,e,i){const s=this.angularVelocity;for(let r=0;r<e;r++){const e=t[r];if(e.age>=e.life||"number"!=typeof e.rotation)continue;const n=s.genValue(e.memory,e.age/e.life);e.rotation+=i*n,e.angularVelocity=n}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new Ce(Vt(t.angularVelocity))}frameUpdate(t){this.angularVelocity.refreshTable?.()}clone(){return new Ce(this.angularVelocity.clone())}reset(){}}class Fe{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 Gt?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 Fe(jt(t.size),Mt.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Fe(this.size.clone(),this.speedRange.clone())}reset(){}}class Ne{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 Gt}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 Ne(jt(t.size))}frameUpdate(t){this._size.refreshTable?.()}clone(){return new Ne(this.size.clone())}reset(){}}class Ie{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 Ie(Vt(t.speed))}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new Ie(this.speed.clone())}reset(){}}class Ee{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 W,this.temp=new W,this.temp2=new W,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)}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 Ee(new W(t.scale[0],t.scale[1],t.scale[2]),t.octaves,new W(t.velocityMultiplier[0],t.velocityMultiplier[1],t.velocityMultiplier[2]),new W(t.timeScale[0],t.timeScale[1],t.timeScale[2]))}clone(){return new Ee(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const De=new W(1,0,0),Ue=new W(0,1,0),Le=new W(0,0,1);class Re{constructor(t=new zt(0),e=new zt(0),i=new zt(0),s=new zt(0),r=new zt(0),n=new zt(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 W,this._tempEmitterPos=new W,this._tempQ=new G,this._tempQInv=new G,this._tempScale=new W(1,1,1),this._tempScaleInv=new W(1,1,1),this._tempRot=new G,this._axisX=new W(1,0,0),this._axisY=new W(0,1,0),this._axisZ=new W(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(De),this._axisY.copy(Ue),this._axisZ.copy(Le),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?Vt(t):new zt(0);return new Re(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 Re(this.linearX.clone(),this.linearY.clone(),this.linearZ.clone(),this.orbitalX.clone(),this.orbitalY.clone(),this.orbitalZ.clone(),this.space)}reset(){}}class $e{constructor(t=64){this.previousVelocity=$e.EMPTY,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*$e.SCALAR_STRIDE)}ensureCapacity(t){if(t<=this.capacity)return!1;let e=this.capacity;for(;e<t;)e*=2;return this.position=$e.grow(this.position,3*e),this.previousPosition=$e.grow(this.previousPosition,3*e),this.previousSize=$e.grow(this.previousSize,3*e),this.previousVelocity.length>0&&(this.previousVelocity=$e.grow(this.previousVelocity,3*e)),this.previousColor=$e.grow(this.previousColor,4*e),this.velocity=$e.grow(this.velocity,3*e),this.size=$e.grow(this.size,3*e),this.startSize=$e.grow(this.startSize,3*e),this.color=$e.grow(this.color,4*e),this.startColor=$e.grow(this.startColor,4*e),this.scalars=$e.growDouble(this.scalars,e*$e.SCALAR_STRIDE),this.capacity=e,!0}keepPreviousVelocity(){return!(this.previousVelocity.length>=3*this.capacity)&&(this.previousVelocity=new Float32Array(3*this.capacity),!0)}swapRows(t,e){if(t===e)return;const i=3*t,s=3*e;$e.swap3(this.position,i,s),$e.swap3(this.previousPosition,i,s),$e.swap3(this.previousSize,i,s),this.previousVelocity.length>0&&$e.swap3(this.previousVelocity,i,s),$e.swap3(this.velocity,i,s),$e.swap3(this.size,i,s),$e.swap3(this.startSize,i,s);const r=4*t,n=4*e;$e.swap4(this.color,r,n),$e.swap4(this.previousColor,r,n),$e.swap4(this.startColor,r,n),$e.swap3(this.scalars,t*$e.SCALAR_STRIDE,e*$e.SCALAR_STRIDE)}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){$e.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}}$e.EMPTY=new Float32Array(0),$e.SCALAR_STRIDE=3,$e.AGE=0,$e.LIFE=1,$e.SPEED_MODIFIER=2;class Je{constructor(t){this.data=t,this.next=null,this.prev=null}hasPrev(){return null!==this.prev}hasNext(){return null!==this.next}}class ke{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 Je(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 Je(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 Je(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 qe{constructor(){this.position=new W,this.velocity=new W,this.age=0,this.life=1,this.size=new W,this.rotation=0,this.color=new ft(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}}class Qe{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}constructor(t=new $e(1),e=0){this.startSpeed=0,this.rotation=0,this.uvTile=0,this.memory=[],this.store=t,this.storeIndex=e;const i=3*e,s=4*e;this.position=new mt(t.position,i),this.previousPosition=new mt(t.previousPosition,i),this.previousVelocity=new mt(t.previousVelocity,i),this.velocity=new mt(t.velocity,i),this.size=new mt(t.size,i),this.startSize=new mt(t.startSize,i),this.color=new vt(t.color,s),this.startColor=new vt(t.startColor,s),this.scalars=t.scalars,this.scalarOffset=e*$e.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*$e.SCALAR_STRIDE}get died(){return this.age>=this.life}reset(){this.memory.length=0}}const Ge=new Float32Array(0);class We{constructor(t,e,i){this.position=t,this.size=e,this.color=i}}class je{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}constructor(t=new $e(1),e=0){this.startSpeed=0,this.length=100,this.previous=new ke,this.uvTile=0,this.historyPositions=Ge,this.historySizes=Ge,this.historyColors=Ge,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 mt(t.position,i),this.previousPosition=new mt(t.previousPosition,i),this.previousVelocity=new mt(t.previousVelocity,i),this.velocity=new mt(t.velocity,i),this.size=new mt(t.size,i),this.startSize=new mt(t.startSize,i),this.color=new vt(t.color,s),this.startColor=new vt(t.startColor,s),this.scalars=t.scalars,this.scalarOffset=e*$e.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*$e.SCALAR_STRIDE}ensureHistoryCapacity(t){this.historyCapacity!==t&&(this.historyCapacity=t,this.historyPositions=new Float32Array(3*t),this.historySizes=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(){this.ensureHistoryCapacity(Math.max(1,Math.ceil(this.length)));const t=this.historyCapacity;if(this.age>this.life)return void(this.historyCount>0&&this.historyCount--);const e=this.historyHead,i=3*e,s=this.historyPositions;s[i]=this.position.x,s[i+1]=this.position.y,s[i+2]=this.position.z,this.historySizes[e]=this.size.x;const r=4*e,n=this.historyColors;n[r]=this.color.x,n[r+1]=this.color.y,n[r+2]=this.color.z,n[r+3]=this.color.w,this.historyHead=(e+1)%t,this.historyCount<t&&this.historyCount++}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.resetHistory()}}class Ye{initialize(t){this.width.startGen(t.memory)}constructor(t){this.width=t,this.type="WidthOverLength"}update(t){if(!(t instanceof je))return;const e=t.historyCount;if(0===e)return;const i=t.historyCapacity,s=t.historySizes,r=t.memory,n=1/t.length;let o=t.getHistoryIndex(0);for(let t=0;t<e;t++)s[o]=this.width.genValue(r,(e-t)*n),o++,o===i&&(o=0)}frameUpdate(t){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(t){return new Ye(Vt(t.width))}clone(){return new Ye(this.width.clone())}reset(){}}const Xe={ApplyForce:{type:"ApplyForce",constructor:Yt,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Yt.fromJSON},Noise:{type:"Noise",constructor:Ve,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Ve.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Ee,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Ee.fromJSON},GravityForce:{type:"GravityForce",constructor:ue,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:ue.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:ee,params:[["color",["colorFunc"]]],loadJSON:ee.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Ce,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Ce.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Oe,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Oe.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Ne,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Ne.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:te,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:te.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Ae,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Ae.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Fe,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Fe.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Ie,params:[["speed",["value","valueFunc"]]],loadJSON:Ie.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:ce,params:[["frame",["value","valueFunc"]]],loadJSON:ce.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:le,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:le.fromJSON},VelocityOverLife:{type:"VelocityOverLife",constructor:Re,params:[["linearX",["value","valueFunc"]],["linearY",["value","valueFunc"]],["linearZ",["value","valueFunc"]],["orbitalX",["value","valueFunc"]],["orbitalY",["value","valueFunc"]],["orbitalZ",["value","valueFunc"]],["space",["string"]]],loadJSON:Re.fromJSON},InheritVelocity:{type:"InheritVelocity",constructor:de,params:[["multiplier",["value","valueFunc"]],["mode",["string"]]],loadJSON:de.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Be,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Be.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ye,params:[["width",["value","valueFunc"]]],loadJSON:Ye.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:Kt,params:[["angle",["value"]]],loadJSON:Kt.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:he,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:he.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:me,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:me.fromJSON},ApplyCollision:{type:"ApplyCollision",constructor:bt,params:[["bounce",["number"]]],loadJSON:bt.fromJSON}};function Ze(t,e){return Xe[t.type]?Xe[t.type].loadJSON(t,e):null}const He={PiecewiseBezier:Pt,Vector3Function:Gt,Quaternion:G};function Ke(t,e){switch(t.type){case"ColorOverLife":return{setup:`const g${e} = behaviors[${e}].color;`,body:`{const c = p.color, sc = p.startColor;\n g${e}.genColor(p.memory, c, t);\n c.x *= sc.x; c.y *= sc.y; c.z *= sc.z; c.w *= sc.w;}`};case"SizeOverLife":return{setup:`const g${e} = behaviors[${e}].size;\n const vec3_${e} = g${e} instanceof deps.Vector3Function;`,body:`if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, t).multiply(p.startSize);\n } else {\n const v = g${e}.genValue(p.memory, t);\n const s = p.size, ss = p.startSize;\n s.x = ss.x * v; s.y = ss.y * v; s.z = ss.z * 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:`{const v = p.velocity; v.x += dx${e}; v.y += dy${e}; v.z += dz${e};}`};case"RotationOverLife":return{setup:`const g${e} = behaviors[${e}].angularVelocity;`,body:`if (typeof p.rotation === 'number') {\n const rate = g${e}.genValue(p.memory, t);\n p.rotation += delta * rate;\n p.angularVelocity = rate;\n }`};case"FrameOverLife":return{setup:`const g${e} = behaviors[${e}].frame;\n const bezier_${e} = g${e} instanceof deps.PiecewiseBezier;`,body:`if (bezier_${e}) { p.uvTile = g${e}.genValue(p.memory, t); }`};case"SpeedOverLife":return{setup:`const g${e} = behaviors[${e}].speed;`,body:`p.speedModifier = g${e}.genValue(p.memory, t);`};case"ForceOverLife":return{setup:`const b${e} = behaviors[${e}];\n const gx${e} = b${e}.x, gy${e} = b${e}.y, gz${e} = b${e}.z;\n const tmp${e} = b${e}._temp, scale${e} = b${e}._tempScale, quat${e} = b${e}._tempQ;\n const local${e} = b${e}.ps !== undefined && !b${e}.ps.worldSpace;`,body:`{tmp${e}.set(\n gx${e}.genValue(p.memory, t),\n gy${e}.genValue(p.memory, t),\n gz${e}.genValue(p.memory, t));\n if (local${e}) { tmp${e}.multiply(scale${e}).applyQuaternion(quat${e}); }\n p.velocity.addScaledVector(tmp${e}, delta);}`};case"LimitSpeedOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.speed;\n const dampen${e} = b${e}.dampen * delta * 20;`,body:`{const v = p.velocity;\n const speed = v.length();\n const limit = g${e}.genValue(p.memory, t);\n if (speed > limit) {\n v.multiplyScalar(1 - ((speed - limit) / speed) * dampen${e});\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 pos = p.position;\n const dx = cx${e} - pos.x, dy = cy${e} - pos.y, dz = cz${e} - pos.z;\n const d2 = dx * dx + dy * dy + dz * dz;\n if (d2 > 0) {\n const s = gm${e} / (d2 * Math.sqrt(d2));\n const v = p.velocity;\n v.x += dx * s; v.y += dy * s; v.z += dz * s;\n }}`};case"ColorBySpeed":return{setup:`const b${e} = behaviors[${e}];\n const 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 = (p.startSpeed - lo${e}) / span${e};\n const c = p.color, sc = p.startColor;\n g${e}.genColor(p.memory, c, ts);\n c.x *= sc.x; c.y *= sc.y; c.z *= sc.z; c.w *= sc.w;}`};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;`,body:`{const ts = (p.startSpeed - lo${e}) / span${e};\n if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, ts).multiply(p.startSize);\n } else {\n const v = g${e}.genValue(p.memory, ts);\n const s = p.size, ss = p.startSize;\n s.x = ss.x * v; s.y = ss.y * v; s.z = ss.z * v;\n }}`};case"RotationBySpeed":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.angularVelocity;\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};`,body:`if (typeof p.rotation === 'number') {\n const rate = g${e}.genValue(p.memory, (p.startSpeed - lo${e}) / span${e});\n p.rotation += delta * rate;\n p.angularVelocity = rate;\n }`};case"OrbitOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.orbitSpeed;\n const axis${e} = b${e}.axis, tmp${e} = b${e}.temp, rot${e} = b${e}.rotation;`,body:`{const pos = p.position;\n tmp${e}.copy(pos).projectOnVector(axis${e});\n rot${e}.setFromAxisAngle(axis${e}, g${e}.genValue(p.memory, t) * delta);\n pos.sub(tmp${e});\n pos.applyQuaternion(rot${e});\n pos.add(tmp${e});}`};case"Rotation3DOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.angularVelocity;\n const q${e} = b${e}.tempQuat;`,body:`{const r = p.rotation;\n if (r instanceof deps.Quaternion) {\n g${e}.genValue(p.memory, q${e}, delta, t);\n r.multiply(q${e});\n const step = p.angularVelocity;\n if (step instanceof deps.Quaternion) { step.copy(q${e}); }\n }}`};case"VelocityOverLife":return{setup:`const b${e} = behaviors[${e}];\n const lx${e} = b${e}.linearX, ly${e} = b${e}.linearY, lz${e} = b${e}.linearZ;\n const ox${e} = b${e}.orbitalX, oy${e} = b${e}.orbitalY, oz${e} = b${e}.orbitalZ;\n const tmp${e} = b${e}._temp, rot${e} = b${e}._tempRot;\n const ax${e} = b${e}._axisX, ay${e} = b${e}._axisY, az${e} = b${e}._axisZ;\n const pivot${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 const scale${e} = toWorld${e} ? b${e}._tempScale : b${e}._tempScaleInv;\n const quat${e} = toWorld${e} ? b${e}._tempQ : b${e}._tempQInv;`,body:`{const pos = p.position;\n tmp${e}.set(\n lx${e}.genValue(p.memory, t),\n ly${e}.genValue(p.memory, t),\n lz${e}.genValue(p.memory, t));\n if (convert${e}) { tmp${e}.multiply(scale${e}).applyQuaternion(quat${e}); }\n pos.addScaledVector(tmp${e}, delta);\n const rx = ox${e}.genValue(p.memory, t) * delta;\n const ry = oy${e}.genValue(p.memory, t) * delta;\n const rz = oz${e}.genValue(p.memory, t) * delta;\n if (rx !== 0 || ry !== 0 || rz !== 0) {\n if (world${e}) { pos.sub(pivot${e}); }\n if (rx !== 0) { rot${e}.setFromAxisAngle(ax${e}, rx); pos.applyQuaternion(rot${e}); }\n if (ry !== 0) { rot${e}.setFromAxisAngle(ay${e}, ry); pos.applyQuaternion(rot${e}); }\n if (rz !== 0) { rot${e}.setFromAxisAngle(az${e}, rz); pos.applyQuaternion(rot${e}); }\n if (world${e}) { pos.add(pivot${e}); }\n }}`};case"InheritVelocity":return{setup:`const b${e} = behaviors[${e}];\n const ps${e} = b${e}.ps;\n const velocity${e} = b${e}.mode === 'current' && ps${e} !== undefined\n ? ps${e}.emitterVelocity : undefined;\n const tmp${e} = b${e}._temp;\n const local${e} = velocity${e} !== undefined && !ps${e}.worldSpace;\n const scale${e} = b${e}._tempScaleInv, quat${e} = b${e}._tempQInv;\n const gm${e} = b${e}.multiplier;`,body:`if (velocity${e} !== undefined) {\n tmp${e}.copy(velocity${e});\n if (local${e}) { tmp${e}.multiply(scale${e}).applyQuaternion(quat${e}); }\n p.position.addScaledVector(tmp${e}, gm${e}.genValue(p.memory, t) * delta);\n }`};default:return null}}const ti=new Map;function ei(t,e){const i=ti.get(e);if(void 0!==i)return i??void 0;const s=function(t){const e=`\n ${t.map(t=>t.setup).join("\n")}\n for (let i = 0; i < count; i++) {\n const p = particles[i];\n if (p.age >= p.life) continue;\n const t = p.age / p.life;\n ${t.map(t=>t.body).join("\n")}\n }`;try{return new Function("deps",`return function (behaviors, particles, count, delta) {${e}};`)(He)}catch(t){return}}(t);return ti.set(e,s??null),s}function ii(t){const e=[];let i=[],s=[],r=0;const n=()=>{if(0===s.length)return;const t=`${r}:${i.map(t=>t.type).join(",")}`,n=s.length>1?ei(s,t):void 0;if(void 0!==n)e.push({behaviors:i,run:n});else for(const t of i)e.push({behaviors:[t]});i=[],s=[]};for(let o=0;o<t.length;o++){const a=t[o],h=Ke(a,o);null!==h?(0===s.length&&(r=o),i.push(a),s.push(h)):(n(),e.push({behaviors:[a]}))}return n(),e}var si;function ri(t,e,i,s){let r;switch(si.Random===t?e=Math.random():si.Burst===t&&s.isBursting&&(e=s.burstParticleIndex/s.burstParticleCount),r=i>0?Math.floor(e/i)*i:e,t){case si.Loop:r%=1;break;case si.PingPong:r=Math.abs(r%2-1)}return r}!function(t){t[t.Random=0]="Random",t[t.Loop=1]="Loop",t[t.PingPong=2]="PingPong",t[t.Burst=3]="Burst"}(si||(si={}));class ni{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??si.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[]}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=ri(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)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new ni({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Vt(t.speed):void 0,spread:t.spread})}clone(){return new ni({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class oi{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??si.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[]}update(t,e){si.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ri(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)}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()}}static fromJSON(t){return new oi({radius:t.radius,arc:t.arc,thickness:t.thickness,angle:t.angle,mode:t.mode,speed:t.speed?Vt(t.speed):void 0,spread:t.spread})}clone(){return new oi({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class ai{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??si.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this._m1=new H}update(t,e){si.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ri(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.velocity,se),t.rotation.setFromRotationMatrix(this._m1))}}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()}}static fromJSON(t){return new ai({radius:t.radius,arc:t.arc,thickness:t.thickness,donutRadius:t.donutRadius,mode:t.mode,speed:t.speed?Vt(t.speed):void 0,spread:t.spread})}clone(){return new ai({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class hi{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}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)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(t){return new hi(t)}clone(){return new hi({width:this.width,height:this.height,column:this.column,row:this.row})}update(t,e){}}class li{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??si.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this._m1=new H}update(t,e){si.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ri(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.position,se),t.rotation.setFromRotationMatrix(this._m1))}}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new li({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Vt(t.speed):void 0,spread:t.spread})}clone(){return new li({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class ci{constructor(){this.type="point",this._m1=new H}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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.velocity,se),t.rotation.setFromRotationMatrix(this._m1))}}toJSON(){return{type:"point"}}static fromJSON(t){return new ci}clone(){return new ci}}class ui{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??si.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this._m1=new H}update(t,e){si.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=ri(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.position,se),t.rotation.setFromRotationMatrix(this._m1))}}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new ui({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Vt(t.speed):void 0,spread:t.spread})}clone(){return new ui({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class di{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??si.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this._m1=new H}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=ri(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.velocity,se),t.rotation.setFromRotationMatrix(this._m1))}}toJSON(){return{type:"rectangle",width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(t){return new di({width:t.width,height:t.height,thickness:t.thickness,mode:t.mode,speed:t.speed?Vt(t.speed):void 0,spread:t.spread})}clone(){return new di({width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}const mi={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ni,loadJSON:ni.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:oi,loadJSON:oi.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ai,loadJSON:ai.fromJSON},point:{type:"point",params:[],constructor:ci,loadJSON:ci.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ui,loadJSON:ui.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:li,loadJSON:li.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:hi,loadJSON:hi.fromJSON},rectangle:{type:"rectangle",params:[["width",["number"]],["height",["number"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:di,loadJSON:di.fromJSON}};function pi(t,e){return mi[t.type].loadJSON(t,e)}const fi=[];function yi(t){if(!fi.find(e=>e.id===t.id)){t.initialize();for(const e of t.emitterShapes)mi[e.type]||(mi[e.type]=e);for(const e of t.behaviors)Xe[e.type]||(Xe[e.type]=e)}}function vi(t){const e=fi.find(e=>e.id===t);if(e){for(const t of e.emitterShapes)mi[t.type]&&delete mi[t.type];for(const t of e.behaviors)Xe[t.type]&&delete Xe[t.type]}}class gi{get mesh(){return this._mesh}set mesh(e){if(this._mesh=e,!e)return;const i=e.getVerticesData(t.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 W,a=new W,h=new W;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 W;c.crossVectors(a,h),r+=.5*c.length(),this._triangleIndexToArea.push(r)}}constructor(t,e){this.type="mesh_surface",this._triangleIndexToArea=[],this._meshReferenceId=e,t&&(this.mesh=t)}initialize(t){if(!this._positions||!this._indices)return t.position.set(0,0,0),void t.velocity.set(0,0,1).multiplyScalar(t.startSpeed);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],m=this._positions[3*h]-c,p=this._positions[3*h+1]-u,f=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+m*n+y*o,u+p*n+v*o,d+f*n+g*o);const x=p*g-f*v,S=f*y-m*g,w=m*v-p*y,b=Math.sqrt(x*x+S*S+w*w)||1;t.velocity.set(x/b,S/b,w/b).multiplyScalar(t.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._mesh?this._mesh.uniqueId?.toString():this._meshReferenceId??""}}static fromJSON(t){return new gi(void 0,t?.mesh)}clone(){return new gi(this._mesh,this._meshReferenceId)}update(t,e){}}const xi={id:"babylon.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["mesh",["mesh"]]],constructor:gi,loadJSON:t=>gi.fromJSON(t)}],behaviors:[]};const Si={};let wi=!1;function bi(){wi||(Si.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",Si.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",Si.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",Si.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",Si.soft_pars_vertex="\n#ifdef SOFT_PARTICLES\n varying vec4 projPosition;\n varying float linearDepth;\n#endif\n",Si.soft_vertex="\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n",Si.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",Si.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",wi=!0)}function zi(t){return Si[t]}function Mi(){return Si}var _i="\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",Ti="\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",Pi="\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",Vi="\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform vec3 ambientColor;\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// 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 vec3 eyePosition;\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 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\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 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",Bi="\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// 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 vec2 alignedPosition = position.xy * size.xy;\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 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\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",Oi="\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// 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 float avgSize = (size.x + 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 mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, vdir)) * 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 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",Ai="\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",Ci="\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",Fi="\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 Ni(t){return t.isWebGPU?p.WGSL:p.GLSL}function Ii(t,e,i,s){if(s===p.WGSL)return d.ShadersStoreWGSL[t+"VertexShader"]=e.wgsl,void(d.ShadersStoreWGSL[t+"FragmentShader"]=i.wgsl);m.ShadersStore[t+"VertexShader"]=e.glsl,m.ShadersStore[t+"FragmentShader"]=i.glsl}var Ei;!function(t){t[t.BillBoard=0]="BillBoard",t[t.StretchedBillBoard=1]="StretchedBillBoard",t[t.Mesh=2]="Mesh",t[t.Trail=3]="Trail",t[t.HorizontalBillBoard=4]="HorizontalBillBoard",t[t.VerticalBillBoard=5]="VerticalBillBoard"}(Ei||(Ei={}));class Di{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,layerMask:t.layerMask},this.mesh=new c("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&&e.setTexture("depthTexture",t)}dispose(){this.mesh.dispose()}}class Ui extends Di{static whiteTexture(t){let e=Ui.whiteTextureByScene.get(t);return e||(e=r.CreateRGBATexture(new Uint8Array([255,255,255,255]),1,1,t),e.name="quarksMeshWhite",Ui.whiteTextureByScene.set(t,e)),e}constructor(t,e){super(t,e),this.shaderMaterial=null,this.vector_=new W,this.vector2_=new W,this.vector3_=new W,this.quaternion_=new G,this.quaternion2_=new G,this.quaternion3_=new G,this.quaternion4_=new G,this.quaternion5_=new G,this.rotationMat_=new lt,this.rotationMat2_=new lt,this.lastStretchedSpeedFactor=Number.NaN,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new c("spriteBatch",this.scene),this.mesh.alwaysSelectAsActiveMesh=!0;const t=new u;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(e,this.offsetBuffer,"offset",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.offsetVB),this.colorBuffer=new Float32Array(4*this.maxParticles),this.colorVB=new t(e,this.colorBuffer,"color",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.colorVB),this.sizeBuffer=new Float32Array(3*this.maxParticles),this.sizeVB=new t(e,this.sizeBuffer,"size",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.sizeVB),this.uvTileBuffer=new Float32Array(this.maxParticles),this.uvTileVB=new t(e,this.uvTileBuffer,"uvTile",!0,!1,1,!0),this.mesh.setVerticesBuffer(this.uvTileVB),this.settings.renderMode===Ei.Mesh?(this.rotationBuffer=new Float32Array(4*this.maxParticles),this.rotationVB=new t(e,this.rotationBuffer,"rotation",!0,!1,4,!0)):(this.rotationBuffer=new Float32Array(this.maxParticles),this.rotationVB=new t(e,this.rotationBuffer,"rotation",!0,!1,1,!0)),this.mesh.setVerticesBuffer(this.rotationVB),this.settings.renderMode===Ei.StretchedBillBoard&&(this.velocityBuffer=new Float32Array(4*this.maxParticles),this.velocityVB=new t(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,h;this.settings.renderMode===Ei.Mesh?(r={glsl:_i,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"},h={glsl:Vi,wgsl:"\nvarying vUV: vec2f;\nvarying vColor: vec4f;\nvarying vNormal: vec3f;\nvarying vWorldPos: vec3f;\n\nuniform lightDirection: vec3f;\nuniform lightColor: vec3f;\nuniform ambientColor: vec3f;\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 USE_ENVMAP_ATLAS\nvar envAtlasSampler: sampler;\nvar envAtlas: texture_2d<f32>;\nuniform eyePosition: vec3f;\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 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\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 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===Ei.StretchedBillBoard?(r={glsl:Oi,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// 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 let avgSize = (vertexInputs.size.x + 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 widthOffset = vertexInputs.position.y * normalize(cross(mvPosition.xyz, vdir)) * 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 let stretched = mvPosition.xyz + widthOffset - lengthOffset;\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#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"},h={glsl:Pi,wgsl:Fi}):(r={glsl:Bi,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// 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 let alignedPosition = vertexInputs.position.xy * vertexInputs.size.xy;\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 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\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"},h={glsl:Pi,wgsl:Fi});const l=this.settings.texture??(this.settings.renderMode===Ei.Mesh?Ui.whiteTexture(this.scene):null);l&&e.push("USE_MAP");const c=this.settings.reflectionAtlas;if(this.settings.renderMode===Ei.Mesh&&!!c&&!c.isReady()&&c){const t=c.onLoadObservable;t?.addOnce(()=>{this.rebuildMaterial()})}const u=this.settings.renderMode===Ei.Mesh&&!!c&&c.isReady();u&&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===Ei.VerticalBillBoard&&e.push("VERTICAL"),this.settings.renderMode===Ei.HorizontalBillBoard&&e.push("HORIZONTAL");const d=Ni(this.scene.getEngine());Ii(t,r,h,d);const m=["position","uv","offset","color","size","rotation","uvTile"];this.settings.renderMode===Ei.Mesh&&m.push("normal"),this.settings.renderMode===Ei.StretchedBillBoard&&m.push("velocity");const p=["world","view","projection","worldView","worldViewProjection"],f=[];(this.settings.uTileCount>1||this.settings.vTileCount>1)&&(p.push("tileCountX"),p.push("tileCountY")),l&&f.push("map"),u&&(f.push("envAtlas"),p.push("eyePosition"),p.push("reflectionLevel")),this.settings.renderMode===Ei.StretchedBillBoard&&p.push("speedFactor"),this.settings.softParticles&&(p.push("softParams"),p.push("projParams"),f.push("depthTexture")),this.settings.materialAlphaTest>0&&p.push("alphaTest"),this.settings.renderMode===Ei.Mesh&&(p.push("lightDirection"),p.push("lightColor"),p.push("ambientColor"));const y=new s(t,this.scene,{vertex:t,fragment:t},{attributes:m,uniforms:p,samplers:f,defines:e,needAlphaBlending:this.settings.materialTransparent,shaderLanguage:d});if(l&&y.setTexture("map",l),u&&c){y.setTexture("envAtlas",c),y.setFloat("reflectionLevel",this.settings.reflectionLevel);const t=new n;y.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.copyFrom(e.globalPosition),y.setVector3("eyePosition",t))})}if((this.settings.uTileCount>1||this.settings.vTileCount>1)&&(y.setFloat("tileCountX",this.settings.uTileCount),y.setFloat("tileCountY",this.settings.vTileCount)),this.settings.renderMode===Ei.StretchedBillBoard&&y.setFloat("speedFactor",this.settings.softNearFade>0?this.settings.softNearFade:1),this.settings.softParticles){y.setVector2("softParams",new o(this.settings.softNearFade,1/Math.max(this.settings.softFarFade-this.settings.softNearFade,1e-4)));const t=new a(0,0,0,0);y.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.x=e.minZ,t.y=e.maxZ,y.setVector4("projParams",t))})}this.settings.materialAlphaTest>0&&y.setFloat("alphaTest",this.settings.materialAlphaTest),this.settings.renderMode===Ei.Mesh&&(y.setVector3("lightDirection",new n(.4,-1,.6)),y.setVector3("lightColor",new n(1,1,1)),y.setVector3("ambientColor",new n(.35,.35,.35))),y.backFaceCulling=!1,this.settings.materialTransparent?y.alphaMode=this.settings.materialBlendMode:y.alphaMode=i.ALPHA_DISABLE,y.needDepthPrePass=this.settings.materialDepthWrite,y.forceDepthWrite=this.settings.materialDepthWrite,y.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=y,this.shaderMaterial=y}update(){let t=0,e=0;const i=this.settings.renderMode,s=i===Ei.Mesh,r=i===Ei.StretchedBillBoard,n=this.getVisibleSystems();for(let t=0;t<n.length;t++)e+=n[t].particleNum;e>this.maxParticles&&this.expandBuffers(e);for(let e=0;e<n.length;e++){const i=n[e],o=i.particles,a=i.particleNum,h=this.quaternion2_,l=this.vector2_,c=this.vector3_,u=i.worldSpace,d=i.emitter.matrixWorld;d.decompose(l,h,c),this.rotationMat_.setFromMatrix4(d);const m=Math.abs(c.x),p=Math.abs(c.y),f=Math.abs(c.z),y=r?i.rendererEmitterSettings:void 0,v=void 0===y||0===y.speedFactor?.001:y.speedFactor,g=y?.lengthFactor??0,x=i.store,S=void 0!==x,w=void 0!==x&&!0!==i.onlyUsedByOther,b=i.simulationResidual??0,z=0===b?0:b/(i.simulationStep??b);S&&(0!==z&&a>0?Ui.continueColor(this.colorBuffer,4*t,x,a,z):this.colorBuffer.set(x.color.subarray(0,4*a),4*t));let M=!1;if(void 0!==x&&u)0!==z&&a>0?Ui.extrapolate(this.offsetBuffer,3*t,x,a,z):this.offsetBuffer.set(x.position.subarray(0,3*a),3*t),0!==z&&a>0?Ui.continueVector3(this.sizeBuffer,3*t,x.size,x.previousSize,a,z):this.sizeBuffer.set(x.size.subarray(0,3*a),3*t),M=!0;else if(w&&a>0){const e=3*t,i=e+3*a,s=this.offsetBuffer;0!==z?Ui.extrapolate(s,e,x,a,z):s.set(x.position.subarray(0,3*a),e);const r=d.elements,n=r[0],o=r[1],h=r[2],l=r[3],c=r[4],u=r[5],y=r[6],v=r[7],g=r[8],S=r[9],w=r[10],b=r[11],_=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+g*r+_)*a,s[t+1]=(o*e+u*i+S*r+T)*a,s[t+2]=(h*e+y*i+w*r+P)*a}const B=this.sizeBuffer;0!==z?Ui.continueVector3(B,e,x.size,x.previousSize,a,z):B.set(x.size.subarray(0,3*a),e);for(let t=e;t<i;t+=3)B[t]*=m,B[t+1]*=p,B[t+2]*=f;M=!0}for(let e=0;e<a;e++,t++){const i=o[e];if(s){let e=i.rotation;const s=i.angularVelocity;let r;if(0!==z&&s instanceof G&&(e=this.quaternion4_.copy(e).multiply(Ui.partialTurn(s,z,this.quaternion5_))),u)r=e;else{let t;t=i.parentMatrix?this.quaternion3_.setFromRotationMatrix(i.parentMatrix):h,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*b:0)}if(!M){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(!u){const t=(i.parentMatrix??d).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;u||i.parentMatrix?(this.sizeBuffer[l]=h.x,this.sizeBuffer[l+1]=h.y,this.sizeBuffer[l+2]=h.z):(this.sizeBuffer[l]=h.x*m,this.sizeBuffer[l+1]=h.y*p,this.sizeBuffer[l+2]=h.z*f)}if(!S){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),u||(i.parentMatrix?(this.rotationMat2_.setFromMatrix4(i.parentMatrix),a.applyMatrix3(this.rotationMat2_)):a.applyMatrix3(this.rotationMat_));const h=4*t;this.velocityBuffer[h]=a.x*v,this.velocityBuffer[h+1]=a.y*v,this.velocityBuffer[h+2]=a.z*v,this.velocityBuffer[h+3]=g}}}r&&n.length>0&&this.syncStretchedSpeedFactor(n[0]),this.mesh.forcedInstanceCount=t,0!==t?(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.uploadClearedInstance(s,r)}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 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()}}Ui.whiteTextureByScene=new WeakMap;class Li extends Di{constructor(t,e){super(t,e),this.drawsNothing=!1,this.vector_=new W,this.vector2_=new W,this.vector3_=new W,this.quaternion_=new G,this.maxParticles=1024,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new c("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),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.PositionKind,this.positionBuffer,!0),this.mesh.setVerticesData(t.UVKind,this.uvBuffer,!0),this.mesh.setVerticesData(t.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(e,this.previousBuffer,"previous",!0,!1,3,!1),this.nextVB=new t(e,this.nextBuffer,"next",!0,!1,3,!1),this.sideVB=new t(e,this.sideBuffer,"side",!0,!1,1,!1),this.widthVB=new t(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(-1e4,-1e4,-1e4),s=new n(1e4,1e4,1e4);if(this.mesh.setBoundingInfo(new f(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=Ni(this.scene.getEngine());Ii(t,{glsl:Ci,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:Ai,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 n=[];this.settings.texture&&n.push("map");const a=new s(t,this.scene,{vertex:t,fragment:t},{attributes:["position","previous","next","side","width","uv","color"],uniforms:["world","view","projection","worldViewProjection","lineWidth","resolution","sizeAttenuation"],samplers:n,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 o(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.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.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];Li.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,m=1/u,p=1/d,f=r.worldSpace,y=(Math.abs(a.x)+Math.abs(a.y)+Math.abs(a.z))/3,v=r.rendererEmitterSettings.followLocalOrigin?0:r.simulationResidual??0,g=0===v?0:v/(r.simulationStep??v);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=s.historyColors,u=s.uvTile%d,v=Math.floor(s.uvTile/d+.001),x=(s.parentMatrix??h).elements,S=x[0],w=x[1],b=x[2],z=x[3],M=x[4],_=x[5],T=x[6],P=x[7],V=x[8],B=x[9],O=x[10],A=x[11],C=x[12],F=x[13],N=x[14],I=x[15],E=1/r;let D=s.getHistoryIndex(0),U=D;for(let i=0;i<r;i++,t+=2){const h=i+1<r?D+1===n?0:D+1:D,l=3*D,g=3*U,x=3*h;let L=o[l],R=o[l+1],$=o[l+2],J=o[g],k=o[g+1],q=o[g+2],Q=o[x],G=o[x+1],W=o[x+2];const j=a[D],Y=4*D,X=c[Y],Z=c[Y+1],H=c[Y+2],K=c[Y+3];if(U=D,D=h,!f){let t=1/(z*L+P*R+A*$+I),e=(S*L+M*R+V*$+C)*t,i=(w*L+_*R+B*$+F)*t;$=(b*L+T*R+O*$+N)*t,L=e,R=i,t=1/(z*J+P*k+A*q+I),e=(S*J+M*k+V*q+C)*t,i=(w*J+_*k+B*q+F)*t,q=(b*J+T*k+O*q+N)*t,J=e,k=i,t=1/(z*Q+P*G+A*W+I),e=(S*Q+M*G+V*W+C)*t,i=(w*Q+_*G+B*W+F)*t,W=(b*Q+T*G+O*W+N)*t,Q=e,G=i}const tt=3*t;this.positionBuffer[tt]=L,this.positionBuffer[tt+1]=R,this.positionBuffer[tt+2]=$,this.positionBuffer[tt+3]=L,this.positionBuffer[tt+4]=R,this.positionBuffer[tt+5]=$,this.previousBuffer[tt]=J,this.previousBuffer[tt+1]=k,this.previousBuffer[tt+2]=q,this.previousBuffer[tt+3]=J,this.previousBuffer[tt+4]=k,this.previousBuffer[tt+5]=q,this.nextBuffer[tt]=Q,this.nextBuffer[tt+1]=G,this.nextBuffer[tt+2]=W,this.nextBuffer[tt+3]=Q,this.nextBuffer[tt+4]=G,this.nextBuffer[tt+5]=W,this.sideBuffer[t]=1,this.sideBuffer[t+1]=-1,f||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*E+u)*m;this.uvBuffer[et]=it,this.uvBuffer[et+1]=(d-v-1)*p,this.uvBuffer[et+2]=it,this.uvBuffer[et+3]=(d-v)*p;const st=4*t;this.colorBuffer[st]=X,this.colorBuffer[st+1]=Z,this.colorBuffer[st+2]=H,this.colorBuffer[st+3]=K,this.colorBuffer[st+4]=X,this.colorBuffer[st+5]=Z,this.colorBuffer[st+6]=H,this.colorBuffer[st+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++)}if(0!==g){const i=s.previousPosition,r=s.position;let n=r.x+(r.x-i.x)*g,o=r.y+(r.y-i.y)*g,a=r.z+(r.z-i.z)*g;const h=t-2,l=this.positionBuffer[3*h],c=this.positionBuffer[3*h+1],x=this.positionBuffer[3*h+2];if(!f){const t=1/(z*n+P*o+A*a+I),e=(S*n+M*o+V*a+C)*t,i=(w*n+_*o+B*a+F)*t;a=(b*n+T*o+O*a+N)*t,n=e,o=i}const E=3*t;this.positionBuffer[E]=n,this.positionBuffer[E+1]=o,this.positionBuffer[E+2]=a,this.positionBuffer[E+3]=n,this.positionBuffer[E+4]=o,this.positionBuffer[E+5]=a,this.previousBuffer[E]=l,this.previousBuffer[E+1]=c,this.previousBuffer[E+2]=x,this.previousBuffer[E+3]=l,this.previousBuffer[E+4]=c,this.previousBuffer[E+5]=x,this.nextBuffer[E]=n,this.nextBuffer[E+1]=o,this.nextBuffer[E+2]=a,this.nextBuffer[E+3]=n,this.nextBuffer[E+4]=o,this.nextBuffer[E+5]=a;const D=3*h;this.nextBuffer[D]=n,this.nextBuffer[D+1]=o,this.nextBuffer[D+2]=a,this.nextBuffer[D+3]=n,this.nextBuffer[D+4]=o,this.nextBuffer[D+5]=a,this.sideBuffer[t]=1,this.sideBuffer[t+1]=-1;const U=s.size.x;f||s.parentMatrix?(this.widthBuffer[t]=U,this.widthBuffer[t+1]=U):(this.widthBuffer[t]=U*y,this.widthBuffer[t+1]=U*y);const L=2*t,R=(1+u)*m;this.uvBuffer[L]=R,this.uvBuffer[L+1]=(d-v-1)*p,this.uvBuffer[L+2]=R,this.uvBuffer[L+3]=(d-v)*p;const $=s.color,J=4*t;this.colorBuffer[J]=$.x,this.colorBuffer[J+1]=$.y,this.colorBuffer[J+2]=$.z,this.colorBuffer[J+3]=$.w,this.colorBuffer[J+4]=$.x,this.colorBuffer[J+5]=$.y,this.colorBuffer[J+6]=$.z,this.colorBuffer[J+7]=$.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){if(e>0&&i>0){this.mesh.updateVerticesData(t.PositionKind,this.positionBuffer.subarray(0,3*e)),this.mesh.updateVerticesData(t.UVKind,this.uvBuffer.subarray(0,2*e)),this.mesh.updateIndices(this.indexBuffer.subarray(0,3*i)),this.previousVB.update(this.previousBuffer.subarray(0,3*e)),this.nextVB.update(this.nextBuffer.subarray(0,3*e)),this.sideVB.update(this.sideBuffer.subarray(0,e)),this.widthVB.update(this.widthBuffer.subarray(0,e));const s=this.mesh.getVertexBuffer(t.ColorKind);s&&s.update(this.colorBuffer.subarray(0,4*e)),this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.adoptMeshBounds(),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),this.mesh.updateIndices(this.indexBuffer.subarray(0,6)),this.adoptMeshBounds(),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 Ri extends e{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}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}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(Ri.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 Ei.Trail:s=new Li(i,r);break;case Ei.Mesh:case Ei.BillBoard:case Ei.VerticalBillBoard:case Ei.HorizontalBillBoard:case Ei.StretchedBillBoard:s=new Ui(i,r);break;default:throw new Error(`Unsupported render mode: ${i.renderMode}`)}s.mesh.parent=this,this.depthTexture&&s.applyDepthTexture(this.depthTexture),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)}configureAdaptivePerformance(t={}){const e=this.adaptivePerformanceState,i=Ri.clamp(t.minQuality??e.minQuality,.05,1),s=Ri.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=Ri.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=Ri.clamp(e.currentQuality-e.decreaseStep,e.minQuality,e.maxQuality):e.currentQuality=Ri.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>Ri.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()}}Ri.EMPTY_BATCH_GRACE_FRAMES=120;const $i=Ri,Ji=new WeakMap,ki=new WeakMap;function qi(t){if(!t?.isCube)return null;const e=t.files??t._files;return 6===e?.length?e.slice():null}function Qi(t){return Ji.get(t)??null}function Gi(t,e){Ji.set(t,e)}async function Wi(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(r.toDataURL("image/jpeg",.92),e,{noMipmap:!0,invertY:!1,samplingMode:y.LINEAR_LINEAR});return o.name="quarksEnvAtlas",o}const ji={createFromFaceUrls:Wi};function Yi(t,e,i){const s=Ji.get(t);if(s)return i(s),s;const r=()=>{const s=ki.get(t);if(s)return void s.then(t=>{t&&i(t)});const r=qi(t);if(!r)return;const n=ji.createFromFaceUrls(r,e).then(e=>(Ji.set(t,e),ki.delete(t),i(e),e)).catch(e=>(ki.delete(t),console.warn("[babylon.quarks] Failed to build env atlas from cubemap faces",e),null));ki.set(t,n)};if(t.isReady())r();else{const e=t.onLoadObservable;e?e.addOnce(()=>r()):r()}return Ji.get(t)??null}class Xi extends g{constructor(t,e,i={}){super(t,e),this.isParticleMeshStandardMaterial=!0,Object.assign(this,i)}}class Zi extends v{constructor(t,e,i={}){super(t,e),this.isParticleMeshPhysicsMaterial=!0,Object.assign(this,i)}}class Hi extends e{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 H,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 Ki(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 ts=new W(0,0,1),es=new G,is=new W,ss=new W,rs=1/60,ns=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),os=new Float32Array([0,0,1,0,1,1,0,1]);const as=new Uint32Array([0,1,2,0,2,3]);class hs{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(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 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===Ei.Trail&&(e=!0),this.rendererSettings.renderMode===Ei.Mesh&&(this.startRotation=new zt(0)),t){case Ei.Trail:this.rendererEmitterSettings={startLength:new zt(30),followLocalOrigin:!1},e=!0;break;case Ei.Mesh:this.rendererEmitterSettings={},this.startRotation=new Bt(new W(0,1,0),new zt(0));break;case Ei.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2};break;case Ei.BillBoard:case Ei.VerticalBillBoard:case Ei.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 $e(64),this.emitterVelocity=new W,this.finishedEventFired=!1,this.startDelayTimeLeft=0,this.tempEmitterPos=new W,this.temp=new W,this.normalMatrix=new lt,this.memory=[],this.listeners={},this.materialRef=null,this.qualityFactor=1,this.simulationAccumulator=0,this.destroyed=!1,this.fusionSteps=[],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 zt(0),this.looping=t.looping??!0,this.prewarm=t.prewarm??!1,this.startLife=t.startLife??new zt(5),this.startSpeed=t.startSpeed??new zt(0),this.startRotation=t.startRotation??new zt(0),this.startSize=t.startSize??new zt(1),this.startColor=t.startColor??new $t(new ft(1,1,1,1)),this.emissionOverTime=t.emissionOverTime??new zt(10),this.emissionOverDistance=t.emissionOverDistance??new zt(0),this.emissionBursts=t.emissionBursts??[],this.onlyUsedByOther=t.onlyUsedByOther??!1,this.emitterShape=t.shape??new ui,this.behaviors=t.behaviors??[],this.worldSpace=t.worldSpace??!1,this.rendererEmitterSettings=t.rendererEmitterSettings??{},t.renderMode===Ei.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??ns,instancingIndices:t.instancingIndices??as,instancingUVs:t.instancingUVs??(t.instancingGeometry?(e=t.instancingGeometry,new Float32Array(e.length/3*2)):os),instancingNormals:t.instancingNormals,renderMode:t.renderMode??Ei.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.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},this.rendererSettings.renderMode!==Ei.Mesh||this.rendererSettings.instancingNormals||(this.rendererSettings.instancingNormals=hs.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 zt(0),this.emitter=new Hi(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=Qi(s),!c&&this.sceneRef&&(Yi(s,this.sceneRef,e=>{this.rendererSettings.reflectionAtlas!==e&&(this.rendererSettings.reflectionAtlas=e,t&&null==t.reflectionAtlas&&(t.reflectionAtlas=e),this.neededToUpdateRender=!0)}),c=Qi(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 je(this.store,e):new Qe(this.store,e))}spawn(t,e,i){const s=is,r=ss;i.decompose(s,es,r);const n=this.behaviors,o=n.length,a=this.rendererSettings.renderMode,h=a===Ei.Trail,l=!h,c=a===Ei.Mesh,u="rotation"===this.startRotation.type,d="vec3function"===this.startSize.type,m=e.time/this.duration,p=h?this.rendererEmitterSettings:void 0,f=Boolean(p?.followLocalOrigin);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,m),this.startLife.startGen(t.memory),t.life=this.startLife.genValue(t.memory,m),t.age=0,this.startSize.startGen(t.memory),d)this.startSize.genValue(t.memory,t.startSize,m);else{const e=this.startSize.genValue(t.memory,m);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;this.startRotation.startGen(t.memory),c?(e.rotation instanceof G||(e.rotation=new G),e.angularVelocity instanceof G&&e.angularVelocity.set(0,0,0,1),u?this.startRotation.genValue(t.memory,e.rotation,1,m):e.rotation.setFromAxisAngle(ts,this.startRotation.genValue(e.memory,m))):(e.rotation=u?0:this.startRotation.genValue(e.memory,m),e.angularVelocity=0)}else if(p){const e=t;p.startLength.startGen(e.memory),e.length=p.startLength.genValue(e.memory,m),e.ensureHistoryCapacity(Math.max(1,Math.ceil(e.length))),e.resetHistory()}if(this.emitterShape.initialize(t,e),h&&f){const e=t;e.localPosition||(e.localPosition=new W),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 G&&t.rotation.multiplyQuaternions(es,t.rotation)):this.onlyUsedByOther&&(t.parentMatrix=i);for(let e=0;e<o;e++)n[e].initialize(t,this)}}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.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/rs-1e-9)));return void(this.simulationAccumulator-=e*rs)}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 W)).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/rs-1e-9)));for(let t=0;t<i;t++)this.simulateStep(rs);this.simulationAccumulator-=i*rs}get simulationStep(){return rs}get simulationResidual(){return this.paused?0:this.simulationAccumulator>rs?rs:this.simulationAccumulator<-rs?-rs: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}return this.fusionPlan=t.slice(),this.fusionSteps=ii(t),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===Ei.Trail,n=this.rendererSettings.renderMode===Ei.StretchedBillBoard,o=this.store,a=3*s;o.previousPosition.set(o.position.subarray(0,a)),o.previousSize.set(o.size.subarray(0,a)),n&&(o.keepPreviousVelocity()&&this.rebindParticles(),o.previousVelocity.set(o.velocity.subarray(0,a))),o.previousColor.set(o.color.subarray(0,4*s)),this.emitterShape.update(this,t);const h=this.behaviorSteps();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);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)}if(r&&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=this.store.position,i=this.store.velocity,r=this.store.scalars,n=$e.SCALAR_STRIDE;for(let o=0,a=0,h=0;o<s;o++,a+=3,h+=n){const s=t*r[h+$e.SPEED_MODIFIER];e[a]+=i[a]*s,e[a+1]+=i[a+1]*s,e[a+2]+=i[a+2]*s,r[h+$e.AGE]+=t}}if(r)for(let t=0;t<s;t++)e[t].update();const l=this.hasListeners("particleDied"),c=this.store,u=c.scalars,d=$e.SCALAR_STRIDE;let m=this.particleNum;for(let t=0;t<m;t++){const i=e[t],s=t*d;if(u[s+$e.AGE]>=u[s+$e.LIFE]&&(!r||0===i.historyCount)){const s=m-1,r=e[s];e[t]=r,e[s]=i,t!==s&&(c.swapRows(t,s),r.setStoreIndex(t),i.setStoreIndex(s)),m--,t--,l&&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()))}emit(t,e,i){if(e.time>this.duration)if(this.looping){e.time-=this.duration,e.burstIndex=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,r=s.length,n=this.qualityFactor;for(;e.burstIndex<r&&s[e.burstIndex].time<=e.time;){const t=s[e.burstIndex];if(Math.random()<t.probability){const s=t.count.genValue(this.memory,this.time),r=n>=.999?s:Math.floor(s*n);e.isBursting=!0,e.burstParticleCount=r,this.spawn(r,e,i),e.isBursting=!1}e.burstIndex++}if(!this.emitEnded){const s=e.time/this.duration;e.waitEmiting+=t*this.emissionOverTime.genValue(this.memory,s)*n;const r=e.previousWorldPos;if(void 0!==r){this.temp.set(i.elements[12],i.elements[13],i.elements[14]),e.travelDistance+=r.distanceTo(this.temp);const t=this.emissionOverDistance.genValue(this.memory,s)*n;if(e.travelDistance*t>0){const i=Math.floor(e.travelDistance*t);e.travelDistance-=i/t,e.waitEmiting+=i}}}const o=Math.floor(e.waitEmiting);o>0&&(this.spawn(o,e,i),e.waitEmiting-=o),void 0===e.previousWorldPos&&(e.previousWorldPos=new W),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})),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}}static fromJSON(t,e,s={},r){const n=pi(t.shape,e);let o;if(t.renderMode===Ei.Trail){const e=t.rendererEmitterSettings;o={startLength:void 0!==e?.startLength?Vt(e.startLength):new zt(30),followLocalOrigin:e?.followLocalOrigin??!1}}else t.renderMode===Ei.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=hs.resolveGeometryData(c),d=new hs({scene:r,autoDestroy:t.autoDestroy,looping:t.looping,prewarm:t.prewarm,duration:t.duration,startDelay:t.startDelay?Vt(t.startDelay):void 0,shape:n,startLife:Vt(t.startLife),startSpeed:Vt(t.startSpeed),startRotation:jt(t.startRotation),startSize:jt(t.startSize),startColor:Jt(t.startColor),emissionOverTime:Vt(t.emissionOverTime),emissionOverDistance:Vt(t.emissionOverDistance),emissionBursts:t.emissionBursts?.map(t=>({time:t.time,count:"number"==typeof t.count?new zt(t.count):Vt(t.count),probability:t.probability??1,interval:t.interval??.1,cycle:t.cycle??t.cycleCount??1})),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.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 zt(t.startTileIndex):Vt(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});return d.behaviors=(t.behaviors??[]).map(t=>{const e=Ze(t,d);return e&&"EmitSubParticleSystem"===e.type&&(s[t.subParticleSystem]=e),e}).filter(t=>null!==t),d}static nextSerializationId(t){return hs.serializationCounter+=1,`${t}_${hs.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===Ei.Trail?{startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===Ei.StretchedBillBoard?{speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:{}}ensureGeometryMeta(t){const e=hs.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=hs.nextSerializationId("quarks_texture"),t.textures[i]=e);const s=this.rendererSettings.reflectionAtlas;let r;s instanceof y&&(r=hs.nextSerializationId("quarks_texture"),t.textures[r]=s);const n=hs.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,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:Ki(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:Ki(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:ns,indices:as,uvs:os}}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===Ei.Trail?{startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===Ei.StretchedBillBoard?{lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:{},new hs({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})),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,scene:this.emitter.getScene()})}}hs.serializationCounter=0;class ls extends e{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 Hi?t.target.system.pause():t.clip?.pause?.()}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(t=>{"ps"===t.type&&t.target instanceof Hi?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 Hi)return void t.target.system.restart();"ps"===t.type&&t.target instanceof Hi?t.target.system.endEmit():t.loop?t.clip?.play?.():t.clip?.stop?.()}}else"ps"===t.type&&t.target instanceof Hi?(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 Hi?i.target.system.endEmit():i.clip?.stop?.():"ps"===i.type&&i.target instanceof Hi?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&&s(t)};s(t),this._tempAnimationJSON.forEach(t=>{const e=i[t.targetUUID];if("ps"===t.type&&e instanceof Hi)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 ls(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}}class cs{constructor(t,e={}){this.scene=t,this.options=e}async load(t){const e=this.options.baseUrl||t.substring(0,t.lastIndexOf("/")+1),i=await fetch(t),s=await i.json();return this.parse(s,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&&(e.geometries[i.uuid]={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})}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 m=0;for(let t=0;t<=s;t++){const u=[],p=t/s,f=o+p*a;for(let t=0;t<=i;t++){const s=t/i,o=r+s*n,a=-e*Math.cos(o)*Math.sin(f),d=e*Math.cos(f),y=e*Math.sin(o)*Math.sin(f);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-p),u.push(m++)}d.push(u)}const p=o<=0,f=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&&p||u.push(i,r,o),t===s-1&&f||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=Ki(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)}parseImages(t,e,i){this._images={};for(const i of t)i.url&&cs.warnIfNotAnImageUrl(i.url),this._images[i.uuid]=i.url?this.resolveImageUrl(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.`)}resolveImageUrl(t,e){return/^(data|blob):/i.test(e)||/^[a-z][a-z0-9+.-]*:\/\//i.test(e)||e.startsWith("/")?e:t+e}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=new y(t,this.scene,{noMipmap:r,invertY:i,samplingMode:"number"==typeof s.samplingMode?s.samplingMode:void 0});Array.isArray(s.wrap)&&(n.wrapU=this.mapWrapMode(s.wrap[0]),n.wrapV=this.mapWrapMode(s.wrap[1]??s.wrap[0])),Array.isArray(s.repeat)&&(n.uScale=s.repeat[0]??1,n.vScale=s.repeat[1]??1),Array.isArray(s.offset)&&(n.uOffset=s.offset[0]??0,n.vOffset=s.offset[1]??0),"number"==typeof s.rotation&&(n.wAng=s.rotation),e.textures[s.uuid]=n}else e.textures[s.uuid]=null}}mapWrapMode(t){switch(t){case 1001:return y.CLAMP_ADDRESSMODE;case 1002:return y.MIRROR_ADDRESSMODE;default:return y.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),"number"==typeof s.alphaMode)t.alphaMode=s.alphaMode;else{const e={1:i.ALPHA_COMBINE,2:i.ALPHA_ADD,3:i.ALPHA_SUBTRACT,4:i.ALPHA_MULTIPLY};t.alphaMode=e[s.blending]||i.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(i||t||"node",this.scene);return s.quarksOriginalType=t,s}createMeshNode(t,e){const s=new c(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 u;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 g(`quarks_loader_material_${n.uuid}`,this.scene);t.alphaMode=n.alphaMode??i.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=ls.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(t.name||t.type||"node",this.scene)}if(t.uuid&&(s._quarksUUID=t.uuid),t.name&&(s.name=t.name),t.matrix){const e=h.FromArray(t.matrix),i=new n(1,1,1),r=l.Identity(),o=new n(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 l(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=hs.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&&s(i)};s(t);const r=s=>{if(s instanceof ls&&s.resolveReferences(t),s instanceof Hi){const t=s.system,e=t._meshSurfaceReferenceUUID;if(e&&"mesh_surface"===t.emitterShape.type){const s=i[e];s instanceof c&&(t.emitterShape.mesh=s)}for(let e=0;e<t.behaviors.length;e++)if(t.behaviors[e]instanceof he){const s=t.behaviors[e],r=s.subParticleSystem;if("string"==typeof r&&i[r]){const t=i[r];s.subParticleSystem=t,t instanceof Hi&&(t.system.onlyUsedByOther=!0)}}}for(const t of s.getChildren())t instanceof e&&r(t)};r(t)}}class us{static runOnAllParticleEmitters(t,e){us.traverseNode(t,t=>{t instanceof Hi&&e(t)})}static addToBatchRenderer(t,e){us.runOnAllParticleEmitters(t,t=>{e.addSystem(t.system)})}static play(t){us.runOnAllParticleEmitters(t,t=>{t.system.play()})}static stop(t){us.runOnAllParticleEmitters(t,t=>{t.system.stop()})}static pause(t){us.runOnAllParticleEmitters(t,t=>{t.system.pause()})}static restart(t){us.runOnAllParticleEmitters(t,t=>{t.system.restart()})}static setAutoDestroy(t,e){us.runOnAllParticleEmitters(t,t=>{t.system.autoDestroy=e})}static endEmit(t){us.runOnAllParticleEmitters(t,t=>{t.system.endEmit()})}static isEffectFinished(t){let e=!1,i=!0;return us.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)us.traverseNode(t,e)}}bi(),yi(xi);export{bt as ApplyCollision,Yt as ApplyForce,Ht as ApplySequences,Bt as AxisAngleGenerator,$i as BatchedParticleRenderer,Ri as BatchedRenderer,Ze as BehaviorFromJSON,Xe as BehaviorTypes,_t as Bezier,Kt as ChangeEmitDirection,ni as CircleEmitter,te as ColorBySpeed,Jt as ColorGeneratorFromJSON,ee as ColorOverLife,Nt as ColorRange,oi as ConeEmitter,$t as ConstantColor,zt as ConstantValue,w as DEG2RAD,ai as DonutEmitter,he as EmitSubParticleSystem,pi as EmitterFromJSON,si as EmitterMode,mi as EmitterShapes,ht as Euler,kt as EulerGenerator,le as ForceOverLife,ce as FrameOverLife,jt as GeneratorFromJSON,Dt as Gradient,ue as GravityForce,hi as GridEmitter,li as HemisphereEmitter,de as InheritVelocity,Mt as IntervalValue,me as LimitSpeedOverLife,Q as MathUtils,lt as Matrix3,H as Matrix4,gi as MeshSurfaceEmitter,xi as MeshSurfaceEmitterPlugin,qe as NodeParticle,Ve as Noise,Be as OrbitOverLife,Hi as ParticleEmitter,Zi as ParticleMeshPhysicsMaterial,Xi as ParticleMeshStandardMaterial,$e as ParticleStore,hs as ParticleSystem,Pt as PiecewiseBezier,Tt as PiecewiseFunction,fi as Plugins,ci as PointEmitter,cs as QuarksLoader,ls as QuarksPrefab,us as QuarksUtil,G as Quaternion,b as RAD2DEG,Ut as RandomColor,Rt as RandomColorBetweenGradient,qt as RandomQuatGenerator,We as RecordState,di as RectangleEmitter,Ei as RenderMode,Oe as Rotation3DOverLife,Ae as RotationBySpeed,Qt as RotationGeneratorFromJSON,Ce as RotationOverLife,Zt as SequencerFromJSON,Fe as SizeBySpeed,Ne as SizeOverLife,Ie as SpeedOverLife,ui as SphereEmitter,Ui as SpriteBatch,Qe as SpriteParticle,ae as SubParticleEmitMode,Xt as TextureSequencer,Li as TrailBatch,je as TrailParticle,Ee as TurbulenceField,Di as VFXBatch,Vt as ValueGeneratorFromJSON,ut as Vector2,W as Vector3,Gt as Vector3Function,Wt as Vector3GeneratorFromJSON,mt as Vector3View,ft as Vector4,vt as Vector4View,Re as VelocityOverLife,X as WebGLCoordinateSystem,Z as WebGPUCoordinateSystem,Ye as WidthOverLength,Gi as cacheEnvAtlas,R as ceilPowerOfTwo,M as clamp,Wi as createEnvAtlasFromFaceUrls,qi as cubeFaceUrls,B as damp,D as degToRad,k as denormalize,Yi as ensureEnvAtlasFromCube,_ as euclideanModulo,$ as floorPowerOfTwo,z as generateUUID,Qi as getCachedEnvAtlas,wt as getPhysicsResolver,Mi as getRegisteredShaderChunks,zi as getShaderChunk,ri as getValueFromEmitterMode,P as inverseLerp,L as isPowerOfTwo,V as lerp,yi as loadPlugin,_i as localParticlePhysicsVertShader,Ti as localParticleVertShader,T as mapLinear,q as normalize,Pi as particleFragShader,Vi as particlePhysicsFragShader,Bi as particleVertShader,O as pingpong,ii as planBehaviorFusion,U as radToDeg,N as randFloat,I as randFloatSpread,F as randInt,bi as registerShaderChunks,E as seededRandom,St as setPhysicsResolver,J as setQuaternionFromProperEuler,C as smootherstep,A as smoothstep,Oi as stretchedBillboardVertShader,Ai as trailFragShader,Ci as trailVertShader,vi as unloadPlugin};
1
+ import{VertexBuffer as t}from"@babylonjs/core/Buffers/buffer";import{TransformNode as e}from"@babylonjs/core/Meshes/transformNode";import{Constants as i}from"@babylonjs/core/Engines/constants";import{ShaderMaterial as s}from"@babylonjs/core/Materials/shaderMaterial";import{RawTexture as r}from"@babylonjs/core/Materials/Textures/rawTexture";import{Vector3 as n,Vector2 as o,Vector4 as a,Matrix as h,Quaternion as l}from"@babylonjs/core/Maths/math.vector";import{Mesh as c}from"@babylonjs/core/Meshes/mesh";import{VertexData as u}from"@babylonjs/core/Meshes/mesh.vertexData";import{ShaderStore as d}from"@babylonjs/core/Engines/shaderStore";import{Effect as p}from"@babylonjs/core/Materials/effect";import{ShaderLanguage as m}from"@babylonjs/core/Materials/shaderLanguage";import{BoundingInfo as f}from"@babylonjs/core/Culling/boundingInfo";import{Texture as y}from"@babylonjs/core/Materials/Textures/texture";import{PBRMaterial as v}from"@babylonjs/core/Materials/PBR/pbrMaterial";import{StandardMaterial as g}from"@babylonjs/core/Materials/standardMaterial";const x=["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 S=1234567;const w=Math.PI/180,b=180/Math.PI;function z(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return(x[255&t]+x[t>>8&255]+x[t>>16&255]+x[t>>24&255]+"-"+x[255&e]+x[e>>8&255]+"-"+x[e>>16&15|64]+x[e>>24&255]+"-"+x[63&i|128]+x[i>>8&255]+"-"+x[i>>16&255]+x[i>>24&255]+x[255&s]+x[s>>8&255]+x[s>>16&255]+x[s>>24&255]).toLowerCase()}function M(t,e,i){return Math.max(e,Math.min(i,t))}function _(t,e){return(t%e+e)%e}function T(t,e,i,s,r){return s+(t-e)*(r-s)/(i-e)}function P(t,e,i){return t!==e?(i-t)/(e-t):0}function O(t,e,i){return(1-i)*t+i*e}function V(t,e,i,s){return O(t,e,1-Math.exp(-i*s))}function B(t,e=1){return e-Math.abs(_(t,2*e)-e)}function A(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*(3-2*t)}function C(t,e,i){return t<=e?0:t>=i?1:(t=(t-e)/(i-e))*t*t*(t*(6*t-15)+10)}function F(t,e){return t+Math.floor(Math.random()*(e-t+1))}function N(t,e){return t+Math.random()*(e-t)}function I(t){return t*(.5-Math.random())}function E(t){void 0!==t&&(S=t);let e=S+=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 U(t){return t*w}function D(t){return t*b}function L(t){return!(t&t-1)&&0!==t}function R(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))}function J(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function k(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),m=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*m,h*p,a*l);break;case"YXY":t.set(h*p,a*c,h*m,a*l);break;case"ZYZ":t.set(h*m,h*p,a*c,a*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function $(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 q(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:w,RAD2DEG:b,generateUUID:z,clamp:M,euclideanModulo:_,mapLinear:T,inverseLerp:P,lerp:O,damp:V,pingpong:B,smoothstep:A,smootherstep:C,randInt:F,randFloat:N,randFloatSpread:I,seededRandom:E,degToRad:U,radToDeg:D,isPowerOfTwo:L,ceilPowerOfTwo:R,floorPowerOfTwo:J,setQuaternionFromProperEuler:k,normalize:q,denormalize:$};class G{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],m=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]=m);if(c!==m||a!==u||h!==d||l!==p){let t=1-o;const e=a*u+h*d+l*p+c*m,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+m*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 G(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(M(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}}G.prototype.isQuaternion=!0;class W{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 W(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(Y.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Y.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 j.copy(this).projectOnVector(t),this.sub(j)}reflect(t){return this.sub(j.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(M(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}}W.prototype.isVector3=!0;const j=new W,Y=new G,X=2e3,Z=2001;class H{constructor(t,e,i,s,r,n,o,a,h,l,c,u,d,p,m,f){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,m,f)}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,m,f){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]=m,y[15]=f,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 H).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/K.setFromMatrixColumn(t,0).length(),r=1/K.setFromMatrixColumn(t,1).length(),n=1/K.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(et,t,it)}lookAt(t,e,i){const s=this.elements;return nt.subVectors(t,e),0===nt.lengthSq()&&(nt.z=1),nt.normalize(),st.crossVectors(i,nt),0===st.lengthSq()&&(1===Math.abs(i.z)?nt.x+=1e-4:nt.z+=1e-4,nt.normalize(),st.crossVectors(i,nt)),st.normalize(),rt.crossVectors(nt,st),s[0]=st.x,s[4]=rt.x,s[8]=nt.x,s[1]=st.y,s[5]=rt.y,s[9]=nt.y,s[2]=st.z,s[6]=rt.z,s[10]=nt.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],m=i[6],f=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],T=s[5],P=s[9],O=s[13],V=s[2],B=s[6],A=s[10],C=s[14],F=s[3],N=s[7],I=s[11],E=s[15];return r[0]=n*w+o*_+a*V+h*F,r[4]=n*b+o*T+a*B+h*N,r[8]=n*z+o*P+a*A+h*I,r[12]=n*M+o*O+a*C+h*E,r[1]=l*w+c*_+u*V+d*F,r[5]=l*b+c*T+u*B+d*N,r[9]=l*z+c*P+u*A+d*I,r[13]=l*M+c*O+u*C+d*E,r[2]=p*w+m*_+f*V+y*F,r[6]=p*b+m*T+f*B+y*N,r[10]=p*z+m*P+f*A+y*I,r[14]=p*M+m*O+f*C+y*E,r[3]=v*w+g*_+x*V+S*F,r[7]=v*b+g*T+x*B+S*N,r[11]=v*z+g*P+x*A+S*I,r[15]=v*M+g*O+x*C+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],m=t[13],f=t[14],y=t[15],v=c*f*h-m*u*h+m*a*d-o*f*d-c*a*y+o*u*y,g=p*u*h-l*f*h-p*a*d+n*f*d+l*a*y-n*u*y,x=l*m*h-p*c*h+p*o*d-n*m*d-l*o*y+n*c*y,S=p*c*a-l*m*a-p*o*u+n*m*u+l*o*f-n*c*f,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]=(m*u*r-c*f*r-m*s*d+i*f*d+c*s*y-i*u*y)*b,t[2]=(o*f*r-m*a*r+m*s*h-i*f*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*f*r-p*u*r+p*s*d-e*f*d-l*s*y+e*u*y)*b,t[6]=(p*a*r-n*f*r-p*s*h+e*f*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*m*r-p*i*d+e*m*d+l*i*y-e*c*y)*b,t[10]=(n*m*r-p*o*r+p*i*h-e*m*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*m*s-p*c*s+p*i*u-e*m*u-l*i*f+e*c*f)*b,t[14]=(p*o*s-n*m*s-p*i*a+e*m*a+n*i*f-e*o*f)*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,m=n*l,f=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-(m+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]=(f+v)*w,s[7]=0,s[8]=(p+g)*b,s[9]=(f-v)*b,s[10]=(1-(u+m))*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=K.set(s[0],s[1],s[2]).length();const n=K.set(s[4],s[5],s[6]).length(),o=K.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],tt.copy(this);const a=1/r,h=1/n,l=1/o;return tt.elements[0]*=a,tt.elements[1]*=a,tt.elements[2]*=a,tt.elements[4]*=h,tt.elements[5]*=h,tt.elements[6]*=h,tt.elements[8]*=l,tt.elements[9]*=l,tt.elements[10]*=l,e.setFromRotationMatrix(tt),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===X)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Z)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,m;if(o===X)p=(n+r)*c,m=-2*c;else{if(o!==Z)throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*c,m=-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]=m,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}}H.prototype.isMatrix4=!0;const K=new W,tt=new H,et=new W(0,0,0),it=new W(1,1,1),st=new W,rt=new W,nt=new W,ot=new H,at=new G;class ht{constructor(t=0,e=0,i=0,s=ht.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 ht(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(M(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(-M(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(M(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(-M(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(M(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(-M(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 ot.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ot,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return at.setFromEuler(this),this.setFromQuaternion(at,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}}ht.DEFAULT_ORDER="XYZ",ht.prototype.isEuler=!0;class lt{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],m=s[0],f=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*m+o*v+a*S,r[3]=n*f+o*g+a*w,r[6]=n*y+o*x+a*b,r[1]=h*m+l*v+c*S,r[4]=h*f+l*g+c*w,r[7]=h*y+l*x+c*b,r[2]=u*m+d*v+p*S,r[5]=u*f+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 m=1/p;return t[0]=c*m,t[1]=(s*h-l*i)*m,t[2]=(o*i-s*n)*m,t[3]=u*m,t[4]=(l*e-s*a)*m,t[5]=(s*r-o*e)*m,t[6]=d*m,t[7]=(i*a-h*e)*m,t[8]=(n*e-i*r)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,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(ct.makeScale(t,e)),this}rotate(t){return this.premultiply(ct.makeRotation(-t)),this}translate(t,e){return this.premultiply(ct.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 lt).fromArray(this.elements)}}lt.prototype.isMatrix3=!0;const ct=new lt;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(M(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 W{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const mt=pt.prototype;mt.data=dt,mt.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 ft{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 ft(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],m=a[2],f=a[6],y=a[10];if(Math.abs(l-u)<n&&Math.abs(c-m)<n&&Math.abs(p-f)<n){if(Math.abs(l+u)<o&&Math.abs(c+m)<o&&Math.abs(p+f)<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+m)/4,S=(p+f)/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((f-p)*(f-p)+(c-m)*(c-m)+(u-l)*(u-l));return Math.abs(v)<.001&&(v=1),this.x=(f-p)/v,this.y=(c-m)/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}}ft.prototype.isVector4=!0;const yt=new Float32Array(4);class vt extends ft{constructor(t,e){super(),this.data=t,this.offset=e}bind(t,e){this.data=t,this.offset=e}}const gt=vt.prototype;let xt;function St(t){xt=t}function wt(){return xt}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 bt{constructor(t,e){this.resolver=t,this.bounce=e,this.type="ApplyCollision",this.tempV=new W}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 bt(wt(),t.bounce)}clone(){return new bt(this.resolver,this.bounce)}reset(){}}class zt{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 zt(t.value)}clone(){return new zt(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 _t{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 _t(e[0],e[4],e[7],e[9]),right:new _t(e[9],e[8],e[6],e[3]),span:e}}clone(){return new _t(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 _t(t.p0,t.p1,t.p2,t.p3)}}class Tt{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 Pt extends Tt{constructor(t=[[new _t(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=Pt.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}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 Pt(t.functions.map(t=>[_t.fromJSON(t.function),t.start]))}clone(){return new Pt(this.functions.map(([t,e])=>[t.clone(),e]))}startGen(t){}}function Ot(t){switch(t.type){case"ConstantValue":return zt.fromJSON(t);case"IntervalValue":return Mt.fromJSON(t);case"PiecewiseBezier":return Pt.fromJSON(t);default:return new zt(0)}}Pt.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 W(t.axis.x,t.axis.y,t.axis.z),Ot(t.angle))}clone(){return new Vt(this.axis.clone(),this.angle.clone())}}const Bt=t=>({r:t.x,g:t.y,b:t.z,a:t.w}),At=t=>new ft(t.r,t.g,t.b,t.a),Ct=(t,e)=>{switch(e){case"Vector3":return new W(t.x,t.y,t.z);case"Vector4":return new ft(t.x,t.y,t.z,t.w);case"Color":return new W(t.r,t.g,t.b);default:return t}},Ft=(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 Nt{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:Bt(this.a),b:Bt(this.b)}}static fromJSON(t){return new Nt(At(t.a),At(t.b))}clone(){return new Nt(this.a.clone(),this.b.clone())}}class It{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:Ft(t,this.subType),pos:e}))}}static fromJSON(t){return new It(t.keys.map(e=>[Ct(e.value,t.subType),e.pos]),t.subType)}clone(){return"Number"===this.subType?new It(this.keys.map(([t,e])=>[t,e]),this.subType):new It(this.keys.map(([t,e])=>[t.clone(),e]),this.subType)}}const Et=new ft;class Ut{constructor(t=[[new W(0,0,0),0],[new W(1,1,1),0]],e=[[1,0],[1,1]]){this.table=null,this.tableSignature=null,this.type="function",this.color=new It(t,"Color"),this.alpha=new It(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=Ut.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}clearTable(){this.table=null,this.tableSignature=null}genColor(t,e,i){const s=this.table;if(null!==s){const t=Ut.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=>[Nt.fromJSON(t.function).a,t.start]);return t.functions.length>0&&e.push([Nt.fromJSON(t.functions[t.functions.length-1].function).b,1]),new Ut(e.map(t=>[new W(t[0].x,t[0].y,t[0].z),t[1]]),e.map(t=>[t[0].w,t[1]]))}{const e=new Ut;return e.alpha=It.fromJSON(t.alpha),e.color=It.fromJSON(t.color),e}}clone(){const t=new Ut;return t.alpha=this.alpha.clone(),t.color=this.color.clone(),t}startGen(t){}}Ut.TABLE_SIZE=257;class Dt{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:Bt(this.a),b:Bt(this.b)}}static fromJSON(t){return new Dt(At(t.a),At(t.b))}clone(){return new Dt(this.a.clone(),this.b.clone())}}const Lt=new ft;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(Ut.fromJSON(t.gradient1),Ut.fromJSON(t.gradient2))}clone(){return new Rt(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:Bt(this.color)}}static fromJSON(t){return new Jt(At(t.color))}clone(){return new Jt(this.color.clone())}}function kt(t){switch(t.type){case"ConstantColor":return Jt.fromJSON(t);case"ColorRange":return Nt.fromJSON(t);case"RandomColor":return Dt.fromJSON(t);case"Gradient":return Ut.fromJSON(t);case"RandomColorBetweenGradient":return Rt.fromJSON(t);default:return new Jt(new ft(1,1,1,1))}}class $t{constructor(t,e,i,s){this.angleX=t,this.angleY=e,this.angleZ=i,this.type="rotation",this.eular=new ht(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 $t(Ot(t.angleX),Ot(t.angleY),Ot(t.angleZ),t.eulerOrder)}clone(){return new $t(this.angleX,this.angleY,this.angleZ,this.eular.order)}}class qt{constructor(){this.indexCount=0,this.type="rotation"}startGen(t){let e,i,s,r,n,o;this.indexCount=t.length,t.push(new G);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[this.indexCount].set(e,i,a*r,a*n)}genValue(t,e,i,s){return-1===this.indexCount&&this.startGen(t),e.copy(t[this.indexCount]),e}toJSON(){return{type:"RandomQuat"}}static fromJSON(t){return new qt}clone(){return new qt}}function Qt(t){switch(t.type){case"AxisAngle":return Vt.fromJSON(t);case"Euler":return $t.fromJSON(t);case"RandomQuat":return qt.fromJSON(t);default:return new qt}}class Gt{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 Gt(Ot(t.x),Ot(t.y),Ot(t.z))}clone(){return new Gt(this.x,this.y,this.z)}}function Wt(t){return"Vector3Function"===t.type?Gt.fromJSON(t):new Gt(new zt(0),new zt(0),new zt(0))}function jt(t){switch(t.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Ot(t);case"AxisAngle":case"RandomQuat":case"Euler":return Qt(t);case"Vector3Function":return Wt(t);default:return new zt(0)}}class Yt{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 Yt(new W(t.direction[0],t.direction[1],t.direction[2]),Ot(t.magnitude??t.force))}clone(){return new Yt(this.direction.clone(),this.magnitude.clone())}reset(){}}class Xt{constructor(t=0,e=0,i=new W){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 Xt(t.scaleX,t.scaleY,new W(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 Xt(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 Zt(t){return"TextureSequencer"===t.type?Xt.fromJSON(t):new Xt}class Ht{constructor(t){this.type="ApplySequences",this.sequencers=[],this.time=0,this.index=0,this.pCount=0,this.tempV=new W,this.delay=t}initialize(t){t.id=this.pCount,t.dst=new W,t.begin=new W,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,Ht.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 Ht(t.delay);return t.sequencers.forEach(t=>{e.sequencers.push([Ot(t.range),Zt(t.sequencer)])}),e}clone(){const t=new Ht(this.delay);return t.sequencers=this.sequencers.map(t=>[t[0].clone(),t[1].clone()]),t}}Ht.BEZIER=new _t(0,0,1,1);class Kt{constructor(t){this.angle=t,this.type="ChangeEmitDirection",this._temp=new W,this._q=new G,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 Kt(Ot(t.angle))}clone(){return new Kt(this.angle)}reset(){}}class te{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 te(kt(t.color),Mt.fromJSON(t.speedRange))}clone(){return new te(this.color.clone(),this.speedRange.clone())}reset(){}}class ee{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 ee(kt(t.color))}clone(){return new ee(this.color.clone())}reset(){}}function ie(t,e){return Math.floor(Math.random()*(e-t))+t}const se=new W(0,1,0),re=new W(0,0,0),ne=new W(1,1,1),oe=new W(0,0,1);var ae;!function(t){t[t.Death=0]="Death",t[t.Birth=1]="Birth",t[t.Frame=2]="Frame"}(ae||(ae={}));class he{constructor(t,e,i,s=ae.Frame,r=1){this.particleSystem=t,this.useVelocityAsBasis=e,this.subParticleSystem=i,this.mode=s,this.emitProbability=r,this.type="EmitSubParticleSystem",this.q_=new G,this.v_=new W,this.v2_=new W,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(t){}update(t,e){(this.mode===ae.Frame||this.mode===ae.Birth&&0===t.age||this.mode===ae.Death&&t.age+e>=t.life)&&this.emit(t,e)}emit(t,e){if(!this.subParticleSystem)return;if(Math.random()>this.emitProbability)return;const i=new H;this.setMatrixFromParticle(i,t),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:i,travelDistance:0,particle:t})}frameUpdate(t){if(this.subParticleSystem)for(let e=0;e<this.subEmissions.length;e++)if(this.subEmissions[e].time>=this.subParticleSystem.system.duration)this.subEmissions[e]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,e--;else{const i=this.subEmissions[e];i.particle&&i.particle.age<i.particle.life?this.setMatrixFromParticle(i.matrix,i.particle):i.particle=void 0,this.subParticleSystem.system.emit(t,i,i.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(t,e){return new he(e,t.useVelocityAsBasis,t.subParticleSystem,t.mode,t.emitProbability)}clone(){return new he(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(oe).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 G?i=e.rotation:(this.q_.setFromAxisAngle(oe,e.rotation),i=this.q_),t.compose(e.position,i,ne);this.particleSystem.worldSpace||t.multiplyMatrices(this.particleSystem.emitter.matrixWorld,t)}}class le{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 W,this._tempScale=new W,this._tempQ=new G}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 le(Ot(t.x),Ot(t.y),Ot(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 le(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class ce{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 ce(Ot(t.frame))}clone(){return new ce(this.frame.clone())}reset(){}}class ue{constructor(t,e){this.center=t,this.magnitude=e,this.type="GravityForce",this.temp=new W}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 ue(new W(t.center[0],t.center[1],t.center[2]),t.magnitude)}clone(){return new ue(this.center.clone(),this.magnitude)}reset(){}}class de{constructor(t=new zt(1),e="initial"){this.multiplier=t,this.mode=e,this.type="InheritVelocity",this._temp=new W,this._tempPos=new W,this._tempQInv=new G,this._tempScaleInv=new W(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 de(t.multiplier?Ot(t.multiplier):new zt(1),"current"===t.mode?"current":"initial")}clone(){return new de(this.multiplier.clone(),this.mode)}reset(){}}class pe{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 pe(Ot(t.speed),t.dampen)}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new pe(this.speed.clone(),this.dampen)}reset(){}}const me=.5*(Math.sqrt(3)-1),fe=(3-Math.sqrt(3))/6,ye=1/3,ve=1/6,ge=(Math.sqrt(5)-1)/4,xe=(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)*me,h=Math.floor(t+a),l=Math.floor(e+a),c=(h+l)*fe,u=t-(h-c),d=e-(l-c);let p,m;u>d?(p=1,m=0):(p=0,m=1);const f=u-p+fe,y=d-m+fe,v=u-1+2*fe,g=d-1+2*fe,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*(Se[t]*u+Se[t+1]*d)}let b=.5-f*f-y*y;if(b>=0){const t=3*i[x+p+s[S+m]];b*=b,n=b*b*(Se[t]*f+Se[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*(Se[t]*v+Se[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)*ye,c=Math.floor(t+l),u=Math.floor(e+l),d=Math.floor(i+l),p=(c+u+d)*ve,m=t-(c-p),f=e-(u-p),y=i-(d-p);let v,g,x,S,w,b;m>=f?f>=y?(v=1,g=0,x=0,S=1,w=1,b=0):m>=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):f<y?(v=0,g=0,x=1,S=0,w=1,b=1):m<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=m-v+ve,M=f-g+ve,_=y-x+ve,T=m-S+2*ve,P=f-w+2*ve,O=y-b+2*ve,V=m-1+.5,B=f-1+.5,A=y-1+.5,C=255&c,F=255&u,N=255&d;let I=.6-m*m-f*f-y*y;if(I<0)n=0;else{const t=3*s[C+r[F+r[N]]];I*=I,n=I*I*(Se[t]*m+Se[t+1]*f+Se[t+2]*y)}let E=.6-z*z-M*M-_*_;if(E<0)o=0;else{const t=3*s[C+v+r[F+g+r[N+x]]];E*=E,o=E*E*(Se[t]*z+Se[t+1]*M+Se[t+2]*_)}let U=.6-T*T-P*P-O*O;if(U<0)a=0;else{const t=3*s[C+S+r[F+w+r[N+b]]];U*=U,a=U*U*(Se[t]*T+Se[t+1]*P+Se[t+2]*O)}let D=.6-V*V-B*B-A*A;if(D<0)h=0;else{const t=3*s[C+1+r[F+1+r[N+1]]];D*=D,h=D*D*(Se[t]*V+Se[t+1]*B+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)*ge,u=Math.floor(t+c),d=Math.floor(e+c),p=Math.floor(i+c),m=Math.floor(s+c),f=(u+d+p+m)*xe,y=t-(u-f),v=e-(d-f),g=i-(p-f),x=s-(m-f);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,T=b>=3?1:0,P=z>=3?1:0,O=S>=2?1:0,V=w>=2?1:0,B=b>=2?1:0,A=z>=2?1:0,C=S>=1?1:0,F=w>=1?1:0,N=b>=1?1:0,I=z>=1?1:0,E=y-M+xe,U=v-_+xe,D=g-T+xe,L=x-P+xe,R=y-O+2*xe,J=v-V+2*xe,k=g-B+2*xe,$=x-A+2*xe,q=y-C+3*xe,Q=v-F+3*xe,G=g-N+3*xe,W=x-I+3*xe,j=y-1+4*xe,Y=v-1+4*xe,X=g-1+4*xe,Z=x-1+4*xe,H=255&u,K=255&d,tt=255&p,et=255&m;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*(we[t]*y+we[t+1]*v+we[t+2]*g+we[t+3]*x)}let st=.6-E*E-U*U-D*D-L*L;if(st<0)o=0;else{const t=r[H+M+r[K+_+r[tt+T+r[et+P]]]]%32*4;st*=st,o=st*st*(we[t]*E+we[t+1]*U+we[t+2]*D+we[t+3]*L)}let rt=.6-R*R-J*J-k*k-$*$;if(rt<0)a=0;else{const t=r[H+O+r[K+V+r[tt+B+r[et+A]]]]%32*4;rt*=rt,a=rt*rt*(we[t]*R+we[t+1]*J+we[t+2]*k+we[t+3]*$)}let nt=.6-q*q-Q*Q-G*G-W*W;if(nt<0)h=0;else{const t=r[H+C+r[K+F+r[tt+N+r[et+I]]]]%32*4;nt*=nt,h=nt*nt*(we[t]*q+we[t+1]*Q+we[t+2]*G+we[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*(we[t]*j+we[t+1]*Y+we[t+2]*X+we[t+3]*Z)}return 27*(n+o+a+h+l)}}const ze=100,Me=new Array(ze),_e=new W,Te=new G;function Pe(t){let e=Me[t];return void 0===e&&(e=new be,Me[t]=e),e}class Oe{constructor(t,e,i=new zt(1),s=new zt(0)){this.frequency=t,this.power=e,this.positionAmount=i,this.rotationAmount=s,this.type="Noise",this.duration=0}initialize(t){const e="number"==typeof t.rotation;let i=t._noiseState;if(void 0===i)return i={lastPos:new W,lastRot:0,lastRotQ:e?null:new G,generatorX:Pe(ie(0,ze)),generatorY:Pe(ie(0,ze)),generatorZ:Pe(ie(0,ze)),generatorW:Pe(ie(0,ze))},void(t._noiseState=i);i.lastPos.set(0,0,0),i.lastRot=0,e?i.lastRotQ=null:null===i.lastRotQ?i.lastRotQ=new G:i.lastRotQ.set(0,0,0,1),i.generatorX=Pe(ie(0,ze)),i.generatorY=Pe(ie(0,ze)),i.generatorZ=Pe(ie(0,ze)),i.generatorW=Pe(ie(0,ze))}update(t,e){const i=t._noiseState;if(void 0===i)return;const s=t.memory,r=t.age/t.life,n=this.frequency.genValue(s,r),o=this.power.genValue(s,r),a=this.positionAmount.genValue(s,r),h=this.rotationAmount.genValue(s,r),l=t.age*n;if(a>0){const e=o*a;t.position.sub(i.lastPos),_e.set(i.generatorX.noise2D(0,l)*e,i.generatorY.noise2D(0,l)*e,i.generatorZ.noise2D(0,l)*e),t.position.add(_e),i.lastPos.copy(_e)}if(h>0){const e=o*h;if("number"==typeof t.rotation){const s=i.generatorW.noise2D(0,l)*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,l)*e,i.generatorY.noise2D(0,l)*e,i.generatorZ.noise2D(0,l)*e,i.generatorW.noise2D(0,l)*e).normalize(),s.multiply(Te),i.lastRotQ.copy(Te)}}}updateAll(t,e,i){for(let s=0;s<e;s++){const e=t[s];e.age<e.life&&this.update(e,i)}}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}static fromJSON(t){return new Oe(Ot(t.frequency),Ot(t.power),Ot(t.positionAmount),Ot(t.rotationAmount))}clone(){return new Oe(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Ve{constructor(t,e=new W(0,1,0)){this.orbitSpeed=t,this.axis=e,this.type="OrbitOverLife",this.temp=new W,this.rotation=new G}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 Ve(Ot(t.orbitSpeed),t.axis?new W(t.axis[0],t.axis[1],t.axis[2]):void 0)}clone(){return new Ve(this.orbitSpeed.clone())}reset(){}}class Be{constructor(t){this.angularVelocity=t,this.type="Rotation3DOverLife",this.tempQuat=new G}initialize(t){t.rotation instanceof G&&(t.angularVelocity=new G,this.angularVelocity.startGen(t.memory))}update(t,e){if(t.rotation instanceof G){this.angularVelocity.genValue(t.memory,this.tempQuat,e,t.age/t.life),t.rotation.multiply(this.tempQuat);const i=t.angularVelocity;i instanceof G&&i.copy(this.tempQuat)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new Be(Qt(t.angularVelocity))}frameUpdate(t){}clone(){return new Be(this.angularVelocity.clone())}reset(){}}class Ae{constructor(t,e){this.angularVelocity=t,this.speedRange=e,this.type="RotationBySpeed",this.tempQuat=new G}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(Ot(t.angularVelocity),Mt.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Ae(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Ce{constructor(t){this.angularVelocity=t,this.type="RotationOverLife"}initialize(t){"number"==typeof t.rotation&&this.angularVelocity.startGen(t.memory)}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}}updateAll(t,e,i){const s=this.angularVelocity;for(let r=0;r<e;r++){const e=t[r];if(e.age>=e.life||"number"!=typeof e.rotation)continue;const n=s.genValue(e.memory,e.age/e.life);e.rotation+=i*n,e.angularVelocity=n}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(t){return new Ce(Ot(t.angularVelocity))}frameUpdate(t){this.angularVelocity.refreshTable?.()}clone(){return new Ce(this.angularVelocity.clone())}reset(){}}class Fe{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 Gt?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 Fe(jt(t.size),Mt.fromJSON(t.speedRange))}frameUpdate(t){}clone(){return new Fe(this.size.clone(),this.speedRange.clone())}reset(){}}class Ne{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 Gt}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 Ne(jt(t.size))}frameUpdate(t){this._size.refreshTable?.()}clone(){return new Ne(this.size.clone())}reset(){}}class Ie{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 Ie(Ot(t.speed))}frameUpdate(t){this.speed.refreshTable?.()}clone(){return new Ie(this.speed.clone())}reset(){}}class Ee{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 W,this.temp=new W,this.temp2=new W,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)}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 Ee(new W(t.scale[0],t.scale[1],t.scale[2]),t.octaves,new W(t.velocityMultiplier[0],t.velocityMultiplier[1],t.velocityMultiplier[2]),new W(t.timeScale[0],t.timeScale[1],t.timeScale[2]))}clone(){return new Ee(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const Ue=new W(1,0,0),De=new W(0,1,0),Le=new W(0,0,1);class Re{constructor(t=new zt(0),e=new zt(0),i=new zt(0),s=new zt(0),r=new zt(0),n=new zt(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 W,this._tempEmitterPos=new W,this._tempQ=new G,this._tempQInv=new G,this._tempScale=new W(1,1,1),this._tempScaleInv=new W(1,1,1),this._tempRot=new G,this._axisX=new W(1,0,0),this._axisY=new W(0,1,0),this._axisZ=new W(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(Ue),this._axisY.copy(De),this._axisZ.copy(Le),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?Ot(t):new zt(0);return new Re(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 Re(this.linearX.clone(),this.linearY.clone(),this.linearZ.clone(),this.orbitalX.clone(),this.orbitalY.clone(),this.orbitalZ.clone(),this.space)}reset(){}}class Je{constructor(t=64){this.previousVelocity=Je.EMPTY,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*Je.SCALAR_STRIDE)}ensureCapacity(t){if(t<=this.capacity)return!1;let e=this.capacity;for(;e<t;)e*=2;return this.position=Je.grow(this.position,3*e),this.previousPosition=Je.grow(this.previousPosition,3*e),this.previousSize=Je.grow(this.previousSize,3*e),this.previousVelocity.length>0&&(this.previousVelocity=Je.grow(this.previousVelocity,3*e)),this.previousColor=Je.grow(this.previousColor,4*e),this.velocity=Je.grow(this.velocity,3*e),this.size=Je.grow(this.size,3*e),this.startSize=Je.grow(this.startSize,3*e),this.color=Je.grow(this.color,4*e),this.startColor=Je.grow(this.startColor,4*e),this.scalars=Je.growDouble(this.scalars,e*Je.SCALAR_STRIDE),this.capacity=e,!0}keepPreviousVelocity(){return!(this.previousVelocity.length>=3*this.capacity)&&(this.previousVelocity=new Float32Array(3*this.capacity),!0)}swapRows(t,e){if(t===e)return;const i=3*t,s=3*e;Je.swap3(this.position,i,s),Je.swap3(this.previousPosition,i,s),Je.swap3(this.previousSize,i,s),this.previousVelocity.length>0&&Je.swap3(this.previousVelocity,i,s),Je.swap3(this.velocity,i,s),Je.swap3(this.size,i,s),Je.swap3(this.startSize,i,s);const r=4*t,n=4*e;Je.swap4(this.color,r,n),Je.swap4(this.previousColor,r,n),Je.swap4(this.startColor,r,n),Je.swap3(this.scalars,t*Je.SCALAR_STRIDE,e*Je.SCALAR_STRIDE)}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){Je.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}}Je.EMPTY=new Float32Array(0),Je.SCALAR_STRIDE=3,Je.AGE=0,Je.LIFE=1,Je.SPEED_MODIFIER=2;class ke{constructor(t){this.data=t,this.next=null,this.prev=null}hasPrev(){return null!==this.prev}hasNext(){return null!==this.next}}class $e{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 ke(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 ke(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 ke(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 qe{constructor(){this.position=new W,this.velocity=new W,this.age=0,this.life=1,this.size=new W,this.rotation=0,this.color=new ft(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}}class Qe{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}constructor(t=new Je(1),e=0){this.startSpeed=0,this.rotation=0,this.uvTile=0,this.flip=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*Je.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*Je.SCALAR_STRIDE}get died(){return this.age>=this.life}reset(){this.memory.length=0}}const Ge=new Float32Array(0);class We{constructor(t,e,i){this.position=t,this.size=e,this.color=i}}class je{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}constructor(t=new Je(1),e=0){this.startSpeed=0,this.length=100,this.previous=new $e,this.uvTile=0,this.historyPositions=Ge,this.historySizes=Ge,this.historyColors=Ge,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*Je.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*Je.SCALAR_STRIDE}ensureHistoryCapacity(t){this.historyCapacity!==t&&(this.historyCapacity=t,this.historyPositions=new Float32Array(3*t),this.historySizes=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(){this.ensureHistoryCapacity(Math.max(1,Math.ceil(this.length)));const t=this.historyCapacity;if(this.age>this.life)return void(this.historyCount>0&&this.historyCount--);const e=this.historyHead,i=3*e,s=this.historyPositions;s[i]=this.position.x,s[i+1]=this.position.y,s[i+2]=this.position.z,this.historySizes[e]=this.size.x;const r=4*e,n=this.historyColors;n[r]=this.color.x,n[r+1]=this.color.y,n[r+2]=this.color.z,n[r+3]=this.color.w,this.historyHead=(e+1)%t,this.historyCount<t&&this.historyCount++}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.resetHistory()}}class Ye{initialize(t){this.width.startGen(t.memory)}constructor(t){this.width=t,this.type="WidthOverLength"}update(t){if(!(t instanceof je))return;const e=t.historyCount;if(0===e)return;const i=t.historyCapacity,s=t.historySizes,r=t.memory,n=1/t.length;let o=t.getHistoryIndex(0);for(let t=0;t<e;t++)s[o]=this.width.genValue(r,(e-t)*n),o++,o===i&&(o=0)}frameUpdate(t){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(t){return new Ye(Ot(t.width))}clone(){return new Ye(this.width.clone())}reset(){}}const Xe={ApplyForce:{type:"ApplyForce",constructor:Yt,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Yt.fromJSON},Noise:{type:"Noise",constructor:Oe,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Oe.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Ee,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Ee.fromJSON},GravityForce:{type:"GravityForce",constructor:ue,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:ue.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:ee,params:[["color",["colorFunc"]]],loadJSON:ee.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Ce,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Ce.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Be,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Be.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Ne,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Ne.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:te,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:te.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Ae,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Ae.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Fe,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Fe.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Ie,params:[["speed",["value","valueFunc"]]],loadJSON:Ie.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:ce,params:[["frame",["value","valueFunc"]]],loadJSON:ce.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:le,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:le.fromJSON},VelocityOverLife:{type:"VelocityOverLife",constructor:Re,params:[["linearX",["value","valueFunc"]],["linearY",["value","valueFunc"]],["linearZ",["value","valueFunc"]],["orbitalX",["value","valueFunc"]],["orbitalY",["value","valueFunc"]],["orbitalZ",["value","valueFunc"]],["space",["string"]]],loadJSON:Re.fromJSON},InheritVelocity:{type:"InheritVelocity",constructor:de,params:[["multiplier",["value","valueFunc"]],["mode",["string"]]],loadJSON:de.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Ve,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Ve.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ye,params:[["width",["value","valueFunc"]]],loadJSON:Ye.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:Kt,params:[["angle",["value"]]],loadJSON:Kt.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:he,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:he.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:pe,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:pe.fromJSON},ApplyCollision:{type:"ApplyCollision",constructor:bt,params:[["bounce",["number"]]],loadJSON:bt.fromJSON}};function Ze(t,e){return Xe[t.type]?Xe[t.type].loadJSON(t,e):null}const He={PiecewiseBezier:Pt,Vector3Function:Gt,Quaternion:G};function Ke(t,e){switch(t.type){case"ColorOverLife":return{setup:`const g${e} = behaviors[${e}].color;`,body:`{const c = p.color, sc = p.startColor;\n g${e}.genColor(p.memory, c, t);\n c.x *= sc.x; c.y *= sc.y; c.z *= sc.z; c.w *= sc.w;}`};case"SizeOverLife":return{setup:`const g${e} = behaviors[${e}].size;\n const vec3_${e} = g${e} instanceof deps.Vector3Function;`,body:`if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, t).multiply(p.startSize);\n } else {\n const v = g${e}.genValue(p.memory, t);\n const s = p.size, ss = p.startSize;\n s.x = ss.x * v; s.y = ss.y * v; s.z = ss.z * 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:`{const v = p.velocity; v.x += dx${e}; v.y += dy${e}; v.z += dz${e};}`};case"RotationOverLife":return{setup:`const g${e} = behaviors[${e}].angularVelocity;`,body:`if (typeof p.rotation === 'number') {\n const rate = g${e}.genValue(p.memory, t);\n p.rotation += delta * rate;\n p.angularVelocity = rate;\n }`};case"FrameOverLife":return{setup:`const g${e} = behaviors[${e}].frame;`,body:`p.uvTile = g${e}.type === 'function' ? g${e}.genValue(p.memory, t) : g${e}.genValue(p.memory);`};case"SpeedOverLife":return{setup:`const g${e} = behaviors[${e}].speed;`,body:`p.speedModifier = g${e}.genValue(p.memory, t);`};case"ForceOverLife":return{setup:`const b${e} = behaviors[${e}];\n const gx${e} = b${e}.x, gy${e} = b${e}.y, gz${e} = b${e}.z;\n const tmp${e} = b${e}._temp, scale${e} = b${e}._tempScale, quat${e} = b${e}._tempQ;\n const local${e} = b${e}.ps !== undefined && !b${e}.ps.worldSpace;`,body:`{tmp${e}.set(\n gx${e}.genValue(p.memory, t),\n gy${e}.genValue(p.memory, t),\n gz${e}.genValue(p.memory, t));\n if (local${e}) { tmp${e}.multiply(scale${e}).applyQuaternion(quat${e}); }\n p.velocity.addScaledVector(tmp${e}, delta);}`};case"LimitSpeedOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.speed;\n const dampen${e} = b${e}.dampen * delta * 20;`,body:`{const v = p.velocity;\n const speed = v.length();\n const limit = g${e}.genValue(p.memory, t);\n if (speed > limit) {\n v.multiplyScalar(1 - ((speed - limit) / speed) * dampen${e});\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 pos = p.position;\n const dx = cx${e} - pos.x, dy = cy${e} - pos.y, dz = cz${e} - pos.z;\n const d2 = dx * dx + dy * dy + dz * dz;\n if (d2 > 0) {\n const s = gm${e} / (d2 * Math.sqrt(d2));\n const v = p.velocity;\n v.x += dx * s; v.y += dy * s; v.z += dz * s;\n }}`};case"ColorBySpeed":return{setup:`const b${e} = behaviors[${e}];\n const 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 = (p.startSpeed - lo${e}) / span${e};\n const c = p.color, sc = p.startColor;\n g${e}.genColor(p.memory, c, ts);\n c.x *= sc.x; c.y *= sc.y; c.z *= sc.z; c.w *= sc.w;}`};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;`,body:`{const ts = (p.startSpeed - lo${e}) / span${e};\n if (vec3_${e}) {\n g${e}.genValue(p.memory, p.size, ts).multiply(p.startSize);\n } else {\n const v = g${e}.genValue(p.memory, ts);\n const s = p.size, ss = p.startSize;\n s.x = ss.x * v; s.y = ss.y * v; s.z = ss.z * v;\n }}`};case"RotationBySpeed":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.angularVelocity;\n const lo${e} = b${e}.speedRange.a;\n const span${e} = b${e}.speedRange.b - lo${e};`,body:`if (typeof p.rotation === 'number') {\n const rate = g${e}.genValue(p.memory, (p.startSpeed - lo${e}) / span${e});\n p.rotation += delta * rate;\n p.angularVelocity = rate;\n }`};case"OrbitOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.orbitSpeed;\n const axis${e} = b${e}.axis, tmp${e} = b${e}.temp, rot${e} = b${e}.rotation;`,body:`{const pos = p.position;\n tmp${e}.copy(pos).projectOnVector(axis${e});\n rot${e}.setFromAxisAngle(axis${e}, g${e}.genValue(p.memory, t) * delta);\n pos.sub(tmp${e});\n pos.applyQuaternion(rot${e});\n pos.add(tmp${e});}`};case"Rotation3DOverLife":return{setup:`const b${e} = behaviors[${e}];\n const g${e} = b${e}.angularVelocity;\n const q${e} = b${e}.tempQuat;`,body:`{const r = p.rotation;\n if (r instanceof deps.Quaternion) {\n g${e}.genValue(p.memory, q${e}, delta, t);\n r.multiply(q${e});\n const step = p.angularVelocity;\n if (step instanceof deps.Quaternion) { step.copy(q${e}); }\n }}`};case"VelocityOverLife":return{setup:`const b${e} = behaviors[${e}];\n const lx${e} = b${e}.linearX, ly${e} = b${e}.linearY, lz${e} = b${e}.linearZ;\n const ox${e} = b${e}.orbitalX, oy${e} = b${e}.orbitalY, oz${e} = b${e}.orbitalZ;\n const tmp${e} = b${e}._temp, rot${e} = b${e}._tempRot;\n const ax${e} = b${e}._axisX, ay${e} = b${e}._axisY, az${e} = b${e}._axisZ;\n const pivot${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 const scale${e} = toWorld${e} ? b${e}._tempScale : b${e}._tempScaleInv;\n const quat${e} = toWorld${e} ? b${e}._tempQ : b${e}._tempQInv;`,body:`{const pos = p.position;\n tmp${e}.set(\n lx${e}.genValue(p.memory, t),\n ly${e}.genValue(p.memory, t),\n lz${e}.genValue(p.memory, t));\n if (convert${e}) { tmp${e}.multiply(scale${e}).applyQuaternion(quat${e}); }\n pos.addScaledVector(tmp${e}, delta);\n const rx = ox${e}.genValue(p.memory, t) * delta;\n const ry = oy${e}.genValue(p.memory, t) * delta;\n const rz = oz${e}.genValue(p.memory, t) * delta;\n if (rx !== 0 || ry !== 0 || rz !== 0) {\n if (world${e}) { pos.sub(pivot${e}); }\n if (rx !== 0) { rot${e}.setFromAxisAngle(ax${e}, rx); pos.applyQuaternion(rot${e}); }\n if (ry !== 0) { rot${e}.setFromAxisAngle(ay${e}, ry); pos.applyQuaternion(rot${e}); }\n if (rz !== 0) { rot${e}.setFromAxisAngle(az${e}, rz); pos.applyQuaternion(rot${e}); }\n if (world${e}) { pos.add(pivot${e}); }\n }}`};case"InheritVelocity":return{setup:`const b${e} = behaviors[${e}];\n const ps${e} = b${e}.ps;\n const velocity${e} = b${e}.mode === 'current' && ps${e} !== undefined\n ? ps${e}.emitterVelocity : undefined;\n const tmp${e} = b${e}._temp;\n const local${e} = velocity${e} !== undefined && !ps${e}.worldSpace;\n const scale${e} = b${e}._tempScaleInv, quat${e} = b${e}._tempQInv;\n const gm${e} = b${e}.multiplier;`,body:`if (velocity${e} !== undefined) {\n tmp${e}.copy(velocity${e});\n if (local${e}) { tmp${e}.multiply(scale${e}).applyQuaternion(quat${e}); }\n p.position.addScaledVector(tmp${e}, gm${e}.genValue(p.memory, t) * delta);\n }`};default:return null}}const ti=new Map;function ei(t,e){const i=ti.get(e);if(void 0!==i)return i??void 0;const s=function(t){const e=`\n ${t.map(t=>t.setup).join("\n")}\n for (let i = 0; i < count; i++) {\n const p = particles[i];\n if (p.age >= p.life) continue;\n const t = p.age / p.life;\n ${t.map(t=>t.body).join("\n")}\n }`;try{return new Function("deps",`return function (behaviors, particles, count, delta) {${e}};`)(He)}catch(t){return}}(t);return ti.set(e,s??null),s}function ii(t){const e=[];let i=[],s=[],r=0;const n=()=>{if(0===s.length)return;const t=`${r}:${i.map(t=>t.type).join(",")}`,n=s.length>1?ei(s,t):void 0;if(void 0!==n)e.push({behaviors:i,run:n});else for(const t of i)e.push({behaviors:[t]});i=[],s=[]};for(let o=0;o<t.length;o++){const a=t[o],h=Ke(a,o);null!==h?(0===s.length&&(r=o),i.push(a),s.push(h)):(n(),e.push({behaviors:[a]}))}return n(),e}var si,ri;!function(t){t[t.Volume=0]="Volume",t[t.Shell=1]="Shell",t[t.Edge=2]="Edge"}(si||(si={}));class ni{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??si.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===si.Shell?i[s]=this.onSurface(s):this.emitFrom===si.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 ni({width:t.width,height:t.height,depth:t.depth,emitFrom:t.emitFrom,boxThickness:Array.isArray(t.boxThickness)?t.boxThickness:void 0})}clone(){return new ni({width:this.width,height:this.height,depth:this.depth,emitFrom:this.emitFrom,boxThickness:this.boxThickness})}}function oi(t,e,i,s){let r;switch(ri.Random===t?e=Math.random():ri.Burst===t&&s.isBursting&&(e=s.burstParticleIndex/s.burstParticleCount),r=i>0?Math.floor(e/i)*i:e,t){case ri.Loop:r%=1;break;case ri.PingPong:r=Math.abs(r%2-1)}return r}!function(t){t[t.Random=0]="Random",t[t.Loop=1]="Loop",t[t.PingPong=2]="PingPong",t[t.Burst=3]="Burst"}(ri||(ri={}));class ai{constructor(t,e,i){this.position=t??new W,this.rotation=e??new G,this.scale=i??new W(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 ai(e?new W(e[0],e[1],e[2]):void 0,i?new G(i[0],i[1],i[2],i[3]):void 0,s?new W(s[0],s[1],s[2]):void 0)}static toShapeJSON(t){return t&&!t.isIdentity()?{transform:t.toJSON()}:{}}clone(){return new ai(this.position.clone(),this.rotation.clone(),this.scale.clone())}}class hi{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??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(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=oi(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(),...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new hi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,transform:ai.fromJSON(t.transform),spread:t.spread})}clone(){return new hi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class li{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??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this.transform=t.transform}update(t,e){ri.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=oi(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(),...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new li({radius:t.radius,arc:t.arc,thickness:t.thickness,angle:t.angle,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,transform:ai.fromJSON(t.transform),spread:t.spread})}clone(){return new li({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 ci{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??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this.transform=t.transform,this._m1=new H}update(t,e){ri.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=oi(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.velocity,se),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(),...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new ci({radius:t.radius,arc:t.arc,thickness:t.thickness,donutRadius:t.donutRadius,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,transform:ai.fromJSON(t.transform),spread:t.spread})}clone(){return new ci({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 ui{constructor(t={}){this.type="edge",this.currentValue=0,this.radius=t.radius??1,this.mode=t.mode??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[]}update(t,e){ri.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=oi(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 ui({radius:t.radius,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,spread:t.spread})}clone(){return new ui({radius:this.radius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class di{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,...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new di({...t,transform:ai.fromJSON(t.transform)})}clone(){return new di({width:this.width,height:this.height,column:this.column,row:this.row,transform:this.transform?.clone()})}update(t,e){}}class pi{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??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this.transform=t.transform,this._m1=new H}update(t,e){ri.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=oi(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.position,se),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(),...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new pi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,transform:ai.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 mi{constructor(t){this.type="point",this._m1=new H,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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.velocity,se),t.rotation.setFromRotationMatrix(this._m1))}this.transform?.apply(t)}toJSON(){return{type:"point",...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new mi(ai.fromJSON(t?.transform))}clone(){return new mi(this.transform?.clone())}}class fi{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??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this.transform=t.transform,this._m1=new H}update(t,e){ri.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e)}initialize(t,e){const i=oi(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.position,se),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(),...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new fi({radius:t.radius,arc:t.arc,thickness:t.thickness,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,transform:ai.fromJSON(t.transform),spread:t.spread})}clone(){return new fi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}class yi{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??ri.Random,this.spread=t.spread??0,this.speed=t.speed??new zt(1),this.memory=[],this.transform=t.transform,this._m1=new H}update(t,e){this.currentValue+=this.speed.genValue(this.memory,t.emissionState.time/t.duration)*e}initialize(t,e){const i=oi(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 G){const e=t.rotation;0===e.x&&0===e.y&&0===e.z&&1===e.w&&(this._m1.lookAt(re,t.velocity,se),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(),...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new yi({width:t.width,height:t.height,thickness:t.thickness,mode:t.mode,speed:t.speed?Ot(t.speed):void 0,transform:ai.fromJSON(t.transform),spread:t.spread})}clone(){return new yi({width:this.width,height:this.height,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),transform:this.transform?.clone(),spread:this.spread})}}const vi={box:{type:"box",params:[["width",["number"]],["height",["number"]],["depth",["number"]],["emitFrom",["number"]],["boxThickness",["vec3"]]],constructor:ni,loadJSON:ni.fromJSON},circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:hi,loadJSON:hi.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:li,loadJSON:li.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ci,loadJSON:ci.fromJSON},edge:{type:"edge",params:[["radius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:ui,loadJSON:ui.fromJSON},point:{type:"point",params:[],constructor:mi,loadJSON:mi.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:fi,loadJSON:fi.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:pi,loadJSON:pi.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:di,loadJSON:di.fromJSON},rectangle:{type:"rectangle",params:[["width",["number"]],["height",["number"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc","value"]]],constructor:yi,loadJSON:yi.fromJSON}};function gi(t,e){return vi[t.type].loadJSON(t,e)}const xi=[];function Si(t){if(!xi.find(e=>e.id===t.id)){t.initialize();for(const e of t.emitterShapes)vi[e.type]||(vi[e.type]=e);for(const e of t.behaviors)Xe[e.type]||(Xe[e.type]=e)}}function wi(t){const e=xi.find(e=>e.id===t);if(e){for(const t of e.emitterShapes)vi[t.type]&&delete vi[t.type];for(const t of e.behaviors)Xe[t.type]&&delete Xe[t.type]}}class bi{get mesh(){return this._mesh}set mesh(e){if(this._mesh=e,!e)return;const i=e.getVerticesData(t.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 W,a=new W,h=new W;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 W;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,m=this._positions[3*h+1]-u,f=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+m*n+v*o,d+f*n+g*o);const x=m*g-f*v,S=f*y-p*g,w=p*v-m*y,b=Math.sqrt(x*x+S*S+w*w)||1;t.velocity.set(x/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??"",...ai.toShapeJSON(this.transform)}}static fromJSON(t){return new bi(void 0,t?.mesh,ai.fromJSON(t?.transform))}clone(){return new bi(this._mesh,this._meshReferenceId,this.transform?.clone())}update(t,e){}}const zi={id:"babylon.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["mesh",["mesh"]]],constructor:bi,loadJSON:t=>bi.fromJSON(t)}],behaviors:[]};const Mi={};let _i=!1;function Ti(){_i||(Mi.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",Mi.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",Mi.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",Mi.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",Mi.soft_pars_vertex="\n#ifdef SOFT_PARTICLES\n varying vec4 projPosition;\n varying float linearDepth;\n#endif\n",Mi.soft_vertex="\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n",Mi.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",Mi.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",_i=!0)}function Pi(t){return Mi[t]}function Oi(){return Mi}var Vi="\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="\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",Ai="\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",Ci="\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform vec3 ambientColor;\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// 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 vec3 eyePosition;\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 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\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 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",Ni="\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",Ii="\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",Ei="\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",Ui="\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 Di(t){return t.isWebGPU?m.WGSL:m.GLSL}function Li(t,e,i,s){if(s===m.WGSL)return d.ShadersStoreWGSL[t+"VertexShader"]=e.wgsl,void(d.ShadersStoreWGSL[t+"FragmentShader"]=i.wgsl);p.ShadersStore[t+"VertexShader"]=e.glsl,p.ShadersStore[t+"FragmentShader"]=i.glsl}var Ri;!function(t){t[t.BillBoard=0]="BillBoard",t[t.StretchedBillBoard=1]="StretchedBillBoard",t[t.Mesh=2]="Mesh",t[t.Trail=3]="Trail",t[t.HorizontalBillBoard=4]="HorizontalBillBoard",t[t.VerticalBillBoard=5]="VerticalBillBoard"}(Ri||(Ri={}));class Ji{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},this.mesh=new c("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&&e.setTexture("depthTexture",t)}dispose(){this.mesh.dispose()}}class ki extends Ji{static whiteTexture(t){let e=ki.whiteTextureByScene.get(t);return e||(e=r.CreateRGBATexture(new Uint8Array([255,255,255,255]),1,1,t),e.name="quarksMeshWhite",ki.whiteTextureByScene.set(t,e)),e}constructor(t,e){super(t,e),this.shaderMaterial=null,this.vector_=new W,this.vector2_=new W,this.vector3_=new W,this.quaternion_=new G,this.quaternion2_=new G,this.quaternion3_=new G,this.quaternion4_=new G,this.quaternion5_=new G,this.rotationMat_=new lt,this.rotationMat2_=new lt,this.lastStretchedSpeedFactor=Number.NaN,this.clearedInstanceUploaded=!1,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new c("spriteBatch",this.scene),this.mesh.alwaysSelectAsActiveMesh=!0;const t=new u;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(e,this.offsetBuffer,"offset",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.offsetVB),this.colorBuffer=new Float32Array(4*this.maxParticles),this.colorVB=new t(e,this.colorBuffer,"color",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.colorVB),this.sizeBuffer=new Float32Array(3*this.maxParticles),this.sizeVB=new t(e,this.sizeBuffer,"size",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.sizeVB),this.uvTileBuffer=new Float32Array(this.maxParticles),this.uvTileVB=new t(e,this.uvTileBuffer,"uvTile",!0,!1,1,!0),this.mesh.setVerticesBuffer(this.uvTileVB),this.settings.renderMode===Ri.Mesh?(this.rotationBuffer=new Float32Array(4*this.maxParticles),this.rotationVB=new t(e,this.rotationBuffer,"rotation",!0,!1,4,!0)):(this.rotationBuffer=new Float32Array(this.maxParticles),this.rotationVB=new t(e,this.rotationBuffer,"rotation",!0,!1,1,!0)),this.mesh.setVerticesBuffer(this.rotationVB),this.settings.renderMode===Ri.StretchedBillBoard&&(this.velocityBuffer=new Float32Array(4*this.maxParticles),this.velocityVB=new t(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,h;this.settings.renderMode===Ri.Mesh?(r={glsl:Vi,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"},h={glsl:Ci,wgsl:"\nvarying vUV: vec2f;\nvarying vColor: vec4f;\nvarying vNormal: vec3f;\nvarying vWorldPos: vec3f;\n\nuniform lightDirection: vec3f;\nuniform lightColor: vec3f;\nuniform ambientColor: vec3f;\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 USE_ENVMAP_ATLAS\nvar envAtlasSampler: sampler;\nvar envAtlas: texture_2d<f32>;\nuniform eyePosition: vec3f;\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 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\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 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===Ri.StretchedBillBoard?(r={glsl:Ni,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"},h={glsl:Ai,wgsl:Ui}):(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"},h={glsl:Ai,wgsl:Ui});const l=this.settings.texture??(this.settings.renderMode===Ri.Mesh?ki.whiteTexture(this.scene):null);l&&e.push("USE_MAP");const c=this.settings.reflectionAtlas;if(this.settings.renderMode===Ri.Mesh&&!!c&&!c.isReady()&&c){const t=c.onLoadObservable;t?.addOnce(()=>{this.rebuildMaterial()})}const u=this.settings.renderMode===Ri.Mesh&&!!c&&c.isReady();u&&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===Ri.VerticalBillBoard&&e.push("VERTICAL"),this.settings.renderMode===Ri.HorizontalBillBoard&&e.push("HORIZONTAL");const d=ki.takesPivotAndFlip(this.settings.renderMode)?this.settings.pivot:void 0;d&&e.push("PIVOT");const p=Di(this.scene.getEngine());Li(t,r,h,p);const m=["position","uv","offset","color","size","rotation","uvTile"];this.settings.renderMode===Ri.Mesh&&m.push("normal"),this.settings.renderMode===Ri.StretchedBillBoard&&m.push("velocity");const f=["world","view","projection","worldView","worldViewProjection"],y=[];(this.settings.uTileCount>1||this.settings.vTileCount>1)&&(f.push("tileCountX"),f.push("tileCountY")),l&&y.push("map"),u&&(y.push("envAtlas"),f.push("eyePosition"),f.push("reflectionLevel")),this.settings.renderMode===Ri.StretchedBillBoard&&f.push("speedFactor"),this.settings.softParticles&&(f.push("softParams"),f.push("projParams"),y.push("depthTexture")),this.settings.materialAlphaTest>0&&f.push("alphaTest"),d&&f.push("pivot"),this.settings.renderMode===Ri.Mesh&&(f.push("lightDirection"),f.push("lightColor"),f.push("ambientColor"));const v=new s(t,this.scene,{vertex:t,fragment:t},{attributes:m,uniforms:f,samplers:y,defines:e,needAlphaBlending:this.settings.materialTransparent,shaderLanguage:p});if(l&&v.setTexture("map",l),u&&c){v.setTexture("envAtlas",c),v.setFloat("reflectionLevel",this.settings.reflectionLevel);const t=new n;v.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.copyFrom(e.globalPosition),v.setVector3("eyePosition",t))})}if((this.settings.uTileCount>1||this.settings.vTileCount>1)&&(v.setFloat("tileCountX",this.settings.uTileCount),v.setFloat("tileCountY",this.settings.vTileCount)),this.settings.renderMode===Ri.StretchedBillBoard&&v.setFloat("speedFactor",this.settings.softNearFade>0?this.settings.softNearFade:1),this.settings.softParticles){v.setVector2("softParams",new o(this.settings.softNearFade,1/Math.max(this.settings.softFarFade-this.settings.softNearFade,1e-4)));const t=new a(0,0,0,0);v.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&(t.x=e.minZ,t.y=e.maxZ,v.setVector4("projParams",t))})}this.settings.materialAlphaTest>0&&v.setFloat("alphaTest",this.settings.materialAlphaTest),d&&v.setVector3("pivot",new n(d.x,d.y,d.z)),this.settings.renderMode===Ri.Mesh&&(v.setVector3("lightDirection",new n(.4,-1,.6)),v.setVector3("lightColor",new n(1,1,1)),v.setVector3("ambientColor",new n(.35,.35,.35))),v.backFaceCulling=!1,this.settings.materialTransparent?v.alphaMode=this.settings.materialBlendMode:v.alphaMode=i.ALPHA_DISABLE,v.needDepthPrePass=this.settings.materialDepthWrite,v.forceDepthWrite=this.settings.materialDepthWrite,v.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=v,this.shaderMaterial=v}update(){let t=0,e=0;const i=this.settings.renderMode,s=i===Ri.Mesh,r=i===Ri.StretchedBillBoard,n=ki.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 m=Math.abs(u.x),f=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?ki.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?ki.extrapolate(this.offsetBuffer,3*t,S,a,M):this.offsetBuffer.set(S.position.subarray(0,3*a),3*t),0!==M&&a>0?ki.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?ki.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],T=r[13],P=r[14],O=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+O);s[t]=(n*e+c*i+g*r+z)*a,s[t+1]=(o*e+u*i+x*r+T)*a,s[t+2]=(h*e+d*i+w*r+P)*a}const V=this.sizeBuffer;0!==M?ki.continueVector3(V,e,S.size,S.previousSize,a,M):V.set(S.size.subarray(0,3*a),e);for(let t=e;t<i;t+=3)V[t]*=m,V[t+1]*=f,V[t+2]*=y;_=!0}const T=t;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 G&&(e=this.quaternion4_.copy(e).multiply(ki.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*m,this.sizeBuffer[l+1]=h.y*f,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&&ki.applyFlip(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===Ri.BillBoard||t===Ri.StretchedBillBoard||t===Ri.VerticalBillBoard||t===Ri.HorizontalBillBoard}static applyFlip(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 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()}}ki.whiteTextureByScene=new WeakMap;class $i extends Ji{constructor(t,e){super(t,e),this.drawsNothing=!1,this.vector_=new W,this.vector2_=new W,this.vector3_=new W,this.quaternion_=new G,this.maxParticles=1024,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new c("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),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.PositionKind,this.positionBuffer,!0),this.mesh.setVerticesData(t.UVKind,this.uvBuffer,!0),this.mesh.setVerticesData(t.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(e,this.previousBuffer,"previous",!0,!1,3,!1),this.nextVB=new t(e,this.nextBuffer,"next",!0,!1,3,!1),this.sideVB=new t(e,this.sideBuffer,"side",!0,!1,1,!1),this.widthVB=new t(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(-1e4,-1e4,-1e4),s=new n(1e4,1e4,1e4);if(this.mesh.setBoundingInfo(new f(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=Di(this.scene.getEngine());Li(t,{glsl:Ei,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:Ii,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 n=[];this.settings.texture&&n.push("map");const a=new s(t,this.scene,{vertex:t,fragment:t},{attributes:["position","previous","next","side","width","uv","color"],uniforms:["world","view","projection","worldViewProjection","lineWidth","resolution","sizeAttenuation"],samplers:n,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 o(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.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.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];$i.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,m=1/d,f=r.worldSpace,y=(Math.abs(a.x)+Math.abs(a.y)+Math.abs(a.z))/3,v=r.rendererEmitterSettings,g=Boolean(v.uvFromHead),x=Boolean(v.colorFromParticle),S=f||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=x?s.store.color:s.historyColors,u=4*s.storeIndex,v=s.uvTile%d,w=Math.floor(s.uvTile/d+.001),z=(s.parentMatrix??h).elements,M=z[0],_=z[1],T=z[2],P=z[3],O=z[4],V=z[5],B=z[6],A=z[7],C=z[8],F=z[9],N=z[10],I=z[11],E=z[12],U=z[13],D=z[14],L=z[15],R=1/(0!==b?r:Math.max(1,r-1));let J=s.getHistoryIndex(0),k=J;for(let i=0;i<r;i++,t+=2){const h=i+1<r?J+1===n?0:J+1:J,l=3*J,b=3*k,z=3*h;let $=o[l],q=o[l+1],Q=o[l+2],G=o[b],W=o[b+1],j=o[b+2],Y=o[z],X=o[z+1],Z=o[z+2];const H=a[J],K=x?u:4*J,tt=c[K],et=c[K+1],it=c[K+2],st=c[K+3];if(k=J,J=h,!S){let t=1/(P*$+A*q+I*Q+L),e=(M*$+O*q+C*Q+E)*t,i=(_*$+V*q+F*Q+U)*t;Q=(T*$+B*q+N*Q+D)*t,$=e,q=i,t=1/(P*G+A*W+I*j+L),e=(M*G+O*W+C*j+E)*t,i=(_*G+V*W+F*j+U)*t,j=(T*G+B*W+N*j+D)*t,G=e,W=i,t=1/(P*Y+A*X+I*Z+L),e=(M*Y+O*X+C*Z+E)*t,i=(_*Y+V*X+F*Z+U)*t,Z=(T*Y+B*X+N*Z+D)*t,Y=e,X=i}const rt=3*t;this.positionBuffer[rt]=$,this.positionBuffer[rt+1]=q,this.positionBuffer[rt+2]=Q,this.positionBuffer[rt+3]=$,this.positionBuffer[rt+4]=q,this.positionBuffer[rt+5]=Q,this.previousBuffer[rt]=G,this.previousBuffer[rt+1]=W,this.previousBuffer[rt+2]=j,this.previousBuffer[rt+3]=G,this.previousBuffer[rt+4]=W,this.previousBuffer[rt+5]=j,this.nextBuffer[rt]=Y,this.nextBuffer[rt+1]=X,this.nextBuffer[rt+2]=Z,this.nextBuffer[rt+3]=Y,this.nextBuffer[rt+4]=X,this.nextBuffer[rt+5]=Z,this.sideBuffer[t]=1,this.sideBuffer[t+1]=-1,f||s.parentMatrix?(this.widthBuffer[t]=H,this.widthBuffer[t+1]=H):(this.widthBuffer[t]=H*y,this.widthBuffer[t+1]=H*y);const nt=2*t,ot=i*R,at=((g?1-ot:ot)+v)*p;this.uvBuffer[nt]=at,this.uvBuffer[nt+1]=(d-w-1)*m,this.uvBuffer[nt+2]=at,this.uvBuffer[nt+3]=(d-w)*m;const ht=4*t;this.colorBuffer[ht]=tt,this.colorBuffer[ht+1]=et,this.colorBuffer[ht+2]=it,this.colorBuffer[ht+3]=st,this.colorBuffer[ht+4]=tt,this.colorBuffer[ht+5]=et,this.colorBuffer[ht+6]=it,this.colorBuffer[ht+7]=st,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++)}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(!f){const t=1/(P*n+A*o+I*a+L),e=(M*n+O*o+C*a+E)*t,i=(_*n+V*o+F*a+U)*t;a=(T*n+B*o+N*a+D)*t,n=e,o=i}const x=3*t;this.positionBuffer[x]=n,this.positionBuffer[x+1]=o,this.positionBuffer[x+2]=a,this.positionBuffer[x+3]=n,this.positionBuffer[x+4]=o,this.positionBuffer[x+5]=a,this.previousBuffer[x]=l,this.previousBuffer[x+1]=c,this.previousBuffer[x+2]=u,this.previousBuffer[x+3]=l,this.previousBuffer[x+4]=c,this.previousBuffer[x+5]=u,this.nextBuffer[x]=n,this.nextBuffer[x+1]=o,this.nextBuffer[x+2]=a,this.nextBuffer[x+3]=n,this.nextBuffer[x+4]=o,this.nextBuffer[x+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,this.sideBuffer[t]=1,this.sideBuffer[t+1]=-1;const z=s.size.x;f||s.parentMatrix?(this.widthBuffer[t]=z,this.widthBuffer[t+1]=z):(this.widthBuffer[t]=z*y,this.widthBuffer[t+1]=z*y);const R=2*t,J=((g?0:1)+v)*p;this.uvBuffer[R]=J,this.uvBuffer[R+1]=(d-w-1)*m,this.uvBuffer[R+2]=J,this.uvBuffer[R+3]=(d-w)*m;const k=s.color,$=4*t;this.colorBuffer[$]=k.x,this.colorBuffer[$+1]=k.y,this.colorBuffer[$+2]=k.z,this.colorBuffer[$+3]=k.w,this.colorBuffer[$+4]=k.x,this.colorBuffer[$+5]=k.y,this.colorBuffer[$+6]=k.z,this.colorBuffer[$+7]=k.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){if(e>0&&i>0){this.mesh.updateVerticesData(t.PositionKind,this.positionBuffer.subarray(0,3*e)),this.mesh.updateVerticesData(t.UVKind,this.uvBuffer.subarray(0,2*e)),this.mesh.updateIndices(this.indexBuffer.subarray(0,3*i)),this.previousVB.update(this.previousBuffer.subarray(0,3*e)),this.nextVB.update(this.nextBuffer.subarray(0,3*e)),this.sideVB.update(this.sideBuffer.subarray(0,e)),this.widthVB.update(this.widthBuffer.subarray(0,e));const s=this.mesh.getVertexBuffer(t.ColorKind);s&&s.update(this.colorBuffer.subarray(0,4*e)),this.mesh.subMeshes&&this.mesh.subMeshes.length>0&&(this.adoptMeshBounds(),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),this.mesh.updateIndices(this.indexBuffer.subarray(0,6)),this.adoptMeshBounds(),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 qi extends e{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}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)}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(qi.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 Ri.Trail:s=new $i(i,r);break;case Ri.Mesh:case Ri.BillBoard:case Ri.VerticalBillBoard:case Ri.HorizontalBillBoard:case Ri.StretchedBillBoard:s=new ki(i,r);break;default:throw new Error(`Unsupported render mode: ${i.renderMode}`)}s.mesh.parent=this,this.depthTexture&&s.applyDepthTexture(this.depthTexture),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)}configureAdaptivePerformance(t={}){const e=this.adaptivePerformanceState,i=qi.clamp(t.minQuality??e.minQuality,.05,1),s=qi.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=qi.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=qi.clamp(e.currentQuality-e.decreaseStep,e.minQuality,e.maxQuality):e.currentQuality=qi.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>qi.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()}}qi.EMPTY_BATCH_GRACE_FRAMES=120;const Qi=qi,Gi=new WeakMap,Wi=new WeakMap;function ji(t){if(!t?.isCube)return null;const e=t.files??t._files;return 6===e?.length?e.slice():null}function Yi(t){return Gi.get(t)??null}function Xi(t,e){Gi.set(t,e)}async function Zi(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(r.toDataURL("image/jpeg",.92),e,{noMipmap:!0,invertY:!1,samplingMode:y.LINEAR_LINEAR});return o.name="quarksEnvAtlas",o}const Hi={createFromFaceUrls:Zi};function Ki(t,e,i){const s=Gi.get(t);if(s)return i(s),s;const r=()=>{const s=Wi.get(t);if(s)return void s.then(t=>{t&&i(t)});const r=ji(t);if(!r)return;const n=Hi.createFromFaceUrls(r,e).then(e=>(Gi.set(t,e),Wi.delete(t),i(e),e)).catch(e=>(Wi.delete(t),console.warn("[babylon.quarks] Failed to build env atlas from cubemap faces",e),null));Wi.set(t,n)};if(t.isReady())r();else{const e=t.onLoadObservable;e?e.addOnce(()=>r()):r()}return Gi.get(t)??null}class ts extends g{constructor(t,e,i={}){super(t,e),this.isParticleMeshStandardMaterial=!0,Object.assign(this,i)}}class es extends v{constructor(t,e,i={}){super(t,e),this.isParticleMeshPhysicsMaterial=!0,Object.assign(this,i)}}class is extends e{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 H,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 ss(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 rs=new W(0,0,1),ns=new G,os=new W,as=new W,hs=1/60,ls=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),cs=new Float32Array([0,0,1,0,1,1,0,1]);const us=new Uint32Array([0,1,2,0,2,3]);function ds(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 ps{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(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=ps.nonZeroPivot(t),this.neededToUpdateRender=!0}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===Ri.Trail&&(e=!0),this.rendererSettings.renderMode===Ri.Mesh&&(this.startRotation=new zt(0)),t){case Ri.Trail:this.rendererEmitterSettings={startLength:new zt(30),followLocalOrigin:!1},e=!0;break;case Ri.Mesh:this.rendererEmitterSettings={},this.startRotation=new Vt(new W(0,1,0),new zt(0));break;case Ri.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2};break;case Ri.BillBoard:case Ri.VerticalBillBoard:case Ri.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 Je(64),this.emitterVelocity=new W,this.finishedEventFired=!1,this.startDelayTimeLeft=0,this.tempEmitterPos=new W,this.temp=new W,this.normalMatrix=new lt,this.memory=[],this.listeners={},this.materialRef=null,this.qualityFactor=1,this.simulationAccumulator=0,this.destroyed=!1,this.fusionSteps=[],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 zt(0),this.looping=t.looping??!0,this.prewarm=t.prewarm??!1,this.startLife=t.startLife??new zt(5),this.startSpeed=t.startSpeed??new zt(0),this.startRotation=t.startRotation??new zt(0),this.startSize=t.startSize??new zt(1),this.startColor=t.startColor??new Jt(new ft(1,1,1,1)),this.emissionOverTime=t.emissionOverTime??new zt(10),this.emissionOverDistance=t.emissionOverDistance??new zt(0),this.emissionBursts=t.emissionBursts??[],this.maxParticles=t.maxParticles,this.onlyUsedByOther=t.onlyUsedByOther??!1,this.emitterShape=t.shape??new fi,this.behaviors=t.behaviors??[],this.worldSpace=t.worldSpace??!1,this.rendererEmitterSettings=t.rendererEmitterSettings??{},t.renderMode===Ri.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??ls,instancingIndices:t.instancingIndices??us,instancingUVs:t.instancingUVs??(t.instancingGeometry?(e=t.instancingGeometry,new Float32Array(e.length/3*2)):cs),instancingNormals:t.instancingNormals,renderMode:t.renderMode??Ri.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.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:ps.nonZeroPivot(t.pivot)},this.flip=ps.nonZeroFlip(t.flip),this.rendererSettings.renderMode!==Ri.Mesh||this.rendererSettings.instancingNormals||(this.rendererSettings.instancingNormals=ps.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 zt(0),this.emitter=new is(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=Yi(s),!c&&this.sceneRef&&(Ki(s,this.sceneRef,e=>{this.rendererSettings.reflectionAtlas!==e&&(this.rendererSettings.reflectionAtlas=e,t&&null==t.reflectionAtlas&&(t.reflectionAtlas=e),this.neededToUpdateRender=!0)}),c=Yi(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 je(this.store,e):new Qe(this.store,e))}spawn(t,e,i){const s=os,r=as;i.decompose(s,ns,r);const n=this.behaviors,o=n.length,a=this.rendererSettings.renderMode,h=a===Ri.Trail,l=!h,c=a===Ri.Mesh,u="rotation"===this.startRotation.type,d="vec3function"===this.startSize.type,p=e.time/this.duration,m=h?this.rendererEmitterSettings:void 0,f=Boolean(m?.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 G||(e.rotation=new G),e.angularVelocity instanceof G&&e.angularVelocity.set(0,0,0,1),u?this.startRotation.genValue(t.memory,e.rotation,1,p):e.rotation.setFromAxisAngle(rs,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(m){const e=t;m.startLength.startGen(e.memory),e.length=m.startLength.genValue(e.memory,p),e.ensureHistoryCapacity(Math.max(1,Math.ceil(e.length))),e.resetHistory()}if(this.emitterShape.initialize(t,e),h&&f){const e=t;e.localPosition||(e.localPosition=new W),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 G&&t.rotation.multiplyQuaternions(ns,t.rotation)):this.onlyUsedByOther&&(t.parentMatrix=i);for(let e=0;e<o;e++)n[e].initialize(t,this)}}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.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/hs-1e-9)));return void(this.simulationAccumulator-=e*hs)}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 W)).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/hs-1e-9)));for(let t=0;t<i;t++)this.simulateStep(hs);this.simulationAccumulator-=i*hs}get simulationStep(){return hs}get simulationResidual(){return this.paused?0:this.simulationAccumulator>hs?hs:this.simulationAccumulator<-hs?-hs: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}return this.fusionPlan=t.slice(),this.fusionSteps=ii(t),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===Ri.Trail,n=this.rendererSettings.renderMode===Ri.StretchedBillBoard,o=this.store,a=3*s;o.previousPosition.set(o.position.subarray(0,a)),o.previousSize.set(o.size.subarray(0,a)),n&&(o.keepPreviousVelocity()&&this.rebindParticles(),o.previousVelocity.set(o.velocity.subarray(0,a))),o.previousColor.set(o.color.subarray(0,4*s)),this.emitterShape.update(this,t);const h=this.behaviorSteps();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);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)}if(s>0){const t=o.previousSize,e=o.size,i=o.previousColor,r=o.color,n=o.scalars,a=Je.SCALAR_STRIDE;for(let o=0,h=0,l=0,c=0;o<s;o++,h+=3,l+=4,c+=a)0===n[c+Je.AGE]&&(t[h]=e[h],t[h+1]=e[h+1],t[h+2]=e[h+2],i[l]=r[l],i[l+1]=r[l+1],i[l+2]=r[l+2],i[l+3]=r[l+3])}if(r&&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=this.store.position,i=this.store.velocity,r=this.store.scalars,n=Je.SCALAR_STRIDE;for(let o=0,a=0,h=0;o<s;o++,a+=3,h+=n){const s=t*r[h+Je.SPEED_MODIFIER];e[a]+=i[a]*s,e[a+1]+=i[a+1]*s,e[a+2]+=i[a+2]*s,r[h+Je.AGE]+=t}}if(r){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;os.set(e[t],e[t+1],e[t+2]),os.applyMatrix4(s.parentMatrix??n),e[t]=os.x,e[t+1]=os.y,e[t+2]=os.z}}}const l=this.hasListeners("particleDied"),c=this.store,u=c.scalars,d=Je.SCALAR_STRIDE;let p=this.particleNum;for(let t=0;t<p;t++){const i=e[t],s=t*d;if(u[s+Je.AGE]>=u[s+Je.LIFE]&&(!r||0===i.historyCount)){const s=p-1,r=e[s];e[t]=r,e[s]=i,t!==s&&(c.swapRows(t,s),r.setStoreIndex(t),i.setStoreIndex(s)),p--,t--,l&&this.fire({type:"particleDied",particleSystem:this,particle:i})}}this.particleNum=p,this.notifyFinished()}notifyFinished(){this.isFinished()&&(this.finishedEventFired||(this.finishedEventFired=!0,this.fire({type:"finished",particleSystem:this})),this.autoDestroy&&(this.markForDestroy=!0,this.dispose()))}emit(t,e,i){if(e.time>this.duration)if(this.looping){e.time-=this.duration,e.burstIndex=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,r=s.length,n=this.qualityFactor;for(;e.burstIndex<r&&s[e.burstIndex].time<=e.time;){const t=s[e.burstIndex];if(Math.random()<t.probability){const s=t.count.genValue(this.memory,this.time),r=n>=.999?s:Math.floor(s*n);e.isBursting=!0,e.burstParticleCount=r,this.spawn(r,e,i),e.isBursting=!1}e.burstIndex++}if(!this.emitEnded){const s=e.time/this.duration;e.waitEmiting+=t*this.emissionOverTime.genValue(this.memory,s)*n;const r=e.previousWorldPos;if(void 0!==r){this.temp.set(i.elements[12],i.elements[13],i.elements[14]),e.travelDistance+=r.distanceTo(this.temp);const t=this.emissionOverDistance.genValue(this.memory,s)*n;if(e.travelDistance*t>0){const i=Math.floor(e.travelDistance*t);e.travelDistance-=i/t,e.waitEmiting+=i}}}const o=Math.floor(e.waitEmiting);o>0&&(this.spawn(o,e,i),e.waitEmiting-=o),void 0===e.previousWorldPos&&(e.previousWorldPos=new W),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=gi(t.shape,e);let o;if(t.renderMode===Ri.Trail){const e=t.rendererEmitterSettings;o={startLength:void 0!==e?.startLength?Ot(e.startLength):new zt(30),followLocalOrigin:e?.followLocalOrigin??!1,...ds(e)}}else t.renderMode===Ri.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=ps.resolveGeometryData(c),d=new ps({scene:r,autoDestroy:t.autoDestroy,looping:t.looping,prewarm:t.prewarm,duration:t.duration,startDelay:t.startDelay?Ot(t.startDelay):void 0,shape:n,startLife:Ot(t.startLife),startSpeed:Ot(t.startSpeed),startRotation:jt(t.startRotation),startSize:jt(t.startSize),startColor:kt(t.startColor),emissionOverTime:Ot(t.emissionOverTime),emissionOverDistance:Ot(t.emissionOverDistance),emissionBursts:t.emissionBursts?.map(t=>({time:t.time,count:"number"==typeof t.count?new zt(t.count):Ot(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.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 zt(t.startTileIndex):Ot(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 W(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});return d.behaviors=(t.behaviors??[]).map(t=>{const e=Ze(t,d);return e&&"EmitSubParticleSystem"===e.type&&(s[t.subParticleSystem]=e),e}).filter(t=>null!==t),d}static nextSerializationId(t){return ps.serializationCounter+=1,`${t}_${ps.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===Ri.Trail?{startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin,...ds(this.rendererEmitterSettings)}:this.renderMode===Ri.StretchedBillBoard?{speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:{}}ensureGeometryMeta(t){const e=ps.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=ps.nextSerializationId("quarks_texture"),t.textures[i]=e);const s=this.rendererSettings.reflectionAtlas;let r;s instanceof y&&(r=ps.nextSerializationId("quarks_texture"),t.textures[r]=s);const n=ps.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,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:ss(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:ss(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:ls,indices:us,uvs:cs}}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===Ri.Trail?{startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin,...ds(this.rendererEmitterSettings)}:this.renderMode===Ri.StretchedBillBoard?{lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:{},new ps({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,scene:this.emitter.getScene()})}}ps.serializationCounter=0;class ms extends e{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 is?t.target.system.pause():t.clip?.pause?.()}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(t=>{"ps"===t.type&&t.target instanceof is?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 is)return void t.target.system.restart();"ps"===t.type&&t.target instanceof is?t.target.system.endEmit():t.loop?t.clip?.play?.():t.clip?.stop?.()}}else"ps"===t.type&&t.target instanceof is?(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 is?i.target.system.endEmit():i.clip?.stop?.():"ps"===i.type&&i.target instanceof is?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&&s(t)};s(t),this._tempAnimationJSON.forEach(t=>{const e=i[t.targetUUID];if("ps"===t.type&&e instanceof is)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 ms(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 fs=new WeakMap,ys=new WeakMap;function vs(t,e){let i=t.get(e);return void 0===i&&(i=new Map,t.set(e,i)),i}class gs{constructor(t,e={}){this.scene=t,this.options=e}async load(t){const e=this.options.baseUrl||t.substring(0,t.lastIndexOf("/")+1),i=await fetch(t),s=await i.json();return await gs.resolveExternalGeometries(s,async t=>{const i=await fetch(gs.resolveUrl(e,t));if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}),this.parse(s,e)}static async resolveExternalGeometries(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"])void 0!==i?.[e]&&(t[e]=i[e]);delete t.url}catch(e){console.warn(`[QuarksLoader] Could not load geometry "${t.url}":`,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() or QuarksLoader.resolveExternalGeometries() 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=vs(ys,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){fs.delete(t),ys.delete(t)}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=[],m=t/s,f=o+m*a;for(let t=0;t<=i;t++){const s=t/i,o=r+s*n,a=-e*Math.cos(o)*Math.sin(f),d=e*Math.cos(f),y=e*Math.sin(o)*Math.sin(f);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-m),u.push(p++)}d.push(u)}const m=o<=0,f=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&&m||u.push(i,r,o),t===s-1&&f||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=ss(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)}parseImages(t,e,i){this._images={};for(const i of t)i.url&&gs.warnIfNotAnImageUrl(i.url),this._images[i.uuid]=i.url?gs.resolveUrl(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.`)}static resolveUrl(t,e){return/^(data|blob):/i.test(e)||/^[a-z][a-z0-9+.-]*:\/\//i.test(e)||e.startsWith("/")?e:t+e}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?vs(fs,this.scene):void 0,h=a?.get(o);if(void 0!==h){e.textures[s.uuid]=h;continue}const l=new y(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.CLAMP_ADDRESSMODE;case 1002:return y.MIRROR_ADDRESSMODE;default:return y.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),"number"==typeof s.alphaMode)t.alphaMode=s.alphaMode;else{const e={1:i.ALPHA_COMBINE,2:i.ALPHA_ADD,3:i.ALPHA_SUBTRACT,4:i.ALPHA_MULTIPLY};t.alphaMode=e[s.blending]||i.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(i||t||"node",this.scene);return s.quarksOriginalType=t,s}createMeshNode(t,e){const s=new c(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 u;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 g(`quarks_loader_material_${n.uuid}`,this.scene);t.alphaMode=n.alphaMode??i.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=ms.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(t.name||t.type||"node",this.scene)}if(t.uuid&&(s._quarksUUID=t.uuid),t.name&&(s.name=t.name),t.matrix){const e=h.FromArray(t.matrix),i=new n(1,1,1),r=l.Identity(),o=new n(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 l(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=ps.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&&s(i)};s(t);const r=s=>{if(s instanceof ms&&s.resolveReferences(t),s instanceof is){const t=s.system,e=t._meshSurfaceReferenceUUID;if(e&&"mesh_surface"===t.emitterShape.type){const s=i[e];s instanceof c&&(t.emitterShape.mesh=s)}for(let e=0;e<t.behaviors.length;e++)if(t.behaviors[e]instanceof he){const s=t.behaviors[e],r=s.subParticleSystem;if("string"==typeof r&&i[r]){const t=i[r];s.subParticleSystem=t,t instanceof is&&(t.system.onlyUsedByOther=!0)}}}for(const t of s.getChildren())t instanceof e&&r(t)};r(t)}}class xs{static runOnAllParticleEmitters(t,e){xs.traverseNode(t,t=>{t instanceof is&&e(t)})}static addToBatchRenderer(t,e){xs.runOnAllParticleEmitters(t,t=>{e.addSystem(t.system)})}static play(t){xs.runOnAllParticleEmitters(t,t=>{t.system.play()})}static stop(t){xs.runOnAllParticleEmitters(t,t=>{t.system.stop()})}static pause(t){xs.runOnAllParticleEmitters(t,t=>{t.system.pause()})}static restart(t){xs.runOnAllParticleEmitters(t,t=>{t.system.restart()})}static setAutoDestroy(t,e){xs.runOnAllParticleEmitters(t,t=>{t.system.autoDestroy=e})}static endEmit(t){xs.runOnAllParticleEmitters(t,t=>{t.system.endEmit()})}static isEffectFinished(t){let e=!1,i=!0;return xs.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)xs.traverseNode(t,e)}}Ti(),Si(zi);export{bt as ApplyCollision,Yt as ApplyForce,Ht as ApplySequences,Vt as AxisAngleGenerator,Qi as BatchedParticleRenderer,qi as BatchedRenderer,Ze as BehaviorFromJSON,Xe as BehaviorTypes,_t as Bezier,si as BoxEmitFrom,ni as BoxEmitter,Kt as ChangeEmitDirection,hi as CircleEmitter,te as ColorBySpeed,kt as ColorGeneratorFromJSON,ee as ColorOverLife,Nt as ColorRange,li as ConeEmitter,Jt as ConstantColor,zt as ConstantValue,w as DEG2RAD,ci as DonutEmitter,ui as EdgeEmitter,he as EmitSubParticleSystem,gi as EmitterFromJSON,ri as EmitterMode,vi as EmitterShapes,ht as Euler,$t as EulerGenerator,le as ForceOverLife,ce as FrameOverLife,jt as GeneratorFromJSON,Ut as Gradient,ue as GravityForce,di as GridEmitter,pi as HemisphereEmitter,de as InheritVelocity,Mt as IntervalValue,pe as LimitSpeedOverLife,Q as MathUtils,lt as Matrix3,H as Matrix4,bi as MeshSurfaceEmitter,zi as MeshSurfaceEmitterPlugin,qe as NodeParticle,Oe as Noise,Ve as OrbitOverLife,is as ParticleEmitter,es as ParticleMeshPhysicsMaterial,ts as ParticleMeshStandardMaterial,Je as ParticleStore,ps as ParticleSystem,Pt as PiecewiseBezier,Tt as PiecewiseFunction,xi as Plugins,mi as PointEmitter,gs as QuarksLoader,ms as QuarksPrefab,xs as QuarksUtil,G as Quaternion,b as RAD2DEG,Dt as RandomColor,Rt as RandomColorBetweenGradient,qt as RandomQuatGenerator,We as RecordState,yi as RectangleEmitter,Ri as RenderMode,Be as Rotation3DOverLife,Ae as RotationBySpeed,Qt as RotationGeneratorFromJSON,Ce as RotationOverLife,Zt as SequencerFromJSON,ai as ShapeTransform,Fe as SizeBySpeed,Ne as SizeOverLife,Ie as SpeedOverLife,fi as SphereEmitter,ki as SpriteBatch,Qe as SpriteParticle,ae as SubParticleEmitMode,Xt as TextureSequencer,$i as TrailBatch,je as TrailParticle,Ee as TurbulenceField,Ji as VFXBatch,Ot as ValueGeneratorFromJSON,ut as Vector2,W as Vector3,Gt as Vector3Function,Wt as Vector3GeneratorFromJSON,pt as Vector3View,ft as Vector4,vt as Vector4View,Re as VelocityOverLife,X as WebGLCoordinateSystem,Z as WebGPUCoordinateSystem,Ye as WidthOverLength,Xi as cacheEnvAtlas,R as ceilPowerOfTwo,M as clamp,Zi as createEnvAtlasFromFaceUrls,ji as cubeFaceUrls,V as damp,U as degToRad,$ as denormalize,Ki as ensureEnvAtlasFromCube,_ as euclideanModulo,J as floorPowerOfTwo,z as generateUUID,Yi as getCachedEnvAtlas,wt as getPhysicsResolver,Oi as getRegisteredShaderChunks,Pi as getShaderChunk,oi as getValueFromEmitterMode,P as inverseLerp,L as isPowerOfTwo,O as lerp,Si as loadPlugin,Vi as localParticlePhysicsVertShader,Bi as localParticleVertShader,T as mapLinear,q as normalize,Ai as particleFragShader,Ci as particlePhysicsFragShader,Fi as particleVertShader,B as pingpong,ii as planBehaviorFusion,D as radToDeg,N as randFloat,I as randFloatSpread,F as randInt,Ti as registerShaderChunks,E as seededRandom,St as setPhysicsResolver,k as setQuaternionFromProperEuler,C as smootherstep,A as smoothstep,Ni as stretchedBillboardVertShader,Ii as trailFragShader,Ei as trailVertShader,wi as unloadPlugin};
2
2
  //# sourceMappingURL=babylon.quarks.esm.js.map