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