@n3rdw1z4rd/core 0.11.0 → 0.14.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 +68 -2
- package/dist/index.d.mts +445 -34
- package/dist/index.d.ts +445 -34
- package/dist/index.js +2239 -255
- package/dist/index.mjs +2175 -254
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -1,2 +1,68 @@
|
|
|
1
|
-
# core
|
|
2
|
-
|
|
1
|
+
# @n3rdw1z4rd/core
|
|
2
|
+
|
|
3
|
+
A personal, browser-facing TypeScript toolkit consolidated out of several game/graphics side projects: math and RNG with no native `Math` dependency, an event emitter, two ECS flavors, procedural generation (pathfinding, Poisson-disk sampling, dungeon layout), a "particle life" simulation in 2D and 3D, and a set of Three.js helpers (camera rig, bootstrap scene, voxel meshing, texture atlases, procedural meshes).
|
|
4
|
+
|
|
5
|
+
Nothing here is trying to be a general-purpose framework - it's the shared plumbing that kept getting copy-pasted between projects, pulled into one place so it only has to be fixed once.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @n3rdw1z4rd/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Peer dependencies (install whichever your project actually uses):
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm install three simplex-noise
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`three` is only required if you import from `@n3rdw1z4rd/core/three` (or the top-level barrel, which re-exports it). `simplex-noise` is required for `Noise` and `AsteroidMesh`.
|
|
20
|
+
|
|
21
|
+
This package ships both CJS and ESM builds plus `.d.ts` types (built with `tsup`). It targets the browser - most modules touch `window`, `document`, or `HTMLCanvasElement`.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { rng, clamp, log, Clock } from '@n3rdw1z4rd/core';
|
|
27
|
+
|
|
28
|
+
log(rng.range(0, 10)); // random int in [0, 10)
|
|
29
|
+
log(clamp(15, 0, 10)); // 10
|
|
30
|
+
|
|
31
|
+
const clock = new Clock();
|
|
32
|
+
clock.run((dt) => {
|
|
33
|
+
// dt is seconds since last frame
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Everything (including the `three/*` modules) is re-exported from the package root, so `import { ThreeJsBoilerPlate } from '@n3rdw1z4rd/core'` works. Import from the `three` subpath if you want to make the Three.js dependency explicit in your own code:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { ThreeJsBoilerPlate } from '@n3rdw1z4rd/core/three';
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What's in here
|
|
44
|
+
|
|
45
|
+
| Area | Docs | Summary |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Math & RNG | [docs/math-and-rng.md](docs/math-and-rng.md) | Pure-math `sin`/`cos`/`floor`/etc. (no native `Math` calls), a seeded `Rng` class with an exclusive `range()`, gaussian sampling, shuffling. |
|
|
48
|
+
| 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). |
|
|
49
|
+
| 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`. |
|
|
50
|
+
| Clock, logging, input | [docs/clock-logging-input.md](docs/clock-logging-input.md) | `Clock` (rAF loop + FPS/dt tracking), `ClockStats` (on-screen overlay), leveled console loggers, `Input` (keyboard/mouse event normalization). |
|
|
51
|
+
| Noise | [docs/noise.md](docs/noise.md) | `Noise` (2D/3D/4D + fractal/fBm, wraps the `simplex-noise` package), plus a self-contained `SimplexNoise` class. |
|
|
52
|
+
| 2D primitives | [docs/2d-primitives.md](docs/2d-primitives.md) | `Vector`, `Rectangle`, `Map2D`/`Map3D` (sparse coordinate maps), `Tilemap<T>`. |
|
|
53
|
+
| Procedural generation | [docs/procedural-generation.md](docs/procedural-generation.md) | `AStar` pathfinding, `PoissonDiskSampler`, and a full room-based dungeon generator (`GenerateRooms`/`GenerateDoors`/`GenerateWalls`). |
|
|
54
|
+
| Particle life | [docs/particles.md](docs/particles.md) | 2D (canvas) and 3D (Three.js `Points`) "particle life" attraction-matrix simulations, `Color`, `SpatialPartition2d`/`3d`. |
|
|
55
|
+
| 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`). |
|
|
56
|
+
| 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`. |
|
|
57
|
+
| 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. |
|
|
58
|
+
| Three.js widgets | [docs/threejs-widgets.md](docs/threejs-widgets.md) | `CreatePaletteController`, a lil-gui color-swatch widget for picking a palette index. |
|
|
59
|
+
| Networking | [docs/networking.md](docs/networking.md) | `WorkerInterface`, a thin `Emitter`-based wrapper around `Worker`. |
|
|
60
|
+
| Misc | [docs/misc.md](docs/misc.md) | A couple of small standalone helpers: `isNullOrUndefined`, `getRedYellowGreenGradientHex`. |
|
|
61
|
+
|
|
62
|
+
## Design notes worth knowing before you dig in
|
|
63
|
+
|
|
64
|
+
- **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.
|
|
65
|
+
- **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.
|
|
66
|
+
- **`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.
|
|
67
|
+
- **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`).
|
|
68
|
+
- **No `gl-matrix` dependency, and no `VEC2`/`VEC3`/`VEC4` types (as of 0.14).** `Input.mousePosition`/`mousePosition2`, `CanvasRenderer`'s draw methods, `TextureAtlas.getUv`, and `Rng.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.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BoxGeometry,
|
|
1
|
+
import * as three from 'three';
|
|
2
|
+
import { BoxGeometry, MeshLambertMaterial, Texture, MeshLambertMaterialParameters, Group, PerspectiveCamera, Object3D, Scene, WebGLRenderer, WebGLRendererParameters, Intersection, ColorRepresentation, Mesh, Vector3, MeshBasicMaterial, MeshPhongMaterial, MeshStandardMaterial, MeshPhysicalMaterial, Points } from 'three';
|
|
3
|
+
import { OrbitControls } from 'three/examples/jsm/Addons.js';
|
|
4
|
+
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
|
|
5
|
+
|
|
6
|
+
declare class Map2D {
|
|
7
|
+
readonly defaultValue: number;
|
|
8
|
+
private _data;
|
|
9
|
+
get size(): number;
|
|
10
|
+
constructor(defaultValue?: number);
|
|
11
|
+
private _floor;
|
|
12
|
+
private _key;
|
|
13
|
+
private _pos;
|
|
14
|
+
clear(): void;
|
|
15
|
+
get(x: number, y: number, defaultValue?: number): number;
|
|
16
|
+
set(x: number, y: number, value?: number): void;
|
|
17
|
+
forEach(callback: (x: number, y: number, v: number) => void): void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface AStarPoint {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}
|
|
24
|
+
interface AStarFindPathParams {
|
|
25
|
+
useAdjacent?: boolean;
|
|
26
|
+
walkableValues?: number[];
|
|
27
|
+
}
|
|
28
|
+
declare class AStar {
|
|
29
|
+
map: Map2D;
|
|
30
|
+
constructor(map: Map2D);
|
|
31
|
+
private _manhattan;
|
|
32
|
+
private _isWalkable;
|
|
33
|
+
private _key;
|
|
34
|
+
findPath(a: AStarPoint, b: AStarPoint, params?: AStarFindPathParams): AStarPoint[];
|
|
35
|
+
}
|
|
3
36
|
|
|
4
37
|
declare class Clock {
|
|
5
38
|
private _lastFrameTime;
|
|
@@ -42,6 +75,134 @@ declare class ClockStats {
|
|
|
42
75
|
update(data: object): void;
|
|
43
76
|
}
|
|
44
77
|
|
|
78
|
+
declare class Color {
|
|
79
|
+
private _hex;
|
|
80
|
+
private _r;
|
|
81
|
+
private _g;
|
|
82
|
+
private _b;
|
|
83
|
+
private _a;
|
|
84
|
+
get r(): number;
|
|
85
|
+
set r(value: number);
|
|
86
|
+
get g(): number;
|
|
87
|
+
set g(value: number);
|
|
88
|
+
get b(): number;
|
|
89
|
+
set b(value: number);
|
|
90
|
+
get a(): number;
|
|
91
|
+
set a(value: number);
|
|
92
|
+
get hexStr(): string;
|
|
93
|
+
set hexStr(value: string);
|
|
94
|
+
get rgba(): number[];
|
|
95
|
+
constructor(r?: string | number, g?: number, b?: number, a?: number);
|
|
96
|
+
private static _normalize;
|
|
97
|
+
private _to_hex;
|
|
98
|
+
private _parse_hex_color_string;
|
|
99
|
+
static fromHsv(h: number, s: number, v: number, a?: number): Color;
|
|
100
|
+
static get BLACK(): Color;
|
|
101
|
+
static get GRAY(): Color;
|
|
102
|
+
static get WHITE(): Color;
|
|
103
|
+
static get RED(): Color;
|
|
104
|
+
static get GREEN(): Color;
|
|
105
|
+
static get BLUE(): Color;
|
|
106
|
+
static get YELLOW(): Color;
|
|
107
|
+
static get ORANGE(): Color;
|
|
108
|
+
static get PURPLE(): Color;
|
|
109
|
+
static get CYAN(): Color;
|
|
110
|
+
static get MAGENTA(): Color;
|
|
111
|
+
static fromName(name: string): Color;
|
|
112
|
+
static get TRANSPARENT(): Color;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare class Vector {
|
|
116
|
+
x: number;
|
|
117
|
+
y: number;
|
|
118
|
+
constructor(x?: number, y?: number);
|
|
119
|
+
clone(): Vector;
|
|
120
|
+
distanceTo(that: Vector): number;
|
|
121
|
+
floored(): Vector;
|
|
122
|
+
plus(x: number | Vector, y?: number): this;
|
|
123
|
+
minus(x: number | Vector, y?: number): this;
|
|
124
|
+
times(x: number | Vector, y?: number): this;
|
|
125
|
+
dividedBy(x: number | Vector, y?: number): this;
|
|
126
|
+
static get NORTH(): Vector;
|
|
127
|
+
static get SOUTH(): Vector;
|
|
128
|
+
static get EAST(): Vector;
|
|
129
|
+
static get WEST(): Vector;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare class Rectangle {
|
|
133
|
+
x: number;
|
|
134
|
+
y: number;
|
|
135
|
+
width: number;
|
|
136
|
+
height: number;
|
|
137
|
+
constructor(x?: number, y?: number, width?: number, height?: number);
|
|
138
|
+
area(): number;
|
|
139
|
+
contains(target: Vector | Rectangle, padding?: number): boolean;
|
|
140
|
+
intersects(other: Rectangle, padding?: number): boolean;
|
|
141
|
+
center(): Vector;
|
|
142
|
+
distanceTo(other: Rectangle): number;
|
|
143
|
+
clone(): Rectangle;
|
|
144
|
+
equals(other: Rectangle): boolean;
|
|
145
|
+
grow(padding: number): Rectangle;
|
|
146
|
+
vectorInside(vec: Vector, padding?: number): boolean;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare type KeyValue = {
|
|
150
|
+
[key: string]: any;
|
|
151
|
+
};
|
|
152
|
+
declare type XY = {
|
|
153
|
+
x: number;
|
|
154
|
+
y: number;
|
|
155
|
+
};
|
|
156
|
+
declare type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
157
|
+
[key: string]: JSONValue;
|
|
158
|
+
};
|
|
159
|
+
declare type DataJson = {
|
|
160
|
+
[k: string]: JSONValue;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
type RectPair = {
|
|
164
|
+
a: Rectangle;
|
|
165
|
+
b: Rectangle;
|
|
166
|
+
};
|
|
167
|
+
type PointPair = {
|
|
168
|
+
a: XY;
|
|
169
|
+
b: XY;
|
|
170
|
+
};
|
|
171
|
+
interface RoomsParams {
|
|
172
|
+
size?: number;
|
|
173
|
+
minSize?: number;
|
|
174
|
+
maxSize?: number;
|
|
175
|
+
padding?: number;
|
|
176
|
+
maxIterations?: number;
|
|
177
|
+
}
|
|
178
|
+
interface PathsParams {
|
|
179
|
+
timeout?: number;
|
|
180
|
+
extraPaths?: number;
|
|
181
|
+
extraPathDensity?: number;
|
|
182
|
+
astarFindPathParams?: AStarFindPathParams;
|
|
183
|
+
}
|
|
184
|
+
interface DoorsParams {
|
|
185
|
+
plotDoors?: boolean;
|
|
186
|
+
chanceExists?: number;
|
|
187
|
+
chanceOpen?: number;
|
|
188
|
+
chanceLocked?: number;
|
|
189
|
+
}
|
|
190
|
+
interface GenerateRoomsParams {
|
|
191
|
+
map?: Map2D;
|
|
192
|
+
rooms?: RoomsParams;
|
|
193
|
+
paths?: PathsParams;
|
|
194
|
+
}
|
|
195
|
+
declare const TILE_EMPTY = 0;
|
|
196
|
+
declare const TILE_FLOOR = 1;
|
|
197
|
+
declare const TILE_PATH = 2;
|
|
198
|
+
declare function GenerateRooms(params?: GenerateRoomsParams): {
|
|
199
|
+
map: Map2D;
|
|
200
|
+
rooms: Rectangle[];
|
|
201
|
+
paths: XY[][];
|
|
202
|
+
};
|
|
203
|
+
declare function GenerateDoors(map: Map2D, paths: XY[][], params?: DoorsParams): XY[];
|
|
204
|
+
declare function GenerateWalls(map: Map2D): XY[];
|
|
205
|
+
|
|
45
206
|
type ECSSystemCallback = (entity: ECSEntity, components: any) => void;
|
|
46
207
|
type ECSTickCallback = () => void;
|
|
47
208
|
interface ECSSystem {
|
|
@@ -92,8 +253,14 @@ declare class Emitter {
|
|
|
92
253
|
constructor();
|
|
93
254
|
on<T extends string[]>(...eventName: [...T, Listener]): this;
|
|
94
255
|
emit(eventName: string, ...args: any[]): this;
|
|
256
|
+
clear(eventName?: string): this;
|
|
95
257
|
}
|
|
96
258
|
declare const GlobalEmitter: Emitter;
|
|
259
|
+
declare class EventBus extends EventTarget {
|
|
260
|
+
emit(type: string, detail?: any): void;
|
|
261
|
+
on(type: string, cb: (e: CustomEvent) => void): void;
|
|
262
|
+
}
|
|
263
|
+
declare const eventBus: EventBus;
|
|
97
264
|
|
|
98
265
|
interface InputState {
|
|
99
266
|
state: number;
|
|
@@ -112,8 +279,8 @@ declare class Input extends Emitter {
|
|
|
112
279
|
private _mouseButtonStates;
|
|
113
280
|
private _mousePosition;
|
|
114
281
|
private _mousePosition2;
|
|
115
|
-
get mousePosition():
|
|
116
|
-
get mousePosition2():
|
|
282
|
+
get mousePosition(): [number, number];
|
|
283
|
+
get mousePosition2(): [number, number];
|
|
117
284
|
constructor();
|
|
118
285
|
private _getCommonEventProps;
|
|
119
286
|
private _onKeyDown;
|
|
@@ -134,9 +301,42 @@ declare const loginf: (...args: any[]) => void;
|
|
|
134
301
|
declare const logwrn: (...args: any[]) => void;
|
|
135
302
|
declare const logerr: (...args: any[]) => void;
|
|
136
303
|
|
|
137
|
-
|
|
304
|
+
type Map3DData = Map<string, number>;
|
|
305
|
+
declare class Map3D {
|
|
306
|
+
readonly defaultValue: number;
|
|
307
|
+
private _data;
|
|
308
|
+
get data(): Map3DData;
|
|
309
|
+
constructor(defaultValue?: number);
|
|
310
|
+
private _floor;
|
|
311
|
+
private _key;
|
|
312
|
+
private _pos;
|
|
313
|
+
clear(): void;
|
|
314
|
+
get(x: number, y: number, z: number, defaultValue?: number): number;
|
|
315
|
+
set(x: number, y: number, z: number, value?: number): void;
|
|
316
|
+
forEach(callback: (x: number, y: number, z: number, v: number) => void): void;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
declare const PI = 3.141592653589793;
|
|
320
|
+
declare function abs(n: number): number;
|
|
321
|
+
declare function min(a: number, b: number): number;
|
|
322
|
+
declare function max(a: number, b: number): number;
|
|
323
|
+
declare function floor(n: number): number;
|
|
324
|
+
declare function ceil(n: number): number;
|
|
325
|
+
declare function round(n: number): number;
|
|
326
|
+
declare function sqrt(n: number): number;
|
|
327
|
+
declare function pow(base: number, exp: number): number;
|
|
328
|
+
declare function hypot2(x: number, y: number): number;
|
|
329
|
+
declare function hypot3(x: number, y: number, z: number): number;
|
|
330
|
+
declare function imul(a: number, b: number): number;
|
|
331
|
+
declare function sin(n: number): number;
|
|
332
|
+
declare function cos(n: number): number;
|
|
333
|
+
declare function clamp(value: number, lo: number, hi: number): number;
|
|
138
334
|
declare function deg2rad(value: number): number;
|
|
139
335
|
declare function lerp(start: number, end: number, scale: number): number;
|
|
336
|
+
declare function distance(x1: number, y1: number, x2: number, y2: number): number;
|
|
337
|
+
declare function squaredDistance(x1: number, y1: number, x2: number, y2: number): number;
|
|
338
|
+
declare function manhattanDistance(x1: number, y1: number, x2: number, y2: number): number;
|
|
339
|
+
declare function roundTo(value: number, digits: number, base?: number): number;
|
|
140
340
|
|
|
141
341
|
declare function isNullOrUndefined(target: any): boolean;
|
|
142
342
|
declare const getRedYellowGreenGradientHex: (min: number, max?: number) => string;
|
|
@@ -159,6 +359,42 @@ declare class Noise {
|
|
|
159
359
|
static fractal3d(x: number, y: number, z: number, fractalParams: FractalParams): number;
|
|
160
360
|
}
|
|
161
361
|
|
|
362
|
+
declare class Renderer {
|
|
363
|
+
private _screenCanvas;
|
|
364
|
+
private _bufferCanvas;
|
|
365
|
+
screenContext: CanvasRenderingContext2D;
|
|
366
|
+
bufferContext: OffscreenCanvasRenderingContext2D;
|
|
367
|
+
get width(): number;
|
|
368
|
+
get height(): number;
|
|
369
|
+
constructor(canvas?: HTMLCanvasElement);
|
|
370
|
+
appendTo(target: HTMLElement, autoResize?: boolean): void;
|
|
371
|
+
resize(displayWidth?: number, displayHeight?: number): boolean;
|
|
372
|
+
setPixel(x: number, y: number, color: Color, size?: number): void;
|
|
373
|
+
render(): void;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
declare class ParticleSystem2d {
|
|
377
|
+
readonly particleCount = 2000;
|
|
378
|
+
private _particleSize;
|
|
379
|
+
private _frictionHalfLife;
|
|
380
|
+
private _range;
|
|
381
|
+
private _rangeFactor;
|
|
382
|
+
private _attractionMatrix;
|
|
383
|
+
private _particles;
|
|
384
|
+
private _spatialPartition;
|
|
385
|
+
constructor();
|
|
386
|
+
private _calcForce;
|
|
387
|
+
private _updateVelocities;
|
|
388
|
+
private _updatePositions;
|
|
389
|
+
update(renderer: Renderer, dt: number): void;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
interface Vec2 {
|
|
393
|
+
x: number;
|
|
394
|
+
y: number;
|
|
395
|
+
}
|
|
396
|
+
declare function PoissonDiskSampler(width: number, height: number, minDist: number, maxPoints?: number): Vec2[];
|
|
397
|
+
|
|
162
398
|
interface DrawParams {
|
|
163
399
|
radius?: number;
|
|
164
400
|
fill?: boolean;
|
|
@@ -173,27 +409,17 @@ declare class CanvasRenderer {
|
|
|
173
409
|
textBaseline: CanvasTextBaseline;
|
|
174
410
|
get width(): number;
|
|
175
411
|
get height(): number;
|
|
176
|
-
get center():
|
|
412
|
+
get center(): [number, number];
|
|
177
413
|
constructor(canvas?: HTMLCanvasElement);
|
|
178
414
|
appendTo(target?: HTMLElement, autoResize?: boolean): void;
|
|
179
415
|
resize(displayWidth?: number, displayHeight?: number): boolean;
|
|
180
416
|
clear(): void;
|
|
181
|
-
drawPoint(xy:
|
|
182
|
-
drawBox(xy:
|
|
183
|
-
drawLine(x1y1x2y2:
|
|
184
|
-
drawText(text: string, xy:
|
|
417
|
+
drawPoint(xy: [number, number], params?: DrawParams): void;
|
|
418
|
+
drawBox(xy: [number, number], wh: [number, number], params?: DrawParams): void;
|
|
419
|
+
drawLine(x1y1x2y2: [number, number, number, number], color?: string): void;
|
|
420
|
+
drawText(text: string, xy: [number, number], color?: string, size?: number, font?: string): void;
|
|
185
421
|
}
|
|
186
422
|
|
|
187
|
-
declare type KeyValue = {
|
|
188
|
-
[key: string]: any;
|
|
189
|
-
};
|
|
190
|
-
declare type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
191
|
-
[key: string]: JSONValue;
|
|
192
|
-
};
|
|
193
|
-
declare type DataJson = {
|
|
194
|
-
[k: string]: JSONValue;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
423
|
declare enum ShaderType {
|
|
198
424
|
VERTEX,
|
|
199
425
|
FRAGMENT
|
|
@@ -207,7 +433,7 @@ type ProgramInfo = {
|
|
|
207
433
|
attributes: KeyValue;
|
|
208
434
|
uniforms: KeyValue;
|
|
209
435
|
};
|
|
210
|
-
type
|
|
436
|
+
type RGBA = [number, number, number, number];
|
|
211
437
|
declare function CreateWebGlContext(canvas?: HTMLCanvasElement): WebGL2RenderingContext;
|
|
212
438
|
declare function ResizeWebGlContext(gl: WebGL2RenderingContext, displayWidth?: number, displayHeight?: number): boolean;
|
|
213
439
|
declare function CompileShader(gl: WebGL2RenderingContext, type: ShaderType, source: string): WebGLShader;
|
|
@@ -232,19 +458,22 @@ declare class WebGlRenderer {
|
|
|
232
458
|
}
|
|
233
459
|
|
|
234
460
|
declare class Rng {
|
|
461
|
+
private __seed;
|
|
235
462
|
private _seed;
|
|
236
463
|
private _uid_characters;
|
|
237
464
|
constructor();
|
|
238
465
|
get seed(): number;
|
|
239
466
|
set seed(value: number);
|
|
467
|
+
get startingSeed(): number;
|
|
240
468
|
get nextf(): number;
|
|
241
469
|
get nexti(): number;
|
|
242
470
|
range(min: number, max?: number): number;
|
|
471
|
+
randomUnitVector(): [number, number];
|
|
472
|
+
parkMillerNormal(): number;
|
|
243
473
|
choose(...args: any[]): any;
|
|
244
474
|
shuffle(value: Array<any> | string): Array<any> | string;
|
|
245
475
|
uid(length?: number): string;
|
|
246
476
|
randomMatrix(size: number): number[][];
|
|
247
|
-
randomUnitVector(): vec2;
|
|
248
477
|
}
|
|
249
478
|
declare const rng: Rng;
|
|
250
479
|
|
|
@@ -262,6 +491,42 @@ declare class SimplexNoise {
|
|
|
262
491
|
noise3d(xin: number, yin: number, zin: number): number;
|
|
263
492
|
}
|
|
264
493
|
|
|
494
|
+
interface SpatialPartitionEntity2d {
|
|
495
|
+
x: number;
|
|
496
|
+
y: number;
|
|
497
|
+
}
|
|
498
|
+
declare class SpatialPartition2d {
|
|
499
|
+
cells: SpatialPartitionEntity2d[][][];
|
|
500
|
+
cellSize: number;
|
|
501
|
+
entities: SpatialPartitionEntity2d[];
|
|
502
|
+
constructor(cellSize: number, entities: SpatialPartitionEntity2d[]);
|
|
503
|
+
addEntity(entity: SpatialPartitionEntity2d): void;
|
|
504
|
+
getCell(x: number, y: number): SpatialPartitionEntity2d[];
|
|
505
|
+
getCellNeighbors(x: number, y: number): SpatialPartitionEntity2d[][];
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
interface SpatialPartitionEntity3d {
|
|
509
|
+
x: number;
|
|
510
|
+
y: number;
|
|
511
|
+
z: number;
|
|
512
|
+
}
|
|
513
|
+
declare class SpatialPartition3d {
|
|
514
|
+
cells: SpatialPartitionEntity3d[][][][];
|
|
515
|
+
cellSize: number;
|
|
516
|
+
entities: SpatialPartitionEntity3d[];
|
|
517
|
+
constructor(cellSize: number, entities: SpatialPartitionEntity3d[]);
|
|
518
|
+
getCell(x: number, y: number, z: number): SpatialPartitionEntity3d[];
|
|
519
|
+
getCellNeighbors(cx: number, cy: number, cz: number): SpatialPartitionEntity3d[][];
|
|
520
|
+
addEntity(entity: SpatialPartitionEntity3d): void;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
declare class Tilemap<T = number> {
|
|
524
|
+
map: Map<string, T>;
|
|
525
|
+
private _key;
|
|
526
|
+
get(x: number, y: number): T | undefined;
|
|
527
|
+
set(x: number, y: number, v: T): void;
|
|
528
|
+
}
|
|
529
|
+
|
|
265
530
|
declare class CubeSphereGeometry extends BoxGeometry {
|
|
266
531
|
readonly size: number;
|
|
267
532
|
readonly segments: number;
|
|
@@ -277,6 +542,7 @@ interface TextureData {
|
|
|
277
542
|
texture: Texture;
|
|
278
543
|
}
|
|
279
544
|
declare function LoadTexture(url: string): Promise<TextureData>;
|
|
545
|
+
declare function CreateSubTexture(texture: Texture, x: number, y: number, w: number, h: number): Texture;
|
|
280
546
|
declare class TextureAtlas extends MeshLambertMaterial {
|
|
281
547
|
readonly textureData: TextureData;
|
|
282
548
|
readonly textureWidth: number;
|
|
@@ -284,11 +550,33 @@ declare class TextureAtlas extends MeshLambertMaterial {
|
|
|
284
550
|
private _uw;
|
|
285
551
|
private _uh;
|
|
286
552
|
constructor(textureData: TextureData, textureWidth: number, textureHeight?: number, params?: MeshLambertMaterialParameters);
|
|
287
|
-
getUv(voxel: number, ux: number, uy: number):
|
|
553
|
+
getUv(voxel: number, ux: number, uy: number): [number, number];
|
|
288
554
|
static CreateFromUrl(url: string, textureWidth: number, textureHeight?: number, params?: MeshLambertMaterialParameters): Promise<TextureAtlas>;
|
|
289
555
|
}
|
|
556
|
+
interface AtlasParams {
|
|
557
|
+
tilePixelWidth?: number;
|
|
558
|
+
tilePixelHeight?: number;
|
|
559
|
+
tilePixelOffsetWidth?: number;
|
|
560
|
+
tilePixelOffsetHeight?: number;
|
|
561
|
+
}
|
|
562
|
+
interface AtlasTextureMaterialParams extends MeshLambertMaterialParameters {
|
|
563
|
+
}
|
|
564
|
+
declare class AtlasTextureMaterial extends MeshLambertMaterial {
|
|
565
|
+
readonly textureData: TextureData;
|
|
566
|
+
readonly tilePixelWidth: number;
|
|
567
|
+
readonly tilePixelHeight: number;
|
|
568
|
+
private _tileCount;
|
|
569
|
+
private _uvWidth;
|
|
570
|
+
private _uvHeight;
|
|
571
|
+
private _textureOffsetWidth;
|
|
572
|
+
private _textureOffsetHeight;
|
|
573
|
+
constructor(textureData: TextureData, atlasParams?: AtlasParams, materialParams?: AtlasTextureMaterialParams);
|
|
574
|
+
getTileUVs(tileIndex: number, vertexIndex: number): [number, number];
|
|
575
|
+
static fromUrl(url: string, atlasParams?: AtlasParams, materialParams?: AtlasTextureMaterialParams): Promise<AtlasTextureMaterial>;
|
|
576
|
+
}
|
|
290
577
|
|
|
291
578
|
interface ThreeJsCameraRigParams {
|
|
579
|
+
camera?: PerspectiveCamera;
|
|
292
580
|
fov?: number;
|
|
293
581
|
aspect?: number;
|
|
294
582
|
near?: number;
|
|
@@ -315,6 +603,7 @@ interface SetupBasicSceneParams {
|
|
|
315
603
|
directionalLight?: boolean;
|
|
316
604
|
gridHelper?: boolean;
|
|
317
605
|
cameraDistance?: number;
|
|
606
|
+
enableControls?: boolean;
|
|
318
607
|
}
|
|
319
608
|
interface ThreeJsBoilerPlateParams {
|
|
320
609
|
parentElement?: HTMLElement;
|
|
@@ -329,15 +618,19 @@ interface ThreeJsBoilerPlateParams {
|
|
|
329
618
|
}
|
|
330
619
|
declare class ThreeJsBoilerPlate {
|
|
331
620
|
clock: Clock;
|
|
332
|
-
scene: Scene
|
|
621
|
+
scene: Scene<three.Object3DEventMap>;
|
|
333
622
|
input: Input;
|
|
334
623
|
private raycaster;
|
|
335
624
|
renderer: WebGLRenderer;
|
|
336
625
|
cameraRig: ThreeJsCameraRig;
|
|
626
|
+
orbitControls?: OrbitControls;
|
|
337
627
|
get canvas(): HTMLCanvasElement;
|
|
338
628
|
get camera(): PerspectiveCamera;
|
|
339
629
|
rng: Rng;
|
|
340
630
|
constructor(params?: ThreeJsBoilerPlateParams);
|
|
631
|
+
enableCameraRigControls(): void;
|
|
632
|
+
enableOrbitControls(): Promise<void>;
|
|
633
|
+
update(): void;
|
|
341
634
|
appendTo(htmlElement?: HTMLElement): void;
|
|
342
635
|
resize(displayWidth?: number, displayHeight?: number): boolean;
|
|
343
636
|
setupBasicScene(params?: SetupBasicSceneParams): void;
|
|
@@ -354,16 +647,134 @@ declare class ThreeJsPlayerController extends Group {
|
|
|
354
647
|
update(deltaTime: number): void;
|
|
355
648
|
}
|
|
356
649
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
650
|
+
type Voxel = {
|
|
651
|
+
x: number;
|
|
652
|
+
y: number;
|
|
653
|
+
z: number;
|
|
654
|
+
color: number;
|
|
655
|
+
};
|
|
656
|
+
type VoxelMap = Map<string, number>;
|
|
657
|
+
type VoxelMaterial = MeshBasicMaterial | MeshLambertMaterial | MeshPhongMaterial | MeshStandardMaterial | MeshPhysicalMaterial;
|
|
658
|
+
interface VoxelData {
|
|
659
|
+
name: string;
|
|
660
|
+
width: number;
|
|
661
|
+
depth: number;
|
|
662
|
+
height: number;
|
|
663
|
+
palette: ColorRepresentation[];
|
|
664
|
+
voxels: Voxel[];
|
|
665
|
+
}
|
|
666
|
+
declare class VoxelMesh extends Mesh {
|
|
667
|
+
readonly type: string;
|
|
668
|
+
width: number;
|
|
669
|
+
depth: number;
|
|
670
|
+
height: number;
|
|
671
|
+
colorPalette: ColorRepresentation[];
|
|
672
|
+
voxels: VoxelMap;
|
|
673
|
+
needsGeometryUpdate: boolean;
|
|
674
|
+
constructor(width: number, depth: number, height: number, material: VoxelMaterial, name?: string);
|
|
675
|
+
private _xyz2k;
|
|
676
|
+
private _k2xyz;
|
|
677
|
+
get(x: number, y: number, z: number): number;
|
|
678
|
+
set(x: number, y: number, z: number, n?: number): void;
|
|
679
|
+
clearVoxels(): void;
|
|
680
|
+
setSize(width: number, depth: number, height: number): void;
|
|
681
|
+
forEachVoxel(callback: (x: number, y: number, z: number, n: number) => void): void;
|
|
682
|
+
importVoxelData(voxelData: VoxelData): void;
|
|
366
683
|
updateGeometry(): void;
|
|
684
|
+
exportData(): VoxelData;
|
|
685
|
+
}
|
|
686
|
+
declare const VoxelFaces: Array<Array<number[]>>;
|
|
687
|
+
declare function BuildDefaultPalette(palette?: ColorRepresentation[]): ColorRepresentation[];
|
|
688
|
+
declare const Colors: {
|
|
689
|
+
rgb12: string[];
|
|
690
|
+
rgb24: string[];
|
|
691
|
+
rgb48: string[];
|
|
692
|
+
rgb64: string[];
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
declare class ParticleSystem3d extends Group {
|
|
696
|
+
readonly particleCount = 1000;
|
|
697
|
+
private _geometry;
|
|
698
|
+
private _particles;
|
|
699
|
+
private _frictionHalfLife;
|
|
700
|
+
private _range;
|
|
701
|
+
private _rangeFactor;
|
|
702
|
+
private _attractionMatrix;
|
|
703
|
+
private _spatialPartition;
|
|
704
|
+
constructor();
|
|
705
|
+
private _calcForce;
|
|
706
|
+
private _updateVelocities;
|
|
707
|
+
private _updatePositions;
|
|
708
|
+
private _sortParticles;
|
|
709
|
+
private _updateGeometry;
|
|
710
|
+
update(camera: PerspectiveCamera, dt: number): void;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
interface AsteroidOptions {
|
|
714
|
+
radius?: number;
|
|
715
|
+
detail?: number;
|
|
716
|
+
noiseScale?: number;
|
|
717
|
+
displacement?: number;
|
|
718
|
+
secondaryNoise?: boolean;
|
|
719
|
+
color?: number;
|
|
720
|
+
}
|
|
721
|
+
declare class AsteroidMesh extends Mesh {
|
|
722
|
+
constructor(options?: AsteroidOptions);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
declare function CreateStarfield(radius?: number, count?: number, color?: number): Points;
|
|
726
|
+
declare function CreateSystemStar(position?: Vector3): Group;
|
|
727
|
+
|
|
728
|
+
interface ColorSelectionOptions {
|
|
729
|
+
signal: AbortSignal;
|
|
730
|
+
}
|
|
731
|
+
interface ColorSelectionResult {
|
|
732
|
+
sRGBHex: ColorRepresentation;
|
|
733
|
+
}
|
|
734
|
+
interface EyeDropper {
|
|
735
|
+
new (): EyeDropper;
|
|
736
|
+
open: (options?: ColorSelectionOptions) => Promise<ColorSelectionResult>;
|
|
737
|
+
}
|
|
738
|
+
declare global {
|
|
739
|
+
interface Window {
|
|
740
|
+
EyeDropper?: EyeDropper;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
type PaletteControllerOnChange = (colorIndex: number) => void;
|
|
744
|
+
interface PaletteController {
|
|
745
|
+
$innerDiv: HTMLDivElement;
|
|
746
|
+
colorButtons: HTMLElement[];
|
|
747
|
+
colorButtonSize: number;
|
|
748
|
+
selectedBorderStyle: string;
|
|
749
|
+
currentColorIndex: number;
|
|
750
|
+
colorPalette: ColorRepresentation[];
|
|
751
|
+
updatePaletteColors(): void;
|
|
752
|
+
setSelectedColor(colorIndex?: number): void;
|
|
753
|
+
findClosestColorMatchIndex(color: ColorRepresentation): number;
|
|
754
|
+
}
|
|
755
|
+
declare function CreatePaletteController(parentGui: GUI, colorPalette: ColorRepresentation[], onChange?: PaletteControllerOnChange, folderName?: string): Promise<PaletteController>;
|
|
756
|
+
|
|
757
|
+
type ThreeComponent = Record<string, any>;
|
|
758
|
+
interface ThreeEntity extends Object3D {
|
|
759
|
+
userData: {
|
|
760
|
+
entityId: string;
|
|
761
|
+
components: Record<string, ThreeComponent>;
|
|
762
|
+
[key: string]: any;
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
declare function GenerateEntityId(): string;
|
|
766
|
+
declare function CreateThreeEntity(obj?: Object3D): ThreeEntity;
|
|
767
|
+
declare function AddThreeComponent<T extends ThreeComponent>(entity: ThreeEntity, name: string, component: T): void;
|
|
768
|
+
declare function GetThreeComponent<T extends ThreeComponent>(entity: ThreeEntity, name: string): T | undefined;
|
|
769
|
+
declare function RemoveThreeComponent(entity: ThreeEntity, name: string): void;
|
|
770
|
+
declare function IsThreeEntity(obj: Object3D): boolean;
|
|
771
|
+
type ThreeSystem = (entities: Map<string, ThreeEntity>, delta: number, ...args: any) => void;
|
|
772
|
+
|
|
773
|
+
declare class WorkerInterface extends Emitter {
|
|
774
|
+
private _worker;
|
|
775
|
+
constructor(url: string | URL);
|
|
776
|
+
postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;
|
|
777
|
+
terminate(): void;
|
|
367
778
|
}
|
|
368
779
|
|
|
369
|
-
export { CanvasRenderer, Clock, ClockStats, type
|
|
780
|
+
export { AStar, type AStarFindPathParams, type AStarPoint, AddThreeComponent, AsteroidMesh, type AsteroidOptions, type AtlasParams, AtlasTextureMaterial, type AtlasTextureMaterialParams, BuildDefaultPalette, CanvasRenderer, Clock, ClockStats, Color, type ColorSelectionOptions, type ColorSelectionResult, Colors, type CommonEventProps, CompileShader, CreatePaletteController, CreateProgram, CreateProgramInfo, CreateStarfield, CreateSubTexture, CreateSystemStar, CreateThreeEntity, CreateWebGlContext, CubeSphereGeometry, type DataJson, type DoorsParams, type DrawParams, ECS, type ECSEntity, type ECSSystem, type ECSSystemCallback, type ECSTickCallback, Emitter, EventBus, type EyeDropper, type FractalParams, GenerateDoors, GenerateEntityId, GenerateRooms, type GenerateRoomsParams, GenerateWalls, GetProgramLocations, GetThreeComponent, GlobalEmitter, Input, type InputState, IsThreeEntity, type JSONValue, type KeyValue, type Listener, LoadTexture, Map2D, Map3D, type Map3DData, Noise, PI, type PaletteController, type PaletteControllerOnChange, ParticleSystem2d, ParticleSystem3d, type PathsParams, type PointPair, PoissonDiskSampler, type ProgramInfo, type ProgramLocations, type RGBA, type RectPair, Rectangle, RemoveThreeComponent, Renderer, type RendererParams, ResizeWebGlContext, Rng, type RoomsParams, type SetupBasicSceneParams, ShaderType, SimplexNoise, SpatialPartition2d, SpatialPartition3d, type SpatialPartitionEntity2d, type SpatialPartitionEntity3d, TILE_EMPTY, TILE_FLOOR, TILE_PATH, TextureAtlas, type TextureData, type ThreeComponent, type ThreeEntity, ThreeJsBoilerPlate, type ThreeJsBoilerPlateParams, ThreeJsCameraRig, type ThreeJsCameraRigParams, ThreeJsPlayerController, type ThreeSystem, Tilemap, Vector, type Voxel, type VoxelData, VoxelFaces, type VoxelMap, type VoxelMaterial, VoxelMesh, WebGlRenderer, WorkerInterface, type XY, abs, ceil, clamp, cos, deg2rad, distance, eventBus, floor, getRedYellowGreenGradientHex, hypot2, hypot3, imul, isNullOrUndefined, lerp, log, logdev, logerr, loginf, logwrn, manhattanDistance, max, min, pow, rng, round, roundTo, sin, sqrt, squaredDistance };
|