@wolffo/three-fire 1.0.7 → 1.1.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 +27 -4
- package/dist/react.d.ts +262 -0
- package/dist/react.esm.js +446 -0
- package/dist/react.esm.js.map +1 -0
- package/dist/react.js +449 -0
- package/dist/react.js.map +1 -0
- package/dist/types/index.d.ts +16 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/react.d.ts +21 -0
- package/dist/types/react.d.ts.map +1 -0
- package/dist/types/vanilla.d.ts +18 -0
- package/dist/types/vanilla.d.ts.map +1 -0
- package/dist/vanilla.d.ts +189 -0
- package/dist/vanilla.esm.js +344 -0
- package/dist/vanilla.esm.js.map +1 -0
- package/dist/vanilla.js +347 -0
- package/dist/vanilla.js.map +1 -0
- package/package.json +13 -2
package/README.md
CHANGED
|
@@ -27,13 +27,27 @@ Modern TypeScript volumetric fire effect for Three.js and React Three Fiber.
|
|
|
27
27
|
npm install @wolffo/three-fire
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Entry Points Summary
|
|
31
|
+
|
|
32
|
+
This package provides separate entry points to optimize bundle size and avoid unnecessary dependencies:
|
|
33
|
+
|
|
34
|
+
| Entry Point | Use Case | Bundle Size | Dependencies |
|
|
35
|
+
|-------------|----------|-------------|--------------|
|
|
36
|
+
| `@wolffo/three-fire/vanilla` | Vanilla Three.js projects | Smallest | Only Three.js |
|
|
37
|
+
| `@wolffo/three-fire/react` | React Three Fiber projects | Medium | React + Three.js |
|
|
38
|
+
| `@wolffo/three-fire` | Legacy/mixed usage | Largest | All dependencies |
|
|
39
|
+
|
|
40
|
+
**⚠️ Migration Notice**: For better performance, migrate from the main entry point to specific entry points:
|
|
41
|
+
- Vanilla Three.js users → use `/vanilla`
|
|
42
|
+
- React Three Fiber users → use `/react`
|
|
43
|
+
|
|
30
44
|
## Usage
|
|
31
45
|
|
|
32
46
|
### React Three Fiber (Recommended)
|
|
33
47
|
|
|
34
48
|
```tsx
|
|
35
49
|
import { Canvas } from '@react-three/fiber'
|
|
36
|
-
import { Fire } from '@wolffo/three-fire'
|
|
50
|
+
import { Fire } from '@wolffo/three-fire/react'
|
|
37
51
|
|
|
38
52
|
function App() {
|
|
39
53
|
return (
|
|
@@ -52,7 +66,7 @@ function App() {
|
|
|
52
66
|
### With custom parameters
|
|
53
67
|
|
|
54
68
|
```tsx
|
|
55
|
-
import { Fire, useFire } from '@wolffo/three-fire'
|
|
69
|
+
import { Fire, useFire } from '@wolffo/three-fire/react'
|
|
56
70
|
|
|
57
71
|
function CustomFire() {
|
|
58
72
|
const fireRef = useFire()
|
|
@@ -79,7 +93,7 @@ function CustomFire() {
|
|
|
79
93
|
### Vanilla Three.js
|
|
80
94
|
|
|
81
95
|
```ts
|
|
82
|
-
import { FireMesh } from '@wolffo/three-fire'
|
|
96
|
+
import { FireMesh } from '@wolffo/three-fire/vanilla'
|
|
83
97
|
import { Scene, TextureLoader } from 'three'
|
|
84
98
|
|
|
85
99
|
const scene = new Scene()
|
|
@@ -109,6 +123,15 @@ function animate() {
|
|
|
109
123
|
animate()
|
|
110
124
|
```
|
|
111
125
|
|
|
126
|
+
### Legacy Usage (Backward Compatibility)
|
|
127
|
+
|
|
128
|
+
⚠️ **Not recommended for new projects** - use specific entry points above for better performance.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
// Legacy import - includes all dependencies
|
|
132
|
+
import { FireMesh, Fire } from '@wolffo/three-fire'
|
|
133
|
+
```
|
|
134
|
+
|
|
112
135
|
## API Reference
|
|
113
136
|
|
|
114
137
|
### FireComponent Props
|
|
@@ -148,7 +171,7 @@ class FireMesh extends Mesh {
|
|
|
148
171
|
|
|
149
172
|
You need to provide a fire texture similar to the one shown below:
|
|
150
173
|
|
|
151
|
-

|
|
174
|
+

|
|
152
175
|
|
|
153
176
|
The texture should be a grayscale gradient that defines the fire's density distribution.
|
|
154
177
|
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ReactThreeFiber } from '@react-three/fiber';
|
|
3
|
+
import { Texture, Color, Matrix4, Vector3, Vector4, Mesh, ShaderMaterial } from 'three';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Uniforms interface for the fire shader
|
|
7
|
+
*/
|
|
8
|
+
interface FireShaderUniforms {
|
|
9
|
+
/** Fire texture (grayscale mask) */
|
|
10
|
+
fireTex: {
|
|
11
|
+
value: Texture | null;
|
|
12
|
+
};
|
|
13
|
+
/** Fire color tint */
|
|
14
|
+
color: {
|
|
15
|
+
value: Color;
|
|
16
|
+
};
|
|
17
|
+
/** Current time for animation */
|
|
18
|
+
time: {
|
|
19
|
+
value: number;
|
|
20
|
+
};
|
|
21
|
+
/** Random seed for fire variation */
|
|
22
|
+
seed: {
|
|
23
|
+
value: number;
|
|
24
|
+
};
|
|
25
|
+
/** Inverse model matrix for ray marching */
|
|
26
|
+
invModelMatrix: {
|
|
27
|
+
value: Matrix4;
|
|
28
|
+
};
|
|
29
|
+
/** Scale of the fire object */
|
|
30
|
+
scale: {
|
|
31
|
+
value: Vector3;
|
|
32
|
+
};
|
|
33
|
+
/** Noise scaling parameters [x, y, z, time] */
|
|
34
|
+
noiseScale: {
|
|
35
|
+
value: Vector4;
|
|
36
|
+
};
|
|
37
|
+
/** Fire shape intensity */
|
|
38
|
+
magnitude: {
|
|
39
|
+
value: number;
|
|
40
|
+
};
|
|
41
|
+
/** Noise lacunarity (frequency multiplier) */
|
|
42
|
+
lacunarity: {
|
|
43
|
+
value: number;
|
|
44
|
+
};
|
|
45
|
+
/** Noise gain (amplitude multiplier) */
|
|
46
|
+
gain: {
|
|
47
|
+
value: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Properties for creating a Fire instance
|
|
53
|
+
*/
|
|
54
|
+
interface FireProps$1 {
|
|
55
|
+
/** Fire texture (grayscale mask defining fire shape) */
|
|
56
|
+
fireTex: Texture;
|
|
57
|
+
/** Fire color tint (default: 0xeeeeee) */
|
|
58
|
+
color?: Color | string | number;
|
|
59
|
+
/** Ray marching iterations - higher = better quality, lower performance (default: 20) */
|
|
60
|
+
iterations?: number;
|
|
61
|
+
/** Noise octaves for turbulence (default: 3) */
|
|
62
|
+
octaves?: number;
|
|
63
|
+
/** Noise scaling parameters [x, y, z, time] (default: [1, 2, 1, 0.3]) */
|
|
64
|
+
noiseScale?: [number, number, number, number];
|
|
65
|
+
/** Fire shape intensity (default: 1.3) */
|
|
66
|
+
magnitude?: number;
|
|
67
|
+
/** Noise lacunarity - frequency multiplier (default: 2.0) */
|
|
68
|
+
lacunarity?: number;
|
|
69
|
+
/** Noise gain - amplitude multiplier (default: 0.5) */
|
|
70
|
+
gain?: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Volumetric fire effect using ray marching shaders
|
|
74
|
+
*
|
|
75
|
+
* Creates a procedural fire effect that renders as a translucent volume.
|
|
76
|
+
* The fire shape is defined by a grayscale texture, with white areas being
|
|
77
|
+
* the most dense part of the fire.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const texture = textureLoader.load('fire.png')
|
|
82
|
+
* const fire = new Fire({
|
|
83
|
+
* fireTex: texture,
|
|
84
|
+
* color: 0xff4400,
|
|
85
|
+
* magnitude: 1.5
|
|
86
|
+
* })
|
|
87
|
+
* scene.add(fire)
|
|
88
|
+
*
|
|
89
|
+
* // In animation loop
|
|
90
|
+
* fire.update(time)
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
declare class Fire extends Mesh {
|
|
94
|
+
material: ShaderMaterial & {
|
|
95
|
+
uniforms: FireShaderUniforms;
|
|
96
|
+
};
|
|
97
|
+
private _time;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new Fire instance
|
|
100
|
+
*
|
|
101
|
+
* @param props - Configuration options for the fire effect
|
|
102
|
+
*/
|
|
103
|
+
constructor({ fireTex, color, iterations, octaves, noiseScale, magnitude, lacunarity, gain, }: FireProps$1);
|
|
104
|
+
/**
|
|
105
|
+
* Updates the fire animation and matrix uniforms
|
|
106
|
+
*
|
|
107
|
+
* Call this method in your animation loop to animate the fire effect.
|
|
108
|
+
*
|
|
109
|
+
* @param time - Current time in seconds (optional)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* function animate() {
|
|
114
|
+
* fire.update(performance.now() / 1000)
|
|
115
|
+
* renderer.render(scene, camera)
|
|
116
|
+
* requestAnimationFrame(animate)
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
update(time?: number): void;
|
|
121
|
+
/**
|
|
122
|
+
* Current animation time in seconds
|
|
123
|
+
*/
|
|
124
|
+
get time(): number;
|
|
125
|
+
set time(value: number);
|
|
126
|
+
/**
|
|
127
|
+
* Fire color tint
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* fire.fireColor = 'orange'
|
|
132
|
+
* fire.fireColor = 0xff4400
|
|
133
|
+
* fire.fireColor = new Color(1, 0.5, 0)
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
get fireColor(): Color;
|
|
137
|
+
set fireColor(color: Color | string | number);
|
|
138
|
+
/**
|
|
139
|
+
* Fire shape intensity
|
|
140
|
+
*
|
|
141
|
+
* Higher values create more dramatic fire shapes.
|
|
142
|
+
* Range: 0.5 - 3.0, Default: 1.3
|
|
143
|
+
*/
|
|
144
|
+
get magnitude(): number;
|
|
145
|
+
set magnitude(value: number);
|
|
146
|
+
/**
|
|
147
|
+
* Noise lacunarity (frequency multiplier)
|
|
148
|
+
*
|
|
149
|
+
* Controls how much the frequency increases for each noise octave.
|
|
150
|
+
* Range: 1.0 - 4.0, Default: 2.0
|
|
151
|
+
*/
|
|
152
|
+
get lacunarity(): number;
|
|
153
|
+
set lacunarity(value: number);
|
|
154
|
+
/**
|
|
155
|
+
* Noise gain (amplitude multiplier)
|
|
156
|
+
*
|
|
157
|
+
* Controls how much the amplitude decreases for each noise octave.
|
|
158
|
+
* Range: 0.1 - 1.0, Default: 0.5
|
|
159
|
+
*/
|
|
160
|
+
get gain(): number;
|
|
161
|
+
set gain(value: number);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare module '@react-three/fiber' {
|
|
165
|
+
interface ThreeElements {
|
|
166
|
+
fire: ReactThreeFiber.Object3DNode<Fire, typeof Fire>;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Props for the Fire React component
|
|
171
|
+
*/
|
|
172
|
+
interface FireProps extends Omit<FireProps$1, 'fireTex'> {
|
|
173
|
+
/** Fire texture URL or Three.js Texture object */
|
|
174
|
+
texture: string | Texture;
|
|
175
|
+
/** Auto-update time from useFrame (default: true) */
|
|
176
|
+
autoUpdate?: boolean;
|
|
177
|
+
/** Custom update function called each frame */
|
|
178
|
+
onUpdate?: (fire: Fire, time: number) => void;
|
|
179
|
+
/** Child components */
|
|
180
|
+
children?: React.ReactNode;
|
|
181
|
+
/** Position in 3D space */
|
|
182
|
+
position?: [number, number, number];
|
|
183
|
+
/** Rotation in radians */
|
|
184
|
+
rotation?: [number, number, number];
|
|
185
|
+
/** Scale factor (uniform or per-axis) */
|
|
186
|
+
scale?: [number, number, number] | number;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Ref interface for imperative fire control
|
|
190
|
+
*/
|
|
191
|
+
interface FireRef {
|
|
192
|
+
/** Fire mesh instance */
|
|
193
|
+
fire: Fire | null;
|
|
194
|
+
/** Update fire animation manually */
|
|
195
|
+
update: (time?: number) => void;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* React Three Fiber component for volumetric fire effect
|
|
199
|
+
*
|
|
200
|
+
* Creates a procedural fire effect that can be easily integrated into R3F scenes.
|
|
201
|
+
* The component automatically handles texture loading, animation updates, and
|
|
202
|
+
* provides props for all fire parameters.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```tsx
|
|
206
|
+
* <Canvas>
|
|
207
|
+
* <Fire
|
|
208
|
+
* texture="/fire.png"
|
|
209
|
+
* color="orange"
|
|
210
|
+
* magnitude={1.5}
|
|
211
|
+
* scale={[2, 3, 2]}
|
|
212
|
+
* position={[0, 0, 0]}
|
|
213
|
+
* />
|
|
214
|
+
* </Canvas>
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @example With custom animation
|
|
218
|
+
* ```tsx
|
|
219
|
+
* <Fire
|
|
220
|
+
* texture="/fire.png"
|
|
221
|
+
* onUpdate={(fire, time) => {
|
|
222
|
+
* fire.fireColor.setHSL((time * 0.1) % 1, 1, 0.5)
|
|
223
|
+
* }}
|
|
224
|
+
* />
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare const FireComponent: React.ForwardRefExoticComponent<FireProps & React.RefAttributes<FireRef>>;
|
|
228
|
+
/**
|
|
229
|
+
* Hook for easier access to fire instance and controls
|
|
230
|
+
*
|
|
231
|
+
* Provides a ref and helper methods for controlling fire imperatively.
|
|
232
|
+
*
|
|
233
|
+
* @returns Object with ref, fire instance, and update method
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```tsx
|
|
237
|
+
* function MyComponent() {
|
|
238
|
+
* const fireRef = useFire()
|
|
239
|
+
*
|
|
240
|
+
* const handleClick = () => {
|
|
241
|
+
* if (fireRef.fire) {
|
|
242
|
+
* fireRef.fire.magnitude = 2.0
|
|
243
|
+
* }
|
|
244
|
+
* }
|
|
245
|
+
*
|
|
246
|
+
* return (
|
|
247
|
+
* <Fire ref={fireRef.ref} texture="/fire.png" />
|
|
248
|
+
* )
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare const useFire: () => {
|
|
253
|
+
/** Ref to pass to Fire component */
|
|
254
|
+
ref: React.RefObject<FireRef>;
|
|
255
|
+
/** Fire mesh instance (null until mounted) */
|
|
256
|
+
fire: Fire | null;
|
|
257
|
+
/** Update fire animation manually */
|
|
258
|
+
update: (time?: number) => void | undefined;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
export { FireComponent as Fire, useFire };
|
|
262
|
+
export type { FireProps, FireRef };
|