hz-particles 1.5.4 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/hz-particles.cjs +5 -5
- package/dist-lib/hz-particles.mjs +77 -75
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class Ji{constructor(t={}){this.config=t,this._posOut=[0,0,0],this._rotMatrix=null,this._invRotMatrix=null,this._cachedRotX=void 0,this._cachedRotY=void 0,this._cachedRotZ=void 0}_updateRotationMatrix(){const t=this.config.emissionRotationX||0,e=this.config.emissionRotationY||0,i=this.config.emissionRotationZ||0;if(t===this._cachedRotX&&e===this._cachedRotY&&i===this._cachedRotZ)return;this._cachedRotX=t,this._cachedRotY=e,this._cachedRotZ=i;const r=t*Math.PI/180,n=e*Math.PI/180,a=i*Math.PI/180,o=Math.cos(r),l=Math.sin(r),c=Math.cos(n),d=Math.sin(n),S=Math.cos(a),b=Math.sin(a);this._rotMatrix=[c*S,l*d*S-o*b,o*d*S+l*b,c*b,l*d*b+o*S,o*d*b-l*S,-d,l*c,o*c],this._invRotMatrix=[this._rotMatrix[0],this._rotMatrix[3],this._rotMatrix[6],this._rotMatrix[1],this._rotMatrix[4],this._rotMatrix[7],this._rotMatrix[2],this._rotMatrix[5],this._rotMatrix[8]]}emitParticle(t,e,i){const r=this._posOut;if(this.config.emissionShape==="cube"||this.config.emissionShape==="box"?this._emitFromCube(r):this.config.emissionShape==="sphere"?this._emitFromSphere(r):this.config.emissionShape==="square"?this._emitFromSquare(r):this.config.emissionShape==="circle"?this._emitFromCircle(r):this.config.emissionShape==="cylinder"?this._emitFromCylinder(r):this.config.emissionShape==="plain"?this._emitFromPlain(r):this.config.emissionShape==="cone"?this._emitFromCone(r):this.config.emissionShape==="torus"?this._emitFromTorus(r):this.config.emissionShape==="line"?this._emitFromLine(r):this.config.emissionShape==="hemisphere"?this._emitFromHemisphere(r):this.config.emissionShape==="disc"?this._emitFromDisc(r):this.config.emissionShape==="annulus"?this._emitFromAnnulus(r):this.config.emissionShape==="capsule"?this._emitFromCapsule(r):this.config.emissionShape==="arc"?this._emitFromArc(r):this.config.emissionShape==="spiral"?this._emitFromSpiral(r):this.config.emissionShape==="frustum"?this._emitFromFrustum(r):this.config.emissionShape==="frustumSurface"?this._emitFromFrustumSurface(r):this.config.emissionShape==="cubeSurface"?this._emitFromCubeSurface(r):this.config.emissionShape==="sphereSurface"?this._emitFromSphereSurface(r):this.config.emissionShape==="boxFrame"?this._emitFromBoxFrame(r):this.config.emissionShape==="polygon"?this._emitFromPolygon(r):this.config.emissionShape==="rectangle"?this._emitFromRectangle(r):(r[0]=0,r[1]=0,r[2]=0),this.config.emissionRotationX||this.config.emissionRotationY||this.config.emissionRotationZ){this._updateRotationMatrix();const o=this._rotMatrix,l=r[0],c=r[1],d=r[2];r[0]=o[0]*l+o[1]*c+o[2]*d,r[1]=o[3]*l+o[4]*c+o[5]*d,r[2]=o[6]*l+o[7]*c+o[8]*d}(this.config.emissionPositionX||this.config.emissionPositionY||this.config.emissionPositionZ)&&(r[0]+=this.config.emissionPositionX||0,r[1]+=this.config.emissionPositionY||0,r[2]+=this.config.emissionPositionZ||0);const n=e*8;t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2];const a=e*4;this.calculateVelocity(r[0],r[1],r[2],i,a),this.setParticleColor(t,n),this.setParticleLifetime(t,n)}applyRotation(t,e,i){this._updateRotationMatrix();const r=this._rotMatrix;return[r[0]*t+r[1]*e+r[2]*i,r[3]*t+r[4]*e+r[5]*i,r[6]*t+r[7]*e+r[8]*i]}inverseRotation(t,e,i){this._updateRotationMatrix();const r=this._invRotMatrix;return[r[0]*t+r[1]*e+r[2]*i,r[3]*t+r[4]*e+r[5]*i,r[6]*t+r[7]*e+r[8]*i]}_emitFromCube(t){let e=this.config.innerLength||0,i=this.config.outerLength||this.config.cubeLength;if(e>0){const r=Math.floor(Math.random()*6),n=Math.random()-.5,a=Math.random()-.5;let o,l,c;switch(r){case 0:o=n,l=a,c=.5;break;case 1:o=n,l=a,c=-.5;break;case 2:o=.5,l=n,c=a;break;case 3:o=-.5,l=n,c=a;break;case 4:o=n,l=.5,c=a;break;case 5:o=n,l=-.5,c=a;break}const d=Math.random(),S=e+d*(i-e);t[0]=o*S,t[1]=l*S,t[2]=c*S}else t[0]=(Math.random()-.5)*i,t[1]=(Math.random()-.5)*i,t[2]=(Math.random()-.5)*i}_emitFromSphere(t){const e=Math.random()*2*Math.PI,i=Math.acos(2*Math.random()-1),r=Math.sin(i)*Math.cos(e),n=Math.sin(i)*Math.sin(e),a=Math.cos(i);let o;this.config.innerRadius===0?o=this.config.outerRadius*Math.cbrt(Math.random()):o=this.config.innerRadius+(this.config.outerRadius-this.config.innerRadius)*Math.random(),t[0]=r*o,t[1]=n*o,t[2]=a*o}_emitFromSquare(t){const e=this.config.squareInnerSize||0,i=this.config.squareSize||2;if(e>0){const r=Math.floor(Math.random()*4);let n=e+(i-e)*Math.random();switch(r){case 0:t[0]=(Math.random()*2-1)*n,t[1]=n;break;case 1:t[0]=n,t[1]=(Math.random()*2-1)*n;break;case 2:t[0]=(Math.random()*2-1)*n,t[1]=-n;break;case 3:t[0]=-n,t[1]=(Math.random()*2-1)*n;break}}else t[0]=(Math.random()*2-1)*i,t[1]=(Math.random()*2-1)*i;t[2]=0}_emitFromCircle(t){const e=this.config.circleInnerRadius||0,i=this.config.circleOuterRadius||2,r=Math.random()*Math.PI*2;let n;e>0?n=e+(i-e)*Math.random():n=i*Math.sqrt(Math.random()),t[0]=Math.cos(r)*n,t[1]=Math.sin(r)*n,t[2]=0}_emitFromPlain(t){const e=this.config.planeWidth||2,i=this.config.planeDepth||2;t[0]=(Math.random()-.5)*e,t[1]=0,t[2]=(Math.random()-.5)*i}_emitFromCone(t){const e=this.config.coneInnerRadius||0,i=this.config.coneOuterRadius||2,r=this.config.coneHeight||4,n=Math.random()*Math.PI*2,a=Math.random(),o=a*r,l=i*(1-a);let c;if(e>0){const d=e*(1-a);c=d+(l-d)*Math.random()}else c=l*Math.sqrt(Math.random());t[0]=Math.cos(n)*c,t[1]=o,t[2]=Math.sin(n)*c}_emitFromTorus(t){const e=this.config.torusMajorRadius||2,i=this.config.torusMinorRadius||.5,r=Math.random()*Math.PI*2,n=Math.random()*Math.PI*2,a=i*Math.sqrt(Math.random());t[0]=(e+a*Math.cos(n))*Math.cos(r),t[1]=a*Math.sin(n),t[2]=(e+a*Math.cos(n))*Math.sin(r)}_emitFromLine(t){const e=this.config.lineLength||4,i=Math.random();t[0]=0,t[1]=(i-.5)*e,t[2]=0}_emitFromHemisphere(t){const e=this.config.hemisphereInnerRadius||0,i=this.config.hemisphereOuterRadius||2,r=Math.random()*Math.PI*2,n=Math.acos(Math.random()),a=Math.sin(n)*Math.cos(r),o=Math.cos(n),l=Math.sin(n)*Math.sin(r);let c;e>0?c=e+(i-e)*Math.random():c=i*Math.cbrt(Math.random()),t[0]=a*c,t[1]=o*c,t[2]=l*c}_emitFromDisc(t){const e=this.config.discRadius||2,i=Math.random()*Math.PI*2,r=e*Math.sqrt(Math.random());t[0]=Math.cos(i)*r,t[1]=0,t[2]=Math.sin(i)*r}_emitFromAnnulus(t){const e=this.config.annulusInnerRadius||1,i=this.config.annulusOuterRadius||2,r=Math.random()*Math.PI*2,n=e+(i-e)*Math.random();t[0]=Math.cos(r)*n,t[1]=0,t[2]=Math.sin(r)*n}_emitFromCapsule(t){const e=this.config.capsuleRadius||.5,i=this.config.capsuleHeight||4,r=i*.5,n=Math.PI*e*e*i,a=4/3*Math.PI*e*e*e,o=n/(n+a);if(Math.random()<o){const l=Math.random()*Math.PI*2,c=e*Math.sqrt(Math.random());t[0]=Math.cos(l)*c,t[1]=(Math.random()-.5)*i,t[2]=Math.sin(l)*c}else{const l=Math.random()*Math.PI*2,c=Math.acos(2*Math.random()-1),d=e*Math.cbrt(Math.random());t[0]=d*Math.sin(c)*Math.cos(l),t[1]=d*Math.cos(c),t[2]=d*Math.sin(c)*Math.sin(l),t[1]+=t[1]>=0?r:-r}}_emitFromArc(t){const e=this.config.arcStartAngle||0,i=this.config.arcEndAngle||180,r=this.config.arcInnerRadius||0,n=this.config.arcOuterRadius||2,a=e*Math.PI/180,o=i*Math.PI/180,l=a+Math.random()*(o-a);let c;r>0?c=r+(n-r)*Math.random():c=n*Math.sqrt(Math.random()),t[0]=Math.cos(l)*c,t[1]=Math.sin(l)*c,t[2]=0}_emitFromSpiral(t){const e=this.config.spiralTurns||3,i=this.config.spiralRadiusStart||.5,r=this.config.spiralRadiusEnd||2,n=this.config.spiralHeight||4,a=Math.random(),o=a*e*Math.PI*2,l=i+(r-i)*a;t[0]=Math.cos(o)*l,t[1]=(a-.5)*n,t[2]=Math.sin(o)*l}_emitFromFrustum(t){const e=this.config.frustumRadiusNear||.5,i=this.config.frustumRadiusFar||2,r=this.config.frustumHeight||4,n=Math.random()*Math.PI*2,a=Math.random(),o=a*r,c=(e+(i-e)*a)*Math.sqrt(Math.random());t[0]=Math.cos(n)*c,t[1]=o,t[2]=Math.sin(n)*c}_emitFromFrustumSurface(t){const e=this.config.frustumRadiusNear??.5,i=this.config.frustumRadiusFar??2,r=this.config.frustumHeight??4,n=Math.random()*Math.PI*2,a=i-e,o=e+a*.5;let l;if(Math.abs(a)<1e-6||o<=1e-6)l=Math.random();else{const S=Math.random(),b=.5*a,f=e,v=-S*o,C=Math.max(0,f*f-4*b*v);l=(-f+Math.sqrt(C))/(2*b),Number.isFinite(l)||(l=Math.random()),l=Math.min(1,Math.max(0,l))}const c=l*r,d=e+a*l;t[0]=Math.cos(n)*d,t[1]=c,t[2]=Math.sin(n)*d}_emitFromCubeSurface(t){const e=this.config.cubeSurfaceSize||2,i=e*.5,r=Math.floor(Math.random()*6),n=(Math.random()-.5)*e,a=(Math.random()-.5)*e;switch(r){case 0:t[0]=n,t[1]=a,t[2]=i;break;case 1:t[0]=n,t[1]=a,t[2]=-i;break;case 2:t[0]=i,t[1]=n,t[2]=a;break;case 3:t[0]=-i,t[1]=n,t[2]=a;break;case 4:t[0]=n,t[1]=i,t[2]=a;break;case 5:t[0]=n,t[1]=-i,t[2]=a;break}}_emitFromSphereSurface(t){const e=this.config.sphereSurfaceRadius||2,i=Math.random()*Math.PI*2,r=Math.acos(2*Math.random()-1);t[0]=e*Math.sin(r)*Math.cos(i),t[1]=e*Math.sin(r)*Math.sin(i),t[2]=e*Math.cos(r)}_emitFromBoxFrame(t){const e=this.config.boxFrameSize||2,i=e*.5,r=Math.floor(Math.random()*12),a=(Math.random()-.5)*e,o=[[-1,-1],[-1,1],[1,-1],[1,1]];if(r<4){const[l,c]=o[r];t[0]=a,t[1]=l*i,t[2]=c*i}else if(r<8){const[l,c]=o[r-4];t[0]=l*i,t[1]=a,t[2]=c*i}else{const[l,c]=o[r-8];t[0]=l*i,t[1]=c*i,t[2]=a}}_emitFromPolygon(t){const e=Math.max(3,Math.floor(this.config.polygonSides||6)),i=this.config.polygonRadius||2,r=Math.floor(Math.random()*e),n=r/e*Math.PI*2,a=(r+1)/e*Math.PI*2;let o=Math.random(),l=Math.random();o+l>1&&(o=1-o,l=1-l);const c=o*Math.cos(n)+l*Math.cos(a),d=o*Math.sin(n)+l*Math.sin(a);t[0]=c*i,t[1]=d*i,t[2]=0}_emitFromRectangle(t){const e=this.config.rectangleWidth||2,i=this.config.rectangleHeight||2;t[0]=(Math.random()-.5)*e,t[1]=(Math.random()-.5)*i,t[2]=0}_emitFromCylinder(t){const e=this.config.cylinderInnerRadius||0,i=this.config.cylinderOuterRadius||2,r=this.config.cylinderHeight||4,n=Math.random()*Math.PI*2;let a;e>0?a=e+(i-e)*Math.random():a=i*Math.sqrt(Math.random()),t[0]=Math.cos(n)*a,t[1]=(Math.random()-.5)*r,t[2]=Math.sin(n)*a}calculateVelocity(t,e,i,r,n){const a=this.config.emissionPositionX||0,o=this.config.emissionPositionY||0,l=this.config.emissionPositionZ||0,c=t-a,d=e-o,S=i-l,b=Math.sqrt(c*c+d*d+S*S);let f,v,C;if(b>1e-4){let G=!1;if(this.config.emissionShape==="circle"&&this.config.circleVelocityDirection==="tangential"){const M=this.inverseRotation(c,d,S),Z=Math.sqrt(M[0]*M[0]+M[1]*M[1]);if(Z>1e-4){const T=-M[1]/Z,D=M[0]/Z,F=this.applyRotation(T,D,0);f=F[0],v=F[1],C=F[2],G=!0}}else if(this.config.emissionShape==="cylinder"&&this.config.cylinderVelocityDirection==="tangential"){const M=this.inverseRotation(c,d,S),Z=Math.sqrt(M[0]*M[0]+M[2]*M[2]);if(Z>1e-4){const T=-M[2]/Z,D=M[0]/Z,F=this.applyRotation(T,0,D);f=F[0],v=F[1],C=F[2],G=!0}else{const T=Math.random()*Math.PI*2,D=this.applyRotation(Math.cos(T),0,Math.sin(T));f=D[0],v=D[1],C=D[2],G=!0}}G||(f=c/b,v=d/b,C=S/b)}else{const G=Math.random()*Math.PI*2,M=Math.acos(2*Math.random()-1);f=Math.sin(M)*Math.cos(G),v=Math.sin(M)*Math.sin(G),C=Math.cos(M)}let z;this.config.randomSpeed?z=(this.config.minSpeed||0)+Math.random()*((this.config.maxSpeed||1)-(this.config.minSpeed||0)):z=this.config.particleSpeed,r[n]=this.config.overrideXVelocity?this.config.xVelocity:f*z,r[n+1]=this.config.overrideYVelocity?this.config.yVelocity:v*z,r[n+2]=this.config.overrideZVelocity?this.config.zVelocity:C*z,r[n+3]=0}setParticleColor(t,e){if(this.config.randomColorEnabled&&this.config.randomColors.length>0){const i=this.config.randomColors,r=i[Math.floor(Math.random()*i.length)];t[e+3]=r[0],t[e+4]=r[1],t[e+5]=r[2]}else this.config.colorTransitionEnabled?(t[e+3]=this.config.startColor[0],t[e+4]=this.config.startColor[1],t[e+5]=this.config.startColor[2]):(t[e+3]=this.config.particleColor[0],t[e+4]=this.config.particleColor[1],t[e+5]=this.config.particleColor[2])}setParticleLifetime(t,e){const i=this.config.lifetime||5;t[e+6]=0,t[e+7]=i+(Math.random()*.4-.2)*i}}const Ki=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class Ji{constructor(t={}){this.config=t,this._posOut=[0,0,0],this._rotMatrix=null,this._invRotMatrix=null,this._cachedRotX=void 0,this._cachedRotY=void 0,this._cachedRotZ=void 0}_updateRotationMatrix(){const t=this.config.emissionRotationX||0,e=this.config.emissionRotationY||0,i=this.config.emissionRotationZ||0;if(t===this._cachedRotX&&e===this._cachedRotY&&i===this._cachedRotZ)return;this._cachedRotX=t,this._cachedRotY=e,this._cachedRotZ=i;const r=t*Math.PI/180,n=e*Math.PI/180,a=i*Math.PI/180,o=Math.cos(r),l=Math.sin(r),c=Math.cos(n),d=Math.sin(n),S=Math.cos(a),b=Math.sin(a);this._rotMatrix=[c*S,l*d*S-o*b,o*d*S+l*b,c*b,l*d*b+o*S,o*d*b-l*S,-d,l*c,o*c],this._invRotMatrix=[this._rotMatrix[0],this._rotMatrix[3],this._rotMatrix[6],this._rotMatrix[1],this._rotMatrix[4],this._rotMatrix[7],this._rotMatrix[2],this._rotMatrix[5],this._rotMatrix[8]]}emitParticle(t,e,i){const r=this._posOut;if(this.config.emissionShape==="cube"||this.config.emissionShape==="box"?this._emitFromCube(r):this.config.emissionShape==="sphere"?this._emitFromSphere(r):this.config.emissionShape==="square"?this._emitFromSquare(r):this.config.emissionShape==="circle"?this._emitFromCircle(r):this.config.emissionShape==="cylinder"?this._emitFromCylinder(r):this.config.emissionShape==="plain"?this._emitFromPlain(r):this.config.emissionShape==="cone"?this._emitFromCone(r):this.config.emissionShape==="torus"?this._emitFromTorus(r):this.config.emissionShape==="line"?this._emitFromLine(r):this.config.emissionShape==="hemisphere"?this._emitFromHemisphere(r):this.config.emissionShape==="disc"?this._emitFromDisc(r):this.config.emissionShape==="annulus"?this._emitFromAnnulus(r):this.config.emissionShape==="capsule"?this._emitFromCapsule(r):this.config.emissionShape==="arc"?this._emitFromArc(r):this.config.emissionShape==="spiral"?this._emitFromSpiral(r):this.config.emissionShape==="frustum"?this._emitFromFrustum(r):this.config.emissionShape==="frustumSurface"?this._emitFromFrustumSurface(r):this.config.emissionShape==="cubeSurface"?this._emitFromCubeSurface(r):this.config.emissionShape==="sphereSurface"?this._emitFromSphereSurface(r):this.config.emissionShape==="boxFrame"?this._emitFromBoxFrame(r):this.config.emissionShape==="polygon"?this._emitFromPolygon(r):this.config.emissionShape==="rectangle"?this._emitFromRectangle(r):(r[0]=0,r[1]=0,r[2]=0),this.config.emissionRotationX||this.config.emissionRotationY||this.config.emissionRotationZ){this._updateRotationMatrix();const o=this._rotMatrix,l=r[0],c=r[1],d=r[2];r[0]=o[0]*l+o[1]*c+o[2]*d,r[1]=o[3]*l+o[4]*c+o[5]*d,r[2]=o[6]*l+o[7]*c+o[8]*d}(this.config.emissionPositionX||this.config.emissionPositionY||this.config.emissionPositionZ)&&(r[0]+=this.config.emissionPositionX||0,r[1]+=this.config.emissionPositionY||0,r[2]+=this.config.emissionPositionZ||0);const n=e*8;t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2];const a=e*4;this.calculateVelocity(r[0],r[1],r[2],i,a),this.setParticleColor(t,n),this.setParticleLifetime(t,n)}applyRotation(t,e,i){this._updateRotationMatrix();const r=this._rotMatrix;return[r[0]*t+r[1]*e+r[2]*i,r[3]*t+r[4]*e+r[5]*i,r[6]*t+r[7]*e+r[8]*i]}inverseRotation(t,e,i){this._updateRotationMatrix();const r=this._invRotMatrix;return[r[0]*t+r[1]*e+r[2]*i,r[3]*t+r[4]*e+r[5]*i,r[6]*t+r[7]*e+r[8]*i]}_emitFromCube(t){let e=this.config.innerLength||0,i=this.config.outerLength||this.config.cubeLength;if(e>0){const r=Math.floor(Math.random()*6),n=Math.random()-.5,a=Math.random()-.5;let o,l,c;switch(r){case 0:o=n,l=a,c=.5;break;case 1:o=n,l=a,c=-.5;break;case 2:o=.5,l=n,c=a;break;case 3:o=-.5,l=n,c=a;break;case 4:o=n,l=.5,c=a;break;case 5:o=n,l=-.5,c=a;break}const d=Math.random(),S=e+d*(i-e);t[0]=o*S,t[1]=l*S,t[2]=c*S}else t[0]=(Math.random()-.5)*i,t[1]=(Math.random()-.5)*i,t[2]=(Math.random()-.5)*i}_emitFromSphere(t){const e=Math.random()*2*Math.PI,i=Math.acos(2*Math.random()-1),r=Math.sin(i)*Math.cos(e),n=Math.sin(i)*Math.sin(e),a=Math.cos(i);let o;this.config.innerRadius===0?o=this.config.outerRadius*Math.cbrt(Math.random()):o=this.config.innerRadius+(this.config.outerRadius-this.config.innerRadius)*Math.random(),t[0]=r*o,t[1]=n*o,t[2]=a*o}_emitFromSquare(t){const e=this.config.squareInnerSize||0,i=this.config.squareSize||2;if(e>0){const r=Math.floor(Math.random()*4);let n=e+(i-e)*Math.random();switch(r){case 0:t[0]=(Math.random()*2-1)*n,t[1]=n;break;case 1:t[0]=n,t[1]=(Math.random()*2-1)*n;break;case 2:t[0]=(Math.random()*2-1)*n,t[1]=-n;break;case 3:t[0]=-n,t[1]=(Math.random()*2-1)*n;break}}else t[0]=(Math.random()*2-1)*i,t[1]=(Math.random()*2-1)*i;t[2]=0}_emitFromCircle(t){const e=this.config.circleInnerRadius||0,i=this.config.circleOuterRadius||2,r=Math.random()*Math.PI*2;let n;e>0?n=e+(i-e)*Math.random():n=i*Math.sqrt(Math.random()),t[0]=Math.cos(r)*n,t[1]=Math.sin(r)*n,t[2]=0}_emitFromPlain(t){const e=this.config.planeWidth||2,i=this.config.planeDepth||2;t[0]=(Math.random()-.5)*e,t[1]=0,t[2]=(Math.random()-.5)*i}_emitFromCone(t){const e=this.config.coneInnerRadius||0,i=this.config.coneOuterRadius||2,r=this.config.coneHeight||4,n=Math.random()*Math.PI*2,a=Math.random(),o=a*r,l=i*(1-a);let c;if(e>0){const d=e*(1-a);c=d+(l-d)*Math.random()}else c=l*Math.sqrt(Math.random());t[0]=Math.cos(n)*c,t[1]=o,t[2]=Math.sin(n)*c}_emitFromTorus(t){const e=this.config.torusMajorRadius||2,i=this.config.torusMinorRadius||.5,r=Math.random()*Math.PI*2,n=Math.random()*Math.PI*2,a=i*Math.sqrt(Math.random());t[0]=(e+a*Math.cos(n))*Math.cos(r),t[1]=a*Math.sin(n),t[2]=(e+a*Math.cos(n))*Math.sin(r)}_emitFromLine(t){const e=this.config.lineLength||4,i=Math.random();t[0]=0,t[1]=(i-.5)*e,t[2]=0}_emitFromHemisphere(t){const e=this.config.hemisphereInnerRadius||0,i=this.config.hemisphereOuterRadius||2,r=Math.random()*Math.PI*2,n=Math.acos(Math.random()),a=Math.sin(n)*Math.cos(r),o=Math.cos(n),l=Math.sin(n)*Math.sin(r);let c;e>0?c=e+(i-e)*Math.random():c=i*Math.cbrt(Math.random()),t[0]=a*c,t[1]=o*c,t[2]=l*c}_emitFromDisc(t){const e=this.config.discRadius||2,i=Math.random()*Math.PI*2,r=e*Math.sqrt(Math.random());t[0]=Math.cos(i)*r,t[1]=0,t[2]=Math.sin(i)*r}_emitFromAnnulus(t){const e=this.config.annulusInnerRadius||1,i=this.config.annulusOuterRadius||2,r=Math.random()*Math.PI*2,n=e+(i-e)*Math.random();t[0]=Math.cos(r)*n,t[1]=0,t[2]=Math.sin(r)*n}_emitFromCapsule(t){const e=this.config.capsuleRadius||.5,i=this.config.capsuleHeight||4,r=i*.5,n=Math.PI*e*e*i,a=4/3*Math.PI*e*e*e,o=n/(n+a);if(Math.random()<o){const l=Math.random()*Math.PI*2,c=e*Math.sqrt(Math.random());t[0]=Math.cos(l)*c,t[1]=(Math.random()-.5)*i,t[2]=Math.sin(l)*c}else{const l=Math.random()*Math.PI*2,c=Math.acos(2*Math.random()-1),d=e*Math.cbrt(Math.random());t[0]=d*Math.sin(c)*Math.cos(l),t[1]=d*Math.cos(c),t[2]=d*Math.sin(c)*Math.sin(l),t[1]+=t[1]>=0?r:-r}}_emitFromArc(t){const e=this.config.arcStartAngle||0,i=this.config.arcEndAngle||180,r=this.config.arcInnerRadius||0,n=this.config.arcOuterRadius||2,a=e*Math.PI/180,o=i*Math.PI/180,l=a+Math.random()*(o-a);let c;r>0?c=r+(n-r)*Math.random():c=n*Math.sqrt(Math.random()),t[0]=Math.cos(l)*c,t[1]=Math.sin(l)*c,t[2]=0}_emitFromSpiral(t){const e=this.config.spiralTurns||3,i=this.config.spiralRadiusStart||.5,r=this.config.spiralRadiusEnd||2,n=this.config.spiralHeight||4,a=Math.random(),o=a*e*Math.PI*2,l=i+(r-i)*a;t[0]=Math.cos(o)*l,t[1]=(a-.5)*n,t[2]=Math.sin(o)*l}_emitFromFrustum(t){const e=this.config.frustumRadiusNear||.5,i=this.config.frustumRadiusFar||2,r=this.config.frustumHeight||4,n=Math.random()*Math.PI*2,a=Math.random(),o=a*r,c=(e+(i-e)*a)*Math.sqrt(Math.random());t[0]=Math.cos(n)*c,t[1]=o,t[2]=Math.sin(n)*c}_emitFromFrustumSurface(t){const e=this.config.frustumRadiusNear??.5,i=this.config.frustumRadiusFar??2,r=this.config.frustumHeight??4,n=Math.random()*Math.PI*2,a=i-e,o=e+a*.5;let l;if(Math.abs(a)<1e-6||o<=1e-6)l=Math.random();else{const S=Math.random(),b=.5*a,f=e,v=-S*o,U=Math.max(0,f*f-4*b*v);l=(-f+Math.sqrt(U))/(2*b),Number.isFinite(l)||(l=Math.random()),l=Math.min(1,Math.max(0,l))}const c=l*r,d=e+a*l;t[0]=Math.cos(n)*d,t[1]=c,t[2]=Math.sin(n)*d}_emitFromCubeSurface(t){const e=this.config.cubeSurfaceSize||2,i=e*.5,r=Math.floor(Math.random()*6),n=(Math.random()-.5)*e,a=(Math.random()-.5)*e;switch(r){case 0:t[0]=n,t[1]=a,t[2]=i;break;case 1:t[0]=n,t[1]=a,t[2]=-i;break;case 2:t[0]=i,t[1]=n,t[2]=a;break;case 3:t[0]=-i,t[1]=n,t[2]=a;break;case 4:t[0]=n,t[1]=i,t[2]=a;break;case 5:t[0]=n,t[1]=-i,t[2]=a;break}}_emitFromSphereSurface(t){const e=this.config.sphereSurfaceRadius||2,i=Math.random()*Math.PI*2,r=Math.acos(2*Math.random()-1);t[0]=e*Math.sin(r)*Math.cos(i),t[1]=e*Math.sin(r)*Math.sin(i),t[2]=e*Math.cos(r)}_emitFromBoxFrame(t){const e=this.config.boxFrameSize||2,i=e*.5,r=Math.floor(Math.random()*12),a=(Math.random()-.5)*e,o=[[-1,-1],[-1,1],[1,-1],[1,1]];if(r<4){const[l,c]=o[r];t[0]=a,t[1]=l*i,t[2]=c*i}else if(r<8){const[l,c]=o[r-4];t[0]=l*i,t[1]=a,t[2]=c*i}else{const[l,c]=o[r-8];t[0]=l*i,t[1]=c*i,t[2]=a}}_emitFromPolygon(t){const e=Math.max(3,Math.floor(this.config.polygonSides||6)),i=this.config.polygonRadius||2,r=Math.floor(Math.random()*e),n=r/e*Math.PI*2,a=(r+1)/e*Math.PI*2;let o=Math.random(),l=Math.random();o+l>1&&(o=1-o,l=1-l);const c=o*Math.cos(n)+l*Math.cos(a),d=o*Math.sin(n)+l*Math.sin(a);t[0]=c*i,t[1]=d*i,t[2]=0}_emitFromRectangle(t){const e=this.config.rectangleWidth||2,i=this.config.rectangleHeight||2;t[0]=(Math.random()-.5)*e,t[1]=(Math.random()-.5)*i,t[2]=0}_emitFromCylinder(t){const e=this.config.cylinderInnerRadius||0,i=this.config.cylinderOuterRadius||2,r=this.config.cylinderHeight||4,n=Math.random()*Math.PI*2;let a;e>0?a=e+(i-e)*Math.random():a=i*Math.sqrt(Math.random()),t[0]=Math.cos(n)*a,t[1]=(Math.random()-.5)*r,t[2]=Math.sin(n)*a}calculateVelocity(t,e,i,r,n){const a=this.config.emissionPositionX||0,o=this.config.emissionPositionY||0,l=this.config.emissionPositionZ||0,c=t-a,d=e-o,S=i-l,b=Math.sqrt(c*c+d*d+S*S);let f,v,U;if(b>1e-4){let G=!1;if(this.config.emissionShape==="circle"&&this.config.circleVelocityDirection==="tangential"){const M=this.inverseRotation(c,d,S),Z=Math.sqrt(M[0]*M[0]+M[1]*M[1]);if(Z>1e-4){const T=-M[1]/Z,D=M[0]/Z,F=this.applyRotation(T,D,0);f=F[0],v=F[1],U=F[2],G=!0}}else if(this.config.emissionShape==="cylinder"&&this.config.cylinderVelocityDirection==="tangential"){const M=this.inverseRotation(c,d,S),Z=Math.sqrt(M[0]*M[0]+M[2]*M[2]);if(Z>1e-4){const T=-M[2]/Z,D=M[0]/Z,F=this.applyRotation(T,0,D);f=F[0],v=F[1],U=F[2],G=!0}else{const T=Math.random()*Math.PI*2,D=this.applyRotation(Math.cos(T),0,Math.sin(T));f=D[0],v=D[1],U=D[2],G=!0}}G||(f=c/b,v=d/b,U=S/b)}else{const G=Math.random()*Math.PI*2,M=Math.acos(2*Math.random()-1);f=Math.sin(M)*Math.cos(G),v=Math.sin(M)*Math.sin(G),U=Math.cos(M)}let z;this.config.randomSpeed?z=(this.config.minSpeed||0)+Math.random()*((this.config.maxSpeed||1)-(this.config.minSpeed||0)):z=this.config.particleSpeed,r[n]=this.config.overrideXVelocity?this.config.xVelocity:f*z,r[n+1]=this.config.overrideYVelocity?this.config.yVelocity:v*z,r[n+2]=this.config.overrideZVelocity?this.config.zVelocity:U*z,r[n+3]=0}setParticleColor(t,e){if(this.config.randomColorEnabled&&this.config.randomColors.length>0){const i=this.config.randomColors,r=i[Math.floor(Math.random()*i.length)];t[e+3]=r[0],t[e+4]=r[1],t[e+5]=r[2]}else this.config.colorTransitionEnabled?(t[e+3]=this.config.startColor[0],t[e+4]=this.config.startColor[1],t[e+5]=this.config.startColor[2]):(t[e+3]=this.config.particleColor[0],t[e+4]=this.config.particleColor[1],t[e+5]=this.config.particleColor[2])}setParticleLifetime(t,e){const i=this.config.lifetime||5;t[e+6]=0,t[e+7]=i+(Math.random()*.4-.2)*i}}const Ki=`
|
|
2
2
|
struct Uniforms {
|
|
3
3
|
transform: mat4x4<f32>,
|
|
4
4
|
cameraPosition: vec3<f32>,
|
|
@@ -894,7 +894,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
|
|
|
894
894
|
var currentFrame = __currentFrame, totalFrames = __totalFrames;
|
|
895
895
|
var particles = __particles, config = __config, math = __math;
|
|
896
896
|
${xr(t)}
|
|
897
|
-
};`,r=new Function(i);this._fn=r()}catch(e){console.warn("[ParticleScript] Compilation error:",e.message),this._fn=null,this._error=!0}}execute(t,e,i,r,n,a,o){if(!this._fn||this._error)return{configDirty:!1,particlesDirty:!1};this._particles._bind(n,a,o),this._configProxy.__resetDirty();try{this._fn(t,e,i,r,this._particles,this._configProxy,ns)}catch(l){console.warn("[ParticleScript] Runtime error:",l.message)}return{configDirty:this._configProxy.__dirty,particlesDirty:this._particles._dirty}}snapshotConfig(t){const e={};for(const i of Ct){const r=t[i];r!==void 0&&(e[i]=Array.isArray(r)?[...r]:r)}this._configSnapshot=e}restoreConfig(t){if(this._configSnapshot){for(const e of Ct)if(e in this._configSnapshot){const i=this._configSnapshot[e];t[e]=Array.isArray(i)?[...i]:i}}}destroy(){this._fn=null,this._particles=null,this._configProxy=null,this._configSnapshot=null}}async function as(s){const t=new DataView(s);if(t.getUint32(0,!0)!==1179937895)throw new Error("Invalid GLB file: incorrect magic number");const i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i} (only version 2 is supported)`);const r=t.getUint32(8,!0);let n=12,a=null,o=null;for(;n<r;){const T=t.getUint32(n,!0),D=t.getUint32(n+4,!0),F=s.slice(n+8,n+8+T);if(D===1313821514){const se=new TextDecoder("utf-8").decode(F);a=JSON.parse(se)}else D===5130562&&(o=F);n+=8+T}if(!a)throw new Error("GLB file missing JSON chunk");if(!a.meshes||a.meshes.length===0)throw new Error("GLB file contains no meshes");const c=a.meshes[0].primitives[0];if(!c)throw new Error("First mesh has no primitives");const d=c.attributes.POSITION;if(d===void 0)throw new Error("Mesh primitive missing POSITION attribute");const S=si(a,o,d,3,5126);let b;if(c.attributes.NORMAL!==void 0)b=si(a,o,c.attributes.NORMAL,3,5126);else{const T=c.indices;if(T===void 0)throw new Error("Cannot generate normals without indices");const D=Xi(a,o,T);b=Pr(S,D)}const f=c.indices;if(f===void 0)throw new Error("Mesh primitive missing indices");const v=Xi(a,o,f),C=S.length/3,z=v.length;let G=null;c.attributes.TEXCOORD_0!==void 0&&(G=si(a,o,c.attributes.TEXCOORD_0,2,5126));let M=!1;if(a.materials&&a.materials.length>0){const T=a.materials[0];T.pbrMetallicRoughness&&T.pbrMetallicRoughness.baseColorTexture!==void 0&&(M=!0)}let Z=null;if(a.skins&&a.skins.length>0)try{Z=Tr(a,o,c),globalThis.__HZFX_DEBUG&&console.log("Animation data extracted:",Z)}catch(T){console.warn("Failed to extract animation data:",T)}return{positions:S,normals:b,indices:v,texCoords:G,vertexCount:C,indexCount:z,animationData:Z,hasBaseColorTexture:M}}function si(s,t,e,i,r){const n=s.accessors[e],o={SCALAR:1,VEC2:2,VEC3:3,VEC4:4}[n.type];if(o!==i)throw new Error(`Attribute accessor type mismatch: expected ${i} components, got ${o}`);if(n.componentType!==r)throw new Error(`Attribute component type mismatch: expected ${r}, got ${n.componentType}`);const c=(s.bufferViews[n.bufferView].byteOffset||0)+(n.byteOffset||0),d=n.count,S=new DataView(t,c,d*i*4),b=new Float32Array(d*i);for(let f=0;f<d*i;f++)b[f]=S.getFloat32(f*4,!0);return b}function Xi(s,t,e){const i=s.accessors[e];if(i.type!=="SCALAR")throw new Error(`Indices accessor must be SCALAR, got ${i.type}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count;if(i.componentType===5123){const o=new DataView(t,n,a*2),l=new Uint16Array(a);for(let c=0;c<a;c++)l[c]=o.getUint16(c*2,!0);return l}else if(i.componentType===5125){const o=new DataView(t,n,a*4),l=new Uint32Array(a);for(let c=0;c<a;c++)l[c]=o.getUint32(c*4,!0);return l}else throw new Error(`Unsupported index component type: ${i.componentType}`)}function Pr(s,t){const e=new Float32Array(s.length);for(let i=0;i<t.length;i+=3){const r=t[i]*3,n=t[i+1]*3,a=t[i+2]*3,o=[s[r],s[r+1],s[r+2]],l=[s[n],s[n+1],s[n+2]],c=[s[a],s[a+1],s[a+2]],d=[l[0]-o[0],l[1]-o[1],l[2]-o[2]],S=[c[0]-o[0],c[1]-o[1],c[2]-o[2]],b=[d[1]*S[2]-d[2]*S[1],d[2]*S[0]-d[0]*S[2],d[0]*S[1]-d[1]*S[0]],f=Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]);f>0&&(b[0]/=f,b[1]/=f,b[2]/=f),e[r]=e[n]=e[a]=b[0],e[r+1]=e[n+1]=e[a+1]=b[1],e[r+2]=e[n+2]=e[a+2]=b[2]}return e}function _r(s,t,e){const i=s.accessors[e];if(i.type!=="VEC4")throw new Error(`JOINTS_0 must be VEC4, got ${i.type}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count;if(i.componentType===5121){const o=new DataView(t,n,a*4),l=new Uint8Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getUint8(c);return l}else if(i.componentType===5123){const o=new DataView(t,n,a*8),l=new Uint8Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getUint16(c*2,!0);return l}else throw new Error(`Unsupported JOINTS_0 component type: ${i.componentType}`)}function Mr(s,t,e){const i=s.accessors[e];if(i.type!=="VEC4")throw new Error(`WEIGHTS_0 must be VEC4, got ${i.type}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count;if(i.componentType===5126){const o=new DataView(t,n,a*16),l=new Float32Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getFloat32(c*4,!0);return l}else if(i.componentType===5121){const o=new DataView(t,n,a*4),l=new Float32Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getUint8(c)/255;return l}else throw new Error(`Unsupported WEIGHTS_0 component type: ${i.componentType}`)}function wr(s,t,e){const i=s.accessors[e];if(i.type!=="MAT4")throw new Error(`Expected MAT4, got ${i.type}`);if(i.componentType!==5126)throw new Error(`Expected FLOAT component type for MAT4, got ${i.componentType}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count,o=new DataView(t,n,a*64),l=new Float32Array(a*16);for(let c=0;c<a*16;c++)l[c]=o.getFloat32(c*4,!0);return l}function Br(s,t,e){const i=s.accessors[e];if(i.type!=="SCALAR")throw new Error(`Expected SCALAR, got ${i.type}`);if(i.componentType!==5126)throw new Error(`Expected FLOAT component type for SCALAR, got ${i.componentType}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count,o=new DataView(t,n,a*4),l=new Float32Array(a);for(let c=0;c<a;c++)l[c]=o.getFloat32(c*4,!0);return l}function Rr(s,t,e){const i=s.accessors[e],n={VEC3:3,VEC4:4}[i.type];if(!n)throw new Error(`Expected VEC3 or VEC4, got ${i.type}`);if(i.componentType!==5126)throw new Error(`Expected FLOAT component type, got ${i.componentType}`);const o=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),l=i.count,c=new DataView(t,o,l*n*4),d=new Float32Array(l*n);for(let S=0;S<l*n;S++)d[S]=c.getFloat32(S*4,!0);return d}function Tr(s,t,e){const i=s.skins[0],r=i.joints,n=wr(s,t,i.inverseBindMatrices),a=e.attributes.JOINTS_0!==void 0?_r(s,t,e.attributes.JOINTS_0):null,o=e.attributes.WEIGHTS_0!==void 0?Mr(s,t,e.attributes.WEIGHTS_0):null;if(!a||!o)throw new Error("Mesh missing JOINTS_0 or WEIGHTS_0 attributes");const l=s.nodes.map(d=>({translation:d.translation||[0,0,0],rotation:d.rotation||[0,0,0,1],scale:d.scale||[1,1,1],children:d.children||[],name:d.name||""})),c=[];if(s.animations&&s.animations.length>0)for(const d of s.animations){const S=[];let b=0;for(const f of d.channels){const v=d.samplers[f.sampler],C=Br(s,t,v.input),z=Rr(s,t,v.output),G=C[C.length-1];G>b&&(b=G),S.push({targetNode:f.target.node,targetPath:f.target.path,interpolation:v.interpolation||"LINEAR",timestamps:C,values:z})}c.push({name:d.name||`Animation ${c.length}`,duration:b,channels:S})}return{joints:r,inverseBindMatrices:n,jointIndices:a,jointWeights:o,nodes:l,animations:c}}async function oi(s){const t=new DataView(s);if(t.getUint32(0,!0)!==1179937895)throw new Error("Invalid GLB file: incorrect magic number");const i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);const r=t.getUint32(8,!0);let n=12,a=null,o=null;for(;n<r;){const Z=t.getUint32(n,!0),T=t.getUint32(n+4,!0),D=s.slice(n+8,n+8+Z);if(T===1313821514){const H=new TextDecoder("utf-8").decode(D);a=JSON.parse(H)}else T===5130562&&(o=D);n+=8+Z}if(!a)throw new Error("GLB file missing JSON chunk");if(!a.materials||a.materials.length===0)return null;const l=a.materials[0];if(!l.pbrMetallicRoughness||l.pbrMetallicRoughness.baseColorTexture===void 0)return null;const c=l.pbrMetallicRoughness.baseColorTexture.index;if(!a.textures||!a.textures[c])return null;const S=a.textures[c].source;if(S===void 0||!a.images||!a.images[S])return null;const b=a.images[S],f=b.mimeType||"image/png";if(b.bufferView===void 0)return null;if(!o)throw new Error("GLB file missing BIN chunk (required for embedded textures)");const v=a.bufferViews[b.bufferView],C=v.byteOffset||0,z=v.byteLength,G=o.slice(C,C+z);return{imageBlob:new Blob([G],{type:f}),mimeType:f}}function Er(s,t,e,i){return i=i||[0,0,0],i[0]=s[0]+(t[0]-s[0])*e,i[1]=s[1]+(t[1]-s[1])*e,i[2]=s[2]+(t[2]-s[2])*e,i}function Ar(s,t,e,i){i=i||[0,0,0,0];let r=s[0]*t[0]+s[1]*t[1]+s[2]*t[2]+s[3]*t[3],n=1;if(r<0&&(r=-r,n=-1),r>.9995){i[0]=s[0]+(n*t[0]-s[0])*e,i[1]=s[1]+(n*t[1]-s[1])*e,i[2]=s[2]+(n*t[2]-s[2])*e,i[3]=s[3]+(n*t[3]-s[3])*e;const d=Math.sqrt(i[0]*i[0]+i[1]*i[1]+i[2]*i[2]+i[3]*i[3]);return d>1e-4?(i[0]/=d,i[1]/=d,i[2]/=d,i[3]/=d):(i[0]=0,i[1]=0,i[2]=0,i[3]=1),i}const a=Math.acos(r),o=Math.sin(a),l=Math.sin((1-e)*a)/o,c=Math.sin(e*a)/o;return i[0]=s[0]*l+n*t[0]*c,i[1]=s[1]*l+n*t[1]*c,i[2]=s[2]*l+n*t[2]*c,i[3]=s[3]*l+n*t[3]*c,i}function Cr(s,t){const e=s[0],i=s[1],r=s[2],n=s[3],a=e+e,o=i+i,l=r+r,c=e*a,d=e*o,S=e*l,b=i*o,f=i*l,v=r*l,C=n*a,z=n*o,G=n*l,M=t||new Float32Array(16);return M[0]=1-(b+v),M[1]=d+G,M[2]=S-z,M[3]=0,M[4]=d-G,M[5]=1-(c+v),M[6]=f+C,M[7]=0,M[8]=S+z,M[9]=f-C,M[10]=1-(c+b),M[11]=0,M[12]=0,M[13]=0,M[14]=0,M[15]=1,M}const Ur=new Float32Array(16);function Ir(s,t,e,i){const r=Cr(t,Ur),n=i||new Float32Array(16);return n[0]=r[0]*e[0],n[1]=r[1]*e[0],n[2]=r[2]*e[0],n[3]=0,n[4]=r[4]*e[1],n[5]=r[5]*e[1],n[6]=r[6]*e[1],n[7]=0,n[8]=r[8]*e[2],n[9]=r[9]*e[2],n[10]=r[10]*e[2],n[11]=0,n[12]=s[0],n[13]=s[1],n[14]=s[2],n[15]=1,n}function Ni(s,t,e){const i=e||new Float32Array(16);for(let r=0;r<4;r++)for(let n=0;n<4;n++)i[r*4+n]=s[0+n]*t[r*4+0]+s[4+n]*t[r*4+1]+s[8+n]*t[r*4+2]+s[12+n]*t[r*4+3];return i}class os{constructor(t){this.joints=t.joints,this.inverseBindMatrices=t.inverseBindMatrices,this.jointWeights=t.jointWeights,this.jointIndices=t.jointIndices,this.nodes=t.nodes,this.animations=t.animations,this.restPositions=null,this.restNormals=null,this.currentAnimIndex=0,this.currentTime=0,this.playing=!0,this.speed=1,this.loop=!0,this.jointLocalTransforms=new Array(this.nodes.length),this.jointGlobalTransforms=new Array(this.nodes.length),this.jointFinalMatrices=new Array(this.joints.length);for(let e=0;e<this.nodes.length;e++)this.jointLocalTransforms[e]=new Float32Array(16),this.jointGlobalTransforms[e]=new Float32Array(16);for(let e=0;e<this.joints.length;e++)this.jointFinalMatrices[e]=new Float32Array(16);this.skinnedPositions=null,this.skinnedNormals=null,this._gpuSkinningReady=!1,this._sV0=new Float64Array(4),this._sV1=new Float64Array(4),this._scrT=new Float64Array(3),this._scrR=new Float64Array(4),this._scrS=new Float64Array(3),this._buildTopologicalOrder(),this._parentMap=new Array(this.nodes.length).fill(-1);for(let e=0;e<this.nodes.length;e++)for(const i of this.nodes[e].children)this._parentMap[i]=e;this._invBindViews=new Array(this.joints.length);for(let e=0;e<this.joints.length;e++)this._invBindViews[e]=this.inverseBindMatrices.subarray(e*16,e*16+16)}setRestPose(t,e){this.restPositions=new Float32Array(t),this.restNormals=new Float32Array(e),this.skinnedPositions=new Float32Array(t.length),this.skinnedNormals=new Float32Array(e.length)}async initGPUSkinning(t,e,i){try{this._gpuDevice=t,this._gpuOutputBuffer=e;const r=this.restPositions.length/3,n=new Float32Array(r*8);for(let l=0;l<r;l++){const c=l*8,d=l*3,S=l*2;n[c]=this.restPositions[d],n[c+1]=this.restPositions[d+1],n[c+2]=this.restPositions[d+2],n[c+3]=this.restNormals[d],n[c+4]=this.restNormals[d+1],n[c+5]=this.restNormals[d+2],n[c+6]=i?i[S]:0,n[c+7]=i?i[S+1]:0}this._gpuRestDataBuffer=t.createBuffer({size:n.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_restData"}),t.queue.writeBuffer(this._gpuRestDataBuffer,0,n),this._gpuJointWeightsBuffer=t.createBuffer({size:this.jointWeights.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_jointWeights"}),t.queue.writeBuffer(this._gpuJointWeightsBuffer,0,this.jointWeights);const a=new Uint32Array(this.jointIndices.length);for(let l=0;l<this.jointIndices.length;l++)a[l]=this.jointIndices[l];this._gpuJointIndicesBuffer=t.createBuffer({size:a.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_jointIndices"}),t.queue.writeBuffer(this._gpuJointIndicesBuffer,0,a),this._gpuJointMatricesBuffer=t.createBuffer({size:this.joints.length*16*4,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_jointMatrices"}),this._gpuJointMatricesData=new Float32Array(this.joints.length*16);const o=t.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:1,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:2,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:3,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:4,visibility:GPUShaderStage.COMPUTE,buffer:{type:"storage"}}]});this._gpuSkinningPipeline=t.createComputePipeline({layout:t.createPipelineLayout({bindGroupLayouts:[o]}),compute:{module:t.createShaderModule({code:yr}),entryPoint:"main"}}),this._gpuSkinningBindGroup=t.createBindGroup({layout:o,entries:[{binding:0,resource:{buffer:this._gpuRestDataBuffer}},{binding:1,resource:{buffer:this._gpuJointWeightsBuffer}},{binding:2,resource:{buffer:this._gpuJointIndicesBuffer}},{binding:3,resource:{buffer:this._gpuJointMatricesBuffer}},{binding:4,resource:{buffer:this._gpuOutputBuffer}}]}),this._gpuVertexCount=r,this._gpuSkinningReady=!0,globalThis.__HZFX_DEBUG&&console.log(`GPU skinning initialized: ${r} vertices, ${this.joints.length} joints`)}catch(r){console.warn("GPU skinning init failed, using CPU fallback:",r),this._gpuSkinningReady=!1}}_applySkinningGPU(){for(let i=0;i<this.joints.length;i++)this._gpuJointMatricesData.set(this.jointFinalMatrices[i],i*16);this._gpuDevice.queue.writeBuffer(this._gpuJointMatricesBuffer,0,this._gpuJointMatricesData);const t=this._gpuDevice.createCommandEncoder({label:"SkinningComputeEncoder"}),e=t.beginComputePass({label:"SkinningComputePass"});e.setPipeline(this._gpuSkinningPipeline),e.setBindGroup(0,this._gpuSkinningBindGroup),e.dispatchWorkgroups(Math.ceil(this._gpuVertexCount/64),1,1),e.end(),this._gpuDevice.queue.submit([t.finish()])}update(t){if(!this.playing||this.animations.length===0)return{positions:this.skinnedPositions,normals:this.skinnedNormals,changed:!1};this.currentTime+=t*this.speed;const e=this.animations[this.currentAnimIndex];return this.loop?this.currentTime=this.currentTime%e.duration:this.currentTime>e.duration&&(this.currentTime=e.duration,this.playing=!1),this._computeLocalTransforms(this.currentTime),this._computeGlobalTransforms(),this._computeFinalMatrices(),this._gpuSkinningReady?(this._applySkinningGPU(),{gpuSkinned:!0,changed:!0}):(this._applySkinning(),{positions:this.skinnedPositions,normals:this.skinnedNormals,changed:!0})}getCurrentAnimation(){return this.animations[this.currentAnimIndex]}setAnimation(t){t>=0&&t<this.animations.length&&(this.currentAnimIndex=t,this.currentTime=0)}getAnimationNames(){return this.animations.map(t=>t.name)}_buildTopologicalOrder(){const t=new Set,e=[],i=n=>{if(t.has(n))return;t.add(n);const a=this.nodes[n];for(const o of a.children)i(o);e.push(n)},r=new Set;for(const n of this.nodes)for(const a of n.children)r.add(a);for(let n=0;n<this.nodes.length;n++)r.has(n)||i(n);this.topologicalOrder=e.reverse()}_sampleChannel(t,e,i){const{timestamps:r,values:n,interpolation:a,targetPath:o}=t;if(e<=r[0])return this._extractValue(n,0,o,i);if(e>=r[r.length-1])return this._extractValue(n,r.length-1,o,i);let l=0,c=r.length-1;for(;c-l>1;){const C=Math.floor((l+c)/2);r[C]<=e?l=C:c=C}const d=r[l],S=r[c],b=(e-d)/(S-d),f=this._extractValue(n,l,o,this._sV0),v=this._extractValue(n,c,o,this._sV1);return a==="STEP"?(i[0]=f[0],i[1]=f[1],i[2]=f[2],o==="rotation"&&(i[3]=f[3]),i):o==="rotation"?Ar(f,v,b,i):Er(f,v,b,i)}_extractValue(t,e,i,r){if(i==="rotation"){const n=e*4;r[0]=t[n],r[1]=t[n+1],r[2]=t[n+2],r[3]=t[n+3]}else{const n=e*3;r[0]=t[n],r[1]=t[n+1],r[2]=t[n+2]}return r}_computeLocalTransforms(t){const e=this.animations[this.currentAnimIndex];for(let i=0;i<this.nodes.length;i++){const r=this.nodes[i];let n=r.translation,a=r.rotation,o=r.scale;for(const l of e.channels)l.targetNode===i&&(l.targetPath==="translation"?n=this._sampleChannel(l,t,this._scrT):l.targetPath==="rotation"?a=this._sampleChannel(l,t,this._scrR):l.targetPath==="scale"&&(o=this._sampleChannel(l,t,this._scrS)));Ir(n,a,o,this.jointLocalTransforms[i])}}_computeGlobalTransforms(){const t=this._parentMap;for(const e of this.topologicalOrder){const i=t[e];i===-1?this.jointGlobalTransforms[e].set(this.jointLocalTransforms[e]):Ni(this.jointGlobalTransforms[i],this.jointLocalTransforms[e],this.jointGlobalTransforms[e])}}_computeFinalMatrices(){for(let t=0;t<this.joints.length;t++){const e=this.joints[t],i=this.jointGlobalTransforms[e];Ni(i,this._invBindViews[t],this.jointFinalMatrices[t])}}_applySkinning(){const t=this.restPositions.length/3,e=this.restPositions,i=this.restNormals,r=this.skinnedPositions,n=this.skinnedNormals,a=this.jointWeights,o=this.jointIndices,l=this.jointFinalMatrices;for(let c=0;c<t;c++){const d=c*3,S=c*4,b=e[d],f=e[d+1],v=e[d+2],C=i[d],z=i[d+1],G=i[d+2];let M=0,Z=0,T=0,D=0,F=0,H=0;for(let ne=0;ne<4;ne++){const re=a[S+ne];if(re===0)continue;const q=l[o[S+ne]];M+=(q[0]*b+q[4]*f+q[8]*v+q[12])*re,Z+=(q[1]*b+q[5]*f+q[9]*v+q[13])*re,T+=(q[2]*b+q[6]*f+q[10]*v+q[14])*re,D+=(q[0]*C+q[4]*z+q[8]*G)*re,F+=(q[1]*C+q[5]*z+q[9]*G)*re,H+=(q[2]*C+q[6]*z+q[10]*G)*re}const se=Math.sqrt(D*D+F*F+H*H);se>1e-4&&(n[d]=D/se,n[d+1]=F/se,n[d+2]=H/se),r[d]=M,r[d+1]=Z,r[d+2]=T}}}class ls{constructor({duration:t=0,loop:e=!1,playbackRate:i=1}={}){this.currentTime=0,this.duration=t,this.loop=e,this.playbackRate=i,this.paused=!1,this._justLooped=!1}tick(t){if(this.paused)return 0;const e=t*this.playbackRate;return this.currentTime+=e,this._justLooped=!1,this.loop&&this.duration>0&&isFinite(this.duration)&&this.currentTime>=this.duration&&(this.currentTime=0,this._justLooped=!0),e}get justLooped(){return this._justLooped}reset(){this.currentTime=0,this._justLooped=!1}seek(t){this.currentTime=Math.max(0,t||0),this._justLooped=!1}}const Yi={linear:s=>s,easeInQuad:s=>s*s,easeOutQuad:s=>1-(1-s)*(1-s),easeInOutQuad:s=>s<.5?2*s*s:1-Math.pow(-2*s+2,2)/2,easeInCubic:s=>s*s*s,easeOutCubic:s=>1-Math.pow(1-s,3),easeInOutCubic:s=>s<.5?4*s*s*s:1-Math.pow(-2*s+2,3)/2,easeInQuart:s=>s*s*s*s,easeOutQuart:s=>1-Math.pow(1-s,4),easeInOutQuart:s=>s<.5?8*s*s*s*s:1-Math.pow(-2*s+2,4)/2,easeOutBack:s=>1+2.70158*Math.pow(s-1,3)+1.70158*Math.pow(s-1,2),easeOutElastic:s=>{if(s===0||s===1)return s;const t=2*Math.PI/3;return Math.pow(2,-10*s)*Math.sin((s*10-.75)*t)+1}};function zr(s,t,e,i){const r=3*s,n=3*(e-s)-r,a=1-r-n,o=3*t,l=3*(i-t)-o,c=1-o-l,d=f=>((a*f+n)*f+r)*f,S=f=>((c*f+l)*f+o)*f,b=f=>(3*a*f+2*n)*f+r;return f=>{if(f<=0)return 0;if(f>=1)return 1;let v=f;for(let C=0;C<8;C++){const z=d(v)-f;if(Math.abs(z)<1e-5)break;const G=b(v);if(Math.abs(G)<1e-6)break;v-=z/G}return S(v)}}function cs(s,t){return typeof s=="function"?s(t):Array.isArray(s)&&s.length===4?zr(s[0],s[1],s[2],s[3])(t):(Yi[s]||Yi.linear)(t)}function Gr(s,t){if(!Array.isArray(s)||s.length===0)return;if(s.length===1||t<=s[0].t)return s[0].v;const e=s[s.length-1];if(t>=e.t)return e.v;for(let i=0;i<s.length-1;i++){const r=s[i],n=s[i+1];if(t>=r.t&&t<=n.t){const a=n.t-r.t,o=a>0?(t-r.t)/a:0;return r.v+(n.v-r.v)*cs(r.ease,o)}}return e.v}function Dr(s,t,e){if(!Array.isArray(s)||s.length===0)return;const i=s.length,r=s[i-1];let n,a,o;if(i===1||t<=s[0].t)n=a=s[0].v,o=0;else if(t>=r.t)n=a=r.v,o=0;else{n=a=r.v,o=0;for(let S=0;S<i-1;S++){const b=s[S],f=s[S+1];if(t>=b.t&&t<=f.t){const v=f.t-b.t;n=b.v,a=f.v,o=cs(b.ease,v>0?(t-b.t)/v:0);break}}}const l=n[0]+(a[0]-n[0])*o,c=n[1]+(a[1]-n[1])*o,d=n[2]+(a[2]-n[2])*o;return e?(e[0]=l,e[1]=c,e[2]=d,e):[l,c,d]}const Fr=["gravityStrength","emissionRate","damping","dampingStrength","particleSize","particleSpeed","opacity","bloomIntensity","emissionPositionX","emissionPositionY","emissionPositionZ","emissionRotationX","emissionRotationY","emissionRotationZ","circleInnerRadius","circleOuterRadius","discRadius","annulusInnerRadius","annulusOuterRadius","arcStartAngle","arcEndAngle","arcInnerRadius","arcOuterRadius","squareSize","rectangleWidth","rectangleHeight","planeWidth","planeDepth","lineLength","polygonRadius","shapeStrokeWidth","shapeStrokeAmplitude","shapeStrokeFrequency","shapeStrokeSpeed"],Vr={square:0,circle:1,triangle:2,diamond:3,star:4,hexagon:5,ring:6,heart:7,cross:8,spark:9,leaf:10,capsule:11,crescent:12,line:13,"curved-line":14};function ji(s){const t=atob(s),e=new Uint8Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return e.buffer}class kt{constructor(t,e){this.device=t,this.config=e,this.MAX_PARTICLES=e.maxParticles||1e4,this.particleCount=e.particleCount||100,this.activeParticles=0,this.emitting=!1,this.currentEmissionTime=0,this.emissionAccumulator=0,this.destroyed=!1,this.particleData=new Float32Array(this.MAX_PARTICLES*8),this.particleVelocities=new Float32Array(this.MAX_PARTICLES*4),this.instanceBuffer=t.createBuffer({size:this.MAX_PARTICLES*8*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC,label:"particleInstanceBuffer"}),this.velocityBuffer=t.createBuffer({size:this.MAX_PARTICLES*4*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,label:"particleVelocityBuffer"}),this.trailBuffer=t.createBuffer({size:this.MAX_PARTICLES*4*4,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,label:"particleTrailBuffer"}),this._trailResetData=new Float32Array(this.MAX_PARTICLES*4),this.appearanceUniformBuffer=t.createBuffer({size:224,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,label:"appearanceUniformBuffer"}),this.bloomIntensityBuffer=t.createBuffer({size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,label:"systemBloomIntensityBuffer"}),e.overrideXVelocity===void 0&&(e.overrideXVelocity=!1),e.overrideYVelocity===void 0&&(e.overrideYVelocity=!1),e.overrideZVelocity===void 0&&(e.overrideZVelocity=!1),e.xVelocity===void 0&&(e.xVelocity=0),e.yVelocity===void 0&&(e.yVelocity=0),e.zVelocity===void 0&&(e.zVelocity=0),e.textureEnabled===void 0&&(e.textureEnabled=!1),e.glbModelEnabled===void 0&&(e.glbModelEnabled=!1),e.textureType===void 0&&(e.textureType="image"),e.glbFileName===void 0&&(e.glbFileName=null),e.animationIndex===void 0&&(e.animationIndex=0),e.animationSpeed===void 0&&(e.animationSpeed=1),e.animationLoop===void 0&&(e.animationLoop=!0),e.useGlbTexture===void 0&&(e.useGlbTexture=!1),e.glbHasTexture===void 0&&(e.glbHasTexture=!1),e.particleShape===void 0&&(e.particleShape="square"),e.particleShapeRotation!==void 0&&(e.rotation=(e.rotation||0)+e.particleShapeRotation,delete e.particleShapeRotation),e.particleShapeRotationX===void 0&&(e.particleShapeRotationX=0),e.particleShapeRotationY===void 0&&(e.particleShapeRotationY=0),e.particleShapeRotationZ===void 0&&(e.particleShapeRotationZ=0),e.particleColor===void 0&&(e.particleColor=[1,1,1]),e.startColor===void 0&&(e.startColor=[1,0,0]),e.endColor===void 0&&(e.endColor=[0,0,1]),e.fadeEnabled===void 0&&(e.fadeEnabled=!0),e.colorTransitionEnabled===void 0&&(e.colorTransitionEnabled=!1),e.randomColorEnabled===void 0&&(e.randomColorEnabled=!1),e.randomColors===void 0&&(e.randomColors=[]),e.particleSize===void 0&&(e.particleSize=.1),e.particleSpeed===void 0&&(e.particleSpeed=1),e.opacity===void 0&&(e.opacity=1),e.aspectRatio===void 0&&(e.aspectRatio=1),e.rotation===void 0&&(e.rotation=0),e.rotationMode===void 0&&(e.rotationMode="fixed"),e.minRotation===void 0&&(e.minRotation=0),e.maxRotation===void 0&&(e.maxRotation=90),e.orientX===void 0&&(e.orientX=0),e.orientY===void 0&&(e.orientY=0),e.orientZ===void 0&&(e.orientZ=0),e.randomSize===void 0&&(e.randomSize=!1),e.minSize===void 0&&(e.minSize=.05),e.maxSize===void 0&&(e.maxSize=.15),e.randomSpeed===void 0&&(e.randomSpeed=!1),e.minSpeed===void 0&&(e.minSpeed=.1),e.maxSpeed===void 0&&(e.maxSpeed=1),e.fadeSizeEnabled===void 0&&(e.fadeSizeEnabled=!1),e.increaseSizeEnabled===void 0&&(e.increaseSizeEnabled=!1),e.sizeLifetimeSpeed===void 0&&(e.sizeLifetimeSpeed=1),e.bloomEnabled===void 0&&(e.bloomEnabled=!0),e.bloomIntensity===void 0&&(e.bloomIntensity=1),e.bloomColor===void 0&&(e.bloomColor=[1,1,1]),e.gravityEnabled===void 0&&(e.gravityEnabled=!1),e.gravityStrength===void 0&&(e.gravityStrength=2),e.dampingEnabled===void 0&&(e.dampingEnabled=!1),e.dampingStrength===void 0&&(e.dampingStrength=1),e.attractorEnabled===void 0&&(e.attractorEnabled=!1),e.attractorStrength===void 0&&(e.attractorStrength=1),e.attractorPosition===void 0&&(e.attractorPosition=[0,0,0]),e.attractorReverse===void 0&&(e.attractorReverse=!1),e.burstMode===void 0&&(e.burstMode=!1),e.emissionShape===void 0&&(e.emissionShape="cube"),e.lifetime===void 0&&(e.lifetime=5),e.emissionRate===void 0&&(e.emissionRate=10),e.startAt===void 0&&(e.startAt=0),e.emissionDuration===void 0&&(e.emissionDuration=10),e.emissionDurationInfinite===void 0&&(e.emissionDurationInfinite=!1),e.emissionDuration>300&&(e.emissionDurationInfinite=!0,e.emissionDuration=10),e.outerLength===void 0&&(e.outerLength=e.cubeLength??2),e.innerLength===void 0&&(e.innerLength=0),e.outerRadius===void 0&&(e.outerRadius=2),e.innerRadius===void 0&&(e.innerRadius=0),e.squareSize===void 0&&(e.squareSize=2),e.squareInnerSize===void 0&&(e.squareInnerSize=0),e.circleInnerRadius===void 0&&(e.circleInnerRadius=0),e.circleOuterRadius===void 0&&(e.circleOuterRadius=2),e.circleVelocityDirection===void 0&&(e.circleVelocityDirection="outward"),e.cylinderInnerRadius===void 0&&(e.cylinderInnerRadius=0),e.cylinderOuterRadius===void 0&&(e.cylinderOuterRadius=2),e.cylinderHeight===void 0&&(e.cylinderHeight=4),e.cylinderVelocityDirection===void 0&&(e.cylinderVelocityDirection="outward"),e.planeWidth===void 0&&(e.planeWidth=2),e.planeDepth===void 0&&(e.planeDepth=2),e.coneOuterRadius===void 0&&(e.coneOuterRadius=2),e.coneInnerRadius===void 0&&(e.coneInnerRadius=0),e.coneHeight===void 0&&(e.coneHeight=4),e.torusMajorRadius===void 0&&(e.torusMajorRadius=2),e.torusMinorRadius===void 0&&(e.torusMinorRadius=.5),e.lineLength===void 0&&(e.lineLength=4),e.hemisphereOuterRadius===void 0&&(e.hemisphereOuterRadius=2),e.hemisphereInnerRadius===void 0&&(e.hemisphereInnerRadius=0),e.discRadius===void 0&&(e.discRadius=2),e.annulusInnerRadius===void 0&&(e.annulusInnerRadius=1),e.annulusOuterRadius===void 0&&(e.annulusOuterRadius=2),e.capsuleRadius===void 0&&(e.capsuleRadius=.5),e.capsuleHeight===void 0&&(e.capsuleHeight=4),e.arcStartAngle===void 0&&(e.arcStartAngle=0),e.arcEndAngle===void 0&&(e.arcEndAngle=180),e.arcInnerRadius===void 0&&(e.arcInnerRadius=0),e.arcOuterRadius===void 0&&(e.arcOuterRadius=2),e.spiralTurns===void 0&&(e.spiralTurns=3),e.spiralRadiusStart===void 0&&(e.spiralRadiusStart=.5),e.spiralRadiusEnd===void 0&&(e.spiralRadiusEnd=2),e.spiralHeight===void 0&&(e.spiralHeight=4),e.frustumRadiusNear===void 0&&(e.frustumRadiusNear=.5),e.frustumRadiusFar===void 0&&(e.frustumRadiusFar=2),e.frustumHeight===void 0&&(e.frustumHeight=4),e.cubeSurfaceSize===void 0&&(e.cubeSurfaceSize=2),e.sphereSurfaceRadius===void 0&&(e.sphereSurfaceRadius=2),e.boxFrameSize===void 0&&(e.boxFrameSize=2),e.polygonSides===void 0&&(e.polygonSides=6),e.polygonRadius===void 0&&(e.polygonRadius=2),e.emissionRotationX===void 0&&(e.emissionRotationX=0),e.emissionRotationY===void 0&&(e.emissionRotationY=0),e.emissionRotationZ===void 0&&(e.emissionRotationZ=0),e.emissionPositionX===void 0&&(e.emissionPositionX=e.emissionTranslationX??0),e.emissionPositionY===void 0&&(e.emissionPositionY=e.emissionTranslationY??0),e.emissionPositionZ===void 0&&(e.emissionPositionZ=e.emissionTranslationZ??0),e.pulseEnabled===void 0&&(e.pulseEnabled=!1),e.pulseAmplitude===void 0&&(e.pulseAmplitude=.5),e.pulseFrequency===void 0&&(e.pulseFrequency=1),e.pulsePhaseRandom===void 0&&(e.pulsePhaseRandom=0),e.pulseOpacity===void 0&&(e.pulseOpacity=!1),e.confinementEnabled===void 0&&(e.confinementEnabled=!1),e.confinementShape===void 0&&(e.confinementShape="box"),e.confinementMode===void 0&&(e.confinementMode="bounce"),e.confinementSpace===void 0&&(e.confinementSpace="world"),e.confinementBoxHalfSize===void 0&&(e.confinementBoxHalfSize=[2,2,2]),e.confinementSphereRadius===void 0&&(e.confinementSphereRadius=3),e.confinementRestitution===void 0&&(e.confinementRestitution=.8),e.confinementFriction===void 0&&(e.confinementFriction=.1),e.softBoundaryEnabled===void 0&&(e.softBoundaryEnabled=!1),e.softBoundaryStrength===void 0&&(e.softBoundaryStrength=5),e.softBoundaryFalloff===void 0&&(e.softBoundaryFalloff=.5),e.depthWriteEnabled===void 0&&(e.depthWriteEnabled=!1),e.velocityStretchEnabled===void 0&&(e.velocityStretchEnabled=!1),e.velocityStretchFactor===void 0&&(e.velocityStretchFactor=1),e.blendMode===void 0&&(e.blendMode="normal"),e.noiseDistortEnabled===void 0&&(e.noiseDistortEnabled=!1),e.noiseTilingX===void 0&&(e.noiseTilingX=3),e.noiseTilingY===void 0&&(e.noiseTilingY=3),e.noiseSpeed===void 0&&(e.noiseSpeed=-1.5),e.noiseAmplitude===void 0&&(e.noiseAmplitude=.08),e.emissionTrailEnabled===void 0&&(e.emissionTrailEnabled=!1),e.emissionTrailDuration===void 0&&(e.emissionTrailDuration=1),e.emissionTrailWidth===void 0&&(e.emissionTrailWidth=.3),e.emissionTrailMinDistance===void 0&&(e.emissionTrailMinDistance=.05),e.emissionTrailMaxPoints===void 0&&(e.emissionTrailMaxPoints=256),e.emissionTrailSegments===void 0&&(e.emissionTrailSegments=8),e.emissionTrailMode===void 0&&(e.emissionTrailMode="ribbon"),e.emissionTrailShape===void 0&&(e.emissionTrailShape="straight"),e.emissionTrailShapeAmplitude===void 0&&(e.emissionTrailShapeAmplitude=.1),e.emissionTrailShapeFrequency===void 0&&(e.emissionTrailShapeFrequency=4),e.emissionTrailShapeSpeed===void 0&&(e.emissionTrailShapeSpeed=0),e.shapeStrokeEnabled===void 0&&(e.shapeStrokeEnabled=!1),e.shapeStrokeWidth===void 0&&(e.shapeStrokeWidth=.08),e.shapeStrokeSegments===void 0&&(e.shapeStrokeSegments=96),e.shapeStrokeShape===void 0&&(e.shapeStrokeShape="straight"),e.shapeStrokeAmplitude===void 0&&(e.shapeStrokeAmplitude=.08),e.shapeStrokeFrequency===void 0&&(e.shapeStrokeFrequency=10),e.shapeStrokeSpeed===void 0&&(e.shapeStrokeSpeed=0),e.shapeDisplay===void 0&&(e.shapeDisplay=!0),e.followSystemTranslation===void 0&&(e.followSystemTranslation=!0),e.followSystemId===void 0&&(e.followSystemId=null),this._newEmissions=[],this._emptyEmissions=[],this._pendingFollowEmissions=this._emptyEmissions,this.glbVertexBuffer=null,this.glbIndexBuffer=null,this.glbIndexCount=0,this.glbIndexFormat="uint16",this.glbMeshData=null,this.glbRawArrayBuffer=null,this.glbAnimator=null,this.glbAnimated=!1,this._glbInterleavedData=null,this._appearanceData=new Float32Array(56),this._bloomIntensityData=new Float32Array(16),this._simPosition=[0,0,0],this._simVelocity=[0,0,0],this._simRotMatrix=null,this._simRotX=0,this._simRotZ=0,this._emitSimRotY=0,this.emitter=new Ji(e),this.physics=new ss(t,this.MAX_PARTICLES),this.textureManager=new rs(t),e.gravityEnabled&&this.setGravity(e.gravityStrength||0),e.dampingEnabled&&this.physics.setDamping(e.dampingStrength||0),e.attractorEnabled&&e.attractorPosition&&this.setAttractor(e.attractorStrength||0,e.attractorPosition,e.attractorReverse),e.confinementEnabled&&this.setConfinement({enabled:!0,shape:e.confinementShape,mode:e.confinementMode,space:e.confinementSpace,boxSize:e.confinementBoxHalfSize,sphereRadius:e.confinementSphereRadius,restitution:e.confinementRestitution,friction:e.confinementFriction}),e.softBoundaryEnabled&&this.setSoftBoundary({enabled:!0,strength:e.softBoundaryStrength,falloff:e.softBoundaryFalloff}),this.particleTexture=this.textureManager.getDefaultTexture(),this.updateBloomIntensity(),this.updateAppearanceUniform(),this.frameCount=0,this.shouldReset=!1,this._scriptParticleData=new Float32Array(this.MAX_PARTICLES*8),this._scriptVelocityData=new Float32Array(this.MAX_PARTICLES*4),this._scriptReadbackPending=!1,this._scriptReadbackReady=!1,this._scriptFrame=0,this._scriptTime=0,this._scriptConfigRestored=!1,this._particleScript=null,e.script&&(this._particleScript=new ai(e.script,e,this.MAX_PARTICLES)),this.initComputePipeline(t)}async initComputePipeline(t){this.computeReady=await this.physics.initComputePipeline(this.instanceBuffer,this.velocityBuffer,this.trailBuffer)}setScript(t){this._particleScript&&(this._particleScript.destroy(),this._particleScript=null),this._scriptReadbackPending=!1,this._scriptReadbackReady=!1,this._scriptFrame=0,this._scriptTime=0,this._scriptConfigRestored=!1,t?(this.config.script=t,this._particleScript=new ai(t,this.config,this.MAX_PARTICLES),this._particleScript.snapshotConfig(this.config)):delete this.config.script}async setTexture(t){this.destroyed||(this.textureManager.destroyTexture(this.particleTexture),this.particleTexture=await this.textureManager.loadTexture(t),this.config.textureEnabled=!0,this.updateAppearanceUniform(),this.updateBuffers())}resetTexture(){this.destroyed||(this.textureManager.destroyTexture(this.particleTexture),this.particleTexture=this.textureManager.getDefaultTexture(),this.config.textureEnabled=!1,this.updateAppearanceUniform(),this.updateBuffers())}async setGLBModel(t){try{this.glbRawArrayBuffer=t;const e=await as(t);this.glbMeshData=e,this.config.glbHasTexture=e.hasBaseColorTexture||!1;const i=new Float32Array(e.vertexCount*8);for(let r=0;r<e.vertexCount;r++){const n=r*8,a=r*3,o=r*2;i[n+0]=e.positions[a+0],i[n+1]=e.positions[a+1],i[n+2]=e.positions[a+2],i[n+3]=e.normals[a+0],i[n+4]=e.normals[a+1],i[n+5]=e.normals[a+2],e.texCoords?(i[n+6]=e.texCoords[o+0],i[n+7]=e.texCoords[o+1]):(i[n+6]=0,i[n+7]=0)}if(this.glbVertexBuffer&&this.glbVertexBuffer.destroy(),this.glbIndexBuffer&&this.glbIndexBuffer.destroy(),this.glbVertexBuffer=this.device.createBuffer({size:i.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE,label:"glbVertexBuffer"}),this.device.queue.writeBuffer(this.glbVertexBuffer,0,i),this.glbIndexBuffer=this.device.createBuffer({size:e.indices.byteLength,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST,label:"glbIndexBuffer"}),this.device.queue.writeBuffer(this.glbIndexBuffer,0,e.indices),this.glbIndexCount=e.indexCount,this.glbIndexFormat=e.indices instanceof Uint32Array?"uint32":"uint16",this.config.glbModelEnabled=!0,this.config.textureType="glb",e.animationData){this.glbAnimator=new os(e.animationData),this.glbAnimator.setRestPose(e.positions,e.normals),this.glbAnimated=!0,this.config.glbAnimated=!0,this.glbAnimator.loop=this.config.animationLoop,this._glbInterleavedData=new Float32Array(e.vertexCount*8);try{await this.glbAnimator.initGPUSkinning(this.device,this.glbVertexBuffer,e.texCoords)}catch(r){console.warn("GPU skinning init failed, using CPU fallback:",r)}globalThis.__HZFX_DEBUG&&console.log(`GLB animated model loaded: ${e.animationData.animations.length} animations`)}else this.glbAnimator=null,this.glbAnimated=!1,this.config.glbAnimated=!1,this._glbInterleavedData=null;globalThis.__HZFX_DEBUG&&console.log(`GLB model loaded: ${e.vertexCount} vertices, ${e.indexCount} indices`)}catch(e){throw console.error("Failed to load GLB model:",e),e}}resetGLBModel(){this.glbVertexBuffer&&(this.glbVertexBuffer.destroy(),this.glbVertexBuffer=null),this.glbIndexBuffer&&(this.glbIndexBuffer.destroy(),this.glbIndexBuffer=null),this.glbIndexCount=0,this.glbIndexFormat="uint16",this.glbMeshData=null,this.glbRawArrayBuffer=null,this.glbAnimator=null,this.glbAnimated=!1,this.config.glbAnimated=!1,this._glbInterleavedData=null,this.config.glbFileName=null,this.config.glbHasTexture=!1,this.config.useGlbTexture=!1,this.config.glbModelEnabled=!1,this.config.textureType="image"}setSimulationTransform(t){if(t.position&&(this._simPosition[0]=t.position[0],this._simPosition[1]=t.position[1],this._simPosition[2]=t.position[2]),t.rotation){this._simRotX=t.rotation[0]||0,this._simRotZ=t.rotation[1]||0,this._simRotY=t.rotation[2]||0;const e=Math.cos(this._simRotX),i=Math.sin(this._simRotX),r=Math.cos(this._simRotZ),n=Math.sin(this._simRotZ),a=Math.cos(this._simRotY),o=Math.sin(this._simRotY);this._simRotMatrix=[a*r,-a*n*e+o*i,a*n*i+o*e,n,r*e,-r*i,-o*r,o*n*e+a*i,-o*n*i+a*e]}else this._simRotMatrix=null,this._simRotX=0,this._simRotZ=0,this._simRotY=0;t.velocity&&(this._simVelocity[0]=t.velocity[0],this._simVelocity[1]=t.velocity[1],this._simVelocity[2]=t.velocity[2])}clearSimulationTransform(){this._simPosition[0]=this._simPosition[1]=this._simPosition[2]=0,this._simVelocity[0]=this._simVelocity[1]=this._simVelocity[2]=0,this._simRotMatrix=null,this._simRotX=0,this._simRotZ=0}updateAnimatedGLBBuffer(){if(!this.glbAnimator||!this.glbAnimator.playing)return!1;if(this.glbAnimator._gpuSkinningReady)return!0;const t=this.glbAnimator.skinnedPositions,e=this.glbAnimator.skinnedNormals,i=this.glbMeshData.texCoords;for(let r=0;r<this.glbMeshData.vertexCount;r++){const n=r*8,a=r*3,o=r*2;this._glbInterleavedData[n]=t[a],this._glbInterleavedData[n+1]=t[a+1],this._glbInterleavedData[n+2]=t[a+2],this._glbInterleavedData[n+3]=e[a],this._glbInterleavedData[n+4]=e[a+1],this._glbInterleavedData[n+5]=e[a+2],i?(this._glbInterleavedData[n+6]=i[o],this._glbInterleavedData[n+7]=i[o+1]):(this._glbInterleavedData[n+6]=0,this._glbInterleavedData[n+7]=0)}return this.device.queue.writeBuffer(this.glbVertexBuffer,0,this._glbInterleavedData),!0}updateAppearanceUniform(){if(this.destroyed)return;let t=0;this.config.rotationMode==="random"?t=1:this.config.rotationMode==="velocity"?t=2:this.config.rotationMode==="oriented"?t=3:this.config.rotationMode==="cylindrical"&&(t=4);const e=Vr[this.config.particleShape]??0,i=this._appearanceData;i[0]=this.config.fadeEnabled?1:0,i[1]=this.config.randomColorEnabled?2:this.config.colorTransitionEnabled?1:0,i[2]=this.config.particleSize,i[3]=this.config.textureEnabled?1:0,i[4]=this.config.particleColor[0],i[5]=this.config.particleColor[1],i[6]=this.config.particleColor[2],i[7]=this.config.rotation||0,i[8]=this.config.startColor[0],i[9]=this.config.startColor[1],i[10]=this.config.startColor[2],i[11]=t,i[12]=this.config.endColor[0],i[13]=this.config.endColor[1],i[14]=this.config.endColor[2],i[15]=this.config.minRotation||0,i[16]=this.config.maxRotation||90,i[17]=this.config.aspectRatio||1,i[18]=this.config.randomSize?1:0,i[19]=this.config.minSize||.1,i[20]=this.config.maxSize||.5,i[21]=this.config.fadeSizeEnabled?1:0,i[22]=this.config.opacity!==void 0?this.config.opacity:1,i[23]=this.config.increaseSizeEnabled?1:0,i[24]=this.config.sizeLifetimeSpeed??1,i[25]=e,i[26]=0,i[27]=this.config.pulseEnabled?1:0,i[28]=this.config.pulseAmplitude??.5,i[29]=this.config.pulseFrequency??1,i[30]=this.config.pulsePhaseRandom??0,i[31]=this.config.pulseOpacity?1:0,i[32]=this.config.particleShapeRotationX||0,i[33]=this.config.particleShapeRotationY||0,i[34]=this.config.particleShapeRotationZ||0,i[35]=0;const r=this.config.followSystemTranslation??!0;i[36]=r?this._simPosition[0]:0,i[37]=r?this._simPosition[1]:0,i[38]=r?this._simPosition[2]:0,i[39]=0,i[40]=this._simRotX,i[41]=this._simRotZ,i[42]=this.config.velocityStretchEnabled?1:0,i[43]=this.config.velocityStretchFactor??1,i[44]=this.config.noiseDistortEnabled?1:0,i[45]=this.config.noiseTilingX??3,i[46]=this.config.noiseTilingY??3,i[47]=this.config.noiseSpeed??-1.5,i[48]=this.config.noiseAmplitude??.08,i[49]=r?this._simVelocity[0]:0,i[50]=r?this._simVelocity[1]:0,i[51]=r?this._simVelocity[2]:0,i[52]=this.config.orientX??0,i[53]=this.config.orientY??0,i[54]=this.config.orientZ??0,i[55]=0,this.device.queue.writeBuffer(this.appearanceUniformBuffer,0,i)}updateBloomIntensity(){const t=this._bloomIntensityData;t[0]=this.config.bloomIntensity||1;const e=this.config.bloomColor||[1,1,1];t[4]=e[0],t[5]=e[1],t[6]=e[2],this.device.queue.writeBuffer(this.bloomIntensityBuffer,0,t)}spawnParticles(t){if(this.activeParticles=0,this.currentEmissionTime=0,this.emissionAccumulator=0,this._newEmissions.length=0,this._pendingFollowEmissions=this._emptyEmissions,this._scriptFrame=0,this._scriptTime=0,this._scriptReadbackPending=!1,this._scriptReadbackReady=!1,this._scriptConfigRestored=!1,this._particleScript&&(this._particleScript._configSnapshot?(this._particleScript.restoreConfig(this.config),this.config.gravityEnabled&&this.setGravity(this.config.gravityStrength),this.config.dampingEnabled&&this.physics.setDamping(this.config.dampingStrength),this.config.attractorEnabled&&this.setAttractor(this.config.attractorStrength,this.config.attractorPosition,this.config.attractorReverse),this.updateAppearanceUniform(),this.updateBloomIntensity()):this._particleScript.snapshotConfig(this.config)),typeof t=="function"&&t(this),this.device.queue.writeBuffer(this.trailBuffer,0,this._trailResetData,0,this.MAX_PARTICLES*4),this.glbAnimator&&(this.glbAnimator.currentTime=0,this.glbAnimator.playing=!0),this.config.followSystemId){this.emitting=!0,this.particleCount=this.MAX_PARTICLES;return}if(this.config.burstMode){const e=this.config.particleCount;this.particleCount=e;let i=0;const r=500;for(let n=0;n<e;n++)if(this.emitParticle(),i++,i>=r||n===e-1){const a=n-i+1,o=a*8,l=a*4;this.device.queue.writeBuffer(this.instanceBuffer,o*4,this.particleData,o,i*8),this.device.queue.writeBuffer(this.velocityBuffer,l*4,this.particleVelocities,l,i*4),i=0}this.emitting=!1}else{this.emitting=!0;const e=this.config.lifetime||5,i=this.config.emissionDurationInfinite?e:Math.min(this.config.emissionDuration||10,e);this.particleCount=Math.min(Math.ceil((this.config.emissionRate||10)*i),this.MAX_PARTICLES)}}get effectiveEmissionDuration(){return this.config.emissionDurationInfinite?1/0:this.config.emissionDuration??10}_applySimTransformToParticle(t){this._emitSimRotY=this._simRotY||0;const e=t*8,i=t*4;if(this._simRotMatrix){const r=this._simRotMatrix,n=this.particleData[e],a=this.particleData[e+1],o=this.particleData[e+2],l=this.particleVelocities[i],c=this.particleVelocities[i+1],d=this.particleVelocities[i+2];this.particleData[e]=r[0]*n+r[1]*a+r[2]*o,this.particleData[e+1]=r[3]*n+r[4]*a+r[5]*o,this.particleData[e+2]=r[6]*n+r[7]*a+r[8]*o,this.particleVelocities[i]=r[0]*l+r[1]*c+r[2]*d,this.particleVelocities[i+1]=r[3]*l+r[4]*c+r[5]*d,this.particleVelocities[i+2]=r[6]*l+r[7]*c+r[8]*d}(this.config.followSystemTranslation??!0)||(this.particleData[e]+=this._simPosition[0],this.particleData[e+1]+=this._simPosition[1],this.particleData[e+2]+=this._simPosition[2])}emitParticle(){if(this.activeParticles>=this.particleCount)return!1;this.emitter.emitParticle(this.particleData,this.activeParticles,this.particleVelocities);const t=this.activeParticles*8,e=this.activeParticles*4;return this._applySimTransformToParticle(this.activeParticles),this._newEmissions.push(this.particleData[t],this.particleData[t+1],this.particleData[t+2],this.particleVelocities[e],this.particleVelocities[e+1],this.particleVelocities[e+2]),this.activeParticles++,!0}emitFollowerParticle(t,e,i){if(this.activeParticles>=this.particleCount)return!1;const r=this.activeParticles*8,n=t+(this.config.emissionPositionX||0),a=e+(this.config.emissionPositionY||0),o=i+(this.config.emissionPositionZ||0);this.particleData[r]=n,this.particleData[r+1]=a,this.particleData[r+2]=o;const l=this.activeParticles*4;return this.emitter.calculateVelocity(n,a,o,this.particleVelocities,l),this.emitter.setParticleColor(this.particleData,r),this.emitter.setParticleLifetime(this.particleData,r),this.activeParticles++,!0}updateParticles(t,e,i=0){const r=this.config.startAt||0,n=r>0&&i<r;if(this._particleScript&&this._scriptReadbackReady){this._scriptReadbackReady=!1,this._scriptTime+=t,this._scriptFrame++;const d=this.config.emissionDurationInfinite?1/0:(this.config.emissionDuration||0)+(this.config.lifetime||0);if(d>0&&this._scriptTime>=d&&!this._scriptConfigRestored)this._scriptConfigRestored=!0,this._particleScript._configSnapshot&&(this._particleScript.restoreConfig(this.config),this.updateAppearanceUniform(),this.updateBloomIntensity(),this.config.gravityEnabled&&this.setGravity(this.config.gravityStrength),this.config.dampingEnabled&&this.physics.setDamping(this.config.dampingStrength),this.config.attractorEnabled&&this.setAttractor(this.config.attractorStrength,this.config.attractorPosition,this.config.attractorReverse));else if(!this._scriptConfigRestored){const S=d>0?Math.ceil(d/.016666666666666666):0,{configDirty:b,particlesDirty:f}=this._particleScript.execute(t,this._scriptTime,this._scriptFrame,S,this._scriptParticleData,this._scriptVelocityData,this.activeParticles);f&&this.activeParticles>0&&(this.device.queue.writeBuffer(this.instanceBuffer,0,this._scriptParticleData,0,this.activeParticles*8),this.device.queue.writeBuffer(this.velocityBuffer,0,this._scriptVelocityData,0,this.activeParticles*4)),b&&(this.updateAppearanceUniform(),this.updateBloomIntensity(),this.config.gravityEnabled&&this.setGravity(this.config.gravityStrength),this.config.dampingEnabled&&this.physics.setDamping(this.config.dampingStrength),this.config.attractorEnabled&&this.setAttractor(this.config.attractorStrength,this.config.attractorPosition,this.config.attractorReverse))}}this.physics.physicsAccumulator+=t;const a=performance.now()/1e3,l=a-this.physics.lastUpdateTime>1/this.physics.minUpdatesPerSecond,c=this.activeParticles;if(!n&&!this.emitting&&!this.config.burstMode&&!this.config.followSystemId&&this.currentEmissionTime<this.effectiveEmissionDuration&&(this.emitting=!0),!n&&this.emitting)if(this.currentEmissionTime+=t,this.currentEmissionTime<this.effectiveEmissionDuration){const d=this.activeParticles;let S=!1;if(this.config.followSystemId){if(this._pendingFollowEmissions.length>0){const b=this._pendingFollowEmissions.length/6;for(let f=0;f<b;f++){const v=f*6;if(this.emitFollowerParticle(this._pendingFollowEmissions[v],this._pendingFollowEmissions[v+1],this._pendingFollowEmissions[v+2]))S=!0;else break}}}else{let b=0;const f=Math.max(0,this.config.emissionRate||0);this.activeParticles<this.particleCount&&f>0?(this.emissionAccumulator+=f*t,b=Math.floor(this.emissionAccumulator+1e-9),b>0&&(this.emissionAccumulator-=b)):this.activeParticles>=this.particleCount&&(this.emissionAccumulator=0);for(let v=0;v<b;v++)if(this.emitParticle())S=!0;else{this.emissionAccumulator=0;break}}if(S){const b=this.activeParticles-d,f=d*8,v=d*4;this.device.queue.writeBuffer(this.instanceBuffer,f*4,this.particleData,f,b*8),this.device.queue.writeBuffer(this.velocityBuffer,v*4,this.particleVelocities,v,b*4)}}else this.emitting=!1,this.currentEmissionTime=this.config.emissionDuration;for(;this.physics.physicsAccumulator>=this.physics.fixedDeltaTime;)this.physics.updatePhysics(this.physics.fixedDeltaTime,c,this.config,this.instanceBuffer,this.velocityBuffer,e),this.physics.physicsAccumulator-=this.physics.fixedDeltaTime,this.physics.physicsClock+=this.physics.fixedDeltaTime;l&&c>0&&(this.physics.updatePhysics(this.physics.fixedDeltaTime,c,this.config,this.instanceBuffer,this.velocityBuffer,e),this.physics.lastUpdateTime=a),this.frameCount++,(this.activeParticles>=this.particleCount||this.frameCount%300===0)&&this.readbackAndProcessParticles(),this._particleScript&&this.activeParticles>0&&!this._scriptReadbackPending&&(this._scriptReadbackPending=!0,this.physics.readbackForScript(this.activeParticles,this._scriptParticleData,this._scriptVelocityData,this.instanceBuffer,this.velocityBuffer).then(d=>{this._scriptReadbackPending=!1,d.shouldUpdate&&(this._scriptReadbackReady=!0)}).catch(()=>{this._scriptReadbackPending=!1}))}async readbackAndProcessParticles(){if(!(this.destroyed||this.activeParticles<=0))try{const t=await this.physics.readbackAndProcessParticles(this.activeParticles,this.particleData,this.particleVelocities,this.instanceBuffer,this.velocityBuffer);if(this.destroyed||!this.particleData||!this.particleVelocities||!t.shouldUpdate)return;let e=0,i=!1;for(let r=0;r<this.activeParticles;r++){const n=this.particleData[r*8+6],a=this.particleData[r*8+7];if(n>=a){if(this.emitting&&this.currentEmissionTime<this.effectiveEmissionDuration&&e<this.particleCount){this.respawnParticle(r,e),e++,i=!0;continue}continue}if(e!==r){const o=r*8,l=e*8;this.particleData.copyWithin(l,o,o+8);const c=r*4,d=e*4;this.particleVelocities.copyWithin(d,c,c+4),i=!0}e++}(e!==this.activeParticles||i)&&(this.activeParticles=e,this.device.queue.writeBuffer(this.instanceBuffer,0,this.particleData,0,this.activeParticles*8),this.device.queue.writeBuffer(this.velocityBuffer,0,this.particleVelocities,0,this.activeParticles*4))}catch(t){t&&t.name==="AbortError"||console.error("Error reading back particle data:",t)}}respawnParticle(t,e){!this.emitting||this.currentEmissionTime>=this.effectiveEmissionDuration||this.config.followSystemId||(this.emitter.emitParticle(this.particleData,e,this.particleVelocities),this._applySimTransformToParticle(e))}updateBuffers(){this.destroyed||!this.particleData||this.activeParticles>0&&this.device.queue.writeBuffer(this.instanceBuffer,0,this.particleData,0,this.activeParticles*8)}updateParticleColors(){if(!(this.destroyed||!this.particleData)){for(let t=0;t<this.activeParticles;t++){const e=t*8;if(this.config.randomColorEnabled&&this.config.randomColors.length>0){const i=this.config.randomColors,r=i[Math.floor(Math.random()*i.length)];this.particleData[e+3]=r[0],this.particleData[e+4]=r[1],this.particleData[e+5]=r[2]}else this.config.colorTransitionEnabled?(this.particleData[e+3]=this.config.startColor[0],this.particleData[e+4]=this.config.startColor[1],this.particleData[e+5]=this.config.startColor[2]):(this.particleData[e+3]=this.config.particleColor[0],this.particleData[e+4]=this.config.particleColor[1],this.particleData[e+5]=this.config.particleColor[2])}this.activeParticles>0&&this.device.queue.writeBuffer(this.instanceBuffer,0,this.particleData,0,this.activeParticles*8)}}updateParticleVelocities(){for(let t=0;t<this.activeParticles;t++){const e=t*8,i=t*4,r=this.particleData[e],n=this.particleData[e+1],a=this.particleData[e+2],o=this.particleVelocities[i],l=this.particleVelocities[i+1],c=this.particleVelocities[i+2],d=Math.sqrt(o*o+l*l+c*c);if(d>.001){const S=this.config.particleSpeed*2;this.particleVelocities[i]=o/d*S,this.particleVelocities[i+1]=l/d*S,this.particleVelocities[i+2]=c/d*S}else{const S=Math.sqrt(r*r+n*n+a*a);if(S>.001){const b=this.config.particleSpeed*2;this.particleVelocities[i]=r/S*b,this.particleVelocities[i+1]=n/S*b,this.particleVelocities[i+2]=a/S*b}else this.particleVelocities[i]=0,this.particleVelocities[i+1]=this.config.particleSpeed*2,this.particleVelocities[i+2]=0}}this.activeParticles>0&&this.device.queue.writeBuffer(this.velocityBuffer,0,this.particleVelocities,0,this.activeParticles*4)}async readbackForRendering(t,e){return this.physics.readbackForRendering(this.activeParticles,t,e,this.instanceBuffer,this.velocityBuffer)}destroy(){this.destroyed=!0,this.instanceBuffer.destroy(),this.velocityBuffer.destroy(),this.trailBuffer.destroy(),this.appearanceUniformBuffer.destroy(),this.bloomIntensityBuffer.destroy(),this.physics.destroy(),this.glbVertexBuffer&&(this.glbVertexBuffer.destroy(),this.glbVertexBuffer=null),this.glbIndexBuffer&&(this.glbIndexBuffer.destroy(),this.glbIndexBuffer=null),this.textureManager.destroyTexture(this.particleTexture),this._particleScript&&(this._particleScript.destroy(),this._particleScript=null),this.glbAnimator=null,this.glbMeshData=null,this.glbRawArrayBuffer=null,this.particleData=null,this.particleVelocities=null,this._scriptParticleData=null,this._scriptVelocityData=null}setGravity(t){this.physics.setGravity(t)}setAttractor(t,e,i=this.config.attractorReverse){this.config.attractorStrength=t,this.config.attractorPosition=e,this.config.attractorReverse=!!i,this.physics.setAttractor(t,e,i)}setConfinement(t){const e=t.center||this.config.confinementCenter||[0,0,0],i=t.space==="local"?[this.config.emissionPositionX||0,this.config.emissionPositionY||0,this.config.emissionPositionZ||0]:[0,0,0],r=[i[0]+(e[0]||0),i[1]+(e[1]||0),i[2]+(e[2]||0)];this.physics.setConfinement({...t,center:r})}setSoftBoundary(t){this.physics.setSoftBoundary(t)}}class us{constructor(t){this.device=t,this.particleSystems=[],this.activeSystemIndex=0,this.systemCounter=1,this.onSystemCreated=null,this.loop=void 0,this.clock=new ls({loop:!!this.loop}),this.ready=!0}createParticleSystem(t={}){const e=this.systemCounter++,i=t.name||`System ${e+1}`,r={...t,name:i,id:e},n=new kt(this.device,r);return this.particleSystems.push({system:n,config:r}),this.particleSystems.length===1&&(this.activeSystemIndex=0),this.onSystemCreated&&typeof this.onSystemCreated=="function"&&this.onSystemCreated(e,r),e}getActiveSystem(){return this.particleSystems.length===0?null:this.particleSystems[this.activeSystemIndex].system}getActiveConfig(){return this.particleSystems.length===0?null:this.particleSystems[this.activeSystemIndex].config}setActiveSystem(t){return t>=0&&t<this.particleSystems.length?(this.activeSystemIndex=t,!0):!1}getSystemById(t){return this.particleSystems.find(({config:e})=>e.id===t)||null}destroy(){for(const{system:t}of this.particleSystems)t.destroy();this.particleSystems=[],this.activeSystemIndex=0}removeSystem(t){if(t>=0&&t<this.particleSystems.length){const e=this.particleSystems[t].config;this.particleSystems[t].system.destroy(),this.particleSystems.splice(t,1);const i=e.id;for(const{config:r}of this.particleSystems)r.followSystemId===i&&(r.followSystemId=null);return this.particleSystems.length===0?this.activeSystemIndex=0:t<=this.activeSystemIndex&&(this.activeSystemIndex=Math.max(0,this.activeSystemIndex-1)),!0}return!1}respawnAllSystems(){var t;(t=this.clock)==null||t.reset();for(const{system:e,config:i}of this.particleSystems)e.spawnParticles(()=>this._applyKeyframesToSystem(e,i,0))}getTotalDuration(){let t=0;for(const{config:e}of this.particleSystems){if(e.emissionDurationInfinite)return 1/0;const i=e.lifetime||5,r=(e.burstMode||e.oneOnlyMode?i:(e.emissionDuration||10)+i)+(e.startAt||0);r>t&&(t=r)}return t||1}updateAllSystems(t){const e=this.device.createCommandEncoder({label:"BatchedPhysicsEncoder"});let i=!1;const r=this.clock?this.clock.currentTime:0,n=this.clock?this.clock.duration:0;if(this.clock&&n>0&&isFinite(n)){const a=Math.min(1,this.clock.currentTime/n);for(const{system:o,config:l}of this.particleSystems)this._applyKeyframesToSystem(o,l,a)}for(const{system:a,config:o}of this.particleSystems){if(o.hidden||o.followSystemId)continue;const l=a.activeParticles>0;a.updateParticles(t,e,r),(l||a.activeParticles>0)&&(i=!0)}for(const{system:a,config:o}of this.particleSystems){if(o.hidden||!o.followSystemId)continue;const l=this.getSystemById(o.followSystemId);l&&(a._pendingFollowEmissions=l.system._newEmissions);const c=a.activeParticles>0;a.updateParticles(t,e,r),(c||a.activeParticles>0)&&(i=!0)}i&&this.device.queue.submit([e.finish()]);for(const{system:a}of this.particleSystems)a._newEmissions.length=0,a._pendingFollowEmissions=a._emptyEmissions}getSystemsList(){return this.particleSystems.map(({config:t},e)=>({name:t.name,id:t.id,index:e,isActive:e===this.activeSystemIndex,hidden:t.hidden||!1}))}duplicateActiveSystem(){if(this.particleSystems.length===0)return-1;const t=this.getActiveConfig(),e=JSON.parse(JSON.stringify(t));return e.name=`${t.name} (Copy)`,e.onAppearanceChange=null,e.onColorChange=null,e.onSizeChange=null,e.onSpeedChange=null,e.onPhysicsChange=null,e.onBloomIntensityChange=null,e.onRespawn=null,e.getActiveSystem=null,delete e.id,this.createParticleSystem(e)}async replaceSystems(t){var e;if(!t||!t.systems||!Array.isArray(t.systems))return console.error("Invalid scene data provided"),!1;this.ready=!1;try{this.particleSystems=[],this.systemCounter=1;for(const r of t.systems){const n=this.systemCounter++,a={...r,id:n},o=new kt(this.device,a);this.particleSystems.push({system:o,config:a})}const i={};t.systems.forEach((r,n)=>{i[r.id]=this.particleSystems[n].config.id});for(const{config:r}of this.particleSystems)r.followSystemId&&i[r.followSystemId]!==void 0&&(r.followSystemId=i[r.followSystemId]);t.activeSystemIndex!==void 0&&t.activeSystemIndex>=0&&t.activeSystemIndex<this.particleSystems.length?this.activeSystemIndex=t.activeSystemIndex:this.activeSystemIndex=0,this.loop=t.loop;for(const{system:r,config:n}of this.particleSystems)if(n.glbModelEnabled)try{let a=null;if(n.glbModelData)a=ji(n.glbModelData);else if(n.glbFileName){const o=await fetch(`/${n.glbFileName}`);o.ok?a=await o.arrayBuffer():console.warn(`GLB file not found: ${n.glbFileName}`)}if(a){if(await r.setGLBModel(a),n.animationIndex!==void 0&&r.glbAnimator&&r.glbAnimator.setAnimation(n.animationIndex),n.animationSpeed!==void 0&&r.glbAnimator&&(r.glbAnimator.speed=n.animationSpeed),n.animationLoop!==void 0&&r.glbAnimator&&(r.glbAnimator.loop=n.animationLoop),n.useGlbTexture&&(n.textureEnabled=!0),n.useGlbTexture&&((e=r.glbMeshData)!=null&&e.hasBaseColorTexture))try{const o=await oi(a);if(o){const l=await createImageBitmap(o.imageBlob);await r.setTexture(l),globalThis.__HZFX_DEBUG&&console.log(`GLB embedded texture restored for ${n.name}`)}}catch(o){console.warn(`Failed to restore GLB texture for ${n.name}:`,o),n.useGlbTexture=!1}}else n.glbModelEnabled=!1}catch(a){console.warn(`Failed to load GLB for ${n.name}:`,a),n.glbModelEnabled=!1}for(const{system:r,config:n}of this.particleSystems)if(n.textureEnabled&&!n.glbModelEnabled&&n.textureImageData)try{const a=new Image;await new Promise((l,c)=>{a.onload=l,a.onerror=c,a.src=n.textureImageData});const o=await createImageBitmap(a);await r.setTexture(o)}catch(a){console.warn(`Failed to restore texture for ${n.name}:`,a),n.textureEnabled=!1}for(const{system:r,config:n}of this.particleSystems)r.updateAppearanceUniform();return this.respawnAllSystems(),!0}catch(i){return console.error("Error replacing systems:",i),!1}finally{this.ready=!0}}async addSystems(t,e=[0,0,0]){var r;if(!t||!t.systems||!Array.isArray(t.systems))return console.error("Invalid scene data provided"),!1;this.ready=!1;const i=[];try{for(const o of t.systems){const l=this.systemCounter++;i.push(l);const c={...o,id:l,emissionPositionX:(o.emissionPositionX||0)+e[0],emissionPositionY:(o.emissionPositionY||0)+e[1],emissionPositionZ:(o.emissionPositionZ||0)+e[2]};o.attractorEnabled&&o.attractorPosition&&(c.attractorPosition=[o.attractorPosition[0]+e[0],o.attractorPosition[1]+e[1],o.attractorPosition[2]+e[2]]),o.confinementEnabled&&o.confinementSpace==="world"&&Array.isArray(o.confinementCenter)&&(c.confinementCenter=[(o.confinementCenter[0]||0)+e[0],(o.confinementCenter[1]||0)+e[1],(o.confinementCenter[2]||0)+e[2]]);const d=new kt(this.device,c);this.particleSystems.push({system:d,config:c}),this.onSystemCreated&&typeof this.onSystemCreated=="function"&&this.onSystemCreated(l,c)}const n=this.particleSystems.length-t.systems.length,a={};t.systems.forEach((o,l)=>{a[o.id]=this.particleSystems[n+l].config.id});for(let o=n;o<this.particleSystems.length;o++){const{config:l}=this.particleSystems[o];l.followSystemId&&a[l.followSystemId]!==void 0&&(l.followSystemId=a[l.followSystemId])}for(const{system:o,config:l}of this.particleSystems)if(l.glbModelEnabled&&!o.glbMeshData)try{let c=null;if(l.glbModelData)c=ji(l.glbModelData);else if(l.glbFileName){const d=await fetch(`/${l.glbFileName}`);d.ok?c=await d.arrayBuffer():console.warn(`GLB file not found: ${l.glbFileName}`)}if(c){if(await o.setGLBModel(c),l.animationIndex!==void 0&&o.glbAnimator&&o.glbAnimator.setAnimation(l.animationIndex),l.animationSpeed!==void 0&&o.glbAnimator&&(o.glbAnimator.speed=l.animationSpeed),l.animationLoop!==void 0&&o.glbAnimator&&(o.glbAnimator.loop=l.animationLoop),l.useGlbTexture&&(l.textureEnabled=!0),l.useGlbTexture&&((r=o.glbMeshData)!=null&&r.hasBaseColorTexture))try{const d=await oi(c);if(d){const S=await createImageBitmap(d.imageBlob);await o.setTexture(S),globalThis.__HZFX_DEBUG&&console.log(`GLB embedded texture restored for ${l.name}`)}}catch(d){console.warn(`Failed to restore GLB texture for ${l.name}:`,d),l.useGlbTexture=!1}}else l.glbModelEnabled=!1}catch(c){console.warn(`Failed to load GLB for ${l.name}:`,c),l.glbModelEnabled=!1}for(const{system:o,config:l}of this.particleSystems)if(l.textureEnabled&&!l.glbModelEnabled&&l.textureImageData&&!o._textureRestored)try{const c=new Image;await new Promise((S,b)=>{c.onload=S,c.onerror=b,c.src=l.textureImageData});const d=await createImageBitmap(c);await o.setTexture(d),o._textureRestored=!0}catch(c){console.warn(`Failed to restore texture for ${l.name}:`,c),l.textureEnabled=!1}return i}catch(n){return console.error("Error adding systems:",n),!1}finally{this.ready=!0}}_applyKeyframesToSystem(t,e,i){const r=e.keyframes;if(!r||e.keyframesEnabled===!1)return;let n=!1,a=!1,o=!1,l=!1,c=!1;for(const d of Fr){const S=r[d];if(!S||!S.length)continue;const b=Gr(S,i);if(b!==void 0){if(d==="damping"){e.dampingStrength=b,l=!0;continue}e[d]=b,(d==="particleSize"||d==="opacity")&&(n=!0),d==="bloomIntensity"&&(a=!0),d==="gravityStrength"&&(o=!0),d==="dampingStrength"&&(l=!0),(d==="attractorStrength"||d==="attractorReverse")&&(c=!0)}}if(r.particleColor&&r.particleColor.length){const d=e.particleColor,S=d&&typeof d.length=="number"&&d.length>=3?d:void 0,b=Dr(r.particleColor,i,S);b&&(e.particleColor=b,n=!0)}n&&t.updateAppearanceUniform(),a&&t.updateBloomIntensity(),o&&e.gravityEnabled&&t.setGravity(e.gravityStrength),l&&e.dampingEnabled&&t.physics.setDamping(e.dampingStrength),c&&e.attractorEnabled&&e.attractorPosition&&t.setAttractor(e.attractorStrength,e.attractorPosition,e.attractorReverse)}}async function ds(s){if(!s)throw new Error("canvas is required for initWebGPU()");if(!navigator.gpu)throw new Error("WebGPU not supported on this browser.");const t=s.getContext("webgpu"),i=await(await navigator.gpu.requestAdapter()).requestDevice(),r=navigator.gpu.getPreferredCanvasFormat();return t.configure({device:i,format:r,alphaMode:"premultiplied"}),{device:i,context:t,format:r,canvas:s}}const Xe="rgba16float",qi=.5,fs=(s,t)=>[Math.max(1,Math.round(s*qi)),Math.max(1,Math.round(t*qi))];function li(s,t,e,i){const r=s.createTexture({size:[e,i],format:Xe,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING,mipLevelCount:1,sampleCount:1}),[n,a]=fs(e,i),o=s.createTexture({size:[n,a],format:Xe,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING,mipLevelCount:1,sampleCount:1}),l=s.createTexture({size:[n,a],format:Xe,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING,mipLevelCount:1,sampleCount:1});return{sceneTexture:r,bloomTexA:o,bloomTexB:l}}function ci(s,t,e){return s.createTexture({size:[t,e],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT})}function pt(s,t,e){const i=s.createBuffer({size:t.byteLength,usage:e,mappedAtCreation:!0});return new t.constructor(i.getMappedRange()).set(t),i.unmap(),i}const ps=`
|
|
897
|
+
};`,r=new Function(i);this._fn=r()}catch(e){console.warn("[ParticleScript] Compilation error:",e.message),this._fn=null,this._error=!0}}execute(t,e,i,r,n,a,o){if(!this._fn||this._error)return{configDirty:!1,particlesDirty:!1};this._particles._bind(n,a,o),this._configProxy.__resetDirty();try{this._fn(t,e,i,r,this._particles,this._configProxy,ns)}catch(l){console.warn("[ParticleScript] Runtime error:",l.message)}return{configDirty:this._configProxy.__dirty,particlesDirty:this._particles._dirty}}snapshotConfig(t){const e={};for(const i of Ct){const r=t[i];r!==void 0&&(e[i]=Array.isArray(r)?[...r]:r)}this._configSnapshot=e}restoreConfig(t){if(this._configSnapshot){for(const e of Ct)if(e in this._configSnapshot){const i=this._configSnapshot[e];t[e]=Array.isArray(i)?[...i]:i}}}destroy(){this._fn=null,this._particles=null,this._configProxy=null,this._configSnapshot=null}}async function as(s){const t=new DataView(s);if(t.getUint32(0,!0)!==1179937895)throw new Error("Invalid GLB file: incorrect magic number");const i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i} (only version 2 is supported)`);const r=t.getUint32(8,!0);let n=12,a=null,o=null;for(;n<r;){const T=t.getUint32(n,!0),D=t.getUint32(n+4,!0),F=s.slice(n+8,n+8+T);if(D===1313821514){const se=new TextDecoder("utf-8").decode(F);a=JSON.parse(se)}else D===5130562&&(o=F);n+=8+T}if(!a)throw new Error("GLB file missing JSON chunk");if(!a.meshes||a.meshes.length===0)throw new Error("GLB file contains no meshes");const c=a.meshes[0].primitives[0];if(!c)throw new Error("First mesh has no primitives");const d=c.attributes.POSITION;if(d===void 0)throw new Error("Mesh primitive missing POSITION attribute");const S=si(a,o,d,3,5126);let b;if(c.attributes.NORMAL!==void 0)b=si(a,o,c.attributes.NORMAL,3,5126);else{const T=c.indices;if(T===void 0)throw new Error("Cannot generate normals without indices");const D=Xi(a,o,T);b=Pr(S,D)}const f=c.indices;if(f===void 0)throw new Error("Mesh primitive missing indices");const v=Xi(a,o,f),U=S.length/3,z=v.length;let G=null;c.attributes.TEXCOORD_0!==void 0&&(G=si(a,o,c.attributes.TEXCOORD_0,2,5126));let M=!1;if(a.materials&&a.materials.length>0){const T=a.materials[0];T.pbrMetallicRoughness&&T.pbrMetallicRoughness.baseColorTexture!==void 0&&(M=!0)}let Z=null;if(a.skins&&a.skins.length>0)try{Z=Tr(a,o,c),globalThis.__HZFX_DEBUG&&console.log("Animation data extracted:",Z)}catch(T){console.warn("Failed to extract animation data:",T)}return{positions:S,normals:b,indices:v,texCoords:G,vertexCount:U,indexCount:z,animationData:Z,hasBaseColorTexture:M}}function si(s,t,e,i,r){const n=s.accessors[e],o={SCALAR:1,VEC2:2,VEC3:3,VEC4:4}[n.type];if(o!==i)throw new Error(`Attribute accessor type mismatch: expected ${i} components, got ${o}`);if(n.componentType!==r)throw new Error(`Attribute component type mismatch: expected ${r}, got ${n.componentType}`);const c=(s.bufferViews[n.bufferView].byteOffset||0)+(n.byteOffset||0),d=n.count,S=new DataView(t,c,d*i*4),b=new Float32Array(d*i);for(let f=0;f<d*i;f++)b[f]=S.getFloat32(f*4,!0);return b}function Xi(s,t,e){const i=s.accessors[e];if(i.type!=="SCALAR")throw new Error(`Indices accessor must be SCALAR, got ${i.type}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count;if(i.componentType===5123){const o=new DataView(t,n,a*2),l=new Uint16Array(a);for(let c=0;c<a;c++)l[c]=o.getUint16(c*2,!0);return l}else if(i.componentType===5125){const o=new DataView(t,n,a*4),l=new Uint32Array(a);for(let c=0;c<a;c++)l[c]=o.getUint32(c*4,!0);return l}else throw new Error(`Unsupported index component type: ${i.componentType}`)}function Pr(s,t){const e=new Float32Array(s.length);for(let i=0;i<t.length;i+=3){const r=t[i]*3,n=t[i+1]*3,a=t[i+2]*3,o=[s[r],s[r+1],s[r+2]],l=[s[n],s[n+1],s[n+2]],c=[s[a],s[a+1],s[a+2]],d=[l[0]-o[0],l[1]-o[1],l[2]-o[2]],S=[c[0]-o[0],c[1]-o[1],c[2]-o[2]],b=[d[1]*S[2]-d[2]*S[1],d[2]*S[0]-d[0]*S[2],d[0]*S[1]-d[1]*S[0]],f=Math.sqrt(b[0]*b[0]+b[1]*b[1]+b[2]*b[2]);f>0&&(b[0]/=f,b[1]/=f,b[2]/=f),e[r]=e[n]=e[a]=b[0],e[r+1]=e[n+1]=e[a+1]=b[1],e[r+2]=e[n+2]=e[a+2]=b[2]}return e}function _r(s,t,e){const i=s.accessors[e];if(i.type!=="VEC4")throw new Error(`JOINTS_0 must be VEC4, got ${i.type}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count;if(i.componentType===5121){const o=new DataView(t,n,a*4),l=new Uint8Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getUint8(c);return l}else if(i.componentType===5123){const o=new DataView(t,n,a*8),l=new Uint8Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getUint16(c*2,!0);return l}else throw new Error(`Unsupported JOINTS_0 component type: ${i.componentType}`)}function Mr(s,t,e){const i=s.accessors[e];if(i.type!=="VEC4")throw new Error(`WEIGHTS_0 must be VEC4, got ${i.type}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count;if(i.componentType===5126){const o=new DataView(t,n,a*16),l=new Float32Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getFloat32(c*4,!0);return l}else if(i.componentType===5121){const o=new DataView(t,n,a*4),l=new Float32Array(a*4);for(let c=0;c<a*4;c++)l[c]=o.getUint8(c)/255;return l}else throw new Error(`Unsupported WEIGHTS_0 component type: ${i.componentType}`)}function wr(s,t,e){const i=s.accessors[e];if(i.type!=="MAT4")throw new Error(`Expected MAT4, got ${i.type}`);if(i.componentType!==5126)throw new Error(`Expected FLOAT component type for MAT4, got ${i.componentType}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count,o=new DataView(t,n,a*64),l=new Float32Array(a*16);for(let c=0;c<a*16;c++)l[c]=o.getFloat32(c*4,!0);return l}function Br(s,t,e){const i=s.accessors[e];if(i.type!=="SCALAR")throw new Error(`Expected SCALAR, got ${i.type}`);if(i.componentType!==5126)throw new Error(`Expected FLOAT component type for SCALAR, got ${i.componentType}`);const n=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),a=i.count,o=new DataView(t,n,a*4),l=new Float32Array(a);for(let c=0;c<a;c++)l[c]=o.getFloat32(c*4,!0);return l}function Rr(s,t,e){const i=s.accessors[e],n={VEC3:3,VEC4:4}[i.type];if(!n)throw new Error(`Expected VEC3 or VEC4, got ${i.type}`);if(i.componentType!==5126)throw new Error(`Expected FLOAT component type, got ${i.componentType}`);const o=(s.bufferViews[i.bufferView].byteOffset||0)+(i.byteOffset||0),l=i.count,c=new DataView(t,o,l*n*4),d=new Float32Array(l*n);for(let S=0;S<l*n;S++)d[S]=c.getFloat32(S*4,!0);return d}function Tr(s,t,e){const i=s.skins[0],r=i.joints,n=wr(s,t,i.inverseBindMatrices),a=e.attributes.JOINTS_0!==void 0?_r(s,t,e.attributes.JOINTS_0):null,o=e.attributes.WEIGHTS_0!==void 0?Mr(s,t,e.attributes.WEIGHTS_0):null;if(!a||!o)throw new Error("Mesh missing JOINTS_0 or WEIGHTS_0 attributes");const l=s.nodes.map(d=>({translation:d.translation||[0,0,0],rotation:d.rotation||[0,0,0,1],scale:d.scale||[1,1,1],children:d.children||[],name:d.name||""})),c=[];if(s.animations&&s.animations.length>0)for(const d of s.animations){const S=[];let b=0;for(const f of d.channels){const v=d.samplers[f.sampler],U=Br(s,t,v.input),z=Rr(s,t,v.output),G=U[U.length-1];G>b&&(b=G),S.push({targetNode:f.target.node,targetPath:f.target.path,interpolation:v.interpolation||"LINEAR",timestamps:U,values:z})}c.push({name:d.name||`Animation ${c.length}`,duration:b,channels:S})}return{joints:r,inverseBindMatrices:n,jointIndices:a,jointWeights:o,nodes:l,animations:c}}async function oi(s){const t=new DataView(s);if(t.getUint32(0,!0)!==1179937895)throw new Error("Invalid GLB file: incorrect magic number");const i=t.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);const r=t.getUint32(8,!0);let n=12,a=null,o=null;for(;n<r;){const Z=t.getUint32(n,!0),T=t.getUint32(n+4,!0),D=s.slice(n+8,n+8+Z);if(T===1313821514){const H=new TextDecoder("utf-8").decode(D);a=JSON.parse(H)}else T===5130562&&(o=D);n+=8+Z}if(!a)throw new Error("GLB file missing JSON chunk");if(!a.materials||a.materials.length===0)return null;const l=a.materials[0];if(!l.pbrMetallicRoughness||l.pbrMetallicRoughness.baseColorTexture===void 0)return null;const c=l.pbrMetallicRoughness.baseColorTexture.index;if(!a.textures||!a.textures[c])return null;const S=a.textures[c].source;if(S===void 0||!a.images||!a.images[S])return null;const b=a.images[S],f=b.mimeType||"image/png";if(b.bufferView===void 0)return null;if(!o)throw new Error("GLB file missing BIN chunk (required for embedded textures)");const v=a.bufferViews[b.bufferView],U=v.byteOffset||0,z=v.byteLength,G=o.slice(U,U+z);return{imageBlob:new Blob([G],{type:f}),mimeType:f}}function Er(s,t,e,i){return i=i||[0,0,0],i[0]=s[0]+(t[0]-s[0])*e,i[1]=s[1]+(t[1]-s[1])*e,i[2]=s[2]+(t[2]-s[2])*e,i}function Ar(s,t,e,i){i=i||[0,0,0,0];let r=s[0]*t[0]+s[1]*t[1]+s[2]*t[2]+s[3]*t[3],n=1;if(r<0&&(r=-r,n=-1),r>.9995){i[0]=s[0]+(n*t[0]-s[0])*e,i[1]=s[1]+(n*t[1]-s[1])*e,i[2]=s[2]+(n*t[2]-s[2])*e,i[3]=s[3]+(n*t[3]-s[3])*e;const d=Math.sqrt(i[0]*i[0]+i[1]*i[1]+i[2]*i[2]+i[3]*i[3]);return d>1e-4?(i[0]/=d,i[1]/=d,i[2]/=d,i[3]/=d):(i[0]=0,i[1]=0,i[2]=0,i[3]=1),i}const a=Math.acos(r),o=Math.sin(a),l=Math.sin((1-e)*a)/o,c=Math.sin(e*a)/o;return i[0]=s[0]*l+n*t[0]*c,i[1]=s[1]*l+n*t[1]*c,i[2]=s[2]*l+n*t[2]*c,i[3]=s[3]*l+n*t[3]*c,i}function Cr(s,t){const e=s[0],i=s[1],r=s[2],n=s[3],a=e+e,o=i+i,l=r+r,c=e*a,d=e*o,S=e*l,b=i*o,f=i*l,v=r*l,U=n*a,z=n*o,G=n*l,M=t||new Float32Array(16);return M[0]=1-(b+v),M[1]=d+G,M[2]=S-z,M[3]=0,M[4]=d-G,M[5]=1-(c+v),M[6]=f+U,M[7]=0,M[8]=S+z,M[9]=f-U,M[10]=1-(c+b),M[11]=0,M[12]=0,M[13]=0,M[14]=0,M[15]=1,M}const Ur=new Float32Array(16);function Ir(s,t,e,i){const r=Cr(t,Ur),n=i||new Float32Array(16);return n[0]=r[0]*e[0],n[1]=r[1]*e[0],n[2]=r[2]*e[0],n[3]=0,n[4]=r[4]*e[1],n[5]=r[5]*e[1],n[6]=r[6]*e[1],n[7]=0,n[8]=r[8]*e[2],n[9]=r[9]*e[2],n[10]=r[10]*e[2],n[11]=0,n[12]=s[0],n[13]=s[1],n[14]=s[2],n[15]=1,n}function Ni(s,t,e){const i=e||new Float32Array(16);for(let r=0;r<4;r++)for(let n=0;n<4;n++)i[r*4+n]=s[0+n]*t[r*4+0]+s[4+n]*t[r*4+1]+s[8+n]*t[r*4+2]+s[12+n]*t[r*4+3];return i}class os{constructor(t){this.joints=t.joints,this.inverseBindMatrices=t.inverseBindMatrices,this.jointWeights=t.jointWeights,this.jointIndices=t.jointIndices,this.nodes=t.nodes,this.animations=t.animations,this.restPositions=null,this.restNormals=null,this.currentAnimIndex=0,this.currentTime=0,this.playing=!0,this.speed=1,this.loop=!0,this.jointLocalTransforms=new Array(this.nodes.length),this.jointGlobalTransforms=new Array(this.nodes.length),this.jointFinalMatrices=new Array(this.joints.length);for(let e=0;e<this.nodes.length;e++)this.jointLocalTransforms[e]=new Float32Array(16),this.jointGlobalTransforms[e]=new Float32Array(16);for(let e=0;e<this.joints.length;e++)this.jointFinalMatrices[e]=new Float32Array(16);this.skinnedPositions=null,this.skinnedNormals=null,this._gpuSkinningReady=!1,this._sV0=new Float64Array(4),this._sV1=new Float64Array(4),this._scrT=new Float64Array(3),this._scrR=new Float64Array(4),this._scrS=new Float64Array(3),this._buildTopologicalOrder(),this._parentMap=new Array(this.nodes.length).fill(-1);for(let e=0;e<this.nodes.length;e++)for(const i of this.nodes[e].children)this._parentMap[i]=e;this._invBindViews=new Array(this.joints.length);for(let e=0;e<this.joints.length;e++)this._invBindViews[e]=this.inverseBindMatrices.subarray(e*16,e*16+16)}setRestPose(t,e){this.restPositions=new Float32Array(t),this.restNormals=new Float32Array(e),this.skinnedPositions=new Float32Array(t.length),this.skinnedNormals=new Float32Array(e.length)}async initGPUSkinning(t,e,i){try{this._gpuDevice=t,this._gpuOutputBuffer=e;const r=this.restPositions.length/3,n=new Float32Array(r*8);for(let l=0;l<r;l++){const c=l*8,d=l*3,S=l*2;n[c]=this.restPositions[d],n[c+1]=this.restPositions[d+1],n[c+2]=this.restPositions[d+2],n[c+3]=this.restNormals[d],n[c+4]=this.restNormals[d+1],n[c+5]=this.restNormals[d+2],n[c+6]=i?i[S]:0,n[c+7]=i?i[S+1]:0}this._gpuRestDataBuffer=t.createBuffer({size:n.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_restData"}),t.queue.writeBuffer(this._gpuRestDataBuffer,0,n),this._gpuJointWeightsBuffer=t.createBuffer({size:this.jointWeights.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_jointWeights"}),t.queue.writeBuffer(this._gpuJointWeightsBuffer,0,this.jointWeights);const a=new Uint32Array(this.jointIndices.length);for(let l=0;l<this.jointIndices.length;l++)a[l]=this.jointIndices[l];this._gpuJointIndicesBuffer=t.createBuffer({size:a.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_jointIndices"}),t.queue.writeBuffer(this._gpuJointIndicesBuffer,0,a),this._gpuJointMatricesBuffer=t.createBuffer({size:this.joints.length*16*4,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST,label:"skinning_jointMatrices"}),this._gpuJointMatricesData=new Float32Array(this.joints.length*16);const o=t.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:1,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:2,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:3,visibility:GPUShaderStage.COMPUTE,buffer:{type:"read-only-storage"}},{binding:4,visibility:GPUShaderStage.COMPUTE,buffer:{type:"storage"}}]});this._gpuSkinningPipeline=t.createComputePipeline({layout:t.createPipelineLayout({bindGroupLayouts:[o]}),compute:{module:t.createShaderModule({code:yr}),entryPoint:"main"}}),this._gpuSkinningBindGroup=t.createBindGroup({layout:o,entries:[{binding:0,resource:{buffer:this._gpuRestDataBuffer}},{binding:1,resource:{buffer:this._gpuJointWeightsBuffer}},{binding:2,resource:{buffer:this._gpuJointIndicesBuffer}},{binding:3,resource:{buffer:this._gpuJointMatricesBuffer}},{binding:4,resource:{buffer:this._gpuOutputBuffer}}]}),this._gpuVertexCount=r,this._gpuSkinningReady=!0,globalThis.__HZFX_DEBUG&&console.log(`GPU skinning initialized: ${r} vertices, ${this.joints.length} joints`)}catch(r){console.warn("GPU skinning init failed, using CPU fallback:",r),this._gpuSkinningReady=!1}}_applySkinningGPU(){for(let i=0;i<this.joints.length;i++)this._gpuJointMatricesData.set(this.jointFinalMatrices[i],i*16);this._gpuDevice.queue.writeBuffer(this._gpuJointMatricesBuffer,0,this._gpuJointMatricesData);const t=this._gpuDevice.createCommandEncoder({label:"SkinningComputeEncoder"}),e=t.beginComputePass({label:"SkinningComputePass"});e.setPipeline(this._gpuSkinningPipeline),e.setBindGroup(0,this._gpuSkinningBindGroup),e.dispatchWorkgroups(Math.ceil(this._gpuVertexCount/64),1,1),e.end(),this._gpuDevice.queue.submit([t.finish()])}update(t){if(!this.playing||this.animations.length===0)return{positions:this.skinnedPositions,normals:this.skinnedNormals,changed:!1};this.currentTime+=t*this.speed;const e=this.animations[this.currentAnimIndex];return this.loop?this.currentTime=this.currentTime%e.duration:this.currentTime>e.duration&&(this.currentTime=e.duration,this.playing=!1),this._computeLocalTransforms(this.currentTime),this._computeGlobalTransforms(),this._computeFinalMatrices(),this._gpuSkinningReady?(this._applySkinningGPU(),{gpuSkinned:!0,changed:!0}):(this._applySkinning(),{positions:this.skinnedPositions,normals:this.skinnedNormals,changed:!0})}getCurrentAnimation(){return this.animations[this.currentAnimIndex]}setAnimation(t){t>=0&&t<this.animations.length&&(this.currentAnimIndex=t,this.currentTime=0)}getAnimationNames(){return this.animations.map(t=>t.name)}_buildTopologicalOrder(){const t=new Set,e=[],i=n=>{if(t.has(n))return;t.add(n);const a=this.nodes[n];for(const o of a.children)i(o);e.push(n)},r=new Set;for(const n of this.nodes)for(const a of n.children)r.add(a);for(let n=0;n<this.nodes.length;n++)r.has(n)||i(n);this.topologicalOrder=e.reverse()}_sampleChannel(t,e,i){const{timestamps:r,values:n,interpolation:a,targetPath:o}=t;if(e<=r[0])return this._extractValue(n,0,o,i);if(e>=r[r.length-1])return this._extractValue(n,r.length-1,o,i);let l=0,c=r.length-1;for(;c-l>1;){const U=Math.floor((l+c)/2);r[U]<=e?l=U:c=U}const d=r[l],S=r[c],b=(e-d)/(S-d),f=this._extractValue(n,l,o,this._sV0),v=this._extractValue(n,c,o,this._sV1);return a==="STEP"?(i[0]=f[0],i[1]=f[1],i[2]=f[2],o==="rotation"&&(i[3]=f[3]),i):o==="rotation"?Ar(f,v,b,i):Er(f,v,b,i)}_extractValue(t,e,i,r){if(i==="rotation"){const n=e*4;r[0]=t[n],r[1]=t[n+1],r[2]=t[n+2],r[3]=t[n+3]}else{const n=e*3;r[0]=t[n],r[1]=t[n+1],r[2]=t[n+2]}return r}_computeLocalTransforms(t){const e=this.animations[this.currentAnimIndex];for(let i=0;i<this.nodes.length;i++){const r=this.nodes[i];let n=r.translation,a=r.rotation,o=r.scale;for(const l of e.channels)l.targetNode===i&&(l.targetPath==="translation"?n=this._sampleChannel(l,t,this._scrT):l.targetPath==="rotation"?a=this._sampleChannel(l,t,this._scrR):l.targetPath==="scale"&&(o=this._sampleChannel(l,t,this._scrS)));Ir(n,a,o,this.jointLocalTransforms[i])}}_computeGlobalTransforms(){const t=this._parentMap;for(const e of this.topologicalOrder){const i=t[e];i===-1?this.jointGlobalTransforms[e].set(this.jointLocalTransforms[e]):Ni(this.jointGlobalTransforms[i],this.jointLocalTransforms[e],this.jointGlobalTransforms[e])}}_computeFinalMatrices(){for(let t=0;t<this.joints.length;t++){const e=this.joints[t],i=this.jointGlobalTransforms[e];Ni(i,this._invBindViews[t],this.jointFinalMatrices[t])}}_applySkinning(){const t=this.restPositions.length/3,e=this.restPositions,i=this.restNormals,r=this.skinnedPositions,n=this.skinnedNormals,a=this.jointWeights,o=this.jointIndices,l=this.jointFinalMatrices;for(let c=0;c<t;c++){const d=c*3,S=c*4,b=e[d],f=e[d+1],v=e[d+2],U=i[d],z=i[d+1],G=i[d+2];let M=0,Z=0,T=0,D=0,F=0,H=0;for(let ne=0;ne<4;ne++){const re=a[S+ne];if(re===0)continue;const q=l[o[S+ne]];M+=(q[0]*b+q[4]*f+q[8]*v+q[12])*re,Z+=(q[1]*b+q[5]*f+q[9]*v+q[13])*re,T+=(q[2]*b+q[6]*f+q[10]*v+q[14])*re,D+=(q[0]*U+q[4]*z+q[8]*G)*re,F+=(q[1]*U+q[5]*z+q[9]*G)*re,H+=(q[2]*U+q[6]*z+q[10]*G)*re}const se=Math.sqrt(D*D+F*F+H*H);se>1e-4&&(n[d]=D/se,n[d+1]=F/se,n[d+2]=H/se),r[d]=M,r[d+1]=Z,r[d+2]=T}}}class ls{constructor({duration:t=0,loop:e=!1,playbackRate:i=1}={}){this.currentTime=0,this.duration=t,this.loop=e,this.playbackRate=i,this.paused=!1,this._justLooped=!1}tick(t){if(this.paused)return 0;const e=t*this.playbackRate;return this.currentTime+=e,this._justLooped=!1,this.loop&&this.duration>0&&isFinite(this.duration)&&this.currentTime>=this.duration&&(this.currentTime=0,this._justLooped=!0),e}get justLooped(){return this._justLooped}reset(){this.currentTime=0,this._justLooped=!1}seek(t){this.currentTime=Math.max(0,t||0),this._justLooped=!1}}const Yi={linear:s=>s,easeInQuad:s=>s*s,easeOutQuad:s=>1-(1-s)*(1-s),easeInOutQuad:s=>s<.5?2*s*s:1-Math.pow(-2*s+2,2)/2,easeInCubic:s=>s*s*s,easeOutCubic:s=>1-Math.pow(1-s,3),easeInOutCubic:s=>s<.5?4*s*s*s:1-Math.pow(-2*s+2,3)/2,easeInQuart:s=>s*s*s*s,easeOutQuart:s=>1-Math.pow(1-s,4),easeInOutQuart:s=>s<.5?8*s*s*s*s:1-Math.pow(-2*s+2,4)/2,easeOutBack:s=>1+2.70158*Math.pow(s-1,3)+1.70158*Math.pow(s-1,2),easeOutElastic:s=>{if(s===0||s===1)return s;const t=2*Math.PI/3;return Math.pow(2,-10*s)*Math.sin((s*10-.75)*t)+1}};function zr(s,t,e,i){const r=3*s,n=3*(e-s)-r,a=1-r-n,o=3*t,l=3*(i-t)-o,c=1-o-l,d=f=>((a*f+n)*f+r)*f,S=f=>((c*f+l)*f+o)*f,b=f=>(3*a*f+2*n)*f+r;return f=>{if(f<=0)return 0;if(f>=1)return 1;let v=f;for(let U=0;U<8;U++){const z=d(v)-f;if(Math.abs(z)<1e-5)break;const G=b(v);if(Math.abs(G)<1e-6)break;v-=z/G}return S(v)}}function cs(s,t){return typeof s=="function"?s(t):Array.isArray(s)&&s.length===4?zr(s[0],s[1],s[2],s[3])(t):(Yi[s]||Yi.linear)(t)}function Gr(s,t){if(!Array.isArray(s)||s.length===0)return;if(s.length===1||t<=s[0].t)return s[0].v;const e=s[s.length-1];if(t>=e.t)return e.v;for(let i=0;i<s.length-1;i++){const r=s[i],n=s[i+1];if(t>=r.t&&t<=n.t){const a=n.t-r.t,o=a>0?(t-r.t)/a:0;return r.v+(n.v-r.v)*cs(r.ease,o)}}return e.v}function Dr(s,t,e){if(!Array.isArray(s)||s.length===0)return;const i=s.length,r=s[i-1];let n,a,o;if(i===1||t<=s[0].t)n=a=s[0].v,o=0;else if(t>=r.t)n=a=r.v,o=0;else{n=a=r.v,o=0;for(let S=0;S<i-1;S++){const b=s[S],f=s[S+1];if(t>=b.t&&t<=f.t){const v=f.t-b.t;n=b.v,a=f.v,o=cs(b.ease,v>0?(t-b.t)/v:0);break}}}const l=n[0]+(a[0]-n[0])*o,c=n[1]+(a[1]-n[1])*o,d=n[2]+(a[2]-n[2])*o;return e?(e[0]=l,e[1]=c,e[2]=d,e):[l,c,d]}const Fr=["gravityStrength","emissionRate","damping","dampingStrength","particleSize","particleSpeed","opacity","bloomIntensity","emissionPositionX","emissionPositionY","emissionPositionZ","emissionRotationX","emissionRotationY","emissionRotationZ","circleInnerRadius","circleOuterRadius","discRadius","annulusInnerRadius","annulusOuterRadius","arcStartAngle","arcEndAngle","arcInnerRadius","arcOuterRadius","squareSize","rectangleWidth","rectangleHeight","planeWidth","planeDepth","lineLength","polygonRadius","shapeStrokeWidth","shapeStrokeAmplitude","shapeStrokeFrequency","shapeStrokeSpeed"],Vr={square:0,circle:1,triangle:2,diamond:3,star:4,hexagon:5,ring:6,heart:7,cross:8,spark:9,leaf:10,capsule:11,crescent:12,line:13,"curved-line":14};function ji(s){const t=atob(s),e=new Uint8Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return e.buffer}class kt{constructor(t,e){this.device=t,this.config=e,this.MAX_PARTICLES=e.maxParticles||1e4,this.particleCount=e.particleCount||100,this.activeParticles=0,this.emitting=!1,this.currentEmissionTime=0,this.emissionAccumulator=0,this.destroyed=!1,this.particleData=new Float32Array(this.MAX_PARTICLES*8),this.particleVelocities=new Float32Array(this.MAX_PARTICLES*4),this.instanceBuffer=t.createBuffer({size:this.MAX_PARTICLES*8*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC,label:"particleInstanceBuffer"}),this.velocityBuffer=t.createBuffer({size:this.MAX_PARTICLES*4*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,label:"particleVelocityBuffer"}),this.trailBuffer=t.createBuffer({size:this.MAX_PARTICLES*4*4,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC,label:"particleTrailBuffer"}),this._trailResetData=new Float32Array(this.MAX_PARTICLES*4),this.appearanceUniformBuffer=t.createBuffer({size:224,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,label:"appearanceUniformBuffer"}),this.bloomIntensityBuffer=t.createBuffer({size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,label:"systemBloomIntensityBuffer"}),e.overrideXVelocity===void 0&&(e.overrideXVelocity=!1),e.overrideYVelocity===void 0&&(e.overrideYVelocity=!1),e.overrideZVelocity===void 0&&(e.overrideZVelocity=!1),e.xVelocity===void 0&&(e.xVelocity=0),e.yVelocity===void 0&&(e.yVelocity=0),e.zVelocity===void 0&&(e.zVelocity=0),e.textureEnabled===void 0&&(e.textureEnabled=!1),e.glbModelEnabled===void 0&&(e.glbModelEnabled=!1),e.textureType===void 0&&(e.textureType="image"),e.glbFileName===void 0&&(e.glbFileName=null),e.animationIndex===void 0&&(e.animationIndex=0),e.animationSpeed===void 0&&(e.animationSpeed=1),e.animationLoop===void 0&&(e.animationLoop=!0),e.useGlbTexture===void 0&&(e.useGlbTexture=!1),e.glbHasTexture===void 0&&(e.glbHasTexture=!1),e.particleShape===void 0&&(e.particleShape="square"),e.particleShapeRotation!==void 0&&(e.rotation=(e.rotation||0)+e.particleShapeRotation,delete e.particleShapeRotation),e.particleShapeRotationX===void 0&&(e.particleShapeRotationX=0),e.particleShapeRotationY===void 0&&(e.particleShapeRotationY=0),e.particleShapeRotationZ===void 0&&(e.particleShapeRotationZ=0),e.particleColor===void 0&&(e.particleColor=[1,1,1]),e.startColor===void 0&&(e.startColor=[1,0,0]),e.endColor===void 0&&(e.endColor=[0,0,1]),e.fadeEnabled===void 0&&(e.fadeEnabled=!0),e.colorTransitionEnabled===void 0&&(e.colorTransitionEnabled=!1),e.randomColorEnabled===void 0&&(e.randomColorEnabled=!1),e.randomColors===void 0&&(e.randomColors=[]),e.particleSize===void 0&&(e.particleSize=.1),e.particleSpeed===void 0&&(e.particleSpeed=1),e.opacity===void 0&&(e.opacity=1),e.aspectRatio===void 0&&(e.aspectRatio=1),e.rotation===void 0&&(e.rotation=0),e.rotationMode===void 0&&(e.rotationMode="fixed"),e.minRotation===void 0&&(e.minRotation=0),e.maxRotation===void 0&&(e.maxRotation=90),e.orientX===void 0&&(e.orientX=0),e.orientY===void 0&&(e.orientY=0),e.orientZ===void 0&&(e.orientZ=0),e.randomSize===void 0&&(e.randomSize=!1),e.minSize===void 0&&(e.minSize=.05),e.maxSize===void 0&&(e.maxSize=.15),e.randomSpeed===void 0&&(e.randomSpeed=!1),e.minSpeed===void 0&&(e.minSpeed=.1),e.maxSpeed===void 0&&(e.maxSpeed=1),e.fadeSizeEnabled===void 0&&(e.fadeSizeEnabled=!1),e.increaseSizeEnabled===void 0&&(e.increaseSizeEnabled=!1),e.sizeLifetimeSpeed===void 0&&(e.sizeLifetimeSpeed=1),e.bloomEnabled===void 0&&(e.bloomEnabled=!0),e.bloomIntensity===void 0&&(e.bloomIntensity=1),e.bloomColor===void 0&&(e.bloomColor=[1,1,1]),e.gravityEnabled===void 0&&(e.gravityEnabled=!1),e.gravityStrength===void 0&&(e.gravityStrength=2),e.dampingEnabled===void 0&&(e.dampingEnabled=!1),e.dampingStrength===void 0&&(e.dampingStrength=1),e.attractorEnabled===void 0&&(e.attractorEnabled=!1),e.attractorStrength===void 0&&(e.attractorStrength=1),e.attractorPosition===void 0&&(e.attractorPosition=[0,0,0]),e.attractorReverse===void 0&&(e.attractorReverse=!1),e.burstMode===void 0&&(e.burstMode=!1),e.emissionShape===void 0&&(e.emissionShape="cube"),e.lifetime===void 0&&(e.lifetime=5),e.emissionRate===void 0&&(e.emissionRate=10),e.startAt===void 0&&(e.startAt=0),e.emissionDuration===void 0&&(e.emissionDuration=10),e.emissionDurationInfinite===void 0&&(e.emissionDurationInfinite=!1),e.emissionDuration>300&&(e.emissionDurationInfinite=!0,e.emissionDuration=10),e.outerLength===void 0&&(e.outerLength=e.cubeLength??2),e.innerLength===void 0&&(e.innerLength=0),e.outerRadius===void 0&&(e.outerRadius=2),e.innerRadius===void 0&&(e.innerRadius=0),e.squareSize===void 0&&(e.squareSize=2),e.squareInnerSize===void 0&&(e.squareInnerSize=0),e.circleInnerRadius===void 0&&(e.circleInnerRadius=0),e.circleOuterRadius===void 0&&(e.circleOuterRadius=2),e.circleVelocityDirection===void 0&&(e.circleVelocityDirection="outward"),e.cylinderInnerRadius===void 0&&(e.cylinderInnerRadius=0),e.cylinderOuterRadius===void 0&&(e.cylinderOuterRadius=2),e.cylinderHeight===void 0&&(e.cylinderHeight=4),e.cylinderVelocityDirection===void 0&&(e.cylinderVelocityDirection="outward"),e.planeWidth===void 0&&(e.planeWidth=2),e.planeDepth===void 0&&(e.planeDepth=2),e.coneOuterRadius===void 0&&(e.coneOuterRadius=2),e.coneInnerRadius===void 0&&(e.coneInnerRadius=0),e.coneHeight===void 0&&(e.coneHeight=4),e.torusMajorRadius===void 0&&(e.torusMajorRadius=2),e.torusMinorRadius===void 0&&(e.torusMinorRadius=.5),e.lineLength===void 0&&(e.lineLength=4),e.hemisphereOuterRadius===void 0&&(e.hemisphereOuterRadius=2),e.hemisphereInnerRadius===void 0&&(e.hemisphereInnerRadius=0),e.discRadius===void 0&&(e.discRadius=2),e.annulusInnerRadius===void 0&&(e.annulusInnerRadius=1),e.annulusOuterRadius===void 0&&(e.annulusOuterRadius=2),e.capsuleRadius===void 0&&(e.capsuleRadius=.5),e.capsuleHeight===void 0&&(e.capsuleHeight=4),e.arcStartAngle===void 0&&(e.arcStartAngle=0),e.arcEndAngle===void 0&&(e.arcEndAngle=180),e.arcInnerRadius===void 0&&(e.arcInnerRadius=0),e.arcOuterRadius===void 0&&(e.arcOuterRadius=2),e.spiralTurns===void 0&&(e.spiralTurns=3),e.spiralRadiusStart===void 0&&(e.spiralRadiusStart=.5),e.spiralRadiusEnd===void 0&&(e.spiralRadiusEnd=2),e.spiralHeight===void 0&&(e.spiralHeight=4),e.frustumRadiusNear===void 0&&(e.frustumRadiusNear=.5),e.frustumRadiusFar===void 0&&(e.frustumRadiusFar=2),e.frustumHeight===void 0&&(e.frustumHeight=4),e.cubeSurfaceSize===void 0&&(e.cubeSurfaceSize=2),e.sphereSurfaceRadius===void 0&&(e.sphereSurfaceRadius=2),e.boxFrameSize===void 0&&(e.boxFrameSize=2),e.polygonSides===void 0&&(e.polygonSides=6),e.polygonRadius===void 0&&(e.polygonRadius=2),e.emissionRotationX===void 0&&(e.emissionRotationX=0),e.emissionRotationY===void 0&&(e.emissionRotationY=0),e.emissionRotationZ===void 0&&(e.emissionRotationZ=0),e.emissionPositionX===void 0&&(e.emissionPositionX=e.emissionTranslationX??0),e.emissionPositionY===void 0&&(e.emissionPositionY=e.emissionTranslationY??0),e.emissionPositionZ===void 0&&(e.emissionPositionZ=e.emissionTranslationZ??0),e.pulseEnabled===void 0&&(e.pulseEnabled=!1),e.pulseAmplitude===void 0&&(e.pulseAmplitude=.5),e.pulseFrequency===void 0&&(e.pulseFrequency=1),e.pulsePhaseRandom===void 0&&(e.pulsePhaseRandom=0),e.pulseOpacity===void 0&&(e.pulseOpacity=!1),e.confinementEnabled===void 0&&(e.confinementEnabled=!1),e.confinementShape===void 0&&(e.confinementShape="box"),e.confinementMode===void 0&&(e.confinementMode="bounce"),e.confinementSpace===void 0&&(e.confinementSpace="world"),e.confinementBoxHalfSize===void 0&&(e.confinementBoxHalfSize=[2,2,2]),e.confinementSphereRadius===void 0&&(e.confinementSphereRadius=3),e.confinementRestitution===void 0&&(e.confinementRestitution=.8),e.confinementFriction===void 0&&(e.confinementFriction=.1),e.softBoundaryEnabled===void 0&&(e.softBoundaryEnabled=!1),e.softBoundaryStrength===void 0&&(e.softBoundaryStrength=5),e.softBoundaryFalloff===void 0&&(e.softBoundaryFalloff=.5),e.depthWriteEnabled===void 0&&(e.depthWriteEnabled=!1),e.velocityStretchEnabled===void 0&&(e.velocityStretchEnabled=!1),e.velocityStretchFactor===void 0&&(e.velocityStretchFactor=1),e.blendMode===void 0&&(e.blendMode="normal"),e.noiseDistortEnabled===void 0&&(e.noiseDistortEnabled=!1),e.noiseTilingX===void 0&&(e.noiseTilingX=3),e.noiseTilingY===void 0&&(e.noiseTilingY=3),e.noiseSpeed===void 0&&(e.noiseSpeed=-1.5),e.noiseAmplitude===void 0&&(e.noiseAmplitude=.08),e.emissionTrailEnabled===void 0&&(e.emissionTrailEnabled=!1),e.emissionTrailDuration===void 0&&(e.emissionTrailDuration=1),e.emissionTrailWidth===void 0&&(e.emissionTrailWidth=.3),e.emissionTrailMinDistance===void 0&&(e.emissionTrailMinDistance=.05),e.emissionTrailMaxPoints===void 0&&(e.emissionTrailMaxPoints=256),e.emissionTrailSegments===void 0&&(e.emissionTrailSegments=8),e.emissionTrailMode===void 0&&(e.emissionTrailMode="ribbon"),e.emissionTrailShape===void 0&&(e.emissionTrailShape="straight"),e.emissionTrailShapeAmplitude===void 0&&(e.emissionTrailShapeAmplitude=.1),e.emissionTrailShapeFrequency===void 0&&(e.emissionTrailShapeFrequency=4),e.emissionTrailShapeSpeed===void 0&&(e.emissionTrailShapeSpeed=0),e.shapeStrokeEnabled===void 0&&(e.shapeStrokeEnabled=!1),e.shapeStrokeWidth===void 0&&(e.shapeStrokeWidth=.08),e.shapeStrokeSegments===void 0&&(e.shapeStrokeSegments=96),e.shapeStrokeShape===void 0&&(e.shapeStrokeShape="straight"),e.shapeStrokeAmplitude===void 0&&(e.shapeStrokeAmplitude=.08),e.shapeStrokeFrequency===void 0&&(e.shapeStrokeFrequency=10),e.shapeStrokeSpeed===void 0&&(e.shapeStrokeSpeed=0),e.shapeDisplay===void 0&&(e.shapeDisplay=!0),e.followSystemTranslation===void 0&&(e.followSystemTranslation=!0),e.followSystemId===void 0&&(e.followSystemId=null),this._newEmissions=[],this._emptyEmissions=[],this._pendingFollowEmissions=this._emptyEmissions,this.glbVertexBuffer=null,this.glbIndexBuffer=null,this.glbIndexCount=0,this.glbIndexFormat="uint16",this.glbMeshData=null,this.glbRawArrayBuffer=null,this.glbAnimator=null,this.glbAnimated=!1,this._glbInterleavedData=null,this._appearanceData=new Float32Array(56),this._bloomIntensityData=new Float32Array(16),this._simPosition=[0,0,0],this._simVelocity=[0,0,0],this._simRotMatrix=null,this._simRotX=0,this._simRotZ=0,this._emitSimRotY=0,this.emitter=new Ji(e),this.physics=new ss(t,this.MAX_PARTICLES),this.textureManager=new rs(t),e.gravityEnabled&&this.setGravity(e.gravityStrength||0),e.dampingEnabled&&this.physics.setDamping(e.dampingStrength||0),e.attractorEnabled&&e.attractorPosition&&this.setAttractor(e.attractorStrength||0,e.attractorPosition,e.attractorReverse),e.confinementEnabled&&this.setConfinement({enabled:!0,shape:e.confinementShape,mode:e.confinementMode,space:e.confinementSpace,boxSize:e.confinementBoxHalfSize,sphereRadius:e.confinementSphereRadius,restitution:e.confinementRestitution,friction:e.confinementFriction}),e.softBoundaryEnabled&&this.setSoftBoundary({enabled:!0,strength:e.softBoundaryStrength,falloff:e.softBoundaryFalloff}),this.particleTexture=this.textureManager.getDefaultTexture(),this.updateBloomIntensity(),this.updateAppearanceUniform(),this.frameCount=0,this.shouldReset=!1,this._scriptParticleData=new Float32Array(this.MAX_PARTICLES*8),this._scriptVelocityData=new Float32Array(this.MAX_PARTICLES*4),this._scriptReadbackPending=!1,this._scriptReadbackReady=!1,this._scriptFrame=0,this._scriptTime=0,this._scriptConfigRestored=!1,this._particleScript=null,e.script&&(this._particleScript=new ai(e.script,e,this.MAX_PARTICLES)),this.initComputePipeline(t)}async initComputePipeline(t){this.computeReady=await this.physics.initComputePipeline(this.instanceBuffer,this.velocityBuffer,this.trailBuffer)}setScript(t){this._particleScript&&(this._particleScript.destroy(),this._particleScript=null),this._scriptReadbackPending=!1,this._scriptReadbackReady=!1,this._scriptFrame=0,this._scriptTime=0,this._scriptConfigRestored=!1,t?(this.config.script=t,this._particleScript=new ai(t,this.config,this.MAX_PARTICLES),this._particleScript.snapshotConfig(this.config)):delete this.config.script}async setTexture(t){this.destroyed||(this.textureManager.destroyTexture(this.particleTexture),this.particleTexture=await this.textureManager.loadTexture(t),this.config.textureEnabled=!0,this.updateAppearanceUniform(),this.updateBuffers())}resetTexture(){this.destroyed||(this.textureManager.destroyTexture(this.particleTexture),this.particleTexture=this.textureManager.getDefaultTexture(),this.config.textureEnabled=!1,this.updateAppearanceUniform(),this.updateBuffers())}async setGLBModel(t){try{this.glbRawArrayBuffer=t;const e=await as(t);this.glbMeshData=e,this.config.glbHasTexture=e.hasBaseColorTexture||!1;const i=new Float32Array(e.vertexCount*8);for(let r=0;r<e.vertexCount;r++){const n=r*8,a=r*3,o=r*2;i[n+0]=e.positions[a+0],i[n+1]=e.positions[a+1],i[n+2]=e.positions[a+2],i[n+3]=e.normals[a+0],i[n+4]=e.normals[a+1],i[n+5]=e.normals[a+2],e.texCoords?(i[n+6]=e.texCoords[o+0],i[n+7]=e.texCoords[o+1]):(i[n+6]=0,i[n+7]=0)}if(this.glbVertexBuffer&&this.glbVertexBuffer.destroy(),this.glbIndexBuffer&&this.glbIndexBuffer.destroy(),this.glbVertexBuffer=this.device.createBuffer({size:i.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST|GPUBufferUsage.STORAGE,label:"glbVertexBuffer"}),this.device.queue.writeBuffer(this.glbVertexBuffer,0,i),this.glbIndexBuffer=this.device.createBuffer({size:e.indices.byteLength,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST,label:"glbIndexBuffer"}),this.device.queue.writeBuffer(this.glbIndexBuffer,0,e.indices),this.glbIndexCount=e.indexCount,this.glbIndexFormat=e.indices instanceof Uint32Array?"uint32":"uint16",this.config.glbModelEnabled=!0,this.config.textureType="glb",e.animationData){this.glbAnimator=new os(e.animationData),this.glbAnimator.setRestPose(e.positions,e.normals),this.glbAnimated=!0,this.config.glbAnimated=!0,this.glbAnimator.loop=this.config.animationLoop,this._glbInterleavedData=new Float32Array(e.vertexCount*8);try{await this.glbAnimator.initGPUSkinning(this.device,this.glbVertexBuffer,e.texCoords)}catch(r){console.warn("GPU skinning init failed, using CPU fallback:",r)}globalThis.__HZFX_DEBUG&&console.log(`GLB animated model loaded: ${e.animationData.animations.length} animations`)}else this.glbAnimator=null,this.glbAnimated=!1,this.config.glbAnimated=!1,this._glbInterleavedData=null;globalThis.__HZFX_DEBUG&&console.log(`GLB model loaded: ${e.vertexCount} vertices, ${e.indexCount} indices`)}catch(e){throw console.error("Failed to load GLB model:",e),e}}resetGLBModel(){this.glbVertexBuffer&&(this.glbVertexBuffer.destroy(),this.glbVertexBuffer=null),this.glbIndexBuffer&&(this.glbIndexBuffer.destroy(),this.glbIndexBuffer=null),this.glbIndexCount=0,this.glbIndexFormat="uint16",this.glbMeshData=null,this.glbRawArrayBuffer=null,this.glbAnimator=null,this.glbAnimated=!1,this.config.glbAnimated=!1,this._glbInterleavedData=null,this.config.glbFileName=null,this.config.glbHasTexture=!1,this.config.useGlbTexture=!1,this.config.glbModelEnabled=!1,this.config.textureType="image"}setSimulationTransform(t){if(t.position&&(this._simPosition[0]=t.position[0],this._simPosition[1]=t.position[1],this._simPosition[2]=t.position[2]),t.rotation){this._simRotX=t.rotation[0]||0,this._simRotZ=t.rotation[1]||0,this._simRotY=t.rotation[2]||0;const e=Math.cos(this._simRotX),i=Math.sin(this._simRotX),r=Math.cos(this._simRotZ),n=Math.sin(this._simRotZ),a=Math.cos(this._simRotY),o=Math.sin(this._simRotY);this._simRotMatrix=[a*r,-a*n*e+o*i,a*n*i+o*e,n,r*e,-r*i,-o*r,o*n*e+a*i,-o*n*i+a*e]}else this._simRotMatrix=null,this._simRotX=0,this._simRotZ=0,this._simRotY=0;t.velocity&&(this._simVelocity[0]=t.velocity[0],this._simVelocity[1]=t.velocity[1],this._simVelocity[2]=t.velocity[2])}clearSimulationTransform(){this._simPosition[0]=this._simPosition[1]=this._simPosition[2]=0,this._simVelocity[0]=this._simVelocity[1]=this._simVelocity[2]=0,this._simRotMatrix=null,this._simRotX=0,this._simRotZ=0}updateAnimatedGLBBuffer(){if(!this.glbAnimator||!this.glbAnimator.playing)return!1;if(this.glbAnimator._gpuSkinningReady)return!0;const t=this.glbAnimator.skinnedPositions,e=this.glbAnimator.skinnedNormals,i=this.glbMeshData.texCoords;for(let r=0;r<this.glbMeshData.vertexCount;r++){const n=r*8,a=r*3,o=r*2;this._glbInterleavedData[n]=t[a],this._glbInterleavedData[n+1]=t[a+1],this._glbInterleavedData[n+2]=t[a+2],this._glbInterleavedData[n+3]=e[a],this._glbInterleavedData[n+4]=e[a+1],this._glbInterleavedData[n+5]=e[a+2],i?(this._glbInterleavedData[n+6]=i[o],this._glbInterleavedData[n+7]=i[o+1]):(this._glbInterleavedData[n+6]=0,this._glbInterleavedData[n+7]=0)}return this.device.queue.writeBuffer(this.glbVertexBuffer,0,this._glbInterleavedData),!0}updateAppearanceUniform(){if(this.destroyed)return;let t=0;this.config.rotationMode==="random"?t=1:this.config.rotationMode==="velocity"?t=2:this.config.rotationMode==="oriented"?t=3:this.config.rotationMode==="cylindrical"&&(t=4);const e=Vr[this.config.particleShape]??0,i=this._appearanceData;i[0]=this.config.fadeEnabled?1:0,i[1]=this.config.randomColorEnabled?2:this.config.colorTransitionEnabled?1:0,i[2]=this.config.particleSize,i[3]=this.config.textureEnabled?1:0,i[4]=this.config.particleColor[0],i[5]=this.config.particleColor[1],i[6]=this.config.particleColor[2],i[7]=this.config.rotation||0,i[8]=this.config.startColor[0],i[9]=this.config.startColor[1],i[10]=this.config.startColor[2],i[11]=t,i[12]=this.config.endColor[0],i[13]=this.config.endColor[1],i[14]=this.config.endColor[2],i[15]=this.config.minRotation||0,i[16]=this.config.maxRotation||90,i[17]=this.config.aspectRatio||1,i[18]=this.config.randomSize?1:0,i[19]=this.config.minSize||.1,i[20]=this.config.maxSize||.5,i[21]=this.config.fadeSizeEnabled?1:0,i[22]=this.config.opacity!==void 0?this.config.opacity:1,i[23]=this.config.increaseSizeEnabled?1:0,i[24]=this.config.sizeLifetimeSpeed??1,i[25]=e,i[26]=0,i[27]=this.config.pulseEnabled?1:0,i[28]=this.config.pulseAmplitude??.5,i[29]=this.config.pulseFrequency??1,i[30]=this.config.pulsePhaseRandom??0,i[31]=this.config.pulseOpacity?1:0,i[32]=this.config.particleShapeRotationX||0,i[33]=this.config.particleShapeRotationY||0,i[34]=this.config.particleShapeRotationZ||0,i[35]=0;const r=this.config.followSystemTranslation??!0;i[36]=r?this._simPosition[0]:0,i[37]=r?this._simPosition[1]:0,i[38]=r?this._simPosition[2]:0,i[39]=0,i[40]=this._simRotX,i[41]=this._simRotZ,i[42]=this.config.velocityStretchEnabled?1:0,i[43]=this.config.velocityStretchFactor??1,i[44]=this.config.noiseDistortEnabled?1:0,i[45]=this.config.noiseTilingX??3,i[46]=this.config.noiseTilingY??3,i[47]=this.config.noiseSpeed??-1.5,i[48]=this.config.noiseAmplitude??.08,i[49]=r?this._simVelocity[0]:0,i[50]=r?this._simVelocity[1]:0,i[51]=r?this._simVelocity[2]:0,i[52]=this.config.orientX??0,i[53]=this.config.orientY??0,i[54]=this.config.orientZ??0,i[55]=0,this.device.queue.writeBuffer(this.appearanceUniformBuffer,0,i)}updateBloomIntensity(){const t=this._bloomIntensityData;t[0]=this.config.bloomIntensity||1;const e=this.config.bloomColor||[1,1,1];t[4]=e[0],t[5]=e[1],t[6]=e[2],this.device.queue.writeBuffer(this.bloomIntensityBuffer,0,t)}spawnParticles(t){if(this.activeParticles=0,this.currentEmissionTime=0,this.emissionAccumulator=0,this._newEmissions.length=0,this._pendingFollowEmissions=this._emptyEmissions,this._scriptFrame=0,this._scriptTime=0,this._scriptReadbackPending=!1,this._scriptReadbackReady=!1,this._scriptConfigRestored=!1,this._particleScript&&(this._particleScript._configSnapshot?(this._particleScript.restoreConfig(this.config),this.config.gravityEnabled&&this.setGravity(this.config.gravityStrength),this.config.dampingEnabled&&this.physics.setDamping(this.config.dampingStrength),this.config.attractorEnabled&&this.setAttractor(this.config.attractorStrength,this.config.attractorPosition,this.config.attractorReverse),this.updateAppearanceUniform(),this.updateBloomIntensity()):this._particleScript.snapshotConfig(this.config)),typeof t=="function"&&t(this),this.device.queue.writeBuffer(this.trailBuffer,0,this._trailResetData,0,this.MAX_PARTICLES*4),this.glbAnimator&&(this.glbAnimator.currentTime=0,this.glbAnimator.playing=!0),this.config.followSystemId){this.emitting=!0,this.particleCount=this.MAX_PARTICLES;return}if(this.config.burstMode){const e=this.config.particleCount;this.particleCount=e;let i=0;const r=500;for(let n=0;n<e;n++)if(this.emitParticle(),i++,i>=r||n===e-1){const a=n-i+1,o=a*8,l=a*4;this.device.queue.writeBuffer(this.instanceBuffer,o*4,this.particleData,o,i*8),this.device.queue.writeBuffer(this.velocityBuffer,l*4,this.particleVelocities,l,i*4),i=0}this.emitting=!1}else{this.emitting=!0;const e=this.config.lifetime||5,i=this.config.emissionDurationInfinite?e:Math.min(this.config.emissionDuration||10,e);this.particleCount=Math.min(Math.ceil((this.config.emissionRate||10)*i),this.MAX_PARTICLES)}}get effectiveEmissionDuration(){return this.config.emissionDurationInfinite?1/0:this.config.emissionDuration??10}_applySimTransformToParticle(t){this._emitSimRotY=this._simRotY||0;const e=t*8,i=t*4;if(this._simRotMatrix){const r=this._simRotMatrix,n=this.particleData[e],a=this.particleData[e+1],o=this.particleData[e+2],l=this.particleVelocities[i],c=this.particleVelocities[i+1],d=this.particleVelocities[i+2];this.particleData[e]=r[0]*n+r[1]*a+r[2]*o,this.particleData[e+1]=r[3]*n+r[4]*a+r[5]*o,this.particleData[e+2]=r[6]*n+r[7]*a+r[8]*o,this.particleVelocities[i]=r[0]*l+r[1]*c+r[2]*d,this.particleVelocities[i+1]=r[3]*l+r[4]*c+r[5]*d,this.particleVelocities[i+2]=r[6]*l+r[7]*c+r[8]*d}(this.config.followSystemTranslation??!0)||(this.particleData[e]+=this._simPosition[0],this.particleData[e+1]+=this._simPosition[1],this.particleData[e+2]+=this._simPosition[2])}emitParticle(){if(this.activeParticles>=this.particleCount)return!1;this.emitter.emitParticle(this.particleData,this.activeParticles,this.particleVelocities);const t=this.activeParticles*8,e=this.activeParticles*4;return this._applySimTransformToParticle(this.activeParticles),this._newEmissions.push(this.particleData[t],this.particleData[t+1],this.particleData[t+2],this.particleVelocities[e],this.particleVelocities[e+1],this.particleVelocities[e+2]),this.activeParticles++,!0}emitFollowerParticle(t,e,i){if(this.activeParticles>=this.particleCount)return!1;const r=this.activeParticles*8,n=t+(this.config.emissionPositionX||0),a=e+(this.config.emissionPositionY||0),o=i+(this.config.emissionPositionZ||0);this.particleData[r]=n,this.particleData[r+1]=a,this.particleData[r+2]=o;const l=this.activeParticles*4;return this.emitter.calculateVelocity(n,a,o,this.particleVelocities,l),this.emitter.setParticleColor(this.particleData,r),this.emitter.setParticleLifetime(this.particleData,r),this.activeParticles++,!0}updateParticles(t,e,i=0){const r=this.config.startAt||0,n=r>0&&i<r;if(this._particleScript&&this._scriptReadbackReady){this._scriptReadbackReady=!1,this._scriptTime+=t,this._scriptFrame++;const d=this.config.emissionDurationInfinite?1/0:(this.config.emissionDuration||0)+(this.config.lifetime||0);if(d>0&&this._scriptTime>=d&&!this._scriptConfigRestored)this._scriptConfigRestored=!0,this._particleScript._configSnapshot&&(this._particleScript.restoreConfig(this.config),this.updateAppearanceUniform(),this.updateBloomIntensity(),this.config.gravityEnabled&&this.setGravity(this.config.gravityStrength),this.config.dampingEnabled&&this.physics.setDamping(this.config.dampingStrength),this.config.attractorEnabled&&this.setAttractor(this.config.attractorStrength,this.config.attractorPosition,this.config.attractorReverse));else if(!this._scriptConfigRestored){const S=d>0?Math.ceil(d/.016666666666666666):0,{configDirty:b,particlesDirty:f}=this._particleScript.execute(t,this._scriptTime,this._scriptFrame,S,this._scriptParticleData,this._scriptVelocityData,this.activeParticles);f&&this.activeParticles>0&&(this.device.queue.writeBuffer(this.instanceBuffer,0,this._scriptParticleData,0,this.activeParticles*8),this.device.queue.writeBuffer(this.velocityBuffer,0,this._scriptVelocityData,0,this.activeParticles*4)),b&&(this.updateAppearanceUniform(),this.updateBloomIntensity(),this.config.gravityEnabled&&this.setGravity(this.config.gravityStrength),this.config.dampingEnabled&&this.physics.setDamping(this.config.dampingStrength),this.config.attractorEnabled&&this.setAttractor(this.config.attractorStrength,this.config.attractorPosition,this.config.attractorReverse))}}this.physics.physicsAccumulator+=t;const a=performance.now()/1e3,l=a-this.physics.lastUpdateTime>1/this.physics.minUpdatesPerSecond,c=this.activeParticles;if(!n&&!this.emitting&&!this.config.burstMode&&!this.config.followSystemId&&this.currentEmissionTime<this.effectiveEmissionDuration&&(this.emitting=!0),!n&&this.emitting)if(this.currentEmissionTime+=t,this.currentEmissionTime<this.effectiveEmissionDuration){const d=this.activeParticles;let S=!1;if(this.config.followSystemId){if(this._pendingFollowEmissions.length>0){const b=this._pendingFollowEmissions.length/6;for(let f=0;f<b;f++){const v=f*6;if(this.emitFollowerParticle(this._pendingFollowEmissions[v],this._pendingFollowEmissions[v+1],this._pendingFollowEmissions[v+2]))S=!0;else break}}}else{let b=0;const f=Math.max(0,this.config.emissionRate||0);this.activeParticles<this.particleCount&&f>0?(this.emissionAccumulator+=f*t,b=Math.floor(this.emissionAccumulator+1e-9),b>0&&(this.emissionAccumulator-=b)):this.activeParticles>=this.particleCount&&(this.emissionAccumulator=0);for(let v=0;v<b;v++)if(this.emitParticle())S=!0;else{this.emissionAccumulator=0;break}}if(S){const b=this.activeParticles-d,f=d*8,v=d*4;this.device.queue.writeBuffer(this.instanceBuffer,f*4,this.particleData,f,b*8),this.device.queue.writeBuffer(this.velocityBuffer,v*4,this.particleVelocities,v,b*4)}}else this.emitting=!1,this.currentEmissionTime=this.config.emissionDuration;for(;this.physics.physicsAccumulator>=this.physics.fixedDeltaTime;)this.physics.updatePhysics(this.physics.fixedDeltaTime,c,this.config,this.instanceBuffer,this.velocityBuffer,e),this.physics.physicsAccumulator-=this.physics.fixedDeltaTime,this.physics.physicsClock+=this.physics.fixedDeltaTime;l&&c>0&&(this.physics.updatePhysics(this.physics.fixedDeltaTime,c,this.config,this.instanceBuffer,this.velocityBuffer,e),this.physics.lastUpdateTime=a),this.frameCount++,(this.activeParticles>=this.particleCount||this.frameCount%300===0)&&this.readbackAndProcessParticles(),this._particleScript&&this.activeParticles>0&&!this._scriptReadbackPending&&(this._scriptReadbackPending=!0,this.physics.readbackForScript(this.activeParticles,this._scriptParticleData,this._scriptVelocityData,this.instanceBuffer,this.velocityBuffer).then(d=>{this._scriptReadbackPending=!1,d.shouldUpdate&&(this._scriptReadbackReady=!0)}).catch(()=>{this._scriptReadbackPending=!1}))}async readbackAndProcessParticles(){if(!(this.destroyed||this.activeParticles<=0))try{const t=await this.physics.readbackAndProcessParticles(this.activeParticles,this.particleData,this.particleVelocities,this.instanceBuffer,this.velocityBuffer);if(this.destroyed||!this.particleData||!this.particleVelocities||!t.shouldUpdate)return;let e=0,i=!1;for(let r=0;r<this.activeParticles;r++){const n=this.particleData[r*8+6],a=this.particleData[r*8+7];if(n>=a){if(this.emitting&&this.currentEmissionTime<this.effectiveEmissionDuration&&e<this.particleCount){this.respawnParticle(r,e),e++,i=!0;continue}continue}if(e!==r){const o=r*8,l=e*8;this.particleData.copyWithin(l,o,o+8);const c=r*4,d=e*4;this.particleVelocities.copyWithin(d,c,c+4),i=!0}e++}(e!==this.activeParticles||i)&&(this.activeParticles=e,this.device.queue.writeBuffer(this.instanceBuffer,0,this.particleData,0,this.activeParticles*8),this.device.queue.writeBuffer(this.velocityBuffer,0,this.particleVelocities,0,this.activeParticles*4))}catch(t){t&&t.name==="AbortError"||console.error("Error reading back particle data:",t)}}respawnParticle(t,e){!this.emitting||this.currentEmissionTime>=this.effectiveEmissionDuration||this.config.followSystemId||(this.emitter.emitParticle(this.particleData,e,this.particleVelocities),this._applySimTransformToParticle(e))}updateBuffers(){this.destroyed||!this.particleData||this.activeParticles>0&&this.device.queue.writeBuffer(this.instanceBuffer,0,this.particleData,0,this.activeParticles*8)}updateParticleColors(){if(!(this.destroyed||!this.particleData)){for(let t=0;t<this.activeParticles;t++){const e=t*8;if(this.config.randomColorEnabled&&this.config.randomColors.length>0){const i=this.config.randomColors,r=i[Math.floor(Math.random()*i.length)];this.particleData[e+3]=r[0],this.particleData[e+4]=r[1],this.particleData[e+5]=r[2]}else this.config.colorTransitionEnabled?(this.particleData[e+3]=this.config.startColor[0],this.particleData[e+4]=this.config.startColor[1],this.particleData[e+5]=this.config.startColor[2]):(this.particleData[e+3]=this.config.particleColor[0],this.particleData[e+4]=this.config.particleColor[1],this.particleData[e+5]=this.config.particleColor[2])}this.activeParticles>0&&this.device.queue.writeBuffer(this.instanceBuffer,0,this.particleData,0,this.activeParticles*8)}}updateParticleVelocities(){for(let t=0;t<this.activeParticles;t++){const e=t*8,i=t*4,r=this.particleData[e],n=this.particleData[e+1],a=this.particleData[e+2],o=this.particleVelocities[i],l=this.particleVelocities[i+1],c=this.particleVelocities[i+2],d=Math.sqrt(o*o+l*l+c*c);if(d>.001){const S=this.config.particleSpeed*2;this.particleVelocities[i]=o/d*S,this.particleVelocities[i+1]=l/d*S,this.particleVelocities[i+2]=c/d*S}else{const S=Math.sqrt(r*r+n*n+a*a);if(S>.001){const b=this.config.particleSpeed*2;this.particleVelocities[i]=r/S*b,this.particleVelocities[i+1]=n/S*b,this.particleVelocities[i+2]=a/S*b}else this.particleVelocities[i]=0,this.particleVelocities[i+1]=this.config.particleSpeed*2,this.particleVelocities[i+2]=0}}this.activeParticles>0&&this.device.queue.writeBuffer(this.velocityBuffer,0,this.particleVelocities,0,this.activeParticles*4)}async readbackForRendering(t,e){return this.physics.readbackForRendering(this.activeParticles,t,e,this.instanceBuffer,this.velocityBuffer)}destroy(){this.destroyed=!0,this.instanceBuffer.destroy(),this.velocityBuffer.destroy(),this.trailBuffer.destroy(),this.appearanceUniformBuffer.destroy(),this.bloomIntensityBuffer.destroy(),this.physics.destroy(),this.glbVertexBuffer&&(this.glbVertexBuffer.destroy(),this.glbVertexBuffer=null),this.glbIndexBuffer&&(this.glbIndexBuffer.destroy(),this.glbIndexBuffer=null),this.textureManager.destroyTexture(this.particleTexture),this._particleScript&&(this._particleScript.destroy(),this._particleScript=null),this.glbAnimator=null,this.glbMeshData=null,this.glbRawArrayBuffer=null,this.particleData=null,this.particleVelocities=null,this._scriptParticleData=null,this._scriptVelocityData=null}setGravity(t){this.physics.setGravity(t)}setAttractor(t,e,i=this.config.attractorReverse){this.config.attractorStrength=t,this.config.attractorPosition=e,this.config.attractorReverse=!!i,this.physics.setAttractor(t,e,i)}setConfinement(t){const e=t.center||this.config.confinementCenter||[0,0,0],i=t.space==="local"?[this.config.emissionPositionX||0,this.config.emissionPositionY||0,this.config.emissionPositionZ||0]:[0,0,0],r=[i[0]+(e[0]||0),i[1]+(e[1]||0),i[2]+(e[2]||0)];this.physics.setConfinement({...t,center:r})}setSoftBoundary(t){this.physics.setSoftBoundary(t)}}class us{constructor(t){this.device=t,this.particleSystems=[],this.activeSystemIndex=0,this.systemCounter=1,this.onSystemCreated=null,this.loop=void 0,this.clock=new ls({loop:!!this.loop}),this.ready=!0}createParticleSystem(t={}){const e=this.systemCounter++,i=t.name||`System ${e+1}`,r={...t,name:i,id:e},n=new kt(this.device,r);return this.particleSystems.push({system:n,config:r}),this.particleSystems.length===1&&(this.activeSystemIndex=0),this.onSystemCreated&&typeof this.onSystemCreated=="function"&&this.onSystemCreated(e,r),e}getActiveSystem(){return this.particleSystems.length===0?null:this.particleSystems[this.activeSystemIndex].system}getActiveConfig(){return this.particleSystems.length===0?null:this.particleSystems[this.activeSystemIndex].config}setActiveSystem(t){return t>=0&&t<this.particleSystems.length?(this.activeSystemIndex=t,!0):!1}getSystemById(t){return this.particleSystems.find(({config:e})=>e.id===t)||null}destroy(){for(const{system:t}of this.particleSystems)t.destroy();this.particleSystems=[],this.activeSystemIndex=0}removeSystem(t){if(t>=0&&t<this.particleSystems.length){const e=this.particleSystems[t].config;this.particleSystems[t].system.destroy(),this.particleSystems.splice(t,1);const i=e.id;for(const{config:r}of this.particleSystems)r.followSystemId===i&&(r.followSystemId=null);return this.particleSystems.length===0?this.activeSystemIndex=0:t<=this.activeSystemIndex&&(this.activeSystemIndex=Math.max(0,this.activeSystemIndex-1)),!0}return!1}respawnAllSystems(){var t;(t=this.clock)==null||t.reset();for(const{system:e,config:i}of this.particleSystems)e.spawnParticles(()=>this._applyKeyframesToSystem(e,i,0))}getTotalDuration(){let t=0;for(const{config:e}of this.particleSystems){if(e.emissionDurationInfinite)return 1/0;const i=e.lifetime||5,r=(e.burstMode||e.oneOnlyMode?i:(e.emissionDuration||10)+i)+(e.startAt||0);r>t&&(t=r)}return t||1}updateAllSystems(t){const e=this.device.createCommandEncoder({label:"BatchedPhysicsEncoder"});let i=!1;const r=this.clock?this.clock.currentTime:0,n=this.clock?this.clock.duration:0;if(this.clock&&n>0&&isFinite(n)){const a=Math.min(1,this.clock.currentTime/n);for(const{system:o,config:l}of this.particleSystems)this._applyKeyframesToSystem(o,l,a)}for(const{system:a,config:o}of this.particleSystems){if(o.hidden||o.followSystemId)continue;const l=a.activeParticles>0;a.updateParticles(t,e,r),(l||a.activeParticles>0)&&(i=!0)}for(const{system:a,config:o}of this.particleSystems){if(o.hidden||!o.followSystemId)continue;const l=this.getSystemById(o.followSystemId);l&&(a._pendingFollowEmissions=l.system._newEmissions);const c=a.activeParticles>0;a.updateParticles(t,e,r),(c||a.activeParticles>0)&&(i=!0)}i&&this.device.queue.submit([e.finish()]);for(const{system:a}of this.particleSystems)a._newEmissions.length=0,a._pendingFollowEmissions=a._emptyEmissions}getSystemsList(){return this.particleSystems.map(({config:t},e)=>({name:t.name,id:t.id,index:e,isActive:e===this.activeSystemIndex,hidden:t.hidden||!1}))}duplicateActiveSystem(){if(this.particleSystems.length===0)return-1;const t=this.getActiveConfig(),e=JSON.parse(JSON.stringify(t));return e.name=`${t.name} (Copy)`,e.onAppearanceChange=null,e.onColorChange=null,e.onSizeChange=null,e.onSpeedChange=null,e.onPhysicsChange=null,e.onBloomIntensityChange=null,e.onRespawn=null,e.getActiveSystem=null,delete e.id,this.createParticleSystem(e)}async replaceSystems(t){var e;if(!t||!t.systems||!Array.isArray(t.systems))return console.error("Invalid scene data provided"),!1;this.ready=!1;try{this.particleSystems=[],this.systemCounter=1;for(const r of t.systems){const n=this.systemCounter++,a={...r,id:n},o=new kt(this.device,a);this.particleSystems.push({system:o,config:a})}const i={};t.systems.forEach((r,n)=>{i[r.id]=this.particleSystems[n].config.id});for(const{config:r}of this.particleSystems)r.followSystemId&&i[r.followSystemId]!==void 0&&(r.followSystemId=i[r.followSystemId]);t.activeSystemIndex!==void 0&&t.activeSystemIndex>=0&&t.activeSystemIndex<this.particleSystems.length?this.activeSystemIndex=t.activeSystemIndex:this.activeSystemIndex=0,this.loop=t.loop;for(const{system:r,config:n}of this.particleSystems)if(n.glbModelEnabled)try{let a=null;if(n.glbModelData)a=ji(n.glbModelData);else if(n.glbFileName){const o=await fetch(`/${n.glbFileName}`);o.ok?a=await o.arrayBuffer():console.warn(`GLB file not found: ${n.glbFileName}`)}if(a){if(await r.setGLBModel(a),n.animationIndex!==void 0&&r.glbAnimator&&r.glbAnimator.setAnimation(n.animationIndex),n.animationSpeed!==void 0&&r.glbAnimator&&(r.glbAnimator.speed=n.animationSpeed),n.animationLoop!==void 0&&r.glbAnimator&&(r.glbAnimator.loop=n.animationLoop),n.useGlbTexture&&(n.textureEnabled=!0),n.useGlbTexture&&((e=r.glbMeshData)!=null&&e.hasBaseColorTexture))try{const o=await oi(a);if(o){const l=await createImageBitmap(o.imageBlob);await r.setTexture(l),globalThis.__HZFX_DEBUG&&console.log(`GLB embedded texture restored for ${n.name}`)}}catch(o){console.warn(`Failed to restore GLB texture for ${n.name}:`,o),n.useGlbTexture=!1}}else n.glbModelEnabled=!1}catch(a){console.warn(`Failed to load GLB for ${n.name}:`,a),n.glbModelEnabled=!1}for(const{system:r,config:n}of this.particleSystems)if(n.textureEnabled&&!n.glbModelEnabled&&n.textureImageData)try{const a=new Image;await new Promise((l,c)=>{a.onload=l,a.onerror=c,a.src=n.textureImageData});const o=await createImageBitmap(a);await r.setTexture(o)}catch(a){console.warn(`Failed to restore texture for ${n.name}:`,a),n.textureEnabled=!1}for(const{system:r,config:n}of this.particleSystems)r.updateAppearanceUniform();return this.respawnAllSystems(),!0}catch(i){return console.error("Error replacing systems:",i),!1}finally{this.ready=!0}}async addSystems(t,e=[0,0,0]){var r;if(!t||!t.systems||!Array.isArray(t.systems))return console.error("Invalid scene data provided"),!1;this.ready=!1;const i=[];try{for(const o of t.systems){const l=this.systemCounter++;i.push(l);const c={...o,id:l,emissionPositionX:(o.emissionPositionX||0)+e[0],emissionPositionY:(o.emissionPositionY||0)+e[1],emissionPositionZ:(o.emissionPositionZ||0)+e[2]};o.attractorEnabled&&o.attractorPosition&&(c.attractorPosition=[o.attractorPosition[0]+e[0],o.attractorPosition[1]+e[1],o.attractorPosition[2]+e[2]]),o.confinementEnabled&&o.confinementSpace==="world"&&Array.isArray(o.confinementCenter)&&(c.confinementCenter=[(o.confinementCenter[0]||0)+e[0],(o.confinementCenter[1]||0)+e[1],(o.confinementCenter[2]||0)+e[2]]);const d=new kt(this.device,c);this.particleSystems.push({system:d,config:c}),this.onSystemCreated&&typeof this.onSystemCreated=="function"&&this.onSystemCreated(l,c)}const n=this.particleSystems.length-t.systems.length,a={};t.systems.forEach((o,l)=>{a[o.id]=this.particleSystems[n+l].config.id});for(let o=n;o<this.particleSystems.length;o++){const{config:l}=this.particleSystems[o];l.followSystemId&&a[l.followSystemId]!==void 0&&(l.followSystemId=a[l.followSystemId])}for(const{system:o,config:l}of this.particleSystems)if(l.glbModelEnabled&&!o.glbMeshData)try{let c=null;if(l.glbModelData)c=ji(l.glbModelData);else if(l.glbFileName){const d=await fetch(`/${l.glbFileName}`);d.ok?c=await d.arrayBuffer():console.warn(`GLB file not found: ${l.glbFileName}`)}if(c){if(await o.setGLBModel(c),l.animationIndex!==void 0&&o.glbAnimator&&o.glbAnimator.setAnimation(l.animationIndex),l.animationSpeed!==void 0&&o.glbAnimator&&(o.glbAnimator.speed=l.animationSpeed),l.animationLoop!==void 0&&o.glbAnimator&&(o.glbAnimator.loop=l.animationLoop),l.useGlbTexture&&(l.textureEnabled=!0),l.useGlbTexture&&((r=o.glbMeshData)!=null&&r.hasBaseColorTexture))try{const d=await oi(c);if(d){const S=await createImageBitmap(d.imageBlob);await o.setTexture(S),globalThis.__HZFX_DEBUG&&console.log(`GLB embedded texture restored for ${l.name}`)}}catch(d){console.warn(`Failed to restore GLB texture for ${l.name}:`,d),l.useGlbTexture=!1}}else l.glbModelEnabled=!1}catch(c){console.warn(`Failed to load GLB for ${l.name}:`,c),l.glbModelEnabled=!1}for(const{system:o,config:l}of this.particleSystems)if(l.textureEnabled&&!l.glbModelEnabled&&l.textureImageData&&!o._textureRestored)try{const c=new Image;await new Promise((S,b)=>{c.onload=S,c.onerror=b,c.src=l.textureImageData});const d=await createImageBitmap(c);await o.setTexture(d),o._textureRestored=!0}catch(c){console.warn(`Failed to restore texture for ${l.name}:`,c),l.textureEnabled=!1}return i}catch(n){return console.error("Error adding systems:",n),!1}finally{this.ready=!0}}_applyKeyframesToSystem(t,e,i){const r=e.keyframes;if(!r||e.keyframesEnabled===!1)return;let n=!1,a=!1,o=!1,l=!1,c=!1;for(const d of Fr){const S=r[d];if(!S||!S.length)continue;const b=Gr(S,i);if(b!==void 0){if(d==="damping"){e.dampingStrength=b,l=!0;continue}e[d]=b,(d==="particleSize"||d==="opacity")&&(n=!0),d==="bloomIntensity"&&(a=!0),d==="gravityStrength"&&(o=!0),d==="dampingStrength"&&(l=!0),(d==="attractorStrength"||d==="attractorReverse")&&(c=!0)}}if(r.particleColor&&r.particleColor.length){const d=e.particleColor,S=d&&typeof d.length=="number"&&d.length>=3?d:void 0,b=Dr(r.particleColor,i,S);b&&(e.particleColor=b,n=!0)}n&&t.updateAppearanceUniform(),a&&t.updateBloomIntensity(),o&&e.gravityEnabled&&t.setGravity(e.gravityStrength),l&&e.dampingEnabled&&t.physics.setDamping(e.dampingStrength),c&&e.attractorEnabled&&e.attractorPosition&&t.setAttractor(e.attractorStrength,e.attractorPosition,e.attractorReverse)}}async function ds(s){if(!s)throw new Error("canvas is required for initWebGPU()");if(!navigator.gpu)throw new Error("WebGPU not supported on this browser.");const t=s.getContext("webgpu"),i=await(await navigator.gpu.requestAdapter()).requestDevice(),r=navigator.gpu.getPreferredCanvasFormat();return t.configure({device:i,format:r,alphaMode:"premultiplied"}),{device:i,context:t,format:r,canvas:s}}const Xe="rgba16float",qi=.5,fs=(s,t)=>[Math.max(1,Math.round(s*qi)),Math.max(1,Math.round(t*qi))];function li(s,t,e,i){const r=s.createTexture({size:[e,i],format:Xe,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING,mipLevelCount:1,sampleCount:1}),[n,a]=fs(e,i),o=s.createTexture({size:[n,a],format:Xe,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING,mipLevelCount:1,sampleCount:1}),l=s.createTexture({size:[n,a],format:Xe,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING,mipLevelCount:1,sampleCount:1});return{sceneTexture:r,bloomTexA:o,bloomTexB:l}}function ci(s,t,e){return s.createTexture({size:[t,e],format:"depth24plus",usage:GPUTextureUsage.RENDER_ATTACHMENT})}function pt(s,t,e){const i=s.createBuffer({size:t.byteLength,usage:e,mappedAtCreation:!0});return new t.constructor(i.getMappedRange()).set(t),i.unmap(),i}const ps=`
|
|
898
898
|
struct Uniforms {
|
|
899
899
|
transform: mat4x4<f32>,
|
|
900
900
|
cameraPosition: vec3<f32>,
|
|
@@ -1192,7 +1192,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
|
|
|
1192
1192
|
|
|
1193
1193
|
return finalColor;
|
|
1194
1194
|
}
|
|
1195
|
-
`;function ms(s){const t=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),e=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),i=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),r=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]});return{particleBindGroupLayout:t,bloomBindGroupLayout:e,compositeBindGroupLayout:i,object3dBindGroupLayout:r}}function ys(s,t,e,i={}){const{depthCompare:r}=i,n=r||"less",{particleBindGroupLayout:a,bloomBindGroupLayout:o,compositeBindGroupLayout:l,object3dBindGroupLayout:c}=e,d=s.createPipelineLayout({bindGroupLayouts:[a]}),S=s.createPipelineLayout({bindGroupLayouts:[o]}),b=s.createPipelineLayout({bindGroupLayouts:[l]}),f=s.createShaderModule({code:Ki}),v=s.createShaderModule({code:Qi}),C=s.createShaderModule({code:es}),z=s.createShaderModule({code:ts}),G=s.createShaderModule({code:ps}),M=s.createShaderModule({code:hs}),Z=Nt=>s.createRenderPipeline({layout:d,vertex:{module:f,entryPoint:"vs_main",buffers:[{arrayStride:12,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]},{arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:1,offset:0,format:"float32x3"},{shaderLocation:2,offset:12,format:"float32x3"},{shaderLocation:3,offset:24,format:"float32x2"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:4,offset:0,format:"float32x3"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:5,offset:0,format:"float32x3"}]}]},fragment:{module:f,entryPoint:"fs_main",targets:[{format:Xe,blend:Nt}]},primitive:{topology:"triangle-list",cullMode:"none"},depthStencil:{depthWriteEnabled:!1,depthCompare:n,format:"depth24plus"}}),T=Z({color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),D=Z({color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),F=s.createRenderPipeline({layout:d,vertex:{module:f,entryPoint:"vs_main",buffers:[{arrayStride:12,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]},{arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:1,offset:0,format:"float32x3"},{shaderLocation:2,offset:12,format:"float32x3"},{shaderLocation:3,offset:24,format:"float32x2"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:4,offset:0,format:"float32x3"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:5,offset:0,format:"float32x3"}]}]},fragment:{module:f,entryPoint:"fs_main",targets:[{format:Xe,writeMask:0}]},primitive:{topology:"triangle-list",cullMode:"none"},depthStencil:{depthWriteEnabled:!0,depthCompare:"always",format:"depth24plus"}}),H=s.createRenderPipeline({layout:S,vertex:{module:v,entryPoint:"vs_main"},fragment:{module:v,entryPoint:"fs_main",targets:[{format:Xe}]},primitive:{topology:"triangle-list"}}),se=s.createRenderPipeline({layout:b,vertex:{module:C,entryPoint:"vs_main"},fragment:{module:C,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),ne=s.createRenderPipeline({layout:b,vertex:{module:z,entryPoint:"vs_main"},fragment:{module:z,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),re=s.createShaderModule({code:mr}),q=s.createRenderPipeline({layout:b,vertex:{module:re,entryPoint:"vs_main"},fragment:{module:re,entryPoint:"fs_main",targets:[{format:t,blend:{color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),tt=s.createPipelineLayout({bindGroupLayouts:[c]}),xt=s.createRenderPipeline({layout:tt,vertex:{module:G,entryPoint:"vs_main",buffers:[{arrayStride:24,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x3"}]}]},fragment:{module:G,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"back"},depthStencil:{depthWriteEnabled:!0,depthCompare:n,format:"depth24plus"}}),at=s.createRenderPipeline({layout:d,vertex:{module:M,entryPoint:"vs_main",buffers:[{arrayStride:32,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x3"},{shaderLocation:2,offset:24,format:"float32x2"}]},{arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:3,offset:0,format:"float32x3"},{shaderLocation:4,offset:12,format:"float32x3"},{shaderLocation:5,offset:24,format:"float32x2"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:6,offset:0,format:"float32x3"}]}]},fragment:{module:M,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"back"},depthStencil:{depthWriteEnabled:!0,depthCompare:n,format:"depth24plus"}});return{particlePipeline:T,particleAdditivePipeline:D,particleDepthWritePipeline:F,blurPipeline:H,compositePipeline:se,directRenderPipeline:ne,finalCompositePipeline:q,object3dPipeline:xt,glbMeshPipeline:at}}function Xt(s,t,e,i){const{uniformBuffer:r,appearanceUniformBuffer:n,horizontalBlurUniformBuffer:a,verticalBlurUniformBuffer:o,bloomIntensityBuffer:l}=e,{sceneTexture:c,bloomTexA:d,bloomTexB:S}=i,b=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:{buffer:r}},{binding:1,resource:{buffer:n}}]}),f=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:c.createView()},{binding:2,resource:{buffer:a}}]}),v=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:d.createView()},{binding:2,resource:{buffer:o}}]}),C=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:c.createView()},{binding:2,resource:S.createView()},{binding:3,resource:{buffer:l}}]}),z=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:c.createView()},{binding:2,resource:S.createView()},{binding:3,resource:{buffer:l}}]});return{particleBindGroup:b,horizontalBlurBindGroup:f,verticalBlurBindGroup:v,compositeBindGroup:C,directRenderBindGroup:z}}function gs(s){return s.createSampler({magFilter:"linear",minFilter:"linear",mipmapFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",maxAnisotropy:16})}function bs(){const s=new Float32Array([-.5,-.5,.5,0,0,1,.5,-.5,.5,0,0,1,.5,.5,.5,0,0,1,-.5,.5,.5,0,0,1,.5,-.5,-.5,0,0,-1,-.5,-.5,-.5,0,0,-1,-.5,.5,-.5,0,0,-1,.5,.5,-.5,0,0,-1,-.5,.5,.5,0,1,0,.5,.5,.5,0,1,0,.5,.5,-.5,0,1,0,-.5,.5,-.5,0,1,0,-.5,-.5,-.5,0,-1,0,.5,-.5,-.5,0,-1,0,.5,-.5,.5,0,-1,0,-.5,-.5,.5,0,-1,0,.5,-.5,.5,1,0,0,.5,-.5,-.5,1,0,0,.5,.5,-.5,1,0,0,.5,.5,.5,1,0,0,-.5,-.5,-.5,-1,0,0,-.5,-.5,.5,-1,0,0,-.5,.5,.5,-1,0,0,-.5,.5,-.5,-1,0,0]),t=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]);return{vertices:s,indices:t}}function Ss(s=16,t=16){const e=[],i=[];for(let r=0;r<=s;r++){const n=r*Math.PI/s,a=Math.sin(n),o=Math.cos(n);for(let l=0;l<=t;l++){const c=l*2*Math.PI/t,d=Math.sin(c),b=Math.cos(c)*a,f=o,v=d*a;e.push(b*.5,f*.5,v*.5),e.push(b,f,v)}}for(let r=0;r<s;r++)for(let n=0;n<t;n++){const a=r*(t+1)+n,o=a+t+1;i.push(a),i.push(o),i.push(a+1),i.push(o),i.push(o+1),i.push(a+1)}return{vertices:new Float32Array(e),indices:new Uint16Array(i)}}class Or{constructor(t,e,i,r,n){this.id=t,this.type=e,this.position=i,this.scale=r,this.color=n,this.rotation=[0,0,0]}getModelMatrix(){const{position:t,scale:e,rotation:i}=this,r=this.createTranslationMatrix(t),n=this.createRotationMatrixX(i[0]),a=this.createRotationMatrixY(i[1]),o=this.createRotationMatrixZ(i[2]),l=this.createScaleMatrix(e);let c=r;return c=this.multiplyMatrices(c,o),c=this.multiplyMatrices(c,a),c=this.multiplyMatrices(c,n),c=this.multiplyMatrices(c,l),c}getNormalMatrix(){return this.getModelMatrix()}createTranslationMatrix([t,e,i]){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,t,e,i,1])}createScaleMatrix([t,e,i]){return new Float32Array([t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1])}createRotationMatrixX(t){const e=Math.cos(t),i=Math.sin(t);return new Float32Array([1,0,0,0,0,e,i,0,0,-i,e,0,0,0,0,1])}createRotationMatrixY(t){const e=Math.cos(t),i=Math.sin(t);return new Float32Array([e,0,-i,0,0,1,0,0,i,0,e,0,0,0,0,1])}createRotationMatrixZ(t){const e=Math.cos(t),i=Math.sin(t);return new Float32Array([e,i,0,0,-i,e,0,0,0,0,1,0,0,0,0,1])}multiplyMatrices(t,e){const i=new Float32Array(16);for(let r=0;r<4;r++)for(let n=0;n<4;n++){let a=0;for(let o=0;o<4;o++)a+=t[r*4+o]*e[o*4+n];i[r*4+n]=a}return i}}class Lr{constructor(t){this.device=t,this.objects=[],this.nextId=0,this.initializeGeometry(),this.onObjectAdded=null,this.onObjectRemoved=null,this.onObjectUpdated=null}initializeGeometry(){const t=bs(),e=Ss(16,16);this.cubeVertexBuffer=pt(this.device,t.vertices,GPUBufferUsage.VERTEX),this.cubeIndexBuffer=pt(this.device,t.indices,GPUBufferUsage.INDEX),this.cubeIndexCount=t.indices.length,this.sphereVertexBuffer=pt(this.device,e.vertices,GPUBufferUsage.VERTEX),this.sphereIndexBuffer=pt(this.device,e.indices,GPUBufferUsage.INDEX),this.sphereIndexCount=e.indices.length}addObject(t,e=[0,0,0],i=[1,1,1],r=[1,1,1,1]){const n=new Or(this.nextId++,t,e,i,r);return n.uniformBuffer=this.device.createBuffer({size:192,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.objects.push(n),this.onObjectAdded&&this.onObjectAdded(n),n}removeObject(t){const e=this.objects.findIndex(i=>i.id===t);e!==-1&&(this.objects[e].uniformBuffer.destroy(),this.objects.splice(e,1),this.onObjectRemoved&&this.onObjectRemoved(t))}updateObjectPosition(t,e){const i=this.objects.find(r=>r.id===t);i&&(i.position=e,this.onObjectUpdated&&this.onObjectUpdated(i))}updateObjectScale(t,e){const i=this.objects.find(r=>r.id===t);i&&(i.scale=e,this.onObjectUpdated&&this.onObjectUpdated(i))}updateObjectColor(t,e){const i=this.objects.find(r=>r.id===t);i&&(i.color=e,this.onObjectUpdated&&this.onObjectUpdated(i))}getAllObjects(){return this.objects}getObject(t){return this.objects.find(e=>e.id===t)}updateObjectUniforms(t){const e=t.getModelMatrix(),i=t.getNormalMatrix(),r=new Float32Array(t.color);this.device.queue.writeBuffer(t.uniformBuffer,0,e),this.device.queue.writeBuffer(t.uniformBuffer,64,i),this.device.queue.writeBuffer(t.uniformBuffer,128,r)}renderObjects(t,e,i,r){for(const n of this.objects){this.updateObjectUniforms(n);const a=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:{buffer:r}},{binding:1,resource:{buffer:n.uniformBuffer}}]});let o,l,c;if(n.type==="cube")o=this.cubeVertexBuffer,l=this.cubeIndexBuffer,c=this.cubeIndexCount;else if(n.type==="sphere")o=this.sphereVertexBuffer,l=this.sphereIndexBuffer,c=this.sphereIndexCount;else continue;t.setPipeline(e),t.setBindGroup(0,a),t.setVertexBuffer(0,o),t.setIndexBuffer(l,"uint16"),t.drawIndexed(c)}}}function kr(s){const t=parseInt(s.slice(1,3),16)/255,e=parseInt(s.slice(3,5),16)/255,i=parseInt(s.slice(5,7),16)/255;return[t,e,i]}function Xr(s){if(!s)return"#ffffff";const t=Math.round(s[0]*255).toString(16).padStart(2,"0"),e=Math.round(s[1]*255).toString(16).padStart(2,"0"),i=Math.round(s[2]*255).toString(16).padStart(2,"0");return`#${t}${e}${i}`}function Nr(s,t,e){const i=Hi([s[0]-t[0],s[1]-t[1],s[2]-t[2]]),r=Hi(Zi(e,i)),n=Zi(i,r);return new Float32Array([r[0],n[0],i[0],0,r[1],n[1],i[1],0,r[2],n[2],i[2],0,-ri(r,s),-ri(n,s),-ri(i,s),1])}function Yr(s,t=Math.PI/4){const r=1/Math.tan(t/2);return new Float32Array([r*s,0,0,0,0,r,0,0,0,0,(100+.1)/(.1-100),-1,0,0,200*.1/(.1-100),0])}function Hi(s){const t=Math.sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]);return[s[0]/t,s[1]/t,s[2]/t]}function Zi(s,t){return[s[1]*t[2]-s[2]*t[1],s[2]*t[0]-s[0]*t[2],s[0]*t[1]-s[1]*t[0]]}function ri(s,t){return s[0]*t[0]+s[1]*t[1]+s[2]*t[2]}function xs(s,t){const e=new Float32Array(16);for(let i=0;i<4;i++)for(let r=0;r<4;r++){let n=0;for(let a=0;a<4;a++)n+=s[i+a*4]*t[a+r*4];e[i+r*4]=n}return e}const ui=1481005640,vs=1,Ps=1313821514,_s=5130562,At="$hzfxAsset",Ms=s=>typeof atob=="function"?Uint8Array.from(atob(s),t=>t.charCodeAt(0)):new Uint8Array(Buffer.from(s,"base64")),Wi=s=>{if(typeof btoa=="function"){let t="";for(let e=0;e<s.length;e++)t+=String.fromCharCode(s[e]);return btoa(t)}return Buffer.from(s).toString("base64")};function jr(s){const t=s.indexOf(","),e=s.slice(5,t),i=e.split(";")[0]||"application/octet-stream",r=s.slice(t+1),a=/;base64/i.test(e)?Ms(r):new TextEncoder().encode(decodeURIComponent(r));return{mime:i,bytes:a}}function $i(s){return(4-s%4)%4}async function ws(s,t={}){const{textureFormat:e="keep",quality:i=.85}=t,r=[],n=[];let a=0;const o=(D,F,H)=>{const se=a,ne=D.length;r.push({offset:se,length:ne,mime:F,kind:H}),n.push(D),a+=ne;const re=$i(ne);return re&&(n.push(new Uint8Array(re)),a+=re),r.length-1},l=e==="webp"&&typeof OffscreenCanvas<"u"&&typeof createImageBitmap=="function",c=[];for(const D of s.systems||[]){const F={...D};if(typeof F.textureImageData=="string"&&F.textureImageData.startsWith("data:")){let{mime:H,bytes:se}=jr(F.textureImageData);if(l&&H!=="image/webp")try{const ne=await createImageBitmap(new Blob([se],{type:H})),re=new OffscreenCanvas(ne.width,ne.height);re.getContext("2d").drawImage(ne,0,0);const q=await re.convertToBlob({type:"image/webp",quality:i}),tt=new Uint8Array(await q.arrayBuffer());tt.length<se.length&&(se=tt,H="image/webp")}catch{}F.textureImageData={[At]:o(se,H,"texture")}}if(typeof F.glbModelData=="string"&&F.glbModelData.length>0){const H=Ms(F.glbModelData);F.glbModelData={[At]:o(H,"model/gltf-binary","glb")}}c.push(F)}const d={...s,systems:c,assets:r},S=new TextEncoder().encode(JSON.stringify(d)),b=$i(S.length),f=new Uint8Array(a);let v=0;for(const D of n)f.set(D,v),v+=D.length;const C=S.length+b,z=20+C+8+a,G=new ArrayBuffer(z),M=new DataView(G),Z=new Uint8Array(G);let T=0;M.setUint32(T,ui,!0),T+=4,M.setUint32(T,vs,!0),T+=4,M.setUint32(T,z,!0),T+=4,M.setUint32(T,C,!0),T+=4,M.setUint32(T,Ps,!0),T+=4,Z.set(S,T),T+=S.length;for(let D=0;D<b;D++)Z[T++]=32;return M.setUint32(T,a,!0),T+=4,M.setUint32(T,_s,!0),T+=4,Z.set(f,T),T+=a,G}function di(s){return!s||s.byteLength<12?!1:new DataView(s).getUint32(0,!0)===ui}function fi(s){const t=new DataView(s);if(t.getUint32(0,!0)!==ui)throw new Error("[unpackHZFX] bad magic — not an .hzfx file");const e=t.getUint32(4,!0);if(e!==vs)throw new Error(`[unpackHZFX] unsupported version ${e}`);let i=12,r=null,n=-1;const a=new Uint8Array(s);for(;i+8<=s.byteLength;){const b=t.getUint32(i,!0);i+=4;const f=t.getUint32(i,!0);i+=4,f===Ps?r=JSON.parse(new TextDecoder().decode(a.subarray(i,i+b))):f===_s&&(n=i),i+=b}if(!r)throw new Error("[unpackHZFX] missing JSON chunk");const o=r.assets||[],l=b=>{const f=o[b];return!f||n<0?null:{...f,bytes:a.subarray(n+f.offset,n+f.offset+f.length)}},c=b=>b&&typeof b=="object"&&typeof b[At]=="number",d=(r.systems||[]).map(b=>{const f={...b};if(c(f.textureImageData)){const v=l(f.textureImageData[At]);f.textureImageData=v?`data:${v.mime};base64,${Wi(v.bytes)}`:void 0}if(c(f.glbModelData)){const v=l(f.glbModelData[At]);f.glbModelData=v?Wi(v.bytes):void 0}return f}),S={...r,systems:d};return delete S.assets,S}function qr(s){const t=new Uint8Array(s);let e="";for(let i=0;i<t.byteLength;i++)e+=String.fromCharCode(t[i]);return btoa(e)}function Bs(s){return{name:s.name,id:s.id,particleCount:s.particleCount,lifetime:s.lifetime,emissionRate:s.emissionRate,emissionDuration:s.emissionDuration,emissionDurationInfinite:s.emissionDurationInfinite||!1,startAt:s.startAt||0,keyframes:s.keyframes||null,keyframesEnabled:s.keyframesEnabled!==!1,particleSize:s.particleSize,particleSpeed:s.particleSpeed,emissionShape:s.emissionShape,outerLength:s.outerLength??s.cubeLength,innerLength:s.innerLength,outerRadius:s.outerRadius,innerRadius:s.innerRadius,squareSize:s.squareSize,squareInnerSize:s.squareInnerSize,circleInnerRadius:s.circleInnerRadius,circleOuterRadius:s.circleOuterRadius,fadeEnabled:s.fadeEnabled,colorTransitionEnabled:s.colorTransitionEnabled,particleColor:s.particleColor,startColor:s.startColor,endColor:s.endColor,randomColorEnabled:s.randomColorEnabled||!1,randomColors:s.randomColors||[],particleShape:s.particleShape||"square",particleShapeRotationX:s.particleShapeRotationX||0,particleShapeRotationY:s.particleShapeRotationY||0,particleShapeRotationZ:s.particleShapeRotationZ||0,pulseEnabled:s.pulseEnabled||!1,pulseAmplitude:s.pulseAmplitude??.5,pulseFrequency:s.pulseFrequency??1,pulsePhaseRandom:s.pulsePhaseRandom??0,pulseOpacity:s.pulseOpacity||!1,bloomEnabled:s.bloomEnabled,bloomIntensity:s.bloomIntensity,bloomColor:s.bloomColor,depthWriteEnabled:s.depthWriteEnabled||!1,burstMode:s.burstMode,gravityEnabled:s.gravityEnabled,gravityStrength:s.gravityStrength,dampingEnabled:s.dampingEnabled,dampingStrength:s.dampingStrength,attractorEnabled:s.attractorEnabled,attractorStrength:s.attractorStrength,attractorReverse:s.attractorReverse??!1,attractorPosition:s.attractorPosition,emissionRotationX:s.emissionRotationX,emissionRotationY:s.emissionRotationY,emissionRotationZ:s.emissionRotationZ,orientToDirection:s.orientToDirection??!1,emissionPositionX:s.emissionPositionX,emissionPositionY:s.emissionPositionY,emissionPositionZ:s.emissionPositionZ,rotation:s.rotation,rotationMode:s.rotationMode,minRotation:s.minRotation,maxRotation:s.maxRotation,orientX:s.orientX,orientY:s.orientY,orientZ:s.orientZ,overrideXVelocity:s.overrideXVelocity,overrideYVelocity:s.overrideYVelocity,overrideZVelocity:s.overrideZVelocity,xVelocity:s.xVelocity,yVelocity:s.yVelocity,zVelocity:s.zVelocity,circleVelocityDirection:s.circleVelocityDirection,cylinderVelocityDirection:s.cylinderVelocityDirection,cylinderInnerRadius:s.cylinderInnerRadius,cylinderOuterRadius:s.cylinderOuterRadius,cylinderHeight:s.cylinderHeight,planeWidth:s.planeWidth,planeDepth:s.planeDepth,rectangleWidth:s.rectangleWidth,rectangleHeight:s.rectangleHeight,coneOuterRadius:s.coneOuterRadius,coneInnerRadius:s.coneInnerRadius,coneHeight:s.coneHeight,torusMajorRadius:s.torusMajorRadius,torusMinorRadius:s.torusMinorRadius,lineLength:s.lineLength,hemisphereOuterRadius:s.hemisphereOuterRadius,hemisphereInnerRadius:s.hemisphereInnerRadius,discRadius:s.discRadius,annulusInnerRadius:s.annulusInnerRadius,annulusOuterRadius:s.annulusOuterRadius,capsuleRadius:s.capsuleRadius,capsuleHeight:s.capsuleHeight,arcStartAngle:s.arcStartAngle,arcEndAngle:s.arcEndAngle,arcInnerRadius:s.arcInnerRadius,arcOuterRadius:s.arcOuterRadius,spiralTurns:s.spiralTurns,spiralRadiusStart:s.spiralRadiusStart,spiralRadiusEnd:s.spiralRadiusEnd,spiralHeight:s.spiralHeight,frustumRadiusNear:s.frustumRadiusNear,frustumRadiusFar:s.frustumRadiusFar,frustumHeight:s.frustumHeight,cubeSurfaceSize:s.cubeSurfaceSize,sphereSurfaceRadius:s.sphereSurfaceRadius,boxFrameSize:s.boxFrameSize,polygonSides:s.polygonSides,polygonRadius:s.polygonRadius,aspectRatio:s.aspectRatio,randomSize:s.randomSize,minSize:s.minSize,maxSize:s.maxSize,fadeSizeEnabled:s.fadeSizeEnabled,increaseSizeEnabled:s.increaseSizeEnabled,sizeLifetimeSpeed:s.sizeLifetimeSpeed,opacity:s.opacity,randomSpeed:s.randomSpeed,minSpeed:s.minSpeed,maxSpeed:s.maxSpeed,oneOnlyMode:s.oneOnlyMode,confinementEnabled:s.confinementEnabled||!1,confinementShape:s.confinementShape||"box",confinementMode:s.confinementMode||"bounce",confinementSpace:s.confinementSpace||"world",confinementBoxHalfSize:s.confinementBoxHalfSize||[2,2,2],confinementSphereRadius:s.confinementSphereRadius??3,confinementRestitution:s.confinementRestitution??.8,confinementFriction:s.confinementFriction??.1,confinementCenter:s.confinementCenter,softBoundaryEnabled:s.softBoundaryEnabled||!1,softBoundaryStrength:s.softBoundaryStrength??5,softBoundaryFalloff:s.softBoundaryFalloff??.5,followSystemId:s.followSystemId||null,followSystemTranslation:s.followSystemTranslation??!0,hidden:s.hidden||!1,emissionTrailEnabled:s.emissionTrailEnabled||!1,emissionTrailDuration:s.emissionTrailDuration??1,emissionTrailWidth:s.emissionTrailWidth??.5,emissionTrailMinDistance:s.emissionTrailMinDistance??.05,emissionTrailMaxPoints:s.emissionTrailMaxPoints??100,emissionTrailSegments:s.emissionTrailSegments??8,emissionTrailMode:s.emissionTrailMode??"ribbon",emissionTrailShape:s.emissionTrailShape??"straight",emissionTrailShapeAmplitude:s.emissionTrailShapeAmplitude??.1,emissionTrailShapeFrequency:s.emissionTrailShapeFrequency??4,emissionTrailShapeSpeed:s.emissionTrailShapeSpeed??0,shapeStrokeEnabled:s.shapeStrokeEnabled||!1,shapeStrokeWidth:s.shapeStrokeWidth??.08,shapeStrokeSegments:s.shapeStrokeSegments??96,shapeStrokeShape:s.shapeStrokeShape??"straight",shapeStrokeAmplitude:s.shapeStrokeAmplitude??.08,shapeStrokeFrequency:s.shapeStrokeFrequency??10,shapeStrokeSpeed:s.shapeStrokeSpeed??0,shapeDisplay:s.shapeDisplay??!0,blendMode:s.blendMode??"normal",noiseDistortEnabled:s.noiseDistortEnabled||!1,noiseTilingX:s.noiseTilingX??3,noiseTilingY:s.noiseTilingY??3,noiseSpeed:s.noiseSpeed??-1.5,noiseAmplitude:s.noiseAmplitude??.08,velocityStretchEnabled:s.velocityStretchEnabled||!1,velocityStretchFactor:s.velocityStretchFactor??1,textureEnabled:s.textureEnabled||!1,textureType:s.textureType,textureFileName:s.textureFileName,imageDescription:s.imageDescription,glbModelEnabled:s.glbModelEnabled||!1,glbFileName:s.glbFileName,glbHasTexture:s.glbHasTexture||!1,useGlbTexture:s.useGlbTexture||!1,glbAnimated:s.glbAnimated||!1,animationIndex:s.animationIndex,animationSpeed:s.animationSpeed,animationLoop:s.animationLoop,glbDescription:s.glbDescription,script:s.script||void 0,displayUnit:s.displayUnit||"m"}}async function Hr(s,t,e="hzfx"){if(!s||!s.particleSystems||s.particleSystems.length===0){alert("No particle systems to save.");return}try{const i={version:"1.0",timestamp:new Date().toISOString(),systems:s.particleSystems.map(({config:d,system:S})=>({...Bs(d),textureImageData:d.textureEnabled&&!d.glbModelEnabled&&d.textureImageData?d.textureImageData:void 0,glbModelData:d.glbModelEnabled&&S.glbRawArrayBuffer?qr(S.glbRawArrayBuffer):void 0})),activeSystemIndex:s.activeSystemIndex,loop:s.loop||!1},r=e==="json"?"json":"hzfx";let n;if(r==="hzfx"){const d=await ws(i,{textureFormat:"webp"});n=new Blob([d],{type:"application/octet-stream"})}else n=new Blob([JSON.stringify(i,null,2)],{type:"application/json"});let a;if(t)a=t;else{const d=new Date;a=`particle-scene_${`${d.getFullYear()}-${(d.getMonth()+1).toString().padStart(2,"0")}-${d.getDate().toString().padStart(2,"0")}_${d.getHours().toString().padStart(2,"0")}${d.getMinutes().toString().padStart(2,"0")}`}`}const o=`${a}.${r}`,l=URL.createObjectURL(n),c=document.createElement("a");c.href=l,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(l)}catch(i){console.error("Error saving scene:",i),alert("Error saving scene. See console for details.")}}function Zr(s){return new Promise((t,e)=>{try{const i=s.target.files[0];if(!i){e(new Error("No file selected"));return}const r=new FileReader;r.onload=n=>{try{const a=n.target.result;let o;if(di(a)?o=fi(a):o=JSON.parse(new TextDecoder().decode(a)),!Array.isArray(o.systems)||o.systems.length===0)throw new Error("No valid particle systems found in the file");t({systems:o.systems.slice(),activeSystemIndex:o.activeSystemIndex||0})}catch(a){console.error("Error loading scene:",a),alert("Error loading scene: "+a.message),e(a)}s.target.value=""},r.onerror=()=>{alert("Failed to read the file"),e(new Error("Failed to read the file")),s.target.value=""},r.readAsArrayBuffer(i)}catch(i){console.error("Error in loadScene:",i),e(i)}})}async function Wr(s){if(!s||typeof s!="string")throw new Error("[fetchPreset] url must be a non-empty string");const t=await fetch(s);if(!t.ok)throw new Error(`[fetchPreset] HTTP ${t.status}: ${t.statusText}`);const e=await t.arrayBuffer();let i;if(di(e)?i=fi(e):i=JSON.parse(new TextDecoder().decode(e)),!Array.isArray(i.systems)||i.systems.length===0)throw new Error('[fetchPreset] Invalid preset: "systems" must be a non-empty array');return{version:i.version,systems:i.systems,activeSystemIndex:i.activeSystemIndex??0}}const $r=s=>`
|
|
1195
|
+
`;function ms(s){const t=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),e=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),i=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),r=s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]});return{particleBindGroupLayout:t,bloomBindGroupLayout:e,compositeBindGroupLayout:i,object3dBindGroupLayout:r}}function ys(s,t,e,i={}){const{depthCompare:r}=i,n=r||"less",{particleBindGroupLayout:a,bloomBindGroupLayout:o,compositeBindGroupLayout:l,object3dBindGroupLayout:c}=e,d=s.createPipelineLayout({bindGroupLayouts:[a]}),S=s.createPipelineLayout({bindGroupLayouts:[o]}),b=s.createPipelineLayout({bindGroupLayouts:[l]}),f=s.createShaderModule({code:Ki}),v=s.createShaderModule({code:Qi}),U=s.createShaderModule({code:es}),z=s.createShaderModule({code:ts}),G=s.createShaderModule({code:ps}),M=s.createShaderModule({code:hs}),Z=Nt=>s.createRenderPipeline({layout:d,vertex:{module:f,entryPoint:"vs_main",buffers:[{arrayStride:12,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]},{arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:1,offset:0,format:"float32x3"},{shaderLocation:2,offset:12,format:"float32x3"},{shaderLocation:3,offset:24,format:"float32x2"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:4,offset:0,format:"float32x3"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:5,offset:0,format:"float32x3"}]}]},fragment:{module:f,entryPoint:"fs_main",targets:[{format:Xe,blend:Nt}]},primitive:{topology:"triangle-list",cullMode:"none"},depthStencil:{depthWriteEnabled:!1,depthCompare:n,format:"depth24plus"}}),T=Z({color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),D=Z({color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),F=s.createRenderPipeline({layout:d,vertex:{module:f,entryPoint:"vs_main",buffers:[{arrayStride:12,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"}]},{arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:1,offset:0,format:"float32x3"},{shaderLocation:2,offset:12,format:"float32x3"},{shaderLocation:3,offset:24,format:"float32x2"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:4,offset:0,format:"float32x3"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:5,offset:0,format:"float32x3"}]}]},fragment:{module:f,entryPoint:"fs_main",targets:[{format:Xe,writeMask:0}]},primitive:{topology:"triangle-list",cullMode:"none"},depthStencil:{depthWriteEnabled:!0,depthCompare:"always",format:"depth24plus"}}),H=s.createRenderPipeline({layout:S,vertex:{module:v,entryPoint:"vs_main"},fragment:{module:v,entryPoint:"fs_main",targets:[{format:Xe}]},primitive:{topology:"triangle-list"}}),se=s.createRenderPipeline({layout:b,vertex:{module:U,entryPoint:"vs_main"},fragment:{module:U,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),ne=s.createRenderPipeline({layout:b,vertex:{module:z,entryPoint:"vs_main"},fragment:{module:z,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),re=s.createShaderModule({code:mr}),q=s.createRenderPipeline({layout:b,vertex:{module:re,entryPoint:"vs_main"},fragment:{module:re,entryPoint:"fs_main",targets:[{format:t,blend:{color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),tt=s.createPipelineLayout({bindGroupLayouts:[c]}),xt=s.createRenderPipeline({layout:tt,vertex:{module:G,entryPoint:"vs_main",buffers:[{arrayStride:24,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x3"}]}]},fragment:{module:G,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"back"},depthStencil:{depthWriteEnabled:!0,depthCompare:n,format:"depth24plus"}}),at=s.createRenderPipeline({layout:d,vertex:{module:M,entryPoint:"vs_main",buffers:[{arrayStride:32,stepMode:"vertex",attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x3"},{shaderLocation:2,offset:24,format:"float32x2"}]},{arrayStride:32,stepMode:"instance",attributes:[{shaderLocation:3,offset:0,format:"float32x3"},{shaderLocation:4,offset:12,format:"float32x3"},{shaderLocation:5,offset:24,format:"float32x2"}]},{arrayStride:16,stepMode:"instance",attributes:[{shaderLocation:6,offset:0,format:"float32x3"}]}]},fragment:{module:M,entryPoint:"fs_main",targets:[{format:Xe,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"back"},depthStencil:{depthWriteEnabled:!0,depthCompare:n,format:"depth24plus"}});return{particlePipeline:T,particleAdditivePipeline:D,particleDepthWritePipeline:F,blurPipeline:H,compositePipeline:se,directRenderPipeline:ne,finalCompositePipeline:q,object3dPipeline:xt,glbMeshPipeline:at}}function Xt(s,t,e,i){const{uniformBuffer:r,appearanceUniformBuffer:n,horizontalBlurUniformBuffer:a,verticalBlurUniformBuffer:o,bloomIntensityBuffer:l}=e,{sceneTexture:c,bloomTexA:d,bloomTexB:S}=i,b=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:{buffer:r}},{binding:1,resource:{buffer:n}}]}),f=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:c.createView()},{binding:2,resource:{buffer:a}}]}),v=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:d.createView()},{binding:2,resource:{buffer:o}}]}),U=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:c.createView()},{binding:2,resource:S.createView()},{binding:3,resource:{buffer:l}}]}),z=s.createBindGroup({layout:s.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:3,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}}]}),entries:[{binding:0,resource:t},{binding:1,resource:c.createView()},{binding:2,resource:S.createView()},{binding:3,resource:{buffer:l}}]});return{particleBindGroup:b,horizontalBlurBindGroup:f,verticalBlurBindGroup:v,compositeBindGroup:U,directRenderBindGroup:z}}function gs(s){return s.createSampler({magFilter:"linear",minFilter:"linear",mipmapFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",maxAnisotropy:16})}function bs(){const s=new Float32Array([-.5,-.5,.5,0,0,1,.5,-.5,.5,0,0,1,.5,.5,.5,0,0,1,-.5,.5,.5,0,0,1,.5,-.5,-.5,0,0,-1,-.5,-.5,-.5,0,0,-1,-.5,.5,-.5,0,0,-1,.5,.5,-.5,0,0,-1,-.5,.5,.5,0,1,0,.5,.5,.5,0,1,0,.5,.5,-.5,0,1,0,-.5,.5,-.5,0,1,0,-.5,-.5,-.5,0,-1,0,.5,-.5,-.5,0,-1,0,.5,-.5,.5,0,-1,0,-.5,-.5,.5,0,-1,0,.5,-.5,.5,1,0,0,.5,-.5,-.5,1,0,0,.5,.5,-.5,1,0,0,.5,.5,.5,1,0,0,-.5,-.5,-.5,-1,0,0,-.5,-.5,.5,-1,0,0,-.5,.5,.5,-1,0,0,-.5,.5,-.5,-1,0,0]),t=new Uint16Array([0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]);return{vertices:s,indices:t}}function Ss(s=16,t=16){const e=[],i=[];for(let r=0;r<=s;r++){const n=r*Math.PI/s,a=Math.sin(n),o=Math.cos(n);for(let l=0;l<=t;l++){const c=l*2*Math.PI/t,d=Math.sin(c),b=Math.cos(c)*a,f=o,v=d*a;e.push(b*.5,f*.5,v*.5),e.push(b,f,v)}}for(let r=0;r<s;r++)for(let n=0;n<t;n++){const a=r*(t+1)+n,o=a+t+1;i.push(a),i.push(o),i.push(a+1),i.push(o),i.push(o+1),i.push(a+1)}return{vertices:new Float32Array(e),indices:new Uint16Array(i)}}class Or{constructor(t,e,i,r,n){this.id=t,this.type=e,this.position=i,this.scale=r,this.color=n,this.rotation=[0,0,0]}getModelMatrix(){const{position:t,scale:e,rotation:i}=this,r=this.createTranslationMatrix(t),n=this.createRotationMatrixX(i[0]),a=this.createRotationMatrixY(i[1]),o=this.createRotationMatrixZ(i[2]),l=this.createScaleMatrix(e);let c=r;return c=this.multiplyMatrices(c,o),c=this.multiplyMatrices(c,a),c=this.multiplyMatrices(c,n),c=this.multiplyMatrices(c,l),c}getNormalMatrix(){return this.getModelMatrix()}createTranslationMatrix([t,e,i]){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,t,e,i,1])}createScaleMatrix([t,e,i]){return new Float32Array([t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1])}createRotationMatrixX(t){const e=Math.cos(t),i=Math.sin(t);return new Float32Array([1,0,0,0,0,e,i,0,0,-i,e,0,0,0,0,1])}createRotationMatrixY(t){const e=Math.cos(t),i=Math.sin(t);return new Float32Array([e,0,-i,0,0,1,0,0,i,0,e,0,0,0,0,1])}createRotationMatrixZ(t){const e=Math.cos(t),i=Math.sin(t);return new Float32Array([e,i,0,0,-i,e,0,0,0,0,1,0,0,0,0,1])}multiplyMatrices(t,e){const i=new Float32Array(16);for(let r=0;r<4;r++)for(let n=0;n<4;n++){let a=0;for(let o=0;o<4;o++)a+=t[r*4+o]*e[o*4+n];i[r*4+n]=a}return i}}class Lr{constructor(t){this.device=t,this.objects=[],this.nextId=0,this.initializeGeometry(),this.onObjectAdded=null,this.onObjectRemoved=null,this.onObjectUpdated=null}initializeGeometry(){const t=bs(),e=Ss(16,16);this.cubeVertexBuffer=pt(this.device,t.vertices,GPUBufferUsage.VERTEX),this.cubeIndexBuffer=pt(this.device,t.indices,GPUBufferUsage.INDEX),this.cubeIndexCount=t.indices.length,this.sphereVertexBuffer=pt(this.device,e.vertices,GPUBufferUsage.VERTEX),this.sphereIndexBuffer=pt(this.device,e.indices,GPUBufferUsage.INDEX),this.sphereIndexCount=e.indices.length}addObject(t,e=[0,0,0],i=[1,1,1],r=[1,1,1,1]){const n=new Or(this.nextId++,t,e,i,r);return n.uniformBuffer=this.device.createBuffer({size:192,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.objects.push(n),this.onObjectAdded&&this.onObjectAdded(n),n}removeObject(t){const e=this.objects.findIndex(i=>i.id===t);e!==-1&&(this.objects[e].uniformBuffer.destroy(),this.objects.splice(e,1),this.onObjectRemoved&&this.onObjectRemoved(t))}updateObjectPosition(t,e){const i=this.objects.find(r=>r.id===t);i&&(i.position=e,this.onObjectUpdated&&this.onObjectUpdated(i))}updateObjectScale(t,e){const i=this.objects.find(r=>r.id===t);i&&(i.scale=e,this.onObjectUpdated&&this.onObjectUpdated(i))}updateObjectColor(t,e){const i=this.objects.find(r=>r.id===t);i&&(i.color=e,this.onObjectUpdated&&this.onObjectUpdated(i))}getAllObjects(){return this.objects}getObject(t){return this.objects.find(e=>e.id===t)}updateObjectUniforms(t){const e=t.getModelMatrix(),i=t.getNormalMatrix(),r=new Float32Array(t.color);this.device.queue.writeBuffer(t.uniformBuffer,0,e),this.device.queue.writeBuffer(t.uniformBuffer,64,i),this.device.queue.writeBuffer(t.uniformBuffer,128,r)}renderObjects(t,e,i,r){for(const n of this.objects){this.updateObjectUniforms(n);const a=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:{buffer:r}},{binding:1,resource:{buffer:n.uniformBuffer}}]});let o,l,c;if(n.type==="cube")o=this.cubeVertexBuffer,l=this.cubeIndexBuffer,c=this.cubeIndexCount;else if(n.type==="sphere")o=this.sphereVertexBuffer,l=this.sphereIndexBuffer,c=this.sphereIndexCount;else continue;t.setPipeline(e),t.setBindGroup(0,a),t.setVertexBuffer(0,o),t.setIndexBuffer(l,"uint16"),t.drawIndexed(c)}}}function kr(s){const t=parseInt(s.slice(1,3),16)/255,e=parseInt(s.slice(3,5),16)/255,i=parseInt(s.slice(5,7),16)/255;return[t,e,i]}function Xr(s){if(!s)return"#ffffff";const t=Math.round(s[0]*255).toString(16).padStart(2,"0"),e=Math.round(s[1]*255).toString(16).padStart(2,"0"),i=Math.round(s[2]*255).toString(16).padStart(2,"0");return`#${t}${e}${i}`}function Nr(s,t,e){const i=Hi([s[0]-t[0],s[1]-t[1],s[2]-t[2]]),r=Hi(Zi(e,i)),n=Zi(i,r);return new Float32Array([r[0],n[0],i[0],0,r[1],n[1],i[1],0,r[2],n[2],i[2],0,-ri(r,s),-ri(n,s),-ri(i,s),1])}function Yr(s,t=Math.PI/4){const r=1/Math.tan(t/2);return new Float32Array([r*s,0,0,0,0,r,0,0,0,0,(100+.1)/(.1-100),-1,0,0,200*.1/(.1-100),0])}function Hi(s){const t=Math.sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]);return[s[0]/t,s[1]/t,s[2]/t]}function Zi(s,t){return[s[1]*t[2]-s[2]*t[1],s[2]*t[0]-s[0]*t[2],s[0]*t[1]-s[1]*t[0]]}function ri(s,t){return s[0]*t[0]+s[1]*t[1]+s[2]*t[2]}function xs(s,t){const e=new Float32Array(16);for(let i=0;i<4;i++)for(let r=0;r<4;r++){let n=0;for(let a=0;a<4;a++)n+=s[i+a*4]*t[a+r*4];e[i+r*4]=n}return e}const ui=1481005640,vs=1,Ps=1313821514,_s=5130562,At="$hzfxAsset",Ms=s=>typeof atob=="function"?Uint8Array.from(atob(s),t=>t.charCodeAt(0)):new Uint8Array(Buffer.from(s,"base64")),Wi=s=>{if(typeof btoa=="function"){let t="";for(let e=0;e<s.length;e++)t+=String.fromCharCode(s[e]);return btoa(t)}return Buffer.from(s).toString("base64")};function jr(s){const t=s.indexOf(","),e=s.slice(5,t),i=e.split(";")[0]||"application/octet-stream",r=s.slice(t+1),a=/;base64/i.test(e)?Ms(r):new TextEncoder().encode(decodeURIComponent(r));return{mime:i,bytes:a}}function $i(s){return(4-s%4)%4}async function ws(s,t={}){const{textureFormat:e="keep",quality:i=.85}=t,r=[],n=[];let a=0;const o=(D,F,H)=>{const se=a,ne=D.length;r.push({offset:se,length:ne,mime:F,kind:H}),n.push(D),a+=ne;const re=$i(ne);return re&&(n.push(new Uint8Array(re)),a+=re),r.length-1},l=e==="webp"&&typeof OffscreenCanvas<"u"&&typeof createImageBitmap=="function",c=[];for(const D of s.systems||[]){const F={...D};if(typeof F.textureImageData=="string"&&F.textureImageData.startsWith("data:")){let{mime:H,bytes:se}=jr(F.textureImageData);if(l&&H!=="image/webp")try{const ne=await createImageBitmap(new Blob([se],{type:H})),re=new OffscreenCanvas(ne.width,ne.height);re.getContext("2d").drawImage(ne,0,0);const q=await re.convertToBlob({type:"image/webp",quality:i}),tt=new Uint8Array(await q.arrayBuffer());tt.length<se.length&&(se=tt,H="image/webp")}catch{}F.textureImageData={[At]:o(se,H,"texture")}}if(typeof F.glbModelData=="string"&&F.glbModelData.length>0){const H=Ms(F.glbModelData);F.glbModelData={[At]:o(H,"model/gltf-binary","glb")}}c.push(F)}const d={...s,systems:c,assets:r},S=new TextEncoder().encode(JSON.stringify(d)),b=$i(S.length),f=new Uint8Array(a);let v=0;for(const D of n)f.set(D,v),v+=D.length;const U=S.length+b,z=20+U+8+a,G=new ArrayBuffer(z),M=new DataView(G),Z=new Uint8Array(G);let T=0;M.setUint32(T,ui,!0),T+=4,M.setUint32(T,vs,!0),T+=4,M.setUint32(T,z,!0),T+=4,M.setUint32(T,U,!0),T+=4,M.setUint32(T,Ps,!0),T+=4,Z.set(S,T),T+=S.length;for(let D=0;D<b;D++)Z[T++]=32;return M.setUint32(T,a,!0),T+=4,M.setUint32(T,_s,!0),T+=4,Z.set(f,T),T+=a,G}function di(s){return!s||s.byteLength<12?!1:new DataView(s).getUint32(0,!0)===ui}function fi(s){const t=new DataView(s);if(t.getUint32(0,!0)!==ui)throw new Error("[unpackHZFX] bad magic — not an .hzfx file");const e=t.getUint32(4,!0);if(e!==vs)throw new Error(`[unpackHZFX] unsupported version ${e}`);let i=12,r=null,n=-1;const a=new Uint8Array(s);for(;i+8<=s.byteLength;){const b=t.getUint32(i,!0);i+=4;const f=t.getUint32(i,!0);i+=4,f===Ps?r=JSON.parse(new TextDecoder().decode(a.subarray(i,i+b))):f===_s&&(n=i),i+=b}if(!r)throw new Error("[unpackHZFX] missing JSON chunk");const o=r.assets||[],l=b=>{const f=o[b];return!f||n<0?null:{...f,bytes:a.subarray(n+f.offset,n+f.offset+f.length)}},c=b=>b&&typeof b=="object"&&typeof b[At]=="number",d=(r.systems||[]).map(b=>{const f={...b};if(c(f.textureImageData)){const v=l(f.textureImageData[At]);f.textureImageData=v?`data:${v.mime};base64,${Wi(v.bytes)}`:void 0}if(c(f.glbModelData)){const v=l(f.glbModelData[At]);f.glbModelData=v?Wi(v.bytes):void 0}return f}),S={...r,systems:d};return delete S.assets,S}function qr(s){const t=new Uint8Array(s);let e="";for(let i=0;i<t.byteLength;i++)e+=String.fromCharCode(t[i]);return btoa(e)}function Bs(s){return{name:s.name,id:s.id,particleCount:s.particleCount,lifetime:s.lifetime,emissionRate:s.emissionRate,emissionDuration:s.emissionDuration,emissionDurationInfinite:s.emissionDurationInfinite||!1,startAt:s.startAt||0,keyframes:s.keyframes||null,keyframesEnabled:s.keyframesEnabled!==!1,particleSize:s.particleSize,particleSpeed:s.particleSpeed,emissionShape:s.emissionShape,outerLength:s.outerLength??s.cubeLength,innerLength:s.innerLength,outerRadius:s.outerRadius,innerRadius:s.innerRadius,squareSize:s.squareSize,squareInnerSize:s.squareInnerSize,circleInnerRadius:s.circleInnerRadius,circleOuterRadius:s.circleOuterRadius,fadeEnabled:s.fadeEnabled,colorTransitionEnabled:s.colorTransitionEnabled,particleColor:s.particleColor,startColor:s.startColor,endColor:s.endColor,randomColorEnabled:s.randomColorEnabled||!1,randomColors:s.randomColors||[],particleShape:s.particleShape||"square",particleShapeRotationX:s.particleShapeRotationX||0,particleShapeRotationY:s.particleShapeRotationY||0,particleShapeRotationZ:s.particleShapeRotationZ||0,pulseEnabled:s.pulseEnabled||!1,pulseAmplitude:s.pulseAmplitude??.5,pulseFrequency:s.pulseFrequency??1,pulsePhaseRandom:s.pulsePhaseRandom??0,pulseOpacity:s.pulseOpacity||!1,bloomEnabled:s.bloomEnabled,bloomIntensity:s.bloomIntensity,bloomColor:s.bloomColor,depthWriteEnabled:s.depthWriteEnabled||!1,burstMode:s.burstMode,gravityEnabled:s.gravityEnabled,gravityStrength:s.gravityStrength,dampingEnabled:s.dampingEnabled,dampingStrength:s.dampingStrength,attractorEnabled:s.attractorEnabled,attractorStrength:s.attractorStrength,attractorReverse:s.attractorReverse??!1,attractorPosition:s.attractorPosition,emissionRotationX:s.emissionRotationX,emissionRotationY:s.emissionRotationY,emissionRotationZ:s.emissionRotationZ,orientToDirection:s.orientToDirection??!1,emissionPositionX:s.emissionPositionX,emissionPositionY:s.emissionPositionY,emissionPositionZ:s.emissionPositionZ,rotation:s.rotation,rotationMode:s.rotationMode,minRotation:s.minRotation,maxRotation:s.maxRotation,orientX:s.orientX,orientY:s.orientY,orientZ:s.orientZ,overrideXVelocity:s.overrideXVelocity,overrideYVelocity:s.overrideYVelocity,overrideZVelocity:s.overrideZVelocity,xVelocity:s.xVelocity,yVelocity:s.yVelocity,zVelocity:s.zVelocity,circleVelocityDirection:s.circleVelocityDirection,cylinderVelocityDirection:s.cylinderVelocityDirection,cylinderInnerRadius:s.cylinderInnerRadius,cylinderOuterRadius:s.cylinderOuterRadius,cylinderHeight:s.cylinderHeight,planeWidth:s.planeWidth,planeDepth:s.planeDepth,rectangleWidth:s.rectangleWidth,rectangleHeight:s.rectangleHeight,coneOuterRadius:s.coneOuterRadius,coneInnerRadius:s.coneInnerRadius,coneHeight:s.coneHeight,torusMajorRadius:s.torusMajorRadius,torusMinorRadius:s.torusMinorRadius,lineLength:s.lineLength,hemisphereOuterRadius:s.hemisphereOuterRadius,hemisphereInnerRadius:s.hemisphereInnerRadius,discRadius:s.discRadius,annulusInnerRadius:s.annulusInnerRadius,annulusOuterRadius:s.annulusOuterRadius,capsuleRadius:s.capsuleRadius,capsuleHeight:s.capsuleHeight,arcStartAngle:s.arcStartAngle,arcEndAngle:s.arcEndAngle,arcInnerRadius:s.arcInnerRadius,arcOuterRadius:s.arcOuterRadius,spiralTurns:s.spiralTurns,spiralRadiusStart:s.spiralRadiusStart,spiralRadiusEnd:s.spiralRadiusEnd,spiralHeight:s.spiralHeight,frustumRadiusNear:s.frustumRadiusNear,frustumRadiusFar:s.frustumRadiusFar,frustumHeight:s.frustumHeight,cubeSurfaceSize:s.cubeSurfaceSize,sphereSurfaceRadius:s.sphereSurfaceRadius,boxFrameSize:s.boxFrameSize,polygonSides:s.polygonSides,polygonRadius:s.polygonRadius,aspectRatio:s.aspectRatio,randomSize:s.randomSize,minSize:s.minSize,maxSize:s.maxSize,fadeSizeEnabled:s.fadeSizeEnabled,increaseSizeEnabled:s.increaseSizeEnabled,sizeLifetimeSpeed:s.sizeLifetimeSpeed,opacity:s.opacity,randomSpeed:s.randomSpeed,minSpeed:s.minSpeed,maxSpeed:s.maxSpeed,oneOnlyMode:s.oneOnlyMode,confinementEnabled:s.confinementEnabled||!1,confinementShape:s.confinementShape||"box",confinementMode:s.confinementMode||"bounce",confinementSpace:s.confinementSpace||"world",confinementBoxHalfSize:s.confinementBoxHalfSize||[2,2,2],confinementSphereRadius:s.confinementSphereRadius??3,confinementRestitution:s.confinementRestitution??.8,confinementFriction:s.confinementFriction??.1,confinementCenter:s.confinementCenter,softBoundaryEnabled:s.softBoundaryEnabled||!1,softBoundaryStrength:s.softBoundaryStrength??5,softBoundaryFalloff:s.softBoundaryFalloff??.5,followSystemId:s.followSystemId||null,followSystemTranslation:s.followSystemTranslation??!0,hidden:s.hidden||!1,emissionTrailEnabled:s.emissionTrailEnabled||!1,emissionTrailDuration:s.emissionTrailDuration??1,emissionTrailWidth:s.emissionTrailWidth??.5,emissionTrailMinDistance:s.emissionTrailMinDistance??.05,emissionTrailMaxPoints:s.emissionTrailMaxPoints??100,emissionTrailSegments:s.emissionTrailSegments??8,emissionTrailMode:s.emissionTrailMode??"ribbon",emissionTrailShape:s.emissionTrailShape??"straight",emissionTrailShapeAmplitude:s.emissionTrailShapeAmplitude??.1,emissionTrailShapeFrequency:s.emissionTrailShapeFrequency??4,emissionTrailShapeSpeed:s.emissionTrailShapeSpeed??0,shapeStrokeEnabled:s.shapeStrokeEnabled||!1,shapeStrokeWidth:s.shapeStrokeWidth??.08,shapeStrokeSegments:s.shapeStrokeSegments??96,shapeStrokeShape:s.shapeStrokeShape??"straight",shapeStrokeAmplitude:s.shapeStrokeAmplitude??.08,shapeStrokeFrequency:s.shapeStrokeFrequency??10,shapeStrokeSpeed:s.shapeStrokeSpeed??0,shapeDisplay:s.shapeDisplay??!0,blendMode:s.blendMode??"normal",noiseDistortEnabled:s.noiseDistortEnabled||!1,noiseTilingX:s.noiseTilingX??3,noiseTilingY:s.noiseTilingY??3,noiseSpeed:s.noiseSpeed??-1.5,noiseAmplitude:s.noiseAmplitude??.08,velocityStretchEnabled:s.velocityStretchEnabled||!1,velocityStretchFactor:s.velocityStretchFactor??1,textureEnabled:s.textureEnabled||!1,textureType:s.textureType,textureFileName:s.textureFileName,imageDescription:s.imageDescription,glbModelEnabled:s.glbModelEnabled||!1,glbFileName:s.glbFileName,glbHasTexture:s.glbHasTexture||!1,useGlbTexture:s.useGlbTexture||!1,glbAnimated:s.glbAnimated||!1,animationIndex:s.animationIndex,animationSpeed:s.animationSpeed,animationLoop:s.animationLoop,glbDescription:s.glbDescription,script:s.script||void 0,displayUnit:s.displayUnit||"m"}}async function Hr(s,t,e="hzfx"){if(!s||!s.particleSystems||s.particleSystems.length===0){alert("No particle systems to save.");return}try{const i={version:"1.0",timestamp:new Date().toISOString(),systems:s.particleSystems.map(({config:d,system:S})=>({...Bs(d),textureImageData:d.textureEnabled&&!d.glbModelEnabled&&d.textureImageData?d.textureImageData:void 0,glbModelData:d.glbModelEnabled&&S.glbRawArrayBuffer?qr(S.glbRawArrayBuffer):void 0})),activeSystemIndex:s.activeSystemIndex,loop:s.loop||!1},r=e==="json"?"json":"hzfx";let n;if(r==="hzfx"){const d=await ws(i,{textureFormat:"webp"});n=new Blob([d],{type:"application/octet-stream"})}else n=new Blob([JSON.stringify(i,null,2)],{type:"application/json"});let a;if(t)a=t;else{const d=new Date;a=`particle-scene_${`${d.getFullYear()}-${(d.getMonth()+1).toString().padStart(2,"0")}-${d.getDate().toString().padStart(2,"0")}_${d.getHours().toString().padStart(2,"0")}${d.getMinutes().toString().padStart(2,"0")}`}`}const o=`${a}.${r}`,l=URL.createObjectURL(n),c=document.createElement("a");c.href=l,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(l)}catch(i){console.error("Error saving scene:",i),alert("Error saving scene. See console for details.")}}function Zr(s){return new Promise((t,e)=>{try{const i=s.target.files[0];if(!i){e(new Error("No file selected"));return}const r=new FileReader;r.onload=n=>{try{const a=n.target.result;let o;if(di(a)?o=fi(a):o=JSON.parse(new TextDecoder().decode(a)),!Array.isArray(o.systems)||o.systems.length===0)throw new Error("No valid particle systems found in the file");t({systems:o.systems.slice(),activeSystemIndex:o.activeSystemIndex||0})}catch(a){console.error("Error loading scene:",a),alert("Error loading scene: "+a.message),e(a)}s.target.value=""},r.onerror=()=>{alert("Failed to read the file"),e(new Error("Failed to read the file")),s.target.value=""},r.readAsArrayBuffer(i)}catch(i){console.error("Error in loadScene:",i),e(i)}})}async function Wr(s){if(!s||typeof s!="string")throw new Error("[fetchPreset] url must be a non-empty string");const t=await fetch(s);if(!t.ok)throw new Error(`[fetchPreset] HTTP ${t.status}: ${t.statusText}`);const e=await t.arrayBuffer();let i;if(di(e)?i=fi(e):i=JSON.parse(new TextDecoder().decode(e)),!Array.isArray(i.systems)||i.systems.length===0)throw new Error('[fetchPreset] Invalid preset: "systems" must be a non-empty array');return{version:i.version,systems:i.systems,activeSystemIndex:i.activeSystemIndex??0}}const $r=s=>`
|
|
1196
1196
|
@vertex fn vs(@builtin(vertex_index) i: u32) -> @builtin(position) vec4f {
|
|
1197
1197
|
var p = array<vec2f, 3>(vec2f(-1.0, -3.0), vec2f(-1.0, 1.0), vec2f(3.0, 1.0));
|
|
1198
1198
|
return vec4f(p[i], 0.0, 1.0);
|
|
@@ -1201,7 +1201,7 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
|
|
|
1201
1201
|
@fragment fn fs(@builtin(position) pos: vec4f) -> @builtin(frag_depth) f32 {
|
|
1202
1202
|
return textureLoad(src, vec2i(pos.xy), 0);
|
|
1203
1203
|
}
|
|
1204
|
-
`;async function Jr(s,t={}){const{getSceneDepth:e=null,autoRespawn:i=!0}=t;let r,n,a;const o=!!(s&&s.device&&s.context);o?({device:r,context:n,canvas:a}=s,a||(a=n.canvas)):(a=s,{device:r,context:n}=await ds(a));const l=navigator.gpu.getPreferredCanvasFormat(),c=t.manager||new us(r),d={layouts:{},pipelines:{}};function S(u){const p=u?"ms":"ss";if(!d.pipelines[p]){const y=r.createShaderModule({code:$r(u)}),h=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"depth",multisampled:u}}]});d.layouts[p]=h,d.pipelines[p]=r.createRenderPipeline({layout:r.createPipelineLayout({bindGroupLayouts:[h]}),vertex:{module:y,entryPoint:"vs"},fragment:{module:y,entryPoint:"fs",targets:[]},primitive:{topology:"triangle-list"},depthStencil:{format:"depth24plus",depthWriteEnabled:!0,depthCompare:"always"}})}return{pipeline:d.pipelines[p],layout:d.layouts[p]}}const b={bloomSourceTextures:{},bloomCompositeTextures:{},combinedTexture:null,getBloomSourceTexture(u,p,y){const h=u;return this.bloomSourceTextures[h]||(this.bloomSourceTextures[h]=r.createTexture({size:[p,y],format:"rgba16float",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING})),this.bloomSourceTextures[h]},getBloomCompositeTexture(u,p,y){const h=u;return this.bloomCompositeTextures[h]||(this.bloomCompositeTextures[h]=r.createTexture({size:[p,y],format:"rgba16float",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING})),this.bloomCompositeTextures[h]},getCombinedTexture(u,p){return this.combinedTexture||(this.combinedTexture=r.createTexture({size:[u,p],format:"rgba16float",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING})),this.combinedTexture},resizeTextures(){Object.values(this.bloomSourceTextures).forEach(u=>u==null?void 0:u.destroy()),Object.values(this.bloomCompositeTextures).forEach(u=>u==null?void 0:u.destroy()),this.combinedTexture&&this.combinedTexture.destroy(),this.bloomSourceTextures={},this.bloomCompositeTextures={},this.combinedTexture=null}},f={systemBindGroups:{},systemBloomHorizontalBindGroups:{},secondHorizontalBindGroups:{},systemBloomCompositeBindGroups:{},combinedBloomCompositeBindGroups:{},combinedInitialBindGroup:null,finalBindGroup:null,textureStates:{},textureRefs:{},clear(){this.systemBindGroups={},this.systemBloomHorizontalBindGroups={},this.secondHorizontalBindGroups={},this.systemBloomCompositeBindGroups={},this.combinedBloomCompositeBindGroups={},this.combinedInitialBindGroup=null,this.finalBindGroup=null,this.textureStates={},this.textureRefs={}}},v=r.createBuffer({size:96,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),C=r.createBuffer({size:208,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),z=r.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),G=r.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),M=r.createBuffer({size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),Z=pt(r,new Uint16Array([0,1,2,0,2,3]),GPUBufferUsage.INDEX),T={},D=()=>pt(r,new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST);c.onSystemCreated=u=>{T[u]||(T[u]=D())};const F=4e4,H=new Float32Array(F*8),se=new Float32Array(F*4),ne=new Float32Array(F*4),re=r.createBuffer({size:F*8*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),q=r.createBuffer({size:F*4*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),tt=r.createBuffer({size:F*4*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),xt=new Map,at=new Map,Nt=8,_e=[];function pi(u){for(const p of _e)if(p.ids.has(u))return p;return null}function Rs(u,p){if(!u.pos)return;u.hist.push({t:p,x:u.pos[0],y:u.pos[1],z:u.pos[2]});const y=p-Nt;for(;u.hist.length>2&&u.hist[0].t<y;)u.hist.shift()}function hi(u,p,y){const h=u.hist;if(h.length===0){const P=u.pos;return P&&(y[0]=P[0],y[1]=P[1],y[2]=P[2]),y}let g;if(p>=h[h.length-1].t)return g=h[h.length-1],y[0]=g.x,y[1]=g.y,y[2]=g.z,y;if(p<=h[0].t)return g=h[0],y[0]=g.x,y[1]=g.y,y[2]=g.z,y;for(let P=h.length-1;P>0;P--)if(h[P-1].t<=p){const _=h[P-1],B=h[P],x=(p-_.t)/Math.max(1e-6,B.t-_.t);return y[0]=_.x+(B.x-_.x)*x,y[1]=_.y+(B.y-_.y)*x,y[2]=_.z+(B.z-_.z)*x,y}return g=h[0],y[0]=g.x,y[1]=g.y,y[2]=g.z,y}const ht=Math.PI*2,ae=new Array(257),oe=new Array(257),le=new Array(257),Yt=new Array(257),jt=new Array(257),qt=new Array(257);new Array(257),new Array(257),new Array(257);const Ae=[0,0,0];function Ts(u){const p=u.emissionRotationX||0,y=u.emissionRotationY||0,h=u.emissionRotationZ||0;if(!p&&!y&&!h)return null;const g=p*Math.PI/180,P=y*Math.PI/180,_=h*Math.PI/180,B=Math.cos(g),x=Math.sin(g),R=Math.cos(P),m=Math.sin(P),w=Math.cos(_),E=Math.sin(_);return[R*w,x*m*w-B*E,B*m*w+x*E,R*E,x*m*E+B*w,B*m*E-x*w,-m,x*R,B*R]}function Ut(u,p,y,h,g){return g[0]=u[0]*p+u[1]*y+u[2]*h,g[1]=u[3]*p+u[4]*y+u[5]*h,g[2]=u[6]*p+u[7]*y+u[8]*h,g}function Es(u,p,y,h,g,P,_){let B=u,x=p,R=y;h&&(Ut(h,B,x,R,_),B=_[0],x=_[1],R=_[2]),B+=P.emissionPositionX||0,x+=P.emissionPositionY||0,R+=P.emissionPositionZ||0,g._simRotMatrix&&(Ut(g._simRotMatrix,B,x,R,_),B=_[0],x=_[1],R=_[2]);const m=g._simPosition;return _[0]=B+(m?m[0]:0),_[1]=x+(m?m[1]:0),_[2]=R+(m?m[2]:0),_}function As(u,p,y,h,g,P){let _=u,B=p,x=y;return h&&(Ut(h,_,B,x,P),_=P[0],B=P[1],x=P[2]),g._simRotMatrix&&(Ut(g._simRotMatrix,_,B,x,P),_=P[0],B=P[1],x=P[2]),P[0]=_,P[1]=B,P[2]=x,P}function Ht(u,p,y,h,g){const P=p*2,_=y*2,B=2*(P+_);let x=(u%1+1)%1*B,R=0,m=0;return x<P?(R=-p+x,m=y):(x-=P)<_?(R=p,m=y-x):(x-=_)<P?(R=p-x,m=-y):(x-=P,R=-p,m=-y+x),h==="xz"?(g[0]=R,g[1]=0,g[2]=m):(g[0]=R,g[1]=m,g[2]=0),g}function Cs(u){const p=u.emissionShape,y=Math.max(1,Math.min(256,Math.floor(u.shapeStrokeSegments??96)));let h=0,g=!1,P=[0,0,1];const _=Ae;if(p==="circle"){g=!0,h=Math.max(3,y),P=[0,0,1];const B=u.circleOuterRadius??2;for(let x=0;x<h;x++){const R=x/h*ht;ae[x]=Math.cos(R)*B,oe[x]=Math.sin(R)*B,le[x]=0}}else if(p==="disc"){g=!0,h=Math.max(3,y),P=[0,1,0];const B=u.discRadius??2;for(let x=0;x<h;x++){const R=x/h*ht;ae[x]=Math.cos(R)*B,oe[x]=0,le[x]=Math.sin(R)*B}}else if(p==="annulus"){g=!0,h=Math.max(3,y),P=[0,1,0];const B=u.annulusInnerRadius??1,x=u.annulusOuterRadius??2,R=B+(x-B)*.5;for(let m=0;m<h;m++){const w=m/h*ht;ae[m]=Math.cos(w)*R,oe[m]=0,le[m]=Math.sin(w)*R}}else if(p==="arc"){g=!1,h=Math.max(2,y+1),P=[0,0,1];const B=u.arcInnerRadius??0,x=u.arcOuterRadius??2,R=B>0?B+(x-B)*.5:x,m=(u.arcStartAngle??0)*Math.PI/180,w=(u.arcEndAngle??180)*Math.PI/180;for(let E=0;E<h;E++){const N=h>1?E/(h-1):0,X=m+(w-m)*N;ae[E]=Math.cos(X)*R,oe[E]=Math.sin(X)*R,le[E]=0}}else if(p==="square"){g=!0,h=Math.max(4,y),P=[0,0,1];const B=u.squareSize??2;for(let x=0;x<h;x++)Ht(x/h,B,B,"xy",_),ae[x]=_[0],oe[x]=_[1],le[x]=_[2]}else if(p==="rectangle"){g=!0,h=Math.max(4,y),P=[0,0,1];const B=(u.rectangleWidth??2)*.5,x=(u.rectangleHeight??2)*.5;for(let R=0;R<h;R++)Ht(R/h,B,x,"xy",_),ae[R]=_[0],oe[R]=_[1],le[R]=_[2]}else if(p==="plain"){g=!0,h=Math.max(4,y),P=[0,1,0];const B=(u.planeWidth??2)*.5,x=(u.planeDepth??2)*.5;for(let R=0;R<h;R++)Ht(R/h,B,x,"xz",_),ae[R]=_[0],oe[R]=_[1],le[R]=_[2]}else if(p==="line"){g=!1,h=Math.max(2,y+1),P=[0,0,1];const B=u.lineLength??4;for(let x=0;x<h;x++){const R=h>1?x/(h-1):0;ae[x]=0,oe[x]=(R-.5)*B,le[x]=0}}else if(p==="polygon"){g=!0,h=Math.max(3,y),P=[0,0,1];const B=Math.max(3,Math.floor(u.polygonSides??6)),x=u.polygonRadius??2;for(let R=0;R<h;R++){const m=R/h*B,w=Math.floor(m),E=m-w,N=w/B*ht,X=(w+1)/B*ht,O=Math.cos(N)*x,U=Math.sin(N)*x,ye=Math.cos(X)*x,xe=Math.sin(X)*x;ae[R]=O+(ye-O)*E,oe[R]=U+(xe-U)*E,le[R]=0}}else h=0;return{count:h,closed:g,planeNormal:P}}function Us(u,p,y){if(!y.shapeStrokeEnabled||y.hidden)return u;const{count:h,closed:g,planeNormal:P}=Cs(y);if(h<2)return u;const _=Ts(y),B=Math.max(1e-4,y.shapeStrokeWidth??.08),x=Math.max(0,y.opacity??1);if(x<=0)return u;As(P[0],P[1],P[2],_,p,Ae);let R=Math.hypot(Ae[0],Ae[1],Ae[2])||1;const m=Ae[0]/R,w=Ae[1]/R,E=Ae[2]/R;for(let I=0;I<h;I++)Es(ae[I],oe[I],le[I],_,p,y,Ae),ae[I]=Ae[0],oe[I]=Ae[1],le[I]=Ae[2];const N=y.shapeStrokeShape??"straight";if(N!=="straight"){const I=y.shapeStrokeAmplitude??.08,K=y.shapeStrokeFrequency??10,Ie=y.shapeStrokeSpeed??0;for(let W=0;W<h;W++){const pe=W===0?g?h-1:0:W-1,ee=W===h-1?g?0:h-1:W+1,ge=ae[ee]-ae[pe],$=oe[ee]-oe[pe],Q=le[ee]-le[pe],J=w*Q-E*$,te=E*ge-m*Q,ce=m*$-w*ge,be=Math.hypot(J,te,ce)||1,ve=J/be,ue=te/be,He=ce/be,Me=g?W/h:W/Math.max(1,h-1),Se=ht*K*Me+Ie*Ve;let he=0,me=0;N==="zigzag"?he=I*Math.sign(Math.sin(Se)||1):N==="sine"?he=I*Math.sin(Se):N==="spiral"&&(he=I*Math.sin(Se),me=I*Math.cos(Se)),ae[W]+=ve*he+m*me,oe[W]+=ue*he+w*me,le[W]+=He*he+E*me}}const X=g?h:h-1,O=y.bloomIntensity||1,U=y.startColor??y.particleColor??[1,1,1],ye=y.endColor??U,xe=y.particleColor??U,Oe=y.randomColorEnabled&&Array.isArray(y.randomColors)&&y.randomColors.length>0?y.randomColors[0]:null,fe=B*.5,_t=Math.max(B*4,1e-4),je=(y.shapeStrokeSpeed??0)*Ve;let it=0;for(let I=0;I<X;I++){const K=g?(I+1)%h:I+1;it+=Math.hypot(ae[K]-ae[I],oe[K]-oe[I],le[K]-le[I])}const ti=g?Math.max(1,Math.round(it/_t)):Math.max(it/_t,1e-6),Mt=it>1e-6?ti/it:0;let qe=0,wt=!1,ut=0,Ue=0,dt=0;for(let I=0;I<h;I++){const K=I===0?g?h-1:0:I-1,Ie=I===h-1?g?0:h-1:I+1;let W=ae[Ie]-ae[K],pe=oe[Ie]-oe[K],ee=le[Ie]-le[K];const ge=Math.hypot(W,pe,ee)||1;W/=ge,pe/=ge,ee/=ge;let $=w*ee-E*pe,Q=E*W-m*ee,J=m*pe-w*W,te=Math.hypot($,Q,J);if(te<1e-5){const ce=V.right[0],be=V.right[1],ve=V.right[2],ue=ce*W+be*pe+ve*ee;$=ce-ue*W,Q=be-ue*pe,J=ve-ue*ee,te=Math.hypot($,Q,J)}if(te<1e-5){const ce=V.up[0],be=V.up[1],ve=V.up[2],ue=ce*W+be*pe+ve*ee;$=ce-ue*W,Q=be-ue*pe,J=ve-ue*ee,te=Math.hypot($,Q,J)||1}$/=te,Q/=te,J/=te,wt&&ut*$+Ue*Q+dt*J<0&&($=-$,Q=-Q,J=-J),Yt[I]=$,jt[I]=Q,qt[I]=J,ut=$,Ue=Q,dt=J,wt=!0}for(let I=0;I<X&&!(u+54>Ce.length);I++){const K=g?(I+1)%h:I+1,Ie=ae[I],W=oe[I],pe=le[I],ee=ae[K],ge=oe[K],$=le[K];let Q=ee-Ie,J=ge-W,te=$-pe;const ce=Math.hypot(Q,J,te)||1;Q/=ce,J/=ce,te/=ce;const be=g?I/h:I/Math.max(1,h-1),ve=g?K/h:K/Math.max(1,h-1),ue=qe*Mt+je,He=(qe+ce)*Mt+je;let Me,Se,he,me,we,Be;Oe?(Me=me=Oe[0],Se=we=Oe[1],he=Be=Oe[2]):y.colorTransitionEnabled?(Me=U[0]+(ye[0]-U[0])*be,Se=U[1]+(ye[1]-U[1])*be,he=U[2]+(ye[2]-U[2])*be,me=U[0]+(ye[0]-U[0])*ve,we=U[1]+(ye[1]-U[1])*ve,Be=U[2]+(ye[2]-U[2])*ve):(Me=me=xe[0],Se=we=xe[1],he=Be=xe[2]),Me=Math.min(1,Me*O),Se=Math.min(1,Se*O),he=Math.min(1,he*O),me=Math.min(1,me*O),we=Math.min(1,we*O),Be=Math.min(1,Be*O);const Bt=Yt[I],bt=jt[I],Le=qt[I],ke=Yt[K],ze=jt[K],Rt=qt[K],Ot=Ie+Bt*fe,Lt=W+bt*fe,Tt=pe+Le*fe,Re=Ie-Bt*fe,Te=W-bt*fe,Ee=pe-Le*fe,st=ee+ke*fe,rt=ge+ze*fe,Et=$+Rt*fe,Ze=ee-ke*fe,We=ge-ze*fe,$e=$-Rt*fe,ft=(A,k,de,Y,L,j,ie,Je,Ke)=>{Ce[u++]=A,Ce[u++]=k,Ce[u++]=de,Ce[u++]=Y,Ce[u++]=L,Ce[u++]=j,Ce[u++]=ie,Ce[u++]=Je,Ce[u++]=Ke};ft(Ot,Lt,Tt,Me,Se,he,x,ue,0),ft(Re,Te,Ee,Me,Se,he,x,ue,1),ft(st,rt,Et,me,we,Be,x,He,0),ft(Re,Te,Ee,Me,Se,he,x,ue,1),ft(Ze,We,$e,me,we,Be,x,He,1),ft(st,rt,Et,me,we,Be,x,He,0),qe+=ce}return u}const Is=.41421356;function zs(){xt.clear(),at.clear();let u=0,p=0,y=0;V.position[0],V.position[1],V.position[2];for(const{system:h,config:g}of c.particleSystems){if(g.hidden)continue;if(g.emissionTrailEnabled&&!g.glbModelEnabled){h.readbackAndProcessParticles();const _=h.particleData,B=h.particleVelocities,x=h.activeParticles;if(_&&B&&x>0){const R=g.emissionTrailMode==="particles",m=u,w=g.emissionTrailDuration??1,E=g.opacity??1,N=g.particleSize??.5,X=g.bloomIntensity||1,O=Math.max(1,Math.min(64,g.emissionTrailSegments??8)),U=g.emissionTrailShape||"straight",ye=g.followSystemTranslation??!0,xe=h._simPosition,Oe=ye&&xe?xe[0]:0,fe=ye&&xe?xe[1]:0,_t=ye&&xe?xe[2]:0,je=h._simVelocity,it=je?je[0]:0,ti=je?je[1]:0,Mt=je?je[2]:0,qe=pi(g.id),wt=!!(ye&&qe&&qe.hist&&qe.hist.length>1);for(let ut=0;ut<x;ut++){const Ue=ut*8,dt=_[Ue],I=_[Ue+1],K=_[Ue+2],Ie=dt+Oe,W=I+fe,pe=K+_t;let ee=_[Ue+3],ge=_[Ue+4],$=_[Ue+5];const Q=_[Ue+6],J=_[Ue+7];if(Q>=J||J<=0)continue;const te=Q/J;if(g.colorTransitionEnabled){const A=g.startColor??[1,0,0],k=g.endColor??[0,0,1];ee=A[0]+(k[0]-A[0])*te,ge=A[1]+(k[1]-A[1])*te,$=A[2]+(k[2]-A[2])*te}ee=Math.min(1,ee*X),ge=Math.min(1,ge*X),$=Math.min(1,$*X);let ce=N;if(g.randomSize){const A=Math.sin(J*54321.67)*43758.5453%1,k=A<0?A+1:A;ce=(g.minSize??.1)+((g.maxSize??.5)-(g.minSize??.1))*k}if(g.fadeSizeEnabled){const A=Math.max(.01,Math.min(10,g.sizeLifetimeSpeed??1));ce*=1-Math.pow(te,1/A)}if(g.increaseSizeEnabled){const A=Math.max(.01,Math.min(10,g.sizeLifetimeSpeed??1));ce*=1+Math.pow(te,1/A)}if(ce<=0||te>.9)continue;const be=Math.min((.9-te)*(1/.2),1),ve=.75*ce*Is*be;let ue=E;if(g.fadeEnabled&&(ue*=Math.max(0,1-te)),ue*=be,ue<.01)continue;const He=ut*4,Me=B[He],Se=B[He+1],he=B[He+2],me=Me+it,we=Se+ti,Be=he+Mt,Bt=Math.sqrt(me*me+we*we+Be*Be);if(Bt<.001)continue;const bt=1/Bt,Le=me*bt,ke=we*bt,ze=Be*bt,Rt=V.right[0],Ot=V.right[1],Lt=V.right[2];let Tt=Rt*Le+Ot*ke+Lt*ze,Re=Rt-Tt*Le,Te=Ot-Tt*ke,Ee=Lt-Tt*ze,st=Math.sqrt(Re*Re+Te*Te+Ee*Ee);if(st<.2){const A=V.up[0],k=V.up[1],de=V.up[2],Y=A*Le+k*ke+de*ze;Re=A-Y*Le,Te=k-Y*ke,Ee=de-Y*ze,st=Math.sqrt(Re*Re+Te*Te+Ee*Ee)||1}Re/=st,Te/=st,Ee/=st;const rt=Math.min(w,Q);if(rt<.001)continue;const Et=g.gravityEnabled&&g.gravityStrength||0,Ze=qs,We=Hs,$e=Zs;if(g.orientToDirection&&g.burstMode&&wt){const A=h._emitSimRotY||0,k=Ws,de=$s,Y=Js;for(let L=0;L<=O;L++){const j=hi(qe,Ve-L/O*rt,Ti);k[L]=j[0],de[L]=j[1],Y[L]=j[2]}for(let L=0;L<=O;L++){const j=L>0?L-1:0,ie=L<O?L+1:O;let Je=k[j]-k[ie],Ke=Y[j]-Y[ie];const nt=(Math.hypot(Je,Ke)>1e-5?Math.atan2(Je,Ke):Math.atan2(it,Mt))-A,Ge=Math.cos(nt),De=Math.sin(nt),et=L/O*rt,ii=-.5*Et*et*et;Ze[L]=Ge*dt+De*K+k[L],We[L]=I+ii+de[L],$e[L]=-De*dt+Ge*K+Y[L]}}else for(let A=0;A<=O;A++){const k=A/O*rt,de=-.5*Et*k*k;if(wt){const Y=hi(qe,Ve-k,Ti);Ze[A]=dt-Me*k+Y[0],We[A]=I-Se*k+de+Y[1],$e[A]=K-he*k+Y[2]}else Ze[A]=Ie-me*k,We[A]=W-we*k+de,$e[A]=pe-Be*k}if(U!=="straight"){const A=g.emissionTrailShapeAmplitude??.1,k=g.emissionTrailShapeFrequency??4,de=g.emissionTrailShapeSpeed??0;let Y=-ze,L=0,j=Le,ie=Math.sqrt(Y*Y+j*j);ie<1e-6&&(Y=0,L=ze,j=-ke,ie=Math.sqrt(Y*Y+L*L+j*j)||1),Y/=ie,L/=ie,j/=ie;const Je=ke*j-ze*L,Ke=ze*Y-Le*j,Qe=Le*L-ke*Y;for(let Pe=1;Pe<=O;Pe++){const nt=Pe/O*rt,Ge=2*Math.PI*k*(Ve-nt)+de*Ve;let De=0,et=0;U==="zigzag"?De=A*Math.sign(Math.sin(Ge)):U==="sine"?De=A*Math.sin(Ge):U==="spiral"&&(De=A*Math.sin(Ge),et=A*Math.cos(Ge)),Ze[Pe]+=Y*De+Je*et,We[Pe]+=L*De+Ke*et,$e[Pe]+=j*De+Qe*et}}if(R)for(let A=1;A<=O&&u<F;A++){const k=A/O,de=Ze[A]-Oe,Y=We[A]-fe,L=$e[A]-_t,j=u*8,ie=u*4;H[j]=de,H[j+1]=Y,H[j+2]=L,H[j+3]=ee,H[j+4]=ge,H[j+5]=$,H[j+6]=Q+(J-Q)*k,H[j+7]=J,se[ie]=0,se[ie+1]=0,se[ie+2]=0,se[ie+3]=0,ne[ie]=de,ne[ie+1]=Y,ne[ie+2]=L,ne[ie+3]=0,u++}else for(let A=0;A<O&&!(p+42>Ye.length);A++){const k=A/O,de=(A+1)/O,Y=Ze[A],L=We[A],j=$e[A],ie=Ze[A+1],Je=We[A+1],Ke=$e[A+1],Qe=ve*(1-k),Pe=ve*(1-de),nt=ue*(1-k)*(1-k),Ge=ue*(1-de)*(1-de),De=Y+Re*Qe,et=L+Te*Qe,ii=j+Ee*Qe,Di=Y-Re*Qe,Fi=L-Te*Qe,Vi=j-Ee*Qe,Oi=ie+Re*Pe,Li=Je+Te*Pe,ki=Ke+Ee*Pe,lr=ie-Re*Pe,cr=Je-Te*Pe,ur=Ke-Ee*Pe,St=(dr,fr,pr,hr)=>{Ye[p++]=dr,Ye[p++]=fr,Ye[p++]=pr,Ye[p++]=ee,Ye[p++]=ge,Ye[p++]=$,Ye[p++]=hr};St(De,et,ii,nt),St(Di,Fi,Vi,nt),St(Oi,Li,ki,Ge),St(Di,Fi,Vi,nt),St(lr,cr,ur,Ge),St(Oi,Li,ki,Ge)}}R&&u>m&&xt.set(g.id,{first:m,count:u-m})}}const P=y;y=Us(y,h,g),y>P&&at.set(g.id,{first:P/9,count:(y-P)/9})}u>0&&(r.queue.writeBuffer(re,0,H,0,u*8),r.queue.writeBuffer(q,0,se,0,u*4),r.queue.writeBuffer(tt,0,ne,0,u*4)),vt=p/7,vt>0&&r.queue.writeBuffer(Zt,0,Ye,0,p),Mi=y/9,Mi>0&&r.queue.writeBuffer(Wt,0,Ce,0,y)}const mi=()=>{const[u,p]=fs(a.width,a.height);r.queue.writeBuffer(z,0,new Float32Array([1,0,u,p,0,0,0,0])),r.queue.writeBuffer(G,0,new Float32Array([0,1,u,p,0,0,0,0]))};mi();const yi=new Float32Array(16).fill(0);yi[0]=1,r.queue.writeBuffer(M,0,yi);const Fe=gs(r),Ne=ms(r),{particlePipeline:Gs,particleAdditivePipeline:Ds,particleDepthWritePipeline:Fs,blurPipeline:It,compositePipeline:Vs,directRenderPipeline:gi,finalCompositePipeline:Os,glbMeshPipeline:Ls}=ys(r,l,Ne),bi=r.createShaderModule({code:`
|
|
1204
|
+
`;async function Jr(s,t={}){const{getSceneDepth:e=null,autoRespawn:i=!0}=t;let r,n,a;const o=!!(s&&s.device&&s.context);o?({device:r,context:n,canvas:a}=s,a||(a=n.canvas)):(a=s,{device:r,context:n}=await ds(a));const l=navigator.gpu.getPreferredCanvasFormat(),c=t.manager||new us(r),d={layouts:{},pipelines:{}};function S(u){const p=u?"ms":"ss";if(!d.pipelines[p]){const y=r.createShaderModule({code:$r(u)}),h=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"depth",multisampled:u}}]});d.layouts[p]=h,d.pipelines[p]=r.createRenderPipeline({layout:r.createPipelineLayout({bindGroupLayouts:[h]}),vertex:{module:y,entryPoint:"vs"},fragment:{module:y,entryPoint:"fs",targets:[]},primitive:{topology:"triangle-list"},depthStencil:{format:"depth24plus",depthWriteEnabled:!0,depthCompare:"always"}})}return{pipeline:d.pipelines[p],layout:d.layouts[p]}}const b={bloomSourceTextures:{},bloomCompositeTextures:{},combinedTexture:null,getBloomSourceTexture(u,p,y){const h=u;return this.bloomSourceTextures[h]||(this.bloomSourceTextures[h]=r.createTexture({size:[p,y],format:"rgba16float",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING})),this.bloomSourceTextures[h]},getBloomCompositeTexture(u,p,y){const h=u;return this.bloomCompositeTextures[h]||(this.bloomCompositeTextures[h]=r.createTexture({size:[p,y],format:"rgba16float",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING})),this.bloomCompositeTextures[h]},getCombinedTexture(u,p){return this.combinedTexture||(this.combinedTexture=r.createTexture({size:[u,p],format:"rgba16float",usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING})),this.combinedTexture},resizeTextures(){Object.values(this.bloomSourceTextures).forEach(u=>u==null?void 0:u.destroy()),Object.values(this.bloomCompositeTextures).forEach(u=>u==null?void 0:u.destroy()),this.combinedTexture&&this.combinedTexture.destroy(),this.bloomSourceTextures={},this.bloomCompositeTextures={},this.combinedTexture=null}},f={systemBindGroups:{},systemBloomHorizontalBindGroups:{},secondHorizontalBindGroups:{},systemBloomCompositeBindGroups:{},combinedBloomCompositeBindGroups:{},combinedInitialBindGroup:null,finalBindGroup:null,textureStates:{},textureRefs:{},clear(){this.systemBindGroups={},this.systemBloomHorizontalBindGroups={},this.secondHorizontalBindGroups={},this.systemBloomCompositeBindGroups={},this.combinedBloomCompositeBindGroups={},this.combinedInitialBindGroup=null,this.finalBindGroup=null,this.textureStates={},this.textureRefs={}}},v=r.createBuffer({size:96,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),U=r.createBuffer({size:208,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),z=r.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),G=r.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),M=r.createBuffer({size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),Z=pt(r,new Uint16Array([0,1,2,0,2,3]),GPUBufferUsage.INDEX),T={},D=()=>pt(r,new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST);c.onSystemCreated=u=>{T[u]||(T[u]=D())};const F=4e4,H=new Float32Array(F*8),se=new Float32Array(F*4),ne=new Float32Array(F*4),re=r.createBuffer({size:F*8*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),q=r.createBuffer({size:F*4*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),tt=r.createBuffer({size:F*4*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),xt=new Map,at=new Map,Nt=8,_e=[];function pi(u){for(const p of _e)if(p.ids.has(u))return p;return null}function Rs(u,p){if(!u.pos)return;u.hist.push({t:p,x:u.pos[0],y:u.pos[1],z:u.pos[2]});const y=p-Nt;for(;u.hist.length>2&&u.hist[0].t<y;)u.hist.shift()}function hi(u,p,y){const h=u.hist;if(h.length===0){const P=u.pos;return P&&(y[0]=P[0],y[1]=P[1],y[2]=P[2]),y}let g;if(p>=h[h.length-1].t)return g=h[h.length-1],y[0]=g.x,y[1]=g.y,y[2]=g.z,y;if(p<=h[0].t)return g=h[0],y[0]=g.x,y[1]=g.y,y[2]=g.z,y;for(let P=h.length-1;P>0;P--)if(h[P-1].t<=p){const _=h[P-1],B=h[P],x=(p-_.t)/Math.max(1e-6,B.t-_.t);return y[0]=_.x+(B.x-_.x)*x,y[1]=_.y+(B.y-_.y)*x,y[2]=_.z+(B.z-_.z)*x,y}return g=h[0],y[0]=g.x,y[1]=g.y,y[2]=g.z,y}const ht=Math.PI*2,ae=new Array(257),oe=new Array(257),le=new Array(257),Yt=new Array(257),jt=new Array(257),qt=new Array(257);new Array(257),new Array(257),new Array(257);const Ae=[0,0,0];function Ts(u){const p=u.emissionRotationX||0,y=u.emissionRotationY||0,h=u.emissionRotationZ||0;if(!p&&!y&&!h)return null;const g=p*Math.PI/180,P=y*Math.PI/180,_=h*Math.PI/180,B=Math.cos(g),x=Math.sin(g),R=Math.cos(P),m=Math.sin(P),w=Math.cos(_),E=Math.sin(_);return[R*w,x*m*w-B*E,B*m*w+x*E,R*E,x*m*E+B*w,B*m*E-x*w,-m,x*R,B*R]}function Ut(u,p,y,h,g){return g[0]=u[0]*p+u[1]*y+u[2]*h,g[1]=u[3]*p+u[4]*y+u[5]*h,g[2]=u[6]*p+u[7]*y+u[8]*h,g}function Es(u,p,y,h,g,P,_){let B=u,x=p,R=y;h&&(Ut(h,B,x,R,_),B=_[0],x=_[1],R=_[2]),B+=P.emissionPositionX||0,x+=P.emissionPositionY||0,R+=P.emissionPositionZ||0,g._simRotMatrix&&(Ut(g._simRotMatrix,B,x,R,_),B=_[0],x=_[1],R=_[2]);const m=g._simPosition;return _[0]=B+(m?m[0]:0),_[1]=x+(m?m[1]:0),_[2]=R+(m?m[2]:0),_}function As(u,p,y,h,g,P){let _=u,B=p,x=y;return h&&(Ut(h,_,B,x,P),_=P[0],B=P[1],x=P[2]),g._simRotMatrix&&(Ut(g._simRotMatrix,_,B,x,P),_=P[0],B=P[1],x=P[2]),P[0]=_,P[1]=B,P[2]=x,P}function Ht(u,p,y,h,g){const P=p*2,_=y*2,B=2*(P+_);let x=(u%1+1)%1*B,R=0,m=0;return x<P?(R=-p+x,m=y):(x-=P)<_?(R=p,m=y-x):(x-=_)<P?(R=p-x,m=-y):(x-=P,R=-p,m=-y+x),h==="xz"?(g[0]=R,g[1]=0,g[2]=m):(g[0]=R,g[1]=m,g[2]=0),g}function Cs(u){const p=u.emissionShape,y=Math.max(1,Math.min(256,Math.floor(u.shapeStrokeSegments??96)));let h=0,g=!1,P=[0,0,1];const _=Ae;if(p==="circle"){g=!0,h=Math.max(3,y),P=[0,0,1];const B=u.circleOuterRadius??2;for(let x=0;x<h;x++){const R=x/h*ht;ae[x]=Math.cos(R)*B,oe[x]=Math.sin(R)*B,le[x]=0}}else if(p==="disc"){g=!0,h=Math.max(3,y),P=[0,1,0];const B=u.discRadius??2;for(let x=0;x<h;x++){const R=x/h*ht;ae[x]=Math.cos(R)*B,oe[x]=0,le[x]=Math.sin(R)*B}}else if(p==="annulus"){g=!0,h=Math.max(3,y),P=[0,1,0];const B=u.annulusInnerRadius??1,x=u.annulusOuterRadius??2,R=B+(x-B)*.5;for(let m=0;m<h;m++){const w=m/h*ht;ae[m]=Math.cos(w)*R,oe[m]=0,le[m]=Math.sin(w)*R}}else if(p==="arc"){g=!1,h=Math.max(2,y+1),P=[0,0,1];const B=u.arcInnerRadius??0,x=u.arcOuterRadius??2,R=B>0?B+(x-B)*.5:x,m=(u.arcStartAngle??0)*Math.PI/180,w=(u.arcEndAngle??180)*Math.PI/180;for(let E=0;E<h;E++){const N=h>1?E/(h-1):0,X=m+(w-m)*N;ae[E]=Math.cos(X)*R,oe[E]=Math.sin(X)*R,le[E]=0}}else if(p==="square"){g=!0,h=Math.max(4,y),P=[0,0,1];const B=u.squareSize??2;for(let x=0;x<h;x++)Ht(x/h,B,B,"xy",_),ae[x]=_[0],oe[x]=_[1],le[x]=_[2]}else if(p==="rectangle"){g=!0,h=Math.max(4,y),P=[0,0,1];const B=(u.rectangleWidth??2)*.5,x=(u.rectangleHeight??2)*.5;for(let R=0;R<h;R++)Ht(R/h,B,x,"xy",_),ae[R]=_[0],oe[R]=_[1],le[R]=_[2]}else if(p==="plain"){g=!0,h=Math.max(4,y),P=[0,1,0];const B=(u.planeWidth??2)*.5,x=(u.planeDepth??2)*.5;for(let R=0;R<h;R++)Ht(R/h,B,x,"xz",_),ae[R]=_[0],oe[R]=_[1],le[R]=_[2]}else if(p==="line"){g=!1,h=Math.max(2,y+1),P=[0,0,1];const B=u.lineLength??4;for(let x=0;x<h;x++){const R=h>1?x/(h-1):0;ae[x]=0,oe[x]=(R-.5)*B,le[x]=0}}else if(p==="polygon"){g=!0,h=Math.max(3,y),P=[0,0,1];const B=Math.max(3,Math.floor(u.polygonSides??6)),x=u.polygonRadius??2;for(let R=0;R<h;R++){const m=R/h*B,w=Math.floor(m),E=m-w,N=w/B*ht,X=(w+1)/B*ht,O=Math.cos(N)*x,A=Math.sin(N)*x,ye=Math.cos(X)*x,xe=Math.sin(X)*x;ae[R]=O+(ye-O)*E,oe[R]=A+(xe-A)*E,le[R]=0}}else h=0;return{count:h,closed:g,planeNormal:P}}function Us(u,p,y){if(!y.shapeStrokeEnabled||y.hidden)return u;const{count:h,closed:g,planeNormal:P}=Cs(y);if(h<2)return u;const _=Ts(y),B=Math.max(1e-4,y.shapeStrokeWidth??.08),x=Math.max(0,y.opacity??1);if(x<=0)return u;As(P[0],P[1],P[2],_,p,Ae);let R=Math.hypot(Ae[0],Ae[1],Ae[2])||1;const m=Ae[0]/R,w=Ae[1]/R,E=Ae[2]/R;for(let I=0;I<h;I++)Es(ae[I],oe[I],le[I],_,p,y,Ae),ae[I]=Ae[0],oe[I]=Ae[1],le[I]=Ae[2];const N=y.shapeStrokeShape??"straight";if(N!=="straight"){const I=y.shapeStrokeAmplitude??.08,K=y.shapeStrokeFrequency??10,Ie=y.shapeStrokeSpeed??0;for(let W=0;W<h;W++){const pe=W===0?g?h-1:0:W-1,ee=W===h-1?g?0:h-1:W+1,ge=ae[ee]-ae[pe],$=oe[ee]-oe[pe],Q=le[ee]-le[pe],J=w*Q-E*$,te=E*ge-m*Q,ce=m*$-w*ge,be=Math.hypot(J,te,ce)||1,ve=J/be,ue=te/be,He=ce/be,Me=g?W/h:W/Math.max(1,h-1),Se=ht*K*Me+Ie*Ve;let he=0,me=0;N==="zigzag"?he=I*Math.sign(Math.sin(Se)||1):N==="sine"?he=I*Math.sin(Se):N==="spiral"&&(he=I*Math.sin(Se),me=I*Math.cos(Se)),ae[W]+=ve*he+m*me,oe[W]+=ue*he+w*me,le[W]+=He*he+E*me}}const X=g?h:h-1,O=y.bloomIntensity||1,A=y.startColor??y.particleColor??[1,1,1],ye=y.endColor??A,xe=y.particleColor??A,Oe=y.randomColorEnabled&&Array.isArray(y.randomColors)&&y.randomColors.length>0?y.randomColors[0]:null,fe=B*.5,_t=Math.max(B*4,1e-4),je=(y.shapeStrokeSpeed??0)*Ve;let it=0;for(let I=0;I<X;I++){const K=g?(I+1)%h:I+1;it+=Math.hypot(ae[K]-ae[I],oe[K]-oe[I],le[K]-le[I])}const ti=g?Math.max(1,Math.round(it/_t)):Math.max(it/_t,1e-6),Mt=it>1e-6?ti/it:0;let qe=0,wt=!1,ut=0,Ue=0,dt=0;for(let I=0;I<h;I++){const K=I===0?g?h-1:0:I-1,Ie=I===h-1?g?0:h-1:I+1;let W=ae[Ie]-ae[K],pe=oe[Ie]-oe[K],ee=le[Ie]-le[K];const ge=Math.hypot(W,pe,ee)||1;W/=ge,pe/=ge,ee/=ge;let $=w*ee-E*pe,Q=E*W-m*ee,J=m*pe-w*W,te=Math.hypot($,Q,J);if(te<1e-5){const ce=V.right[0],be=V.right[1],ve=V.right[2],ue=ce*W+be*pe+ve*ee;$=ce-ue*W,Q=be-ue*pe,J=ve-ue*ee,te=Math.hypot($,Q,J)}if(te<1e-5){const ce=V.up[0],be=V.up[1],ve=V.up[2],ue=ce*W+be*pe+ve*ee;$=ce-ue*W,Q=be-ue*pe,J=ve-ue*ee,te=Math.hypot($,Q,J)||1}$/=te,Q/=te,J/=te,wt&&ut*$+Ue*Q+dt*J<0&&($=-$,Q=-Q,J=-J),Yt[I]=$,jt[I]=Q,qt[I]=J,ut=$,Ue=Q,dt=J,wt=!0}for(let I=0;I<X&&!(u+54>Ce.length);I++){const K=g?(I+1)%h:I+1,Ie=ae[I],W=oe[I],pe=le[I],ee=ae[K],ge=oe[K],$=le[K];let Q=ee-Ie,J=ge-W,te=$-pe;const ce=Math.hypot(Q,J,te)||1;Q/=ce,J/=ce,te/=ce;const be=g?I/h:I/Math.max(1,h-1),ve=g?K/h:K/Math.max(1,h-1),ue=qe*Mt+je,He=(qe+ce)*Mt+je;let Me,Se,he,me,we,Be;Oe?(Me=me=Oe[0],Se=we=Oe[1],he=Be=Oe[2]):y.colorTransitionEnabled?(Me=A[0]+(ye[0]-A[0])*be,Se=A[1]+(ye[1]-A[1])*be,he=A[2]+(ye[2]-A[2])*be,me=A[0]+(ye[0]-A[0])*ve,we=A[1]+(ye[1]-A[1])*ve,Be=A[2]+(ye[2]-A[2])*ve):(Me=me=xe[0],Se=we=xe[1],he=Be=xe[2]),Me=Math.min(1,Me*O),Se=Math.min(1,Se*O),he=Math.min(1,he*O),me=Math.min(1,me*O),we=Math.min(1,we*O),Be=Math.min(1,Be*O);const Bt=Yt[I],bt=jt[I],Le=qt[I],ke=Yt[K],ze=jt[K],Rt=qt[K],Ot=Ie+Bt*fe,Lt=W+bt*fe,Tt=pe+Le*fe,Re=Ie-Bt*fe,Te=W-bt*fe,Ee=pe-Le*fe,st=ee+ke*fe,rt=ge+ze*fe,Et=$+Rt*fe,Ze=ee-ke*fe,We=ge-ze*fe,$e=$-Rt*fe,ft=(C,k,de,Y,L,j,ie,Je,Ke)=>{Ce[u++]=C,Ce[u++]=k,Ce[u++]=de,Ce[u++]=Y,Ce[u++]=L,Ce[u++]=j,Ce[u++]=ie,Ce[u++]=Je,Ce[u++]=Ke};ft(Ot,Lt,Tt,Me,Se,he,x,ue,0),ft(Re,Te,Ee,Me,Se,he,x,ue,1),ft(st,rt,Et,me,we,Be,x,He,0),ft(Re,Te,Ee,Me,Se,he,x,ue,1),ft(Ze,We,$e,me,we,Be,x,He,1),ft(st,rt,Et,me,we,Be,x,He,0),qe+=ce}return u}const Is=.41421356;function zs(){xt.clear(),at.clear();let u=0,p=0,y=0;V.position[0],V.position[1],V.position[2];for(const{system:h,config:g}of c.particleSystems){if(g.hidden)continue;if(g.emissionTrailEnabled&&!g.glbModelEnabled){h.readbackAndProcessParticles();const _=h.particleData,B=h.particleVelocities,x=h.activeParticles;if(_&&B&&x>0){const R=g.emissionTrailMode==="particles",m=u,w=g.emissionTrailDuration??1,E=g.opacity??1,N=g.particleSize??.5,X=g.bloomIntensity||1,O=Math.max(1,Math.min(64,g.emissionTrailSegments??8)),A=g.emissionTrailShape||"straight",ye=g.followSystemTranslation??!0,xe=h._simPosition,Oe=ye&&xe?xe[0]:0,fe=ye&&xe?xe[1]:0,_t=ye&&xe?xe[2]:0,je=h._simVelocity,it=je?je[0]:0,ti=je?je[1]:0,Mt=je?je[2]:0,qe=pi(g.id),wt=!!(ye&&qe&&qe.hist&&qe.hist.length>1);for(let ut=0;ut<x;ut++){const Ue=ut*8,dt=_[Ue],I=_[Ue+1],K=_[Ue+2],Ie=dt+Oe,W=I+fe,pe=K+_t;let ee=_[Ue+3],ge=_[Ue+4],$=_[Ue+5];const Q=_[Ue+6],J=_[Ue+7];if(Q>=J||J<=0)continue;const te=Q/J;if(g.colorTransitionEnabled){const C=g.startColor??[1,0,0],k=g.endColor??[0,0,1];ee=C[0]+(k[0]-C[0])*te,ge=C[1]+(k[1]-C[1])*te,$=C[2]+(k[2]-C[2])*te}ee=Math.min(1,ee*X),ge=Math.min(1,ge*X),$=Math.min(1,$*X);let ce=N;if(g.randomSize){const C=Math.sin(J*54321.67)*43758.5453%1,k=C<0?C+1:C;ce=(g.minSize??.1)+((g.maxSize??.5)-(g.minSize??.1))*k}if(g.fadeSizeEnabled){const C=Math.max(.01,Math.min(10,g.sizeLifetimeSpeed??1));ce*=1-Math.pow(te,1/C)}if(g.increaseSizeEnabled){const C=Math.max(.01,Math.min(10,g.sizeLifetimeSpeed??1));ce*=1+Math.pow(te,1/C)}if(ce<=0||te>.9)continue;const be=Math.min((.9-te)*(1/.2),1),ve=.75*ce*Is*be;let ue=E;if(g.fadeEnabled&&(ue*=Math.max(0,1-te)),ue*=be,ue<.01)continue;const He=ut*4,Me=B[He],Se=B[He+1],he=B[He+2],me=Me+it,we=Se+ti,Be=he+Mt,Bt=Math.sqrt(me*me+we*we+Be*Be);if(Bt<.001)continue;const bt=1/Bt,Le=me*bt,ke=we*bt,ze=Be*bt,Rt=V.right[0],Ot=V.right[1],Lt=V.right[2];let Tt=Rt*Le+Ot*ke+Lt*ze,Re=Rt-Tt*Le,Te=Ot-Tt*ke,Ee=Lt-Tt*ze,st=Math.sqrt(Re*Re+Te*Te+Ee*Ee);if(st<.2){const C=V.up[0],k=V.up[1],de=V.up[2],Y=C*Le+k*ke+de*ze;Re=C-Y*Le,Te=k-Y*ke,Ee=de-Y*ze,st=Math.sqrt(Re*Re+Te*Te+Ee*Ee)||1}Re/=st,Te/=st,Ee/=st;const rt=Math.min(w,Q);if(rt<.001)continue;const Et=g.gravityEnabled&&g.gravityStrength||0,Ze=qs,We=Hs,$e=Zs;if(g.orientToDirection&&g.burstMode&&wt){const C=h._emitSimRotY||0,k=Ws,de=$s,Y=Js;for(let L=0;L<=O;L++){const j=hi(qe,Ve-L/O*rt,Ti);k[L]=j[0],de[L]=j[1],Y[L]=j[2]}for(let L=0;L<=O;L++){const j=L>0?L-1:0,ie=L<O?L+1:O;let Je=k[j]-k[ie],Ke=Y[j]-Y[ie];const nt=(Math.hypot(Je,Ke)>1e-5?Math.atan2(Je,Ke):Math.atan2(it,Mt))-C,Ge=Math.cos(nt),De=Math.sin(nt),et=L/O*rt,ii=-.5*Et*et*et;Ze[L]=Ge*dt+De*K+k[L],We[L]=I+ii+de[L],$e[L]=-De*dt+Ge*K+Y[L]}}else for(let C=0;C<=O;C++){const k=C/O*rt,de=-.5*Et*k*k;if(wt){const Y=hi(qe,Ve-k,Ti);Ze[C]=dt-Me*k+Y[0],We[C]=I-Se*k+de+Y[1],$e[C]=K-he*k+Y[2]}else Ze[C]=Ie-me*k,We[C]=W-we*k+de,$e[C]=pe-Be*k}if(A!=="straight"){const C=g.emissionTrailShapeAmplitude??.1,k=g.emissionTrailShapeFrequency??4,de=g.emissionTrailShapeSpeed??0;let Y=-ze,L=0,j=Le,ie=Math.sqrt(Y*Y+j*j);ie<1e-6&&(Y=0,L=ze,j=-ke,ie=Math.sqrt(Y*Y+L*L+j*j)||1),Y/=ie,L/=ie,j/=ie;const Je=ke*j-ze*L,Ke=ze*Y-Le*j,Qe=Le*L-ke*Y;for(let Pe=1;Pe<=O;Pe++){const nt=Pe/O*rt,Ge=2*Math.PI*k*(Ve-nt)+de*Ve;let De=0,et=0;A==="zigzag"?De=C*Math.sign(Math.sin(Ge)):A==="sine"?De=C*Math.sin(Ge):A==="spiral"&&(De=C*Math.sin(Ge),et=C*Math.cos(Ge)),Ze[Pe]+=Y*De+Je*et,We[Pe]+=L*De+Ke*et,$e[Pe]+=j*De+Qe*et}}if(R)for(let C=1;C<=O&&u<F;C++){const k=C/O,de=Ze[C]-Oe,Y=We[C]-fe,L=$e[C]-_t,j=u*8,ie=u*4;H[j]=de,H[j+1]=Y,H[j+2]=L,H[j+3]=ee,H[j+4]=ge,H[j+5]=$,H[j+6]=Q+(J-Q)*k,H[j+7]=J,se[ie]=0,se[ie+1]=0,se[ie+2]=0,se[ie+3]=0,ne[ie]=de,ne[ie+1]=Y,ne[ie+2]=L,ne[ie+3]=0,u++}else for(let C=0;C<O&&!(p+42>Ye.length);C++){const k=C/O,de=(C+1)/O,Y=Ze[C],L=We[C],j=$e[C],ie=Ze[C+1],Je=We[C+1],Ke=$e[C+1],Qe=ve*(1-k),Pe=ve*(1-de),nt=ue*(1-k)*(1-k),Ge=ue*(1-de)*(1-de),De=Y+Re*Qe,et=L+Te*Qe,ii=j+Ee*Qe,Di=Y-Re*Qe,Fi=L-Te*Qe,Vi=j-Ee*Qe,Oi=ie+Re*Pe,Li=Je+Te*Pe,ki=Ke+Ee*Pe,lr=ie-Re*Pe,cr=Je-Te*Pe,ur=Ke-Ee*Pe,St=(dr,fr,pr,hr)=>{Ye[p++]=dr,Ye[p++]=fr,Ye[p++]=pr,Ye[p++]=ee,Ye[p++]=ge,Ye[p++]=$,Ye[p++]=hr};St(De,et,ii,nt),St(Di,Fi,Vi,nt),St(Oi,Li,ki,Ge),St(Di,Fi,Vi,nt),St(lr,cr,ur,Ge),St(Oi,Li,ki,Ge)}}R&&u>m&&xt.set(g.id,{first:m,count:u-m})}}const P=y;y=Us(y,h,g),y>P&&at.set(g.id,{first:P/9,count:(y-P)/9})}u>0&&(r.queue.writeBuffer(re,0,H,0,u*8),r.queue.writeBuffer(q,0,se,0,u*4),r.queue.writeBuffer(tt,0,ne,0,u*4)),vt=p/7,vt>0&&r.queue.writeBuffer(Zt,0,Ye,0,p),Mi=y/9,Mi>0&&r.queue.writeBuffer(Wt,0,Ce,0,y)}const mi=()=>{const[u,p]=fs(a.width,a.height);r.queue.writeBuffer(z,0,new Float32Array([1,0,u,p,0,0,0,0])),r.queue.writeBuffer(G,0,new Float32Array([0,1,u,p,0,0,0,0]))};mi();const yi=new Float32Array(16).fill(0);yi[0]=1,r.queue.writeBuffer(M,0,yi);const Fe=gs(r),Ne=ms(r),{particlePipeline:Gs,particleAdditivePipeline:Ds,particleDepthWritePipeline:Fs,blurPipeline:It,compositePipeline:Vs,directRenderPipeline:gi,finalCompositePipeline:Os,glbMeshPipeline:Ls}=ys(r,l,Ne),bi=r.createShaderModule({code:`
|
|
1205
1205
|
struct U { mvp: mat4x4<f32> };
|
|
1206
1206
|
@group(0) @binding(0) var<uniform> u: U;
|
|
1207
1207
|
struct VIn { @location(0) pos: vec3<f32>, @location(1) col: vec4<f32> };
|
|
@@ -1349,4 +1349,4 @@ return function(__deltaTime, __time, __currentFrame, __totalFrames, __particles,
|
|
|
1349
1349
|
}
|
|
1350
1350
|
return vec4<f32>(i.col, i.alpha);
|
|
1351
1351
|
}
|
|
1352
|
-
`}),Pi=u=>r.createRenderPipeline({layout:r.createPipelineLayout({bindGroupLayouts:[Ne.particleBindGroupLayout]}),vertex:{module:vi,entryPoint:"vs",buffers:[{arrayStride:36,attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x4"},{shaderLocation:2,offset:28,format:"float32x2"}]}]},fragment:{module:vi,entryPoint:"fs",targets:[{format:"rgba16float",blend:u}]},primitive:{topology:"triangle-list"},depthStencil:{format:"depth24plus",depthWriteEnabled:!1,depthCompare:"less-equal"}}),Ns=Pi({color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),Ys=Pi({color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),_i=256*256*6,Ce=new Float32Array(_i*9),Wt=r.createBuffer({size:_i*9*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,label:"shapeStrokeBuffer"});let Mi=0,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct}=li(r,l,a.width,a.height),zt=ci(r,a.width,a.height),mt,wi,Gt,Pt;const Bi=()=>{const u=p=>p.createView();mt=u(ot),wi=u(lt),Gt=u(ct),Pt=u(zt)};Bi();const $t={uniformBuffer:v,appearanceUniformBuffer:C,horizontalBlurUniformBuffer:z,verticalBlurUniformBuffer:G,bloomIntensityBuffer:M};let Dt=Xt(r,Fe,$t,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct});const V={mvp:new Float32Array(16),position:new Float32Array([0,0,10]),right:new Float32Array([1,0,0]),up:new Float32Array([0,1,0]),hasCamera:!1};let Ve=0,js=0;const yt=new Float32Array(5),Ri=new Float32Array(16),qs=new Array(65),Hs=new Array(65),Zs=new Array(65),Ws=new Array(65),$s=new Array(65),Js=new Array(65),Ti=[0,0,0],gt={key:null,ms:!1,bindGroup:null};let Ei=!1,Jt=!0,Ft=!1,Vt=null,Kt=a.width,Qt=a.height;function Ai(){const u=[ot,lt,ct,zt],p=li(r,l,a.width,a.height);ot=p.sceneTexture,lt=p.bloomTexA,ct=p.bloomTexB,zt=ci(r,a.width,a.height),Bi(),mi(),f.clear(),b.resizeTextures(),Dt=Xt(r,Fe,$t,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct});let y=!1;const h=()=>{if(!y){y=!0,requestAnimationFrame(h);return}u.forEach(g=>g.destroy())};requestAnimationFrame(h)}function Ks(u,p,y){V.mvp.set(xs(u,p)),p&&p.length>=10&&(V.right[0]=p[0],V.right[1]=p[4],V.right[2]=p[8],V.up[0]=p[1],V.up[1]=p[5],V.up[2]=p[9]),y&&(V.position[0]=y.x??y[0],V.position[1]=y.y??y[1],V.position[2]=y.z??y[2]),V.hasCamera=!0}function Qs(u,p){V.mvp.set(u),p&&(V.position[0]=p.x??p[0],V.position[1]=p.y??p[1],V.position[2]=p.z??p[2]),V.hasCamera=!0}async function ei(u){if(Ft){Vt=u;return}Ft=!0;try{for(const p in T)delete T[p];f.clear(),b.resizeTextures(),Dt=Xt(r,Fe,$t,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct}),await c.replaceSystems({systems:[],activeSystemIndex:0});for(const p of u)await c.addSystems(p.preset,p.position||[0,0,0]);for(const{config:p}of c.particleSystems)T[p.id]||(T[p.id]=D());Jt=!0,c.respawnAllSystems()}finally{if(Ft=!1,Vt){const p=Vt;Vt=null,ei(p)}}}async function er(u,p=[0,0,0]){return ei([{preset:u,position:p}])}function tr(u){if(Ei||Ft||!c.ready||u<=0||c.particleSystems.length===0)return;const p=c.clock;if(p&&(p.loop=c.loop??i,p.duration=c.getTotalDuration(),u=p.tick(u)),u>.1&&(u=.1),u<=0)return;if((a.width!==Kt||a.height!==Qt)&&(Kt=a.width,Qt=a.height,Ai()),Ve+=u,_e.length){for(const m of _e){if(m.getPosition){const w=m.getPosition();w?(m.pos||(m.pos=m._posBuf),Array.isArray(w)?(m.pos[0]=w[0],m.pos[1]=w[1],m.pos[2]=w[2]):(m.pos[0]=w.x,m.pos[1]=w.y,m.pos[2]=w.z)):m.pos=null}m.vel=m._velBuf,m.pos&&m.prevPos&&m.wasActive&&u>0?(m.vel[0]=(m.pos[0]-m.prevPos[0])/u,m.vel[1]=(m.pos[1]-m.prevPos[1])/u,m.vel[2]=(m.pos[2]-m.prevPos[2])/u):(m.vel[0]=0,m.vel[1]=0,m.vel[2]=0),m.justResumed=!!m.pos&&!m.wasActive,m.justResumed&&(m.hist.length=0)}for(const{system:m,config:w}of c.particleSystems){const E=pi(w.id);if(!(!E||E.historyOnly)&&(w.hidden=!E.pos,E.pos)){let N=null;if(E.orientToDirection&&E.vel){const X=E.vel[0],O=E.vel[2];Math.hypot(X,O)>1e-4&&(N=[0,0,Math.atan2(X,O)])}m.setSimulationTransform({position:E.pos,velocity:E.vel,rotation:N}),m.updateAppearanceUniform(),(E.justResumed||m.activeParticles===0)&&m.spawnParticles()}}for(const m of _e)m.pos?Rs(m,Ve):m.hist.length=0,m.pos?(m._prevPosBuf[0]=m.pos[0],m._prevPosBuf[1]=m.pos[1],m._prevPosBuf[2]=m.pos[2],m.prevPos=m._prevPosBuf):m.prevPos=null,m.wasActive=!!m.pos;if(globalThis.__HZFX_DEBUG&&(js++&63)===0){const m=c.particleSystems.reduce((X,O)=>X+(O.system.activeParticles|0),0),w=_e.find(X=>X.pos),E=w?Math.hypot(V.position[0]-w.pos[0],V.position[1]-w.pos[1],V.position[2]-w.pos[2]).toFixed(1):"-",N=_e.map(X=>`{ids:[${[...X.ids]}],pos:${X.pos?"1":"0"},hist:${X.hist.length}}`).join(",");console.info(`[HZFX] movingGroups(${_e.length})=[${N}] activeParticles=${m} systems=${c.particleSystems.length} ribbonVerts=${vt} camDist=${E} t=${Ve.toFixed(1)}`)}}if(c.updateAllSystems(u),p?p.loop:c.loop??i){const m=c.particleSystems.length>0&&c.particleSystems.every(({system:w})=>w.activeParticles===0&&!w.emitting);(p&&p.justLooped||m&&Jt)&&c.respawnAllSystems(),Jt=!m}for(const{system:m,config:w}of c.particleSystems)w.glbModelEnabled&&m.glbAnimator&&(m.glbAnimator.update(u),m.updateAnimatedGLBBuffer());r.queue.writeBuffer(v,0,V.mvp),yt[0]=V.position[0],yt[1]=V.position[1],yt[2]=V.position[2],yt[3]=a.height/Math.max(1,a.width),yt[4]=Ve,r.queue.writeBuffer(v,64,yt),zs();const h=r.createCommandEncoder();let g=!1;if(e)try{const m=e();if(m){let w=null,E=null,N=!1;if(m instanceof GPUTexture?m.width===a.width&&m.height===a.height&&(w=m,E=()=>m.createView({aspect:"depth-only"}),N=m.sampleCount>1):m.view&&(w=m.view,E=()=>m.view,N=!!m.multisampled),w){const{pipeline:X,layout:O}=S(N);(gt.key!==w||gt.ms!==N)&&(gt.key=w,gt.ms=N,gt.bindGroup=r.createBindGroup({layout:O,entries:[{binding:0,resource:E()}]}));const U=h.beginRenderPass({colorAttachments:[],depthStencilAttachment:{view:Pt,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}});U.setPipeline(X),U.setBindGroup(0,gt.bindGroup),U.draw(3),U.end(),g=!0}}}catch{}const P=h.beginRenderPass({colorAttachments:[{view:mt,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}],depthStencilAttachment:g?{view:Pt,depthLoadOp:"load",depthStoreOp:"store"}:{view:Pt,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}});for(const{system:m,config:w}of c.particleSystems)w.bloomEnabled||w.hidden||m.activeParticles===0&&!at.has(w.id)||(Ui(P,m,w),Ii(P,m,w));vt>0&&(P.setPipeline(ks),P.setBindGroup(0,Xs),P.setVertexBuffer(0,Zt),P.draw(vt)),P.end();const _=new Map;for(const{system:m,config:w}of c.particleSystems){if(!w.bloomEnabled||w.hidden||m.activeParticles===0&&!at.has(w.id))continue;const E=w.bloomColor||[1,1,1],N=`b${w.bloomIntensity??1}|${E[0]}|${E[1]}|${E[2]}`,X=_.get(N);X?X.membres.push({system:m,config:w}):_.set(N,{membres:[{system:m,config:w}],premier:m})}if(_.size>0){const m={colorAttachments:[{view:wi,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]},w={colorAttachments:[{view:Gt,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]};for(const[E,N]of _){const X=b.getBloomSourceTexture(E,a.width,a.height),O=h.beginRenderPass({colorAttachments:[{view:X.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}],depthStencilAttachment:{view:Pt,depthClearValue:1,depthLoadOp:"load",depthStoreOp:"store"}});for(const{system:Oe,config:fe}of N.membres)Ui(O,Oe,fe),Ii(O,Oe,fe);O.end(),Ri[0]=N.membres[0].config.bloomIntensity,r.queue.writeBuffer(M,0,Ri),f.systemBloomHorizontalBindGroups[E]||(f.systemBloomHorizontalBindGroups[E]=r.createBindGroup({layout:Ne.bloomBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:X.createView()},{binding:2,resource:{buffer:z}}]}));let U=h.beginRenderPass(m);U.setPipeline(It),U.setBindGroup(0,f.systemBloomHorizontalBindGroups[E]),U.draw(3),U.end(),U=h.beginRenderPass(w),U.setPipeline(It),U.setBindGroup(0,Dt.verticalBlurBindGroup),U.draw(3),U.end(),f.secondHorizontalBindGroups[E]||(f.secondHorizontalBindGroups[E]=r.createBindGroup({layout:Ne.bloomBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:Gt},{binding:2,resource:{buffer:z}}]})),U=h.beginRenderPass(m),U.setPipeline(It),U.setBindGroup(0,f.secondHorizontalBindGroups[E]),U.draw(3),U.end(),U=h.beginRenderPass(w),U.setPipeline(It),U.setBindGroup(0,Dt.verticalBlurBindGroup),U.draw(3),U.end();const ye=`${E}#${N.premier.config.id}`,xe=b.getBloomCompositeTexture(E,a.width,a.height);U=h.beginRenderPass({colorAttachments:[{view:xe.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]}),U.setPipeline(Vs),f.systemBloomCompositeBindGroups[ye]||(f.systemBloomCompositeBindGroups[ye]=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:X.createView()},{binding:2,resource:Gt},{binding:3,resource:{buffer:N.premier.bloomIntensityBuffer}}]})),U.setBindGroup(0,f.systemBloomCompositeBindGroups[ye]),U.draw(3),U.end()}}const B=b.getCombinedTexture(a.width,a.height),x=h.beginRenderPass({colorAttachments:[{view:B.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]});x.setPipeline(gi),f.combinedInitialBindGroup||(f.combinedInitialBindGroup=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:mt},{binding:2,resource:mt},{binding:3,resource:{buffer:M}}]})),x.setBindGroup(0,f.combinedInitialBindGroup),x.draw(3);for(const m of _.keys())x.setPipeline(gi),f.combinedBloomCompositeBindGroups[m]||(f.combinedBloomCompositeBindGroups[m]=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:b.getBloomCompositeTexture(m,a.width,a.height).createView()},{binding:2,resource:mt},{binding:3,resource:{buffer:M}}]})),x.setBindGroup(0,f.combinedBloomCompositeBindGroups[m]),x.draw(3);x.end();const R=h.beginRenderPass({colorAttachments:[{view:n.getCurrentTexture().createView(),loadOp:o?"load":"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]});R.setPipeline(Os),f.finalBindGroup||(f.finalBindGroup=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:B.createView()},{binding:2,resource:mt},{binding:3,resource:{buffer:M}}]})),R.setBindGroup(0,f.finalBindGroup),R.draw(3),R.end(),r.queue.submit([h.finish()])}function Ci(u,p){const y=u.config.id,h=!f.systemBindGroups[y]||f.textureStates[y]!==p.textureEnabled||f.textureRefs[y]!==u.particleTexture;return f.textureStates[y]=p.textureEnabled,f.textureRefs[y]=u.particleTexture,h&&(f.systemBindGroups[y]=r.createBindGroup({layout:Ne.particleBindGroupLayout,entries:[{binding:0,resource:{buffer:v}},{binding:1,resource:{buffer:u.appearanceUniformBuffer}},{binding:2,resource:u.particleTexture.createView()},{binding:3,resource:Fe}]})),f.systemBindGroups[y]}function Ui(u,p,y){const h=p.config.id,g=y.glbModelEnabled&&p.glbMeshData,P=Ci(p,y),_=y.shapeDisplay!==!1;if(g)_&&(u.setPipeline(Ls),u.setBindGroup(0,P),u.setVertexBuffer(0,p.glbVertexBuffer),u.setVertexBuffer(1,p.instanceBuffer),u.setVertexBuffer(2,p.velocityBuffer),u.setIndexBuffer(p.glbIndexBuffer,p.glbIndexFormat),u.drawIndexed(p.glbIndexCount,p.activeParticles));else{u.setPipeline(y.blendMode==="additive"?Ds:Gs),u.setIndexBuffer(Z,"uint16"),T[h]||(T[h]=D()),u.setVertexBuffer(0,T[h]),u.setBindGroup(0,P),_&&(u.setVertexBuffer(1,p.instanceBuffer),u.setVertexBuffer(2,p.velocityBuffer),u.setVertexBuffer(3,p.trailBuffer),u.drawIndexed(6,p.activeParticles));const B=xt.get(h);B&&(u.setVertexBuffer(1,re),u.setVertexBuffer(2,q),u.setVertexBuffer(3,tt),u.drawIndexed(6,B.count,0,0,B.first)),_&&y.depthWriteEnabled&&(u.setPipeline(Fs),u.drawIndexed(6,p.activeParticles))}}function Ii(u,p,y){const h=at.get(y.id);!h||h.count<=0||(u.setPipeline(y.blendMode==="additive"?Ys:Ns),u.setBindGroup(0,Ci(p,y)),u.setVertexBuffer(0,Wt),u.draw(h.count,1,h.first,0))}function ir(){Kt=a.width,Qt=a.height,Ai()}function sr(){f.clear()}function rr(){Ei=!0,c.destroy(),[ot,lt,ct,zt].forEach(u=>u==null?void 0:u.destroy()),b.resizeTextures(),[v,C,z,G,M,Z,re,q,tt,Zt,Wt].forEach(u=>u==null?void 0:u.destroy()),Object.values(T).forEach(u=>u==null?void 0:u.destroy())}async function zi(u,p){const y=await c.addSystems(u,p);for(const{config:h}of c.particleSystems)T[h.id]||(T[h.id]=D());return c.respawnAllSystems(),new Set(Array.isArray(y)?y:[])}function Gi(u){var p;for(const y of u){const h=c.particleSystems.findIndex(P=>P.config.id===y);if(h<0)continue;c.removeSystem(h),(p=T[y])==null||p.destroy(),delete T[y],delete f.systemBindGroups[y],delete f.textureStates[y],delete f.textureRefs[y];const g=`#${y}`;for(const P in f.systemBloomCompositeBindGroups)P.endsWith(g)&&delete f.systemBloomCompositeBindGroups[P]}}async function nr(u,p=[0,0,0]){const y=await zi(u,p);return{remove(){Gi(y)}}}async function ar(u,p={}){const y=await zi(u,[0,0,0]);globalThis.__HZFX_DEBUG&&console.info(`[HZFX] addMovingEmitter: presetSystems=${(u&&u.systems||[]).length} newIds=[${[...y]}]`);const h={ids:y,pos:null,hist:[],getPosition:p.getPosition||null,orientToDirection:!!p.orientToDirection,_posBuf:[0,0,0],_velBuf:[0,0,0],_prevPosBuf:[0,0,0]};return _e.push(h),{setPosition(g){g&&(h.pos=Array.isArray(g)?[g[0],g[1],g[2]]:[g.x,g.y,g.z])},setOrientToDirection(g){h.orientToDirection=!!g},remove(){Gi(y);const g=_e.indexOf(h);g>=0&&_e.splice(g,1)}}}function or(u,p){const h={ids:u instanceof Set?u:new Set(u),pos:null,hist:[],getPosition:p,historyOnly:!0,_posBuf:[0,0,0],_velBuf:[0,0,0],_prevPosBuf:[0,0,0]};return _e.push(h),{remove(){const g=_e.indexOf(h);g>=0&&_e.splice(g,1)},setIds(g){h.ids=g instanceof Set?g:new Set(g)}}}return{manager:c,device:r,context:n,setCamera:Ks,setCameraMVP:Qs,setEmitters:ei,loadPreset:er,addEmitter:nr,addMovingEmitter:ar,render:tr,resize:ir,clearCaches:sr,trackHistoryGroup:or,destroy:rr}}function Kr(s){return()=>{var t,e,i,r,n,a,o,l;try{const c=s.backend;if(!c)return null;const d=s.domElement.width,S=s.domElement.height,b=(typeof s._getFrameBufferTarget=="function"?s._getFrameBufferTarget():null)||s._frameBufferTarget||null;if(s.needsFrameBufferTarget&&b){const C=c.get(b),z=((i=(e=(t=s._textures)==null?void 0:t.get)==null?void 0:e.call(t,b))==null?void 0:i.depthTexture)||b.depthTexture,G=[(r=C==null?void 0:C.depthTexture)==null?void 0:r.texture,C==null?void 0:C.depthTexture,(n=C==null?void 0:C.depthBuffer)==null?void 0:n.texture,z?(a=c.get(z))==null?void 0:a.texture:null];for(const M of G)if(M&&typeof M.createView=="function"&&M.width===d&&M.height===S)return M;return null}const f=s.getCanvasTarget?c.get(s.getCanvasTarget()):null,v=((l=(o=f==null?void 0:f.descriptor)==null?void 0:o.depthStencilAttachment)==null?void 0:l.view)??null;return v?{view:v,multisampled:(s.currentSamples??0)>1}:null}catch{return null}}}exports.GLBAnimator=os;exports.HZClock=ls;exports.Objects3DManager=Lr;exports.ParticleEmitter=Ji;exports.ParticlePhysics=ss;exports.ParticleScript=ai;exports.ParticleSystem=kt;exports.ParticleSystemManager=us;exports.ParticleTextureManager=rs;exports.blurShader=Qi;exports.compositeShader=es;exports.createBindGroupLayouts=ms;exports.createBindGroups=Xt;exports.createBuffer=pt;exports.createCubeGeometry=bs;exports.createDepthTexture=ci;exports.createLookAtMatrix=Nr;exports.createProjectionMatrix=Yr;exports.createRenderPipelines=ys;exports.createRenderTextures=li;exports.createSampler=gs;exports.createSphereGeometry=Ss;exports.directRenderShader=ts;exports.extractGLBTexture=oi;exports.fetchPreset=Wr;exports.glbMeshParticleShader=hs;exports.hexToRgb=kr;exports.initHzFxOverlay=Jr;exports.initWebGPU=ds;exports.isHZFX=di;exports.loadScene=Zr;exports.makeThreeSceneDepth=Kr;exports.multiplyMatrices=xs;exports.object3dShader=ps;exports.packHZFX=ws;exports.parseGLB=as;exports.particlePhysicsShader=is;exports.particleShader=Ki;exports.rgbToHex=Xr;exports.saveScene=Hr;exports.serializeSystemConfig=Bs;exports.unpackHZFX=fi;
|
|
1352
|
+
`}),Pi=u=>r.createRenderPipeline({layout:r.createPipelineLayout({bindGroupLayouts:[Ne.particleBindGroupLayout]}),vertex:{module:vi,entryPoint:"vs",buffers:[{arrayStride:36,attributes:[{shaderLocation:0,offset:0,format:"float32x3"},{shaderLocation:1,offset:12,format:"float32x4"},{shaderLocation:2,offset:28,format:"float32x2"}]}]},fragment:{module:vi,entryPoint:"fs",targets:[{format:"rgba16float",blend:u}]},primitive:{topology:"triangle-list"},depthStencil:{format:"depth24plus",depthWriteEnabled:!1,depthCompare:"less-equal"}}),Ns=Pi({color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),Ys=Pi({color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}),_i=256*256*6,Ce=new Float32Array(_i*9),Wt=r.createBuffer({size:_i*9*4,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,label:"shapeStrokeBuffer"});let Mi=0,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct}=li(r,l,a.width,a.height),zt=ci(r,a.width,a.height),mt,wi,Gt,Pt;const Bi=()=>{const u=p=>p.createView();mt=u(ot),wi=u(lt),Gt=u(ct),Pt=u(zt)};Bi();const $t={uniformBuffer:v,appearanceUniformBuffer:U,horizontalBlurUniformBuffer:z,verticalBlurUniformBuffer:G,bloomIntensityBuffer:M};let Dt=Xt(r,Fe,$t,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct});const V={mvp:new Float32Array(16),position:new Float32Array([0,0,10]),right:new Float32Array([1,0,0]),up:new Float32Array([0,1,0]),hasCamera:!1};let Ve=0,js=0;const yt=new Float32Array(5),Ri=new Float32Array(16),qs=new Array(65),Hs=new Array(65),Zs=new Array(65),Ws=new Array(65),$s=new Array(65),Js=new Array(65),Ti=[0,0,0],gt={key:null,ms:!1,bindGroup:null};let Ei=!1,Jt=!0,Ft=!1,Vt=null,Kt=a.width,Qt=a.height;function Ai(){const u=[ot,lt,ct,zt],p=li(r,l,a.width,a.height);ot=p.sceneTexture,lt=p.bloomTexA,ct=p.bloomTexB,zt=ci(r,a.width,a.height),Bi(),mi(),f.clear(),b.resizeTextures(),Dt=Xt(r,Fe,$t,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct});let y=!1;const h=()=>{if(!y){y=!0,requestAnimationFrame(h);return}u.forEach(g=>g.destroy())};requestAnimationFrame(h)}function Ks(u,p,y){V.mvp.set(xs(u,p)),p&&p.length>=10&&(V.right[0]=p[0],V.right[1]=p[4],V.right[2]=p[8],V.up[0]=p[1],V.up[1]=p[5],V.up[2]=p[9]),y&&(V.position[0]=y.x??y[0],V.position[1]=y.y??y[1],V.position[2]=y.z??y[2]),V.hasCamera=!0}function Qs(u,p){V.mvp.set(u),p&&(V.position[0]=p.x??p[0],V.position[1]=p.y??p[1],V.position[2]=p.z??p[2]),V.hasCamera=!0}async function ei(u){if(Ft){Vt=u;return}Ft=!0;try{for(const p in T)delete T[p];f.clear(),b.resizeTextures(),Dt=Xt(r,Fe,$t,{sceneTexture:ot,bloomTexA:lt,bloomTexB:ct}),await c.replaceSystems({systems:[],activeSystemIndex:0});for(const p of u)await c.addSystems(p.preset,p.position||[0,0,0]);for(const{config:p}of c.particleSystems)T[p.id]||(T[p.id]=D());Jt=!0,c.respawnAllSystems()}finally{if(Ft=!1,Vt){const p=Vt;Vt=null,ei(p)}}}async function er(u,p=[0,0,0]){return ei([{preset:u,position:p}])}function tr(u){if(Ei||Ft||!c.ready||u<=0||c.particleSystems.length===0)return;const p=c.clock;if(p&&(p.loop=c.loop??i,p.duration=c.getTotalDuration(),u=p.tick(u)),u>.1&&(u=.1),u<=0)return;if((a.width!==Kt||a.height!==Qt)&&(Kt=a.width,Qt=a.height,Ai()),Ve+=u,_e.length){for(const m of _e){if(m.getPosition){const w=m.getPosition();w?(m.pos||(m.pos=m._posBuf),Array.isArray(w)?(m.pos[0]=w[0],m.pos[1]=w[1],m.pos[2]=w[2]):(m.pos[0]=w.x,m.pos[1]=w.y,m.pos[2]=w.z)):m.pos=null}m.vel=m._velBuf,m.pos&&m.prevPos&&m.wasActive&&u>0?(m.vel[0]=(m.pos[0]-m.prevPos[0])/u,m.vel[1]=(m.pos[1]-m.prevPos[1])/u,m.vel[2]=(m.pos[2]-m.prevPos[2])/u):(m.vel[0]=0,m.vel[1]=0,m.vel[2]=0),m.justResumed=!!m.pos&&!m.wasActive,m.justResumed&&(m.hist.length=0)}for(const{system:m,config:w}of c.particleSystems){const E=pi(w.id);if(!(!E||E.historyOnly)&&(w.hidden=!E.pos,E.pos)){let N=null;if(E.orientToDirection&&E.vel){const O=E.vel[0],A=E.vel[2];Math.hypot(O,A)>1e-4&&(N=[0,0,Math.atan2(O,A)])}m.setSimulationTransform({position:E.pos,velocity:E.vel,rotation:N}),m.updateAppearanceUniform();const X=m.activeParticles===0&&!m.emitting;(E.justResumed||X)&&m.spawnParticles()}}for(const m of _e)m.pos?Rs(m,Ve):m.hist.length=0,m.pos?(m._prevPosBuf[0]=m.pos[0],m._prevPosBuf[1]=m.pos[1],m._prevPosBuf[2]=m.pos[2],m.prevPos=m._prevPosBuf):m.prevPos=null,m.wasActive=!!m.pos;if(globalThis.__HZFX_DEBUG&&(js++&63)===0){const m=c.particleSystems.reduce((X,O)=>X+(O.system.activeParticles|0),0),w=_e.find(X=>X.pos),E=w?Math.hypot(V.position[0]-w.pos[0],V.position[1]-w.pos[1],V.position[2]-w.pos[2]).toFixed(1):"-",N=_e.map(X=>`{ids:[${[...X.ids]}],pos:${X.pos?"1":"0"},hist:${X.hist.length}}`).join(",");console.info(`[HZFX] movingGroups(${_e.length})=[${N}] activeParticles=${m} systems=${c.particleSystems.length} ribbonVerts=${vt} camDist=${E} t=${Ve.toFixed(1)}`)}}if(c.updateAllSystems(u),p?p.loop:c.loop??i){const m=c.particleSystems.length>0&&c.particleSystems.every(({system:w})=>w.activeParticles===0&&!w.emitting);(p&&p.justLooped||m&&Jt)&&c.respawnAllSystems(),Jt=!m}for(const{system:m,config:w}of c.particleSystems)w.glbModelEnabled&&m.glbAnimator&&(m.glbAnimator.update(u),m.updateAnimatedGLBBuffer());r.queue.writeBuffer(v,0,V.mvp),yt[0]=V.position[0],yt[1]=V.position[1],yt[2]=V.position[2],yt[3]=a.height/Math.max(1,a.width),yt[4]=Ve,r.queue.writeBuffer(v,64,yt),zs();const h=r.createCommandEncoder();let g=!1;if(e)try{const m=e();if(m){let w=null,E=null,N=!1;if(m instanceof GPUTexture?m.width===a.width&&m.height===a.height&&(w=m,E=()=>m.createView({aspect:"depth-only"}),N=m.sampleCount>1):m.view&&(w=m.view,E=()=>m.view,N=!!m.multisampled),w){const{pipeline:X,layout:O}=S(N);(gt.key!==w||gt.ms!==N)&&(gt.key=w,gt.ms=N,gt.bindGroup=r.createBindGroup({layout:O,entries:[{binding:0,resource:E()}]}));const A=h.beginRenderPass({colorAttachments:[],depthStencilAttachment:{view:Pt,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}});A.setPipeline(X),A.setBindGroup(0,gt.bindGroup),A.draw(3),A.end(),g=!0}}}catch{}const P=h.beginRenderPass({colorAttachments:[{view:mt,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}],depthStencilAttachment:g?{view:Pt,depthLoadOp:"load",depthStoreOp:"store"}:{view:Pt,depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}});for(const{system:m,config:w}of c.particleSystems)w.bloomEnabled||w.hidden||m.activeParticles===0&&!at.has(w.id)||(Ui(P,m,w),Ii(P,m,w));vt>0&&(P.setPipeline(ks),P.setBindGroup(0,Xs),P.setVertexBuffer(0,Zt),P.draw(vt)),P.end();const _=new Map;for(const{system:m,config:w}of c.particleSystems){if(!w.bloomEnabled||w.hidden||m.activeParticles===0&&!at.has(w.id))continue;const E=w.bloomColor||[1,1,1],N=`b${w.bloomIntensity??1}|${E[0]}|${E[1]}|${E[2]}`,X=_.get(N);X?X.membres.push({system:m,config:w}):_.set(N,{membres:[{system:m,config:w}],premier:m})}if(_.size>0){const m={colorAttachments:[{view:wi,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]},w={colorAttachments:[{view:Gt,loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]};for(const[E,N]of _){const X=b.getBloomSourceTexture(E,a.width,a.height),O=h.beginRenderPass({colorAttachments:[{view:X.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}],depthStencilAttachment:{view:Pt,depthClearValue:1,depthLoadOp:"load",depthStoreOp:"store"}});for(const{system:Oe,config:fe}of N.membres)Ui(O,Oe,fe),Ii(O,Oe,fe);O.end(),Ri[0]=N.membres[0].config.bloomIntensity,r.queue.writeBuffer(M,0,Ri),f.systemBloomHorizontalBindGroups[E]||(f.systemBloomHorizontalBindGroups[E]=r.createBindGroup({layout:Ne.bloomBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:X.createView()},{binding:2,resource:{buffer:z}}]}));let A=h.beginRenderPass(m);A.setPipeline(It),A.setBindGroup(0,f.systemBloomHorizontalBindGroups[E]),A.draw(3),A.end(),A=h.beginRenderPass(w),A.setPipeline(It),A.setBindGroup(0,Dt.verticalBlurBindGroup),A.draw(3),A.end(),f.secondHorizontalBindGroups[E]||(f.secondHorizontalBindGroups[E]=r.createBindGroup({layout:Ne.bloomBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:Gt},{binding:2,resource:{buffer:z}}]})),A=h.beginRenderPass(m),A.setPipeline(It),A.setBindGroup(0,f.secondHorizontalBindGroups[E]),A.draw(3),A.end(),A=h.beginRenderPass(w),A.setPipeline(It),A.setBindGroup(0,Dt.verticalBlurBindGroup),A.draw(3),A.end();const ye=`${E}#${N.premier.config.id}`,xe=b.getBloomCompositeTexture(E,a.width,a.height);A=h.beginRenderPass({colorAttachments:[{view:xe.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]}),A.setPipeline(Vs),f.systemBloomCompositeBindGroups[ye]||(f.systemBloomCompositeBindGroups[ye]=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:X.createView()},{binding:2,resource:Gt},{binding:3,resource:{buffer:N.premier.bloomIntensityBuffer}}]})),A.setBindGroup(0,f.systemBloomCompositeBindGroups[ye]),A.draw(3),A.end()}}const B=b.getCombinedTexture(a.width,a.height),x=h.beginRenderPass({colorAttachments:[{view:B.createView(),loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]});x.setPipeline(gi),f.combinedInitialBindGroup||(f.combinedInitialBindGroup=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:mt},{binding:2,resource:mt},{binding:3,resource:{buffer:M}}]})),x.setBindGroup(0,f.combinedInitialBindGroup),x.draw(3);for(const m of _.keys())x.setPipeline(gi),f.combinedBloomCompositeBindGroups[m]||(f.combinedBloomCompositeBindGroups[m]=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:b.getBloomCompositeTexture(m,a.width,a.height).createView()},{binding:2,resource:mt},{binding:3,resource:{buffer:M}}]})),x.setBindGroup(0,f.combinedBloomCompositeBindGroups[m]),x.draw(3);x.end();const R=h.beginRenderPass({colorAttachments:[{view:n.getCurrentTexture().createView(),loadOp:o?"load":"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]});R.setPipeline(Os),f.finalBindGroup||(f.finalBindGroup=r.createBindGroup({layout:Ne.compositeBindGroupLayout,entries:[{binding:0,resource:Fe},{binding:1,resource:B.createView()},{binding:2,resource:mt},{binding:3,resource:{buffer:M}}]})),R.setBindGroup(0,f.finalBindGroup),R.draw(3),R.end(),r.queue.submit([h.finish()])}function Ci(u,p){const y=u.config.id,h=!f.systemBindGroups[y]||f.textureStates[y]!==p.textureEnabled||f.textureRefs[y]!==u.particleTexture;return f.textureStates[y]=p.textureEnabled,f.textureRefs[y]=u.particleTexture,h&&(f.systemBindGroups[y]=r.createBindGroup({layout:Ne.particleBindGroupLayout,entries:[{binding:0,resource:{buffer:v}},{binding:1,resource:{buffer:u.appearanceUniformBuffer}},{binding:2,resource:u.particleTexture.createView()},{binding:3,resource:Fe}]})),f.systemBindGroups[y]}function Ui(u,p,y){const h=p.config.id,g=y.glbModelEnabled&&p.glbMeshData,P=Ci(p,y),_=y.shapeDisplay!==!1;if(g)_&&(u.setPipeline(Ls),u.setBindGroup(0,P),u.setVertexBuffer(0,p.glbVertexBuffer),u.setVertexBuffer(1,p.instanceBuffer),u.setVertexBuffer(2,p.velocityBuffer),u.setIndexBuffer(p.glbIndexBuffer,p.glbIndexFormat),u.drawIndexed(p.glbIndexCount,p.activeParticles));else{u.setPipeline(y.blendMode==="additive"?Ds:Gs),u.setIndexBuffer(Z,"uint16"),T[h]||(T[h]=D()),u.setVertexBuffer(0,T[h]),u.setBindGroup(0,P),_&&(u.setVertexBuffer(1,p.instanceBuffer),u.setVertexBuffer(2,p.velocityBuffer),u.setVertexBuffer(3,p.trailBuffer),u.drawIndexed(6,p.activeParticles));const B=xt.get(h);B&&(u.setVertexBuffer(1,re),u.setVertexBuffer(2,q),u.setVertexBuffer(3,tt),u.drawIndexed(6,B.count,0,0,B.first)),_&&y.depthWriteEnabled&&(u.setPipeline(Fs),u.drawIndexed(6,p.activeParticles))}}function Ii(u,p,y){const h=at.get(y.id);!h||h.count<=0||(u.setPipeline(y.blendMode==="additive"?Ys:Ns),u.setBindGroup(0,Ci(p,y)),u.setVertexBuffer(0,Wt),u.draw(h.count,1,h.first,0))}function ir(){Kt=a.width,Qt=a.height,Ai()}function sr(){f.clear()}function rr(){Ei=!0,c.destroy(),[ot,lt,ct,zt].forEach(u=>u==null?void 0:u.destroy()),b.resizeTextures(),[v,U,z,G,M,Z,re,q,tt,Zt,Wt].forEach(u=>u==null?void 0:u.destroy()),Object.values(T).forEach(u=>u==null?void 0:u.destroy())}async function zi(u,p){const y=await c.addSystems(u,p);for(const{config:h}of c.particleSystems)T[h.id]||(T[h.id]=D());return c.respawnAllSystems(),new Set(Array.isArray(y)?y:[])}function Gi(u){var p;for(const y of u){const h=c.particleSystems.findIndex(P=>P.config.id===y);if(h<0)continue;c.removeSystem(h),(p=T[y])==null||p.destroy(),delete T[y],delete f.systemBindGroups[y],delete f.textureStates[y],delete f.textureRefs[y];const g=`#${y}`;for(const P in f.systemBloomCompositeBindGroups)P.endsWith(g)&&delete f.systemBloomCompositeBindGroups[P]}}async function nr(u,p=[0,0,0]){const y=await zi(u,p);return{remove(){Gi(y)}}}async function ar(u,p={}){const y=await zi(u,[0,0,0]);globalThis.__HZFX_DEBUG&&console.info(`[HZFX] addMovingEmitter: presetSystems=${(u&&u.systems||[]).length} newIds=[${[...y]}]`);const h={ids:y,pos:null,hist:[],getPosition:p.getPosition||null,orientToDirection:!!p.orientToDirection,_posBuf:[0,0,0],_velBuf:[0,0,0],_prevPosBuf:[0,0,0]};return _e.push(h),{setPosition(g){g&&(h.pos=Array.isArray(g)?[g[0],g[1],g[2]]:[g.x,g.y,g.z])},setOrientToDirection(g){h.orientToDirection=!!g},remove(){Gi(y);const g=_e.indexOf(h);g>=0&&_e.splice(g,1)}}}function or(u,p){const h={ids:u instanceof Set?u:new Set(u),pos:null,hist:[],getPosition:p,historyOnly:!0,_posBuf:[0,0,0],_velBuf:[0,0,0],_prevPosBuf:[0,0,0]};return _e.push(h),{remove(){const g=_e.indexOf(h);g>=0&&_e.splice(g,1)},setIds(g){h.ids=g instanceof Set?g:new Set(g)}}}return{manager:c,device:r,context:n,setCamera:Ks,setCameraMVP:Qs,setEmitters:ei,loadPreset:er,addEmitter:nr,addMovingEmitter:ar,render:tr,resize:ir,clearCaches:sr,trackHistoryGroup:or,destroy:rr}}function Kr(s){return()=>{var t,e,i,r,n,a,o,l;try{const c=s.backend;if(!c)return null;const d=s.domElement.width,S=s.domElement.height,b=(typeof s._getFrameBufferTarget=="function"?s._getFrameBufferTarget():null)||s._frameBufferTarget||null;if(s.needsFrameBufferTarget&&b){const U=c.get(b),z=((i=(e=(t=s._textures)==null?void 0:t.get)==null?void 0:e.call(t,b))==null?void 0:i.depthTexture)||b.depthTexture,G=[(r=U==null?void 0:U.depthTexture)==null?void 0:r.texture,U==null?void 0:U.depthTexture,(n=U==null?void 0:U.depthBuffer)==null?void 0:n.texture,z?(a=c.get(z))==null?void 0:a.texture:null];for(const M of G)if(M&&typeof M.createView=="function"&&M.width===d&&M.height===S)return M;return null}const f=s.getCanvasTarget?c.get(s.getCanvasTarget()):null,v=((l=(o=f==null?void 0:f.descriptor)==null?void 0:o.depthStencilAttachment)==null?void 0:l.view)??null;return v?{view:v,multisampled:(s.currentSamples??0)>1}:null}catch{return null}}}exports.GLBAnimator=os;exports.HZClock=ls;exports.Objects3DManager=Lr;exports.ParticleEmitter=Ji;exports.ParticlePhysics=ss;exports.ParticleScript=ai;exports.ParticleSystem=kt;exports.ParticleSystemManager=us;exports.ParticleTextureManager=rs;exports.blurShader=Qi;exports.compositeShader=es;exports.createBindGroupLayouts=ms;exports.createBindGroups=Xt;exports.createBuffer=pt;exports.createCubeGeometry=bs;exports.createDepthTexture=ci;exports.createLookAtMatrix=Nr;exports.createProjectionMatrix=Yr;exports.createRenderPipelines=ys;exports.createRenderTextures=li;exports.createSampler=gs;exports.createSphereGeometry=Ss;exports.directRenderShader=ts;exports.extractGLBTexture=oi;exports.fetchPreset=Wr;exports.glbMeshParticleShader=hs;exports.hexToRgb=kr;exports.initHzFxOverlay=Jr;exports.initWebGPU=ds;exports.isHZFX=di;exports.loadScene=Zr;exports.makeThreeSceneDepth=Kr;exports.multiplyMatrices=xs;exports.object3dShader=ps;exports.packHZFX=ws;exports.parseGLB=as;exports.particlePhysicsShader=is;exports.particleShader=Ki;exports.rgbToHex=Xr;exports.saveScene=Hr;exports.serializeSystemConfig=Bs;exports.unpackHZFX=fi;
|
|
@@ -193,8 +193,8 @@ class qs {
|
|
|
193
193
|
if (Math.abs(a) < 1e-6 || o <= 1e-6)
|
|
194
194
|
l = Math.random();
|
|
195
195
|
else {
|
|
196
|
-
const S = Math.random(), b = 0.5 * a, f = e, v = -S * o,
|
|
197
|
-
l = (-f + Math.sqrt(
|
|
196
|
+
const S = Math.random(), b = 0.5 * a, f = e, v = -S * o, U = Math.max(0, f * f - 4 * b * v);
|
|
197
|
+
l = (-f + Math.sqrt(U)) / (2 * b), Number.isFinite(l) || (l = Math.random()), l = Math.min(1, Math.max(0, l));
|
|
198
198
|
}
|
|
199
199
|
const c = l * r, d = e + a * l;
|
|
200
200
|
t[0] = Math.cos(n) * d, t[1] = c, t[2] = Math.sin(n) * d;
|
|
@@ -257,32 +257,32 @@ class qs {
|
|
|
257
257
|
}
|
|
258
258
|
calculateVelocity(t, e, i, r, n) {
|
|
259
259
|
const a = this.config.emissionPositionX || 0, o = this.config.emissionPositionY || 0, l = this.config.emissionPositionZ || 0, c = t - a, d = e - o, S = i - l, b = Math.sqrt(c * c + d * d + S * S);
|
|
260
|
-
let f, v,
|
|
260
|
+
let f, v, U;
|
|
261
261
|
if (b > 1e-4) {
|
|
262
262
|
let D = !1;
|
|
263
263
|
if (this.config.emissionShape === "circle" && this.config.circleVelocityDirection === "tangential") {
|
|
264
264
|
const M = this.inverseRotation(c, d, S), Z = Math.sqrt(M[0] * M[0] + M[1] * M[1]);
|
|
265
265
|
if (Z > 1e-4) {
|
|
266
266
|
const T = -M[1] / Z, G = M[0] / Z, F = this.applyRotation(T, G, 0);
|
|
267
|
-
f = F[0], v = F[1],
|
|
267
|
+
f = F[0], v = F[1], U = F[2], D = !0;
|
|
268
268
|
}
|
|
269
269
|
} else if (this.config.emissionShape === "cylinder" && this.config.cylinderVelocityDirection === "tangential") {
|
|
270
270
|
const M = this.inverseRotation(c, d, S), Z = Math.sqrt(M[0] * M[0] + M[2] * M[2]);
|
|
271
271
|
if (Z > 1e-4) {
|
|
272
272
|
const T = -M[2] / Z, G = M[0] / Z, F = this.applyRotation(T, 0, G);
|
|
273
|
-
f = F[0], v = F[1],
|
|
273
|
+
f = F[0], v = F[1], U = F[2], D = !0;
|
|
274
274
|
} else {
|
|
275
275
|
const T = Math.random() * Math.PI * 2, G = this.applyRotation(Math.cos(T), 0, Math.sin(T));
|
|
276
|
-
f = G[0], v = G[1],
|
|
276
|
+
f = G[0], v = G[1], U = G[2], D = !0;
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
D || (f = c / b, v = d / b,
|
|
279
|
+
D || (f = c / b, v = d / b, U = S / b);
|
|
280
280
|
} else {
|
|
281
281
|
const D = Math.random() * Math.PI * 2, M = Math.acos(2 * Math.random() - 1);
|
|
282
|
-
f = Math.sin(M) * Math.cos(D), v = Math.sin(M) * Math.sin(D),
|
|
282
|
+
f = Math.sin(M) * Math.cos(D), v = Math.sin(M) * Math.sin(D), U = Math.cos(M);
|
|
283
283
|
}
|
|
284
284
|
let z;
|
|
285
|
-
this.config.randomSpeed ? z = (this.config.minSpeed || 0) + Math.random() * ((this.config.maxSpeed || 1) - (this.config.minSpeed || 0)) : z = this.config.particleSpeed, r[n] = this.config.overrideXVelocity ? this.config.xVelocity : f * z, r[n + 1] = this.config.overrideYVelocity ? this.config.yVelocity : v * z, r[n + 2] = this.config.overrideZVelocity ? this.config.zVelocity :
|
|
285
|
+
this.config.randomSpeed ? z = (this.config.minSpeed || 0) + Math.random() * ((this.config.maxSpeed || 1) - (this.config.minSpeed || 0)) : z = this.config.particleSpeed, r[n] = this.config.overrideXVelocity ? this.config.xVelocity : f * z, r[n + 1] = this.config.overrideYVelocity ? this.config.yVelocity : v * z, r[n + 2] = this.config.overrideZVelocity ? this.config.zVelocity : U * z, r[n + 3] = 0;
|
|
286
286
|
}
|
|
287
287
|
setParticleColor(t, e) {
|
|
288
288
|
if (this.config.randomColorEnabled && this.config.randomColors.length > 0) {
|
|
@@ -1854,7 +1854,7 @@ async function or(s) {
|
|
|
1854
1854
|
const f = c.indices;
|
|
1855
1855
|
if (f === void 0)
|
|
1856
1856
|
throw new Error("Mesh primitive missing indices");
|
|
1857
|
-
const v = Fi(a, o, f),
|
|
1857
|
+
const v = Fi(a, o, f), U = S.length / 3, z = v.length;
|
|
1858
1858
|
let D = null;
|
|
1859
1859
|
c.attributes.TEXCOORD_0 !== void 0 && (D = ti(a, o, c.attributes.TEXCOORD_0, 2, 5126));
|
|
1860
1860
|
let M = !1;
|
|
@@ -1874,7 +1874,7 @@ async function or(s) {
|
|
|
1874
1874
|
normals: b,
|
|
1875
1875
|
indices: v,
|
|
1876
1876
|
texCoords: D,
|
|
1877
|
-
vertexCount:
|
|
1877
|
+
vertexCount: U,
|
|
1878
1878
|
indexCount: z,
|
|
1879
1879
|
animationData: Z,
|
|
1880
1880
|
hasBaseColorTexture: M
|
|
@@ -2011,12 +2011,12 @@ function hr(s, t, e) {
|
|
|
2011
2011
|
const S = [];
|
|
2012
2012
|
let b = 0;
|
|
2013
2013
|
for (const f of d.channels) {
|
|
2014
|
-
const v = d.samplers[f.sampler],
|
|
2014
|
+
const v = d.samplers[f.sampler], U = fr(s, t, v.input), z = pr(s, t, v.output), D = U[U.length - 1];
|
|
2015
2015
|
D > b && (b = D), S.push({
|
|
2016
2016
|
targetNode: f.target.node,
|
|
2017
2017
|
targetPath: f.target.path,
|
|
2018
2018
|
interpolation: v.interpolation || "LINEAR",
|
|
2019
|
-
timestamps:
|
|
2019
|
+
timestamps: U,
|
|
2020
2020
|
values: z
|
|
2021
2021
|
});
|
|
2022
2022
|
}
|
|
@@ -2070,7 +2070,7 @@ async function Vi(s) {
|
|
|
2070
2070
|
return null;
|
|
2071
2071
|
if (!o)
|
|
2072
2072
|
throw new Error("GLB file missing BIN chunk (required for embedded textures)");
|
|
2073
|
-
const v = a.bufferViews[b.bufferView],
|
|
2073
|
+
const v = a.bufferViews[b.bufferView], U = v.byteOffset || 0, z = v.byteLength, D = o.slice(U, U + z);
|
|
2074
2074
|
return { imageBlob: new Blob([D], { type: f }), mimeType: f };
|
|
2075
2075
|
}
|
|
2076
2076
|
function mr(s, t, e, i) {
|
|
@@ -2088,8 +2088,8 @@ function yr(s, t, e, i) {
|
|
|
2088
2088
|
return i[0] = s[0] * l + n * t[0] * c, i[1] = s[1] * l + n * t[1] * c, i[2] = s[2] * l + n * t[2] * c, i[3] = s[3] * l + n * t[3] * c, i;
|
|
2089
2089
|
}
|
|
2090
2090
|
function gr(s, t) {
|
|
2091
|
-
const e = s[0], i = s[1], r = s[2], n = s[3], a = e + e, o = i + i, l = r + r, c = e * a, d = e * o, S = e * l, b = i * o, f = i * l, v = r * l,
|
|
2092
|
-
return M[0] = 1 - (b + v), M[1] = d + D, M[2] = S - z, M[3] = 0, M[4] = d - D, M[5] = 1 - (c + v), M[6] = f +
|
|
2091
|
+
const e = s[0], i = s[1], r = s[2], n = s[3], a = e + e, o = i + i, l = r + r, c = e * a, d = e * o, S = e * l, b = i * o, f = i * l, v = r * l, U = n * a, z = n * o, D = n * l, M = t || new Float32Array(16);
|
|
2092
|
+
return M[0] = 1 - (b + v), M[1] = d + D, M[2] = S - z, M[3] = 0, M[4] = d - D, M[5] = 1 - (c + v), M[6] = f + U, M[7] = 0, M[8] = S + z, M[9] = f - U, M[10] = 1 - (c + b), M[11] = 0, M[12] = 0, M[13] = 0, M[14] = 0, M[15] = 1, M;
|
|
2093
2093
|
}
|
|
2094
2094
|
const br = new Float32Array(16);
|
|
2095
2095
|
function Sr(s, t, e, i) {
|
|
@@ -2260,8 +2260,8 @@ class xr {
|
|
|
2260
2260
|
return this._extractValue(n, r.length - 1, o, i);
|
|
2261
2261
|
let l = 0, c = r.length - 1;
|
|
2262
2262
|
for (; c - l > 1; ) {
|
|
2263
|
-
const
|
|
2264
|
-
r[
|
|
2263
|
+
const U = Math.floor((l + c) / 2);
|
|
2264
|
+
r[U] <= e ? l = U : c = U;
|
|
2265
2265
|
}
|
|
2266
2266
|
const d = r[l], S = r[c], b = (e - d) / (S - d), f = this._extractValue(n, l, o, this._sV0), v = this._extractValue(n, c, o, this._sV1);
|
|
2267
2267
|
return a === "STEP" ? (i[0] = f[0], i[1] = f[1], i[2] = f[2], o === "rotation" && (i[3] = f[3]), i) : o === "rotation" ? yr(f, v, b, i) : mr(f, v, b, i);
|
|
@@ -2322,13 +2322,13 @@ class xr {
|
|
|
2322
2322
|
_applySkinning() {
|
|
2323
2323
|
const t = this.restPositions.length / 3, e = this.restPositions, i = this.restNormals, r = this.skinnedPositions, n = this.skinnedNormals, a = this.jointWeights, o = this.jointIndices, l = this.jointFinalMatrices;
|
|
2324
2324
|
for (let c = 0; c < t; c++) {
|
|
2325
|
-
const d = c * 3, S = c * 4, b = e[d], f = e[d + 1], v = e[d + 2],
|
|
2325
|
+
const d = c * 3, S = c * 4, b = e[d], f = e[d + 1], v = e[d + 2], U = i[d], z = i[d + 1], D = i[d + 2];
|
|
2326
2326
|
let M = 0, Z = 0, T = 0, G = 0, F = 0, H = 0;
|
|
2327
2327
|
for (let ne = 0; ne < 4; ne++) {
|
|
2328
2328
|
const re = a[S + ne];
|
|
2329
2329
|
if (re === 0) continue;
|
|
2330
2330
|
const q = l[o[S + ne]];
|
|
2331
|
-
M += (q[0] * b + q[4] * f + q[8] * v + q[12]) * re, Z += (q[1] * b + q[5] * f + q[9] * v + q[13]) * re, T += (q[2] * b + q[6] * f + q[10] * v + q[14]) * re, G += (q[0] *
|
|
2331
|
+
M += (q[0] * b + q[4] * f + q[8] * v + q[12]) * re, Z += (q[1] * b + q[5] * f + q[9] * v + q[13]) * re, T += (q[2] * b + q[6] * f + q[10] * v + q[14]) * re, G += (q[0] * U + q[4] * z + q[8] * D) * re, F += (q[1] * U + q[5] * z + q[9] * D) * re, H += (q[2] * U + q[6] * z + q[10] * D) * re;
|
|
2332
2332
|
}
|
|
2333
2333
|
const se = Math.sqrt(G * G + F * F + H * H);
|
|
2334
2334
|
se > 1e-4 && (n[d] = G / se, n[d + 1] = F / se, n[d + 2] = H / se), r[d] = M, r[d + 1] = Z, r[d + 2] = T;
|
|
@@ -2381,7 +2381,7 @@ function Pr(s, t, e, i) {
|
|
|
2381
2381
|
if (f <= 0) return 0;
|
|
2382
2382
|
if (f >= 1) return 1;
|
|
2383
2383
|
let v = f;
|
|
2384
|
-
for (let
|
|
2384
|
+
for (let U = 0; U < 8; U++) {
|
|
2385
2385
|
const z = d(v) - f;
|
|
2386
2386
|
if (Math.abs(z) < 1e-5) break;
|
|
2387
2387
|
const D = b(v);
|
|
@@ -3672,7 +3672,7 @@ function Ur(s, t, e, i = {}) {
|
|
|
3672
3672
|
code: Hs
|
|
3673
3673
|
}), v = s.createShaderModule({
|
|
3674
3674
|
code: Zs
|
|
3675
|
-
}),
|
|
3675
|
+
}), U = s.createShaderModule({
|
|
3676
3676
|
code: Ws
|
|
3677
3677
|
}), z = s.createShaderModule({
|
|
3678
3678
|
code: $s
|
|
@@ -3883,11 +3883,11 @@ function Ur(s, t, e, i = {}) {
|
|
|
3883
3883
|
}), se = s.createRenderPipeline({
|
|
3884
3884
|
layout: b,
|
|
3885
3885
|
vertex: {
|
|
3886
|
-
module:
|
|
3886
|
+
module: U,
|
|
3887
3887
|
entryPoint: "vs_main"
|
|
3888
3888
|
},
|
|
3889
3889
|
fragment: {
|
|
3890
|
-
module:
|
|
3890
|
+
module: U,
|
|
3891
3891
|
entryPoint: "fs_main",
|
|
3892
3892
|
targets: [{
|
|
3893
3893
|
format: Xe,
|
|
@@ -4227,7 +4227,7 @@ function si(s, t, e, i) {
|
|
|
4227
4227
|
resource: { buffer: o }
|
|
4228
4228
|
}
|
|
4229
4229
|
]
|
|
4230
|
-
}),
|
|
4230
|
+
}), U = s.createBindGroup({
|
|
4231
4231
|
layout: s.createBindGroupLayout({
|
|
4232
4232
|
entries: [
|
|
4233
4233
|
{
|
|
@@ -4318,7 +4318,7 @@ function si(s, t, e, i) {
|
|
|
4318
4318
|
particleBindGroup: b,
|
|
4319
4319
|
horizontalBlurBindGroup: f,
|
|
4320
4320
|
verticalBlurBindGroup: v,
|
|
4321
|
-
compositeBindGroup:
|
|
4321
|
+
compositeBindGroup: U,
|
|
4322
4322
|
directRenderBindGroup: z
|
|
4323
4323
|
};
|
|
4324
4324
|
}
|
|
@@ -4936,9 +4936,9 @@ async function Or(s, t = {}) {
|
|
|
4936
4936
|
let v = 0;
|
|
4937
4937
|
for (const G of n)
|
|
4938
4938
|
f.set(G, v), v += G.length;
|
|
4939
|
-
const
|
|
4939
|
+
const U = S.length + b, z = 20 + U + 8 + a, D = new ArrayBuffer(z), M = new DataView(D), Z = new Uint8Array(D);
|
|
4940
4940
|
let T = 0;
|
|
4941
|
-
M.setUint32(T, ai, !0), T += 4, M.setUint32(T, Ki, !0), T += 4, M.setUint32(T, z, !0), T += 4, M.setUint32(T,
|
|
4941
|
+
M.setUint32(T, ai, !0), T += 4, M.setUint32(T, Ki, !0), T += 4, M.setUint32(T, z, !0), T += 4, M.setUint32(T, U, !0), T += 4, M.setUint32(T, Qi, !0), T += 4, Z.set(S, T), T += S.length;
|
|
4942
4942
|
for (let G = 0; G < b; G++) Z[T++] = 32;
|
|
4943
4943
|
return M.setUint32(T, a, !0), T += 4, M.setUint32(T, es, !0), T += 4, Z.set(f, T), T += a, D;
|
|
4944
4944
|
}
|
|
@@ -5336,7 +5336,7 @@ async function Jr(s, t = {}) {
|
|
|
5336
5336
|
clear() {
|
|
5337
5337
|
this.systemBindGroups = {}, this.systemBloomHorizontalBindGroups = {}, this.secondHorizontalBindGroups = {}, this.systemBloomCompositeBindGroups = {}, this.combinedBloomCompositeBindGroups = {}, this.combinedInitialBindGroup = null, this.finalBindGroup = null, this.textureStates = {}, this.textureRefs = {};
|
|
5338
5338
|
}
|
|
5339
|
-
}, v = r.createBuffer({ size: 96, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }),
|
|
5339
|
+
}, v = r.createBuffer({ size: 96, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), U = r.createBuffer({ size: 208, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), z = r.createBuffer({ size: 32, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), D = r.createBuffer({ size: 32, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), M = r.createBuffer({ size: 64, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }), Z = St(r, new Uint16Array([0, 1, 2, 0, 2, 3]), GPUBufferUsage.INDEX), T = {}, G = () => St(r, new Float32Array([-0.5, -0.5, 0, 0.5, -0.5, 0, 0.5, 0.5, 0, -0.5, 0.5, 0]), GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST);
|
|
5340
5340
|
c.onSystemCreated = (u) => {
|
|
5341
5341
|
T[u] || (T[u] = G());
|
|
5342
5342
|
};
|
|
@@ -5464,8 +5464,8 @@ async function Jr(s, t = {}) {
|
|
|
5464
5464
|
g = !0, h = Math.max(3, y), P = [0, 0, 1];
|
|
5465
5465
|
const B = Math.max(3, Math.floor(u.polygonSides ?? 6)), x = u.polygonRadius ?? 2;
|
|
5466
5466
|
for (let R = 0; R < h; R++) {
|
|
5467
|
-
const m = R / h * B, w = Math.floor(m), E = m - w, N = w / B * pt, X = (w + 1) / B * pt, O = Math.cos(N) * x,
|
|
5468
|
-
ae[R] = O + (ye - O) * E, oe[R] =
|
|
5467
|
+
const m = R / h * B, w = Math.floor(m), E = m - w, N = w / B * pt, X = (w + 1) / B * pt, O = Math.cos(N) * x, A = Math.sin(N) * x, ye = Math.cos(X) * x, xe = Math.sin(X) * x;
|
|
5468
|
+
ae[R] = O + (ye - O) * E, oe[R] = A + (xe - A) * E, le[R] = 0;
|
|
5469
5469
|
}
|
|
5470
5470
|
} else
|
|
5471
5471
|
h = 0;
|
|
@@ -5491,7 +5491,7 @@ async function Jr(s, t = {}) {
|
|
|
5491
5491
|
N === "zigzag" ? he = I * Math.sign(Math.sin(Se) || 1) : N === "sine" ? he = I * Math.sin(Se) : N === "spiral" && (he = I * Math.sin(Se), me = I * Math.cos(Se)), ae[W] += ve * he + m * me, oe[W] += ue * he + w * me, le[W] += He * he + E * me;
|
|
5492
5492
|
}
|
|
5493
5493
|
}
|
|
5494
|
-
const X = g ? h : h - 1, O = y.bloomIntensity || 1,
|
|
5494
|
+
const X = g ? h : h - 1, O = y.bloomIntensity || 1, A = y.startColor ?? y.particleColor ?? [1, 1, 1], ye = y.endColor ?? A, xe = y.particleColor ?? A, Oe = y.randomColorEnabled && Array.isArray(y.randomColors) && y.randomColors.length > 0 ? y.randomColors[0] : null, fe = B * 0.5, _t = Math.max(B * 4, 1e-4), je = (y.shapeStrokeSpeed ?? 0) * Ve;
|
|
5495
5495
|
let it = 0;
|
|
5496
5496
|
for (let I = 0; I < X; I++) {
|
|
5497
5497
|
const K = g ? (I + 1) % h : I + 1;
|
|
@@ -5522,9 +5522,9 @@ async function Jr(s, t = {}) {
|
|
|
5522
5522
|
Q /= ce, J /= ce, te /= ce;
|
|
5523
5523
|
const be = g ? I / h : I / Math.max(1, h - 1), ve = g ? K / h : K / Math.max(1, h - 1), ue = qe * Mt + je, He = (qe + ce) * Mt + je;
|
|
5524
5524
|
let Me, Se, he, me, we, Be;
|
|
5525
|
-
Oe ? (Me = me = Oe[0], Se = we = Oe[1], he = Be = Oe[2]) : y.colorTransitionEnabled ? (Me =
|
|
5526
|
-
const Bt = Xt[I], gt = Nt[I], Le = Yt[I], ke = Xt[K], ze = Nt[K], Rt = Yt[K], Ot = Ie + Bt * fe, Lt = W + gt * fe, Tt = pe + Le * fe, Re = Ie - Bt * fe, Te = W - gt * fe, Ee = pe - Le * fe, st = ee + ke * fe, rt = ge + ze * fe, Et = $ + Rt * fe, Ze = ee - ke * fe, We = ge - ze * fe, $e = $ - Rt * fe, ft = (
|
|
5527
|
-
Ce[u++] =
|
|
5525
|
+
Oe ? (Me = me = Oe[0], Se = we = Oe[1], he = Be = Oe[2]) : y.colorTransitionEnabled ? (Me = A[0] + (ye[0] - A[0]) * be, Se = A[1] + (ye[1] - A[1]) * be, he = A[2] + (ye[2] - A[2]) * be, me = A[0] + (ye[0] - A[0]) * ve, we = A[1] + (ye[1] - A[1]) * ve, Be = A[2] + (ye[2] - A[2]) * ve) : (Me = me = xe[0], Se = we = xe[1], he = Be = xe[2]), Me = Math.min(1, Me * O), Se = Math.min(1, Se * O), he = Math.min(1, he * O), me = Math.min(1, me * O), we = Math.min(1, we * O), Be = Math.min(1, Be * O);
|
|
5526
|
+
const Bt = Xt[I], gt = Nt[I], Le = Yt[I], ke = Xt[K], ze = Nt[K], Rt = Yt[K], Ot = Ie + Bt * fe, Lt = W + gt * fe, Tt = pe + Le * fe, Re = Ie - Bt * fe, Te = W - gt * fe, Ee = pe - Le * fe, st = ee + ke * fe, rt = ge + ze * fe, Et = $ + Rt * fe, Ze = ee - ke * fe, We = ge - ze * fe, $e = $ - Rt * fe, ft = (C, k, de, Y, L, j, ie, Je, Ke) => {
|
|
5527
|
+
Ce[u++] = C, Ce[u++] = k, Ce[u++] = de, Ce[u++] = Y, Ce[u++] = L, Ce[u++] = j, Ce[u++] = ie, Ce[u++] = Je, Ce[u++] = Ke;
|
|
5528
5528
|
};
|
|
5529
5529
|
ft(Ot, Lt, Tt, Me, Se, he, x, ue, 0), ft(Re, Te, Ee, Me, Se, he, x, ue, 1), ft(st, rt, Et, me, we, Be, x, He, 0), ft(Re, Te, Ee, Me, Se, he, x, ue, 1), ft(Ze, We, $e, me, we, Be, x, He, 1), ft(st, rt, Et, me, we, Be, x, He, 0), qe += ce;
|
|
5530
5530
|
}
|
|
@@ -5541,7 +5541,7 @@ async function Jr(s, t = {}) {
|
|
|
5541
5541
|
h.readbackAndProcessParticles();
|
|
5542
5542
|
const _ = h.particleData, B = h.particleVelocities, x = h.activeParticles;
|
|
5543
5543
|
if (_ && B && x > 0) {
|
|
5544
|
-
const R = g.emissionTrailMode === "particles", m = u, w = g.emissionTrailDuration ?? 1, E = g.opacity ?? 1, N = g.particleSize ?? 0.5, X = g.bloomIntensity || 1, O = Math.max(1, Math.min(64, g.emissionTrailSegments ?? 8)),
|
|
5544
|
+
const R = g.emissionTrailMode === "particles", m = u, w = g.emissionTrailDuration ?? 1, E = g.opacity ?? 1, N = g.particleSize ?? 0.5, X = g.bloomIntensity || 1, O = Math.max(1, Math.min(64, g.emissionTrailSegments ?? 8)), A = g.emissionTrailShape || "straight", ye = g.followSystemTranslation ?? !0, xe = h._simPosition, Oe = ye && xe ? xe[0] : 0, fe = ye && xe ? xe[1] : 0, _t = ye && xe ? xe[2] : 0, je = h._simVelocity, it = je ? je[0] : 0, Qt = je ? je[1] : 0, Mt = je ? je[2] : 0, qe = oi(g.id), wt = !!(ye && qe && qe.hist && qe.hist.length > 1);
|
|
5545
5545
|
for (let ut = 0; ut < x; ut++) {
|
|
5546
5546
|
const Ue = ut * 8, dt = _[Ue], I = _[Ue + 1], K = _[Ue + 2], Ie = dt + Oe, W = I + fe, pe = K + _t;
|
|
5547
5547
|
let ee = _[Ue + 3], ge = _[Ue + 4], $ = _[Ue + 5];
|
|
@@ -5549,22 +5549,22 @@ async function Jr(s, t = {}) {
|
|
|
5549
5549
|
if (Q >= J || J <= 0) continue;
|
|
5550
5550
|
const te = Q / J;
|
|
5551
5551
|
if (g.colorTransitionEnabled) {
|
|
5552
|
-
const
|
|
5553
|
-
ee =
|
|
5552
|
+
const C = g.startColor ?? [1, 0, 0], k = g.endColor ?? [0, 0, 1];
|
|
5553
|
+
ee = C[0] + (k[0] - C[0]) * te, ge = C[1] + (k[1] - C[1]) * te, $ = C[2] + (k[2] - C[2]) * te;
|
|
5554
5554
|
}
|
|
5555
5555
|
ee = Math.min(1, ee * X), ge = Math.min(1, ge * X), $ = Math.min(1, $ * X);
|
|
5556
5556
|
let ce = N;
|
|
5557
5557
|
if (g.randomSize) {
|
|
5558
|
-
const
|
|
5558
|
+
const C = Math.sin(J * 54321.67) * 43758.5453 % 1, k = C < 0 ? C + 1 : C;
|
|
5559
5559
|
ce = (g.minSize ?? 0.1) + ((g.maxSize ?? 0.5) - (g.minSize ?? 0.1)) * k;
|
|
5560
5560
|
}
|
|
5561
5561
|
if (g.fadeSizeEnabled) {
|
|
5562
|
-
const
|
|
5563
|
-
ce *= 1 - Math.pow(te, 1 /
|
|
5562
|
+
const C = Math.max(0.01, Math.min(10, g.sizeLifetimeSpeed ?? 1));
|
|
5563
|
+
ce *= 1 - Math.pow(te, 1 / C);
|
|
5564
5564
|
}
|
|
5565
5565
|
if (g.increaseSizeEnabled) {
|
|
5566
|
-
const
|
|
5567
|
-
ce *= 1 + Math.pow(te, 1 /
|
|
5566
|
+
const C = Math.max(0.01, Math.min(10, g.sizeLifetimeSpeed ?? 1));
|
|
5567
|
+
ce *= 1 + Math.pow(te, 1 / C);
|
|
5568
5568
|
}
|
|
5569
5569
|
if (ce <= 0 || te > 0.9) continue;
|
|
5570
5570
|
const be = Math.min((0.9 - te) * (1 / 0.2), 1), ve = 0.75 * ce * us * be;
|
|
@@ -5575,15 +5575,15 @@ async function Jr(s, t = {}) {
|
|
|
5575
5575
|
const gt = 1 / Bt, Le = me * gt, ke = we * gt, ze = Be * gt, Rt = V.right[0], Ot = V.right[1], Lt = V.right[2];
|
|
5576
5576
|
let Tt = Rt * Le + Ot * ke + Lt * ze, Re = Rt - Tt * Le, Te = Ot - Tt * ke, Ee = Lt - Tt * ze, st = Math.sqrt(Re * Re + Te * Te + Ee * Ee);
|
|
5577
5577
|
if (st < 0.2) {
|
|
5578
|
-
const
|
|
5579
|
-
Re =
|
|
5578
|
+
const C = V.up[0], k = V.up[1], de = V.up[2], Y = C * Le + k * ke + de * ze;
|
|
5579
|
+
Re = C - Y * Le, Te = k - Y * ke, Ee = de - Y * ze, st = Math.sqrt(Re * Re + Te * Te + Ee * Ee) || 1;
|
|
5580
5580
|
}
|
|
5581
5581
|
Re /= st, Te /= st, Ee /= st;
|
|
5582
5582
|
const rt = Math.min(w, Q);
|
|
5583
5583
|
if (rt < 1e-3) continue;
|
|
5584
5584
|
const Et = g.gravityEnabled && g.gravityStrength || 0, Ze = _s, We = Ms, $e = ws;
|
|
5585
5585
|
if (g.orientToDirection && g.burstMode && wt) {
|
|
5586
|
-
const
|
|
5586
|
+
const C = h._emitSimRotY || 0, k = Bs, de = Rs, Y = Ts;
|
|
5587
5587
|
for (let L = 0; L <= O; L++) {
|
|
5588
5588
|
const j = li(qe, Ve - L / O * rt, Pi);
|
|
5589
5589
|
k[L] = j[0], de[L] = j[1], Y[L] = j[2];
|
|
@@ -5591,36 +5591,36 @@ async function Jr(s, t = {}) {
|
|
|
5591
5591
|
for (let L = 0; L <= O; L++) {
|
|
5592
5592
|
const j = L > 0 ? L - 1 : 0, ie = L < O ? L + 1 : O;
|
|
5593
5593
|
let Je = k[j] - k[ie], Ke = Y[j] - Y[ie];
|
|
5594
|
-
const nt = (Math.hypot(Je, Ke) > 1e-5 ? Math.atan2(Je, Ke) : Math.atan2(it, Mt)) -
|
|
5594
|
+
const nt = (Math.hypot(Je, Ke) > 1e-5 ? Math.atan2(Je, Ke) : Math.atan2(it, Mt)) - C, De = Math.cos(nt), Ge = Math.sin(nt), et = L / O * rt, ei = -0.5 * Et * et * et;
|
|
5595
5595
|
Ze[L] = De * dt + Ge * K + k[L], We[L] = I + ei + de[L], $e[L] = -Ge * dt + De * K + Y[L];
|
|
5596
5596
|
}
|
|
5597
|
-
} else for (let
|
|
5598
|
-
const k =
|
|
5597
|
+
} else for (let C = 0; C <= O; C++) {
|
|
5598
|
+
const k = C / O * rt, de = -0.5 * Et * k * k;
|
|
5599
5599
|
if (wt) {
|
|
5600
5600
|
const Y = li(qe, Ve - k, Pi);
|
|
5601
|
-
Ze[
|
|
5601
|
+
Ze[C] = dt - Me * k + Y[0], We[C] = I - Se * k + de + Y[1], $e[C] = K - he * k + Y[2];
|
|
5602
5602
|
} else
|
|
5603
|
-
Ze[
|
|
5603
|
+
Ze[C] = Ie - me * k, We[C] = W - we * k + de, $e[C] = pe - Be * k;
|
|
5604
5604
|
}
|
|
5605
|
-
if (
|
|
5606
|
-
const
|
|
5605
|
+
if (A !== "straight") {
|
|
5606
|
+
const C = g.emissionTrailShapeAmplitude ?? 0.1, k = g.emissionTrailShapeFrequency ?? 4, de = g.emissionTrailShapeSpeed ?? 0;
|
|
5607
5607
|
let Y = -ze, L = 0, j = Le, ie = Math.sqrt(Y * Y + j * j);
|
|
5608
5608
|
ie < 1e-6 && (Y = 0, L = ze, j = -ke, ie = Math.sqrt(Y * Y + L * L + j * j) || 1), Y /= ie, L /= ie, j /= ie;
|
|
5609
5609
|
const Je = ke * j - ze * L, Ke = ze * Y - Le * j, Qe = Le * L - ke * Y;
|
|
5610
5610
|
for (let Pe = 1; Pe <= O; Pe++) {
|
|
5611
5611
|
const nt = Pe / O * rt, De = 2 * Math.PI * k * (Ve - nt) + de * Ve;
|
|
5612
5612
|
let Ge = 0, et = 0;
|
|
5613
|
-
|
|
5613
|
+
A === "zigzag" ? Ge = C * Math.sign(Math.sin(De)) : A === "sine" ? Ge = C * Math.sin(De) : A === "spiral" && (Ge = C * Math.sin(De), et = C * Math.cos(De)), Ze[Pe] += Y * Ge + Je * et, We[Pe] += L * Ge + Ke * et, $e[Pe] += j * Ge + Qe * et;
|
|
5614
5614
|
}
|
|
5615
5615
|
}
|
|
5616
5616
|
if (R)
|
|
5617
|
-
for (let
|
|
5618
|
-
const k =
|
|
5617
|
+
for (let C = 1; C <= O && u < F; C++) {
|
|
5618
|
+
const k = C / O, de = Ze[C] - Oe, Y = We[C] - fe, L = $e[C] - _t, j = u * 8, ie = u * 4;
|
|
5619
5619
|
H[j] = de, H[j + 1] = Y, H[j + 2] = L, H[j + 3] = ee, H[j + 4] = ge, H[j + 5] = $, H[j + 6] = Q + (J - Q) * k, H[j + 7] = J, se[ie] = 0, se[ie + 1] = 0, se[ie + 2] = 0, se[ie + 3] = 0, ne[ie] = de, ne[ie + 1] = Y, ne[ie + 2] = L, ne[ie + 3] = 0, u++;
|
|
5620
5620
|
}
|
|
5621
5621
|
else
|
|
5622
|
-
for (let
|
|
5623
|
-
const k =
|
|
5622
|
+
for (let C = 0; C < O && !(p + 42 > Ye.length); C++) {
|
|
5623
|
+
const k = C / O, de = (C + 1) / O, Y = Ze[C], L = We[C], j = $e[C], ie = Ze[C + 1], Je = We[C + 1], Ke = $e[C + 1], Qe = ve * (1 - k), Pe = ve * (1 - de), nt = ue * (1 - k) * (1 - k), De = ue * (1 - de) * (1 - de), Ge = Y + Re * Qe, et = L + Te * Qe, ei = j + Ee * Qe, Ai = Y - Re * Qe, Ci = L - Te * Qe, Ui = j - Ee * Qe, Ii = ie + Re * Pe, zi = Je + Te * Pe, Di = Ke + Ee * Pe, Os = ie - Re * Pe, Ls = Je - Te * Pe, ks = Ke - Ee * Pe, bt = (Xs, Ns, Ys, js) => {
|
|
5624
5624
|
Ye[p++] = Xs, Ye[p++] = Ns, Ye[p++] = Ys, Ye[p++] = ee, Ye[p++] = ge, Ye[p++] = $, Ye[p++] = js;
|
|
5625
5625
|
};
|
|
5626
5626
|
bt(Ge, et, ei, nt), bt(Ai, Ci, Ui, nt), bt(Ii, zi, Di, De), bt(Ai, Ci, Ui, nt), bt(Os, Ls, ks, De), bt(Ii, zi, Di, De);
|
|
@@ -5867,7 +5867,7 @@ async function Jr(s, t = {}) {
|
|
|
5867
5867
|
ht = u(ot), Si = u(lt), Dt = u(ct), Pt = u(zt);
|
|
5868
5868
|
};
|
|
5869
5869
|
xi();
|
|
5870
|
-
const Zt = { uniformBuffer: v, appearanceUniformBuffer:
|
|
5870
|
+
const Zt = { uniformBuffer: v, appearanceUniformBuffer: U, horizontalBlurUniformBuffer: z, verticalBlurUniformBuffer: D, bloomIntensityBuffer: M };
|
|
5871
5871
|
let Gt = si(r, Fe, Zt, { sceneTexture: ot, bloomTexA: lt, bloomTexB: ct });
|
|
5872
5872
|
const V = {
|
|
5873
5873
|
mvp: new Float32Array(16),
|
|
@@ -5940,10 +5940,12 @@ async function Jr(s, t = {}) {
|
|
|
5940
5940
|
if (!(!E || E.historyOnly) && (w.hidden = !E.pos, E.pos)) {
|
|
5941
5941
|
let N = null;
|
|
5942
5942
|
if (E.orientToDirection && E.vel) {
|
|
5943
|
-
const
|
|
5944
|
-
Math.hypot(
|
|
5943
|
+
const O = E.vel[0], A = E.vel[2];
|
|
5944
|
+
Math.hypot(O, A) > 1e-4 && (N = [0, 0, Math.atan2(O, A)]);
|
|
5945
5945
|
}
|
|
5946
|
-
m.setSimulationTransform({ position: E.pos, velocity: E.vel, rotation: N }), m.updateAppearanceUniform()
|
|
5946
|
+
m.setSimulationTransform({ position: E.pos, velocity: E.vel, rotation: N }), m.updateAppearanceUniform();
|
|
5947
|
+
const X = m.activeParticles === 0 && !m.emitting;
|
|
5948
|
+
(E.justResumed || X) && m.spawnParticles();
|
|
5947
5949
|
}
|
|
5948
5950
|
}
|
|
5949
5951
|
for (const m of _e)
|
|
@@ -5973,11 +5975,11 @@ async function Jr(s, t = {}) {
|
|
|
5973
5975
|
layout: O,
|
|
5974
5976
|
entries: [{ binding: 0, resource: E() }]
|
|
5975
5977
|
}));
|
|
5976
|
-
const
|
|
5978
|
+
const A = h.beginRenderPass({
|
|
5977
5979
|
colorAttachments: [],
|
|
5978
5980
|
depthStencilAttachment: { view: Pt, depthClearValue: 1, depthLoadOp: "clear", depthStoreOp: "store" }
|
|
5979
5981
|
});
|
|
5980
|
-
|
|
5982
|
+
A.setPipeline(X), A.setBindGroup(0, yt.bindGroup), A.draw(3), A.end(), g = !0;
|
|
5981
5983
|
}
|
|
5982
5984
|
}
|
|
5983
5985
|
} catch {
|
|
@@ -6016,19 +6018,19 @@ async function Jr(s, t = {}) {
|
|
|
6016
6018
|
{ binding: 2, resource: { buffer: z } }
|
|
6017
6019
|
]
|
|
6018
6020
|
}));
|
|
6019
|
-
let
|
|
6020
|
-
|
|
6021
|
+
let A = h.beginRenderPass(m);
|
|
6022
|
+
A.setPipeline(It), A.setBindGroup(0, f.systemBloomHorizontalBindGroups[E]), A.draw(3), A.end(), A = h.beginRenderPass(w), A.setPipeline(It), A.setBindGroup(0, Gt.verticalBlurBindGroup), A.draw(3), A.end(), f.secondHorizontalBindGroups[E] || (f.secondHorizontalBindGroups[E] = r.createBindGroup({
|
|
6021
6023
|
layout: Ne.bloomBindGroupLayout,
|
|
6022
6024
|
entries: [
|
|
6023
6025
|
{ binding: 0, resource: Fe },
|
|
6024
6026
|
{ binding: 1, resource: Dt },
|
|
6025
6027
|
{ binding: 2, resource: { buffer: z } }
|
|
6026
6028
|
]
|
|
6027
|
-
})),
|
|
6029
|
+
})), A = h.beginRenderPass(m), A.setPipeline(It), A.setBindGroup(0, f.secondHorizontalBindGroups[E]), A.draw(3), A.end(), A = h.beginRenderPass(w), A.setPipeline(It), A.setBindGroup(0, Gt.verticalBlurBindGroup), A.draw(3), A.end();
|
|
6028
6030
|
const ye = `${E}#${N.premier.config.id}`, xe = b.getBloomCompositeTexture(E, a.width, a.height);
|
|
6029
|
-
|
|
6031
|
+
A = h.beginRenderPass({
|
|
6030
6032
|
colorAttachments: [{ view: xe.createView(), loadOp: "clear", storeOp: "store", clearValue: { r: 0, g: 0, b: 0, a: 0 } }]
|
|
6031
|
-
}),
|
|
6033
|
+
}), A.setPipeline(ms), f.systemBloomCompositeBindGroups[ye] || (f.systemBloomCompositeBindGroups[ye] = r.createBindGroup({
|
|
6032
6034
|
layout: Ne.compositeBindGroupLayout,
|
|
6033
6035
|
entries: [
|
|
6034
6036
|
{ binding: 0, resource: Fe },
|
|
@@ -6039,7 +6041,7 @@ async function Jr(s, t = {}) {
|
|
|
6039
6041
|
// écrit par `particleSystem`, pas le tampon partagé qui ne porte que l'intensité.
|
|
6040
6042
|
{ binding: 3, resource: { buffer: N.premier.bloomIntensityBuffer } }
|
|
6041
6043
|
]
|
|
6042
|
-
})),
|
|
6044
|
+
})), A.setBindGroup(0, f.systemBloomCompositeBindGroups[ye]), A.draw(3), A.end();
|
|
6043
6045
|
}
|
|
6044
6046
|
}
|
|
6045
6047
|
const B = b.getCombinedTexture(a.width, a.height), x = h.beginRenderPass({
|
|
@@ -6118,7 +6120,7 @@ async function Jr(s, t = {}) {
|
|
|
6118
6120
|
function Ds() {
|
|
6119
6121
|
_i = !0, c.destroy(), [ot, lt, ct, zt].forEach((u) => u == null ? void 0 : u.destroy()), b.resizeTextures(), [
|
|
6120
6122
|
v,
|
|
6121
|
-
|
|
6123
|
+
U,
|
|
6122
6124
|
z,
|
|
6123
6125
|
D,
|
|
6124
6126
|
M,
|
|
@@ -6212,10 +6214,10 @@ function Kr(s) {
|
|
|
6212
6214
|
if (!c) return null;
|
|
6213
6215
|
const d = s.domElement.width, S = s.domElement.height, b = (typeof s._getFrameBufferTarget == "function" ? s._getFrameBufferTarget() : null) || s._frameBufferTarget || null;
|
|
6214
6216
|
if (s.needsFrameBufferTarget && b) {
|
|
6215
|
-
const
|
|
6216
|
-
(r =
|
|
6217
|
-
|
|
6218
|
-
(n =
|
|
6217
|
+
const U = c.get(b), z = ((i = (e = (t = s._textures) == null ? void 0 : t.get) == null ? void 0 : e.call(t, b)) == null ? void 0 : i.depthTexture) || b.depthTexture, D = [
|
|
6218
|
+
(r = U == null ? void 0 : U.depthTexture) == null ? void 0 : r.texture,
|
|
6219
|
+
U == null ? void 0 : U.depthTexture,
|
|
6220
|
+
(n = U == null ? void 0 : U.depthBuffer) == null ? void 0 : n.texture,
|
|
6219
6221
|
z ? (a = c.get(z)) == null ? void 0 : a.texture : null
|
|
6220
6222
|
];
|
|
6221
6223
|
for (const M of D)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hz-particles",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "High-performance WebGPU particle engine with compute shaders, GPU instancing, GLB model support, and skeletal animations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist-lib/hz-particles.cjs",
|