@guinetik/gcanvas 1.0.0 → 1.0.2
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/demos/coordinates.html +698 -0
- package/demos/cube3d.html +23 -0
- package/demos/demos.css +17 -3
- package/demos/dino.html +42 -0
- package/demos/fluid-simple.html +22 -0
- package/demos/fluid.html +37 -0
- package/demos/gameobjects.html +626 -0
- package/demos/index.html +19 -7
- package/demos/js/blob.js +18 -5
- package/demos/js/coordinates.js +840 -0
- package/demos/js/cube3d.js +789 -0
- package/demos/js/dino.js +1420 -0
- package/demos/js/fluid-simple.js +253 -0
- package/demos/js/fluid.js +527 -0
- package/demos/js/gameobjects.js +176 -0
- package/demos/js/plane3d.js +256 -0
- package/demos/js/platformer.js +1579 -0
- package/demos/js/sphere3d.js +229 -0
- package/demos/js/sprite.js +473 -0
- package/demos/js/tde/accretiondisk.js +65 -12
- package/demos/js/tde/blackholescene.js +2 -2
- package/demos/js/tde/config.js +2 -2
- package/demos/js/tde/index.js +152 -27
- package/demos/js/tde/lensedstarfield.js +32 -25
- package/demos/js/tde/tdestar.js +78 -98
- package/demos/js/tde/tidalstream.js +24 -8
- package/demos/plane3d.html +24 -0
- package/demos/platformer.html +43 -0
- package/demos/sphere3d.html +24 -0
- package/demos/sprite.html +18 -0
- package/docs/README.md +230 -222
- package/docs/api/FluidSystem.md +173 -0
- package/docs/concepts/architecture-overview.md +204 -204
- package/docs/concepts/coordinate-system.md +384 -0
- package/docs/concepts/rendering-pipeline.md +279 -279
- package/docs/concepts/shapes-vs-gameobjects.md +187 -0
- package/docs/concepts/two-layer-architecture.md +229 -229
- package/docs/fluid-dynamics.md +99 -0
- package/docs/getting-started/first-game.md +354 -354
- package/docs/getting-started/installation.md +175 -157
- package/docs/modules/collision/README.md +2 -2
- package/docs/modules/fluent/README.md +6 -6
- package/docs/modules/game/README.md +303 -303
- package/docs/modules/isometric-camera.md +2 -2
- package/docs/modules/isometric.md +1 -1
- package/docs/modules/painter/README.md +328 -328
- package/docs/modules/particle/README.md +3 -3
- package/docs/modules/shapes/README.md +221 -221
- package/docs/modules/shapes/base/euclidian.md +123 -123
- package/docs/modules/shapes/base/shape.md +262 -262
- package/docs/modules/shapes/base/transformable.md +243 -243
- package/docs/modules/state/README.md +2 -2
- package/docs/modules/util/README.md +1 -1
- package/docs/modules/util/camera3d.md +3 -3
- package/docs/modules/util/scene3d.md +1 -1
- package/package.json +3 -1
- package/readme.md +19 -5
- package/src/collision/collision.js +75 -0
- package/src/game/game.js +11 -5
- package/src/game/index.js +2 -1
- package/src/game/objects/index.js +3 -0
- package/src/game/objects/platformer-scene.js +411 -0
- package/src/game/objects/scene.js +14 -0
- package/src/game/objects/sprite.js +529 -0
- package/src/game/pipeline.js +20 -16
- package/src/game/systems/FluidSystem.js +835 -0
- package/src/game/systems/index.js +11 -0
- package/src/game/ui/button.js +39 -18
- package/src/game/ui/cursor.js +14 -0
- package/src/game/ui/fps.js +12 -4
- package/src/game/ui/index.js +2 -0
- package/src/game/ui/stepper.js +549 -0
- package/src/game/ui/theme.js +123 -0
- package/src/game/ui/togglebutton.js +9 -3
- package/src/game/ui/tooltip.js +11 -4
- package/src/io/input.js +75 -45
- package/src/io/mouse.js +44 -19
- package/src/io/touch.js +35 -12
- package/src/math/fluid.js +507 -0
- package/src/math/index.js +2 -0
- package/src/mixins/anchor.js +17 -7
- package/src/motion/tweenetik.js +16 -0
- package/src/shapes/cube3d.js +599 -0
- package/src/shapes/index.js +3 -0
- package/src/shapes/plane3d.js +687 -0
- package/src/shapes/sphere3d.js +75 -6
- package/src/util/camera2d.js +315 -0
- package/src/util/camera3d.js +218 -12
- package/src/util/index.js +1 -0
- package/src/webgl/shaders/plane-shaders.js +332 -0
- package/src/webgl/shaders/sphere-shaders.js +4 -2
- package/types/fluent.d.ts +361 -0
- package/types/game.d.ts +303 -0
- package/types/index.d.ts +144 -5
- package/types/math.d.ts +361 -0
- package/types/motion.d.ts +271 -0
- package/types/particle.d.ts +373 -0
- package/types/shapes.d.ts +107 -9
- package/types/util.d.ts +353 -0
- package/types/webgl.d.ts +109 -0
- package/disk_example.png +0 -0
- package/tde.png +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Fluid & Gas Dynamics (Math-Only)
|
|
2
|
+
|
|
3
|
+
Pure math helpers for SPH-style liquids and lightweight gas simulation. The math stays in `src/math/fluid.js`; consumers (games/demos) are responsible for applying forces to their particles.
|
|
4
|
+
|
|
5
|
+
## What’s Included
|
|
6
|
+
- SPH density, pressure, and viscosity kernels (`computeDensities`, `computePressures`, `computeFluidForces`).
|
|
7
|
+
- Simplified gas mixing with diffusion/pressure/turbulence (`computeGasForces`).
|
|
8
|
+
- Thermal buoyancy coupling (`computeThermalBuoyancy`) that pairs with `src/math/heat.js`.
|
|
9
|
+
- Force blending and pure Euler integration (`blendForces`, `integrateEuler`).
|
|
10
|
+
- Config factory with no magic numbers (`getDefaultFluidConfig`).
|
|
11
|
+
|
|
12
|
+
## Config
|
|
13
|
+
Defined in `src/math/fluid.js` and merged via `mergeConfig` internally.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const CONFIG = {
|
|
17
|
+
kernel: { smoothingRadius: 28 },
|
|
18
|
+
fluid: {
|
|
19
|
+
restDensity: 1.1,
|
|
20
|
+
particleMass: 1,
|
|
21
|
+
pressureStiffness: 1800,
|
|
22
|
+
viscosity: 0.18,
|
|
23
|
+
surfaceTension: 0,
|
|
24
|
+
maxForce: 6000,
|
|
25
|
+
},
|
|
26
|
+
gas: {
|
|
27
|
+
interactionRadius: 34,
|
|
28
|
+
pressure: 12,
|
|
29
|
+
diffusion: 0.08,
|
|
30
|
+
drag: 0.04,
|
|
31
|
+
buoyancy: 260,
|
|
32
|
+
neutralTemperature: 0.5,
|
|
33
|
+
turbulence: 16,
|
|
34
|
+
},
|
|
35
|
+
external: { gravity: { x: 0, y: 820 } },
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Override by passing `{ fluid: { … }, gas: { … }, kernel: { … } }` to any helper.
|
|
40
|
+
|
|
41
|
+
## Particle Shape
|
|
42
|
+
Any object with `{ x, y, vx, vy, size?, mass?, custom? }`. Mass is resolved from:
|
|
43
|
+
`custom.mass` → `mass` → `size` → `config.fluid.particleMass`.
|
|
44
|
+
|
|
45
|
+
## Core API (pure)
|
|
46
|
+
- `computeDensities(particles, cfg?)` → `Float32Array densities`.
|
|
47
|
+
- `computePressures(densities, cfg?)` → `Float32Array pressures`.
|
|
48
|
+
- `computeFluidForces(particles, cfg?)` → `{ forces, densities, pressures }`.
|
|
49
|
+
- `computeGasForces(particles, cfg?)` → `{ forces }`.
|
|
50
|
+
- `computeThermalBuoyancy(particles, cfg?)` → `forces[]` using `temperature` or `custom.temperature`.
|
|
51
|
+
- `blendForces(a, b, t)` → lerped forces.
|
|
52
|
+
- `integrateEuler(particles, forces, dt, cfg?)` → new `{ x, y, vx, vy }[]` (no mutation).
|
|
53
|
+
|
|
54
|
+
## Applying in a Game (pattern)
|
|
55
|
+
1) Build forces:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { computeFluidForces, computeGasForces, blendForces, computeThermalBuoyancy } from "../../src/math/fluid.js";
|
|
59
|
+
|
|
60
|
+
const liquid = computeFluidForces(particles, { kernel: { smoothingRadius: 26 } });
|
|
61
|
+
const gas = computeGasForces(particles, { gas: { interactionRadius: 40 } });
|
|
62
|
+
const buoyancy = computeThermalBuoyancy(particles);
|
|
63
|
+
|
|
64
|
+
// Combine as you see fit (example: mix liquid & gas modes, then add buoyancy)
|
|
65
|
+
const mixed = blendForces(liquid.forces, gas.forces, modeT); // modeT: 0..1
|
|
66
|
+
for (let i = 0; i < particles.length; i++) {
|
|
67
|
+
mixed[i].x += buoyancy[i].x;
|
|
68
|
+
mixed[i].y += buoyancy[i].y;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
2) Apply to your particles (consumer-controlled):
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
// Mutate in your game loop; math module stays pure.
|
|
76
|
+
for (let i = 0; i < particles.length; i++) {
|
|
77
|
+
const p = particles[i];
|
|
78
|
+
const f = mixed[i];
|
|
79
|
+
const mass = p.custom.mass ?? 1;
|
|
80
|
+
p.vx += (f.x / mass) * dt;
|
|
81
|
+
p.vy += (f.y / mass) * dt;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
3) Let your normal updaters move/render (e.g., `ParticleSystem` velocity updater).
|
|
86
|
+
|
|
87
|
+
## Heat Coupling
|
|
88
|
+
Assign `p.temperature` or `p.custom.temperature` each frame (e.g., via `heat.zoneTemperature`). Pass the same particles to `computeThermalBuoyancy` and add the resulting forces.
|
|
89
|
+
|
|
90
|
+
## Notes & Tips
|
|
91
|
+
- Keep `smoothingRadius` proportional to particle spacing (roughly 2–3× average spacing).
|
|
92
|
+
- Clamp velocities in the consumer if you target 10k–20k particles to keep the frame budget.
|
|
93
|
+
- For gases, favor lower `pressure` and higher `diffusion` to avoid jitter.
|
|
94
|
+
- The math never allocates inside the hot path besides output arrays; reuse them between frames if you need fewer allocations (pass your own particles array).
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|