hz-particles 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
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 g=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(c,a,g.get?g:{enumerable:!0,get:()=>e[a]})}}return c.default=e,Object.freeze(c)}const o=an(cn);function Vt(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,g){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)*Vt(g)*Math.PI*2;O*=1+C*Math.sin(c*j*Math.PI*2+we)}return Math.max(0,O)}function Rt(e,c,a,g){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)*Vt(g)*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:g=!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,V=r.useRef(null),b=512,I=r.useRef({buf:new Float32Array(b*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(()=>{g&&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&&g&&u&&!ye.current&&(l.respawnAllSystems(),ye.current=!0,ke.current=!1)},[g,u]);const f=r.useMemo(()=>new o.Matrix4,[]),v=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)%b,n.count<b&&n.count++}const Re=Ae.current;let Be=0;for(let n=0;n<m.particleSystems.length;n++){const{system:s,config:z}=m.particleSystems[n],B=s.particleData,fe=s.activeParticles;if(!B||fe<=0)continue;const w=s._simPosition,Z=z.emissionTrailEnabled&&w?w[0]:0,Ve=z.emissionTrailEnabled&&w?w[1]:0,Ne=z.emissionTrailEnabled&&w?w[2]:0;for(let pe=0;pe<fe;pe++){const T=pe*8,ot=B[T+0]+Z,rt=B[T+1]+Ve,ct=B[T+2]+Ne;let H=B[T+3],me=B[T+4],he=B[T+5];const Me=B[T+6],N=B[T+7];if(Me>=N||N<=0)continue;const y=Me/N;if(z.colorTransitionEnabled){const A=z.startColor??[1,0,0],P=z.endColor??[0,0,1];H=A[0]+(P[0]-A[0])*y,me=A[1]+(P[1]-A[1])*y,he=A[2]+(P[2]-A[2])*y}const xe=z.bloomIntensity??1;H=Math.min(1,H*xe),me=Math.min(1,me*xe),he=Math.min(1,he*xe);const Se=Rt(z,Me,N,pe);H*=Se,me*=Se,he*=Se;const Q=Pt(z,Me,N,pe);if(!(Q<=0)){if(v.set(ot,rt,ct),W.subVectors(X.position,v).normalize(),le.setFromUnitVectors(nt,W),z.velocityStretchEnabled&&s.particleVelocities){const A=pe*4,P=s.particleVelocities[A],ge=s.particleVelocities[A+1],be=s.particleVelocities[A+2],Te=Math.sqrt(P*P+ge*ge+be*be);if(Te>.001){const Qe=z.velocityStretchFactor??1,Oe=Q*(1+Te*Qe);se.set(Q,Oe,1),W.set(P,ge,be).normalize(),le.setFromUnitVectors(nt,W);const Je=(Oe-Q)*.5;v.addScaledVector(W,Je)}else se.set(Q,Q,1)}else se.set(Q,Q,1);f.compose(v,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 Tt=Be>0||m.particleSystems.some(({system:n})=>n.emitting||n.activeParticles>0);if(ke.current&&!Tt&&(ye.current=!1,k==null||k()),ke.current=Tt,Fe&&V.current){const n=h.array,s=ne.array;let z=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,Ve=fe.particleVelocities,Ne=fe.activeParticles;if(!Z||!Ve||Ne<=0)continue;const pe=w.emissionTrailDuration??1,T=fe._simPosition,ot=T?T[0]:0,rt=T?T[1]:0,ct=T?T[2]:0,H=fe._simVelocity,me=H?H[0]:0,he=H?H[1]:0,Me=H?H[2]:0,N=I.current,y=N.buf,xe=N.count,Se=N.head,Q=N.elapsed;for(let A=0;A<Ne&&!(z+Y*6>t*Y*6);A++){const P=A*8,ge=Z[P],be=Z[P+1],Te=Z[P+2],Qe=ge+ot,Oe=be+rt,Je=Te+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],M=w.endColor??[0,0,1];He=R[0]+(M[0]-R[0])*Ze,_e=R[1]+(M[1]-R[1])*Ze,qe=R[2]+(M[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=Ve[lt],$e=Ve[lt+1],et=Ve[lt+2],ut=Math.min(pe,je);if(ut<.001)continue;const It=xe>=2;if(!It){const R=Ke+me,M=$e+he,G=et+Me;if(Math.sqrt(R*R+M*M+G*G)<.001)continue}const Ft=(R,M)=>{const G=Q-R;for(let q=0;q<xe-1;q++){const L=((Se-1-q)%b+b)%b,E=((Se-2-q)%b+b)%b,J=y[L*4+3],K=y[E*4+3];if(G>=K&&G<=J){const re=J!==K?(G-K)/(J-K):0;M[0]=y[E*4]+(y[L*4]-y[E*4])*re,M[1]=y[E*4+1]+(y[L*4+1]-y[E*4+1])*re,M[2]=y[E*4+2]+(y[L*4+2]-y[E*4+2])*re;return}}const _=((Se-xe)%b+b)%b;M[0]=y[_*4],M[1]=y[_*4+1],M[2]=y[_*4+2]},Jt=X.position.x,Kt=X.position.y,$t=X.position.z;for(let R=0;R<Y;R++){const M=R/Y,G=(R+1)/Y,_=M*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=Te-et*_+ve[2],K=ge-Ke*q+ze[0],re=be-$e*q+ze[1],Ge=Te-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-M),Ee=Et*(1-G),Mt=it*(1-M)*(1-M),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,x=z*3,S=z*3;n[x]=en,n[x+1]=tn,n[x+2]=nn,s[S]=St,s[S+1]=gt,s[S+2]=bt,n[x+3]=qt,n[x+4]=jt,n[x+5]=Xt,s[S+3]=St,s[S+4]=gt,s[S+5]=bt,n[x+6]=Zt,n[x+7]=Gt,n[x+8]=Lt,s[S+6]=vt,s[S+7]=zt,s[S+8]=wt,n[x+9]=qt,n[x+10]=jt,n[x+11]=Xt,s[S+9]=St,s[S+10]=gt,s[S+11]=bt,n[x+12]=sn,n[x+13]=on,n[x+14]=rn,s[S+12]=vt,s[S+13]=zt,s[S+14]=wt,n[x+15]=Zt,n[x+16]=Gt,n[x+17]=Lt,s[S+15]=vt,s[S+16]=zt,s[S+17]=wt,z+=6}}}F.setDrawRange(0,z),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:V,geometry:F,material:ie,frustumCulled:!1,renderOrder:99,visible:u})]}):null}const fn=`
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=`
2
2
  attribute vec4 aColor;
