hz-particles 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Le=require("react/jsx-runtime"),r=require("react"),tt=require("@react-three/fiber"),cn=require("three"),At=require("hz-particles");function an(e){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const b=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(c,a,b.get?b:{enumerable:!0,get:()=>e[a]})}}return c.default=e,Object.freeze(c)}const o=an(cn);function Tt(e){return Math.abs(Math.sin(e*12.9898)*43758.5453)%1}function ln(e){const c=Math.sin(e*54321.67)*43758.5453%1;return c<0?c+1:c}function Pt(e,c,a,b){if(a<=0)return 0;const u=c/a;let O=e.particleSize??.5;if(e.randomSize){const C=e.minSize??.1,j=e.maxSize??.5;O=C+(j-C)*ln(a)}const k=Math.max(.01,Math.min(10,e.sizeLifetimeSpeed??1));if(e.fadeSizeEnabled&&(O*=1-Math.pow(u,1/k)),e.increaseSizeEnabled&&(O*=1+Math.pow(u,1/k)),e.pulseEnabled){const C=e.pulseAmplitude??.5,j=e.pulseFrequency??1,we=(e.pulsePhaseRandom??0)*Tt(b)*Math.PI*2;O*=1+C*Math.sin(c*j*Math.PI*2+we)}return Math.max(0,O)}function Rt(e,c,a,b){if(a<=0)return 0;let u=e.opacity??1;const O=c/a;if(e.fadeEnabled&&(u*=Math.max(0,1-O)),e.pulseEnabled&&e.pulseOpacity){const k=e.pulseAmplitude??.5,C=e.pulseFrequency??1,X=(e.pulsePhaseRandom??0)*Tt(b)*Math.PI*2;u*=Math.max(0,1+k*Math.sin(c*C*Math.PI*2+X))}return Math.max(0,Math.min(1,u))}function Yt(e,c){return c===1?e:{...e,systems:e.systems.map(a=>({...a,particleSize:(a.particleSize??.5)*c,minSize:a.minSize!=null?a.minSize*c:void 0,maxSize:a.maxSize!=null?a.maxSize*c:void 0,particleSpeed:(a.particleSpeed??1)*c,minSpeed:a.minSpeed!=null?a.minSpeed*c:void 0,maxSpeed:a.maxSpeed!=null?a.maxSpeed*c:void 0}))}}function un(e){let c=0;for(const a of e.systems)c+=a.maxParticles??1e4;return c}function dn({preset:e,position:c,positionRef:a,autoPlay:b=!0,visible:u=!0,scale:O=1,onComplete:k}){var oe;const[C,j]=r.useState(typeof e=="string"?null:e);r.useEffect(()=>{typeof e=="string"?(j(null),At.fetchPreset(e).then(j).catch(l=>{console.error("[HZParticlesFX] Failed to fetch preset:",l)})):j(e)},[e]);const{camera:X,gl:we}=tt.useThree(),Ie=r.useRef(null);if(!Ie.current){const l=(oe=we.backend)==null?void 0:oe.device;l&&(Ie.current=l)}const ce=Ie.current,Ae=r.useRef(null),ae=r.useRef(null),ke=r.useRef(!1),ye=r.useRef(!1),p=r.useMemo(()=>C?Yt(C,O):null,[C,O]),D=r.useMemo(()=>p?un(p):0,[p]),Ye=r.useMemo(()=>c?c instanceof o.Vector3?c.clone():new o.Vector3(...c):new o.Vector3(0,0,0),[c]),Fe=r.useMemo(()=>(p==null?void 0:p.systems.some(l=>l.emissionTrailEnabled))??!1,[p]),We=r.useMemo(()=>new o.PlaneGeometry(1,1),[]),Ue=r.useMemo(()=>{const l=document.createElement("canvas");l.width=64,l.height=64;const i=l.getContext("2d");i.clearRect(0,0,64,64);const m=i.createRadialGradient(32,32,0,32,32,32);m.addColorStop(0,"rgba(255,255,255,1)"),m.addColorStop(.7,"rgba(255,255,255,1)"),m.addColorStop(1,"rgba(255,255,255,0)"),i.fillStyle=m,i.beginPath(),i.arc(32,32,32,0,Math.PI*2),i.fill();const d=new o.CanvasTexture(l);d.flipY=!1;const U=new o.MeshBasicMaterial({color:16777215,transparent:!0,depthWrite:!1,alphaTest:.01,map:d,vertexColors:!0,side:o.DoubleSide,blending:o.AdditiveBlending});return U.needsUpdate=!0,U},[]),Y=8,t=2e3,T=r.useRef(null),v=512,I=r.useRef({buf:new Float32Array(v*4),head:0,count:0,elapsed:0}),{trailGeo:F,trailPosAttr:h,trailColAttr:ne}=r.useMemo(()=>{const l=t*Y*6,i=new Float32Array(l*3),m=new Float32Array(l*3),d=new o.BufferGeometry,U=new o.BufferAttribute(i,3);U.setUsage(o.DynamicDrawUsage),d.setAttribute("position",U);const de=new o.BufferAttribute(m,3);return de.setUsage(o.DynamicDrawUsage),d.setAttribute("color",de),d.setDrawRange(0,0),{trailGeo:d,trailPosAttr:U,trailColAttr:de}},[]),ie=r.useMemo(()=>new o.MeshBasicMaterial({vertexColors:!0,transparent:!0,depthWrite:!1,side:o.DoubleSide,blending:o.AdditiveBlending}),[]);r.useEffect(()=>{if(!ce||!p)return;const l=new At.ParticleSystemManager(ce);return ae.current=l,ye.current=!1,l.replaceSystems(p).then(()=>{b&&u&&(l.respawnAllSystems(),ye.current=!0)}).catch(i=>{console.error("[HZParticlesFX] replaceSystems FAILED:",i)}),()=>{typeof l.destroy=="function"&&l.destroy(),ae.current=null}},[ce,p]),r.useEffect(()=>{const l=ae.current;l&&b&&u&&!ye.current&&(l.respawnAllSystems(),ye.current=!0,ke.current=!1)},[b,u]);const f=r.useMemo(()=>new o.Matrix4,[]),z=r.useMemo(()=>new o.Vector3,[]),W=r.useMemo(()=>new o.Vector3,[]),le=r.useMemo(()=>new o.Quaternion,[]),se=r.useMemo(()=>new o.Vector3,[]),nt=r.useMemo(()=>new o.Vector3(0,0,1),[]),Pe=r.useMemo(()=>new o.Color,[]),ue=r.useRef(null);return tt.useFrame((l,i)=>{if(!u||!Ae.current||!ae.current)return;const m=ae.current,d=(a==null?void 0:a.current)??Ye,U=i>1?i/1e3:i,de=ue.current,st=de&&U>0,Wt=st?(d.x-de.x)/U:0,Nt=st?(d.y-de.y)/U:0,Qt=st?(d.z-de.z)/U:0;ue.current={x:d.x,y:d.y,z:d.z};for(const{system:n,config:s}of m.particleSystems)s.emissionTrailEnabled?(n.setSimulationTransform({position:[d.x,d.y,d.z],velocity:[Wt,Nt,Qt]}),s.shapeTranslationX=0,s.shapeTranslationY=0,s.shapeTranslationZ=0):(s.shapeTranslationX=d.x,s.shapeTranslationY=d.y,s.shapeTranslationZ=d.z);m.updateAllSystems(U);for(const{system:n}of m.particleSystems)n.readbackAndProcessParticles();if(Fe){const n=I.current;n.elapsed+=U;const s=n.head*4;n.buf[s]=d.x,n.buf[s+1]=d.y,n.buf[s+2]=d.z,n.buf[s+3]=n.elapsed,n.head=(n.head+1)%v,n.count<v&&n.count++}const Re=Ae.current;let Be=0;for(let n=0;n<m.particleSystems.length;n++){const{system:s,config:y}=m.particleSystems[n],B=s.particleData,fe=s.activeParticles;if(!B||fe<=0||y.emissionTrailEnabled)continue;const w=s._simPosition,Z=y.emissionTrailEnabled&&w?w[0]:0,Te=y.emissionTrailEnabled&&w?w[1]:0,Ne=y.emissionTrailEnabled&&w?w[2]:0;for(let pe=0;pe<fe;pe++){const V=pe*8,ot=B[V+0]+Z,rt=B[V+1]+Te,ct=B[V+2]+Ne;let H=B[V+3],me=B[V+4],he=B[V+5];const Me=B[V+6],N=B[V+7];if(Me>=N||N<=0)continue;const M=Me/N;if(y.colorTransitionEnabled){const A=y.startColor??[1,0,0],P=y.endColor??[0,0,1];H=A[0]+(P[0]-A[0])*M,me=A[1]+(P[1]-A[1])*M,he=A[2]+(P[2]-A[2])*M}const xe=y.bloomIntensity??1;H=Math.min(1,H*xe),me=Math.min(1,me*xe),he=Math.min(1,he*xe);const Se=Rt(y,Me,N,pe);H*=Se,me*=Se,he*=Se;const Q=Pt(y,Me,N,pe);if(!(Q<=0)){if(z.set(ot,rt,ct),W.subVectors(X.position,z).normalize(),le.setFromUnitVectors(nt,W),y.velocityStretchEnabled&&s.particleVelocities){const A=pe*4,P=s.particleVelocities[A],ge=s.particleVelocities[A+1],be=s.particleVelocities[A+2],Ve=Math.sqrt(P*P+ge*ge+be*be);if(Ve>.001){const Qe=y.velocityStretchFactor??1,Oe=Q*(1+Ve*Qe);se.set(Q,Oe,1),W.set(P,ge,be).normalize(),le.setFromUnitVectors(nt,W);const Je=(Oe-Q)*.5;z.addScaledVector(W,Je)}else se.set(Q,Q,1)}else se.set(Q,Q,1);f.compose(z,le,se),Re.setMatrixAt(Be,f),Pe.setRGB(H,me,he),Re.setColorAt(Be,Pe),Be++}}}Re.count=Be,Re.instanceMatrix.needsUpdate=!0,Re.instanceColor&&(Re.instanceColor.needsUpdate=!0);const Vt=Be>0||m.particleSystems.some(({system:n})=>n.emitting||n.activeParticles>0);if(ke.current&&!Vt&&(ye.current=!1,k==null||k()),ke.current=Vt,Fe&&T.current){const n=h.array,s=ne.array;let y=0;for(let B=0;B<m.particleSystems.length;B++){const{system:fe,config:w}=m.particleSystems[B];if(!w.emissionTrailEnabled||w.glbModelEnabled||w.textureEnabled)continue;const Z=fe.particleData,Te=fe.particleVelocities,Ne=fe.activeParticles;if(!Z||!Te||Ne<=0)continue;const pe=w.emissionTrailDuration??1,V=fe._simPosition,ot=V?V[0]:0,rt=V?V[1]:0,ct=V?V[2]:0,H=fe._simVelocity,me=H?H[0]:0,he=H?H[1]:0,Me=H?H[2]:0,N=I.current,M=N.buf,xe=N.count,Se=N.head,Q=N.elapsed;for(let A=0;A<Ne&&!(y+Y*6>t*Y*6);A++){const P=A*8,ge=Z[P],be=Z[P+1],Ve=Z[P+2],Qe=ge+ot,Oe=be+rt,Je=Ve+ct;let He=Z[P+3],_e=Z[P+4],qe=Z[P+5];const je=Z[P+6],Xe=Z[P+7];if(je>=Xe||Xe<=0)continue;const Ze=je/Xe;if(Ze>.9)continue;const Ct=Math.min((.9-Ze)*(1/.2),1);if(w.colorTransitionEnabled){const R=w.startColor??[1,0,0],x=w.endColor??[0,0,1];He=R[0]+(x[0]-R[0])*Ze,_e=R[1]+(x[1]-R[1])*Ze,qe=R[2]+(x[2]-R[2])*Ze}const at=w.bloomIntensity??1;He=Math.min(1,He*at),_e=Math.min(1,_e*at),qe=Math.min(1,qe*at);const Dt=Pt(w,je,Xe,A);if(Dt<=0)continue;const Et=Dt*.5*Ct,it=Rt(w,je,Xe,A)*Ct;if(it<.01)continue;const lt=A*4,Ke=Te[lt],$e=Te[lt+1],et=Te[lt+2],ut=Math.min(pe,je);if(ut<.001)continue;const It=xe>=2;if(!It){const R=Ke+me,x=$e+he,G=et+Me;if(Math.sqrt(R*R+x*x+G*G)<.001)continue}const Ft=(R,x)=>{const G=Q-R;for(let q=0;q<xe-1;q++){const L=((Se-1-q)%v+v)%v,E=((Se-2-q)%v+v)%v,J=M[L*4+3],K=M[E*4+3];if(G>=K&&G<=J){const re=J!==K?(G-K)/(J-K):0;x[0]=M[E*4]+(M[L*4]-M[E*4])*re,x[1]=M[E*4+1]+(M[L*4+1]-M[E*4+1])*re,x[2]=M[E*4+2]+(M[L*4+2]-M[E*4+2])*re;return}}const _=((Se-xe)%v+v)%v;x[0]=M[_*4],x[1]=M[_*4+1],x[2]=M[_*4+2]},Jt=X.position.x,Kt=X.position.y,$t=X.position.z;for(let R=0;R<Y;R++){const x=R/Y,G=(R+1)/Y,_=x*ut,q=G*ut;let L,E,J,K,re,Ge;if(It){const ve=[0,0,0],ze=[0,0,0];Ft(_,ve),Ft(q,ze),L=ge-Ke*_+ve[0],E=be-$e*_+ve[1],J=Ve-et*_+ve[2],K=ge-Ke*q+ze[0],re=be-$e*q+ze[1],Ge=Ve-et*q+ze[2]}else{const ve=Ke+me,ze=$e+he,kt=et+Me;L=Qe-ve*_,E=Oe-ze*_,J=Je-kt*_,K=Qe-ve*q,re=Oe-ze*q,Ge=Je-kt*q}const dt=K-L,ft=re-E,pt=Ge-J,Ut=Math.sqrt(dt*dt+ft*ft+pt*pt);if(Ut<1e-6)continue;const mt=1/Ut,ht=dt*mt,Bt=ft*mt,yt=pt*mt,Ot=Jt-L,Ht=Kt-E,_t=$t-J;let $=Bt*_t-yt*Ht,ee=yt*Ot-ht*_t,te=ht*Ht-Bt*Ot,Ce=Math.sqrt($*$+ee*ee+te*te);if(Ce<1e-6&&($=-yt,ee=0,te=ht,Ce=Math.sqrt($*$+ee*ee+te*te)),Ce<1e-6)continue;$/=Ce,ee/=Ce,te/=Ce;const De=Et*(1-x),Ee=Et*(1-G),Mt=it*(1-x)*(1-x),xt=it*(1-G)*(1-G),en=L+$*De,tn=E+ee*De,nn=J+te*De,qt=L-$*De,jt=E-ee*De,Xt=J-te*De,Zt=K+$*Ee,Gt=re+ee*Ee,Lt=Ge+te*Ee,sn=K-$*Ee,on=re-ee*Ee,rn=Ge-te*Ee,St=He*Mt,gt=_e*Mt,bt=qe*Mt,vt=He*xt,zt=_e*xt,wt=qe*xt,S=y*3,g=y*3;n[S]=en,n[S+1]=tn,n[S+2]=nn,s[g]=St,s[g+1]=gt,s[g+2]=bt,n[S+3]=qt,n[S+4]=jt,n[S+5]=Xt,s[g+3]=St,s[g+4]=gt,s[g+5]=bt,n[S+6]=Zt,n[S+7]=Gt,n[S+8]=Lt,s[g+6]=vt,s[g+7]=zt,s[g+8]=wt,n[S+9]=qt,n[S+10]=jt,n[S+11]=Xt,s[g+9]=St,s[g+10]=gt,s[g+11]=bt,n[S+12]=sn,n[S+13]=on,n[S+14]=rn,s[g+12]=vt,s[g+13]=zt,s[g+14]=wt,n[S+15]=Zt,n[S+16]=Gt,n[S+17]=Lt,s[g+15]=vt,s[g+16]=zt,s[g+17]=wt,y+=6}}}F.setDrawRange(0,y),h.needsUpdate=!0,ne.needsUpdate=!0}}),C?Le.jsxs(Le.Fragment,{children:[Le.jsx("instancedMesh",{ref:Ae,args:[We,Ue,D],frustumCulled:!1,renderOrder:100,visible:u}),Fe&&Le.jsx("mesh",{ref:T,geometry:F,material:ie,frustumCulled:!1,renderOrder:99,visible:u})]}):null}const fn=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Qe=require("react/jsx-runtime"),r=require("react"),at=require("@react-three/fiber"),fn=require("three"),It=require("hz-particles");function pn(e){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const a in e)if(a!=="default"){const b=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(c,a,b.get?b:{enumerable:!0,get:()=>e[a]})}}return c.default=e,Object.freeze(c)}const o=pn(fn);function Bt(e){return Math.abs(Math.sin(e*12.9898)*43758.5453)%1}function mn(e){const c=Math.sin(e*54321.67)*43758.5453%1;return c<0?c+1:c}function Ft(e,c,a,b){if(a<=0)return 0;const u=c/a;let H=e.particleSize??.5;if(e.randomSize){const C=e.minSize??.1,X=e.maxSize??.5;H=C+(X-C)*mn(a)}const Y=Math.max(.01,Math.min(10,e.sizeLifetimeSpeed??1));if(e.fadeSizeEnabled&&(H*=1-Math.pow(u,1/Y)),e.increaseSizeEnabled&&(H*=1+Math.pow(u,1/Y)),e.pulseEnabled){const C=e.pulseAmplitude??.5,X=e.pulseFrequency??1,Re=(e.pulsePhaseRandom??0)*Bt(b)*Math.PI*2;H*=1+C*Math.sin(c*X*Math.PI*2+Re)}return Math.max(0,H)}function Ut(e,c,a,b){if(a<=0)return 0;let u=e.opacity??1;const H=c/a;if(e.fadeEnabled&&(u*=Math.max(0,1-H)),e.pulseEnabled&&e.pulseOpacity){const Y=e.pulseAmplitude??.5,C=e.pulseFrequency??1,Z=(e.pulsePhaseRandom??0)*Bt(b)*Math.PI*2;u*=Math.max(0,1+Y*Math.sin(c*C*Math.PI*2+Z))}return Math.max(0,Math.min(1,u))}function Kt(e,c){return c===1?e:{...e,systems:e.systems.map(a=>({...a,particleSize:(a.particleSize??.5)*c,minSize:a.minSize!=null?a.minSize*c:void 0,maxSize:a.maxSize!=null?a.maxSize*c:void 0,particleSpeed:(a.particleSpeed??1)*c,minSpeed:a.minSpeed!=null?a.minSpeed*c:void 0,maxSpeed:a.maxSpeed!=null?a.maxSpeed*c:void 0}))}}function hn(e){let c=0;for(const a of e.systems)c+=a.maxParticles??1e4;return c}function yn({preset:e,position:c,positionRef:a,autoPlay:b=!0,visible:u=!0,scale:H=1,onComplete:Y}){var ne;const[C,X]=r.useState(typeof e=="string"?null:e);r.useEffect(()=>{typeof e=="string"?(X(null),It.fetchPreset(e).then(X).catch(l=>{console.error("[HZParticlesFX] Failed to fetch preset:",l)})):X(e)},[e]);const{camera:Z,gl:Re}=at.useThree(),qe=r.useRef(null);if(!qe.current){const l=(ne=Re.backend)==null?void 0:ne.device;l&&(qe.current=l)}const le=qe.current,Te=r.useRef(null),ue=r.useRef(null),Je=r.useRef(!1),be=r.useRef(!1),h=r.useMemo(()=>C?Kt(C,H):null,[C,H]),D=r.useMemo(()=>h?hn(h):0,[h]),Ke=r.useMemo(()=>c?c instanceof o.Vector3?c.clone():new o.Vector3(...c):new o.Vector3(0,0,0),[c]),je=r.useMemo(()=>(h==null?void 0:h.systems.some(l=>l.emissionTrailEnabled))??!1,[h]),$e=r.useMemo(()=>new o.PlaneGeometry(1,1),[]),Xe=r.useMemo(()=>{const l=document.createElement("canvas");l.width=64,l.height=64;const i=l.getContext("2d");i.clearRect(0,0,64,64);const y=i.createRadialGradient(32,32,0,32,32,32);y.addColorStop(0,"rgba(255,255,255,1)"),y.addColorStop(.7,"rgba(255,255,255,1)"),y.addColorStop(1,"rgba(255,255,255,0)"),i.fillStyle=y,i.beginPath(),i.arc(32,32,32,0,Math.PI*2),i.fill();const d=new o.CanvasTexture(l);d.flipY=!1;const F=new o.MeshBasicMaterial({color:16777215,transparent:!0,depthWrite:!1,alphaTest:.01,map:d,vertexColors:!0,side:o.DoubleSide,blending:o.AdditiveBlending});return F.needsUpdate=!0,F},[]),L=8,t=2e3,T=r.useRef(null),g=512,E=r.useRef({buf:new Float32Array(g*4),head:0,count:0,elapsed:0}),{trailGeo:I,trailPosAttr:M,trailColAttr:ee}=r.useMemo(()=>{const l=t*L*6,i=new Float32Array(l*3),y=new Float32Array(l*3),d=new o.BufferGeometry,F=new o.BufferAttribute(i,3);F.setUsage(o.DynamicDrawUsage),d.setAttribute("position",F);const me=new o.BufferAttribute(y,3);return me.setUsage(o.DynamicDrawUsage),d.setAttribute("color",me),d.setDrawRange(0,0),{trailGeo:d,trailPosAttr:F,trailColAttr:me}},[]),de=r.useMemo(()=>new o.MeshBasicMaterial({vertexColors:!0,transparent:!0,depthWrite:!1,side:o.DoubleSide,blending:o.AdditiveBlending}),[]);r.useEffect(()=>{if(!le||!h)return;const l=new It.ParticleSystemManager(le);return ue.current=l,be.current=!1,l.replaceSystems(h).then(()=>{b&&u&&(l.respawnAllSystems(),be.current=!0)}).catch(i=>{console.error("[HZParticlesFX] replaceSystems FAILED:",i)}),()=>{typeof l.destroy=="function"&&l.destroy(),ue.current=null}},[le,h]),r.useEffect(()=>{const l=ue.current;l&&b&&u&&!be.current&&(l.respawnAllSystems(),be.current=!0,Je.current=!1)},[b,u]);const p=r.useMemo(()=>new o.Matrix4,[]),z=r.useMemo(()=>new o.Vector3,[]),k=r.useMemo(()=>new o.Vector3,[]),fe=r.useMemo(()=>new o.Quaternion,[]),te=r.useMemo(()=>new o.Vector3,[]),it=r.useMemo(()=>new o.Vector3(0,0,1),[]),Ve=r.useMemo(()=>new o.Color,[]),pe=r.useRef(null);return at.useFrame((l,i)=>{if(!u||!Te.current||!ue.current)return;const y=ue.current,d=(a==null?void 0:a.current)??Ke,F=i>1?i/1e3:i,me=pe.current,lt=me&&F>0,$t=lt?(d.x-me.x)/F:0,en=lt?(d.y-me.y)/F:0,tn=lt?(d.z-me.z)/F:0;pe.current={x:d.x,y:d.y,z:d.z};for(const{system:n,config:s}of y.particleSystems)s.emissionTrailEnabled?(n.setSimulationTransform({position:[d.x,d.y,d.z],velocity:[$t,en,tn]}),s.shapeTranslationX=0,s.shapeTranslationY=0,s.shapeTranslationZ=0):(s.shapeTranslationX=d.x,s.shapeTranslationY=d.y,s.shapeTranslationZ=d.z);y.updateAllSystems(F);for(const{system:n}of y.particleSystems)n.readbackAndProcessParticles();if(je){const n=E.current;n.elapsed+=F;const s=n.head*4;n.buf[s]=d.x,n.buf[s+1]=d.y,n.buf[s+2]=d.z,n.buf[s+3]=n.elapsed,n.head=(n.head+1)%g,n.count<g&&n.count++}const Ce=Te.current;let Ze=0;for(let n=0;n<y.particleSystems.length;n++){const{system:s,config:w}=y.particleSystems[n],U=s.particleData,he=s.activeParticles;if(!U||he<=0)continue;const A=s._simPosition,G=w.emissionTrailEnabled&&A?A[0]:0,De=w.emissionTrailEnabled&&A?A[1]:0,et=w.emissionTrailEnabled&&A?A[2]:0;for(let ye=0;ye<he;ye++){const V=ye*8,ut=U[V+0]+G,dt=U[V+1]+De,ft=U[V+2]+et;let O=U[V+3],se=U[V+4],oe=U[V+5];const Me=U[V+6],W=U[V+7];if(Me>=W||W<=0)continue;const x=Me/W;if(w.colorTransitionEnabled){const P=w.startColor??[1,0,0],R=w.endColor??[0,0,1];O=P[0]+(R[0]-P[0])*x,se=P[1]+(R[1]-P[1])*x,oe=P[2]+(R[2]-P[2])*x}const ge=w.bloomIntensity??1;O=Math.min(1,O*ge),se=Math.min(1,se*ge),oe=Math.min(1,oe*ge);const ze=Ut(w,Me,W,ye);O*=ze,se*=ze,oe*=ze;const N=Ft(w,Me,W,ye);if(!(N<=0)){if(z.set(ut,dt,ft),k.subVectors(Z.position,z).normalize(),fe.setFromUnitVectors(it,k),w.velocityStretchEnabled&&s.particleVelocities){const P=ye*4,R=s.particleVelocities[P],re=s.particleVelocities[P+1],ce=s.particleVelocities[P+2],xe=Math.sqrt(R*R+re*re+ce*ce);if(xe>.001){const Ee=w.velocityStretchFactor??1,we=N*(1+xe*Ee);te.set(N,we,1),k.set(R,re,ce).normalize(),fe.setFromUnitVectors(it,k);const Ie=(we-N)*.5;z.addScaledVector(k,Ie)}else te.set(N,N,1)}else te.set(N,N,1);p.compose(z,fe,te),Ce.setMatrixAt(Ze,p),Ve.setRGB(O,se,oe),Ce.setColorAt(Ze,Ve),Ze++}}}Ce.count=Ze,Ce.instanceMatrix.needsUpdate=!0,Ce.instanceColor&&(Ce.instanceColor.needsUpdate=!0);const Ht=Ze>0||y.particleSystems.some(({system:n})=>n.emitting||n.activeParticles>0);if(Je.current&&!Ht&&(be.current=!1,Y==null||Y()),Je.current=Ht,je&&T.current){const n=M.array,s=ee.array;let w=0;for(let U=0;U<y.particleSystems.length;U++){const{system:he,config:A}=y.particleSystems[U];if(!A.emissionTrailEnabled||A.glbModelEnabled||A.textureEnabled)continue;const G=he.particleData,De=he.particleVelocities,et=he.activeParticles;if(!G||!De||et<=0)continue;const ye=A.emissionTrailDuration??1,V=he._simPosition,ut=V?V[0]:0,dt=V?V[1]:0,ft=V?V[2]:0,O=he._simVelocity,se=O?O[0]:0,oe=O?O[1]:0,Me=O?O[2]:0,W=E.current,x=W.buf,ge=W.count,ze=W.head,N=W.elapsed;for(let P=0;P<et&&!(w+L*6>t*L*6);P++){const R=P*8,re=G[R],ce=G[R+1],xe=G[R+2],Ee=re+ut,we=ce+dt,Ie=xe+ft;let Ge=G[R+3],Ye=G[R+4],Le=G[R+5];const ke=G[R+6],We=G[R+7];if(ke>=We||We<=0)continue;const Ne=ke/We;if(Ne>.9)continue;const Ot=Math.min((.9-Ne)*(1/.2),1);if(A.colorTransitionEnabled){const m=A.startColor??[1,0,0],f=A.endColor??[0,0,1];Ge=m[0]+(f[0]-m[0])*Ne,Ye=m[1]+(f[1]-m[1])*Ne,Le=m[2]+(f[2]-m[2])*Ne}const pt=A.bloomIntensity??1;Ge=Math.min(1,Ge*pt),Ye=Math.min(1,Ye*pt),Le=Math.min(1,Le*pt);const _t=Ft(A,ke,We,P);if(_t<=0)continue;const qt=_t*.5*Ot,mt=Ut(A,ke,We,P)*Ot;if(mt<.01)continue;const ht=P*4,Fe=De[ht],Ue=De[ht+1],Be=De[ht+2],Q=Math.min(ye,ke);if(Q<.001)continue;const yt=ge>=2;if(!yt){const m=Fe+se,f=Ue+oe,B=Be+Me;if(Math.sqrt(m*m+f*f+B*B)<.001)continue}const tt=(m,f)=>{const B=N-m;for(let q=0;q<ge-1;q++){const ae=((ze-1-q)%g+g)%g,j=((ze-2-q)%g+g)%g,Se=x[ae*4+3],ie=x[j*4+3];if(B>=ie&&B<=Se){const ve=Se!==ie?(B-ie)/(Se-ie):0;f[0]=x[j*4]+(x[ae*4]-x[j*4])*ve,f[1]=x[j*4+1]+(x[ae*4+1]-x[j*4+1])*ve,f[2]=x[j*4+2]+(x[ae*4+2]-x[j*4+2])*ve;return}}const _=((ze-ge)%g+g)%g;f[0]=x[_*4],f[1]=x[_*4+1],f[2]=x[_*4+2]},nn=Z.position.x,sn=Z.position.y,on=Z.position.z;let nt,st,ot,Mt,xt,St;if(yt){const m=[0,0,0],f=[0,0,0];tt(0,m),tt(Q,f),nt=re+m[0],st=ce+m[1],ot=xe+m[2],Mt=re-Fe*Q+f[0],xt=ce-Ue*Q+f[1],St=xe-Be*Q+f[2]}else{const m=Fe+se,f=Ue+oe,B=Be+Me;nt=Ee,st=we,ot=Ie,Mt=Ee-m*Q,xt=we-f*Q,St=Ie-B*Q}const vt=Mt-nt,bt=xt-st,gt=St-ot,rt=Math.sqrt(vt*vt+bt*bt+gt*gt);if(rt<1e-6)continue;const zt=vt/rt,jt=bt/rt,wt=gt/rt,Xt=nn-nt,Zt=sn-st,Gt=on-ot;let J=jt*Gt-wt*Zt,K=wt*Xt-zt*Gt,$=zt*Zt-jt*Xt,He=Math.sqrt(J*J+K*K+$*$);if(He<1e-6&&(J=-wt,K=0,$=zt,He=Math.sqrt(J*J+K*K+$*$)),!(He<1e-6)){J/=He,K/=He,$/=He;for(let m=0;m<L;m++){const f=m/L,B=(m+1)/L,_=f*Q,q=B*Q;let ae,j,Se,ie,ve,ct;if(yt){const Ae=[0,0,0],Pe=[0,0,0];tt(_,Ae),tt(q,Pe),ae=re-Fe*_+Ae[0],j=ce-Ue*_+Ae[1],Se=xe-Be*_+Ae[2],ie=re-Fe*q+Pe[0],ve=ce-Ue*q+Pe[1],ct=xe-Be*q+Pe[2]}else{const Ae=Fe+se,Pe=Ue+oe,Jt=Be+Me;ae=Ee-Ae*_,j=we-Pe*_,Se=Ie-Jt*_,ie=Ee-Ae*q,ve=we-Pe*q,ct=Ie-Jt*q}const Oe=qt*(1-f),_e=qt*(1-B),At=mt*(1-f)*(1-f),Pt=mt*(1-B)*(1-B),rn=ae+J*Oe,cn=j+K*Oe,an=Se+$*Oe,Yt=ae-J*Oe,Lt=j-K*Oe,kt=Se-$*Oe,Wt=ie+J*_e,Nt=ve+K*_e,Qt=ct+$*_e,ln=ie-J*_e,un=ve-K*_e,dn=ct-$*_e,Rt=Ge*At,Tt=Ye*At,Vt=Le*At,Ct=Ge*Pt,Dt=Ye*Pt,Et=Le*Pt,S=w*3,v=w*3;n[S]=rn,n[S+1]=cn,n[S+2]=an,s[v]=Rt,s[v+1]=Tt,s[v+2]=Vt,n[S+3]=Yt,n[S+4]=Lt,n[S+5]=kt,s[v+3]=Rt,s[v+4]=Tt,s[v+5]=Vt,n[S+6]=Wt,n[S+7]=Nt,n[S+8]=Qt,s[v+6]=Ct,s[v+7]=Dt,s[v+8]=Et,n[S+9]=Yt,n[S+10]=Lt,n[S+11]=kt,s[v+9]=Rt,s[v+10]=Tt,s[v+11]=Vt,n[S+12]=ln,n[S+13]=un,n[S+14]=dn,s[v+12]=Ct,s[v+13]=Dt,s[v+14]=Et,n[S+15]=Wt,n[S+16]=Nt,n[S+17]=Qt,s[v+15]=Ct,s[v+16]=Dt,s[v+17]=Et,w+=6}}}}I.setDrawRange(0,w),M.needsUpdate=!0,ee.needsUpdate=!0}}),C?Qe.jsxs(Qe.Fragment,{children:[Qe.jsx("instancedMesh",{ref:Te,args:[$e,Xe,D],frustumCulled:!1,renderOrder:100,visible:u}),je&&Qe.jsx("mesh",{ref:T,geometry:I,material:de,frustumCulled:!1,renderOrder:99,visible:u})]}):null}const Mn=`
2
2
  attribute vec4 aColor;
3
3
  varying vec4 vColor;
4
4
  void main() {
5
5
  vColor = aColor;
6
6
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
7
7
  }
8
- `,pn=`
8
+ `,xn=`
9
9
  varying vec4 vColor;
10
10
  void main() {
11
11
  gl_FragColor = vColor;
12
12
  }
13
- `;function mn({positionRef:e,duration:c=1,width:a=.3,color:b=[1,1,1],maxPoints:u=256,minDistance:O=.05,opacity:k=1,blending:C=o.AdditiveBlending,visible:j=!0}){const{camera:X}=tt.useThree(),we=r.useRef(null),Ie=r.useRef({positions:new Float32Array(u*3),times:new Float32Array(u),head:0,count:0,lastPos:new o.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:ce,posAttr:Ae,colorAttr:ae,indexBuf:ke}=r.useMemo(()=>{const Ue=u*2,Y=new Float32Array(Ue*3),t=new Float32Array(Ue*4),T=new o.BufferGeometry,v=new o.BufferAttribute(Y,3);v.setUsage(o.DynamicDrawUsage),T.setAttribute("position",v);const I=new o.BufferAttribute(t,4);I.setUsage(o.DynamicDrawUsage),T.setAttribute("aColor",I);const F=(u-1)*6,h=new Uint32Array(F);for(let ie=0;ie<u-1;ie++){const f=ie*2,z=ie*6;h[z]=f,h[z+1]=f+1,h[z+2]=f+2,h[z+3]=f+1,h[z+4]=f+3,h[z+5]=f+2}const ne=new o.BufferAttribute(h,1);return T.setIndex(ne),T.setDrawRange(0,0),{geometry:T,posAttr:v,colorAttr:I,indexBuf:ne}},[u]),ye=r.useMemo(()=>new o.ShaderMaterial({vertexShader:fn,fragmentShader:pn,transparent:!0,depthWrite:!1,side:o.DoubleSide,blending:C}),[C]),p=r.useMemo(()=>new o.Vector3,[]),D=r.useMemo(()=>new o.Vector3,[]),Ye=r.useMemo(()=>new o.Vector3,[]),Fe=r.useMemo(()=>new o.Vector3(0,1,0),[]),We=r.useMemo(()=>new o.Vector3,[]);return tt.useFrame((Ue,Y)=>{if(!we.current)return;const t=Ie.current;if(t.elapsed+=Y,!j){t.count=0,t.head=0,t.lastPos.set(1/0,1/0,1/0),ce.setDrawRange(0,0);return}const T=e.current;if(!T)return;if(t.lastPos.distanceTo(T)>=O){const f=(t.head+t.count)%u;t.positions[f*3]=T.x,t.positions[f*3+1]=T.y,t.positions[f*3+2]=T.z,t.times[f]=t.elapsed,t.count<u?t.count++:t.head=(t.head+1)%u,t.lastPos.copy(T)}for(;t.count>0;){const f=t.head;if(t.elapsed-t.times[f]>c)t.head=(t.head+1)%u,t.count--;else break}if(t.count<2){ce.setDrawRange(0,0);return}const I=Ae.array,F=ae.array;let h=null;const ne=t.count;for(let f=0;f<ne;f++){const z=(t.head+f)%u,W=t.positions[z*3],le=t.positions[z*3+1],se=t.positions[z*3+2],Pe=1-(t.elapsed-t.times[z])/c;if(f<ne-1){const m=(t.head+f+1)%u;p.set(t.positions[m*3]-W,t.positions[m*3+1]-le,t.positions[m*3+2]-se);const d=p.length();d>1e-6?p.divideScalar(d):h&&p.copy(h)}else h&&p.copy(h);Ye.set(X.position.x-W,X.position.y-le,X.position.z-se),D.crossVectors(p,Ye);let ue=D.length();ue<1e-6&&(We.crossVectors(p,Fe),D.copy(We),ue=D.length(),ue<1e-6&&(D.set(1,0,0),ue=1)),D.divideScalar(ue);const oe=a*Pe,l=k*Pe*Pe,i=f*2;I[i*3]=W+D.x*oe,I[i*3+1]=le+D.y*oe,I[i*3+2]=se+D.z*oe,I[(i+1)*3]=W-D.x*oe,I[(i+1)*3+1]=le-D.y*oe,I[(i+1)*3+2]=se-D.z*oe,F[i*4]=b[0],F[i*4+1]=b[1],F[i*4+2]=b[2],F[i*4+3]=l,F[(i+1)*4]=b[0],F[(i+1)*4+1]=b[1],F[(i+1)*4+2]=b[2],F[(i+1)*4+3]=l,h=h||new o.Vector3,h.copy(p)}const ie=(ne-1)*6;ce.setDrawRange(0,ie),Ae.needsUpdate=!0,ae.needsUpdate=!0}),Le.jsx("mesh",{ref:we,geometry:ce,material:ye,frustumCulled:!1,renderOrder:101,visible:j})}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>At.fetchPreset});exports.HZParticlesFX=dn;exports.HZTrailRibbon=mn;exports.computeParticleOpacity=Rt;exports.computeParticleSize=Pt;exports.particleHash=Tt;exports.scalePreset=Yt;
13
+ `;function Sn({positionRef:e,duration:c=1,width:a=.3,color:b=[1,1,1],maxPoints:u=256,minDistance:H=.05,opacity:Y=1,blending:C=o.AdditiveBlending,visible:X=!0}){const{camera:Z}=at.useThree(),Re=r.useRef(null),qe=r.useRef({positions:new Float32Array(u*3),times:new Float32Array(u),head:0,count:0,lastPos:new o.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:le,posAttr:Te,colorAttr:ue,indexBuf:Je}=r.useMemo(()=>{const Xe=u*2,L=new Float32Array(Xe*3),t=new Float32Array(Xe*4),T=new o.BufferGeometry,g=new o.BufferAttribute(L,3);g.setUsage(o.DynamicDrawUsage),T.setAttribute("position",g);const E=new o.BufferAttribute(t,4);E.setUsage(o.DynamicDrawUsage),T.setAttribute("aColor",E);const I=(u-1)*6,M=new Uint32Array(I);for(let de=0;de<u-1;de++){const p=de*2,z=de*6;M[z]=p,M[z+1]=p+1,M[z+2]=p+2,M[z+3]=p+1,M[z+4]=p+3,M[z+5]=p+2}const ee=new o.BufferAttribute(M,1);return T.setIndex(ee),T.setDrawRange(0,0),{geometry:T,posAttr:g,colorAttr:E,indexBuf:ee}},[u]),be=r.useMemo(()=>new o.ShaderMaterial({vertexShader:Mn,fragmentShader:xn,transparent:!0,depthWrite:!1,side:o.DoubleSide,blending:C}),[C]),h=r.useMemo(()=>new o.Vector3,[]),D=r.useMemo(()=>new o.Vector3,[]),Ke=r.useMemo(()=>new o.Vector3,[]),je=r.useMemo(()=>new o.Vector3(0,1,0),[]),$e=r.useMemo(()=>new o.Vector3,[]);return at.useFrame((Xe,L)=>{if(!Re.current)return;const t=qe.current;if(t.elapsed+=L,!X){t.count=0,t.head=0,t.lastPos.set(1/0,1/0,1/0),le.setDrawRange(0,0);return}const T=e.current;if(!T)return;if(t.lastPos.distanceTo(T)>=H){const p=(t.head+t.count)%u;t.positions[p*3]=T.x,t.positions[p*3+1]=T.y,t.positions[p*3+2]=T.z,t.times[p]=t.elapsed,t.count<u?t.count++:t.head=(t.head+1)%u,t.lastPos.copy(T)}for(;t.count>0;){const p=t.head;if(t.elapsed-t.times[p]>c)t.head=(t.head+1)%u,t.count--;else break}if(t.count<2){le.setDrawRange(0,0);return}const E=Te.array,I=ue.array;let M=null;const ee=t.count;for(let p=0;p<ee;p++){const z=(t.head+p)%u,k=t.positions[z*3],fe=t.positions[z*3+1],te=t.positions[z*3+2],Ve=1-(t.elapsed-t.times[z])/c;if(p<ee-1){const y=(t.head+p+1)%u;h.set(t.positions[y*3]-k,t.positions[y*3+1]-fe,t.positions[y*3+2]-te);const d=h.length();d>1e-6?h.divideScalar(d):M&&h.copy(M)}else M&&h.copy(M);Ke.set(Z.position.x-k,Z.position.y-fe,Z.position.z-te),D.crossVectors(h,Ke);let pe=D.length();pe<1e-6&&($e.crossVectors(h,je),D.copy($e),pe=D.length(),pe<1e-6&&(D.set(1,0,0),pe=1)),D.divideScalar(pe);const ne=a*Ve,l=Y*Ve*Ve,i=p*2;E[i*3]=k+D.x*ne,E[i*3+1]=fe+D.y*ne,E[i*3+2]=te+D.z*ne,E[(i+1)*3]=k-D.x*ne,E[(i+1)*3+1]=fe-D.y*ne,E[(i+1)*3+2]=te-D.z*ne,I[i*4]=b[0],I[i*4+1]=b[1],I[i*4+2]=b[2],I[i*4+3]=l,I[(i+1)*4]=b[0],I[(i+1)*4+1]=b[1],I[(i+1)*4+2]=b[2],I[(i+1)*4+3]=l,M=M||new o.Vector3,M.copy(h)}const de=(ee-1)*6;le.setDrawRange(0,de),Te.needsUpdate=!0,ue.needsUpdate=!0}),Qe.jsx("mesh",{ref:Re,geometry:le,material:be,frustumCulled:!1,renderOrder:101,visible:X})}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>It.fetchPreset});exports.HZParticlesFX=yn;exports.HZTrailRibbon=Sn;exports.computeParticleOpacity=Ut;exports.computeParticleSize=Ft;exports.particleHash=Bt;exports.scalePreset=Kt;
@@ -1,42 +1,42 @@
1
- import { jsxs as an, Fragment as ln, jsx as be } from "react/jsx-runtime";
2
- import { useState as un, useEffect as Me, useRef as nt, useMemo as d } from "react";
3
- import { useThree as ke, useFrame as We } from "@react-three/fiber";
1
+ import { jsxs as fn, Fragment as mn, jsx as Ee } from "react/jsx-runtime";
2
+ import { useState as hn, useEffect as Ie, useRef as tt, useMemo as m } from "react";
3
+ import { useThree as Je, useFrame as Ke } from "@react-three/fiber";
4
4
  import * as s from "three";
5
- import { fetchPreset as pn, ParticleSystemManager as dn } from "hz-particles";
6
- import { fetchPreset as Vn } from "hz-particles";
7
- function je(o) {
5
+ import { fetchPreset as yn, ParticleSystemManager as xn } from "hz-particles";
6
+ import { fetchPreset as Dn } from "hz-particles";
7
+ function $e(o) {
8
8
  return Math.abs(Math.sin(o * 12.9898) * 43758.5453) % 1;
9
9
  }
10
- function fn(o) {
10
+ function vn(o) {
11
11
  const r = Math.sin(o * 54321.67) * 43758.5453 % 1;
12
12
  return r < 0 ? r + 1 : r;
13
13
  }
14
- function Ze(o, r, i, R) {
14
+ function Qe(o, r, i, R) {
15
15
  if (i <= 0) return 0;
16
16
  const l = r / i;
17
- let _ = o.particleSize ?? 0.5;
17
+ let H = o.particleSize ?? 0.5;
18
18
  if (o.randomSize) {
19
19
  const T = o.minSize ?? 0.1, G = o.maxSize ?? 0.5;
20
- _ = T + (G - T) * fn(i);
20
+ H = T + (G - T) * vn(i);
21
21
  }
22
- const k = Math.max(0.01, Math.min(10, o.sizeLifetimeSpeed ?? 1));
23
- if (o.fadeSizeEnabled && (_ *= 1 - Math.pow(l, 1 / k)), o.increaseSizeEnabled && (_ *= 1 + Math.pow(l, 1 / k)), o.pulseEnabled) {
24
- const T = o.pulseAmplitude ?? 0.5, G = o.pulseFrequency ?? 1, bt = (o.pulsePhaseRandom ?? 0) * je(R) * Math.PI * 2;
25
- _ *= 1 + T * Math.sin(r * G * Math.PI * 2 + bt);
22
+ const L = Math.max(0.01, Math.min(10, o.sizeLifetimeSpeed ?? 1));
23
+ if (o.fadeSizeEnabled && (H *= 1 - Math.pow(l, 1 / L)), o.increaseSizeEnabled && (H *= 1 + Math.pow(l, 1 / L)), o.pulseEnabled) {
24
+ const T = o.pulseAmplitude ?? 0.5, G = o.pulseFrequency ?? 1, Ct = (o.pulsePhaseRandom ?? 0) * $e(R) * Math.PI * 2;
25
+ H *= 1 + T * Math.sin(r * G * Math.PI * 2 + Ct);
26
26
  }
27
- return Math.max(0, _);
27
+ return Math.max(0, H);
28
28
  }
29
- function Ye(o, r, i, R) {
29
+ function Ne(o, r, i, R) {
30
30
  if (i <= 0) return 0;
31
31
  let l = o.opacity ?? 1;
32
- const _ = r / i;
33
- if (o.fadeEnabled && (l *= Math.max(0, 1 - _)), o.pulseEnabled && o.pulseOpacity) {
34
- const k = o.pulseAmplitude ?? 0.5, T = o.pulseFrequency ?? 1, L = (o.pulsePhaseRandom ?? 0) * je(R) * Math.PI * 2;
35
- l *= Math.max(0, 1 + k * Math.sin(r * T * Math.PI * 2 + L));
32
+ const H = r / i;
33
+ if (o.fadeEnabled && (l *= Math.max(0, 1 - H)), o.pulseEnabled && o.pulseOpacity) {
34
+ const L = o.pulseAmplitude ?? 0.5, T = o.pulseFrequency ?? 1, O = (o.pulsePhaseRandom ?? 0) * $e(R) * Math.PI * 2;
35
+ l *= Math.max(0, 1 + L * Math.sin(r * T * Math.PI * 2 + O));
36
36
  }
37
37
  return Math.max(0, Math.min(1, l));
38
38
  }
39
- function mn(o, r) {
39
+ function Sn(o, r) {
40
40
  return r === 1 ? o : {
41
41
  ...o,
42
42
  systems: o.systems.map((i) => ({
@@ -50,54 +50,54 @@ function mn(o, r) {
50
50
  }))
51
51
  };
52
52
  }
53
- function hn(o) {
53
+ function zn(o) {
54
54
  let r = 0;
55
55
  for (const i of o.systems)
56
56
  r += i.maxParticles ?? 1e4;
57
57
  return r;
58
58
  }
59
- function zn({
59
+ function Pn({
60
60
  preset: o,
61
61
  position: r,
62
62
  positionRef: i,
63
63
  autoPlay: R = !0,
64
64
  visible: l = !0,
65
- scale: _ = 1,
66
- onComplete: k
65
+ scale: H = 1,
66
+ onComplete: L
67
67
  }) {
68
- var rt;
69
- const [T, G] = un(
68
+ var st;
69
+ const [T, G] = hn(
70
70
  typeof o == "string" ? null : o
71
71
  );
72
- Me(() => {
73
- typeof o == "string" ? (G(null), pn(o).then(G).catch((a) => {
72
+ Ie(() => {
73
+ typeof o == "string" ? (G(null), yn(o).then(G).catch((a) => {
74
74
  console.error("[HZParticlesFX] Failed to fetch preset:", a);
75
75
  })) : G(o);
76
76
  }, [o]);
77
- const { camera: L, gl: bt } = ke(), Ft = nt(null);
78
- if (!Ft.current) {
79
- const a = (rt = bt.backend) == null ? void 0 : rt.device;
80
- a && (Ft.current = a);
77
+ const { camera: O, gl: Ct } = Je(), qt = tt(null);
78
+ if (!qt.current) {
79
+ const a = (st = Ct.backend) == null ? void 0 : st.device;
80
+ a && (qt.current = a);
81
81
  }
82
- const at = Ft.current, Vt = nt(null), it = nt(null), kt = nt(!1), xt = nt(!1), f = d(
83
- () => T ? mn(T, _) : null,
84
- [T, _]
85
- ), D = d(
86
- () => f ? hn(f) : 0,
87
- [f]
88
- ), Wt = d(() => r ? r instanceof s.Vector3 ? r.clone() : new s.Vector3(...r) : new s.Vector3(0, 0, 0), [r]), Ut = d(
89
- () => (f == null ? void 0 : f.systems.some((a) => a.emissionTrailEnabled)) ?? !1,
90
- [f]
91
- ), jt = d(() => new s.PlaneGeometry(1, 1), []), Bt = d(() => {
82
+ const ut = qt.current, Rt = tt(null), dt = tt(null), Jt = tt(!1), gt = tt(!1), h = m(
83
+ () => T ? Sn(T, H) : null,
84
+ [T, H]
85
+ ), D = m(
86
+ () => h ? zn(h) : 0,
87
+ [h]
88
+ ), Kt = m(() => r ? r instanceof s.Vector3 ? r.clone() : new s.Vector3(...r) : new s.Vector3(0, 0, 0), [r]), Gt = m(
89
+ () => (h == null ? void 0 : h.systems.some((a) => a.emissionTrailEnabled)) ?? !1,
90
+ [h]
91
+ ), $t = m(() => new s.PlaneGeometry(1, 1), []), Ot = m(() => {
92
92
  const a = document.createElement("canvas");
93
93
  a.width = 64, a.height = 64;
94
94
  const c = a.getContext("2d");
95
95
  c.clearRect(0, 0, 64, 64);
96
- const m = c.createRadialGradient(32, 32, 0, 32, 32, 32);
97
- m.addColorStop(0, "rgba(255,255,255,1)"), m.addColorStop(0.7, "rgba(255,255,255,1)"), m.addColorStop(1, "rgba(255,255,255,0)"), c.fillStyle = m, c.beginPath(), c.arc(32, 32, 32, 0, Math.PI * 2), c.fill();
96
+ const y = c.createRadialGradient(32, 32, 0, 32, 32, 32);
97
+ y.addColorStop(0, "rgba(255,255,255,1)"), y.addColorStop(0.7, "rgba(255,255,255,1)"), y.addColorStop(1, "rgba(255,255,255,0)"), c.fillStyle = y, c.beginPath(), c.arc(32, 32, 32, 0, Math.PI * 2), c.fill();
98
98
  const u = new s.CanvasTexture(a);
99
99
  u.flipY = !1;
100
- const U = new s.MeshBasicMaterial({
100
+ const F = new s.MeshBasicMaterial({
101
101
  color: 16777215,
102
102
  transparent: !0,
103
103
  depthWrite: !1,
@@ -107,185 +107,194 @@ function zn({
107
107
  side: s.DoubleSide,
108
108
  blending: s.AdditiveBlending
109
109
  });
110
- return U.needsUpdate = !0, U;
111
- }, []), W = 8, t = 2e3, P = nt(null), w = 512, E = nt({
110
+ return F.needsUpdate = !0, F;
111
+ }, []), k = 8, t = 2e3, P = tt(null), w = 512, I = tt({
112
112
  buf: new Float32Array(w * 4),
113
113
  // x, y, z, time
114
114
  head: 0,
115
115
  count: 0,
116
116
  elapsed: 0
117
- }), { trailGeo: F, trailPosAttr: h, trailColAttr: st } = d(() => {
118
- const a = t * W * 6, c = new Float32Array(a * 3), m = new Float32Array(a * 3), u = new s.BufferGeometry(), U = new s.BufferAttribute(c, 3);
119
- U.setUsage(s.DynamicDrawUsage), u.setAttribute("position", U);
120
- const dt = new s.BufferAttribute(m, 3);
121
- return dt.setUsage(s.DynamicDrawUsage), u.setAttribute("color", dt), u.setDrawRange(0, 0), { trailGeo: u, trailPosAttr: U, trailColAttr: dt };
122
- }, []), lt = d(() => new s.MeshBasicMaterial({
117
+ }), { trailGeo: E, trailPosAttr: x, trailColAttr: et } = m(() => {
118
+ const a = t * k * 6, c = new Float32Array(a * 3), y = new Float32Array(a * 3), u = new s.BufferGeometry(), F = new s.BufferAttribute(c, 3);
119
+ F.setUsage(s.DynamicDrawUsage), u.setAttribute("position", F);
120
+ const ht = new s.BufferAttribute(y, 3);
121
+ return ht.setUsage(s.DynamicDrawUsage), u.setAttribute("color", ht), u.setDrawRange(0, 0), { trailGeo: u, trailPosAttr: F, trailColAttr: ht };
122
+ }, []), pt = m(() => new s.MeshBasicMaterial({
123
123
  vertexColors: !0,
124
124
  transparent: !0,
125
125
  depthWrite: !1,
126
126
  side: s.DoubleSide,
127
127
  blending: s.AdditiveBlending
128
128
  }), []);
129
- Me(() => {
130
- if (!at || !f)
129
+ Ie(() => {
130
+ if (!ut || !h)
131
131
  return;
132
- const a = new dn(at);
133
- return it.current = a, xt.current = !1, a.replaceSystems(f).then(() => {
134
- R && l && (a.respawnAllSystems(), xt.current = !0);
132
+ const a = new xn(ut);
133
+ return dt.current = a, gt.current = !1, a.replaceSystems(h).then(() => {
134
+ R && l && (a.respawnAllSystems(), gt.current = !0);
135
135
  }).catch((c) => {
136
136
  console.error("[HZParticlesFX] replaceSystems FAILED:", c);
137
137
  }), () => {
138
- typeof a.destroy == "function" && a.destroy(), it.current = null;
138
+ typeof a.destroy == "function" && a.destroy(), dt.current = null;
139
139
  };
140
- }, [at, f]), Me(() => {
141
- const a = it.current;
142
- a && R && l && !xt.current && (a.respawnAllSystems(), xt.current = !0, kt.current = !1);
140
+ }, [ut, h]), Ie(() => {
141
+ const a = dt.current;
142
+ a && R && l && !gt.current && (a.respawnAllSystems(), gt.current = !0, Jt.current = !1);
143
143
  }, [R, l]);
144
- const p = d(() => new s.Matrix4(), []), z = d(() => new s.Vector3(), []), j = d(() => new s.Vector3(), []), ut = d(() => new s.Quaternion(), []), ot = d(() => new s.Vector3(), []), ee = d(() => new s.Vector3(0, 0, 1), []), Pt = d(() => new s.Color(), []), pt = nt(null);
145
- return We((a, c) => {
146
- if (!l || !Vt.current || !it.current) return;
147
- const m = it.current, u = (i == null ? void 0 : i.current) ?? Wt, U = c > 1 ? c / 1e3 : c, dt = pt.current, ne = dt && U > 0, Qe = ne ? (u.x - dt.x) / U : 0, Ne = ne ? (u.y - dt.y) / U : 0, Je = ne ? (u.z - dt.z) / U : 0;
148
- pt.current = { x: u.x, y: u.y, z: u.z };
149
- for (const { system: e, config: n } of m.particleSystems)
144
+ const p = m(() => new s.Matrix4(), []), g = m(() => new s.Vector3(), []), W = m(() => new s.Vector3(), []), ft = m(() => new s.Quaternion(), []), nt = m(() => new s.Vector3(), []), ae = m(() => new s.Vector3(0, 0, 1), []), Tt = m(() => new s.Color(), []), mt = tt(null);
145
+ return Ke((a, c) => {
146
+ if (!l || !Rt.current || !dt.current) return;
147
+ const y = dt.current, u = (i == null ? void 0 : i.current) ?? Kt, F = c > 1 ? c / 1e3 : c, ht = mt.current, ie = ht && F > 0, tn = ie ? (u.x - ht.x) / F : 0, en = ie ? (u.y - ht.y) / F : 0, nn = ie ? (u.z - ht.z) / F : 0;
148
+ mt.current = { x: u.x, y: u.y, z: u.z };
149
+ for (const { system: e, config: n } of y.particleSystems)
150
150
  n.emissionTrailEnabled ? (e.setSimulationTransform({
151
151
  position: [u.x, u.y, u.z],
152
- velocity: [Qe, Ne, Je]
152
+ velocity: [tn, en, nn]
153
153
  }), n.shapeTranslationX = 0, n.shapeTranslationY = 0, n.shapeTranslationZ = 0) : (n.shapeTranslationX = u.x, n.shapeTranslationY = u.y, n.shapeTranslationZ = u.z);
154
- m.updateAllSystems(U);
155
- for (const { system: e } of m.particleSystems)
154
+ y.updateAllSystems(F);
155
+ for (const { system: e } of y.particleSystems)
156
156
  e.readbackAndProcessParticles();
157
- if (Ut) {
158
- const e = E.current;
159
- e.elapsed += U;
157
+ if (Gt) {
158
+ const e = I.current;
159
+ e.elapsed += F;
160
160
  const n = e.head * 4;
161
161
  e.buf[n] = u.x, e.buf[n + 1] = u.y, e.buf[n + 2] = u.z, e.buf[n + 3] = e.elapsed, e.head = (e.head + 1) % w, e.count < w && e.count++;
162
162
  }
163
- const Ct = Vt.current;
164
- let _t = 0;
165
- for (let e = 0; e < m.particleSystems.length; e++) {
166
- const { system: n, config: y } = m.particleSystems[e], B = n.particleData, ft = n.activeParticles;
167
- if (!B || ft <= 0 || y.emissionTrailEnabled) continue;
168
- const A = n._simPosition, O = y.emissionTrailEnabled && A ? A[0] : 0, Rt = y.emissionTrailEnabled && A ? A[1] : 0, Qt = y.emissionTrailEnabled && A ? A[2] : 0;
169
- for (let mt = 0; mt < ft; mt++) {
170
- const C = mt * 8, se = B[C + 0] + O, oe = B[C + 1] + Rt, re = B[C + 2] + Qt;
171
- let H = B[C + 3], ht = B[C + 4], yt = B[C + 5];
172
- const vt = B[C + 6], Q = B[C + 7];
173
- if (vt >= Q || Q <= 0) continue;
174
- const x = vt / Q;
175
- if (y.colorTransitionEnabled) {
176
- const M = y.startColor ?? [1, 0, 0], b = y.endColor ?? [0, 0, 1];
177
- H = M[0] + (b[0] - M[0]) * x, ht = M[1] + (b[1] - M[1]) * x, yt = M[2] + (b[2] - M[2]) * x;
163
+ const Dt = Rt.current;
164
+ let Yt = 0;
165
+ for (let e = 0; e < y.particleSystems.length; e++) {
166
+ const { system: n, config: A } = y.particleSystems[e], U = n.particleData, yt = n.activeParticles;
167
+ if (!U || yt <= 0) continue;
168
+ const M = n._simPosition, Y = A.emissionTrailEnabled && M ? M[0] : 0, It = A.emissionTrailEnabled && M ? M[1] : 0, te = A.emissionTrailEnabled && M ? M[2] : 0;
169
+ for (let xt = 0; xt < yt; xt++) {
170
+ const C = xt * 8, le = U[C + 0] + Y, ue = U[C + 1] + It, de = U[C + 2] + te;
171
+ let _ = U[C + 3], ot = U[C + 4], rt = U[C + 5];
172
+ const vt = U[C + 6], j = U[C + 7];
173
+ if (vt >= j || j <= 0) continue;
174
+ const v = vt / j;
175
+ if (A.colorTransitionEnabled) {
176
+ const b = A.startColor ?? [1, 0, 0], V = A.endColor ?? [0, 0, 1];
177
+ _ = b[0] + (V[0] - b[0]) * v, ot = b[1] + (V[1] - b[1]) * v, rt = b[2] + (V[2] - b[2]) * v;
178
178
  }
179
- const St = y.bloomIntensity ?? 1;
180
- H = Math.min(1, H * St), ht = Math.min(1, ht * St), yt = Math.min(1, yt * St);
181
- const gt = Ye(y, vt, Q, mt);
182
- H *= gt, ht *= gt, yt *= gt;
183
- const N = Ze(y, vt, Q, mt);
184
- if (!(N <= 0)) {
185
- if (z.set(se, oe, re), j.subVectors(L.position, z).normalize(), ut.setFromUnitVectors(ee, j), y.velocityStretchEnabled && n.particleVelocities) {
186
- const M = mt * 4, b = n.particleVelocities[M], wt = n.particleVelocities[M + 1], zt = n.particleVelocities[M + 2], Tt = Math.sqrt(b * b + wt * wt + zt * zt);
187
- if (Tt > 1e-3) {
188
- const Nt = y.velocityStretchFactor ?? 1, Ht = N * (1 + Tt * Nt);
189
- ot.set(N, Ht, 1), j.set(b, wt, zt).normalize(), ut.setFromUnitVectors(ee, j);
190
- const Jt = (Ht - N) * 0.5;
191
- z.addScaledVector(j, Jt);
179
+ const At = A.bloomIntensity ?? 1;
180
+ _ = Math.min(1, _ * At), ot = Math.min(1, ot * At), rt = Math.min(1, rt * At);
181
+ const Mt = Ne(A, vt, j, xt);
182
+ _ *= Mt, ot *= Mt, rt *= Mt;
183
+ const Q = Qe(A, vt, j, xt);
184
+ if (!(Q <= 0)) {
185
+ if (g.set(le, ue, de), W.subVectors(O.position, g).normalize(), ft.setFromUnitVectors(ae, W), A.velocityStretchEnabled && n.particleVelocities) {
186
+ const b = xt * 4, V = n.particleVelocities[b], ct = n.particleVelocities[b + 1], at = n.particleVelocities[b + 2], St = Math.sqrt(V * V + ct * ct + at * at);
187
+ if (St > 1e-3) {
188
+ const Et = A.velocityStretchFactor ?? 1, bt = Q * (1 + St * Et);
189
+ nt.set(Q, bt, 1), W.set(V, ct, at).normalize(), ft.setFromUnitVectors(ae, W);
190
+ const Ft = (bt - Q) * 0.5;
191
+ g.addScaledVector(W, Ft);
192
192
  } else
193
- ot.set(N, N, 1);
193
+ nt.set(Q, Q, 1);
194
194
  } else
195
- ot.set(N, N, 1);
196
- p.compose(z, ut, ot), Ct.setMatrixAt(_t, p), Pt.setRGB(H, ht, yt), Ct.setColorAt(_t, Pt), _t++;
195
+ nt.set(Q, Q, 1);
196
+ p.compose(g, ft, nt), Dt.setMatrixAt(Yt, p), Tt.setRGB(_, ot, rt), Dt.setColorAt(Yt, Tt), Yt++;
197
197
  }
198
198
  }
199
199
  }
200
- Ct.count = _t, Ct.instanceMatrix.needsUpdate = !0, Ct.instanceColor && (Ct.instanceColor.needsUpdate = !0);
201
- const Ve = _t > 0 || m.particleSystems.some(({ system: e }) => e.emitting || e.activeParticles > 0);
202
- if (kt.current && !Ve && (xt.current = !1, k == null || k()), kt.current = Ve, Ut && P.current) {
203
- const e = h.array, n = st.array;
204
- let y = 0;
205
- for (let B = 0; B < m.particleSystems.length; B++) {
206
- const { system: ft, config: A } = m.particleSystems[B];
207
- if (!A.emissionTrailEnabled || A.glbModelEnabled || A.textureEnabled) continue;
208
- const O = ft.particleData, Rt = ft.particleVelocities, Qt = ft.activeParticles;
209
- if (!O || !Rt || Qt <= 0) continue;
210
- const mt = A.emissionTrailDuration ?? 1, C = ft._simPosition, se = C ? C[0] : 0, oe = C ? C[1] : 0, re = C ? C[2] : 0, H = ft._simVelocity, ht = H ? H[0] : 0, yt = H ? H[1] : 0, vt = H ? H[2] : 0, Q = E.current, x = Q.buf, St = Q.count, gt = Q.head, N = Q.elapsed;
211
- for (let M = 0; M < Qt && !(y + W * 6 > t * W * 6); M++) {
212
- const b = M * 8, wt = O[b], zt = O[b + 1], Tt = O[b + 2], Nt = wt + se, Ht = zt + oe, Jt = Tt + re;
213
- let qt = O[b + 3], Xt = O[b + 4], Gt = O[b + 5];
214
- const Lt = O[b + 6], Ot = O[b + 7];
215
- if (Lt >= Ot || Ot <= 0) continue;
216
- const Zt = Lt / Ot;
217
- if (Zt > 0.9) continue;
218
- const Pe = Math.min((0.9 - Zt) * (1 / 0.2), 1);
219
- if (A.colorTransitionEnabled) {
220
- const V = A.startColor ?? [1, 0, 0], v = A.endColor ?? [0, 0, 1];
221
- qt = V[0] + (v[0] - V[0]) * Zt, Xt = V[1] + (v[1] - V[1]) * Zt, Gt = V[2] + (v[2] - V[2]) * Zt;
200
+ Dt.count = Yt, Dt.instanceMatrix.needsUpdate = !0, Dt.instanceColor && (Dt.instanceColor.needsUpdate = !0);
201
+ const Fe = Yt > 0 || y.particleSystems.some(({ system: e }) => e.emitting || e.activeParticles > 0);
202
+ if (Jt.current && !Fe && (gt.current = !1, L == null || L()), Jt.current = Fe, Gt && P.current) {
203
+ const e = x.array, n = et.array;
204
+ let A = 0;
205
+ for (let U = 0; U < y.particleSystems.length; U++) {
206
+ const { system: yt, config: M } = y.particleSystems[U];
207
+ if (!M.emissionTrailEnabled || M.glbModelEnabled || M.textureEnabled) continue;
208
+ const Y = yt.particleData, It = yt.particleVelocities, te = yt.activeParticles;
209
+ if (!Y || !It || te <= 0) continue;
210
+ const xt = M.emissionTrailDuration ?? 1, C = yt._simPosition, le = C ? C[0] : 0, ue = C ? C[1] : 0, de = C ? C[2] : 0, _ = yt._simVelocity, ot = _ ? _[0] : 0, rt = _ ? _[1] : 0, vt = _ ? _[2] : 0, j = I.current, v = j.buf, At = j.count, Mt = j.head, Q = j.elapsed;
211
+ for (let b = 0; b < te && !(A + k * 6 > t * k * 6); b++) {
212
+ const V = b * 8, ct = Y[V], at = Y[V + 1], St = Y[V + 2], Et = ct + le, bt = at + ue, Ft = St + de;
213
+ let Lt = Y[V + 3], kt = Y[V + 4], Wt = Y[V + 5];
214
+ const jt = Y[V + 6], Qt = Y[V + 7];
215
+ if (jt >= Qt || Qt <= 0) continue;
216
+ const Nt = jt / Qt;
217
+ if (Nt > 0.9) continue;
218
+ const Ue = Math.min((0.9 - Nt) * (1 / 0.2), 1);
219
+ if (M.colorTransitionEnabled) {
220
+ const f = M.startColor ?? [1, 0, 0], d = M.endColor ?? [0, 0, 1];
221
+ Lt = f[0] + (d[0] - f[0]) * Nt, kt = f[1] + (d[1] - f[1]) * Nt, Wt = f[2] + (d[2] - f[2]) * Nt;
222
222
  }
223
- const ce = A.bloomIntensity ?? 1;
224
- qt = Math.min(1, qt * ce), Xt = Math.min(1, Xt * ce), Gt = Math.min(1, Gt * ce);
225
- const Ce = Ze(A, Lt, Ot, M);
226
- if (Ce <= 0) continue;
227
- const Re = Ce * 0.5 * Pe, ae = Ye(A, Lt, Ot, M) * Pe;
228
- if (ae < 0.01) continue;
229
- const ie = M * 4, Kt = Rt[ie], $t = Rt[ie + 1], te = Rt[ie + 2], le = Math.min(mt, Lt);
230
- if (le < 1e-3) continue;
231
- const Te = St >= 2;
232
- if (!Te) {
233
- const V = Kt + ht, v = $t + yt, Z = te + vt;
234
- if (Math.sqrt(V * V + v * v + Z * Z) < 1e-3) continue;
223
+ const pe = M.bloomIntensity ?? 1;
224
+ Lt = Math.min(1, Lt * pe), kt = Math.min(1, kt * pe), Wt = Math.min(1, Wt * pe);
225
+ const Be = Qe(M, jt, Qt, b);
226
+ if (Be <= 0) continue;
227
+ const He = Be * 0.5 * Ue, fe = Ne(M, jt, Qt, b) * Ue;
228
+ if (fe < 0.01) continue;
229
+ const me = b * 4, Ut = It[me], Bt = It[me + 1], Ht = It[me + 2], N = Math.min(xt, jt);
230
+ if (N < 1e-3) continue;
231
+ const he = At >= 2;
232
+ if (!he) {
233
+ const f = Ut + ot, d = Bt + rt, B = Ht + vt;
234
+ if (Math.sqrt(f * f + d * d + B * B) < 1e-3) continue;
235
235
  }
236
- const De = (V, v) => {
237
- const Z = N - V;
238
- for (let X = 0; X < St - 1; X++) {
239
- const Y = ((gt - 1 - X) % w + w) % w, I = ((gt - 2 - X) % w + w) % w, J = x[Y * 4 + 3], K = x[I * 4 + 3];
240
- if (Z >= K && Z <= J) {
241
- const ct = J !== K ? (Z - K) / (J - K) : 0;
242
- v[0] = x[I * 4] + (x[Y * 4] - x[I * 4]) * ct, v[1] = x[I * 4 + 1] + (x[Y * 4 + 1] - x[I * 4 + 1]) * ct, v[2] = x[I * 4 + 2] + (x[Y * 4 + 2] - x[I * 4 + 2]) * ct;
236
+ const ee = (f, d) => {
237
+ const B = Q - f;
238
+ for (let Z = 0; Z < At - 1; Z++) {
239
+ const it = ((Mt - 1 - Z) % w + w) % w, q = ((Mt - 2 - Z) % w + w) % w, zt = v[it * 4 + 3], lt = v[q * 4 + 3];
240
+ if (B >= lt && B <= zt) {
241
+ const wt = zt !== lt ? (B - lt) / (zt - lt) : 0;
242
+ d[0] = v[q * 4] + (v[it * 4] - v[q * 4]) * wt, d[1] = v[q * 4 + 1] + (v[it * 4 + 1] - v[q * 4 + 1]) * wt, d[2] = v[q * 4 + 2] + (v[it * 4 + 2] - v[q * 4 + 2]) * wt;
243
243
  return;
244
244
  }
245
245
  }
246
- const q = ((gt - St) % w + w) % w;
247
- v[0] = x[q * 4], v[1] = x[q * 4 + 1], v[2] = x[q * 4 + 2];
248
- }, Ke = L.position.x, $e = L.position.y, tn = L.position.z;
249
- for (let V = 0; V < W; V++) {
250
- const v = V / W, Z = (V + 1) / W, q = v * le, X = Z * le;
251
- let Y, I, J, K, ct, Yt;
252
- if (Te) {
253
- const At = [0, 0, 0], Mt = [0, 0, 0];
254
- De(q, At), De(X, Mt), Y = wt - Kt * q + At[0], I = zt - $t * q + At[1], J = Tt - te * q + At[2], K = wt - Kt * X + Mt[0], ct = zt - $t * X + Mt[1], Yt = Tt - te * X + Mt[2];
255
- } else {
256
- const At = Kt + ht, Mt = $t + yt, Oe = te + vt;
257
- Y = Nt - At * q, I = Ht - Mt * q, J = Jt - Oe * q, K = Nt - At * X, ct = Ht - Mt * X, Yt = Jt - Oe * X;
246
+ const X = ((Mt - At) % w + w) % w;
247
+ d[0] = v[X * 4], d[1] = v[X * 4 + 1], d[2] = v[X * 4 + 2];
248
+ }, sn = O.position.x, on = O.position.y, rn = O.position.z;
249
+ let ne, se, oe, ye, xe, ve;
250
+ if (he) {
251
+ const f = [0, 0, 0], d = [0, 0, 0];
252
+ ee(0, f), ee(N, d), ne = ct + f[0], se = at + f[1], oe = St + f[2], ye = ct - Ut * N + d[0], xe = at - Bt * N + d[1], ve = St - Ht * N + d[2];
253
+ } else {
254
+ const f = Ut + ot, d = Bt + rt, B = Ht + vt;
255
+ ne = Et, se = bt, oe = Ft, ye = Et - f * N, xe = bt - d * N, ve = Ft - B * N;
256
+ }
257
+ const Se = ye - ne, ze = xe - se, we = ve - oe, re = Math.sqrt(Se * Se + ze * ze + we * we);
258
+ if (re < 1e-6) continue;
259
+ const ge = Se / re, _e = ze / re, Ae = we / re, Xe = sn - ne, Ze = on - se, qe = rn - oe;
260
+ let J = _e * qe - Ae * Ze, K = Ae * Xe - ge * qe, $ = ge * Ze - _e * Xe, _t = Math.sqrt(J * J + K * K + $ * $);
261
+ if (_t < 1e-6 && (J = -Ae, K = 0, $ = ge, _t = Math.sqrt(J * J + K * K + $ * $)), !(_t < 1e-6)) {
262
+ J /= _t, K /= _t, $ /= _t;
263
+ for (let f = 0; f < k; f++) {
264
+ const d = f / k, B = (f + 1) / k, X = d * N, Z = B * N;
265
+ let it, q, zt, lt, wt, ce;
266
+ if (he) {
267
+ const Vt = [0, 0, 0], Pt = [0, 0, 0];
268
+ ee(X, Vt), ee(Z, Pt), it = ct - Ut * X + Vt[0], q = at - Bt * X + Vt[1], zt = St - Ht * X + Vt[2], lt = ct - Ut * Z + Pt[0], wt = at - Bt * Z + Pt[1], ce = St - Ht * Z + Pt[2];
269
+ } else {
270
+ const Vt = Ut + ot, Pt = Bt + rt, je = Ht + vt;
271
+ it = Et - Vt * X, q = bt - Pt * X, zt = Ft - je * X, lt = Et - Vt * Z, wt = bt - Pt * Z, ce = Ft - je * Z;
272
+ }
273
+ const Xt = He * (1 - d), Zt = He * (1 - B), Me = fe * (1 - d) * (1 - d), be = fe * (1 - B) * (1 - B), cn = it + J * Xt, an = q + K * Xt, ln = zt + $ * Xt, Ge = it - J * Xt, Oe = q - K * Xt, Ye = zt - $ * Xt, Le = lt + J * Zt, ke = wt + K * Zt, We = ce + $ * Zt, un = lt - J * Zt, dn = wt - K * Zt, pn = ce - $ * Zt, Ve = Lt * Me, Pe = kt * Me, Ce = Wt * Me, Re = Lt * be, Te = kt * be, De = Wt * be, S = A * 3, z = A * 3;
274
+ e[S] = cn, e[S + 1] = an, e[S + 2] = ln, n[z] = Ve, n[z + 1] = Pe, n[z + 2] = Ce, e[S + 3] = Ge, e[S + 4] = Oe, e[S + 5] = Ye, n[z + 3] = Ve, n[z + 4] = Pe, n[z + 5] = Ce, e[S + 6] = Le, e[S + 7] = ke, e[S + 8] = We, n[z + 6] = Re, n[z + 7] = Te, n[z + 8] = De, e[S + 9] = Ge, e[S + 10] = Oe, e[S + 11] = Ye, n[z + 9] = Ve, n[z + 10] = Pe, n[z + 11] = Ce, e[S + 12] = un, e[S + 13] = dn, e[S + 14] = pn, n[z + 12] = Re, n[z + 13] = Te, n[z + 14] = De, e[S + 15] = Le, e[S + 16] = ke, e[S + 17] = We, n[z + 15] = Re, n[z + 16] = Te, n[z + 17] = De, A += 6;
258
275
  }
259
- const ue = K - Y, pe = ct - I, de = Yt - J, Ie = Math.sqrt(ue * ue + pe * pe + de * de);
260
- if (Ie < 1e-6) continue;
261
- const fe = 1 / Ie, me = ue * fe, Ee = pe * fe, he = de * fe, Fe = Ke - Y, Ue = $e - I, Be = tn - J;
262
- let $ = Ee * Be - he * Ue, tt = he * Fe - me * Be, et = me * Ue - Ee * Fe, Dt = Math.sqrt($ * $ + tt * tt + et * et);
263
- if (Dt < 1e-6 && ($ = -he, tt = 0, et = me, Dt = Math.sqrt($ * $ + tt * tt + et * et)), Dt < 1e-6) continue;
264
- $ /= Dt, tt /= Dt, et /= Dt;
265
- const It = Re * (1 - v), Et = Re * (1 - Z), ye = ae * (1 - v) * (1 - v), xe = ae * (1 - Z) * (1 - Z), en = Y + $ * It, nn = I + tt * It, sn = J + et * It, _e = Y - $ * It, He = I - tt * It, qe = J - et * It, Xe = K + $ * Et, Ge = ct + tt * Et, Le = Yt + et * Et, on = K - $ * Et, rn = ct - tt * Et, cn = Yt - et * Et, ve = qt * ye, Se = Xt * ye, ge = Gt * ye, we = qt * xe, ze = Xt * xe, Ae = Gt * xe, S = y * 3, g = y * 3;
266
- e[S] = en, e[S + 1] = nn, e[S + 2] = sn, n[g] = ve, n[g + 1] = Se, n[g + 2] = ge, e[S + 3] = _e, e[S + 4] = He, e[S + 5] = qe, n[g + 3] = ve, n[g + 4] = Se, n[g + 5] = ge, e[S + 6] = Xe, e[S + 7] = Ge, e[S + 8] = Le, n[g + 6] = we, n[g + 7] = ze, n[g + 8] = Ae, e[S + 9] = _e, e[S + 10] = He, e[S + 11] = qe, n[g + 9] = ve, n[g + 10] = Se, n[g + 11] = ge, e[S + 12] = on, e[S + 13] = rn, e[S + 14] = cn, n[g + 12] = we, n[g + 13] = ze, n[g + 14] = Ae, e[S + 15] = Xe, e[S + 16] = Ge, e[S + 17] = Le, n[g + 15] = we, n[g + 16] = ze, n[g + 17] = Ae, y += 6;
267
276
  }
268
277
  }
269
278
  }
270
- F.setDrawRange(0, y), h.needsUpdate = !0, st.needsUpdate = !0;
279
+ E.setDrawRange(0, A), x.needsUpdate = !0, et.needsUpdate = !0;
271
280
  }
272
- }), T ? /* @__PURE__ */ an(ln, { children: [
273
- /* @__PURE__ */ be(
281
+ }), T ? /* @__PURE__ */ fn(mn, { children: [
282
+ /* @__PURE__ */ Ee(
274
283
  "instancedMesh",
275
284
  {
276
- ref: Vt,
277
- args: [jt, Bt, D],
285
+ ref: Rt,
286
+ args: [$t, Ot, D],
278
287
  frustumCulled: !1,
279
288
  renderOrder: 100,
280
289
  visible: l
281
290
  }
282
291
  ),
283
- Ut && /* @__PURE__ */ be(
292
+ Gt && /* @__PURE__ */ Ee(
284
293
  "mesh",
285
294
  {
286
295
  ref: P,
287
- geometry: F,
288
- material: lt,
296
+ geometry: E,
297
+ material: pt,
289
298
  frustumCulled: !1,
290
299
  renderOrder: 99,
291
300
  visible: l
@@ -293,7 +302,7 @@ function zn({
293
302
  )
294
303
  ] }) : null;
295
304
  }
296
- const yn = (
305
+ const wn = (
297
306
  /* glsl */
298
307
  `
