@n3rdw1z4rd/core 0.20.0 → 0.22.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/dist/graph/doc.d.ts +141 -0
- package/dist/graph/doc.js +173 -0
- package/dist/graph/evaluate.d.ts +114 -0
- package/dist/graph/evaluate.js +319 -0
- package/dist/graph/index.d.ts +9 -0
- package/dist/graph/index.js +9 -0
- package/dist/graph/node.d.ts +153 -0
- package/dist/graph/node.js +94 -0
- package/dist/graph/nodes.d.ts +11 -0
- package/dist/graph/nodes.js +399 -0
- package/dist/graph/script.d.ts +64 -0
- package/dist/graph/script.js +111 -0
- package/dist/graph/sources.d.ts +11 -0
- package/dist/graph/sources.js +263 -0
- package/dist/graph/subgraph.d.ts +36 -0
- package/dist/graph/subgraph.js +280 -0
- package/dist/graph/types.d.ts +56 -0
- package/dist/graph/types.js +67 -0
- package/dist/graph.cjs +1723 -0
- package/dist/graph.d.cts +576 -0
- package/dist/index.cjs +53 -52
- package/dist/rng-Dhqq7owV.cjs +642 -0
- package/dist/{spatial-partition-3d-Ba-VBveM.cjs → spatial-partition-3d-CmSCL87Z.cjs} +19 -660
- package/dist/three/adaptive-grid.d.ts +43 -0
- package/dist/three/adaptive-grid.js +127 -0
- package/dist/three/ecs.d.ts +5 -3
- package/dist/three/ecs.js +5 -3
- package/dist/three/editor-camera.d.ts +93 -0
- package/dist/three/editor-camera.js +174 -0
- package/dist/three/index.d.ts +6 -1
- package/dist/three/index.js +6 -1
- package/dist/three/picking.d.ts +34 -0
- package/dist/three/picking.js +59 -0
- package/dist/three/schema.d.ts +139 -0
- package/dist/three/schema.js +214 -0
- package/dist/three/world.d.ts +192 -0
- package/dist/three/world.js +363 -0
- package/dist/three.cjs +970 -23
- package/dist/three.d.cts +497 -5
- package/dist/vite.cjs +40 -0
- package/dist/vite.d.cts +35 -0
- package/dist/vite.d.ts +35 -0
- package/dist/vite.js +39 -0
- package/package.json +21 -1
package/dist/three.d.cts
CHANGED
|
@@ -1,5 +1,138 @@
|
|
|
1
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";
|
|
2
|
+
import { BufferGeometry, ColorRepresentation, Group, LineBasicMaterial, LineSegments, Material, Mesh, MeshLambertMaterial, MeshLambertMaterialParameters, Object3D, OrthographicCamera, PerspectiveCamera, Points, Raycaster, Texture, Vector3, WebGLRenderer, WebGLRendererParameters } from "three";
|
|
3
|
+
//#region src/three/editor-camera.d.ts
|
|
4
|
+
/** Screen edges covered by UI, CSS px. */
|
|
5
|
+
export interface ViewInsets {
|
|
6
|
+
l: number;
|
|
7
|
+
r: number;
|
|
8
|
+
t: number;
|
|
9
|
+
b: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An editor viewport camera: orthographic or perspective, with pan, zoom-at-cursor, orbit
|
|
13
|
+
* and fit-to-bounds, and conversions between screen (CSS px, relative to the canvas) and
|
|
14
|
+
* world coordinates.
|
|
15
|
+
*
|
|
16
|
+
* Both projections share one rig — a `target` the camera looks at, `yaw`/`pitch` around it,
|
|
17
|
+
* and a `zoom` in screen px per world unit at the target — so switching projection keeps the
|
|
18
|
+
* framing. `yaw = pitch = 0` looks down -Z at the XY plane: a 2D view (three.js convention,
|
|
19
|
+
* +Y up). Set `orbit = false` to lock it there.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const view = new EditorCamera();
|
|
23
|
+
* view.resize(canvas.clientWidth, canvas.clientHeight);
|
|
24
|
+
* view.pan(dx, dy); // the world follows the pointer
|
|
25
|
+
* view.zoomAt(x, y, 1.1); // the point under the cursor stays put
|
|
26
|
+
* renderer.render(scene, view.camera); // the active three.js camera (updated by the calls above)
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @category Three.js
|
|
30
|
+
*/
|
|
31
|
+
export declare class EditorCamera {
|
|
32
|
+
readonly ortho: OrthographicCamera;
|
|
33
|
+
readonly perspective: PerspectiveCamera;
|
|
34
|
+
/** the point looked at (and orbited around) */
|
|
35
|
+
readonly target: Vector3;
|
|
36
|
+
/** radians around +Y */
|
|
37
|
+
yaw: number;
|
|
38
|
+
/** radians; positive looks down from above */
|
|
39
|
+
pitch: number;
|
|
40
|
+
/** screen px per world unit, at the target */
|
|
41
|
+
zoom: number;
|
|
42
|
+
minZoom: number;
|
|
43
|
+
maxZoom: number;
|
|
44
|
+
/** false locks yaw/pitch at 0 (a 2D view) */
|
|
45
|
+
orbit: boolean;
|
|
46
|
+
/** pitch limit, radians */
|
|
47
|
+
maxPitch: number;
|
|
48
|
+
/** view size, CSS px */
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
private _projection;
|
|
52
|
+
private readonly raycaster;
|
|
53
|
+
private readonly ndc;
|
|
54
|
+
private readonly plane;
|
|
55
|
+
constructor(options?: {
|
|
56
|
+
projection?: 'orthographic' | 'perspective';
|
|
57
|
+
fov?: number;
|
|
58
|
+
orbit?: boolean;
|
|
59
|
+
});
|
|
60
|
+
get projection(): 'orthographic' | 'perspective';
|
|
61
|
+
set projection(p: 'orthographic' | 'perspective');
|
|
62
|
+
/** the active three.js camera */
|
|
63
|
+
get camera(): OrthographicCamera | PerspectiveCamera;
|
|
64
|
+
/** distance from the target that gives `zoom` px per unit (perspective) */
|
|
65
|
+
get distance(): number;
|
|
66
|
+
resize(width: number, height: number): void;
|
|
67
|
+
/** Recomputes both cameras from the rig; the other methods call it. */
|
|
68
|
+
update(): void;
|
|
69
|
+
/** A ray from the camera through the screen point (CSS px). */
|
|
70
|
+
rayAt(sx: number, sy: number): Raycaster;
|
|
71
|
+
/**
|
|
72
|
+
* The world point under the screen point on the plane `z = planeZ` (default: through the
|
|
73
|
+
* target), or null if the view is edge-on to it.
|
|
74
|
+
*/
|
|
75
|
+
screenToWorld(sx: number, sy: number, planeZ?: number, out?: Vector3): Vector3 | null;
|
|
76
|
+
/** The screen point (CSS px) of a world point; `z` > 1 means behind the camera. */
|
|
77
|
+
worldToScreen(point: Vector3): {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
z: number;
|
|
81
|
+
};
|
|
82
|
+
/** Pans by a screen-space delta: the world follows the pointer. */
|
|
83
|
+
pan(dx: number, dy: number): void;
|
|
84
|
+
/** Orbits by a screen-space delta (no-op while `orbit` is false). */
|
|
85
|
+
rotate(dx: number, dy: number, speed?: number): void;
|
|
86
|
+
/** Zooms by `factor`, keeping the world point under (sx, sy) fixed where possible. */
|
|
87
|
+
zoomAt(sx: number, sy: number, factor: number): void;
|
|
88
|
+
/**
|
|
89
|
+
* Frames a box on the XY plane inside the view, leaving `margin` CSS px and keeping
|
|
90
|
+
* clear of `insets` (screen edges covered by UI). Keeps yaw/pitch.
|
|
91
|
+
*/
|
|
92
|
+
fit(minX: number, minY: number, maxX: number, maxY: number, insets?: ViewInsets, margin?: number, maxZoom?: number): void;
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/three/adaptive-grid.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* An infinite-looking grid on the XY plane for editor views: each {@link AdaptiveGrid.update}
|
|
98
|
+
* rebuilds just the lines in view, doubling the spacing when zoomed out so lines never get
|
|
99
|
+
* closer than `minSpacingPx`. Optional origin cross.
|
|
100
|
+
*
|
|
101
|
+
* ```ts
|
|
102
|
+
* const grid = new AdaptiveGrid({ color: '#262626' });
|
|
103
|
+
* scene.add(grid);
|
|
104
|
+
* // per frame, after moving the camera:
|
|
105
|
+
* grid.update(view, 32);
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @category Three.js
|
|
109
|
+
*/
|
|
110
|
+
export declare class AdaptiveGrid extends LineSegments<BufferGeometry, LineBasicMaterial> {
|
|
111
|
+
minSpacingPx: number;
|
|
112
|
+
/** draw the grid lines (false: just the origin cross, if `origin`) */
|
|
113
|
+
lines: boolean;
|
|
114
|
+
/** draw a small cross at the origin (`originSizePx` long) */
|
|
115
|
+
origin: boolean;
|
|
116
|
+
originSizePx: number;
|
|
117
|
+
/** the most lines per axis (a far-off perspective view stops there) */
|
|
118
|
+
maxLines: number;
|
|
119
|
+
private readonly gridColor;
|
|
120
|
+
private readonly originColor;
|
|
121
|
+
private positions;
|
|
122
|
+
private colors;
|
|
123
|
+
constructor(options?: {
|
|
124
|
+
color?: ColorRepresentation;
|
|
125
|
+
originColor?: ColorRepresentation;
|
|
126
|
+
minSpacingPx?: number;
|
|
127
|
+
origin?: boolean;
|
|
128
|
+
originSizePx?: number;
|
|
129
|
+
});
|
|
130
|
+
/** Rebuilds the lines for the current view; `cell` is the base spacing in world units. */
|
|
131
|
+
update(view: EditorCamera, cell: number, z?: number): void;
|
|
132
|
+
private ensure;
|
|
133
|
+
dispose(): void;
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
3
136
|
//#region src/three/asteroid-mesh.d.ts
|
|
4
137
|
/**
|
|
5
138
|
* Options for the {@link AsteroidMesh} constructor.
|
|
@@ -247,7 +380,7 @@ export type ThreeComponent = Record<string, any>;
|
|
|
247
380
|
export interface ThreeEntity extends Object3D {
|
|
248
381
|
/** `Object3D.userData` with the entity's id and components */
|
|
249
382
|
userData: {
|
|
250
|
-
/**
|
|
383
|
+
/** the object's `uuid` (kept in sync by {@link World}) */
|
|
251
384
|
entityId: string;
|
|
252
385
|
/** components by name */
|
|
253
386
|
components: Record<string, ThreeComponent>;
|
|
@@ -257,12 +390,14 @@ export interface ThreeEntity extends Object3D {
|
|
|
257
390
|
/**
|
|
258
391
|
* Returns a new id `"entity_<n>"` from a module-level counter (unique per page load, not random).
|
|
259
392
|
*
|
|
393
|
+
* @deprecated entities now use their `Object3D.uuid` as id (stable across save and load);
|
|
394
|
+
* this is no longer used by {@link CreateThreeEntity}
|
|
260
395
|
* @category ECS
|
|
261
396
|
*/
|
|
262
397
|
export declare function GenerateEntityId(): string;
|
|
263
398
|
/**
|
|
264
|
-
* Turns `obj` (default: a new `Group`) into an entity in place:
|
|
265
|
-
*
|
|
399
|
+
* Turns `obj` (default: a new `Group`) into an entity in place: an empty component set
|
|
400
|
+
* (replacing any it had), with its `uuid` as id.
|
|
266
401
|
*
|
|
267
402
|
* ```ts
|
|
268
403
|
* const ship = CreateThreeEntity(shipMesh);
|
|
@@ -357,6 +492,362 @@ export declare class ParticleSystem3d extends Group {
|
|
|
357
492
|
update(camera: PerspectiveCamera, dt: number): void;
|
|
358
493
|
}
|
|
359
494
|
//#endregion
|
|
495
|
+
//#region src/three/schema.d.ts
|
|
496
|
+
/**
|
|
497
|
+
* Component schemas: what fields a component type has, their types, defaults and ranges.
|
|
498
|
+
*
|
|
499
|
+
* A schema is what lets an editor work with components it has never seen: the inspector,
|
|
500
|
+
* the scene serializer and (later) graph nodes are all generated from it.
|
|
501
|
+
*
|
|
502
|
+
* Two ways to declare a component type, producing the same {@link ComponentType}:
|
|
503
|
+
*
|
|
504
|
+
* ```ts
|
|
505
|
+
* // a class with standard (TC39) decorators — needs the `decorators()` Vite plugin
|
|
506
|
+
* // from `@n3rdw1z4rd/core/vite` until browsers run decorators natively
|
|
507
|
+
* @component('RigidBody')
|
|
508
|
+
* class RigidBody {
|
|
509
|
+
* @field({ type: 'enum', options: ['dynamic', 'fixed', 'kinematic'] }) kind = 'dynamic';
|
|
510
|
+
* @field({ min: 0, step: 0.1 }) mass = 1;
|
|
511
|
+
* @field() velocity = new Vector3();
|
|
512
|
+
* }
|
|
513
|
+
*
|
|
514
|
+
* // plain data — no decorators, works anywhere (e.g. in a worker or a user script)
|
|
515
|
+
* const Health = defineComponent('Health', {
|
|
516
|
+
* value: { type: 'number', default: 100, min: 0 },
|
|
517
|
+
* regen: { type: 'boolean', default: false },
|
|
518
|
+
* });
|
|
519
|
+
* ```
|
|
520
|
+
*
|
|
521
|
+
* @module
|
|
522
|
+
*/
|
|
523
|
+
/** @category ECS */
|
|
524
|
+
export type FieldType = 'number' | 'boolean' | 'string' | 'color' | 'vec2' | 'vec3' | 'enum' | 'entity' | 'asset';
|
|
525
|
+
/**
|
|
526
|
+
* One field of a component schema.
|
|
527
|
+
*
|
|
528
|
+
* @category ECS
|
|
529
|
+
*/
|
|
530
|
+
export interface FieldDef {
|
|
531
|
+
type: FieldType;
|
|
532
|
+
/** the value a new component starts with */
|
|
533
|
+
default?: unknown;
|
|
534
|
+
/** shown instead of the field name */
|
|
535
|
+
label?: string;
|
|
536
|
+
min?: number;
|
|
537
|
+
max?: number;
|
|
538
|
+
step?: number;
|
|
539
|
+
/** the choices of an `enum` field */
|
|
540
|
+
options?: readonly string[];
|
|
541
|
+
/** kept and saved, but not shown in an inspector */
|
|
542
|
+
hidden?: boolean;
|
|
543
|
+
/** saved, but not editable in an inspector */
|
|
544
|
+
readonly?: boolean;
|
|
545
|
+
/** not saved with the scene (runtime-only state) */
|
|
546
|
+
transient?: boolean;
|
|
547
|
+
/**
|
|
548
|
+
* Editor hint: show the field only while this returns true for the component, e.g.
|
|
549
|
+
* `showIf: (shape) => shape.kind === 'box'`. Not saved (schemas aren't).
|
|
550
|
+
*/
|
|
551
|
+
showIf?: (component: any) => boolean;
|
|
552
|
+
}
|
|
553
|
+
/** @category ECS */
|
|
554
|
+
export interface ComponentSchema {
|
|
555
|
+
/** unique among registered types; the key the component is stored and saved under */
|
|
556
|
+
name: string;
|
|
557
|
+
fields: Record<string, FieldDef>;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* A component type: its schema, and how to make an instance.
|
|
561
|
+
*
|
|
562
|
+
* @category ECS
|
|
563
|
+
*/
|
|
564
|
+
export interface ComponentType<T extends object = any> {
|
|
565
|
+
readonly schema: ComponentSchema;
|
|
566
|
+
/** the class, for class-based types */
|
|
567
|
+
readonly ctor?: new () => T;
|
|
568
|
+
/** a new instance with the defaults, then `data` (raw JSON or live values) applied */
|
|
569
|
+
create(data?: Partial<Record<keyof T, unknown>> | Record<string, unknown>): T;
|
|
570
|
+
}
|
|
571
|
+
/** Works out a field's type from a value, e.g. a class field's initial value. */
|
|
572
|
+
export declare function inferFieldType(value: unknown): FieldType;
|
|
573
|
+
/** A field value as plain JSON: vectors become arrays, colors `#rrggbb` strings. */
|
|
574
|
+
export declare function fieldToJson(def: FieldDef, value: unknown): unknown;
|
|
575
|
+
/**
|
|
576
|
+
* Applies a JSON (or live) value to a field. When the field currently holds a three.js
|
|
577
|
+
* object (a `Vector3`, a `Color`…) it is updated in place, so references to it stay valid.
|
|
578
|
+
*/
|
|
579
|
+
export declare function applyFieldValue(target: Record<string, any>, key: string, def: FieldDef, json: unknown): void;
|
|
580
|
+
/** The saved form of a component: every non-transient field, as JSON. */
|
|
581
|
+
export declare function componentToJson(type: ComponentType, component: Record<string, any>): Record<string, unknown>;
|
|
582
|
+
/**
|
|
583
|
+
* Declares a component type from plain field definitions; instances are plain objects.
|
|
584
|
+
*
|
|
585
|
+
* @category ECS
|
|
586
|
+
*/
|
|
587
|
+
export declare function defineComponent<F extends Record<string, FieldDef>>(name: string, fields: F, registry?: ComponentRegistry | null): ComponentType<{ [K in keyof F]: any; }>;
|
|
588
|
+
type FieldOptions = Partial<FieldDef>;
|
|
589
|
+
/**
|
|
590
|
+
* Field decorator: marks a class field as part of the component's schema. The type is
|
|
591
|
+
* inferred from the initial value when not given.
|
|
592
|
+
*
|
|
593
|
+
* @category ECS
|
|
594
|
+
*/
|
|
595
|
+
export declare function field(options?: FieldOptions): (_value: undefined, context: ClassFieldDecoratorContext) => void;
|
|
596
|
+
/**
|
|
597
|
+
* Class decorator: registers the class as a component type (in the default registry, or
|
|
598
|
+
* the one given). Give it a name: class names don't survive minification.
|
|
599
|
+
*
|
|
600
|
+
* @category ECS
|
|
601
|
+
*/
|
|
602
|
+
export declare function component(name?: string, registry?: ComponentRegistry): <C extends new () => object>(ctor: C, context: ClassDecoratorContext<C>) => void;
|
|
603
|
+
/**
|
|
604
|
+
* The {@link ComponentType} for a class with `@field`s (made once, then cached). Field types
|
|
605
|
+
* and defaults come from a fresh instance.
|
|
606
|
+
*
|
|
607
|
+
* @category ECS
|
|
608
|
+
*/
|
|
609
|
+
export declare function componentType<T extends object>(ctor: new () => T, name?: string): ComponentType<T>;
|
|
610
|
+
/**
|
|
611
|
+
* Component types by name (and by class). Scenes are saved with type names and loaded
|
|
612
|
+
* through a registry.
|
|
613
|
+
*
|
|
614
|
+
* @category ECS
|
|
615
|
+
*/
|
|
616
|
+
export declare class ComponentRegistry {
|
|
617
|
+
private readonly byName;
|
|
618
|
+
register(type: ComponentType): ComponentType;
|
|
619
|
+
get(name: string): ComponentType | undefined;
|
|
620
|
+
has(name: string): boolean;
|
|
621
|
+
/** The type of a name, class, type or instance (via its constructor); undefined if unknown. */
|
|
622
|
+
resolve(ref: string | ComponentType | (new () => object) | object): ComponentType | undefined;
|
|
623
|
+
/** every registered type, e.g. for an "add component" menu */
|
|
624
|
+
all(): ComponentType[];
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* The default registry, used by `@component` and {@link defineComponent} unless given another.
|
|
628
|
+
*
|
|
629
|
+
* @category ECS
|
|
630
|
+
*/
|
|
631
|
+
export declare const components: ComponentRegistry;
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/three/world.d.ts
|
|
634
|
+
/**
|
|
635
|
+
* A scene of entities: three.js objects with components (see {@link CreateThreeEntity}),
|
|
636
|
+
* tracked by their `Object3D.uuid`.
|
|
637
|
+
*
|
|
638
|
+
* The world keeps an index of which entities have which components (for {@link World.query}),
|
|
639
|
+
* runs systems, tells listeners what changed (so editor panels stay in sync), and saves and
|
|
640
|
+
* loads the whole scene as plain JSON ({@link SceneDoc}).
|
|
641
|
+
*
|
|
642
|
+
* The three.js scene graph is the hierarchy: parent an entity under another and it moves
|
|
643
|
+
* with it. Transforms live on the objects themselves (`position`, `rotation`, `scale`), so
|
|
644
|
+
* there is no Transform component.
|
|
645
|
+
*
|
|
646
|
+
* ```ts
|
|
647
|
+
* const world = new World();
|
|
648
|
+
* const ball = world.create('ball');
|
|
649
|
+
* world.addComponent(ball, RigidBody, { mass: 2 });
|
|
650
|
+
*
|
|
651
|
+
* world.addSystem({ query: ['RigidBody'], update(entities, dt) { ... } });
|
|
652
|
+
* renderer.setAnimationLoop(() => { world.update(clock.tick()); renderer.render(world.root, camera); });
|
|
653
|
+
*
|
|
654
|
+
* const saved = world.serialize(); // JSON-safe
|
|
655
|
+
* world.load(saved); // same entities, same uuids
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* Add and remove entities through the world (not `Object3D.add`/`remove` directly), and call
|
|
659
|
+
* {@link World.changed} after editing a component in place, so the index and listeners stay
|
|
660
|
+
* current.
|
|
661
|
+
*
|
|
662
|
+
* @category ECS
|
|
663
|
+
*/
|
|
664
|
+
export declare class World {
|
|
665
|
+
readonly root: Object3D;
|
|
666
|
+
readonly registry: ComponentRegistry;
|
|
667
|
+
private readonly entities;
|
|
668
|
+
private readonly index;
|
|
669
|
+
private readonly systems;
|
|
670
|
+
private readonly listeners;
|
|
671
|
+
constructor(options?: {
|
|
672
|
+
root?: Object3D;
|
|
673
|
+
registry?: ComponentRegistry;
|
|
674
|
+
});
|
|
675
|
+
/** number of entities */
|
|
676
|
+
get size(): number;
|
|
677
|
+
[Symbol.iterator](): IterableIterator<ThreeEntity>;
|
|
678
|
+
/** The entity with this uuid. */
|
|
679
|
+
get(uuid: string): ThreeEntity | undefined;
|
|
680
|
+
has(obj: Object3D): boolean;
|
|
681
|
+
/** Makes a new entity (an empty `Group`, or `obj`) and adds it under `parent` (default: the root). */
|
|
682
|
+
create(name?: string, parent?: Object3D, obj?: Object3D): ThreeEntity;
|
|
683
|
+
/**
|
|
684
|
+
* Puts `obj` under `parent` (default: the root) and starts tracking it — and every entity
|
|
685
|
+
* among its descendants. `obj` is made an entity if it isn't one.
|
|
686
|
+
*/
|
|
687
|
+
add(obj: Object3D, parent?: Object3D): ThreeEntity;
|
|
688
|
+
/** Takes the entity (and its descendants) out of the scene and stops tracking them. */
|
|
689
|
+
remove(entity: Object3D): void;
|
|
690
|
+
/** Removes every entity. */
|
|
691
|
+
clear(): void;
|
|
692
|
+
/**
|
|
693
|
+
* Moves `entity` under `parent` (default: the root). By default its world transform is
|
|
694
|
+
* kept (it doesn't jump); pass `keepWorldTransform = false` to keep its local one instead.
|
|
695
|
+
*/
|
|
696
|
+
reparent(entity: ThreeEntity, parent?: Object3D, keepWorldTransform?: boolean): void;
|
|
697
|
+
/** The closest ancestor that is an entity of this world, or null. */
|
|
698
|
+
parentOf(entity: Object3D): ThreeEntity | null;
|
|
699
|
+
/** The entities directly under `parent` (default: the root), looking through non-entity objects. */
|
|
700
|
+
childrenOf(parent?: Object3D): ThreeEntity[];
|
|
701
|
+
/** A deep copy of the entity and its descendant entities (new uuids), added next to it. */
|
|
702
|
+
clone(entity: ThreeEntity, parent?: Object3D): ThreeEntity;
|
|
703
|
+
private track;
|
|
704
|
+
private untrack;
|
|
705
|
+
private indexSet;
|
|
706
|
+
/** The registered type for a name, class or type; throws if unknown. */
|
|
707
|
+
typeOf(ref: ComponentRef): ComponentType;
|
|
708
|
+
/**
|
|
709
|
+
* Adds a component made from its type's defaults plus `data`, replacing one of the same
|
|
710
|
+
* type. Returns the component.
|
|
711
|
+
*/
|
|
712
|
+
addComponent<T extends object>(entity: ThreeEntity, ref: ComponentRef<T>, data?: Record<string, unknown>): T;
|
|
713
|
+
getComponent<T extends object>(entity: ThreeEntity, ref: ComponentRef<T>): T | undefined;
|
|
714
|
+
hasComponent(entity: ThreeEntity, ref: ComponentRef): boolean;
|
|
715
|
+
removeComponent(entity: ThreeEntity, ref: ComponentRef): void;
|
|
716
|
+
/** The names of the entity's components, in the order they were added. */
|
|
717
|
+
componentNames(entity: ThreeEntity): string[];
|
|
718
|
+
/**
|
|
719
|
+
* Tells listeners a component (or the entity's transform/name, with `component` omitted)
|
|
720
|
+
* was edited in place. `field` narrows it to one field.
|
|
721
|
+
*/
|
|
722
|
+
changed(entity: ThreeEntity, component?: ComponentRef, field?: string): void;
|
|
723
|
+
/** Entities that have every one of the given components. */
|
|
724
|
+
query(...refs: ComponentRef[]): ThreeEntity[];
|
|
725
|
+
/** Entities whose name is `name`. */
|
|
726
|
+
findByName(name: string): ThreeEntity[];
|
|
727
|
+
private nameOf;
|
|
728
|
+
/**
|
|
729
|
+
* Adds a system, run by {@link World.update} in the order added. With a `query`, it gets
|
|
730
|
+
* the entities that have all of those components; without, every entity.
|
|
731
|
+
*/
|
|
732
|
+
addSystem(system: WorldSystem | WorldSystem['update'], query?: ComponentRef[]): WorldSystem;
|
|
733
|
+
removeSystem(system: WorldSystem): void;
|
|
734
|
+
/** Runs every enabled system once. */
|
|
735
|
+
update(delta: number): void;
|
|
736
|
+
/** Listens for an event; returns a function that stops listening. */
|
|
737
|
+
on<K extends keyof WorldEvents>(event: K, listener: (...args: WorldEvents[K]) => void): () => void;
|
|
738
|
+
private emit;
|
|
739
|
+
/** The whole scene as plain JSON. */
|
|
740
|
+
serialize(meta?: Record<string, unknown>): SceneDoc;
|
|
741
|
+
/**
|
|
742
|
+
* Replaces the scene with a saved one (or, with `replace: false`, adds to it). Entities
|
|
743
|
+
* keep their saved uuids.
|
|
744
|
+
*/
|
|
745
|
+
load(doc: SceneDoc, options?: {
|
|
746
|
+
replace?: boolean;
|
|
747
|
+
}): ThreeEntity[];
|
|
748
|
+
/**
|
|
749
|
+
* `entities` and their descendant entities, depth-first (parents before children), as JSON:
|
|
750
|
+
* e.g. a prefab or the clipboard.
|
|
751
|
+
*/
|
|
752
|
+
serializeEntities(entities: ThreeEntity[]): EntityDoc[];
|
|
753
|
+
private serializeEntity;
|
|
754
|
+
/**
|
|
755
|
+
* Makes entities from saved docs. A doc whose `parent` isn't among `docs` goes under
|
|
756
|
+
* `options.parent` (default: the root). With `newIds`, every entity gets a fresh uuid and
|
|
757
|
+
* `entity` fields pointing inside the set are remapped (pasting, prefabs, clone).
|
|
758
|
+
*/
|
|
759
|
+
instantiate(docs: EntityDoc[], options?: {
|
|
760
|
+
parent?: Object3D;
|
|
761
|
+
newIds?: boolean;
|
|
762
|
+
}): ThreeEntity[];
|
|
763
|
+
}
|
|
764
|
+
/** A component reference: its name, type, or class. */
|
|
765
|
+
export type ComponentRef<T extends object = any> = string | ComponentType<T> | (new () => T);
|
|
766
|
+
/** @category ECS */
|
|
767
|
+
export interface WorldSystem {
|
|
768
|
+
/** components an entity needs to be passed to `update` */
|
|
769
|
+
query?: ComponentRef[];
|
|
770
|
+
/** false skips it in {@link World.update} */
|
|
771
|
+
enabled?: boolean;
|
|
772
|
+
update(entities: ThreeEntity[], delta: number, world: World): void;
|
|
773
|
+
}
|
|
774
|
+
/** @category ECS */
|
|
775
|
+
export interface WorldEvents {
|
|
776
|
+
entityAdded: [entity: ThreeEntity];
|
|
777
|
+
entityRemoved: [entity: ThreeEntity];
|
|
778
|
+
componentAdded: [entity: ThreeEntity, name: string, component: object];
|
|
779
|
+
componentRemoved: [entity: ThreeEntity, name: string, component: object];
|
|
780
|
+
/** `component` undefined: the entity itself (transform, name, visibility) */
|
|
781
|
+
changed: [entity: ThreeEntity, component: string | undefined, field: string | undefined];
|
|
782
|
+
reparented: [entity: ThreeEntity, parent: Object3D];
|
|
783
|
+
}
|
|
784
|
+
type Vec3 = [number, number, number];
|
|
785
|
+
export declare const SCENE_FORMAT = "n3rdw1z4rd.scene";
|
|
786
|
+
export declare const SCENE_VERSION = 1;
|
|
787
|
+
/**
|
|
788
|
+
* A saved scene: plain JSON.
|
|
789
|
+
*
|
|
790
|
+
* @category ECS
|
|
791
|
+
*/
|
|
792
|
+
export interface SceneDoc {
|
|
793
|
+
format: typeof SCENE_FORMAT;
|
|
794
|
+
version: number;
|
|
795
|
+
/** depth-first: parents before their children */
|
|
796
|
+
entities: EntityDoc[];
|
|
797
|
+
/** anything else the app wants saved with the scene (camera, settings, scripts…) */
|
|
798
|
+
meta?: Record<string, unknown>;
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* One saved entity. Only entities are saved: non-entity objects (e.g. meshes a render
|
|
802
|
+
* system made) are rebuilt from components.
|
|
803
|
+
*
|
|
804
|
+
* @category ECS
|
|
805
|
+
*/
|
|
806
|
+
export interface EntityDoc {
|
|
807
|
+
uuid: string;
|
|
808
|
+
name?: string;
|
|
809
|
+
/** the parent entity's uuid; null for a top-level entity */
|
|
810
|
+
parent: string | null;
|
|
811
|
+
position: Vec3;
|
|
812
|
+
/** Euler angles, radians */
|
|
813
|
+
rotation: Vec3;
|
|
814
|
+
rotationOrder?: string;
|
|
815
|
+
scale: Vec3;
|
|
816
|
+
visible?: false;
|
|
817
|
+
/** component JSON by type name */
|
|
818
|
+
components: Record<string, Record<string, unknown>>;
|
|
819
|
+
}
|
|
820
|
+
//#endregion
|
|
821
|
+
//#region src/three/picking.d.ts
|
|
822
|
+
/** @category Three.js */
|
|
823
|
+
export interface EntityHit {
|
|
824
|
+
entity: ThreeEntity;
|
|
825
|
+
/** world point hit */
|
|
826
|
+
point: Vector3;
|
|
827
|
+
distance: number;
|
|
828
|
+
/** the object actually hit (e.g. a mesh a render system made under the entity) */
|
|
829
|
+
object: Object3D;
|
|
830
|
+
}
|
|
831
|
+
/** @category Three.js */
|
|
832
|
+
export interface PickOptions {
|
|
833
|
+
/**
|
|
834
|
+
* On a miss, also try rays this many CSS px around the point and take the hit closest to
|
|
835
|
+
* it — small things are hard to hit with a finger.
|
|
836
|
+
*/
|
|
837
|
+
slopPx?: number;
|
|
838
|
+
/** skip hits on objects this returns false for (e.g. gizmos, helpers) */
|
|
839
|
+
filter?: (object: Object3D) => boolean;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* The entity under a screen point (CSS px): raycasts the world's scene and walks up from
|
|
843
|
+
* whatever was hit to the closest entity of `world`. Invisible objects are skipped.
|
|
844
|
+
*
|
|
845
|
+
* @category Three.js
|
|
846
|
+
*/
|
|
847
|
+
export declare function pickEntity(world: World, view: EditorCamera, sx: number, sy: number, options?: PickOptions): EntityHit | null;
|
|
848
|
+
/** The closest entity of `world` at or above `object`, or null. */
|
|
849
|
+
export declare function entityOf(world: World, object: Object3D): ThreeEntity | null;
|
|
850
|
+
//#endregion
|
|
360
851
|
//#region src/three/renderer.d.ts
|
|
361
852
|
/**
|
|
362
853
|
* `WebGLRenderer` that uses the device pixel ratio and can size itself to its parent element.
|
|
@@ -652,4 +1143,5 @@ export declare class VoxelMesh extends Mesh<VoxelGeometry, Material | Material[]
|
|
|
652
1143
|
/** Rebuilds the geometry if the voxels changed; returns whether it did. */
|
|
653
1144
|
update(): boolean;
|
|
654
1145
|
}
|
|
655
|
-
//#endregion
|
|
1146
|
+
//#endregion
|
|
1147
|
+
export {};
|
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/vite.ts
|
|
3
|
+
/** @category Build */
|
|
4
|
+
function decorators() {
|
|
5
|
+
const file = /\.[cm]?[jt]sx?$/;
|
|
6
|
+
const usesDecorator = /(^|[\s;{(])@[A-Za-z_$][\w$]*\s*(\(|\n|\s+[A-Za-z_$#])/m;
|
|
7
|
+
let transform;
|
|
8
|
+
return {
|
|
9
|
+
name: "n3rdw1z4rd:standard-decorators",
|
|
10
|
+
enforce: "pre",
|
|
11
|
+
async transform(code, id) {
|
|
12
|
+
const path = id.split("?")[0];
|
|
13
|
+
if (!file.test(path) || path.includes("/node_modules/") || !usesDecorator.test(code)) return null;
|
|
14
|
+
transform ??= (await import(
|
|
15
|
+
/* @vite-ignore */
|
|
16
|
+
"esbuild"
|
|
17
|
+
).catch(() => {
|
|
18
|
+
throw new Error("@n3rdw1z4rd/core/vite: install esbuild (npm i -D esbuild) to compile @field decorators");
|
|
19
|
+
})).transform;
|
|
20
|
+
const loader = path.slice(path.lastIndexOf(".") + 1).replace(/^[cm]/, "");
|
|
21
|
+
const result = await transform(code, {
|
|
22
|
+
loader,
|
|
23
|
+
sourcefile: path,
|
|
24
|
+
sourcemap: true,
|
|
25
|
+
target: "es2022",
|
|
26
|
+
jsx: "preserve",
|
|
27
|
+
tsconfigRaw: { compilerOptions: {
|
|
28
|
+
useDefineForClassFields: true,
|
|
29
|
+
verbatimModuleSyntax: true
|
|
30
|
+
} }
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
code: result.code,
|
|
34
|
+
map: result.map
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.decorators = decorators;
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/vite.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Vite plugin: lowers standard (TC39) decorators such as `@field` / `@component` with esbuild.
|
|
4
|
+
*
|
|
5
|
+
* Vite 8 compiles TypeScript with Oxc, which only lowers legacy `experimentalDecorators` and
|
|
6
|
+
* passes standard decorators through untouched — no browser can run that yet. This runs
|
|
7
|
+
* first on any source file that uses a decorator; Oxc then sees plain TS/JS.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* // vite.config.ts
|
|
11
|
+
* import { decorators } from '@n3rdw1z4rd/core/vite';
|
|
12
|
+
* export default defineConfig({ plugins: [decorators()] });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Requires `esbuild` to be installed alongside Vite. Node-only: not exported from the
|
|
16
|
+
* package root.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
* @module @n3rdw1z4rd/core/vite
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The part of Vite's `Plugin` this uses, declared here so core doesn't depend on Vite
|
|
23
|
+
* (structurally compatible: pass it straight to `plugins`).
|
|
24
|
+
*/
|
|
25
|
+
export interface DecoratorsPlugin {
|
|
26
|
+
name: string;
|
|
27
|
+
enforce: 'pre';
|
|
28
|
+
transform(code: string, id: string): Promise<{
|
|
29
|
+
code: string;
|
|
30
|
+
map: string;
|
|
31
|
+
} | null>;
|
|
32
|
+
}
|
|
33
|
+
/** @category Build */
|
|
34
|
+
export declare function decorators(): DecoratorsPlugin;
|
|
35
|
+
//#endregion
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/vite.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Vite plugin: lowers standard (TC39) decorators such as `@field` / `@component` with esbuild.
|
|
4
|
+
*
|
|
5
|
+
* Vite 8 compiles TypeScript with Oxc, which only lowers legacy `experimentalDecorators` and
|
|
6
|
+
* passes standard decorators through untouched — no browser can run that yet. This runs
|
|
7
|
+
* first on any source file that uses a decorator; Oxc then sees plain TS/JS.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* // vite.config.ts
|
|
11
|
+
* import { decorators } from '@n3rdw1z4rd/core/vite';
|
|
12
|
+
* export default defineConfig({ plugins: [decorators()] });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Requires `esbuild` to be installed alongside Vite. Node-only: not exported from the
|
|
16
|
+
* package root.
|
|
17
|
+
*
|
|
18
|
+
* @packageDocumentation
|
|
19
|
+
* @module @n3rdw1z4rd/core/vite
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The part of Vite's `Plugin` this uses, declared here so core doesn't depend on Vite
|
|
23
|
+
* (structurally compatible: pass it straight to `plugins`).
|
|
24
|
+
*/
|
|
25
|
+
export interface DecoratorsPlugin {
|
|
26
|
+
name: string;
|
|
27
|
+
enforce: 'pre';
|
|
28
|
+
transform(code: string, id: string): Promise<{
|
|
29
|
+
code: string;
|
|
30
|
+
map: string;
|
|
31
|
+
} | null>;
|
|
32
|
+
}
|
|
33
|
+
/** @category Build */
|
|
34
|
+
export declare function decorators(): DecoratorsPlugin;
|
|
35
|
+
//#endregion
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/vite.ts
|
|
2
|
+
/** @category Build */
|
|
3
|
+
function decorators() {
|
|
4
|
+
const file = /\.[cm]?[jt]sx?$/;
|
|
5
|
+
const usesDecorator = /(^|[\s;{(])@[A-Za-z_$][\w$]*\s*(\(|\n|\s+[A-Za-z_$#])/m;
|
|
6
|
+
let transform;
|
|
7
|
+
return {
|
|
8
|
+
name: "n3rdw1z4rd:standard-decorators",
|
|
9
|
+
enforce: "pre",
|
|
10
|
+
async transform(code, id) {
|
|
11
|
+
const path = id.split("?")[0];
|
|
12
|
+
if (!file.test(path) || path.includes("/node_modules/") || !usesDecorator.test(code)) return null;
|
|
13
|
+
transform ??= (await import(
|
|
14
|
+
/* @vite-ignore */
|
|
15
|
+
"esbuild"
|
|
16
|
+
).catch(() => {
|
|
17
|
+
throw new Error("@n3rdw1z4rd/core/vite: install esbuild (npm i -D esbuild) to compile @field decorators");
|
|
18
|
+
})).transform;
|
|
19
|
+
const loader = path.slice(path.lastIndexOf(".") + 1).replace(/^[cm]/, "");
|
|
20
|
+
const result = await transform(code, {
|
|
21
|
+
loader,
|
|
22
|
+
sourcefile: path,
|
|
23
|
+
sourcemap: true,
|
|
24
|
+
target: "es2022",
|
|
25
|
+
jsx: "preserve",
|
|
26
|
+
tsconfigRaw: { compilerOptions: {
|
|
27
|
+
useDefineForClassFields: true,
|
|
28
|
+
verbatimModuleSyntax: true
|
|
29
|
+
} }
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
code: result.code,
|
|
33
|
+
map: result.map
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { decorators };
|