@n3rdw1z4rd/core 0.17.0 → 0.17.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 +3 -29
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -0
- package/dist/index.mjs +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,9 +29,11 @@ log(rng.range(0, 10)); // random int in [0, 10)
|
|
|
29
29
|
log(clamp(15, 0, 10)); // 10
|
|
30
30
|
|
|
31
31
|
const clock = new Clock();
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
clock.onFrame.subscribe((dt) => {
|
|
33
34
|
// dt is seconds since last frame
|
|
34
35
|
});
|
|
36
|
+
|
|
35
37
|
clock.start();
|
|
36
38
|
```
|
|
37
39
|
|
|
@@ -40,31 +42,3 @@ Everything (including the `three/*` modules) is re-exported from the package roo
|
|
|
40
42
|
```ts
|
|
41
43
|
import { ThreeJsBoilerPlate } from "@n3rdw1z4rd/core/three";
|
|
42
44
|
```
|
|
43
|
-
|
|
44
|
-
## What's in here
|
|
45
|
-
|
|
46
|
-
| Area | Docs | Summary |
|
|
47
|
-
|---|---|---|
|
|
48
|
-
| Math & RNG | [docs/math-and-rng.md](docs/math-and-rng.md) | Pure-math `sin`/`cos`/`floor`/etc. (no native `Math` calls), a seeded `RandomNumberGenerator` class with an exclusive `range()`, gaussian sampling, shuffling. |
|
|
49
|
-
| Events | [docs/events.md](docs/events.md) | `Emitter` (typed on/emit/clear), `EventBus` (DOM `CustomEvent`-based, for cross-module pub/sub without a shared instance). |
|
|
50
|
-
| ECS | [docs/ecs.md](docs/ecs.md) | Two independent designs: a component-template-registry singleton (`ECS.instance`), and an Object3D-based variant under `three/ecs.ts` where components live in `userData`. |
|
|
51
|
-
| Clock, logging, input | [docs/clock-logging-input.md](docs/clock-logging-input.md) | `Clock` (rAF loop + FPS/dt tracking, emits a `'frame'` event), leveled console loggers, `Input` (keyboard/mouse event normalization). |
|
|
52
|
-
| Noise | [docs/noise.md](docs/noise.md) | `Noise` (2D/3D/4D + fractal/fBm, wraps the `simplex-noise` package), plus a self-contained `SimplexNoise` class. |
|
|
53
|
-
| 2D primitives | [docs/2d-primitives.md](docs/2d-primitives.md) | `Vector`, `Rectangle`, `Map2D`/`Map3D` (sparse coordinate maps), `Tilemap<T>`. |
|
|
54
|
-
| Procedural generation | [docs/procedural-generation.md](docs/procedural-generation.md) | `AStar` pathfinding, `PoissonDiskSampler`, and a full room-based dungeon generator (`GenerateRooms`/`GenerateDoors`/`GenerateWalls`). |
|
|
55
|
-
| Particle life | [docs/particles.md](docs/particles.md) | 2D (canvas) and 3D (Three.js `Points`) "particle life" attraction-matrix simulations, `Color`, `SpatialPartition2d`/`3d`. |
|
|
56
|
-
| 2D/WebGL rendering | [docs/rendering-2d-webgl.md](docs/rendering-2d-webgl.md) | `CanvasRenderer` (shape/text drawing), and a thin raw-WebGL2 helper layer (`CreateWebGlContext`, shader/program helpers, `WebGlRenderer`). |
|
|
57
|
-
| Three.js bootstrap | [docs/threejs-bootstrap.md](docs/threejs-bootstrap.md) | `ThreeJsBoilerPlate` (scene/camera/renderer/input wiring), `ThreeJsCameraRig` (hand-rolled orbit rig) vs. opt-in `OrbitControls`, `ThreeJsPlayerController`. |
|
|
58
|
-
| Three.js meshes & textures | [docs/threejs-meshes-and-textures.md](docs/threejs-meshes-and-textures.md) | `VoxelMesh` (per-face-culled voxel geometry + palettes), `TextureAtlas`/`AtlasTextureMaterial`, `CubeSphereGeometry`, `AsteroidMesh`, starfield generators. |
|
|
59
|
-
| Three.js widgets | [docs/threejs-widgets.md](docs/threejs-widgets.md) | `CreatePaletteController`, a lil-gui color-swatch widget for picking a palette index. |
|
|
60
|
-
| Networking | [docs/networking.md](docs/networking.md) | `WorkerInterface`, a thin `Emitter`-based wrapper around `Worker`. |
|
|
61
|
-
| Misc | [docs/misc.md](docs/misc.md) | A handful of small standalone helpers: `isNullOrUndefined`, `isPositiveString`, `getRedYellowGreenGradientHex`, `GetUrlParams`. |
|
|
62
|
-
|
|
63
|
-
## Design notes worth knowing before you dig in
|
|
64
|
-
|
|
65
|
-
- **Two ECS designs, on purpose.** The top-level `ECS` (in `ecs.ts`) is a component-template-registry singleton (`ECS.instance.createComponent(...)`). The Three.js-flavored one (`three/ecs.ts`) stores components directly on an `Object3D`'s `userData`, so the scene graph doubles as the entity list. Pick whichever fits a given project - they don't interoperate and aren't meant to.
|
|
66
|
-
- **Two camera-control approaches, both supported.** `ThreeJsBoilerPlate.enableCameraRigControls()` uses the hand-rolled `ThreeJsCameraRig` (orbit/dolly driven by `Input` events). `enableOrbitControls()` uses Three's own `OrbitControls` instead. They're mutually exclusive - call one or the other, not both.
|
|
67
|
-
- **`rng.range(min, max)` is exclusive of `max`.** If you're carrying over code from an older version of this package (pre-0.12), note this changed from inclusive to exclusive.
|
|
68
|
-
- **No native `Math` calls in `math.ts`.** `sin`/`cos`/`floor`/`ceil`/`round`/`sqrt` etc. are all reimplemented from scratch (Taylor series + quadrant reduction for trig, accurate to ~4.65e-7). Everything else in the package builds on these rather than calling `Math.*` directly, with a few explicitly-commented pragmatic exceptions (e.g. `rng.parkMillerNormal()` uses native `Math.log`).
|
|
69
|
-
- **No `gl-matrix` dependency, and no `VEC2`/`VEC3`/`VEC4` types (as of 0.14).** `Input.mousePosition`/`mousePosition2`, `CanvasRenderer`'s draw methods, `TextureAtlas.getUv`, and `RandomNumberGenerator.randomUnitVector` used to return `gl-matrix`'s `vec2`/`vec4` (`Float32Array`-backed at runtime, 32-bit float precision). They now return plain `[number, number]`/`[number, number, number, number]` tuples inline - full double precision, no longer `instanceof Float32Array`, and no named vector type at all. If you're upgrading from an older version and relied on any of that, this is a breaking change.
|
|
70
|
-
- **`Rng` was renamed to `RandomNumberGenerator`.** The shared instance is still exported as `rng`, but the class type itself is `RandomNumberGenerator` now, not `Rng`. Update any type annotations that referenced `Rng` directly.
|
package/dist/index.d.mts
CHANGED
|
@@ -382,6 +382,7 @@ declare class CanvasRenderer {
|
|
|
382
382
|
constructor(canvas?: HTMLCanvasElement);
|
|
383
383
|
resize(width?: number, height?: number): boolean;
|
|
384
384
|
clear(): void;
|
|
385
|
+
render(callback: () => void, camera?: XYZ): void;
|
|
385
386
|
private drawPath;
|
|
386
387
|
drawRect(x: number, y: number, width: number, height: number, params?: DrawParams): void;
|
|
387
388
|
drawPixel(x: number, y: number, params?: DrawParams): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -382,6 +382,7 @@ declare class CanvasRenderer {
|
|
|
382
382
|
constructor(canvas?: HTMLCanvasElement);
|
|
383
383
|
resize(width?: number, height?: number): boolean;
|
|
384
384
|
clear(): void;
|
|
385
|
+
render(callback: () => void, camera?: XYZ): void;
|
|
385
386
|
private drawPath;
|
|
386
387
|
drawRect(x: number, y: number, width: number, height: number, params?: DrawParams): void;
|
|
387
388
|
drawPixel(x: number, y: number, params?: DrawParams): void;
|
package/dist/index.js
CHANGED
|
@@ -1878,6 +1878,16 @@ var CanvasRenderer = class {
|
|
|
1878
1878
|
clear() {
|
|
1879
1879
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
1880
1880
|
}
|
|
1881
|
+
render(callback, camera) {
|
|
1882
|
+
camera = camera ?? { x: 0, y: 0, z: 1 };
|
|
1883
|
+
this.clear();
|
|
1884
|
+
this.context.save();
|
|
1885
|
+
this.context.translate(this.width / 2, this.height / 2);
|
|
1886
|
+
this.context.scale(camera.z, camera.z);
|
|
1887
|
+
this.context.translate(-camera.x, -camera.y);
|
|
1888
|
+
callback();
|
|
1889
|
+
this.context.restore();
|
|
1890
|
+
}
|
|
1881
1891
|
drawPath(buildPath, params = {}) {
|
|
1882
1892
|
this.context.fillStyle = params.color ?? DEFAULT_COLOR;
|
|
1883
1893
|
this.context.strokeStyle = params.color ?? DEFAULT_COLOR;
|
package/dist/index.mjs
CHANGED
|
@@ -1875,6 +1875,16 @@ var CanvasRenderer = class {
|
|
|
1875
1875
|
clear() {
|
|
1876
1876
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
1877
1877
|
}
|
|
1878
|
+
render(callback, camera) {
|
|
1879
|
+
camera = camera ?? { x: 0, y: 0, z: 1 };
|
|
1880
|
+
this.clear();
|
|
1881
|
+
this.context.save();
|
|
1882
|
+
this.context.translate(this.width / 2, this.height / 2);
|
|
1883
|
+
this.context.scale(camera.z, camera.z);
|
|
1884
|
+
this.context.translate(-camera.x, -camera.y);
|
|
1885
|
+
callback();
|
|
1886
|
+
this.context.restore();
|
|
1887
|
+
}
|
|
1878
1888
|
drawPath(buildPath, params = {}) {
|
|
1879
1889
|
this.context.fillStyle = params.color ?? DEFAULT_COLOR;
|
|
1880
1890
|
this.context.strokeStyle = params.color ?? DEFAULT_COLOR;
|