r3f-vfx 0.0.7 → 0.0.8

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +252 -0
  2. package/package.json +1 -1
@@ -0,0 +1,252 @@
1
+ import * as react from 'react';
2
+ import { RefObject, ReactNode } from 'react';
3
+ import * as THREE from 'three/webgpu';
4
+ import { CurveData, Rotation3DInput, Appearance, Lighting, ParticleData, EmitterShape, CoreState } from 'core-vfx';
5
+ export { Appearance, AttractorConfig, AttractorType, BaseParticleProps, Blending, CollisionConfig, CurveData, CurvePoint, Easing, EmitterShape, FlipbookConfig, FrictionConfig, Lighting, ParticleData, Rotation3DInput, StretchConfig, TurbulenceConfig, bakeCurveToArray, createCombinedCurveTexture } from 'core-vfx';
6
+
7
+ type VFXParticlesProps = {
8
+ /** Optional name for registering with useVFXStore (enables VFXEmitter linking) */
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
+ /** Show debug control panel */
140
+ debug?: boolean;
141
+ };
142
+ declare const VFXParticles: react.ForwardRefExoticComponent<VFXParticlesProps & react.RefAttributes<unknown>>;
143
+
144
+ interface VFXEmitterProps {
145
+ /** Name of the registered VFXParticles system */
146
+ name?: string;
147
+ /** Direct ref to VFXParticles (alternative to name) */
148
+ particlesRef?: RefObject<any> | any;
149
+ /** Local position offset */
150
+ position?: [number, number, number];
151
+ /** Particles to emit per burst */
152
+ emitCount?: number;
153
+ /** Seconds between emissions (0 = every frame) */
154
+ delay?: number;
155
+ /** Start emitting automatically */
156
+ autoStart?: boolean;
157
+ /** Keep emitting (false = emit once) */
158
+ loop?: boolean;
159
+ /** Transform direction by parent's world rotation */
160
+ localDirection?: boolean;
161
+ /** Direction override [[minX,maxX],[minY,maxY],[minZ,maxZ]] */
162
+ direction?: [[number, number], [number, number], [number, number]];
163
+ /** Per-spawn overrides (size, speed, colors, etc.) */
164
+ overrides?: Record<string, any> | null;
165
+ /** Callback fired after each emission */
166
+ onEmit?: (params: {
167
+ position: [number, number, number] | number[];
168
+ count: number;
169
+ direction: any;
170
+ }) => void;
171
+ /** Children elements */
172
+ children?: ReactNode;
173
+ }
174
+ /**
175
+ * VFXEmitter - A reusable emitter component that links to a VFXParticles system
176
+ *
177
+ * Multiple VFXEmitters can share a single VFXParticles instance without adding
178
+ * supplementary draw calls. Each emitter just calls spawn() on the shared system.
179
+ *
180
+ * The emitter renders a <group> that inherits parent transforms automatically,
181
+ * so you can place it as a child of any object and it will follow.
182
+ *
183
+ * Usage:
184
+ *
185
+ * // First, set up a VFXParticles with a name
186
+ * <VFXParticles name="sparks" maxParticles={1000} autoStart={false} ... />
187
+ *
188
+ * // Place emitter as child - it automatically follows parent transforms!
189
+ * <group ref={playerRef}>
190
+ * <VFXEmitter
191
+ * name="sparks"
192
+ * position={[0, 1, 0]} // Local offset from parent
193
+ * emitCount={5}
194
+ * delay={0.1}
195
+ * />
196
+ * </group>
197
+ *
198
+ * // Use localDirection to emit relative to parent's rotation
199
+ * <VFXEmitter
200
+ * name="sparks"
201
+ * direction={[[0, 0], [0, 0], [-1, -1]]} // Emit backward in local space
202
+ * localDirection={true} // Direction is transformed by parent's rotation
203
+ * />
204
+ *
205
+ * @param {object} props
206
+ * @param {string} props.name - Name of the registered VFXParticles system
207
+ * @param {object} [props.particlesRef] - Direct ref to VFXParticles (alternative to name)
208
+ * @param {[number, number, number]} [props.position=[0,0,0]] - Local position offset
209
+ * @param {number} [props.emitCount=10] - Particles to emit per burst
210
+ * @param {number} [props.delay=0] - Seconds between emissions (0 = every frame)
211
+ * @param {boolean} [props.autoStart=true] - Start emitting automatically
212
+ * @param {boolean} [props.loop=true] - Keep emitting (false = emit once)
213
+ * @param {boolean} [props.localDirection=false] - Transform direction by parent's world rotation
214
+ * @param {array} [props.direction] - Direction override [[minX,maxX],[minY,maxY],[minZ,maxZ]]
215
+ * @param {object} [props.overrides] - Per-spawn overrides (size, speed, colors, etc.)
216
+ * @param {function} [props.onEmit] - Callback fired after each emission
217
+ */
218
+ declare const VFXEmitter: react.ForwardRefExoticComponent<VFXEmitterProps & react.RefAttributes<unknown>>;
219
+ /**
220
+ * Higher-order hook for programmatic emitter control
221
+ *
222
+ * Usage:
223
+ * const { emit, burst, start, stop } = useVFXEmitter("sparks");
224
+ *
225
+ * // Emit at a position
226
+ * emit([1, 2, 3], 50);
227
+ *
228
+ * // Burst with overrides
229
+ * burst([0, 0, 0], 100, { colorStart: ["#ff0000"] });
230
+ */
231
+ declare function useVFXEmitter(name: string): {
232
+ emit: (position?: number[], count?: number, overrides?: null) => boolean;
233
+ burst: (position?: number[], count?: number, overrides?: null) => boolean;
234
+ start: () => boolean;
235
+ stop: () => boolean;
236
+ clear: () => boolean;
237
+ isEmitting: () => boolean;
238
+ getUniforms: () => Record<string, unknown> | null;
239
+ getParticles: () => {
240
+ spawn: (x: number, y: number, z: number, count: number, overrides?: Record<string, unknown> | null) => void;
241
+ start: () => void;
242
+ stop: () => void;
243
+ clear: () => void;
244
+ isEmitting: boolean;
245
+ uniforms: Record<string, unknown>;
246
+ } | null;
247
+ };
248
+
249
+ declare function useVFXStore(): CoreState;
250
+ declare function useVFXStore<T>(selector: (state: CoreState) => T): T;
251
+
252
+ export { VFXEmitter, VFXParticles, useVFXEmitter, useVFXStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "r3f-vfx",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {