@n3rdw1z4rd/core 0.13.0 → 0.14.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 +68 -2
- package/dist/index.d.mts +10 -15
- package/dist/index.d.ts +10 -15
- package/dist/index.js +8 -11
- package/dist/index.mjs +8 -11
- package/package.json +19 -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,4 +1,3 @@
|
|
|
1
|
-
import { vec2, vec4 } from 'gl-matrix';
|
|
2
1
|
import * as three from 'three';
|
|
3
2
|
import { BoxGeometry, MeshLambertMaterial, Texture, MeshLambertMaterialParameters, Group, PerspectiveCamera, Object3D, Scene, WebGLRenderer, WebGLRendererParameters, Intersection, ColorRepresentation, Mesh, Vector3, MeshBasicMaterial, MeshPhongMaterial, MeshStandardMaterial, MeshPhysicalMaterial, Points } from 'three';
|
|
4
3
|
import { OrbitControls } from 'three/examples/jsm/Addons.js';
|
|
@@ -280,8 +279,8 @@ declare class Input extends Emitter {
|
|
|
280
279
|
private _mouseButtonStates;
|
|
281
280
|
private _mousePosition;
|
|
282
281
|
private _mousePosition2;
|
|
283
|
-
get mousePosition():
|
|
284
|
-
get mousePosition2():
|
|
282
|
+
get mousePosition(): [number, number];
|
|
283
|
+
get mousePosition2(): [number, number];
|
|
285
284
|
constructor();
|
|
286
285
|
private _getCommonEventProps;
|
|
287
286
|
private _onKeyDown;
|
|
@@ -318,10 +317,6 @@ declare class Map3D {
|
|
|
318
317
|
}
|
|
319
318
|
|
|
320
319
|
declare const PI = 3.141592653589793;
|
|
321
|
-
type VEC2 = [number, number];
|
|
322
|
-
type VEC3 = VEC2 & [number];
|
|
323
|
-
type VEC4 = VEC3 & [number];
|
|
324
|
-
type COLOR = VEC3;
|
|
325
320
|
declare function abs(n: number): number;
|
|
326
321
|
declare function min(a: number, b: number): number;
|
|
327
322
|
declare function max(a: number, b: number): number;
|
|
@@ -414,15 +409,15 @@ declare class CanvasRenderer {
|
|
|
414
409
|
textBaseline: CanvasTextBaseline;
|
|
415
410
|
get width(): number;
|
|
416
411
|
get height(): number;
|
|
417
|
-
get center():
|
|
412
|
+
get center(): [number, number];
|
|
418
413
|
constructor(canvas?: HTMLCanvasElement);
|
|
419
414
|
appendTo(target?: HTMLElement, autoResize?: boolean): void;
|
|
420
415
|
resize(displayWidth?: number, displayHeight?: number): boolean;
|
|
421
416
|
clear(): void;
|
|
422
|
-
drawPoint(xy:
|
|
423
|
-
drawBox(xy:
|
|
424
|
-
drawLine(x1y1x2y2:
|
|
425
|
-
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;
|
|
426
421
|
}
|
|
427
422
|
|
|
428
423
|
declare enum ShaderType {
|
|
@@ -473,7 +468,7 @@ declare class Rng {
|
|
|
473
468
|
get nextf(): number;
|
|
474
469
|
get nexti(): number;
|
|
475
470
|
range(min: number, max?: number): number;
|
|
476
|
-
randomUnitVector():
|
|
471
|
+
randomUnitVector(): [number, number];
|
|
477
472
|
parkMillerNormal(): number;
|
|
478
473
|
choose(...args: any[]): any;
|
|
479
474
|
shuffle(value: Array<any> | string): Array<any> | string;
|
|
@@ -555,7 +550,7 @@ declare class TextureAtlas extends MeshLambertMaterial {
|
|
|
555
550
|
private _uw;
|
|
556
551
|
private _uh;
|
|
557
552
|
constructor(textureData: TextureData, textureWidth: number, textureHeight?: number, params?: MeshLambertMaterialParameters);
|
|
558
|
-
getUv(voxel: number, ux: number, uy: number):
|
|
553
|
+
getUv(voxel: number, ux: number, uy: number): [number, number];
|
|
559
554
|
static CreateFromUrl(url: string, textureWidth: number, textureHeight?: number, params?: MeshLambertMaterialParameters): Promise<TextureAtlas>;
|
|
560
555
|
}
|
|
561
556
|
interface AtlasParams {
|
|
@@ -782,4 +777,4 @@ declare class WorkerInterface extends Emitter {
|
|
|
782
777
|
terminate(): void;
|
|
783
778
|
}
|
|
784
779
|
|
|
785
|
-
export { AStar, type AStarFindPathParams, type AStarPoint, AddThreeComponent, AsteroidMesh, type AsteroidOptions, type AtlasParams, AtlasTextureMaterial, type AtlasTextureMaterialParams, BuildDefaultPalette,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { vec2, vec4 } from 'gl-matrix';
|
|
2
1
|
import * as three from 'three';
|
|
3
2
|
import { BoxGeometry, MeshLambertMaterial, Texture, MeshLambertMaterialParameters, Group, PerspectiveCamera, Object3D, Scene, WebGLRenderer, WebGLRendererParameters, Intersection, ColorRepresentation, Mesh, Vector3, MeshBasicMaterial, MeshPhongMaterial, MeshStandardMaterial, MeshPhysicalMaterial, Points } from 'three';
|
|
4
3
|
import { OrbitControls } from 'three/examples/jsm/Addons.js';
|
|
@@ -280,8 +279,8 @@ declare class Input extends Emitter {
|
|
|
280
279
|
private _mouseButtonStates;
|
|
281
280
|
private _mousePosition;
|
|
282
281
|
private _mousePosition2;
|
|
283
|
-
get mousePosition():
|
|
284
|
-
get mousePosition2():
|
|
282
|
+
get mousePosition(): [number, number];
|
|
283
|
+
get mousePosition2(): [number, number];
|
|
285
284
|
constructor();
|
|
286
285
|
private _getCommonEventProps;
|
|
287
286
|
private _onKeyDown;
|
|
@@ -318,10 +317,6 @@ declare class Map3D {
|
|
|
318
317
|
}
|
|
319
318
|
|
|
320
319
|
declare const PI = 3.141592653589793;
|
|
321
|
-
type VEC2 = [number, number];
|
|
322
|
-
type VEC3 = VEC2 & [number];
|
|
323
|
-
type VEC4 = VEC3 & [number];
|
|
324
|
-
type COLOR = VEC3;
|
|
325
320
|
declare function abs(n: number): number;
|
|
326
321
|
declare function min(a: number, b: number): number;
|
|
327
322
|
declare function max(a: number, b: number): number;
|
|
@@ -414,15 +409,15 @@ declare class CanvasRenderer {
|
|
|
414
409
|
textBaseline: CanvasTextBaseline;
|
|
415
410
|
get width(): number;
|
|
416
411
|
get height(): number;
|
|
417
|
-
get center():
|
|
412
|
+
get center(): [number, number];
|
|
418
413
|
constructor(canvas?: HTMLCanvasElement);
|
|
419
414
|
appendTo(target?: HTMLElement, autoResize?: boolean): void;
|
|
420
415
|
resize(displayWidth?: number, displayHeight?: number): boolean;
|
|
421
416
|
clear(): void;
|
|
422
|
-
drawPoint(xy:
|
|
423
|
-
drawBox(xy:
|
|
424
|
-
drawLine(x1y1x2y2:
|
|
425
|
-
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;
|
|
426
421
|
}
|
|
427
422
|
|
|
428
423
|
declare enum ShaderType {
|
|
@@ -473,7 +468,7 @@ declare class Rng {
|
|
|
473
468
|
get nextf(): number;
|
|
474
469
|
get nexti(): number;
|
|
475
470
|
range(min: number, max?: number): number;
|
|
476
|
-
randomUnitVector():
|
|
471
|
+
randomUnitVector(): [number, number];
|
|
477
472
|
parkMillerNormal(): number;
|
|
478
473
|
choose(...args: any[]): any;
|
|
479
474
|
shuffle(value: Array<any> | string): Array<any> | string;
|
|
@@ -555,7 +550,7 @@ declare class TextureAtlas extends MeshLambertMaterial {
|
|
|
555
550
|
private _uw;
|
|
556
551
|
private _uh;
|
|
557
552
|
constructor(textureData: TextureData, textureWidth: number, textureHeight?: number, params?: MeshLambertMaterialParameters);
|
|
558
|
-
getUv(voxel: number, ux: number, uy: number):
|
|
553
|
+
getUv(voxel: number, ux: number, uy: number): [number, number];
|
|
559
554
|
static CreateFromUrl(url: string, textureWidth: number, textureHeight?: number, params?: MeshLambertMaterialParameters): Promise<TextureAtlas>;
|
|
560
555
|
}
|
|
561
556
|
interface AtlasParams {
|
|
@@ -782,4 +777,4 @@ declare class WorkerInterface extends Emitter {
|
|
|
782
777
|
terminate(): void;
|
|
783
778
|
}
|
|
784
779
|
|
|
785
|
-
export { AStar, type AStarFindPathParams, type AStarPoint, AddThreeComponent, AsteroidMesh, type AsteroidOptions, type AtlasParams, AtlasTextureMaterial, type AtlasTextureMaterialParams, BuildDefaultPalette,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1375,13 +1375,12 @@ var EventBus = class extends EventTarget {
|
|
|
1375
1375
|
var eventBus = new EventBus();
|
|
1376
1376
|
|
|
1377
1377
|
// src/input.ts
|
|
1378
|
-
var import_gl_matrix = require("gl-matrix");
|
|
1379
1378
|
var Input = class extends Emitter {
|
|
1380
1379
|
inputThreshold = 200;
|
|
1381
1380
|
_keyStates = {};
|
|
1382
1381
|
_mouseButtonStates = {};
|
|
1383
|
-
_mousePosition =
|
|
1384
|
-
_mousePosition2 =
|
|
1382
|
+
_mousePosition = [0, 0];
|
|
1383
|
+
_mousePosition2 = [0, 0];
|
|
1385
1384
|
get mousePosition() {
|
|
1386
1385
|
return this._mousePosition;
|
|
1387
1386
|
}
|
|
@@ -1457,13 +1456,13 @@ var Input = class extends Emitter {
|
|
|
1457
1456
|
_onMouseMove(ev) {
|
|
1458
1457
|
const props = this._getCommonEventProps(ev);
|
|
1459
1458
|
const { buttons, offsetX, offsetY, movementX, movementY } = ev;
|
|
1460
|
-
this._mousePosition =
|
|
1459
|
+
this._mousePosition = [offsetX, offsetY];
|
|
1461
1460
|
const width = window.innerWidth;
|
|
1462
1461
|
const height = window.innerHeight;
|
|
1463
|
-
this._mousePosition2 =
|
|
1462
|
+
this._mousePosition2 = [
|
|
1464
1463
|
ev.clientX / width * 2 - 1,
|
|
1465
1464
|
-(ev.clientY / height) * 2 + 1
|
|
1466
|
-
|
|
1465
|
+
];
|
|
1467
1466
|
this.emit("mouse_move", {
|
|
1468
1467
|
...props,
|
|
1469
1468
|
buttons,
|
|
@@ -1910,7 +1909,6 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
|
1910
1909
|
}
|
|
1911
1910
|
|
|
1912
1911
|
// src/renderer/canvas-renderer.ts
|
|
1913
|
-
var import_gl_matrix2 = require("gl-matrix");
|
|
1914
1912
|
var CanvasRenderer = class {
|
|
1915
1913
|
ctx;
|
|
1916
1914
|
clearColor = "#000000";
|
|
@@ -1925,7 +1923,7 @@ var CanvasRenderer = class {
|
|
|
1925
1923
|
return this.ctx?.canvas.height ?? 0;
|
|
1926
1924
|
}
|
|
1927
1925
|
get center() {
|
|
1928
|
-
return
|
|
1926
|
+
return [this.width / 2, this.height / 2];
|
|
1929
1927
|
}
|
|
1930
1928
|
constructor(canvas) {
|
|
1931
1929
|
this.ctx = (canvas ?? document.createElement("canvas")).getContext("2d");
|
|
@@ -2451,7 +2449,6 @@ var CubeSphereGeometry = class extends import_three.BoxGeometry {
|
|
|
2451
2449
|
};
|
|
2452
2450
|
|
|
2453
2451
|
// src/three/texture-atlas.ts
|
|
2454
|
-
var import_gl_matrix3 = require("gl-matrix");
|
|
2455
2452
|
var import_three2 = require("three");
|
|
2456
2453
|
function LoadTexture(url) {
|
|
2457
2454
|
return new Promise((res, rej) => {
|
|
@@ -2506,10 +2503,10 @@ var TextureAtlas = class _TextureAtlas extends import_three2.MeshLambertMaterial
|
|
|
2506
2503
|
_uw;
|
|
2507
2504
|
_uh;
|
|
2508
2505
|
getUv(voxel, ux, uy) {
|
|
2509
|
-
return
|
|
2506
|
+
return [
|
|
2510
2507
|
(voxel + ux) * this._uw,
|
|
2511
2508
|
1 - (1 - uy) * this._uh
|
|
2512
|
-
|
|
2509
|
+
];
|
|
2513
2510
|
}
|
|
2514
2511
|
static CreateFromUrl(url, textureWidth, textureHeight = textureWidth, params) {
|
|
2515
2512
|
return LoadTexture(url).then((textureData) => new _TextureAtlas(
|
package/dist/index.mjs
CHANGED
|
@@ -1249,13 +1249,12 @@ var EventBus = class extends EventTarget {
|
|
|
1249
1249
|
var eventBus = new EventBus();
|
|
1250
1250
|
|
|
1251
1251
|
// src/input.ts
|
|
1252
|
-
import { vec2 } from "gl-matrix";
|
|
1253
1252
|
var Input = class extends Emitter {
|
|
1254
1253
|
inputThreshold = 200;
|
|
1255
1254
|
_keyStates = {};
|
|
1256
1255
|
_mouseButtonStates = {};
|
|
1257
|
-
_mousePosition =
|
|
1258
|
-
_mousePosition2 =
|
|
1256
|
+
_mousePosition = [0, 0];
|
|
1257
|
+
_mousePosition2 = [0, 0];
|
|
1259
1258
|
get mousePosition() {
|
|
1260
1259
|
return this._mousePosition;
|
|
1261
1260
|
}
|
|
@@ -1331,13 +1330,13 @@ var Input = class extends Emitter {
|
|
|
1331
1330
|
_onMouseMove(ev) {
|
|
1332
1331
|
const props = this._getCommonEventProps(ev);
|
|
1333
1332
|
const { buttons, offsetX, offsetY, movementX, movementY } = ev;
|
|
1334
|
-
this._mousePosition =
|
|
1333
|
+
this._mousePosition = [offsetX, offsetY];
|
|
1335
1334
|
const width = window.innerWidth;
|
|
1336
1335
|
const height = window.innerHeight;
|
|
1337
|
-
this._mousePosition2 =
|
|
1336
|
+
this._mousePosition2 = [
|
|
1338
1337
|
ev.clientX / width * 2 - 1,
|
|
1339
1338
|
-(ev.clientY / height) * 2 + 1
|
|
1340
|
-
|
|
1339
|
+
];
|
|
1341
1340
|
this.emit("mouse_move", {
|
|
1342
1341
|
...props,
|
|
1343
1342
|
buttons,
|
|
@@ -1784,7 +1783,6 @@ function PoissonDiskSampler(width, height, minDist, maxPoints = 30) {
|
|
|
1784
1783
|
}
|
|
1785
1784
|
|
|
1786
1785
|
// src/renderer/canvas-renderer.ts
|
|
1787
|
-
import { vec2 as vec22 } from "gl-matrix";
|
|
1788
1786
|
var CanvasRenderer = class {
|
|
1789
1787
|
ctx;
|
|
1790
1788
|
clearColor = "#000000";
|
|
@@ -1799,7 +1797,7 @@ var CanvasRenderer = class {
|
|
|
1799
1797
|
return this.ctx?.canvas.height ?? 0;
|
|
1800
1798
|
}
|
|
1801
1799
|
get center() {
|
|
1802
|
-
return
|
|
1800
|
+
return [this.width / 2, this.height / 2];
|
|
1803
1801
|
}
|
|
1804
1802
|
constructor(canvas) {
|
|
1805
1803
|
this.ctx = (canvas ?? document.createElement("canvas")).getContext("2d");
|
|
@@ -2325,7 +2323,6 @@ var CubeSphereGeometry = class extends BoxGeometry {
|
|
|
2325
2323
|
};
|
|
2326
2324
|
|
|
2327
2325
|
// src/three/texture-atlas.ts
|
|
2328
|
-
import { vec2 as vec23 } from "gl-matrix";
|
|
2329
2326
|
import { TextureLoader, MeshLambertMaterial, NearestFilter, RepeatWrapping } from "three";
|
|
2330
2327
|
function LoadTexture(url) {
|
|
2331
2328
|
return new Promise((res, rej) => {
|
|
@@ -2380,10 +2377,10 @@ var TextureAtlas = class _TextureAtlas extends MeshLambertMaterial {
|
|
|
2380
2377
|
_uw;
|
|
2381
2378
|
_uh;
|
|
2382
2379
|
getUv(voxel, ux, uy) {
|
|
2383
|
-
return
|
|
2380
|
+
return [
|
|
2384
2381
|
(voxel + ux) * this._uw,
|
|
2385
2382
|
1 - (1 - uy) * this._uh
|
|
2386
|
-
|
|
2383
|
+
];
|
|
2387
2384
|
}
|
|
2388
2385
|
static CreateFromUrl(url, textureWidth, textureHeight = textureWidth, params) {
|
|
2389
2386
|
return LoadTexture(url).then((textureData) => new _TextureAtlas(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n3rdw1z4rd/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "core library",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,7 +17,24 @@
|
|
|
17
17
|
"type": "git",
|
|
18
18
|
"url": "git+https://github.com/n3rdw1z4rd/core.git"
|
|
19
19
|
},
|
|
20
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"typescript",
|
|
22
|
+
"browser",
|
|
23
|
+
"game-dev",
|
|
24
|
+
"toolkit",
|
|
25
|
+
"three.js",
|
|
26
|
+
"threejs",
|
|
27
|
+
"webgl",
|
|
28
|
+
"canvas",
|
|
29
|
+
"ecs",
|
|
30
|
+
"entity-component-system",
|
|
31
|
+
"rng",
|
|
32
|
+
"procedural-generation",
|
|
33
|
+
"pathfinding",
|
|
34
|
+
"voxel",
|
|
35
|
+
"particle-system",
|
|
36
|
+
"simplex-noise"
|
|
37
|
+
],
|
|
21
38
|
"author": "",
|
|
22
39
|
"license": "MIT",
|
|
23
40
|
"type": "commonjs",
|
|
@@ -29,12 +46,10 @@
|
|
|
29
46
|
"heap-js": "latest"
|
|
30
47
|
},
|
|
31
48
|
"peerDependencies": {
|
|
32
|
-
"gl-matrix": "latest",
|
|
33
49
|
"simplex-noise": "latest",
|
|
34
50
|
"three": "latest"
|
|
35
51
|
},
|
|
36
52
|
"devDependencies": {
|
|
37
|
-
"@types/gl-matrix": "latest",
|
|
38
53
|
"@types/three": "latest",
|
|
39
54
|
"shx": "latest",
|
|
40
55
|
"tsup": "latest",
|