@waica/engine 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -1
- package/dist/anchored-pieces.d.ts +3 -2
- package/dist/anchored-pieces.js +12 -8
- package/dist/archetype.d.ts +2 -2
- package/dist/assets/asset-loader.d.ts +28 -5
- package/dist/assets/asset-loader.js +63 -7
- package/dist/assets/model-backend.d.ts +21 -0
- package/dist/assets/model-backend.js +21 -0
- package/dist/assets/model-cache.d.ts +47 -0
- package/dist/assets/model-cache.js +117 -0
- package/dist/audio/audio-subsystem.d.ts +6 -1
- package/dist/audio/audio-subsystem.js +8 -15
- package/dist/audio/placement.d.ts +41 -0
- package/dist/audio/placement.js +21 -0
- package/dist/audio/spatial.d.ts +20 -0
- package/dist/audio/spatial.js +26 -0
- package/dist/audio/types.d.ts +7 -1
- package/dist/camera-projection.d.ts +38 -0
- package/dist/camera-projection.js +44 -0
- package/dist/camera-rig.d.ts +48 -0
- package/dist/camera-rig.js +98 -0
- package/dist/camera.d.ts +20 -3
- package/dist/camera.js +3 -1
- package/dist/component.d.ts +38 -2
- package/dist/component.js +3 -0
- package/dist/components/animated-sprite.d.ts +2 -1
- package/dist/components/animated-sprite.js +1 -0
- package/dist/components/collider.d.ts +89 -0
- package/dist/components/collider.js +57 -0
- package/dist/components/dynamic-body.d.ts +2 -1
- package/dist/components/dynamic-body.js +1 -0
- package/dist/components/hitbox.d.ts +2 -1
- package/dist/components/hitbox.js +1 -0
- package/dist/components/light.d.ts +2 -1
- package/dist/components/light.js +1 -0
- package/dist/components/model.d.ts +63 -0
- package/dist/components/model.js +117 -0
- package/dist/components/particle-emitter.d.ts +2 -1
- package/dist/components/particle-emitter.js +1 -0
- package/dist/components/point-light.d.ts +75 -0
- package/dist/components/point-light.js +102 -0
- package/dist/components/rigid-body.d.ts +114 -0
- package/dist/components/rigid-body.js +83 -0
- package/dist/components/solid.d.ts +2 -1
- package/dist/components/solid.js +1 -0
- package/dist/components/sprite.d.ts +2 -1
- package/dist/components/sprite.js +1 -0
- package/dist/components/sun.d.ts +46 -0
- package/dist/components/sun.js +74 -0
- package/dist/components/tilemap.d.ts +2 -1
- package/dist/components/tilemap.js +1 -0
- package/dist/entity-transform.d.ts +18 -0
- package/dist/entity-transform.js +17 -0
- package/dist/game.d.ts +51 -15
- package/dist/game.js +83 -70
- package/dist/index.d.ts +29 -4
- package/dist/index.js +12 -1
- package/dist/lit-frame.js +10 -3
- package/dist/physics-3d/body-contacts.d.ts +10 -0
- package/dist/physics-3d/body-contacts.js +59 -0
- package/dist/physics-3d/body-sync.d.ts +52 -0
- package/dist/physics-3d/body-sync.js +153 -0
- package/dist/physics-3d/character-controller.d.ts +44 -0
- package/dist/physics-3d/character-controller.js +126 -0
- package/dist/physics-3d/physics-host.d.ts +86 -0
- package/dist/physics-3d/physics-host.js +174 -0
- package/dist/physics-3d/physics-world.d.ts +65 -0
- package/dist/physics-3d/physics-world.js +158 -0
- package/dist/physics-3d/rapier-module.d.ts +17 -0
- package/dist/physics-3d/rapier-module.js +19 -0
- package/dist/physics-3d/sensor-dispatch.d.ts +10 -0
- package/dist/physics-3d/sensor-dispatch.js +77 -0
- package/dist/physics-3d/world-queries.d.ts +39 -0
- package/dist/physics-3d/world-queries.js +63 -0
- package/dist/pointer-raycast.d.ts +17 -0
- package/dist/pointer-raycast.js +48 -0
- package/dist/pointer.d.ts +27 -6
- package/dist/pointer.js +43 -17
- package/dist/runtime-bridge.d.ts +1 -1
- package/dist/runtime-inspection.d.ts +9 -0
- package/dist/runtime-inspection.js +8 -2
- package/dist/runtime-lighting-snapshot.d.ts +27 -1
- package/dist/runtime-lighting-snapshot.js +31 -0
- package/dist/runtime-physics-snapshot.d.ts +41 -0
- package/dist/runtime-physics-snapshot.js +45 -0
- package/dist/runtime-view-snapshot.d.ts +25 -0
- package/dist/runtime-view-snapshot.js +30 -0
- package/dist/scene-camera-3d.d.ts +66 -0
- package/dist/scene-camera-3d.js +117 -0
- package/dist/scene-lights-3d.d.ts +17 -0
- package/dist/scene-lights-3d.js +27 -0
- package/dist/scene-simulation.d.ts +22 -0
- package/dist/scene-simulation.js +29 -0
- package/dist/scene-space.d.ts +50 -0
- package/dist/scene-space.js +103 -0
- package/dist/scene.d.ts +12 -2
- package/dist/scene.js +11 -4
- package/dist/simulation-phases.d.ts +9 -0
- package/dist/simulation-phases.js +19 -0
- package/dist/spatial-query-3d.d.ts +48 -0
- package/dist/spatial-query-3d.js +96 -0
- package/dist/spatial-query.d.ts +18 -4
- package/dist/spatial-query.js +57 -1
- package/package.json +2 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
2
|
+
import type { Vec3Json } from '../scene-camera-3d.js';
|
|
3
|
+
export type ColliderShape = 'box' | 'sphere' | 'capsule';
|
|
4
|
+
export declare const COLLIDER_SHAPES: readonly ColliderShape[];
|
|
5
|
+
/**
|
|
6
|
+
* The 3D scene's collision shape (ADR 0028), Rapier's model: alone on an
|
|
7
|
+
* entity it is a fixed wall or floor, created at the entity's position and
|
|
8
|
+
* rotation scaled by `entity.scale`, and moving the entity later does not
|
|
9
|
+
* move it. With a `RigidBody` beside it, it is the body that falls, bounces
|
|
10
|
+
* or walks. `sensor: true` makes it a trigger instead — it detects and never
|
|
11
|
+
* pushes — with the 2D Hitbox's `layer` and `collidesWith` semantics (ADR
|
|
12
|
+
* 0016); with the default mask (`['*']`) a sensor is not told about fixed
|
|
13
|
+
* solid colliders (the level's walls and floors), as a Hitbox never sees a
|
|
14
|
+
* Solid — a mask that names their layer still is. `size` is a box's full
|
|
15
|
+
* extents; `radius` a sphere's or capsule's; `height` a capsule's total
|
|
16
|
+
* end-to-end height, at least twice its radius; `offset` is in the entity's
|
|
17
|
+
* local frame. A Collider in a 2D scene creates nothing; one whose params
|
|
18
|
+
* Rapier cannot take creates no body and warns once (`validate_project`
|
|
19
|
+
* reports them as `invalid-collider-param`).
|
|
20
|
+
*/
|
|
21
|
+
export declare class Collider extends Component {
|
|
22
|
+
static componentName: string;
|
|
23
|
+
static space: ComponentSpace;
|
|
24
|
+
static params: {
|
|
25
|
+
shape: {
|
|
26
|
+
label: string;
|
|
27
|
+
options: ColliderShape[];
|
|
28
|
+
};
|
|
29
|
+
size: {
|
|
30
|
+
label: string;
|
|
31
|
+
kind: "vector3";
|
|
32
|
+
};
|
|
33
|
+
radius: {
|
|
34
|
+
label: string;
|
|
35
|
+
min: number;
|
|
36
|
+
step: number;
|
|
37
|
+
};
|
|
38
|
+
height: {
|
|
39
|
+
label: string;
|
|
40
|
+
min: number;
|
|
41
|
+
step: number;
|
|
42
|
+
};
|
|
43
|
+
offset: {
|
|
44
|
+
label: string;
|
|
45
|
+
kind: "vector3";
|
|
46
|
+
};
|
|
47
|
+
sensor: {
|
|
48
|
+
label: string;
|
|
49
|
+
};
|
|
50
|
+
layer: {
|
|
51
|
+
label: string;
|
|
52
|
+
};
|
|
53
|
+
collidesWith: {
|
|
54
|
+
label: string;
|
|
55
|
+
kind: "string-list";
|
|
56
|
+
};
|
|
57
|
+
friction: {
|
|
58
|
+
label: string;
|
|
59
|
+
min: number;
|
|
60
|
+
max: number;
|
|
61
|
+
step: number;
|
|
62
|
+
};
|
|
63
|
+
restitution: {
|
|
64
|
+
label: string;
|
|
65
|
+
min: number;
|
|
66
|
+
max: number;
|
|
67
|
+
step: number;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
shape: ColliderShape;
|
|
71
|
+
/** A box's full extents `[x, y, z]`. */
|
|
72
|
+
size: Vec3Json;
|
|
73
|
+
/** A sphere's or capsule's radius. */
|
|
74
|
+
radius: number;
|
|
75
|
+
/** A capsule's total end-to-end height. */
|
|
76
|
+
height: number;
|
|
77
|
+
/** Where the shape sits in the entity's local frame. */
|
|
78
|
+
offset: Vec3Json;
|
|
79
|
+
/** A trigger: detects overlaps, never pushes or is pushed. */
|
|
80
|
+
sensor: boolean;
|
|
81
|
+
/** One exact, case-sensitive `^[a-z][a-z0-9-]*$` membership name. */
|
|
82
|
+
layer: string;
|
|
83
|
+
/** Outgoing layer interest for `onCollide`; `'*'` means every valid layer and `[]` means none. */
|
|
84
|
+
collidesWith: string[];
|
|
85
|
+
friction: number;
|
|
86
|
+
restitution: number;
|
|
87
|
+
onReady(): void;
|
|
88
|
+
onDestroy(): void;
|
|
89
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Component } from '../component.js';
|
|
2
|
+
export const COLLIDER_SHAPES = ['box', 'sphere', 'capsule'];
|
|
3
|
+
/**
|
|
4
|
+
* The 3D scene's collision shape (ADR 0028), Rapier's model: alone on an
|
|
5
|
+
* entity it is a fixed wall or floor, created at the entity's position and
|
|
6
|
+
* rotation scaled by `entity.scale`, and moving the entity later does not
|
|
7
|
+
* move it. With a `RigidBody` beside it, it is the body that falls, bounces
|
|
8
|
+
* or walks. `sensor: true` makes it a trigger instead — it detects and never
|
|
9
|
+
* pushes — with the 2D Hitbox's `layer` and `collidesWith` semantics (ADR
|
|
10
|
+
* 0016); with the default mask (`['*']`) a sensor is not told about fixed
|
|
11
|
+
* solid colliders (the level's walls and floors), as a Hitbox never sees a
|
|
12
|
+
* Solid — a mask that names their layer still is. `size` is a box's full
|
|
13
|
+
* extents; `radius` a sphere's or capsule's; `height` a capsule's total
|
|
14
|
+
* end-to-end height, at least twice its radius; `offset` is in the entity's
|
|
15
|
+
* local frame. A Collider in a 2D scene creates nothing; one whose params
|
|
16
|
+
* Rapier cannot take creates no body and warns once (`validate_project`
|
|
17
|
+
* reports them as `invalid-collider-param`).
|
|
18
|
+
*/
|
|
19
|
+
export class Collider extends Component {
|
|
20
|
+
static componentName = 'Collider';
|
|
21
|
+
static space = '3d';
|
|
22
|
+
static params = {
|
|
23
|
+
shape: { label: 'Shape', options: [...COLLIDER_SHAPES] },
|
|
24
|
+
size: { label: 'Size', kind: 'vector3' },
|
|
25
|
+
radius: { label: 'Radius', min: 0.01, step: 0.05 },
|
|
26
|
+
height: { label: 'Height', min: 0.01, step: 0.05 },
|
|
27
|
+
offset: { label: 'Offset', kind: 'vector3' },
|
|
28
|
+
sensor: { label: 'Sensor' },
|
|
29
|
+
layer: { label: 'Collision Layer' },
|
|
30
|
+
collidesWith: { label: 'Collision Mask', kind: 'string-list' },
|
|
31
|
+
friction: { label: 'Friction', min: 0, max: 1, step: 0.05 },
|
|
32
|
+
restitution: { label: 'Restitution', min: 0, max: 1, step: 0.05 },
|
|
33
|
+
};
|
|
34
|
+
shape = 'box';
|
|
35
|
+
/** A box's full extents `[x, y, z]`. */
|
|
36
|
+
size = [1, 1, 1];
|
|
37
|
+
/** A sphere's or capsule's radius. */
|
|
38
|
+
radius = 0.5;
|
|
39
|
+
/** A capsule's total end-to-end height. */
|
|
40
|
+
height = 1.8;
|
|
41
|
+
/** Where the shape sits in the entity's local frame. */
|
|
42
|
+
offset = [0, 0, 0];
|
|
43
|
+
/** A trigger: detects overlaps, never pushes or is pushed. */
|
|
44
|
+
sensor = false;
|
|
45
|
+
/** One exact, case-sensitive `^[a-z][a-z0-9-]*$` membership name. */
|
|
46
|
+
layer = 'default';
|
|
47
|
+
/** Outgoing layer interest for `onCollide`; `'*'` means every valid layer and `[]` means none. */
|
|
48
|
+
collidesWith = ['*'];
|
|
49
|
+
friction = 0.5;
|
|
50
|
+
restitution = 0;
|
|
51
|
+
onReady() {
|
|
52
|
+
this.game.physics.attach(this.entity);
|
|
53
|
+
}
|
|
54
|
+
onDestroy() {
|
|
55
|
+
this.game.physics.detach(this.entity);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type CollisionPoint, type CollisionShape } from '../collision-shape.js';
|
|
2
|
-
import { Component } from '../component.js';
|
|
2
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
3
3
|
/**
|
|
4
4
|
* Reusable linear body: integrates its public velocity and resolves only
|
|
5
5
|
* against static Solid geometry. Hitbox trigger overlaps remain independent.
|
|
6
6
|
*/
|
|
7
7
|
export declare class DynamicBody extends Component {
|
|
8
8
|
static componentName: string;
|
|
9
|
+
static space: ComponentSpace;
|
|
9
10
|
static params: {
|
|
10
11
|
vx: {
|
|
11
12
|
label: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from '../component.js';
|
|
1
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
2
2
|
import { type CollisionPoint, type CollisionShape } from '../collision-shape.js';
|
|
3
3
|
/**
|
|
4
4
|
* Trigger collider. A pair is tested when either Hitbox's Collision Mask
|
|
@@ -8,6 +8,7 @@ import { type CollisionPoint, type CollisionShape } from '../collision-shape.js'
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class Hitbox extends Component {
|
|
10
10
|
static componentName: string;
|
|
11
|
+
static space: ComponentSpace;
|
|
11
12
|
static params: {
|
|
12
13
|
layer: {
|
|
13
14
|
label: string;
|
|
@@ -8,6 +8,7 @@ import { resolveCollisionPoints, } from '../collision-shape.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export class Hitbox extends Component {
|
|
10
10
|
static componentName = 'Hitbox';
|
|
11
|
+
static space = '2d';
|
|
11
12
|
static params = {
|
|
12
13
|
layer: { label: 'Collision Layer' },
|
|
13
14
|
collidesWith: { label: 'Collision Mask', kind: 'string-list' },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from '../component.js';
|
|
1
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
2
2
|
import type { LightField } from '../light-field.js';
|
|
3
3
|
/**
|
|
4
4
|
* A source of 2D light owned by its entity (issue #78, `CONTEXT.md` Light):
|
|
@@ -10,6 +10,7 @@ import type { LightField } from '../light-field.js';
|
|
|
10
10
|
*/
|
|
11
11
|
export declare class Light extends Component {
|
|
12
12
|
static componentName: string;
|
|
13
|
+
static space: ComponentSpace;
|
|
13
14
|
static params: {
|
|
14
15
|
radius: {
|
|
15
16
|
label: string;
|
package/dist/components/light.js
CHANGED
|
@@ -12,6 +12,7 @@ const finiteOr = (value, fallback) => (Number.isFinite(value) ? value : fallback
|
|
|
12
12
|
*/
|
|
13
13
|
export class Light extends Component {
|
|
14
14
|
static componentName = 'Light';
|
|
15
|
+
static space = '2d';
|
|
15
16
|
static params = {
|
|
16
17
|
radius: { label: 'Radius', min: 0, step: 0.25 },
|
|
17
18
|
color: { label: 'Color', kind: 'color' },
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as THREE from 'three/webgpu';
|
|
2
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
3
|
+
export type ModelShape = 'box' | 'sphere' | 'plane';
|
|
4
|
+
/**
|
|
5
|
+
* A 3D thing an entity draws (3D scenes, ADR 0027): a glTF/glb from `src`
|
|
6
|
+
* (a `waica:` uri or a project path, loaded once through `game.assets`) or a
|
|
7
|
+
* primitive `shape` of a `color` and a uniform `size`. With both, `src` wins.
|
|
8
|
+
* Its root hangs under the entity's node, so the entity's position, rotation
|
|
9
|
+
* and scale place it; the glTF keeps the materials it ships with, a
|
|
10
|
+
* primitive has a standard (lit) node material. `color` and `size` follow the
|
|
11
|
+
* inspector live; a new `src` or `shape` rebuilds the content. Destroying it
|
|
12
|
+
* removes the root and disposes only what it created — never the cached glTF.
|
|
13
|
+
* In a 2D scene it creates nothing (`validate_project` reports it).
|
|
14
|
+
*/
|
|
15
|
+
export declare class Model extends Component {
|
|
16
|
+
static componentName: string;
|
|
17
|
+
static space: ComponentSpace;
|
|
18
|
+
static params: {
|
|
19
|
+
src: {
|
|
20
|
+
label: string;
|
|
21
|
+
kind: "model";
|
|
22
|
+
};
|
|
23
|
+
shape: {
|
|
24
|
+
label: string;
|
|
25
|
+
options: ModelShape[];
|
|
26
|
+
};
|
|
27
|
+
color: {
|
|
28
|
+
label: string;
|
|
29
|
+
kind: "color";
|
|
30
|
+
};
|
|
31
|
+
size: {
|
|
32
|
+
label: string;
|
|
33
|
+
min: number;
|
|
34
|
+
step: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
static transient: string[];
|
|
38
|
+
/** What this Model draws, under the entity's node; null until it is ready. The Pointer ray-casts against it. */
|
|
39
|
+
root: THREE.Group | null;
|
|
40
|
+
private _src;
|
|
41
|
+
private _shape;
|
|
42
|
+
private _color;
|
|
43
|
+
private _size;
|
|
44
|
+
private _primitive;
|
|
45
|
+
/** A `waica:` uri or project path to a `.glb` / `.gltf`; empty draws the primitive `shape`. */
|
|
46
|
+
get src(): string;
|
|
47
|
+
set src(value: string);
|
|
48
|
+
get shape(): ModelShape;
|
|
49
|
+
set shape(value: ModelShape);
|
|
50
|
+
/** `0xrrggbb` of a primitive. */
|
|
51
|
+
get color(): number;
|
|
52
|
+
set color(value: number);
|
|
53
|
+
/** Uniform scale of a primitive: the box side, sphere diameter or plane side in world units. */
|
|
54
|
+
get size(): number;
|
|
55
|
+
set size(value: number);
|
|
56
|
+
onReady(): void;
|
|
57
|
+
onDestroy(): void;
|
|
58
|
+
private build;
|
|
59
|
+
private buildPrimitive;
|
|
60
|
+
private rebuild;
|
|
61
|
+
/** Empties the root and disposes the primitive this Model created; a glTF's clone only leaves the graph. */
|
|
62
|
+
private clear;
|
|
63
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as THREE from 'three/webgpu';
|
|
2
|
+
import { Component } from '../component.js';
|
|
3
|
+
const SHAPES = ['box', 'sphere', 'plane'];
|
|
4
|
+
/** One unit of the shape: a box of side 1, a sphere of diameter 1, a plane of side 1 lying flat on the ground (normal up). */
|
|
5
|
+
function primitiveGeometry(shape) {
|
|
6
|
+
switch (shape) {
|
|
7
|
+
case 'sphere':
|
|
8
|
+
return new THREE.SphereGeometry(0.5, 32, 16);
|
|
9
|
+
case 'plane':
|
|
10
|
+
return new THREE.PlaneGeometry(1, 1).rotateX(-Math.PI / 2);
|
|
11
|
+
case 'box':
|
|
12
|
+
return new THREE.BoxGeometry(1, 1, 1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A 3D thing an entity draws (3D scenes, ADR 0027): a glTF/glb from `src`
|
|
17
|
+
* (a `waica:` uri or a project path, loaded once through `game.assets`) or a
|
|
18
|
+
* primitive `shape` of a `color` and a uniform `size`. With both, `src` wins.
|
|
19
|
+
* Its root hangs under the entity's node, so the entity's position, rotation
|
|
20
|
+
* and scale place it; the glTF keeps the materials it ships with, a
|
|
21
|
+
* primitive has a standard (lit) node material. `color` and `size` follow the
|
|
22
|
+
* inspector live; a new `src` or `shape` rebuilds the content. Destroying it
|
|
23
|
+
* removes the root and disposes only what it created — never the cached glTF.
|
|
24
|
+
* In a 2D scene it creates nothing (`validate_project` reports it).
|
|
25
|
+
*/
|
|
26
|
+
export class Model extends Component {
|
|
27
|
+
static componentName = 'Model';
|
|
28
|
+
static space = '3d';
|
|
29
|
+
static params = {
|
|
30
|
+
src: { label: 'Model file', kind: 'model' },
|
|
31
|
+
shape: { label: 'Shape', options: [...SHAPES] },
|
|
32
|
+
color: { label: 'Color', kind: 'color' },
|
|
33
|
+
size: { label: 'Size', min: 0.01, step: 0.1 },
|
|
34
|
+
};
|
|
35
|
+
static transient = ['root'];
|
|
36
|
+
/** What this Model draws, under the entity's node; null until it is ready. The Pointer ray-casts against it. */
|
|
37
|
+
root = null;
|
|
38
|
+
_src = '';
|
|
39
|
+
_shape = 'box';
|
|
40
|
+
_color = 0xffffff;
|
|
41
|
+
_size = 1;
|
|
42
|
+
_primitive = null;
|
|
43
|
+
/** A `waica:` uri or project path to a `.glb` / `.gltf`; empty draws the primitive `shape`. */
|
|
44
|
+
get src() {
|
|
45
|
+
return this._src;
|
|
46
|
+
}
|
|
47
|
+
set src(value) {
|
|
48
|
+
this._src = value;
|
|
49
|
+
this.rebuild();
|
|
50
|
+
}
|
|
51
|
+
get shape() {
|
|
52
|
+
return this._shape;
|
|
53
|
+
}
|
|
54
|
+
set shape(value) {
|
|
55
|
+
this._shape = SHAPES.includes(value) ? value : 'box';
|
|
56
|
+
this.rebuild();
|
|
57
|
+
}
|
|
58
|
+
/** `0xrrggbb` of a primitive. */
|
|
59
|
+
get color() {
|
|
60
|
+
return this._color;
|
|
61
|
+
}
|
|
62
|
+
set color(value) {
|
|
63
|
+
this._color = value;
|
|
64
|
+
this._primitive?.mesh.material.color.setHex(value);
|
|
65
|
+
}
|
|
66
|
+
/** Uniform scale of a primitive: the box side, sphere diameter or plane side in world units. */
|
|
67
|
+
get size() {
|
|
68
|
+
return this._size;
|
|
69
|
+
}
|
|
70
|
+
set size(value) {
|
|
71
|
+
this._size = value;
|
|
72
|
+
this._primitive?.mesh.scale.setScalar(value);
|
|
73
|
+
}
|
|
74
|
+
onReady() {
|
|
75
|
+
// Draws only in a 3D scene, like Sun and PointLight: 2.5D is a later block, and a lit-less mesh would come out black.
|
|
76
|
+
if (this.game.space !== '3d')
|
|
77
|
+
return;
|
|
78
|
+
this.root = new THREE.Group();
|
|
79
|
+
this.root.name = 'waica:model';
|
|
80
|
+
this.entity.node.add(this.root);
|
|
81
|
+
this.build();
|
|
82
|
+
}
|
|
83
|
+
onDestroy() {
|
|
84
|
+
this.clear();
|
|
85
|
+
this.root?.removeFromParent();
|
|
86
|
+
}
|
|
87
|
+
build() {
|
|
88
|
+
if (!this.root)
|
|
89
|
+
return;
|
|
90
|
+
if (this._src)
|
|
91
|
+
this.root.add(this.game.assets.model(this._src).root);
|
|
92
|
+
else
|
|
93
|
+
this.buildPrimitive(this.root);
|
|
94
|
+
}
|
|
95
|
+
buildPrimitive(root) {
|
|
96
|
+
const material = new THREE.MeshStandardNodeMaterial({ color: this._color });
|
|
97
|
+
const mesh = new THREE.Mesh(primitiveGeometry(this._shape), material);
|
|
98
|
+
mesh.scale.setScalar(this._size);
|
|
99
|
+
root.add(mesh);
|
|
100
|
+
this._primitive = { mesh };
|
|
101
|
+
}
|
|
102
|
+
rebuild() {
|
|
103
|
+
if (!this.root)
|
|
104
|
+
return;
|
|
105
|
+
this.clear();
|
|
106
|
+
this.build();
|
|
107
|
+
}
|
|
108
|
+
/** Empties the root and disposes the primitive this Model created; a glTF's clone only leaves the graph. */
|
|
109
|
+
clear() {
|
|
110
|
+
this.root?.clear();
|
|
111
|
+
if (!this._primitive)
|
|
112
|
+
return;
|
|
113
|
+
this._primitive.mesh.geometry.dispose();
|
|
114
|
+
this._primitive.mesh.material.dispose();
|
|
115
|
+
this._primitive = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component } from '../component.js';
|
|
1
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
2
2
|
import type { YSortBatchParticipant, YSortEntry } from '../render-sort.js';
|
|
3
3
|
export type ParticleVector = [number, number];
|
|
4
4
|
export type ParticleSpace = 'world' | 'local';
|
|
@@ -8,6 +8,7 @@ export type ParticleBlend = 'normal' | 'additive';
|
|
|
8
8
|
/** A fixed-capacity source of short-lived, batched 2D particles. */
|
|
9
9
|
export declare class ParticleEmitter extends Component implements YSortBatchParticipant {
|
|
10
10
|
static componentName: string;
|
|
11
|
+
static space: ComponentSpace;
|
|
11
12
|
static displayName: string;
|
|
12
13
|
static params: {
|
|
13
14
|
rate: {
|
|
@@ -5,6 +5,7 @@ import { setEmissive } from '../render-layers.js';
|
|
|
5
5
|
/** A fixed-capacity source of short-lived, batched 2D particles. */
|
|
6
6
|
export class ParticleEmitter extends Component {
|
|
7
7
|
static componentName = 'ParticleEmitter';
|
|
8
|
+
static space = '2d';
|
|
8
9
|
static displayName = 'Particle Emitter';
|
|
9
10
|
static params = {
|
|
10
11
|
rate: { label: 'Rate', min: 0 },
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as THREE from 'three/webgpu';
|
|
2
|
+
import { Component, type ComponentSpace } from '../component.js';
|
|
3
|
+
/**
|
|
4
|
+
* A point light in a 3D scene (ADR 0027, `CONTEXT.md` Point Light): it shines
|
|
5
|
+
* in every direction from the entity's position plus an offset (in the
|
|
6
|
+
* entity's local frame: it turns and scales with the entity, so a lantern's
|
|
7
|
+
* offset follows the object it hangs on), reaching
|
|
8
|
+
* `distance` world units (0 = without limit) and fading with `decay` (2 is
|
|
9
|
+
* physical). Not the 2D `Light`, which paints a light-map. No shadows. In a
|
|
10
|
+
* 2D scene it creates nothing; the three light lives under the entity's node
|
|
11
|
+
* and leaves with it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PointLight extends Component {
|
|
14
|
+
static componentName: string;
|
|
15
|
+
static space: ComponentSpace;
|
|
16
|
+
static displayName: string;
|
|
17
|
+
static params: {
|
|
18
|
+
color: {
|
|
19
|
+
label: string;
|
|
20
|
+
kind: "color";
|
|
21
|
+
};
|
|
22
|
+
intensity: {
|
|
23
|
+
label: string;
|
|
24
|
+
min: number;
|
|
25
|
+
step: number;
|
|
26
|
+
};
|
|
27
|
+
distance: {
|
|
28
|
+
label: string;
|
|
29
|
+
min: number;
|
|
30
|
+
step: number;
|
|
31
|
+
};
|
|
32
|
+
decay: {
|
|
33
|
+
label: string;
|
|
34
|
+
min: number;
|
|
35
|
+
step: number;
|
|
36
|
+
};
|
|
37
|
+
offsetX: {
|
|
38
|
+
label: string;
|
|
39
|
+
};
|
|
40
|
+
offsetY: {
|
|
41
|
+
label: string;
|
|
42
|
+
};
|
|
43
|
+
offsetZ: {
|
|
44
|
+
label: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
static transient: string[];
|
|
48
|
+
/** The three light, null in a 2D scene or before the component is ready. */
|
|
49
|
+
light: THREE.PointLight | null;
|
|
50
|
+
private _color;
|
|
51
|
+
private _intensity;
|
|
52
|
+
private _distance;
|
|
53
|
+
private _decay;
|
|
54
|
+
private _offsetX;
|
|
55
|
+
private _offsetY;
|
|
56
|
+
private _offsetZ;
|
|
57
|
+
get color(): number;
|
|
58
|
+
set color(value: number);
|
|
59
|
+
get intensity(): number;
|
|
60
|
+
set intensity(value: number);
|
|
61
|
+
/** World units the light reaches; 0 reaches without limit. */
|
|
62
|
+
get distance(): number;
|
|
63
|
+
set distance(value: number);
|
|
64
|
+
get decay(): number;
|
|
65
|
+
set decay(value: number);
|
|
66
|
+
get offsetX(): number;
|
|
67
|
+
set offsetX(value: number);
|
|
68
|
+
get offsetY(): number;
|
|
69
|
+
set offsetY(value: number);
|
|
70
|
+
get offsetZ(): number;
|
|
71
|
+
set offsetZ(value: number);
|
|
72
|
+
onReady(): void;
|
|
73
|
+
onDestroy(): void;
|
|
74
|
+
private place;
|
|
75
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as THREE from 'three/webgpu';
|
|
2
|
+
import { Component } from '../component.js';
|
|
3
|
+
/**
|
|
4
|
+
* A point light in a 3D scene (ADR 0027, `CONTEXT.md` Point Light): it shines
|
|
5
|
+
* in every direction from the entity's position plus an offset (in the
|
|
6
|
+
* entity's local frame: it turns and scales with the entity, so a lantern's
|
|
7
|
+
* offset follows the object it hangs on), reaching
|
|
8
|
+
* `distance` world units (0 = without limit) and fading with `decay` (2 is
|
|
9
|
+
* physical). Not the 2D `Light`, which paints a light-map. No shadows. In a
|
|
10
|
+
* 2D scene it creates nothing; the three light lives under the entity's node
|
|
11
|
+
* and leaves with it.
|
|
12
|
+
*/
|
|
13
|
+
export class PointLight extends Component {
|
|
14
|
+
static componentName = 'PointLight';
|
|
15
|
+
static space = '3d';
|
|
16
|
+
static displayName = 'Point light (3D)';
|
|
17
|
+
static params = {
|
|
18
|
+
color: { label: 'Color', kind: 'color' },
|
|
19
|
+
intensity: { label: 'Intensity', min: 0, step: 0.5 },
|
|
20
|
+
distance: { label: 'Distance (0 = unlimited)', min: 0, step: 0.5 },
|
|
21
|
+
decay: { label: 'Decay', min: 0, step: 0.1 },
|
|
22
|
+
offsetX: { label: 'x offset' },
|
|
23
|
+
offsetY: { label: 'y offset' },
|
|
24
|
+
offsetZ: { label: 'z offset' },
|
|
25
|
+
};
|
|
26
|
+
static transient = ['light'];
|
|
27
|
+
/** The three light, null in a 2D scene or before the component is ready. */
|
|
28
|
+
light = null;
|
|
29
|
+
_color = 0xffffff;
|
|
30
|
+
_intensity = 1;
|
|
31
|
+
_distance = 0;
|
|
32
|
+
_decay = 2;
|
|
33
|
+
_offsetX = 0;
|
|
34
|
+
_offsetY = 0;
|
|
35
|
+
_offsetZ = 0;
|
|
36
|
+
get color() {
|
|
37
|
+
return this._color;
|
|
38
|
+
}
|
|
39
|
+
set color(value) {
|
|
40
|
+
this._color = value;
|
|
41
|
+
this.light?.color.setHex(value);
|
|
42
|
+
}
|
|
43
|
+
get intensity() {
|
|
44
|
+
return this._intensity;
|
|
45
|
+
}
|
|
46
|
+
set intensity(value) {
|
|
47
|
+
this._intensity = value;
|
|
48
|
+
if (this.light)
|
|
49
|
+
this.light.intensity = value;
|
|
50
|
+
}
|
|
51
|
+
/** World units the light reaches; 0 reaches without limit. */
|
|
52
|
+
get distance() {
|
|
53
|
+
return this._distance;
|
|
54
|
+
}
|
|
55
|
+
set distance(value) {
|
|
56
|
+
this._distance = value;
|
|
57
|
+
if (this.light)
|
|
58
|
+
this.light.distance = value;
|
|
59
|
+
}
|
|
60
|
+
get decay() {
|
|
61
|
+
return this._decay;
|
|
62
|
+
}
|
|
63
|
+
set decay(value) {
|
|
64
|
+
this._decay = value;
|
|
65
|
+
if (this.light)
|
|
66
|
+
this.light.decay = value;
|
|
67
|
+
}
|
|
68
|
+
get offsetX() {
|
|
69
|
+
return this._offsetX;
|
|
70
|
+
}
|
|
71
|
+
set offsetX(value) {
|
|
72
|
+
this._offsetX = value;
|
|
73
|
+
this.place();
|
|
74
|
+
}
|
|
75
|
+
get offsetY() {
|
|
76
|
+
return this._offsetY;
|
|
77
|
+
}
|
|
78
|
+
set offsetY(value) {
|
|
79
|
+
this._offsetY = value;
|
|
80
|
+
this.place();
|
|
81
|
+
}
|
|
82
|
+
get offsetZ() {
|
|
83
|
+
return this._offsetZ;
|
|
84
|
+
}
|
|
85
|
+
set offsetZ(value) {
|
|
86
|
+
this._offsetZ = value;
|
|
87
|
+
this.place();
|
|
88
|
+
}
|
|
89
|
+
onReady() {
|
|
90
|
+
if (this.game.space !== '3d')
|
|
91
|
+
return;
|
|
92
|
+
this.light = new THREE.PointLight(this._color, this._intensity, this._distance, this._decay);
|
|
93
|
+
this.entity.node.add(this.light);
|
|
94
|
+
this.place();
|
|
95
|
+
}
|
|
96
|
+
onDestroy() {
|
|
97
|
+
this.light?.removeFromParent();
|
|
98
|
+
}
|
|
99
|
+
place() {
|
|
100
|
+
this.light?.position.set(this._offsetX, this._offsetY, this._offsetZ);
|
|
101
|
+
}
|
|
102
|
+
}
|