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