@wolffo/three-fire 1.0.1

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/index.js ADDED
@@ -0,0 +1,463 @@
1
+ 'use strict';
2
+
3
+ var three = require('three');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var react = require('react');
6
+ var fiber = require('@react-three/fiber');
7
+
8
+ /**
9
+ * Volumetric fire shader using ray marching and simplex noise
10
+ *
11
+ * Based on "Real-Time procedural volumetric fire" by Alfred et al.
12
+ * Uses simplex noise for turbulence and ray marching for volume rendering.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const material = new ShaderMaterial({
17
+ * defines: FireShader.defines,
18
+ * uniforms: FireShader.uniforms,
19
+ * vertexShader: FireShader.vertexShader,
20
+ * fragmentShader: FireShader.fragmentShader,
21
+ * transparent: true
22
+ * })
23
+ * ```
24
+ */
25
+ const FireShader = {
26
+ defines: {
27
+ ITERATIONS: '20',
28
+ OCTAVES: '3',
29
+ },
30
+ uniforms: {
31
+ fireTex: { value: null },
32
+ color: { value: new three.Color(0xeeeeee) },
33
+ time: { value: 0.0 },
34
+ seed: { value: 0.0 },
35
+ invModelMatrix: { value: new three.Matrix4() },
36
+ scale: { value: new three.Vector3(1, 1, 1) },
37
+ noiseScale: { value: new three.Vector4(1, 2, 1, 0.3) },
38
+ magnitude: { value: 1.3 },
39
+ lacunarity: { value: 2.0 },
40
+ gain: { value: 0.5 },
41
+ },
42
+ vertexShader: /* glsl */ `
43
+ varying vec3 vWorldPos;
44
+
45
+ void main() {
46
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
47
+ vWorldPos = (modelMatrix * vec4(position, 1.0)).xyz;
48
+ }
49
+ `,
50
+ fragmentShader: /* glsl */ `
51
+ uniform vec3 color;
52
+ uniform float time;
53
+ uniform float seed;
54
+ uniform mat4 invModelMatrix;
55
+ uniform vec3 scale;
56
+ uniform vec4 noiseScale;
57
+ uniform float magnitude;
58
+ uniform float lacunarity;
59
+ uniform float gain;
60
+ uniform sampler2D fireTex;
61
+
62
+ varying vec3 vWorldPos;
63
+
64
+ // GLSL simplex noise function by ashima
65
+ vec3 mod289(vec3 x) {
66
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
67
+ }
68
+
69
+ vec4 mod289(vec4 x) {
70
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
71
+ }
72
+
73
+ vec4 permute(vec4 x) {
74
+ return mod289(((x * 34.0) + 1.0) * x);
75
+ }
76
+
77
+ vec4 taylorInvSqrt(vec4 r) {
78
+ return 1.79284291400159 - 0.85373472095314 * r;
79
+ }
80
+
81
+ float snoise(vec3 v) {
82
+ const vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);
83
+ const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
84
+
85
+ vec3 i = floor(v + dot(v, C.yyy));
86
+ vec3 x0 = v - i + dot(i, C.xxx);
87
+
88
+ vec3 g = step(x0.yzx, x0.xyz);
89
+ vec3 l = 1.0 - g;
90
+ vec3 i1 = min(g.xyz, l.zxy);
91
+ vec3 i2 = max(g.xyz, l.zxy);
92
+
93
+ vec3 x1 = x0 - i1 + C.xxx;
94
+ vec3 x2 = x0 - i2 + C.yyy;
95
+ vec3 x3 = x0 - D.yyy;
96
+
97
+ i = mod289(i);
98
+ vec4 p = permute(permute(permute(
99
+ i.z + vec4(0.0, i1.z, i2.z, 1.0))
100
+ + i.y + vec4(0.0, i1.y, i2.y, 1.0))
101
+ + i.x + vec4(0.0, i1.x, i2.x, 1.0));
102
+
103
+ float n_ = 0.142857142857;
104
+ vec3 ns = n_ * D.wyz - D.xzx;
105
+
106
+ vec4 j = p - 49.0 * floor(p * ns.z * ns.z);
107
+
108
+ vec4 x_ = floor(j * ns.z);
109
+ vec4 y_ = floor(j - 7.0 * x_);
110
+
111
+ vec4 x = x_ * ns.x + ns.yyyy;
112
+ vec4 y = y_ * ns.x + ns.yyyy;
113
+ vec4 h = 1.0 - abs(x) - abs(y);
114
+
115
+ vec4 b0 = vec4(x.xy, y.xy);
116
+ vec4 b1 = vec4(x.zw, y.zw);
117
+
118
+ vec4 s0 = floor(b0) * 2.0 + 1.0;
119
+ vec4 s1 = floor(b1) * 2.0 + 1.0;
120
+ vec4 sh = -step(h, vec4(0.0));
121
+
122
+ vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
123
+ vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
124
+
125
+ vec3 p0 = vec3(a0.xy, h.x);
126
+ vec3 p1 = vec3(a0.zw, h.y);
127
+ vec3 p2 = vec3(a1.xy, h.z);
128
+ vec3 p3 = vec3(a1.zw, h.w);
129
+
130
+ vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
131
+ p0 *= norm.x;
132
+ p1 *= norm.y;
133
+ p2 *= norm.z;
134
+ p3 *= norm.w;
135
+
136
+ vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);
137
+ m = m * m;
138
+ return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
139
+ }
140
+
141
+ float turbulence(vec3 p) {
142
+ float sum = 0.0;
143
+ float freq = 1.0;
144
+ float amp = 1.0;
145
+
146
+ for(int i = 0; i < OCTAVES; i++) {
147
+ sum += abs(snoise(p * freq)) * amp;
148
+ freq *= lacunarity;
149
+ amp *= gain;
150
+ }
151
+
152
+ return sum;
153
+ }
154
+
155
+ vec4 samplerFire(vec3 p, vec4 scale) {
156
+ vec2 st = vec2(sqrt(dot(p.xz, p.xz)), p.y);
157
+
158
+ if(st.x <= 0.0 || st.x >= 1.0 || st.y <= 0.0 || st.y >= 1.0) {
159
+ return vec4(0.0);
160
+ }
161
+
162
+ p.y -= (seed + time) * scale.w;
163
+ p *= scale.xyz;
164
+
165
+ st.y += sqrt(st.y) * magnitude * turbulence(p);
166
+
167
+ if(st.y <= 0.0 || st.y >= 1.0) {
168
+ return vec4(0.0);
169
+ }
170
+
171
+ return texture2D(fireTex, st);
172
+ }
173
+
174
+ vec3 localize(vec3 p) {
175
+ return (invModelMatrix * vec4(p, 1.0)).xyz;
176
+ }
177
+
178
+ void main() {
179
+ vec3 rayPos = vWorldPos;
180
+ vec3 rayDir = normalize(rayPos - cameraPosition);
181
+ float rayLen = 0.0288 * length(scale.xyz);
182
+
183
+ vec4 col = vec4(0.0);
184
+
185
+ for(int i = 0; i < ITERATIONS; i++) {
186
+ rayPos += rayDir * rayLen;
187
+ vec3 lp = localize(rayPos);
188
+ lp.y += 0.5;
189
+ lp.xz *= 2.0;
190
+ col += samplerFire(lp, noiseScale);
191
+ }
192
+
193
+ // Apply color tint to the fire
194
+ col.rgb *= color;
195
+ col.a = col.r;
196
+ gl_FragColor = col;
197
+ }
198
+ `,
199
+ };
200
+
201
+ /**
202
+ * Volumetric fire effect using ray marching shaders
203
+ *
204
+ * Creates a procedural fire effect that renders as a translucent volume.
205
+ * The fire shape is defined by a grayscale texture, with white areas being
206
+ * the most dense part of the fire.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * const texture = textureLoader.load('fire.png')
211
+ * const fire = new Fire({
212
+ * fireTex: texture,
213
+ * color: 0xff4400,
214
+ * magnitude: 1.5
215
+ * })
216
+ * scene.add(fire)
217
+ *
218
+ * // In animation loop
219
+ * fire.update(time)
220
+ * ```
221
+ */
222
+ class Fire extends three.Mesh {
223
+ /**
224
+ * Creates a new Fire instance
225
+ *
226
+ * @param props - Configuration options for the fire effect
227
+ */
228
+ constructor({ fireTex, color = 0xeeeeee, iterations = 20, octaves = 3, noiseScale = [1, 2, 1, 0.3], magnitude = 1.3, lacunarity = 2.0, gain = 0.5, }) {
229
+ const geometry = new three.BoxGeometry(1, 1, 1);
230
+ const material = new three.ShaderMaterial({
231
+ defines: {
232
+ ITERATIONS: iterations.toString(),
233
+ OCTAVES: octaves.toString(),
234
+ },
235
+ uniforms: {
236
+ fireTex: { value: fireTex },
237
+ color: { value: color instanceof three.Color ? color : new three.Color(color) },
238
+ time: { value: 0.0 },
239
+ seed: { value: Math.random() * 19.19 },
240
+ invModelMatrix: { value: new three.Matrix4() },
241
+ scale: { value: new three.Vector3(1, 1, 1) },
242
+ noiseScale: { value: new three.Vector4(...noiseScale) },
243
+ magnitude: { value: magnitude },
244
+ lacunarity: { value: lacunarity },
245
+ gain: { value: gain },
246
+ },
247
+ vertexShader: FireShader.vertexShader,
248
+ fragmentShader: FireShader.fragmentShader,
249
+ transparent: true,
250
+ depthWrite: false,
251
+ depthTest: false,
252
+ });
253
+ super(geometry, material);
254
+ this._time = 0;
255
+ // Configure texture
256
+ fireTex.magFilter = fireTex.minFilter = three.LinearFilter;
257
+ fireTex.wrapS = fireTex.wrapT = three.ClampToEdgeWrapping;
258
+ }
259
+ /**
260
+ * Updates the fire animation and matrix uniforms
261
+ *
262
+ * Call this method in your animation loop to animate the fire effect.
263
+ *
264
+ * @param time - Current time in seconds (optional)
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * function animate() {
269
+ * fire.update(performance.now() / 1000)
270
+ * renderer.render(scene, camera)
271
+ * requestAnimationFrame(animate)
272
+ * }
273
+ * ```
274
+ */
275
+ update(time) {
276
+ if (time !== undefined) {
277
+ this._time = time;
278
+ this.material.uniforms.time.value = time;
279
+ }
280
+ this.updateMatrixWorld();
281
+ this.material.uniforms.invModelMatrix.value.copy(this.matrixWorld).invert();
282
+ this.material.uniforms.scale.value.copy(this.scale);
283
+ }
284
+ /**
285
+ * Current animation time in seconds
286
+ */
287
+ get time() {
288
+ return this._time;
289
+ }
290
+ set time(value) {
291
+ this._time = value;
292
+ this.material.uniforms.time.value = value;
293
+ }
294
+ /**
295
+ * Fire color tint
296
+ *
297
+ * @example
298
+ * ```ts
299
+ * fire.fireColor = 'orange'
300
+ * fire.fireColor = 0xff4400
301
+ * fire.fireColor = new Color(1, 0.5, 0)
302
+ * ```
303
+ */
304
+ get fireColor() {
305
+ return this.material.uniforms.color.value;
306
+ }
307
+ set fireColor(color) {
308
+ this.material.uniforms.color.value = color instanceof three.Color ? color : new three.Color(color);
309
+ }
310
+ /**
311
+ * Fire shape intensity
312
+ *
313
+ * Higher values create more dramatic fire shapes.
314
+ * Range: 0.5 - 3.0, Default: 1.3
315
+ */
316
+ get magnitude() {
317
+ return this.material.uniforms.magnitude.value;
318
+ }
319
+ set magnitude(value) {
320
+ this.material.uniforms.magnitude.value = value;
321
+ }
322
+ /**
323
+ * Noise lacunarity (frequency multiplier)
324
+ *
325
+ * Controls how much the frequency increases for each noise octave.
326
+ * Range: 1.0 - 4.0, Default: 2.0
327
+ */
328
+ get lacunarity() {
329
+ return this.material.uniforms.lacunarity.value;
330
+ }
331
+ set lacunarity(value) {
332
+ this.material.uniforms.lacunarity.value = value;
333
+ }
334
+ /**
335
+ * Noise gain (amplitude multiplier)
336
+ *
337
+ * Controls how much the amplitude decreases for each noise octave.
338
+ * Range: 0.1 - 1.0, Default: 0.5
339
+ */
340
+ get gain() {
341
+ return this.material.uniforms.gain.value;
342
+ }
343
+ set gain(value) {
344
+ this.material.uniforms.gain.value = value;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Helper hook for texture loading (alternative to @react-three/drei)
350
+ */
351
+ const useTexture = (url) => fiber.useLoader(three.TextureLoader, url);
352
+ // Extend R3F with our Fire class
353
+ fiber.extend({ Fire: Fire });
354
+ /**
355
+ * React Three Fiber component for volumetric fire effect
356
+ *
357
+ * Creates a procedural fire effect that can be easily integrated into R3F scenes.
358
+ * The component automatically handles texture loading, animation updates, and
359
+ * provides props for all fire parameters.
360
+ *
361
+ * @example
362
+ * ```tsx
363
+ * <Canvas>
364
+ * <Fire
365
+ * texture="/fire.png"
366
+ * color="orange"
367
+ * magnitude={1.5}
368
+ * scale={[2, 3, 2]}
369
+ * position={[0, 0, 0]}
370
+ * />
371
+ * </Canvas>
372
+ * ```
373
+ *
374
+ * @example With custom animation
375
+ * ```tsx
376
+ * <Fire
377
+ * texture="/fire.png"
378
+ * onUpdate={(fire, time) => {
379
+ * fire.fireColor.setHSL((time * 0.1) % 1, 1, 0.5)
380
+ * }}
381
+ * />
382
+ * ```
383
+ */
384
+ const FireComponent = react.forwardRef(({ texture, color = 0xeeeeee, iterations = 20, octaves = 3, noiseScale = [1, 2, 1, 0.3], magnitude = 1.3, lacunarity = 2.0, gain = 0.5, autoUpdate = true, onUpdate, children, ...props }, ref) => {
385
+ const fireRef = react.useRef(null);
386
+ // Load texture if string is provided
387
+ const loadedTexture = useTexture(typeof texture === 'string' ? texture : '');
388
+ const finalTexture = typeof texture === 'string' ? loadedTexture : texture;
389
+ // Memoize fire props to prevent unnecessary recreations
390
+ const fireProps = react.useMemo(() => ({
391
+ fireTex: finalTexture,
392
+ color: color instanceof three.Color ? color : new three.Color(color),
393
+ iterations,
394
+ octaves,
395
+ noiseScale,
396
+ magnitude,
397
+ lacunarity,
398
+ gain,
399
+ }), [finalTexture, color, iterations, octaves, noiseScale, magnitude, lacunarity, gain]);
400
+ // Auto-update with useFrame
401
+ fiber.useFrame((state) => {
402
+ if (fireRef.current && autoUpdate) {
403
+ const time = state.clock.getElapsedTime();
404
+ fireRef.current.update(time);
405
+ onUpdate?.(fireRef.current, time);
406
+ }
407
+ });
408
+ // Expose imperative handle
409
+ react.useImperativeHandle(ref, () => ({
410
+ get fire() {
411
+ return fireRef.current;
412
+ },
413
+ update: (time) => {
414
+ if (fireRef.current) {
415
+ fireRef.current.update(time);
416
+ }
417
+ },
418
+ }), []);
419
+ return (jsxRuntime.jsx("fire", { ref: fireRef, args: [fireProps], ...props, children: children }));
420
+ });
421
+ FireComponent.displayName = 'Fire';
422
+ /**
423
+ * Hook for easier access to fire instance and controls
424
+ *
425
+ * Provides a ref and helper methods for controlling fire imperatively.
426
+ *
427
+ * @returns Object with ref, fire instance, and update method
428
+ *
429
+ * @example
430
+ * ```tsx
431
+ * function MyComponent() {
432
+ * const fireRef = useFire()
433
+ *
434
+ * const handleClick = () => {
435
+ * if (fireRef.fire) {
436
+ * fireRef.fire.magnitude = 2.0
437
+ * }
438
+ * }
439
+ *
440
+ * return (
441
+ * <Fire ref={fireRef.ref} texture="/fire.png" />
442
+ * )
443
+ * }
444
+ * ```
445
+ */
446
+ const useFire = () => {
447
+ const ref = react.useRef(null);
448
+ return {
449
+ /** Ref to pass to Fire component */
450
+ ref,
451
+ /** Fire mesh instance (null until mounted) */
452
+ fire: ref.current?.fire || null,
453
+ /** Update fire animation manually */
454
+ update: (time) => ref.current?.update(time),
455
+ };
456
+ };
457
+
458
+ exports.Fire = FireComponent;
459
+ exports.FireComponent = FireComponent;
460
+ exports.FireMesh = Fire;
461
+ exports.FireShader = FireShader;
462
+ exports.useFire = useFire;
463
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/FireShader.ts","../src/Fire.ts","../src/FireComponent.tsx"],"sourcesContent":[null,null,null],"names":["Color","Matrix4","Vector3","Vector4","Mesh","BoxGeometry","ShaderMaterial","LinearFilter","ClampToEdgeWrapping","useLoader","TextureLoader","extend","FireMesh","forwardRef","useRef","useMemo","useFrame","useImperativeHandle","_jsx"],"mappings":";;;;;;;AA4BA;;;;;;;;;;;;;;;;AAgBG;AACI,MAAM,UAAU,GAAG;AACxB,IAAA,OAAO,EAAE;AACP,QAAA,UAAU,EAAE,IAAI;AAChB,QAAA,OAAO,EAAE,GAAG;AACb,KAAA;AAED,IAAA,QAAQ,EAAE;AACR,QAAA,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;QACxB,KAAK,EAAE,EAAE,KAAK,EAAE,IAAIA,WAAK,CAAC,QAAQ,CAAC,EAAE;AACrC,QAAA,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE;AACpB,QAAA,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE;AACpB,QAAA,cAAc,EAAE,EAAE,KAAK,EAAE,IAAIC,aAAO,EAAE,EAAE;AACxC,QAAA,KAAK,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GAAG,MAAM;AAElC;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACI,MAAM,OAAO,GAAG,MAAK;AAC1B,IAAA,MAAM,GAAG,GAAGJ,YAAM,CAAU,IAAI,CAAC;IACjC,OAAO;;QAEL,GAAG;;AAEH,QAAA,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI;;AAE/B,QAAA,MAAM,EAAE,CAAC,IAAa,KAAK,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC;KACrD;AACH;;;;;;;;"}
@@ -0,0 +1,115 @@
1
+ import { Mesh, ShaderMaterial, Texture, Color } from 'three';
2
+ import { FireShaderUniforms } from './FireShader';
3
+ /**
4
+ * Properties for creating a Fire instance
5
+ */
6
+ export interface FireProps {
7
+ /** Fire texture (grayscale mask defining fire shape) */
8
+ fireTex: Texture;
9
+ /** Fire color tint (default: 0xeeeeee) */
10
+ color?: Color | string | number;
11
+ /** Ray marching iterations - higher = better quality, lower performance (default: 20) */
12
+ iterations?: number;
13
+ /** Noise octaves for turbulence (default: 3) */
14
+ octaves?: number;
15
+ /** Noise scaling parameters [x, y, z, time] (default: [1, 2, 1, 0.3]) */
16
+ noiseScale?: [number, number, number, number];
17
+ /** Fire shape intensity (default: 1.3) */
18
+ magnitude?: number;
19
+ /** Noise lacunarity - frequency multiplier (default: 2.0) */
20
+ lacunarity?: number;
21
+ /** Noise gain - amplitude multiplier (default: 0.5) */
22
+ gain?: number;
23
+ }
24
+ /**
25
+ * Volumetric fire effect using ray marching shaders
26
+ *
27
+ * Creates a procedural fire effect that renders as a translucent volume.
28
+ * The fire shape is defined by a grayscale texture, with white areas being
29
+ * the most dense part of the fire.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const texture = textureLoader.load('fire.png')
34
+ * const fire = new Fire({
35
+ * fireTex: texture,
36
+ * color: 0xff4400,
37
+ * magnitude: 1.5
38
+ * })
39
+ * scene.add(fire)
40
+ *
41
+ * // In animation loop
42
+ * fire.update(time)
43
+ * ```
44
+ */
45
+ export declare class Fire extends Mesh {
46
+ material: ShaderMaterial & {
47
+ uniforms: FireShaderUniforms;
48
+ };
49
+ private _time;
50
+ /**
51
+ * Creates a new Fire instance
52
+ *
53
+ * @param props - Configuration options for the fire effect
54
+ */
55
+ constructor({ fireTex, color, iterations, octaves, noiseScale, magnitude, lacunarity, gain, }: FireProps);
56
+ /**
57
+ * Updates the fire animation and matrix uniforms
58
+ *
59
+ * Call this method in your animation loop to animate the fire effect.
60
+ *
61
+ * @param time - Current time in seconds (optional)
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * function animate() {
66
+ * fire.update(performance.now() / 1000)
67
+ * renderer.render(scene, camera)
68
+ * requestAnimationFrame(animate)
69
+ * }
70
+ * ```
71
+ */
72
+ update(time?: number): void;
73
+ /**
74
+ * Current animation time in seconds
75
+ */
76
+ get time(): number;
77
+ set time(value: number);
78
+ /**
79
+ * Fire color tint
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * fire.fireColor = 'orange'
84
+ * fire.fireColor = 0xff4400
85
+ * fire.fireColor = new Color(1, 0.5, 0)
86
+ * ```
87
+ */
88
+ get fireColor(): Color;
89
+ set fireColor(color: Color | string | number);
90
+ /**
91
+ * Fire shape intensity
92
+ *
93
+ * Higher values create more dramatic fire shapes.
94
+ * Range: 0.5 - 3.0, Default: 1.3
95
+ */
96
+ get magnitude(): number;
97
+ set magnitude(value: number);
98
+ /**
99
+ * Noise lacunarity (frequency multiplier)
100
+ *
101
+ * Controls how much the frequency increases for each noise octave.
102
+ * Range: 1.0 - 4.0, Default: 2.0
103
+ */
104
+ get lacunarity(): number;
105
+ set lacunarity(value: number);
106
+ /**
107
+ * Noise gain (amplitude multiplier)
108
+ *
109
+ * Controls how much the amplitude decreases for each noise octave.
110
+ * Range: 0.1 - 1.0, Default: 0.5
111
+ */
112
+ get gain(): number;
113
+ set gain(value: number);
114
+ }
115
+ //# sourceMappingURL=Fire.d.ts.map
@@ -0,0 +1 @@
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H,IAAW,SAAS,IAAI,KAAK,CAE5B;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,EAElD;IAED;;;;;OAKG;IACH,IAAW,SAAS,IAAI,MAAM,CAE7B;IAED,IAAW,SAAS,CAAC,KAAK,EAAE,MAAM,EAEjC;IAED;;;;;OAKG;IACH,IAAW,UAAU,IAAI,MAAM,CAE9B;IAED,IAAW,UAAU,CAAC,KAAK,EAAE,MAAM,EAElC;IAED;;;;;OAKG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED,IAAW,IAAI,CAAC,KAAK,EAAE,MAAM,EAE5B;CACF"}
@@ -0,0 +1,101 @@
1
+ import React from 'react';
2
+ import { ReactThreeFiber } from '@react-three/fiber';
3
+ import { Fire as FireMesh, FireProps as FireMeshProps } from './Fire';
4
+ import { Texture } from 'three';
5
+ declare module '@react-three/fiber' {
6
+ interface ThreeElements {
7
+ fire: ReactThreeFiber.Object3DNode<FireMesh, typeof FireMesh>;
8
+ }
9
+ }
10
+ /**
11
+ * Props for the Fire React component
12
+ */
13
+ export interface FireProps extends Omit<FireMeshProps, 'fireTex'> {
14
+ /** Fire texture URL or Three.js Texture object */
15
+ texture: string | Texture;
16
+ /** Auto-update time from useFrame (default: true) */
17
+ autoUpdate?: boolean;
18
+ /** Custom update function called each frame */
19
+ onUpdate?: (fire: FireMesh, time: number) => void;
20
+ /** Child components */
21
+ children?: React.ReactNode;
22
+ /** Position in 3D space */
23
+ position?: [number, number, number];
24
+ /** Rotation in radians */
25
+ rotation?: [number, number, number];
26
+ /** Scale factor (uniform or per-axis) */
27
+ scale?: [number, number, number] | number;
28
+ }
29
+ /**
30
+ * Ref interface for imperative fire control
31
+ */
32
+ export interface FireRef {
33
+ /** Fire mesh instance */
34
+ fire: FireMesh | null;
35
+ /** Update fire animation manually */
36
+ update: (time?: number) => void;
37
+ }
38
+ /**
39
+ * React Three Fiber component for volumetric fire effect
40
+ *
41
+ * Creates a procedural fire effect that can be easily integrated into R3F scenes.
42
+ * The component automatically handles texture loading, animation updates, and
43
+ * provides props for all fire parameters.
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * <Canvas>
48
+ * <Fire
49
+ * texture="/fire.png"
50
+ * color="orange"
51
+ * magnitude={1.5}
52
+ * scale={[2, 3, 2]}
53
+ * position={[0, 0, 0]}
54
+ * />
55
+ * </Canvas>
56
+ * ```
57
+ *
58
+ * @example With custom animation
59
+ * ```tsx
60
+ * <Fire
61
+ * texture="/fire.png"
62
+ * onUpdate={(fire, time) => {
63
+ * fire.fireColor.setHSL((time * 0.1) % 1, 1, 0.5)
64
+ * }}
65
+ * />
66
+ * ```
67
+ */
68
+ export declare const FireComponent: React.ForwardRefExoticComponent<FireProps & React.RefAttributes<FireRef>>;
69
+ /**
70
+ * Hook for easier access to fire instance and controls
71
+ *
72
+ * Provides a ref and helper methods for controlling fire imperatively.
73
+ *
74
+ * @returns Object with ref, fire instance, and update method
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * function MyComponent() {
79
+ * const fireRef = useFire()
80
+ *
81
+ * const handleClick = () => {
82
+ * if (fireRef.fire) {
83
+ * fireRef.fire.magnitude = 2.0
84
+ * }
85
+ * }
86
+ *
87
+ * return (
88
+ * <Fire ref={fireRef.ref} texture="/fire.png" />
89
+ * )
90
+ * }
91
+ * ```
92
+ */
93
+ export declare const useFire: () => {
94
+ /** Ref to pass to Fire component */
95
+ ref: React.RefObject<FireRef>;
96
+ /** Fire mesh instance (null until mounted) */
97
+ fire: FireMesh | null;
98
+ /** Update fire animation manually */
99
+ update: (time?: number) => void | undefined;
100
+ };
101
+ //# sourceMappingURL=FireComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FireComponent.d.ts","sourceRoot":"","sources":["../../src/FireComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAA;AAC/E,OAAO,EAAoB,eAAe,EAAa,MAAM,oBAAoB,CAAA;AACjF,OAA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