3
3
  varying vec4 vColor;
4
4
  void main() {
@@ -10,4 +10,4 @@ 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:g=[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),V=new o.BufferGeometry,b=new o.BufferAttribute(Y,3);b.setUsage(o.DynamicDrawUsage),V.setAttribute("position",b);const I=new o.BufferAttribute(t,4);I.setUsage(o.DynamicDrawUsage),V.setAttribute("aColor",I);const F=(u-1)*6,h=new Uint32Array(F);for(let ie=0;ie<u-1;ie++){const f=ie*2,v=ie*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 ne=new o.BufferAttribute(h,1);return V.setIndex(ne),V.setDrawRange(0,0),{geometry:V,posAttr:b,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 V=e.current;if(!V)return;if(t.lastPos.distanceTo(V)>=O){const f=(t.head+t.count)%u;t.positions[f*3]=V.x,t.positions[f*3+1]=V.y,t.positions[f*3+2]=V.z,t.times[f]=t.elapsed,t.count<u?t.count++:t.head=(t.head+1)%u,t.lastPos.copy(V)}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 v=(t.head+f)%u,W=t.positions[v*3],le=t.positions[v*3+1],se=t.positions[v*3+2],Pe=1-(t.elapsed-t.times[v])/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]=g[0],F[i*4+1]=g[1],F[i*4+2]=g[2],F[i*4+3]=l,F[(i+1)*4]=g[0],F[(i+1)*4+1]=g[1],F[(i+1)*4+2]=g[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=Vt;exports.scalePreset=Yt;
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;
@@ -108,8 +108,8 @@ function zn({
108
108
  blending: s.AdditiveBlending
109
109
  });
110
110
  return U.needsUpdate = !0, U;
111
- }, []), W = 8, t = 2e3, P = nt(null), g = 512, E = nt({
112
- buf: new Float32Array(g * 4),
111
+ }, []), W = 8, t = 2e3, P = nt(null), w = 512, E = nt({
112
+ buf: new Float32Array(w * 4),
113
113
  // x, y, z, time
114
114
  head: 0,
115
115
  count: 0,
@@ -141,7 +141,7 @@ function zn({
141
141
  const a = it.current;
142
142
  a && R && l && !xt.current && (a.respawnAllSystems(), xt.current = !0, kt.current = !1);
143
143
  }, [R, l]);
144
- const p = d(() => new s.Matrix4(), []), w = 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);
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
145
  return We((a, c) => {
146
146
  if (!l || !Vt.current || !it.current) return;
147
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;
@@ -158,42 +158,42 @@ function zn({
158
158
  const e = E.current;
159
159
  e.elapsed += U;
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) % g, e.count < g && 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) % w, e.count < w && e.count++;
162
162
  }
163
163
  const Ct = Vt.current;
164
164
  let _t = 0;
165
165
  for (let e = 0; e < m.particleSystems.length; e++) {
166
- const { system: n, config: z } = m.particleSystems[e], B = n.particleData, ft = n.activeParticles;
167
- if (!B || ft <= 0) continue;
168
- const A = n._simPosition, O = z.emissionTrailEnabled && A ? A[0] : 0, Rt = z.emissionTrailEnabled && A ? A[1] : 0, Qt = z.emissionTrailEnabled && A ? A[2] : 0;
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
169
  for (let mt = 0; mt < ft; mt++) {
170
170
  const C = mt * 8, se = B[C + 0] + O, oe = B[C + 1] + Rt, re = B[C + 2] + Qt;
171
171
  let H = B[C + 3], ht = B[C + 4], yt = B[C + 5];
172
172
  const vt = B[C + 6], Q = B[C + 7];
173
173
  if (vt >= Q || Q <= 0) continue;
174
- const y = vt / Q;
175
- if (z.colorTransitionEnabled) {
176
- const M = z.startColor ?? [1, 0, 0], b = z.endColor ?? [0, 0, 1];
177
- H = M[0] + (b[0] - M[0]) * y, ht = M[1] + (b[1] - M[1]) * y, yt = M[2] + (b[2] - M[2]) * y;
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;
178
178
  }
179
- const St = z.bloomIntensity ?? 1;
179
+ const St = y.bloomIntensity ?? 1;
180
180
  H = Math.min(1, H * St), ht = Math.min(1, ht * St), yt = Math.min(1, yt * St);
181
- const gt = Ye(z, vt, Q, mt);
181
+ const gt = Ye(y, vt, Q, mt);
182
182
  H *= gt, ht *= gt, yt *= gt;
183
- const N = Ze(z, vt, Q, mt);
183
+ const N = Ze(y, vt, Q, mt);
184
184
  if (!(N <= 0)) {
185
- if (w.set(se, oe, re), j.subVectors(L.position, w).normalize(), ut.setFromUnitVectors(ee, j), z.velocityStretchEnabled && n.particleVelocities) {
185
+ if (z.set(se, oe, re), j.subVectors(L.position, z).normalize(), ut.setFromUnitVectors(ee, j), y.velocityStretchEnabled && n.particleVelocities) {
186
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
187
  if (Tt > 1e-3) {
188
- const Nt = z.velocityStretchFactor ?? 1, Ht = N * (1 + Tt * Nt);
188
+ const Nt = y.velocityStretchFactor ?? 1, Ht = N * (1 + Tt * Nt);
189
189
  ot.set(N, Ht, 1), j.set(b, wt, zt).normalize(), ut.setFromUnitVectors(ee, j);
190
190
  const Jt = (Ht - N) * 0.5;
191
- w.addScaledVector(j, Jt);
191
+ z.addScaledVector(j, Jt);
192
192
  } else
193
193
  ot.set(N, N, 1);
194
194
  } else
195
195
  ot.set(N, N, 1);
196
- p.compose(w, ut, ot), Ct.setMatrixAt(_t, p), Pt.setRGB(H, ht, yt), Ct.setColorAt(_t, Pt), _t++;
196
+ p.compose(z, ut, ot), Ct.setMatrixAt(_t, p), Pt.setRGB(H, ht, yt), Ct.setColorAt(_t, Pt), _t++;
197
197
  }
198
198
  }
199
199
  }
@@ -201,14 +201,14 @@ function zn({
201
201
  const Ve = _t > 0 || m.particleSystems.some(({ system: e }) => e.emitting || e.activeParticles > 0);
202
202
  if (kt.current && !Ve && (xt.current = !1, k == null || k()), kt.current = Ve, Ut && P.current) {
203
203
  const e = h.array, n = st.array;
204
- let z = 0;
204
+ let y = 0;
205
205
  for (let B = 0; B < m.particleSystems.length; B++) {
206
206
  const { system: ft, config: A } = m.particleSystems[B];
207
207
  if (!A.emissionTrailEnabled || A.glbModelEnabled || A.textureEnabled) continue;
208
208
  const O = ft.particleData, Rt = ft.particleVelocities, Qt = ft.activeParticles;
209
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, y = Q.buf, St = Q.count, gt = Q.head, N = Q.elapsed;
211
- for (let M = 0; M < Qt && !(z + W * 6 > t * W * 6); M++) {
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
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
213
  let qt = O[b + 3], Xt = O[b + 4], Gt = O[b + 5];
214
214
  const Lt = O[b + 6], Ot = O[b + 7];
@@ -217,8 +217,8 @@ function zn({
217
217
  if (Zt > 0.9) continue;
218
218
  const Pe = Math.min((0.9 - Zt) * (1 / 0.2), 1);
219
219
  if (A.colorTransitionEnabled) {
220
- const V = A.startColor ?? [1, 0, 0], x = A.endColor ?? [0, 0, 1];
221
- qt = V[0] + (x[0] - V[0]) * Zt, Xt = V[1] + (x[1] - V[1]) * Zt, Gt = V[2] + (x[2] - V[2]) * Zt;
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;
222
222
  }
223
223
  const ce = A.bloomIntensity ?? 1;
224
224
  qt = Math.min(1, qt * ce), Xt = Math.min(1, Xt * ce), Gt = Math.min(1, Gt * ce);
@@ -230,24 +230,24 @@ function zn({
230
230
  if (le < 1e-3) continue;
231
231
  const Te = St >= 2;
232
232
  if (!Te) {
233
- const V = Kt + ht, x = $t + yt, Z = te + vt;
234
- if (Math.sqrt(V * V + x * x + Z * Z) < 1e-3) continue;
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
235
  }
236
- const De = (V, x) => {
236
+ const De = (V, v) => {
237
237
  const Z = N - V;
238
238
  for (let X = 0; X < St - 1; X++) {
239
- const Y = ((gt - 1 - X) % g + g) % g, I = ((gt - 2 - X) % g + g) % g, J = y[Y * 4 + 3], K = y[I * 4 + 3];
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
240
  if (Z >= K && Z <= J) {
241
241
  const ct = J !== K ? (Z - K) / (J - K) : 0;
242
- x[0] = y[I * 4] + (y[Y * 4] - y[I * 4]) * ct, x[1] = y[I * 4 + 1] + (y[Y * 4 + 1] - y[I * 4 + 1]) * ct, x[2] = y[I * 4 + 2] + (y[Y * 4 + 2] - y[I * 4 + 2]) * ct;
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;
243
243
  return;
244
244
  }
245
245
  }
246
- const q = ((gt - St) % g + g) % g;
247
- x[0] = y[q * 4], x[1] = y[q * 4 + 1], x[2] = y[q * 4 + 2];
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
248
  }, Ke = L.position.x, $e = L.position.y, tn = L.position.z;
249
249
  for (let V = 0; V < W; V++) {
250
- const x = V / W, Z = (V + 1) / W, q = x * le, X = Z * le;
250
+ const v = V / W, Z = (V + 1) / W, q = v * le, X = Z * le;
251
251
  let Y, I, J, K, ct, Yt;
252
252
  if (Te) {
253
253
  const At = [0, 0, 0], Mt = [0, 0, 0];
@@ -262,12 +262,12 @@ function zn({
262
262
  let $ = Ee * Be - he * Ue, tt = he * Fe - me * Be, et = me * Ue - Ee * Fe, Dt = Math.sqrt($ * $ + tt * tt + et * et);
263
263
  if (Dt < 1e-6 && ($ = -he, tt = 0, et = me, Dt = Math.sqrt($ * $ + tt * tt + et * et)), Dt < 1e-6) continue;
264
264
  $ /= Dt, tt /= Dt, et /= Dt;
265
- const It = Re * (1 - x), Et = Re * (1 - Z), ye = ae * (1 - x) * (1 - x), 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, v = z * 3, S = z * 3;
266
- e[v] = en, e[v + 1] = nn, e[v + 2] = sn, n[S] = ve, n[S + 1] = Se, n[S + 2] = ge, e[v + 3] = _e, e[v + 4] = He, e[v + 5] = qe, n[S + 3] = ve, n[S + 4] = Se, n[S + 5] = ge, e[v + 6] = Xe, e[v + 7] = Ge, e[v + 8] = Le, n[S + 6] = we, n[S + 7] = ze, n[S + 8] = Ae, e[v + 9] = _e, e[v + 10] = He, e[v + 11] = qe, n[S + 9] = ve, n[S + 10] = Se, n[S + 11] = ge, e[v + 12] = on, e[v + 13] = rn, e[v + 14] = cn, n[S + 12] = we, n[S + 13] = ze, n[S + 14] = Ae, e[v + 15] = Xe, e[v + 16] = Ge, e[v + 17] = Le, n[S + 15] = we, n[S + 16] = ze, n[S + 17] = Ae, z += 6;
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
267
  }
268
268
  }
269
269
  }
270
- F.setDrawRange(0, z), h.needsUpdate = !0, st.needsUpdate = !0;
270
+ F.setDrawRange(0, y), h.needsUpdate = !0, st.needsUpdate = !0;
271
271
  }
272
272
  }), T ? /* @__PURE__ */ an(ln, { children: [
273
273
  /* @__PURE__ */ be(
@@ -331,17 +331,17 @@ function An({
331
331
  lastPos: new s.Vector3(1 / 0, 1 / 0, 1 / 0),
332
332
  elapsed: 0
333
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(), g = new s.BufferAttribute(W, 3);
335
- g.setUsage(s.DynamicDrawUsage), P.setAttribute("position", g);
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
336
  const E = new s.BufferAttribute(t, 4);
337
337
  E.setUsage(s.DynamicDrawUsage), P.setAttribute("aColor", E);
338
338
  const F = (l - 1) * 6, h = new Uint32Array(F);
339
339
  for (let lt = 0; lt < l - 1; lt++) {
340
- const p = lt * 2, w = lt * 6;
341
- h[w] = p, h[w + 1] = p + 1, h[w + 2] = p + 2, h[w + 3] = p + 1, h[w + 4] = p + 3, h[w + 5] = p + 2;
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;
342
342
  }
343
343
  const st = new s.BufferAttribute(h, 1);
344
- return P.setIndex(st), P.setDrawRange(0, 0), { geometry: P, posAttr: g, colorAttr: E, indexBuf: st };
344
+ return P.setIndex(st), P.setDrawRange(0, 0), { geometry: P, posAttr: w, colorAttr: E, indexBuf: st };
345
345
  }, [l]), xt = d(() => new s.ShaderMaterial({
346
346
  vertexShader: yn,
347
347
  fragmentShader: xn,
@@ -378,7 +378,7 @@ function An({
378
378
  let h = null;
379
379
  const st = t.count;
380
380
  for (let p = 0; p < st; p++) {
381
- const w = (t.head + p) % l, j = t.positions[w * 3], ut = t.positions[w * 3 + 1], ot = t.positions[w * 3 + 2], Pt = 1 - (t.elapsed - t.times[w]) / r;
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
382
  if (p < st - 1) {
383
383
  const m = (t.head + p + 1) % l;
384
384
  f.set(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hz-particles",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "High-performance WebGPU particle engine with compute shaders, GPU instancing, GLB model support, and skeletal animations",
5
5
  "type": "module",
6
6
  "main": "dist-lib/hz-particles.cjs",