r3f-vfx 0.1.8 → 0.2.0
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 +471 -471
- package/dist/index.d.ts +25 -233
- package/dist/index.js +455 -1411
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,226 +1,45 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { RefObject, ReactNode } from 'react';
|
|
3
|
-
import * as
|
|
4
|
-
import {
|
|
5
|
-
export { Appearance, AttractorConfig, AttractorType, BaseParticleProps, Blending, CollisionConfig, CurveChannel, CurveData, CurvePoint, CurveTextureResult, Easing, EmitterShape, FlipbookConfig, FrictionConfig, Lighting, ParticleData, Rotation3DInput, StretchConfig, TurbulenceConfig, bakeCurveToArray, buildCurveTextureBin, createCombinedCurveTexture } from 'core-vfx';
|
|
3
|
+
import * as core_vfx from 'core-vfx';
|
|
4
|
+
import { VFXParticleSystemOptions, EmitterControllerOptions, CoreState } from 'core-vfx';
|
|
5
|
+
export { Appearance, AttractorConfig, AttractorType, BaseParticleProps, Blending, CollisionConfig, CurveChannel, CurveData, CurvePoint, CurveTextureResolved, CurveTextureResult, Easing, EmitterController, EmitterControllerOptions, EmitterShape, FlipbookConfig, FrictionConfig, Lighting, NormalizedParticleProps, ParticleData, Rotation3DInput, StretchConfig, TurbulenceConfig, VFXParticleSystem, VFXParticleSystemOptions, bakeCurveToArray, buildCurveTextureBin, createCombinedCurveTexture, isNonDefaultRotation, isWebGPUBackend, normalizeProps, resolveCurveTexture } from 'core-vfx';
|
|
6
6
|
|
|
7
|
-
type VFXParticlesProps = {
|
|
7
|
+
type VFXParticlesProps = VFXParticleSystemOptions & {
|
|
8
8
|
/** Optional name for registering with useVFXStore (enables VFXEmitter linking) */
|
|
9
9
|
name?: string;
|
|
10
|
-
/** Maximum number of particles */
|
|
11
|
-
maxParticles?: number;
|
|
12
|
-
/** Particle size [min, max] or single value */
|
|
13
|
-
size?: number | [number, number];
|
|
14
|
-
/** Array of hex color strings for start color */
|
|
15
|
-
colorStart?: string[];
|
|
16
|
-
/** Array of hex color strings for end color (null = use colorStart) */
|
|
17
|
-
colorEnd?: string[] | null;
|
|
18
|
-
/** Fade size [start, end] multiplier over lifetime */
|
|
19
|
-
fadeSize?: number | [number, number];
|
|
20
|
-
/** Curve data for size over lifetime */
|
|
21
|
-
fadeSizeCurve?: CurveData;
|
|
22
|
-
/** Fade opacity [start, end] multiplier over lifetime */
|
|
23
|
-
fadeOpacity?: number | [number, number];
|
|
24
|
-
/** Curve data for opacity over lifetime */
|
|
25
|
-
fadeOpacityCurve?: CurveData;
|
|
26
|
-
/** Curve data for velocity over lifetime */
|
|
27
|
-
velocityCurve?: CurveData;
|
|
28
|
-
/** Gravity vector [x, y, z] */
|
|
29
|
-
gravity?: [number, number, number];
|
|
30
|
-
/** Particle lifetime in seconds [min, max] or single value */
|
|
31
|
-
lifetime?: number | [number, number];
|
|
32
|
-
/** Direction ranges for velocity */
|
|
33
|
-
direction?: Rotation3DInput;
|
|
34
|
-
/** Start position offset ranges */
|
|
35
|
-
startPosition?: Rotation3DInput;
|
|
36
|
-
/** Speed [min, max] or single value */
|
|
37
|
-
speed?: number | [number, number];
|
|
38
|
-
/** Friction settings */
|
|
39
|
-
friction?: {
|
|
40
|
-
intensity?: number | [number, number];
|
|
41
|
-
easing?: string;
|
|
42
|
-
};
|
|
43
|
-
/** Particle appearance type */
|
|
44
|
-
appearance?: (typeof Appearance)[keyof typeof Appearance];
|
|
45
|
-
/** Alpha map texture */
|
|
46
|
-
alphaMap?: THREE.Texture | null;
|
|
47
|
-
/** Flipbook animation settings */
|
|
48
|
-
flipbook?: {
|
|
49
|
-
rows: number;
|
|
50
|
-
columns: number;
|
|
51
|
-
} | null;
|
|
52
|
-
/** Rotation [min, max] in radians or 3D rotation ranges */
|
|
53
|
-
rotation?: Rotation3DInput;
|
|
54
|
-
/** Rotation speed [min, max] in radians/second or 3D ranges */
|
|
55
|
-
rotationSpeed?: Rotation3DInput;
|
|
56
|
-
/** Curve data for rotation speed over lifetime */
|
|
57
|
-
rotationSpeedCurve?: CurveData;
|
|
58
|
-
/** Custom geometry for 3D particles */
|
|
59
|
-
geometry?: THREE.BufferGeometry | null;
|
|
60
|
-
/** Rotate geometry to face velocity direction */
|
|
61
|
-
orientToDirection?: boolean;
|
|
62
|
-
/** Which local axis aligns with velocity */
|
|
63
|
-
orientAxis?: string;
|
|
64
|
-
/** Stretch particles based on speed */
|
|
65
|
-
stretchBySpeed?: {
|
|
66
|
-
factor: number;
|
|
67
|
-
maxStretch: number;
|
|
68
|
-
} | null;
|
|
69
|
-
/** Material lighting type for geometry mode */
|
|
70
|
-
lighting?: (typeof Lighting)[keyof typeof Lighting];
|
|
71
|
-
/** Enable shadows on geometry instances */
|
|
72
|
-
shadow?: boolean;
|
|
73
|
-
/** Blending mode */
|
|
74
|
-
blending?: THREE.Blending;
|
|
75
|
-
/** Color intensity multiplier */
|
|
76
|
-
intensity?: number;
|
|
77
|
-
/** Emitter position [x, y, z] */
|
|
78
|
-
position?: [number, number, number];
|
|
79
|
-
/** Start emitting automatically */
|
|
80
|
-
autoStart?: boolean;
|
|
81
|
-
/** Delay between emissions in seconds */
|
|
82
|
-
delay?: number;
|
|
83
|
-
/** TSL node or function for backdrop sampling */
|
|
84
|
-
backdropNode?: any | ((data: ParticleData) => any) | null;
|
|
85
|
-
/** TSL node or function for custom opacity */
|
|
86
|
-
opacityNode?: any | ((data: ParticleData) => any) | null;
|
|
87
|
-
/** TSL node or function to override color */
|
|
88
|
-
colorNode?: any | ((data: ParticleData, defaultColor: any) => any) | null;
|
|
89
|
-
/** TSL node or function for alpha test/discard */
|
|
90
|
-
alphaTestNode?: any | ((data: ParticleData) => any) | null;
|
|
91
|
-
/** TSL node or function for shadow map output */
|
|
92
|
-
castShadowNode?: any | ((data: ParticleData) => any) | null;
|
|
93
|
-
/** Number of particles to emit per frame */
|
|
94
|
-
emitCount?: number;
|
|
95
|
-
/** Emitter shape type */
|
|
96
|
-
emitterShape?: (typeof EmitterShape)[keyof typeof EmitterShape];
|
|
97
|
-
/** Emitter radius [inner, outer] */
|
|
98
|
-
emitterRadius?: number | [number, number];
|
|
99
|
-
/** Cone angle in radians */
|
|
100
|
-
emitterAngle?: number;
|
|
101
|
-
/** Cone height [min, max] */
|
|
102
|
-
emitterHeight?: number | [number, number];
|
|
103
|
-
/** Emit from surface only */
|
|
104
|
-
emitterSurfaceOnly?: boolean;
|
|
105
|
-
/** Direction for cone/disk normal */
|
|
106
|
-
emitterDirection?: [number, number, number];
|
|
107
|
-
/** Turbulence settings */
|
|
108
|
-
turbulence?: {
|
|
109
|
-
intensity: number;
|
|
110
|
-
frequency?: number;
|
|
111
|
-
speed?: number;
|
|
112
|
-
} | null;
|
|
113
|
-
/** Array of attractors (max 4) */
|
|
114
|
-
attractors?: Array<{
|
|
115
|
-
position?: [number, number, number];
|
|
116
|
-
strength?: number;
|
|
117
|
-
radius?: number;
|
|
118
|
-
type?: 'point' | 'vortex';
|
|
119
|
-
axis?: [number, number, number];
|
|
120
|
-
}> | null;
|
|
121
|
-
/** Particles move from spawn position to center over lifetime */
|
|
122
|
-
attractToCenter?: boolean;
|
|
123
|
-
/** Use start position offset as direction */
|
|
124
|
-
startPositionAsDirection?: boolean;
|
|
125
|
-
/** Fade particles when intersecting scene geometry */
|
|
126
|
-
softParticles?: boolean;
|
|
127
|
-
/** Distance over which to fade soft particles */
|
|
128
|
-
softDistance?: number;
|
|
129
|
-
/** Plane collision settings */
|
|
130
|
-
collision?: {
|
|
131
|
-
plane?: {
|
|
132
|
-
y: number;
|
|
133
|
-
};
|
|
134
|
-
bounce?: number;
|
|
135
|
-
friction?: number;
|
|
136
|
-
die?: boolean;
|
|
137
|
-
sizeBasedGravity?: number;
|
|
138
|
-
} | null;
|
|
139
10
|
/** Show debug control panel */
|
|
140
11
|
debug?: boolean;
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
12
|
+
/** Optional fallback content to render when WebGPU is not available */
|
|
13
|
+
fallback?: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
declare const VFXParticles: react.ForwardRefExoticComponent<core_vfx.BaseParticleProps & {
|
|
16
|
+
backdropNode?: any | ((data: core_vfx.ParticleData) => any) | null;
|
|
17
|
+
opacityNode?: any | ((data: core_vfx.ParticleData) => any) | null;
|
|
18
|
+
colorNode?: any | ((data: core_vfx.ParticleData, defaultColor: any) => any) | null;
|
|
19
|
+
alphaTestNode?: any | ((data: core_vfx.ParticleData) => any) | null;
|
|
20
|
+
castShadowNode?: any | ((data: core_vfx.ParticleData) => any) | null;
|
|
144
21
|
depthTest?: boolean;
|
|
145
|
-
/** Render order (higher values render on top) */
|
|
146
22
|
renderOrder?: number;
|
|
147
|
-
|
|
148
|
-
|
|
23
|
+
curveTexturePath?: string | null;
|
|
24
|
+
} & {
|
|
25
|
+
/** Optional name for registering with useVFXStore (enables VFXEmitter linking) */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** Show debug control panel */
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
/** Optional fallback content to render when WebGPU is not available */
|
|
30
|
+
fallback?: React.ReactNode;
|
|
31
|
+
} & react.RefAttributes<unknown>>;
|
|
149
32
|
|
|
150
|
-
interface VFXEmitterProps {
|
|
33
|
+
interface VFXEmitterProps extends EmitterControllerOptions {
|
|
151
34
|
/** Name of the registered VFXParticles system */
|
|
152
35
|
name?: string;
|
|
153
36
|
/** Direct ref to VFXParticles (alternative to name) */
|
|
154
37
|
particlesRef?: RefObject<any> | any;
|
|
155
38
|
/** Local position offset */
|
|
156
39
|
position?: [number, number, number];
|
|
157
|
-
/** Particles to emit per burst */
|
|
158
|
-
emitCount?: number;
|
|
159
|
-
/** Seconds between emissions (0 = every frame) */
|
|
160
|
-
delay?: number;
|
|
161
|
-
/** Start emitting automatically */
|
|
162
|
-
autoStart?: boolean;
|
|
163
|
-
/** Keep emitting (false = emit once) */
|
|
164
|
-
loop?: boolean;
|
|
165
|
-
/** Transform direction by parent's world rotation */
|
|
166
|
-
localDirection?: boolean;
|
|
167
|
-
/** Direction override [[minX,maxX],[minY,maxY],[minZ,maxZ]] */
|
|
168
|
-
direction?: [[number, number], [number, number], [number, number]];
|
|
169
|
-
/** Per-spawn overrides (size, speed, colors, etc.) */
|
|
170
|
-
overrides?: Record<string, any> | null;
|
|
171
|
-
/** Callback fired after each emission */
|
|
172
|
-
onEmit?: (params: {
|
|
173
|
-
position: [number, number, number] | number[];
|
|
174
|
-
count: number;
|
|
175
|
-
direction: any;
|
|
176
|
-
}) => void;
|
|
177
40
|
/** Children elements */
|
|
178
41
|
children?: ReactNode;
|
|
179
42
|
}
|
|
180
|
-
/**
|
|
181
|
-
* VFXEmitter - A reusable emitter component that links to a VFXParticles system
|
|
182
|
-
*
|
|
183
|
-
* Multiple VFXEmitters can share a single VFXParticles instance without adding
|
|
184
|
-
* supplementary draw calls. Each emitter just calls spawn() on the shared system.
|
|
185
|
-
*
|
|
186
|
-
* The emitter renders a <group> that inherits parent transforms automatically,
|
|
187
|
-
* so you can place it as a child of any object and it will follow.
|
|
188
|
-
*
|
|
189
|
-
* Usage:
|
|
190
|
-
*
|
|
191
|
-
* // First, set up a VFXParticles with a name
|
|
192
|
-
* <VFXParticles name="sparks" maxParticles={1000} autoStart={false} ... />
|
|
193
|
-
*
|
|
194
|
-
* // Place emitter as child - it automatically follows parent transforms!
|
|
195
|
-
* <group ref={playerRef}>
|
|
196
|
-
* <VFXEmitter
|
|
197
|
-
* name="sparks"
|
|
198
|
-
* position={[0, 1, 0]} // Local offset from parent
|
|
199
|
-
* emitCount={5}
|
|
200
|
-
* delay={0.1}
|
|
201
|
-
* />
|
|
202
|
-
* </group>
|
|
203
|
-
*
|
|
204
|
-
* // Use localDirection to emit relative to parent's rotation
|
|
205
|
-
* <VFXEmitter
|
|
206
|
-
* name="sparks"
|
|
207
|
-
* direction={[[0, 0], [0, 0], [-1, -1]]} // Emit backward in local space
|
|
208
|
-
* localDirection={true} // Direction is transformed by parent's rotation
|
|
209
|
-
* />
|
|
210
|
-
*
|
|
211
|
-
* @param {object} props
|
|
212
|
-
* @param {string} props.name - Name of the registered VFXParticles system
|
|
213
|
-
* @param {object} [props.particlesRef] - Direct ref to VFXParticles (alternative to name)
|
|
214
|
-
* @param {[number, number, number]} [props.position=[0,0,0]] - Local position offset
|
|
215
|
-
* @param {number} [props.emitCount=10] - Particles to emit per burst
|
|
216
|
-
* @param {number} [props.delay=0] - Seconds between emissions (0 = every frame)
|
|
217
|
-
* @param {boolean} [props.autoStart=true] - Start emitting automatically
|
|
218
|
-
* @param {boolean} [props.loop=true] - Keep emitting (false = emit once)
|
|
219
|
-
* @param {boolean} [props.localDirection=false] - Transform direction by parent's world rotation
|
|
220
|
-
* @param {array} [props.direction] - Direction override [[minX,maxX],[minY,maxY],[minZ,maxZ]]
|
|
221
|
-
* @param {object} [props.overrides] - Per-spawn overrides (size, speed, colors, etc.)
|
|
222
|
-
* @param {function} [props.onEmit] - Callback fired after each emission
|
|
223
|
-
*/
|
|
224
43
|
declare const VFXEmitter: react.ForwardRefExoticComponent<VFXEmitterProps & react.RefAttributes<unknown>>;
|
|
225
44
|
/**
|
|
226
45
|
* Higher-order hook for programmatic emitter control
|
|
@@ -242,14 +61,7 @@ declare function useVFXEmitter(name: string): {
|
|
|
242
61
|
clear: () => boolean;
|
|
243
62
|
isEmitting: () => boolean;
|
|
244
63
|
getUniforms: () => Record<string, unknown> | null;
|
|
245
|
-
getParticles: () =>
|
|
246
|
-
spawn: (x: number, y: number, z: number, count: number, overrides?: Record<string, unknown> | null) => void;
|
|
247
|
-
start: () => void;
|
|
248
|
-
stop: () => void;
|
|
249
|
-
clear: () => void;
|
|
250
|
-
isEmitting: boolean;
|
|
251
|
-
uniforms: Record<string, unknown>;
|
|
252
|
-
} | null;
|
|
64
|
+
getParticles: () => core_vfx.ParticleSystemRef | null;
|
|
253
65
|
};
|
|
254
66
|
|
|
255
67
|
declare function useVFXStoreImpl(): CoreState;
|
|
@@ -264,24 +76,4 @@ declare const useVFXStore: typeof useVFXStoreImpl & {
|
|
|
264
76
|
getInitialState: () => CoreState;
|
|
265
77
|
};
|
|
266
78
|
|
|
267
|
-
type
|
|
268
|
-
texture: THREE.DataTexture;
|
|
269
|
-
/** Per-channel enabled state, combining curve props and loaded .bin channels */
|
|
270
|
-
sizeEnabled: boolean;
|
|
271
|
-
opacityEnabled: boolean;
|
|
272
|
-
velocityEnabled: boolean;
|
|
273
|
-
rotationSpeedEnabled: boolean;
|
|
274
|
-
};
|
|
275
|
-
/**
|
|
276
|
-
* Hook for curve texture loading/baking.
|
|
277
|
-
*
|
|
278
|
-
* If curveTexturePath is provided, loads pre-baked texture from file.
|
|
279
|
-
* The .bin file contains a header with a bitmask of which channels are active.
|
|
280
|
-
* Only those channels override the curve props; the rest use curve props or defaults.
|
|
281
|
-
*
|
|
282
|
-
* If curves are defined (no path), bakes them synchronously on the main thread.
|
|
283
|
-
* If no curves AND no path, returns default texture (no baking needed).
|
|
284
|
-
*/
|
|
285
|
-
declare const useCurveTextureAsync: (sizeCurve: CurveData | null, opacityCurve: CurveData | null, velocityCurve: CurveData | null, rotationSpeedCurve: CurveData | null, curveTexturePath?: string | null) => CurveTextureHookResult;
|
|
286
|
-
|
|
287
|
-
export { type CurveTextureHookResult, VFXEmitter, VFXParticles, useCurveTextureAsync, useVFXEmitter, useVFXStore };
|
|
79
|
+
export { VFXEmitter, VFXParticles, type VFXParticlesProps, useVFXEmitter, useVFXStore };
|