hz-particles 1.4.2 → 1.4.3
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/README.md +1 -1
- package/dist-lib/hz-particles-r3f.cjs +2 -2
- package/dist-lib/hz-particles-r3f.mjs +173 -146
- package/dist-lib/hz-particles.cjs +23 -20
- package/dist-lib/hz-particles.d.ts +4 -3
- package/dist-lib/hz-particles.mjs +423 -407
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -348,7 +348,7 @@ class ParticleSystem {
|
|
|
348
348
|
| `updateParticles(deltaTime)` | Execute a physics simulation step on the GPU. |
|
|
349
349
|
| `spawnParticles()` | Emit new particles according to emitter configuration. |
|
|
350
350
|
| `setGravity(value)` | Set gravity strength (default `9.8`). |
|
|
351
|
-
| `setAttractor(strength, position)` | Set an attractor point `[x, y, z]`. |
|
|
351
|
+
| `setAttractor(strength, position, reverse?)` | Set an attractor or repulsor point `[x, y, z]`. |
|
|
352
352
|
| `render(renderPass)` | Render particles to the current render pass. |
|
|
353
353
|
|
|
354
354
|
### `ParticleSystemManager`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),N=require("@react-three/fiber"),X=require("hz-particles"),Q=require("react/jsx-runtime"),Y=require("three");function $(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const l in r)if(l!=="default"){const e=Object.getOwnPropertyDescriptor(r,l);Object.defineProperty(t,l,e.get?e:{enumerable:!0,get:()=>r[l]})}}return t.default=r,Object.freeze(t)}const p=$(Y);function K(r,t){if(t===1)return r;const l=(e,o)=>e!=null?e*t:o*t;return{...r,systems:r.systems.map(e=>({...e,particleSize:l(e.particleSize,.5),minSize:e.minSize!=null?e.minSize*t:void 0,maxSize:e.maxSize!=null?e.maxSize*t:void 0,particleSpeed:(e.particleSpeed??1)*t,minSpeed:e.minSpeed!=null?e.minSpeed*t:void 0,maxSpeed:e.maxSpeed!=null?e.maxSpeed*t:void 0,cubeLength:e.cubeLength!=null?e.cubeLength*t:void 0,outerLength:e.outerLength!=null?e.outerLength*t:void 0,innerLength:e.innerLength!=null?e.innerLength*t:void 0,outerRadius:e.outerRadius!=null?e.outerRadius*t:void 0,innerRadius:e.innerRadius!=null?e.innerRadius*t:void 0,squareSize:e.squareSize!=null?e.squareSize*t:void 0,squareInnerSize:e.squareInnerSize!=null?e.squareInnerSize*t:void 0,circleInnerRadius:e.circleInnerRadius!=null?e.circleInnerRadius*t:void 0,circleOuterRadius:e.circleOuterRadius!=null?e.circleOuterRadius*t:void 0,cylinderInnerRadius:e.cylinderInnerRadius!=null?e.cylinderInnerRadius*t:void 0,cylinderOuterRadius:e.cylinderOuterRadius!=null?e.cylinderOuterRadius*t:void 0,cylinderHeight:e.cylinderHeight!=null?e.cylinderHeight*t:void 0,rectangleWidth:e.rectangleWidth!=null?e.rectangleWidth*t:void 0,rectangleHeight:e.rectangleHeight!=null?e.rectangleHeight*t:void 0,coneOuterRadius:e.coneOuterRadius!=null?e.coneOuterRadius*t:void 0,coneInnerRadius:e.coneInnerRadius!=null?e.coneInnerRadius*t:void 0,coneHeight:e.coneHeight!=null?e.coneHeight*t:void 0,torusMajorRadius:e.torusMajorRadius!=null?e.torusMajorRadius*t:void 0,torusMinorRadius:e.torusMinorRadius!=null?e.torusMinorRadius*t:void 0,lineLength:e.lineLength!=null?e.lineLength*t:void 0,hemisphereOuterRadius:e.hemisphereOuterRadius!=null?e.hemisphereOuterRadius*t:void 0,hemisphereInnerRadius:e.hemisphereInnerRadius!=null?e.hemisphereInnerRadius*t:void 0,discRadius:e.discRadius!=null?e.discRadius*t:void 0,annulusInnerRadius:e.annulusInnerRadius!=null?e.annulusInnerRadius*t:void 0,annulusOuterRadius:e.annulusOuterRadius!=null?e.annulusOuterRadius*t:void 0,capsuleRadius:e.capsuleRadius!=null?e.capsuleRadius*t:void 0,capsuleHeight:e.capsuleHeight!=null?e.capsuleHeight*t:void 0,arcInnerRadius:e.arcInnerRadius!=null?e.arcInnerRadius*t:void 0,arcOuterRadius:e.arcOuterRadius!=null?e.arcOuterRadius*t:void 0,spiralRadiusStart:e.spiralRadiusStart!=null?e.spiralRadiusStart*t:void 0,spiralRadiusEnd:e.spiralRadiusEnd!=null?e.spiralRadiusEnd*t:void 0,spiralHeight:e.spiralHeight!=null?e.spiralHeight*t:void 0,frustumRadiusNear:e.frustumRadiusNear!=null?e.frustumRadiusNear*t:void 0,frustumRadiusFar:e.frustumRadiusFar!=null?e.frustumRadiusFar*t:void 0,frustumHeight:e.frustumHeight!=null?e.frustumHeight*t:void 0,cubeSurfaceSize:e.cubeSurfaceSize!=null?e.cubeSurfaceSize*t:void 0,sphereSurfaceRadius:e.sphereSurfaceRadius!=null?e.sphereSurfaceRadius*t:void 0,boxFrameSize:e.boxFrameSize!=null?e.boxFrameSize*t:void 0,polygonRadius:e.polygonRadius!=null?e.polygonRadius*t:void 0,emissionTrailWidth:(e.emissionTrailWidth??.3)*t,emissionTrailDuration:(e.emissionTrailDuration??1)*t,emissionTrailMinDistance:e.emissionTrailMinDistance!=null?e.emissionTrailMinDistance*t:void 0,emissionTrailShapeAmplitude:e.emissionTrailShapeAmplitude!=null?e.emissionTrailShapeAmplitude*t:void 0}))}}function y({preset:r,positionRef:t,position:l=[0,0,0],scale:e=1,active:o=!0,renderPriority:z=1,noOcclusion:O=!1,respectReducedMotion:w=!0}){const v=d.useRef(null),S=d.useRef(null),H=d.useRef(!1),L=d.useRef(0),A=d.useRef(o);A.current=o;const C=d.useRef(l);C.current=l;const P=d.useRef(!1),q=d.useMemo(()=>e&&e!==1?K(r,e):r,[r,e]),V=i=>t?i.addMovingEmitter(q,{getPosition:()=>{const u=t.current;return A.current&&u?[u.x,u.y,u.z]:null}}):i.addEmitter(q,C.current);return d.useEffect(()=>{var c,m;const i=v.current;if(!i)return;let u=!1;return(m=(c=S.current)==null?void 0:c.remove)==null||m.call(c),S.current=null,V(i).then(s=>{var x;u?(x=s==null?void 0:s.remove)==null||x.call(s):S.current=s}),()=>{u=!0}},[q]),d.useEffect(()=>{var c;if(typeof window>"u"||!window.matchMedia)return;const i=window.matchMedia("(prefers-reduced-motion: reduce)"),u=()=>{P.current=i.matches};return u(),(c=i.addEventListener)==null||c.call(i,"change",u),()=>{var m;return(m=i.removeEventListener)==null?void 0:m.call(i,"change",u)}},[]),d.useEffect(()=>()=>{var i,u,c,m;(u=(i=S.current)==null?void 0:i.remove)==null||u.call(i),(m=(c=v.current)==null?void 0:c.destroy)==null||m.call(c),v.current=null,S.current=null,H.current=!1},[]),N.useFrame(i=>{var n,h;i.gl.render(i.scene,i.camera);const u=performance.now(),c=L.current?Math.min(.05,(u-L.current)/1e3):.016;L.current=u;const m=i.gl,s=m.backend,x=(s==null?void 0:s.context)||((h=(n=m.domElement)==null?void 0:n.getContext)==null?void 0:h.call(n,"webgpu"));!v.current&&!H.current&&(s!=null&&s.device)&&x&&(H.current=!0,X.initHzFxOverlay({device:s.device,context:x,canvas:m.domElement},{getSceneDepth:O?()=>null:X.makeThreeSceneDepth(m)}).then(f=>(v.current=f,V(f))).then(f=>{S.current=f}).catch(f=>console.error("[HZFaithfulFX] init failed:",f)));const F=v.current;if(F){const f=i.camera;F.setCamera(f.projectionMatrix.elements,f.matrixWorldInverse.elements,f.position),w&&P.current||F.render(c)}},z),null}const ee=`
|
|
2
2
|
attribute vec4 aColor;
|
|
3
3
|
varying vec4 vColor;
|
|
4
4
|
void main() {
|
|
@@ -10,4 +10,4 @@ varying vec4 vColor;
|
|
|
10
10
|
void main() {
|
|
11
11
|
gl_FragColor = vColor;
|
|
12
12
|
}
|
|
13
|
-
`;function ne({positionRef:r,duration:t=1,width:
|
|
13
|
+
`;function ne({positionRef:r,duration:t=1,width:l=.3,color:e=[1,1,1],maxPoints:o=256,minDistance:z=.05,opacity:O=1,blending:w=p.AdditiveBlending,visible:v=!0}){const{camera:S}=N.useThree(),H=d.useRef(null),L=d.useRef({positions:new Float32Array(o*3),times:new Float32Array(o),head:0,count:0,lastPos:new p.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:A,posAttr:C,colorAttr:P,indexBuf:q}=d.useMemo(()=>{const x=o*2,F=new Float32Array(x*3),n=new Float32Array(x*4),h=new p.BufferGeometry,f=new p.BufferAttribute(F,3);f.setUsage(p.DynamicDrawUsage),h.setAttribute("position",f);const I=new p.BufferAttribute(n,4);I.setUsage(p.DynamicDrawUsage),h.setAttribute("aColor",I);const b=(o-1)*6,R=new Uint32Array(b);for(let T=0;T<o-1;T++){const a=T*2,M=T*6;R[M]=a,R[M+1]=a+1,R[M+2]=a+2,R[M+3]=a+1,R[M+4]=a+3,R[M+5]=a+2}const E=new p.BufferAttribute(R,1);return h.setIndex(E),h.setDrawRange(0,0),{geometry:h,posAttr:f,colorAttr:I,indexBuf:E}},[o]),V=d.useMemo(()=>new p.ShaderMaterial({vertexShader:ee,fragmentShader:te,transparent:!0,depthWrite:!1,side:p.DoubleSide,blending:w}),[w]),i=d.useMemo(()=>new p.Vector3,[]),u=d.useMemo(()=>new p.Vector3,[]),c=d.useMemo(()=>new p.Vector3,[]),m=d.useMemo(()=>new p.Vector3(0,1,0),[]),s=d.useMemo(()=>new p.Vector3,[]);return N.useFrame((x,F)=>{if(!H.current)return;const n=L.current;if(n.elapsed+=F,!v){n.count=0,n.head=0,n.lastPos.set(1/0,1/0,1/0),A.setDrawRange(0,0);return}const h=r.current;if(!h)return;if(n.lastPos.distanceTo(h)>=z){const a=(n.head+n.count)%o;n.positions[a*3]=h.x,n.positions[a*3+1]=h.y,n.positions[a*3+2]=h.z,n.times[a]=n.elapsed,n.count<o?n.count++:n.head=(n.head+1)%o,n.lastPos.copy(h)}for(;n.count>0;){const a=n.head;if(n.elapsed-n.times[a]>t)n.head=(n.head+1)%o,n.count--;else break}if(n.count<2){A.setDrawRange(0,0);return}const I=C.array,b=P.array;let R=null;const E=n.count;for(let a=0;a<E;a++){const M=(n.head+a)%o,B=n.positions[M*3],U=n.positions[M*3+1],W=n.positions[M*3+2],_=1-(n.elapsed-n.times[M])/t;if(a<E-1){const Z=(n.head+a+1)%o;i.set(n.positions[Z*3]-B,n.positions[Z*3+1]-U,n.positions[Z*3+2]-W);const J=i.length();J>1e-6?i.divideScalar(J):R&&i.copy(R)}else R&&i.copy(R);c.set(S.position.x-B,S.position.y-U,S.position.z-W),u.crossVectors(i,c);let j=u.length();j<1e-6&&(s.crossVectors(i,m),u.copy(s),j=u.length(),j<1e-6&&(u.set(1,0,0),j=1)),u.divideScalar(j);const D=l*_,G=O*_*_,g=a*2;I[g*3]=B+u.x*D,I[g*3+1]=U+u.y*D,I[g*3+2]=W+u.z*D,I[(g+1)*3]=B-u.x*D,I[(g+1)*3+1]=U-u.y*D,I[(g+1)*3+2]=W-u.z*D,b[g*4]=e[0],b[g*4+1]=e[1],b[g*4+2]=e[2],b[g*4+3]=G,b[(g+1)*4]=e[0],b[(g+1)*4+1]=e[1],b[(g+1)*4+2]=e[2],b[(g+1)*4+3]=G,R=R||new p.Vector3,R.copy(i)}const T=(E-1)*6;A.setDrawRange(0,T),C.needsUpdate=!0,P.needsUpdate=!0}),Q.jsx("mesh",{ref:H,geometry:A,material:V,frustumCulled:!1,renderOrder:101,visible:v})}function k(r){return Math.abs(Math.sin(r*12.9898)*43758.5453)%1}function re(r){const t=Math.sin(r*54321.67)*43758.5453%1;return t<0?t+1:t}function ie(r,t,l,e){if(l<=0)return 0;const o=t/l;let z=r.particleSize??.5;if(r.randomSize){const w=r.minSize??.1,v=r.maxSize??.5;z=w+(v-w)*re(l)}const O=Math.max(.01,Math.min(10,r.sizeLifetimeSpeed??1));if(r.fadeSizeEnabled&&(z*=1-Math.pow(o,1/O)),r.increaseSizeEnabled&&(z*=1+Math.pow(o,1/O)),r.pulseEnabled){const w=r.pulseAmplitude??.5,v=r.pulseFrequency??1,H=(r.pulsePhaseRandom??0)*k(e)*Math.PI*2;z*=1+w*Math.sin(t*v*Math.PI*2+H)}return Math.max(0,z)}function ue(r,t,l,e){if(l<=0)return 0;let o=r.opacity??1;const z=t/l;if(r.fadeEnabled&&(o*=Math.max(0,1-z)),r.pulseEnabled&&r.pulseOpacity){const O=r.pulseAmplitude??.5,w=r.pulseFrequency??1,S=(r.pulsePhaseRandom??0)*k(e)*Math.PI*2;o*=Math.max(0,1+O*Math.sin(t*w*Math.PI*2+S))}return Math.max(0,Math.min(1,o))}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>X.fetchPreset});exports.HZFaithfulFX=y;exports.HZTrailRibbon=ne;exports.computeParticleOpacity=ue;exports.computeParticleSize=ie;exports.particleHash=k;exports.scalePreset=K;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { useFrame as J, useThree as
|
|
3
|
-
import { initHzFxOverlay as
|
|
4
|
-
import { fetchPreset as
|
|
5
|
-
import { jsx as
|
|
6
|
-
import * as
|
|
1
|
+
import { useRef as A, useMemo as O, useEffect as X } from "react";
|
|
2
|
+
import { useFrame as J, useThree as Q } from "@react-three/fiber";
|
|
3
|
+
import { initHzFxOverlay as Y, makeThreeSceneDepth as $ } from "hz-particles";
|
|
4
|
+
import { fetchPreset as fe } from "hz-particles";
|
|
5
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
6
|
+
import * as c from "three";
|
|
7
7
|
function ee(r, n) {
|
|
8
8
|
if (n === 1) return r;
|
|
9
|
-
const
|
|
9
|
+
const v = (e, o) => e != null ? e * n : o * n;
|
|
10
10
|
return {
|
|
11
11
|
...r,
|
|
12
12
|
systems: r.systems.map((e) => ({
|
|
13
13
|
...e,
|
|
14
14
|
// Particle visual size
|
|
15
|
-
particleSize:
|
|
15
|
+
particleSize: v(e.particleSize, 0.5),
|
|
16
16
|
minSize: e.minSize != null ? e.minSize * n : void 0,
|
|
17
17
|
maxSize: e.maxSize != null ? e.maxSize * n : void 0,
|
|
18
18
|
// Speed
|
|
@@ -32,6 +32,33 @@ function ee(r, n) {
|
|
|
32
32
|
cylinderInnerRadius: e.cylinderInnerRadius != null ? e.cylinderInnerRadius * n : void 0,
|
|
33
33
|
cylinderOuterRadius: e.cylinderOuterRadius != null ? e.cylinderOuterRadius * n : void 0,
|
|
34
34
|
cylinderHeight: e.cylinderHeight != null ? e.cylinderHeight * n : void 0,
|
|
35
|
+
rectangleWidth: e.rectangleWidth != null ? e.rectangleWidth * n : void 0,
|
|
36
|
+
rectangleHeight: e.rectangleHeight != null ? e.rectangleHeight * n : void 0,
|
|
37
|
+
coneOuterRadius: e.coneOuterRadius != null ? e.coneOuterRadius * n : void 0,
|
|
38
|
+
coneInnerRadius: e.coneInnerRadius != null ? e.coneInnerRadius * n : void 0,
|
|
39
|
+
coneHeight: e.coneHeight != null ? e.coneHeight * n : void 0,
|
|
40
|
+
torusMajorRadius: e.torusMajorRadius != null ? e.torusMajorRadius * n : void 0,
|
|
41
|
+
torusMinorRadius: e.torusMinorRadius != null ? e.torusMinorRadius * n : void 0,
|
|
42
|
+
lineLength: e.lineLength != null ? e.lineLength * n : void 0,
|
|
43
|
+
hemisphereOuterRadius: e.hemisphereOuterRadius != null ? e.hemisphereOuterRadius * n : void 0,
|
|
44
|
+
hemisphereInnerRadius: e.hemisphereInnerRadius != null ? e.hemisphereInnerRadius * n : void 0,
|
|
45
|
+
discRadius: e.discRadius != null ? e.discRadius * n : void 0,
|
|
46
|
+
annulusInnerRadius: e.annulusInnerRadius != null ? e.annulusInnerRadius * n : void 0,
|
|
47
|
+
annulusOuterRadius: e.annulusOuterRadius != null ? e.annulusOuterRadius * n : void 0,
|
|
48
|
+
capsuleRadius: e.capsuleRadius != null ? e.capsuleRadius * n : void 0,
|
|
49
|
+
capsuleHeight: e.capsuleHeight != null ? e.capsuleHeight * n : void 0,
|
|
50
|
+
arcInnerRadius: e.arcInnerRadius != null ? e.arcInnerRadius * n : void 0,
|
|
51
|
+
arcOuterRadius: e.arcOuterRadius != null ? e.arcOuterRadius * n : void 0,
|
|
52
|
+
spiralRadiusStart: e.spiralRadiusStart != null ? e.spiralRadiusStart * n : void 0,
|
|
53
|
+
spiralRadiusEnd: e.spiralRadiusEnd != null ? e.spiralRadiusEnd * n : void 0,
|
|
54
|
+
spiralHeight: e.spiralHeight != null ? e.spiralHeight * n : void 0,
|
|
55
|
+
frustumRadiusNear: e.frustumRadiusNear != null ? e.frustumRadiusNear * n : void 0,
|
|
56
|
+
frustumRadiusFar: e.frustumRadiusFar != null ? e.frustumRadiusFar * n : void 0,
|
|
57
|
+
frustumHeight: e.frustumHeight != null ? e.frustumHeight * n : void 0,
|
|
58
|
+
cubeSurfaceSize: e.cubeSurfaceSize != null ? e.cubeSurfaceSize * n : void 0,
|
|
59
|
+
sphereSurfaceRadius: e.sphereSurfaceRadius != null ? e.sphereSurfaceRadius * n : void 0,
|
|
60
|
+
boxFrameSize: e.boxFrameSize != null ? e.boxFrameSize * n : void 0,
|
|
61
|
+
polygonRadius: e.polygonRadius != null ? e.polygonRadius * n : void 0,
|
|
35
62
|
// Trail
|
|
36
63
|
emissionTrailWidth: (e.emissionTrailWidth ?? 0.3) * n,
|
|
37
64
|
emissionTrailDuration: (e.emissionTrailDuration ?? 1) * n,
|
|
@@ -40,73 +67,73 @@ function ee(r, n) {
|
|
|
40
67
|
}))
|
|
41
68
|
};
|
|
42
69
|
}
|
|
43
|
-
function
|
|
70
|
+
function le({
|
|
44
71
|
preset: r,
|
|
45
72
|
positionRef: n,
|
|
46
|
-
position:
|
|
73
|
+
position: v = [0, 0, 0],
|
|
47
74
|
scale: e = 1,
|
|
48
|
-
active:
|
|
49
|
-
renderPriority:
|
|
50
|
-
noOcclusion:
|
|
51
|
-
respectReducedMotion:
|
|
75
|
+
active: o = !0,
|
|
76
|
+
renderPriority: z = 1,
|
|
77
|
+
noOcclusion: H = !1,
|
|
78
|
+
respectReducedMotion: I = !0
|
|
52
79
|
}) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
const
|
|
80
|
+
const f = A(null), g = A(null), b = A(!1), C = A(0), F = A(o);
|
|
81
|
+
F.current = o;
|
|
82
|
+
const V = A(v);
|
|
83
|
+
V.current = v;
|
|
84
|
+
const B = A(!1), W = O(
|
|
58
85
|
() => e && e !== 1 ? ee(r, e) : r,
|
|
59
86
|
[r, e]
|
|
60
|
-
), q = (i) => n ? i.addMovingEmitter(
|
|
87
|
+
), q = (i) => n ? i.addMovingEmitter(W, {
|
|
61
88
|
getPosition: () => {
|
|
62
|
-
const
|
|
63
|
-
return
|
|
89
|
+
const u = n.current;
|
|
90
|
+
return F.current && u ? [u.x, u.y, u.z] : null;
|
|
64
91
|
}
|
|
65
|
-
}) : i.addEmitter(
|
|
92
|
+
}) : i.addEmitter(W, V.current);
|
|
66
93
|
return X(() => {
|
|
67
|
-
var
|
|
68
|
-
const i =
|
|
94
|
+
var d, p;
|
|
95
|
+
const i = f.current;
|
|
69
96
|
if (!i) return;
|
|
70
|
-
let
|
|
71
|
-
return (
|
|
72
|
-
var
|
|
73
|
-
|
|
97
|
+
let u = !1;
|
|
98
|
+
return (p = (d = g.current) == null ? void 0 : d.remove) == null || p.call(d), g.current = null, q(i).then((l) => {
|
|
99
|
+
var x;
|
|
100
|
+
u ? (x = l == null ? void 0 : l.remove) == null || x.call(l) : g.current = l;
|
|
74
101
|
}), () => {
|
|
75
|
-
|
|
102
|
+
u = !0;
|
|
76
103
|
};
|
|
77
|
-
}, [
|
|
78
|
-
var
|
|
104
|
+
}, [W]), X(() => {
|
|
105
|
+
var d;
|
|
79
106
|
if (typeof window > "u" || !window.matchMedia) return;
|
|
80
|
-
const i = window.matchMedia("(prefers-reduced-motion: reduce)"),
|
|
81
|
-
|
|
107
|
+
const i = window.matchMedia("(prefers-reduced-motion: reduce)"), u = () => {
|
|
108
|
+
B.current = i.matches;
|
|
82
109
|
};
|
|
83
|
-
return
|
|
84
|
-
var
|
|
85
|
-
return (
|
|
110
|
+
return u(), (d = i.addEventListener) == null || d.call(i, "change", u), () => {
|
|
111
|
+
var p;
|
|
112
|
+
return (p = i.removeEventListener) == null ? void 0 : p.call(i, "change", u);
|
|
86
113
|
};
|
|
87
114
|
}, []), X(() => () => {
|
|
88
|
-
var i,
|
|
89
|
-
(
|
|
115
|
+
var i, u, d, p;
|
|
116
|
+
(u = (i = g.current) == null ? void 0 : i.remove) == null || u.call(i), (p = (d = f.current) == null ? void 0 : d.destroy) == null || p.call(d), f.current = null, g.current = null, b.current = !1;
|
|
90
117
|
}, []), J((i) => {
|
|
91
|
-
var t,
|
|
118
|
+
var t, s;
|
|
92
119
|
i.gl.render(i.scene, i.camera);
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
!
|
|
97
|
-
{ device:
|
|
98
|
-
{ getSceneDepth:
|
|
99
|
-
).then((m) => (
|
|
100
|
-
|
|
120
|
+
const u = performance.now(), d = C.current ? Math.min(0.05, (u - C.current) / 1e3) : 0.016;
|
|
121
|
+
C.current = u;
|
|
122
|
+
const p = i.gl, l = p.backend, x = (l == null ? void 0 : l.context) || ((s = (t = p.domElement) == null ? void 0 : t.getContext) == null ? void 0 : s.call(t, "webgpu"));
|
|
123
|
+
!f.current && !b.current && (l != null && l.device) && x && (b.current = !0, Y(
|
|
124
|
+
{ device: l.device, context: x, canvas: p.domElement },
|
|
125
|
+
{ getSceneDepth: H ? () => null : $(p) }
|
|
126
|
+
).then((m) => (f.current = m, q(m))).then((m) => {
|
|
127
|
+
g.current = m;
|
|
101
128
|
}).catch((m) => console.error("[HZFaithfulFX] init failed:", m)));
|
|
102
|
-
const E =
|
|
129
|
+
const E = f.current;
|
|
103
130
|
if (E) {
|
|
104
131
|
const m = i.camera;
|
|
105
|
-
E.setCamera(m.projectionMatrix.elements, m.matrixWorldInverse.elements, m.position),
|
|
132
|
+
E.setCamera(m.projectionMatrix.elements, m.matrixWorldInverse.elements, m.position), I && B.current || E.render(d);
|
|
106
133
|
}
|
|
107
|
-
},
|
|
134
|
+
}, z), null;
|
|
108
135
|
}
|
|
109
|
-
const
|
|
136
|
+
const ne = (
|
|
110
137
|
/* glsl */
|
|
111
138
|
`
|
|
112
139
|
attribute vec4 aColor;
|
|
@@ -116,7 +143,7 @@ void main() {
|
|
|
116
143
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
117
144
|
}
|
|
118
145
|
`
|
|
119
|
-
),
|
|
146
|
+
), te = (
|
|
120
147
|
/* glsl */
|
|
121
148
|
`
|
|
122
149
|
varying vec4 vColor;
|
|
@@ -125,104 +152,104 @@ void main() {
|
|
|
125
152
|
}
|
|
126
153
|
`
|
|
127
154
|
);
|
|
128
|
-
function
|
|
155
|
+
function ce({
|
|
129
156
|
positionRef: r,
|
|
130
157
|
duration: n = 1,
|
|
131
|
-
width:
|
|
158
|
+
width: v = 0.3,
|
|
132
159
|
color: e = [1, 1, 1],
|
|
133
|
-
maxPoints:
|
|
134
|
-
minDistance:
|
|
135
|
-
opacity:
|
|
136
|
-
blending:
|
|
137
|
-
visible:
|
|
160
|
+
maxPoints: o = 256,
|
|
161
|
+
minDistance: z = 0.05,
|
|
162
|
+
opacity: H = 1,
|
|
163
|
+
blending: I = c.AdditiveBlending,
|
|
164
|
+
visible: f = !0
|
|
138
165
|
}) {
|
|
139
|
-
const { camera:
|
|
140
|
-
positions: new Float32Array(
|
|
141
|
-
times: new Float32Array(
|
|
166
|
+
const { camera: g } = Q(), b = A(null), C = A({
|
|
167
|
+
positions: new Float32Array(o * 3),
|
|
168
|
+
times: new Float32Array(o),
|
|
142
169
|
head: 0,
|
|
143
170
|
count: 0,
|
|
144
|
-
lastPos: new
|
|
171
|
+
lastPos: new c.Vector3(1 / 0, 1 / 0, 1 / 0),
|
|
145
172
|
elapsed: 0
|
|
146
|
-
}), { geometry:
|
|
147
|
-
const
|
|
148
|
-
m.setUsage(
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
for (let
|
|
153
|
-
const
|
|
154
|
-
|
|
173
|
+
}), { geometry: F, posAttr: V, colorAttr: B, indexBuf: W } = O(() => {
|
|
174
|
+
const x = o * 2, E = new Float32Array(x * 3), t = new Float32Array(x * 4), s = new c.BufferGeometry(), m = new c.BufferAttribute(E, 3);
|
|
175
|
+
m.setUsage(c.DynamicDrawUsage), s.setAttribute("position", m);
|
|
176
|
+
const M = new c.BufferAttribute(t, 4);
|
|
177
|
+
M.setUsage(c.DynamicDrawUsage), s.setAttribute("aColor", M);
|
|
178
|
+
const w = (o - 1) * 6, h = new Uint32Array(w);
|
|
179
|
+
for (let D = 0; D < o - 1; D++) {
|
|
180
|
+
const a = D * 2, S = D * 6;
|
|
181
|
+
h[S] = a, h[S + 1] = a + 1, h[S + 2] = a + 2, h[S + 3] = a + 1, h[S + 4] = a + 3, h[S + 5] = a + 2;
|
|
155
182
|
}
|
|
156
|
-
const
|
|
157
|
-
return
|
|
158
|
-
}, [
|
|
159
|
-
vertexShader:
|
|
160
|
-
fragmentShader:
|
|
183
|
+
const T = new c.BufferAttribute(h, 1);
|
|
184
|
+
return s.setIndex(T), s.setDrawRange(0, 0), { geometry: s, posAttr: m, colorAttr: M, indexBuf: T };
|
|
185
|
+
}, [o]), q = O(() => new c.ShaderMaterial({
|
|
186
|
+
vertexShader: ne,
|
|
187
|
+
fragmentShader: te,
|
|
161
188
|
transparent: !0,
|
|
162
189
|
depthWrite: !1,
|
|
163
|
-
side:
|
|
164
|
-
blending:
|
|
165
|
-
}), [
|
|
166
|
-
return J((
|
|
167
|
-
if (!
|
|
168
|
-
const t =
|
|
169
|
-
if (t.elapsed += E, !
|
|
170
|
-
t.count = 0, t.head = 0, t.lastPos.set(1 / 0, 1 / 0, 1 / 0),
|
|
190
|
+
side: c.DoubleSide,
|
|
191
|
+
blending: I
|
|
192
|
+
}), [I]), i = O(() => new c.Vector3(), []), u = O(() => new c.Vector3(), []), d = O(() => new c.Vector3(), []), p = O(() => new c.Vector3(0, 1, 0), []), l = O(() => new c.Vector3(), []);
|
|
193
|
+
return J((x, E) => {
|
|
194
|
+
if (!b.current) return;
|
|
195
|
+
const t = C.current;
|
|
196
|
+
if (t.elapsed += E, !f) {
|
|
197
|
+
t.count = 0, t.head = 0, t.lastPos.set(1 / 0, 1 / 0, 1 / 0), F.setDrawRange(0, 0);
|
|
171
198
|
return;
|
|
172
199
|
}
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
175
|
-
if (t.lastPos.distanceTo(
|
|
176
|
-
const
|
|
177
|
-
t.positions[
|
|
200
|
+
const s = r.current;
|
|
201
|
+
if (!s) return;
|
|
202
|
+
if (t.lastPos.distanceTo(s) >= z) {
|
|
203
|
+
const a = (t.head + t.count) % o;
|
|
204
|
+
t.positions[a * 3] = s.x, t.positions[a * 3 + 1] = s.y, t.positions[a * 3 + 2] = s.z, t.times[a] = t.elapsed, t.count < o ? t.count++ : t.head = (t.head + 1) % o, t.lastPos.copy(s);
|
|
178
205
|
}
|
|
179
206
|
for (; t.count > 0; ) {
|
|
180
|
-
const
|
|
181
|
-
if (t.elapsed - t.times[
|
|
182
|
-
t.head = (t.head + 1) %
|
|
207
|
+
const a = t.head;
|
|
208
|
+
if (t.elapsed - t.times[a] > n)
|
|
209
|
+
t.head = (t.head + 1) % o, t.count--;
|
|
183
210
|
else
|
|
184
211
|
break;
|
|
185
212
|
}
|
|
186
213
|
if (t.count < 2) {
|
|
187
|
-
|
|
214
|
+
F.setDrawRange(0, 0);
|
|
188
215
|
return;
|
|
189
216
|
}
|
|
190
|
-
const
|
|
191
|
-
let
|
|
192
|
-
const
|
|
193
|
-
for (let
|
|
194
|
-
const
|
|
195
|
-
if (
|
|
196
|
-
const _ = (t.head +
|
|
217
|
+
const M = V.array, w = B.array;
|
|
218
|
+
let h = null;
|
|
219
|
+
const T = t.count;
|
|
220
|
+
for (let a = 0; a < T; a++) {
|
|
221
|
+
const S = (t.head + a) % o, j = t.positions[S * 3], P = t.positions[S * 3 + 1], N = t.positions[S * 3 + 2], Z = 1 - (t.elapsed - t.times[S]) / n;
|
|
222
|
+
if (a < T - 1) {
|
|
223
|
+
const _ = (t.head + a + 1) % o;
|
|
197
224
|
i.set(
|
|
198
|
-
t.positions[_ * 3] -
|
|
199
|
-
t.positions[_ * 3 + 1] -
|
|
200
|
-
t.positions[_ * 3 + 2] -
|
|
225
|
+
t.positions[_ * 3] - j,
|
|
226
|
+
t.positions[_ * 3 + 1] - P,
|
|
227
|
+
t.positions[_ * 3 + 2] - N
|
|
201
228
|
);
|
|
202
229
|
const k = i.length();
|
|
203
|
-
k > 1e-6 ? i.divideScalar(k) :
|
|
204
|
-
} else
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
),
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
const L =
|
|
213
|
-
|
|
230
|
+
k > 1e-6 ? i.divideScalar(k) : h && i.copy(h);
|
|
231
|
+
} else h && i.copy(h);
|
|
232
|
+
d.set(
|
|
233
|
+
g.position.x - j,
|
|
234
|
+
g.position.y - P,
|
|
235
|
+
g.position.z - N
|
|
236
|
+
), u.crossVectors(i, d);
|
|
237
|
+
let U = u.length();
|
|
238
|
+
U < 1e-6 && (l.crossVectors(i, p), u.copy(l), U = u.length(), U < 1e-6 && (u.set(1, 0, 0), U = 1)), u.divideScalar(U);
|
|
239
|
+
const L = v * Z, G = H * Z * Z, R = a * 2;
|
|
240
|
+
M[R * 3] = j + u.x * L, M[R * 3 + 1] = P + u.y * L, M[R * 3 + 2] = N + u.z * L, M[(R + 1) * 3] = j - u.x * L, M[(R + 1) * 3 + 1] = P - u.y * L, M[(R + 1) * 3 + 2] = N - u.z * L, w[R * 4] = e[0], w[R * 4 + 1] = e[1], w[R * 4 + 2] = e[2], w[R * 4 + 3] = G, w[(R + 1) * 4] = e[0], w[(R + 1) * 4 + 1] = e[1], w[(R + 1) * 4 + 2] = e[2], w[(R + 1) * 4 + 3] = G, h = h || new c.Vector3(), h.copy(i);
|
|
214
241
|
}
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
}), /* @__PURE__ */
|
|
242
|
+
const D = (T - 1) * 6;
|
|
243
|
+
F.setDrawRange(0, D), V.needsUpdate = !0, B.needsUpdate = !0;
|
|
244
|
+
}), /* @__PURE__ */ y(
|
|
218
245
|
"mesh",
|
|
219
246
|
{
|
|
220
|
-
ref:
|
|
221
|
-
geometry:
|
|
247
|
+
ref: b,
|
|
248
|
+
geometry: F,
|
|
222
249
|
material: q,
|
|
223
250
|
frustumCulled: !1,
|
|
224
251
|
renderOrder: 101,
|
|
225
|
-
visible:
|
|
252
|
+
visible: f
|
|
226
253
|
}
|
|
227
254
|
);
|
|
228
255
|
}
|
|
@@ -233,37 +260,37 @@ function re(r) {
|
|
|
233
260
|
const n = Math.sin(r * 54321.67) * 43758.5453 % 1;
|
|
234
261
|
return n < 0 ? n + 1 : n;
|
|
235
262
|
}
|
|
236
|
-
function
|
|
237
|
-
if (
|
|
238
|
-
const
|
|
239
|
-
let
|
|
263
|
+
function pe(r, n, v, e) {
|
|
264
|
+
if (v <= 0) return 0;
|
|
265
|
+
const o = n / v;
|
|
266
|
+
let z = r.particleSize ?? 0.5;
|
|
240
267
|
if (r.randomSize) {
|
|
241
|
-
const
|
|
242
|
-
|
|
268
|
+
const I = r.minSize ?? 0.1, f = r.maxSize ?? 0.5;
|
|
269
|
+
z = I + (f - I) * re(v);
|
|
243
270
|
}
|
|
244
|
-
const
|
|
245
|
-
if (r.fadeSizeEnabled && (
|
|
246
|
-
const
|
|
247
|
-
|
|
271
|
+
const H = Math.max(0.01, Math.min(10, r.sizeLifetimeSpeed ?? 1));
|
|
272
|
+
if (r.fadeSizeEnabled && (z *= 1 - Math.pow(o, 1 / H)), r.increaseSizeEnabled && (z *= 1 + Math.pow(o, 1 / H)), r.pulseEnabled) {
|
|
273
|
+
const I = r.pulseAmplitude ?? 0.5, f = r.pulseFrequency ?? 1, b = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
|
|
274
|
+
z *= 1 + I * Math.sin(n * f * Math.PI * 2 + b);
|
|
248
275
|
}
|
|
249
|
-
return Math.max(0,
|
|
276
|
+
return Math.max(0, z);
|
|
250
277
|
}
|
|
251
|
-
function
|
|
252
|
-
if (
|
|
253
|
-
let
|
|
254
|
-
const
|
|
255
|
-
if (r.fadeEnabled && (
|
|
256
|
-
const
|
|
257
|
-
|
|
278
|
+
function se(r, n, v, e) {
|
|
279
|
+
if (v <= 0) return 0;
|
|
280
|
+
let o = r.opacity ?? 1;
|
|
281
|
+
const z = n / v;
|
|
282
|
+
if (r.fadeEnabled && (o *= Math.max(0, 1 - z)), r.pulseEnabled && r.pulseOpacity) {
|
|
283
|
+
const H = r.pulseAmplitude ?? 0.5, I = r.pulseFrequency ?? 1, g = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
|
|
284
|
+
o *= Math.max(0, 1 + H * Math.sin(n * I * Math.PI * 2 + g));
|
|
258
285
|
}
|
|
259
|
-
return Math.max(0, Math.min(1,
|
|
286
|
+
return Math.max(0, Math.min(1, o));
|
|
260
287
|
}
|
|
261
288
|
export {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
289
|
+
le as HZFaithfulFX,
|
|
290
|
+
ce as HZTrailRibbon,
|
|
291
|
+
se as computeParticleOpacity,
|
|
292
|
+
pe as computeParticleSize,
|
|
293
|
+
fe as fetchPreset,
|
|
267
294
|
K as particleHash,
|
|
268
295
|
ee as scalePreset
|
|
269
296
|
};
|