hz-particles 1.0.0 → 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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # hz-particles
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/hz-particles.svg)](https://www.npmjs.com/package/hz-particles)
4
- [![license](https://img.shields.io/npm/l/hz-particles.svg)](https://github.com/TODO/hz-particles/blob/main/LICENSE)
4
+ [![license](https://img.shields.io/npm/l/hz-particles.svg)](https://github.com/jguyet/particle-system/blob/main/LICENSE)
5
5
  [![WebGPU](https://img.shields.io/badge/WebGPU-required-blue.svg)](https://caniuse.com/webgpu)
6
6
 
7
7
  A high-performance WebGPU particle engine for the web.
@@ -34,11 +34,15 @@ npm install hz-particles
34
34
 
35
35
  ## Quick Start
36
36
 
37
+ ### Option 1: Using the built-in WebGPU helper
38
+
37
39
  ```javascript
38
40
  import { initWebGPU, ParticleSystemManager } from 'hz-particles';
39
41
 
40
- // 1. Setup WebGPU context
42
+ // 1. Setup WebGPU context with the convenience helper
41
43
  const canvas = document.getElementById('webgpu-canvas');
44
+ canvas.width = 800;
45
+ canvas.height = 600;
42
46
  const { device, context, format } = await initWebGPU(canvas);
43
47
 
44
48
  // 2. Create particle system manager
@@ -92,6 +96,37 @@ function render() {
92
96
  render();
93
97
  ```
94
98
 
99
+ ### Option 2: Using an existing WebGPU setup
100
+
101
+ If you already have a WebGPU device and context (e.g., from an existing project or framework), you can skip `initWebGPU()` and use the library directly:
102
+
103
+ ```javascript
104
+ import { ParticleSystemManager, createRenderTextures, createDepthTexture } from 'hz-particles';
105
+
106
+ // Assume you already have these from your existing WebGPU setup
107
+ const device = yourExistingDevice;
108
+ const context = yourExistingContext;
109
+ const format = navigator.gpu.getPreferredCanvasFormat();
110
+ const canvas = yourExistingCanvas;
111
+
112
+ // Create particle system manager with your device
113
+ const manager = new ParticleSystemManager(device);
114
+
115
+ // Create a particle system
116
+ const systemId = manager.createParticleSystem({
117
+ maxParticles: 10000,
118
+ particleCount: 1000,
119
+ });
120
+
121
+ // Initialize and use as shown in Option 1
122
+ const system = manager.getActiveSystem();
123
+ await system.initComputePipeline(device);
124
+
125
+ // Your render loop...
126
+ ```
127
+
128
+ This approach is ideal for integrating into existing WebGPU applications, frameworks, or when you need custom WebGPU initialization.
129
+
95
130
  ## React Three Fiber Integration
96
131
 
97
132
  While `hz-particles` uses native WebGPU (not Three.js internally), you can integrate it into React Three Fiber applications:
@@ -111,6 +146,8 @@ function ParticleLayer() {
111
146
  async function init() {
112
147
  // Create dedicated WebGPU canvas
113
148
  const canvas = canvasRef.current;
149
+ canvas.width = window.innerWidth;
150
+ canvas.height = window.innerHeight;
114
151
  const { device, context, format } = await initWebGPU(canvas);
115
152
 
116
153
  // Setup particle system
@@ -194,12 +231,12 @@ function App() {
194
231
 
195
232
  ## API Reference
196
233
 
197
- ### `initWebGPU(canvas?)`
234
+ ### `initWebGPU(canvas)`
198
235
 
199
- Initialize WebGPU context and device.
236
+ Convenience helper to initialize WebGPU context and device. **Library consumers with their own WebGPU setup do NOT need to use this function** — you can pass your existing `device`, `context`, `format`, and `canvas` directly to the library's components.
200
237
 
201
238
  ```typescript
202
- async function initWebGPU(canvas?: HTMLCanvasElement): Promise<{
239
+ async function initWebGPU(canvas: HTMLCanvasElement): Promise<{
203
240
  device: GPUDevice,
204
241
  context: GPUCanvasContext,
205
242
  format: GPUTextureFormat,
@@ -208,11 +245,15 @@ async function initWebGPU(canvas?: HTMLCanvasElement): Promise<{
208
245
  ```
209
246
 
210
247
  **Parameters:**
211
- - `canvas` (optional) — Canvas element. If omitted, looks for `document.getElementById('webgpu-canvas')`
248
+ - `canvas` (required) — Canvas element for WebGPU rendering. You must size the canvas before calling this function.
212
249
 
213
250
  **Returns:** Object with WebGPU device, canvas context, texture format, and canvas element
214
251
 
215
- **Throws:** Error if WebGPU is not supported
252
+ **Throws:**
253
+ - Error if `canvas` is not provided
254
+ - Error if WebGPU is not supported
255
+
256
+ **Note:** This function does NOT handle canvas sizing. You should set `canvas.width` and `canvas.height` before calling `initWebGPU()`.
216
257
 
217
258
  ---
218
259
 
@@ -407,7 +448,7 @@ input.addEventListener('change', async (event) => {
407
448
 
408
449
  ## Online Editor
409
450
 
410
- Try the interactive particle editor: [Online Editor](https://your-domain.com/editor) (deployment URL coming soon)
451
+ Try the interactive particle editor at `http://localhost:8110/editor` when running the Docker container (`docker-compose up` from the repository root)
411
452
 
412
453
  The editor provides a visual interface for:
413
454
  - Real-time particle system configuration