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