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