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