299
308
  attribute vec4 aColor;
@@ -303,7 +312,7 @@ void main() {
303
312
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
304
313
  }
305
314
  `
306
- ), xn = (
315
+ ), gn = (
307
316
  /* glsl */
308
317
  `
309
318
  varying vec4 vColor;
@@ -312,54 +321,54 @@ void main() {
312
321
  }
313
322
  `
314
323
  );
315
- function An({
324
+ function Cn({
316
325
  positionRef: o,
317
326
  duration: r = 1,
318
327
  width: i = 0.3,
319
328
  color: R = [1, 1, 1],
320
329
  maxPoints: l = 256,
321
- minDistance: _ = 0.05,
322
- opacity: k = 1,
330
+ minDistance: H = 0.05,
331
+ opacity: L = 1,
323
332
  blending: T = s.AdditiveBlending,
324
333
  visible: G = !0
325
334
  }) {
326
- const { camera: L } = ke(), bt = nt(null), Ft = nt({
335
+ const { camera: O } = Je(), Ct = tt(null), qt = tt({
327
336
  positions: new Float32Array(l * 3),
328
337
  times: new Float32Array(l),
329
338
  head: 0,
330
339
  count: 0,
331
340
  lastPos: new s.Vector3(1 / 0, 1 / 0, 1 / 0),
332
341
  elapsed: 0
333
- }), { geometry: at, posAttr: Vt, colorAttr: it, indexBuf: kt } = d(() => {
334
- const Bt = l * 2, W = new Float32Array(Bt * 3), t = new Float32Array(Bt * 4), P = new s.BufferGeometry(), w = new s.BufferAttribute(W, 3);
342
+ }), { geometry: ut, posAttr: Rt, colorAttr: dt, indexBuf: Jt } = m(() => {
343
+ const Ot = l * 2, k = new Float32Array(Ot * 3), t = new Float32Array(Ot * 4), P = new s.BufferGeometry(), w = new s.BufferAttribute(k, 3);
335
344
  w.setUsage(s.DynamicDrawUsage), P.setAttribute("position", w);
336
- const E = new s.BufferAttribute(t, 4);
337
- E.setUsage(s.DynamicDrawUsage), P.setAttribute("aColor", E);
338
- const F = (l - 1) * 6, h = new Uint32Array(F);
339
- for (let lt = 0; lt < l - 1; lt++) {
340
- const p = lt * 2, z = lt * 6;
341
- h[z] = p, h[z + 1] = p + 1, h[z + 2] = p + 2, h[z + 3] = p + 1, h[z + 4] = p + 3, h[z + 5] = p + 2;
345
+ const I = new s.BufferAttribute(t, 4);
346
+ I.setUsage(s.DynamicDrawUsage), P.setAttribute("aColor", I);
347
+ const E = (l - 1) * 6, x = new Uint32Array(E);
348
+ for (let pt = 0; pt < l - 1; pt++) {
349
+ const p = pt * 2, g = pt * 6;
350
+ x[g] = p, x[g + 1] = p + 1, x[g + 2] = p + 2, x[g + 3] = p + 1, x[g + 4] = p + 3, x[g + 5] = p + 2;
342
351
  }
343
- const st = new s.BufferAttribute(h, 1);
344
- return P.setIndex(st), P.setDrawRange(0, 0), { geometry: P, posAttr: w, colorAttr: E, indexBuf: st };
345
- }, [l]), xt = d(() => new s.ShaderMaterial({
346
- vertexShader: yn,
347
- fragmentShader: xn,
352
+ const et = new s.BufferAttribute(x, 1);
353
+ return P.setIndex(et), P.setDrawRange(0, 0), { geometry: P, posAttr: w, colorAttr: I, indexBuf: et };
354
+ }, [l]), gt = m(() => new s.ShaderMaterial({
355
+ vertexShader: wn,
356
+ fragmentShader: gn,
348
357
  transparent: !0,
349
358
  depthWrite: !1,
350
359
  side: s.DoubleSide,
351
360
  blending: T
352
- }), [T]), f = d(() => new s.Vector3(), []), D = d(() => new s.Vector3(), []), Wt = d(() => new s.Vector3(), []), Ut = d(() => new s.Vector3(0, 1, 0), []), jt = d(() => new s.Vector3(), []);
353
- return We((Bt, W) => {
354
- if (!bt.current) return;
355
- const t = Ft.current;
356
- if (t.elapsed += W, !G) {
357
- t.count = 0, t.head = 0, t.lastPos.set(1 / 0, 1 / 0, 1 / 0), at.setDrawRange(0, 0);
361
+ }), [T]), h = m(() => new s.Vector3(), []), D = m(() => new s.Vector3(), []), Kt = m(() => new s.Vector3(), []), Gt = m(() => new s.Vector3(0, 1, 0), []), $t = m(() => new s.Vector3(), []);
362
+ return Ke((Ot, k) => {
363
+ if (!Ct.current) return;
364
+ const t = qt.current;
365
+ if (t.elapsed += k, !G) {
366
+ t.count = 0, t.head = 0, t.lastPos.set(1 / 0, 1 / 0, 1 / 0), ut.setDrawRange(0, 0);
358
367
  return;
359
368
  }
360
369
  const P = o.current;
361
370
  if (!P) return;
362
- if (t.lastPos.distanceTo(P) >= _) {
371
+ if (t.lastPos.distanceTo(P) >= H) {
363
372
  const p = (t.head + t.count) % l;
364
373
  t.positions[p * 3] = P.x, t.positions[p * 3 + 1] = P.y, t.positions[p * 3 + 2] = P.z, t.times[p] = t.elapsed, t.count < l ? t.count++ : t.head = (t.head + 1) % l, t.lastPos.copy(P);
365
374
  }
@@ -371,42 +380,42 @@ function An({
371
380
  break;
372
381
  }
373
382
  if (t.count < 2) {
374
- at.setDrawRange(0, 0);
383
+ ut.setDrawRange(0, 0);
375
384
  return;
376
385
  }
377
- const E = Vt.array, F = it.array;
378
- let h = null;
379
- const st = t.count;
380
- for (let p = 0; p < st; p++) {
381
- const z = (t.head + p) % l, j = t.positions[z * 3], ut = t.positions[z * 3 + 1], ot = t.positions[z * 3 + 2], Pt = 1 - (t.elapsed - t.times[z]) / r;
382
- if (p < st - 1) {
383
- const m = (t.head + p + 1) % l;
384
- f.set(
385
- t.positions[m * 3] - j,
386
- t.positions[m * 3 + 1] - ut,
387
- t.positions[m * 3 + 2] - ot
386
+ const I = Rt.array, E = dt.array;
387
+ let x = null;
388
+ const et = t.count;
389
+ for (let p = 0; p < et; p++) {
390
+ const g = (t.head + p) % l, W = t.positions[g * 3], ft = t.positions[g * 3 + 1], nt = t.positions[g * 3 + 2], Tt = 1 - (t.elapsed - t.times[g]) / r;
391
+ if (p < et - 1) {
392
+ const y = (t.head + p + 1) % l;
393
+ h.set(
394
+ t.positions[y * 3] - W,
395
+ t.positions[y * 3 + 1] - ft,
396
+ t.positions[y * 3 + 2] - nt
388
397
  );
389
- const u = f.length();
390
- u > 1e-6 ? f.divideScalar(u) : h && f.copy(h);
391
- } else h && f.copy(h);
392
- Wt.set(
393
- L.position.x - j,
394
- L.position.y - ut,
395
- L.position.z - ot
396
- ), D.crossVectors(f, Wt);
397
- let pt = D.length();
398
- pt < 1e-6 && (jt.crossVectors(f, Ut), D.copy(jt), pt = D.length(), pt < 1e-6 && (D.set(1, 0, 0), pt = 1)), D.divideScalar(pt);
399
- const rt = i * Pt, a = k * Pt * Pt, c = p * 2;
400
- E[c * 3] = j + D.x * rt, E[c * 3 + 1] = ut + D.y * rt, E[c * 3 + 2] = ot + D.z * rt, E[(c + 1) * 3] = j - D.x * rt, E[(c + 1) * 3 + 1] = ut - D.y * rt, E[(c + 1) * 3 + 2] = ot - D.z * rt, F[c * 4] = R[0], F[c * 4 + 1] = R[1], F[c * 4 + 2] = R[2], F[c * 4 + 3] = a, F[(c + 1) * 4] = R[0], F[(c + 1) * 4 + 1] = R[1], F[(c + 1) * 4 + 2] = R[2], F[(c + 1) * 4 + 3] = a, h = h || new s.Vector3(), h.copy(f);
398
+ const u = h.length();
399
+ u > 1e-6 ? h.divideScalar(u) : x && h.copy(x);
400
+ } else x && h.copy(x);
401
+ Kt.set(
402
+ O.position.x - W,
403
+ O.position.y - ft,
404
+ O.position.z - nt
405
+ ), D.crossVectors(h, Kt);
406
+ let mt = D.length();
407
+ mt < 1e-6 && ($t.crossVectors(h, Gt), D.copy($t), mt = D.length(), mt < 1e-6 && (D.set(1, 0, 0), mt = 1)), D.divideScalar(mt);
408
+ const st = i * Tt, a = L * Tt * Tt, c = p * 2;
409
+ I[c * 3] = W + D.x * st, I[c * 3 + 1] = ft + D.y * st, I[c * 3 + 2] = nt + D.z * st, I[(c + 1) * 3] = W - D.x * st, I[(c + 1) * 3 + 1] = ft - D.y * st, I[(c + 1) * 3 + 2] = nt - D.z * st, E[c * 4] = R[0], E[c * 4 + 1] = R[1], E[c * 4 + 2] = R[2], E[c * 4 + 3] = a, E[(c + 1) * 4] = R[0], E[(c + 1) * 4 + 1] = R[1], E[(c + 1) * 4 + 2] = R[2], E[(c + 1) * 4 + 3] = a, x = x || new s.Vector3(), x.copy(h);
401
410
  }
402
- const lt = (st - 1) * 6;
403
- at.setDrawRange(0, lt), Vt.needsUpdate = !0, it.needsUpdate = !0;
404
- }), /* @__PURE__ */ be(
411
+ const pt = (et - 1) * 6;
412
+ ut.setDrawRange(0, pt), Rt.needsUpdate = !0, dt.needsUpdate = !0;
413
+ }), /* @__PURE__ */ Ee(
405
414
  "mesh",
406
415
  {
407
- ref: bt,
408
- geometry: at,
409
- material: xt,
416
+ ref: Ct,
417
+ geometry: ut,
418
+ material: gt,
410
419
  frustumCulled: !1,
411
420
  renderOrder: 101,
412
421
  visible: G
@@ -414,11 +423,11 @@ function An({
414
423
  );
415
424
  }
416
425
  export {
417
- zn as HZParticlesFX,
418
- An as HZTrailRibbon,
419
- Ye as computeParticleOpacity,
420
- Ze as computeParticleSize,
421
- Vn as fetchPreset,
422
- je as particleHash,
423
- mn as scalePreset
426
+ Pn as HZParticlesFX,
427
+ Cn as HZTrailRibbon,
428
+ Ne as computeParticleOpacity,
429
+ Qe as computeParticleSize,
430
+ Dn as fetchPreset,
431
+ $e as particleHash,
432
+ Sn as scalePreset
424
433
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hz-particles",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
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",