@n3rdw1z4rd/core 0.18.5 → 0.19.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 +72 -10
- package/dist/astar.d.ts +44 -0
- package/dist/astar.js +118 -0
- package/dist/canvas-renderer.d.ts +157 -0
- package/dist/canvas-renderer.js +207 -0
- package/dist/clock.d.ts +69 -0
- package/dist/clock.js +108 -0
- package/dist/color-palette.d.ts +25 -0
- package/dist/color-palette.js +112 -0
- package/dist/color.d.ts +90 -0
- package/dist/color.js +224 -0
- package/dist/css/main.css +1 -3
- package/dist/disposable.d.ts +27 -0
- package/dist/disposable.js +32 -0
- package/dist/dungeon-generator.d.ts +142 -0
- package/dist/dungeon-generator.js +288 -0
- package/dist/ecs.d.ts +87 -0
- package/dist/ecs.js +101 -0
- package/dist/emitter.d.ts +40 -0
- package/dist/emitter.js +54 -0
- package/dist/event-queue.d.ts +29 -0
- package/dist/event-queue.js +40 -0
- package/dist/index.cjs +3820 -0
- package/dist/index.d.cts +2657 -0
- package/dist/index.d.ts +35 -873
- package/dist/index.js +34 -3981
- package/dist/input/action-map.d.ts +79 -0
- package/dist/input/action-map.js +131 -0
- package/dist/input/bindings.d.ts +273 -0
- package/dist/input/bindings.js +250 -0
- package/dist/input/gestures.d.ts +108 -0
- package/dist/input/gestures.js +159 -0
- package/dist/input/index.d.ts +5 -0
- package/dist/input/index.js +5 -0
- package/dist/input/input.d.ts +297 -0
- package/dist/input/input.js +695 -0
- package/dist/log.d.ts +8 -0
- package/dist/log.js +9 -0
- package/dist/map2d.d.ts +83 -0
- package/dist/map2d.js +120 -0
- package/dist/map3d-CHDJiq5T.d.cts +236 -0
- package/dist/map3d.d.ts +94 -0
- package/dist/map3d.js +148 -0
- package/dist/math.d.ts +176 -0
- package/dist/math.js +206 -0
- package/dist/misc.d.ts +46 -0
- package/dist/misc.js +71 -0
- package/dist/observable.d.ts +43 -0
- package/dist/observable.js +53 -0
- package/dist/particle-renderer.d.ts +47 -0
- package/dist/particle-renderer.js +82 -0
- package/dist/particle-system-2d.d.ts +60 -0
- package/dist/particle-system-2d.js +147 -0
- package/dist/random.d.ts +46 -0
- package/dist/random.js +74 -0
- package/dist/rectangle.d.ts +44 -0
- package/dist/rectangle.js +69 -0
- package/dist/rng.d.ts +72 -0
- package/dist/rng.js +152 -0
- package/dist/signal.d.ts +34 -0
- package/dist/signal.js +41 -0
- package/dist/spatial-partition-2d.d.ts +42 -0
- package/dist/spatial-partition-2d.js +52 -0
- package/dist/spatial-partition-3d-Ba-VBveM.cjs +1324 -0
- package/dist/spatial-partition-3d.d.ts +44 -0
- package/dist/spatial-partition-3d.js +57 -0
- package/dist/three/asteroid-mesh.d.ts +41 -0
- package/dist/three/asteroid-mesh.js +44 -0
- package/dist/three/camera-rig.d.ts +140 -0
- package/dist/three/camera-rig.js +197 -0
- package/dist/three/cube-sphere-geometry.d.ts +55 -0
- package/dist/three/cube-sphere-geometry.js +239 -0
- package/dist/three/ecs.d.ts +75 -0
- package/dist/three/ecs.js +64 -0
- package/dist/three/index.d.ts +12 -0
- package/dist/three/index.js +12 -0
- package/dist/three/particle-system-3d.d.ts +53 -0
- package/dist/three/particle-system-3d.js +224 -0
- package/dist/three/renderer.d.ts +38 -0
- package/dist/three/renderer.js +57 -0
- package/dist/three/starfield.d.ts +23 -0
- package/dist/three/starfield.js +64 -0
- package/dist/three/texture-atlas.d.ts +76 -0
- package/dist/three/texture-atlas.js +84 -0
- package/dist/three/texture-utils.d.ts +31 -0
- package/dist/three/texture-utils.js +44 -0
- package/dist/three/voxel-geometry.d.ts +72 -0
- package/dist/three/voxel-geometry.js +231 -0
- package/dist/three/voxel-mesh.d.ts +67 -0
- package/dist/three/voxel-mesh.js +71 -0
- package/dist/three.cjs +1307 -0
- package/dist/three.d.cts +655 -0
- package/dist/tilemap.d.ts +17 -0
- package/dist/tilemap.js +26 -0
- package/dist/types.d.ts +34 -0
- package/dist/types.js +0 -0
- package/dist/vector.d.ts +78 -0
- package/dist/vector.js +169 -0
- package/dist/webgl-renderer.d.ts +89 -0
- package/dist/webgl-renderer.js +140 -0
- package/dist/webgl.d.ts +357 -0
- package/dist/webgl.js +628 -0
- package/dist/worker-interface.d.ts +30 -0
- package/dist/worker-interface.js +39 -0
- package/package.json +55 -13
- package/dist/css/index.ts +0 -1
- package/dist/index.css +0 -104
- package/dist/index.d.mts +0 -873
- package/dist/index.mjs +0 -3977
package/dist/three.d.cts
ADDED
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
import { d as ColorPalette, h as NoiseFunction3D, i as Map3D } from "./map3d-CHDJiq5T.cjs";
|
|
2
|
+
import { BufferGeometry, Group, Material, Mesh, MeshLambertMaterial, MeshLambertMaterialParameters, Object3D, PerspectiveCamera, Points, Texture, Vector3, WebGLRenderer, WebGLRendererParameters } from "three";
|
|
3
|
+
//#region src/three/asteroid-mesh.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Options for the {@link AsteroidMesh} constructor.
|
|
6
|
+
*
|
|
7
|
+
* @category Geometry & Meshes
|
|
8
|
+
*/
|
|
9
|
+
export interface AsteroidOptions {
|
|
10
|
+
/** shapes the surface; expected to return roughly -1..1 */
|
|
11
|
+
noise3d: NoiseFunction3D;
|
|
12
|
+
/** base radius before displacement, default 1 */
|
|
13
|
+
radius?: number;
|
|
14
|
+
/** IcosahedronGeometry subdivision level, default 1 */
|
|
15
|
+
detail?: number;
|
|
16
|
+
/** noise frequency: vertex positions are multiplied by this before sampling, default 1 */
|
|
17
|
+
noiseScale?: number;
|
|
18
|
+
/** each vertex moves by `noise * displacement` times its distance from the center, default 0.1 */
|
|
19
|
+
displacement?: number;
|
|
20
|
+
/** optional extra detail layer, sampled at twice the frequency and half the weight */
|
|
21
|
+
secondaryNoise?: NoiseFunction3D;
|
|
22
|
+
/** 0xRRGGBB, default 0x888888 */
|
|
23
|
+
color?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Lumpy rock: an icosphere whose vertices are pushed in and out by 3D noise, with a
|
|
27
|
+
* `MeshStandardMaterial`. The geometry is non-indexed, so normals are per face (a faceted look).
|
|
28
|
+
* Deterministic for a deterministic noise function.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createNoise3D } from 'simplex-noise';
|
|
32
|
+
*
|
|
33
|
+
* const rock = new AsteroidMesh({ noise3d: createNoise3D(() => rng.nextFloat()), radius: 2, detail: 3, displacement: 0.25 });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @category Geometry & Meshes
|
|
37
|
+
*/
|
|
38
|
+
export declare class AsteroidMesh extends Mesh {
|
|
39
|
+
constructor(options: AsteroidOptions);
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/three/camera-rig.d.ts
|
|
43
|
+
/**
|
|
44
|
+
* Options for the {@link CameraRig} constructor.
|
|
45
|
+
*
|
|
46
|
+
* @category Camera
|
|
47
|
+
*/
|
|
48
|
+
export interface CameraRigParams {
|
|
49
|
+
/** camera to use; default: a new PerspectiveCamera built from `fov`, `aspect`, `near`, `far` */
|
|
50
|
+
camera?: PerspectiveCamera;
|
|
51
|
+
/** degrees, vertical; default 70 (ignored when `camera` is given) */
|
|
52
|
+
fov?: number;
|
|
53
|
+
/** default 2 (ignored when `camera` is given) */
|
|
54
|
+
aspect?: number;
|
|
55
|
+
/** default 0.1 (ignored when `camera` is given) */
|
|
56
|
+
near?: number;
|
|
57
|
+
/** default 1000 (ignored when `camera` is given) */
|
|
58
|
+
far?: number;
|
|
59
|
+
/** object to follow; see {@link CameraRig.target} */
|
|
60
|
+
target?: Object3D;
|
|
61
|
+
/** starting zoom distance, default 5; clamped like {@link CameraRig.distance} */
|
|
62
|
+
distance?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Pitch range for a {@link CameraRig}.
|
|
66
|
+
*
|
|
67
|
+
* @category Camera
|
|
68
|
+
*/
|
|
69
|
+
export interface PitchLimits {
|
|
70
|
+
/** radians; negative looks down */
|
|
71
|
+
min: number;
|
|
72
|
+
/** radians; positive looks up */
|
|
73
|
+
max: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Third-person camera that orbits a target and zooms seamlessly into first person.
|
|
77
|
+
*
|
|
78
|
+
* The orbit pivot sits at the target's eye height (`targetOffset`); the camera sits `distance`
|
|
79
|
+
* behind it. Zooming below `firstPersonThreshold` goes to distance 0, which puts the camera at the
|
|
80
|
+
* eyes: first person, with the same yaw and pitch.
|
|
81
|
+
*
|
|
82
|
+
* Add the rig to the scene (not to the target), feed it input with `orbit()` / `dolly()`, and call
|
|
83
|
+
* `update(deltaTime)` once per frame.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const rig = new CameraRig({ target: player, distance: 6 });
|
|
87
|
+
* scene.add(rig);
|
|
88
|
+
*
|
|
89
|
+
* addEventListener('mousemove', (e) => rig.orbit(e.movementX, e.movementY));
|
|
90
|
+
* addEventListener('wheel', (e) => rig.dolly(e.deltaY));
|
|
91
|
+
*
|
|
92
|
+
* // each frame
|
|
93
|
+
* rig.update(deltaTime);
|
|
94
|
+
* renderer.render(scene, rig.camera);
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @category Camera
|
|
98
|
+
*/
|
|
99
|
+
export declare class CameraRig extends Group {
|
|
100
|
+
/** the camera to render with; a child of `gimbal` */
|
|
101
|
+
readonly camera: PerspectiveCamera;
|
|
102
|
+
/** pitch */
|
|
103
|
+
readonly gimbal: Group<import("three").Object3DEventMap>;
|
|
104
|
+
/** followed by position, not parented */
|
|
105
|
+
target?: Object3D;
|
|
106
|
+
/** pivot (eye height) above the target's origin, world space */
|
|
107
|
+
targetOffset: Vector3;
|
|
108
|
+
/** radians, around world up */
|
|
109
|
+
yaw: number;
|
|
110
|
+
/** radians, negative looks down */
|
|
111
|
+
pitch: number;
|
|
112
|
+
/** > 0 disables first person */
|
|
113
|
+
minDistance: number;
|
|
114
|
+
/** furthest zoom distance */
|
|
115
|
+
maxDistance: number;
|
|
116
|
+
/** zooming in below this goes all the way to first person */
|
|
117
|
+
firstPersonThreshold: number;
|
|
118
|
+
/** pitch range in third person; default -80° to 30° */
|
|
119
|
+
pitchLimits: PitchLimits;
|
|
120
|
+
/** pitch range in first person; the range blends between the two while zooming */
|
|
121
|
+
firstPersonPitchLimits: PitchLimits;
|
|
122
|
+
/** sideways camera shift in third person (over-the-shoulder) */
|
|
123
|
+
shoulderOffset: number;
|
|
124
|
+
/** the shift fades out as distance goes from this to 0 */
|
|
125
|
+
shoulderFadeDistance: number;
|
|
126
|
+
/** set `target.visible = false` while in first person */
|
|
127
|
+
hideTargetInFirstPerson: boolean;
|
|
128
|
+
/** the camera pulls in rather than passing through these */
|
|
129
|
+
collisionObjects: Object3D[];
|
|
130
|
+
/** distance kept between the camera and a surface */
|
|
131
|
+
collisionPadding: number;
|
|
132
|
+
/** radians per pixel */
|
|
133
|
+
orbitSensitivity: number;
|
|
134
|
+
/** per wheel delta unit (multiplicative zoom) */
|
|
135
|
+
zoomSensitivity: number;
|
|
136
|
+
/** higher = snappier; 0 = instant */
|
|
137
|
+
zoomDamping: number;
|
|
138
|
+
/** 0 = locked to the target */
|
|
139
|
+
followDamping: number;
|
|
140
|
+
/** called from `update()` when the camera switches between first and third person */
|
|
141
|
+
onModeChange?: (firstPerson: boolean) => void;
|
|
142
|
+
private _targetDistance;
|
|
143
|
+
private _distance;
|
|
144
|
+
private _cameraDistance;
|
|
145
|
+
private _recovering;
|
|
146
|
+
private _firstPerson;
|
|
147
|
+
private _initialized;
|
|
148
|
+
private readonly _raycaster;
|
|
149
|
+
private readonly _pivot;
|
|
150
|
+
private readonly _desired;
|
|
151
|
+
private readonly _direction;
|
|
152
|
+
/** Zoom distance the rig is easing towards; 0 = first person. */
|
|
153
|
+
get distance(): number;
|
|
154
|
+
/**
|
|
155
|
+
* Jumps to a zoom distance without easing, clamped to [`minDistance`, `maxDistance`]; below
|
|
156
|
+
* `firstPersonThreshold` becomes 0 (first person) unless `minDistance > 0`.
|
|
157
|
+
*/
|
|
158
|
+
set distance(value: number);
|
|
159
|
+
/** Current distance of the camera from the pivot, after smoothing and collision. */
|
|
160
|
+
get cameraDistance(): number;
|
|
161
|
+
/** whether the camera is currently closer than `firstPersonThreshold` (as of the last `update()`) */
|
|
162
|
+
get isFirstPerson(): boolean;
|
|
163
|
+
constructor(params?: CameraRigParams);
|
|
164
|
+
/** Rotate from pointer movement in pixels (e.g. movementX / movementY). */
|
|
165
|
+
orbit(deltaX: number, deltaY: number): void;
|
|
166
|
+
/** Zoom from wheel movement (e.g. WheelEvent.deltaY); positive zooms out. */
|
|
167
|
+
dolly(delta: number): void;
|
|
168
|
+
/**
|
|
169
|
+
* Follows the target, eases zoom, applies yaw / pitch and collision, and positions the camera.
|
|
170
|
+
* Call once per frame.
|
|
171
|
+
*
|
|
172
|
+
* @param deltaTime seconds since the last update
|
|
173
|
+
*/
|
|
174
|
+
update(deltaTime: number): void;
|
|
175
|
+
private _collide;
|
|
176
|
+
private _clampDistance;
|
|
177
|
+
private _clampPitch;
|
|
178
|
+
private _setFirstPerson;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/three/cube-sphere-geometry.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* A sphere built from a subdivided cube, for planets and other displaced spheres.
|
|
184
|
+
*
|
|
185
|
+
* Vertices on the cube's edges and corners are shared between faces, so there are no seams:
|
|
186
|
+
* displacement and computed normals are continuous across the whole surface. Points are
|
|
187
|
+
* mapped from cube to sphere with the "spherified cube" mapping, which spaces vertices far
|
|
188
|
+
* more evenly than normalizing (no bunching at the face corners).
|
|
189
|
+
*
|
|
190
|
+
* The geometry has positions, normals and an index; it has no UVs, since one set of UVs can't
|
|
191
|
+
* wrap a sphere without seams (use triplanar mapping or vertex colors for surfaces).
|
|
192
|
+
*
|
|
193
|
+
* ```ts
|
|
194
|
+
* const planet = new CubeSphereGeometry(10, 64) // radius 5
|
|
195
|
+
* .applyFractalBrownianMotion(noise3d, 5, 0.5, 0.3, 0.4); // up to ±0.4 height
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @category Geometry & Meshes
|
|
199
|
+
*/
|
|
200
|
+
export declare class CubeSphereGeometry extends BufferGeometry {
|
|
201
|
+
readonly size: number;
|
|
202
|
+
readonly segments: number;
|
|
203
|
+
readonly type: string;
|
|
204
|
+
/** `size / 2`: the undisplaced radius */
|
|
205
|
+
readonly radius: number;
|
|
206
|
+
private readonly _directions;
|
|
207
|
+
/**
|
|
208
|
+
* @param size diameter of the sphere
|
|
209
|
+
* @param segments subdivisions along each cube edge
|
|
210
|
+
*/
|
|
211
|
+
constructor(size: number, segments: number);
|
|
212
|
+
/**
|
|
213
|
+
* Sets each vertex to `radius + height(direction)` along its direction from the center,
|
|
214
|
+
* then recomputes normals and bounds. Always starts from the undisplaced sphere, so calling
|
|
215
|
+
* it again replaces the previous displacement rather than adding to it.
|
|
216
|
+
*
|
|
217
|
+
* @param height offset in world units for the unit direction (x, y, z)
|
|
218
|
+
*/
|
|
219
|
+
displace(height: (x: number, y: number, z: number) => number): this;
|
|
220
|
+
/**
|
|
221
|
+
* Displaces the surface with fractal Brownian motion. Noise is sampled at the undisplaced
|
|
222
|
+
* surface point times `scale`; the summed octaves are normalized to the noise's range and
|
|
223
|
+
* multiplied by `amplitude`.
|
|
224
|
+
*/
|
|
225
|
+
applyFractalBrownianMotion(noise3d: NoiseFunction3D, octaves: number, persistence: number, scale: number, amplitude: number): this;
|
|
226
|
+
private static fBm;
|
|
227
|
+
/**
|
|
228
|
+
* maps a point on the [-1, 1] cube onto the unit sphere with even spacing
|
|
229
|
+
* (https://mathproofs.blogspot.com/2005/07/mapping-cube-to-sphere.html)
|
|
230
|
+
*/
|
|
231
|
+
static spherify(x: number, y: number, z: number): [number, number, number];
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/three/ecs.d.ts
|
|
235
|
+
/**
|
|
236
|
+
* A component: any plain object of data, stored by name on a {@link ThreeEntity}.
|
|
237
|
+
*
|
|
238
|
+
* @category ECS
|
|
239
|
+
*/
|
|
240
|
+
export type ThreeComponent = Record<string, any>;
|
|
241
|
+
/**
|
|
242
|
+
* An `Object3D` used as an entity: its id and components live in `userData`. Create one with
|
|
243
|
+
* {@link CreateThreeEntity}.
|
|
244
|
+
*
|
|
245
|
+
* @category ECS
|
|
246
|
+
*/
|
|
247
|
+
export interface ThreeEntity extends Object3D {
|
|
248
|
+
/** `Object3D.userData` with the entity's id and components */
|
|
249
|
+
userData: {
|
|
250
|
+
/** unique within the page, from {@link GenerateEntityId} */
|
|
251
|
+
entityId: string;
|
|
252
|
+
/** components by name */
|
|
253
|
+
components: Record<string, ThreeComponent>;
|
|
254
|
+
[key: string]: any;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Returns a new id `"entity_<n>"` from a module-level counter (unique per page load, not random).
|
|
259
|
+
*
|
|
260
|
+
* @category ECS
|
|
261
|
+
*/
|
|
262
|
+
export declare function GenerateEntityId(): string;
|
|
263
|
+
/**
|
|
264
|
+
* Turns `obj` (default: a new `Group`) into an entity in place: gives it a new id and an empty
|
|
265
|
+
* component set, replacing any it had.
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* const ship = CreateThreeEntity(shipMesh);
|
|
269
|
+
* AddThreeComponent(ship, 'velocity', { x: 0, y: 0, z: 1 });
|
|
270
|
+
* GetThreeComponent<{ x: number, y: number, z: number }>(ship, 'velocity')!.z; // 1
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
273
|
+
* @returns the same object, typed as a {@link ThreeEntity}
|
|
274
|
+
* @category ECS
|
|
275
|
+
*/
|
|
276
|
+
export declare function CreateThreeEntity(obj?: Object3D): ThreeEntity;
|
|
277
|
+
/**
|
|
278
|
+
* Stores `component` on `entity` under `name`, replacing any component with that name.
|
|
279
|
+
*
|
|
280
|
+
* @category ECS
|
|
281
|
+
*/
|
|
282
|
+
export declare function AddThreeComponent<T extends ThreeComponent>(entity: ThreeEntity, name: string, component: T): void;
|
|
283
|
+
/**
|
|
284
|
+
* The component named `name`, or `undefined` if the entity has none. `T` is not checked.
|
|
285
|
+
*
|
|
286
|
+
* @category ECS
|
|
287
|
+
*/
|
|
288
|
+
export declare function GetThreeComponent<T extends ThreeComponent>(entity: ThreeEntity, name: string): T | undefined;
|
|
289
|
+
/**
|
|
290
|
+
* Removes the component named `name`, if any.
|
|
291
|
+
*
|
|
292
|
+
* @category ECS
|
|
293
|
+
*/
|
|
294
|
+
export declare function RemoveThreeComponent(entity: ThreeEntity, name: string): void;
|
|
295
|
+
/**
|
|
296
|
+
* Whether `obj` has been made an entity (has a `userData.entityId`).
|
|
297
|
+
*
|
|
298
|
+
* @category ECS
|
|
299
|
+
*/
|
|
300
|
+
export declare function IsThreeEntity(obj: Object3D): boolean;
|
|
301
|
+
/**
|
|
302
|
+
* A system: called with all entities (by id) and the frame's delta time, plus any extra arguments.
|
|
303
|
+
*
|
|
304
|
+
* @category ECS
|
|
305
|
+
*/
|
|
306
|
+
export type ThreeSystem = (entities: Map<string, ThreeEntity>, delta: number, ...args: any) => void;
|
|
307
|
+
//#endregion
|
|
308
|
+
//#region src/three/particle-system-3d.d.ts
|
|
309
|
+
/**
|
|
310
|
+
* "Particle life" simulation in 3D: 1000 colored points in five species that attract or repel each
|
|
311
|
+
* other according to a random species-by-species matrix, forming moving clusters. Particles live in
|
|
312
|
+
* a wrapping unit cube; the group is offset by -0.5 so the cube is centred on its origin (scale it
|
|
313
|
+
* to resize).
|
|
314
|
+
*
|
|
315
|
+
* Neighbours are found with a {@link SpatialPartition3d}. Points are drawn at a fixed 4 pixels and
|
|
316
|
+
* sorted back to front each update.
|
|
317
|
+
*
|
|
318
|
+
* ```ts
|
|
319
|
+
* const life = new ParticleSystem3d(42);
|
|
320
|
+
* life.scale.setScalar(10);
|
|
321
|
+
* scene.add(life);
|
|
322
|
+
*
|
|
323
|
+
* // each frame
|
|
324
|
+
* life.update(camera, deltaTime);
|
|
325
|
+
* ```
|
|
326
|
+
*
|
|
327
|
+
* @category Particles
|
|
328
|
+
*/
|
|
329
|
+
export declare class ParticleSystem3d extends Group {
|
|
330
|
+
/** number of particles; fixed */
|
|
331
|
+
readonly particleCount = 1000;
|
|
332
|
+
/** the seed the starting state came from */
|
|
333
|
+
readonly seed: number;
|
|
334
|
+
/** seconds; larger `dt` values passed to `update()` are capped to this so a stall can't blow the simulation up */
|
|
335
|
+
maxDeltaTime: number;
|
|
336
|
+
private _geometry;
|
|
337
|
+
private _particles;
|
|
338
|
+
private _frictionHalfLife;
|
|
339
|
+
private _range;
|
|
340
|
+
private _forceFactor;
|
|
341
|
+
private _positions;
|
|
342
|
+
private _colors;
|
|
343
|
+
private _cameraLocal;
|
|
344
|
+
private _attractionMatrix;
|
|
345
|
+
private _spatialPartition;
|
|
346
|
+
/** the same seed always produces the same starting state (positions, colors, attraction matrix) */
|
|
347
|
+
constructor(seed?: number);
|
|
348
|
+
private _calcForce;
|
|
349
|
+
private _updateVelocities;
|
|
350
|
+
private _updatePositions;
|
|
351
|
+
private _sortParticles;
|
|
352
|
+
private _updateGeometry;
|
|
353
|
+
/**
|
|
354
|
+
* Advances the simulation by `dt` seconds and refreshes the points, sorted back to front as
|
|
355
|
+
* seen from `camera`. `dt` is capped to {@link ParticleSystem3d.maxDeltaTime}.
|
|
356
|
+
*/
|
|
357
|
+
update(camera: PerspectiveCamera, dt: number): void;
|
|
358
|
+
}
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/three/renderer.d.ts
|
|
361
|
+
/**
|
|
362
|
+
* `WebGLRenderer` that uses the device pixel ratio and can size itself to its parent element.
|
|
363
|
+
*
|
|
364
|
+
* ```ts
|
|
365
|
+
* const renderer = new Renderer({ antialias: true });
|
|
366
|
+
* container.appendChild(renderer.domElement);
|
|
367
|
+
*
|
|
368
|
+
* // each frame
|
|
369
|
+
* if (renderer.resize()) {
|
|
370
|
+
* camera.aspect = renderer.aspectRatio;
|
|
371
|
+
* camera.updateProjectionMatrix();
|
|
372
|
+
* }
|
|
373
|
+
* renderer.render(scene, camera);
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @category Rendering
|
|
377
|
+
*/
|
|
378
|
+
export declare class Renderer extends WebGLRenderer {
|
|
379
|
+
private _size;
|
|
380
|
+
/** CSS pixels, same as setSize() and resize(); domElement.width/height are CSS pixels * pixel ratio */
|
|
381
|
+
get width(): number;
|
|
382
|
+
/** CSS pixels */
|
|
383
|
+
get height(): number;
|
|
384
|
+
/** width / height (1 while the height is 0) */
|
|
385
|
+
get aspectRatio(): number;
|
|
386
|
+
constructor(parameters?: WebGLRendererParameters);
|
|
387
|
+
/**
|
|
388
|
+
* Sets the size in CSS pixels, if it differs from the current one. A missing `width` / `height`
|
|
389
|
+
* defaults to the parent element's client size (or the current size when there is no parent, or
|
|
390
|
+
* the parent has no size yet, e.g. before layout or while hidden).
|
|
391
|
+
*
|
|
392
|
+
* @returns whether the size changed
|
|
393
|
+
*/
|
|
394
|
+
resize(width?: number, height?: number): boolean;
|
|
395
|
+
}
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/three/starfield.d.ts
|
|
398
|
+
/**
|
|
399
|
+
* Points spread uniformly over a sphere's surface, for a distant star backdrop (point size 5 with
|
|
400
|
+
* size attenuation, 0.9 opacity). The same `seed` always gives the same stars; without one,
|
|
401
|
+
* positions come from the shared {@link rng}.
|
|
402
|
+
*
|
|
403
|
+
* @param radius sphere radius in world units
|
|
404
|
+
* @param count number of stars
|
|
405
|
+
* @param color 0xRRGGBB
|
|
406
|
+
* @param seed seeds a private {@link Rng} for a reproducible starfield
|
|
407
|
+
* @category Geometry & Meshes
|
|
408
|
+
*/
|
|
409
|
+
export declare function CreateStarfield(radius?: number, count?: number, color?: number, seed?: number): Points;
|
|
410
|
+
/**
|
|
411
|
+
* A sun: a bright unlit sphere (radius 50, color 0xffddaa) plus a white `PointLight` (intensity
|
|
412
|
+
* 10, no distance falloff) at the same spot.
|
|
413
|
+
*
|
|
414
|
+
* @param position where to put both, in the group's space; default the origin
|
|
415
|
+
* @category Geometry & Meshes
|
|
416
|
+
*/
|
|
417
|
+
export declare function CreateSystemStar(position?: Vector3): Group;
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/three/texture-utils.d.ts
|
|
420
|
+
/**
|
|
421
|
+
* A loaded texture with its image size, as returned by {@link LoadTexture}.
|
|
422
|
+
*
|
|
423
|
+
* @category Textures
|
|
424
|
+
*/
|
|
425
|
+
export interface TextureData {
|
|
426
|
+
/** image width in pixels */
|
|
427
|
+
width: number;
|
|
428
|
+
/** image height in pixels */
|
|
429
|
+
height: number;
|
|
430
|
+
/** the loaded texture */
|
|
431
|
+
texture: Texture<any>;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Loads an image into a `Texture` with three's `TextureLoader`.
|
|
435
|
+
*
|
|
436
|
+
* @returns resolves once the image has loaded; rejects with the loader's error
|
|
437
|
+
* @category Textures
|
|
438
|
+
*/
|
|
439
|
+
export declare function LoadTexture(url: string): Promise<TextureData>;
|
|
440
|
+
/**
|
|
441
|
+
* A clone of `texture` showing only the rectangle at (x, y) of size w x h, in pixels with y measured
|
|
442
|
+
* from the image's top, via `offset` / `repeat`. Sets `magFilter` to `NearestFilter` and `wrapS` / `wrapT`
|
|
443
|
+
* to `RepeatWrapping`. The clone shares the source image, so no pixels are copied.
|
|
444
|
+
*
|
|
445
|
+
* @category Textures
|
|
446
|
+
*/
|
|
447
|
+
export declare function CreateSubTexture(texture: Texture, x: number, y: number, w: number, h: number): Texture;
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/three/texture-atlas.d.ts
|
|
450
|
+
/**
|
|
451
|
+
* Texture coordinate `[u, v]`, each 0..1, with v = 1 at the image's top (three.js convention).
|
|
452
|
+
*
|
|
453
|
+
* @category Textures
|
|
454
|
+
*/
|
|
455
|
+
export type UV = [number, number];
|
|
456
|
+
/**
|
|
457
|
+
* Tile layout of a {@link TextureAtlas}.
|
|
458
|
+
*
|
|
459
|
+
* @category Textures
|
|
460
|
+
*/
|
|
461
|
+
export interface AtlasParams {
|
|
462
|
+
/** pixels, default 16 */
|
|
463
|
+
tileWidth?: number;
|
|
464
|
+
/** pixels, default tileWidth */
|
|
465
|
+
tileHeight?: number;
|
|
466
|
+
/** pixels from the left edge before the first column, default 0 */
|
|
467
|
+
offsetX?: number;
|
|
468
|
+
/** pixels from the top edge before the first row, default 0 */
|
|
469
|
+
offsetY?: number;
|
|
470
|
+
/** pixels between neighbouring tiles, default 0 */
|
|
471
|
+
spacing?: number;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Tile layout and UV lookup for a texture atlas (tile sheet). Tiles are numbered left to
|
|
475
|
+
* right, top to bottom, starting at 0.
|
|
476
|
+
*
|
|
477
|
+
* Not a material: use `atlas.texture` as the `map` of any material, or `createMaterial()`
|
|
478
|
+
* for the common Lambert setup. The texture's `magFilter` is set to `NearestFilter`.
|
|
479
|
+
*
|
|
480
|
+
* ```ts
|
|
481
|
+
* const atlas = await TextureAtlas.load('tiles.png', { tileWidth: 16 });
|
|
482
|
+
* const material = atlas.createMaterial();
|
|
483
|
+
* const [u, v] = atlas.getUV(5, 0, 0); // bottom-left of tile 5
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
486
|
+
* @category Textures
|
|
487
|
+
*/
|
|
488
|
+
export declare class TextureAtlas {
|
|
489
|
+
/** the whole sheet */
|
|
490
|
+
readonly texture: Texture;
|
|
491
|
+
/** texture size in pixels */
|
|
492
|
+
readonly width: number;
|
|
493
|
+
/** texture size in pixels */
|
|
494
|
+
readonly height: number;
|
|
495
|
+
/** pixels */
|
|
496
|
+
readonly tileWidth: number;
|
|
497
|
+
/** pixels */
|
|
498
|
+
readonly tileHeight: number;
|
|
499
|
+
/** pixels from the left edge before the first column */
|
|
500
|
+
readonly offsetX: number;
|
|
501
|
+
/** pixels from the top edge before the first row */
|
|
502
|
+
readonly offsetY: number;
|
|
503
|
+
/** pixels between neighbouring tiles */
|
|
504
|
+
readonly spacing: number;
|
|
505
|
+
/** tiles per row */
|
|
506
|
+
readonly columns: number;
|
|
507
|
+
/** tiles per column (only whole tiles count) */
|
|
508
|
+
readonly rows: number;
|
|
509
|
+
/** `columns * rows` */
|
|
510
|
+
get tileCount(): number;
|
|
511
|
+
constructor(textureData: TextureData, params?: AtlasParams);
|
|
512
|
+
/** Loads the image at `url` (see {@link LoadTexture}) and builds an atlas from it. */
|
|
513
|
+
static load(url: string, params?: AtlasParams): Promise<TextureAtlas>;
|
|
514
|
+
/**
|
|
515
|
+
* UV of a point inside a tile. `u` and `v` are in [0, 1] across the tile, with (0, 0) at the
|
|
516
|
+
* tile's bottom-left and (1, 1) at its top-right, matching three.js (v = 1 is the image's top).
|
|
517
|
+
*/
|
|
518
|
+
getUV(tile: number, u: number, v: number): UV;
|
|
519
|
+
/** a Lambert material using this atlas, set up for pixel-art tiles with transparency */
|
|
520
|
+
createMaterial(params?: MeshLambertMaterialParameters): MeshLambertMaterial;
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/three/voxel-geometry.d.ts
|
|
524
|
+
/**
|
|
525
|
+
* Options for {@link buildVoxelGeometry} and {@link VoxelGeometry}.
|
|
526
|
+
*
|
|
527
|
+
* @category Voxels
|
|
528
|
+
*/
|
|
529
|
+
export interface BuildVoxelGeometryOptions {
|
|
530
|
+
/** voxel value -> 0xRRGGBB (sRGB) */
|
|
531
|
+
palette?: ColorPalette;
|
|
532
|
+
/** color for values the palette doesn't cover; default: a stable color hashed from the value */
|
|
533
|
+
missingColor?: number;
|
|
534
|
+
/** voxel lookup where this map has none (e.g. neighbouring chunks) */
|
|
535
|
+
neighbor?: (x: number, y: number, z: number) => number;
|
|
536
|
+
/** also emit faces between two solid voxels. Default false. */
|
|
537
|
+
includeHiddenFaces?: boolean;
|
|
538
|
+
/** merge same-looking faces into larger quads. Default true. */
|
|
539
|
+
greedy?: boolean;
|
|
540
|
+
/** darken vertices in corners and creases. Default true. */
|
|
541
|
+
ambientOcclusion?: boolean;
|
|
542
|
+
/** 0..1: how dark the most occluded corner gets. Default 0.5. */
|
|
543
|
+
aoStrength?: number;
|
|
544
|
+
/** rebuild into this geometry instead of creating one */
|
|
545
|
+
target?: BufferGeometry;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Builds a mesh for the voxels in `voxels`: one quad per visible face, merged into larger quads
|
|
549
|
+
* (`greedy`) and shaded with per-vertex ambient occlusion. A voxel's value is its palette index;
|
|
550
|
+
* the map's default value means empty.
|
|
551
|
+
*
|
|
552
|
+
* Positions are in the map's own coordinates, so a chunk stored in chunk-local coordinates is
|
|
553
|
+
* placed by positioning its mesh. Pass `neighbor` so faces against neighbouring chunks are culled
|
|
554
|
+
* and their voxels count for ambient occlusion.
|
|
555
|
+
*
|
|
556
|
+
* The geometry has position, normal and color attributes and an index; use a material with
|
|
557
|
+
* `vertexColors: true`. The output is deterministic: the same voxels and options always produce
|
|
558
|
+
* the same buffers.
|
|
559
|
+
*
|
|
560
|
+
* ```ts
|
|
561
|
+
* const voxels = new Map3D();
|
|
562
|
+
* voxels.setArea(0, 0, 0, 7, 0, 7, 0); // 8x1x8 slab of palette index 0
|
|
563
|
+
* voxels.set(3, 1, 3, 1);
|
|
564
|
+
*
|
|
565
|
+
* const geometry = buildVoxelGeometry(voxels, { palette: [0x55aa33, 0x8b5a2b] });
|
|
566
|
+
* scene.add(new Mesh(geometry, new MeshLambertMaterial({ vertexColors: true })));
|
|
567
|
+
* ```
|
|
568
|
+
*
|
|
569
|
+
* @returns `options.target` if given, otherwise a new geometry
|
|
570
|
+
* @category Voxels
|
|
571
|
+
*/
|
|
572
|
+
export declare function buildVoxelGeometry(voxels: Map3D, options?: BuildVoxelGeometryOptions): BufferGeometry;
|
|
573
|
+
/**
|
|
574
|
+
* Geometry that owns its voxels; call `update()` after changing them. See
|
|
575
|
+
* {@link buildVoxelGeometry} for how voxels are meshed, and {@link VoxelMesh} for an editable mesh
|
|
576
|
+
* that tracks changes for you.
|
|
577
|
+
*
|
|
578
|
+
* @category Voxels
|
|
579
|
+
*/
|
|
580
|
+
export declare class VoxelGeometry extends BufferGeometry {
|
|
581
|
+
type: string;
|
|
582
|
+
/** voxel data (palette indices); the map's default value is empty */
|
|
583
|
+
voxels: Map3D;
|
|
584
|
+
/** meshing options used by every `update()` */
|
|
585
|
+
options: Omit<BuildVoxelGeometryOptions, 'target'>;
|
|
586
|
+
/** Builds the geometry right away. */
|
|
587
|
+
constructor(voxels?: Map3D, options?: Omit<BuildVoxelGeometryOptions, 'target'>);
|
|
588
|
+
/** Rebuilds the geometry from `voxels` and `options`. */
|
|
589
|
+
update(): this;
|
|
590
|
+
}
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/three/voxel-mesh.d.ts
|
|
593
|
+
/**
|
|
594
|
+
* Box of voxel cells a {@link VoxelMesh} accepts, from the origin.
|
|
595
|
+
*
|
|
596
|
+
* @category Voxels
|
|
597
|
+
*/
|
|
598
|
+
export interface VoxelBounds {
|
|
599
|
+
/** x */
|
|
600
|
+
width: number;
|
|
601
|
+
/** y */
|
|
602
|
+
height: number;
|
|
603
|
+
/** z */
|
|
604
|
+
depth: number;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Options for the {@link VoxelMesh} constructor; the rest are passed on to {@link VoxelGeometry}.
|
|
608
|
+
*
|
|
609
|
+
* @category Voxels
|
|
610
|
+
*/
|
|
611
|
+
export interface VoxelMeshOptions extends Omit<BuildVoxelGeometryOptions, 'target'> {
|
|
612
|
+
/** vertexColors is turned on; default: MeshLambertMaterial */
|
|
613
|
+
material?: Material | Material[];
|
|
614
|
+
/** voxels may only be set inside [0, width) x [0, height) x [0, depth) */
|
|
615
|
+
bounds?: VoxelBounds;
|
|
616
|
+
/** existing voxel data to show */
|
|
617
|
+
voxels?: Map3D;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Editable voxel model: `set()` voxels, then `update()` rebuilds the geometry if anything changed.
|
|
621
|
+
* Voxel values are palette indices; `Map3D`'s default value (-1) means empty.
|
|
622
|
+
*
|
|
623
|
+
* ```ts
|
|
624
|
+
* const model = new VoxelMesh({ palette: [0xff0000, 0x00ff00], bounds: { width: 16, height: 16, depth: 16 } });
|
|
625
|
+
* scene.add(model);
|
|
626
|
+
*
|
|
627
|
+
* model.set(0, 0, 0, 1);
|
|
628
|
+
* model.update(); // rebuilds once, however many voxels changed
|
|
629
|
+
* ```
|
|
630
|
+
*
|
|
631
|
+
* @category Voxels
|
|
632
|
+
*/
|
|
633
|
+
export declare class VoxelMesh extends Mesh<VoxelGeometry, Material | Material[]> {
|
|
634
|
+
/** `set()` ignores voxels outside these; undefined = unbounded */
|
|
635
|
+
bounds?: VoxelBounds;
|
|
636
|
+
private _dirty;
|
|
637
|
+
/** the geometry's voxel data; call `invalidate()` after changing it directly */
|
|
638
|
+
get voxels(): Map3D;
|
|
639
|
+
/** geometry is out of date with the voxels */
|
|
640
|
+
get needsUpdate(): boolean;
|
|
641
|
+
constructor(options?: VoxelMeshOptions);
|
|
642
|
+
/** Whether (x, y, z) is inside `bounds` (always true without bounds). */
|
|
643
|
+
inBounds(x: number, y: number, z: number): boolean;
|
|
644
|
+
/** Voxel value at (x, y, z); the map's default value (-1 unless you passed your own map) if empty. */
|
|
645
|
+
get(x: number, y: number, z: number): number;
|
|
646
|
+
/** Sets a voxel; leave out `value` (or pass the default value) to remove it. Ignored outside the bounds. */
|
|
647
|
+
set(x: number, y: number, z: number, value?: number): void;
|
|
648
|
+
/** (not `clear()`: that's Object3D's "remove all children") */
|
|
649
|
+
clearVoxels(): void;
|
|
650
|
+
/** Call after changing `voxels` directly (or the geometry's options) to force a rebuild. */
|
|
651
|
+
invalidate(): void;
|
|
652
|
+
/** Rebuilds the geometry if the voxels changed; returns whether it did. */
|
|
653
|
+
update(): boolean;
|
|
654
|
+
}
|
|
655
|
+
//#endregion
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/tilemap.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Sparse 2D grid of arbitrary values, keyed by floored integer coordinates. Simpler than
|
|
4
|
+
* {@link Map2D} (string keys, any value type, no default value or range limit).
|
|
5
|
+
*
|
|
6
|
+
* @category Maps & Spatial
|
|
7
|
+
*/
|
|
8
|
+
export declare class Tilemap<T = number> {
|
|
9
|
+
/** backing store, keyed `"<x>x<y>"` (floored) */
|
|
10
|
+
map: Map<string, T>;
|
|
11
|
+
private _key;
|
|
12
|
+
/** Value of the tile containing (x, y), or `undefined` if none was set. */
|
|
13
|
+
get(x: number, y: number): T | undefined;
|
|
14
|
+
/** Sets the tile containing (x, y). */
|
|
15
|
+
set(x: number, y: number, v: T): void;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
package/dist/tilemap.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/tilemap.ts
|
|
2
|
+
/**
|
|
3
|
+
* Sparse 2D grid of arbitrary values, keyed by floored integer coordinates. Simpler than
|
|
4
|
+
* {@link Map2D} (string keys, any value type, no default value or range limit).
|
|
5
|
+
*
|
|
6
|
+
* @category Maps & Spatial
|
|
7
|
+
*/
|
|
8
|
+
var Tilemap = class {
|
|
9
|
+
/** backing store, keyed `"<x>x<y>"` (floored) */
|
|
10
|
+
map = /* @__PURE__ */ new Map();
|
|
11
|
+
_key(x, y) {
|
|
12
|
+
x = Math.floor(x);
|
|
13
|
+
y = Math.floor(y);
|
|
14
|
+
return `${x}x${y}`;
|
|
15
|
+
}
|
|
16
|
+
/** Value of the tile containing (x, y), or `undefined` if none was set. */
|
|
17
|
+
get(x, y) {
|
|
18
|
+
return this.map.get(this._key(x, y));
|
|
19
|
+
}
|
|
20
|
+
/** Sets the tile containing (x, y). */
|
|
21
|
+
set(x, y, v) {
|
|
22
|
+
this.map.set(this._key(x, y), v);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { Tilemap };
|