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