hz-particles 1.0.5 → 1.0.7

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