@kvyverse/world-runtime 0.1.0 → 0.4.2
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 +84 -59
- package/dist/{BallCollider-8ZrxReEd.js → BallCollider-3L5vOrcL.js} +2 -2
- package/dist/{CapsuleCollider-bynyf6Mc.js → CapsuleCollider-CBTsR-Ys.js} +2 -2
- package/dist/ChatModule-2tiWS_Yr.js +411 -0
- package/dist/{Collider-4_rCTHVA.js → Collider-CPUCG3RA.js} +2 -2
- package/dist/{ConeCollider-DtRZmgK8.js → ConeCollider-C3XU3Y9X.js} +2 -2
- package/dist/{ConvexMeshCollider-BSmDM4o3.js → ConvexMeshCollider-DzNV4HTO.js} +1 -1
- package/dist/{CuboidCollider-CJvq7--s.js → CuboidCollider-Dp1DZoFM.js} +1 -1
- package/dist/{CylinderCollider-CQPSh4tu.js → CylinderCollider-C0h_nhB5.js} +2 -2
- package/dist/{FpsCameraController-BE2EirRj.js → FpsCameraController-2GNWJM5D.js} +1 -1
- package/dist/RapierDebugRenderer-BQy_m-3C.js +73 -0
- package/dist/{RapierFpsPlayerController-VsNfQl6v.js → RapierFpsPlayerController-DthD8dw9.js} +5 -22
- package/dist/{RapierPhysics-C_3b7QOn.js → RapierPhysics-CU6X--c7.js} +34 -15
- package/dist/{Rigidbody-b7QNF4ev.js → Rigidbody-DLhN8ddv.js} +12 -1
- package/dist/World.d.ts +4 -2
- package/dist/WorldRuntime.d.ts +15 -5
- package/dist/addons/AddonsRuntime.d.ts +37 -0
- package/dist/addons/builtin-libs.d.ts +20 -0
- package/dist/addons/lib-registry.d.ts +60 -0
- package/dist/addons/required-libs.d.ts +9 -0
- package/dist/addons/types.d.ts +28 -0
- package/dist/behaviours/physics/BallCollider.d.ts +1 -1
- package/dist/behaviours/physics/CapsuleCollider.d.ts +1 -1
- package/dist/behaviours/physics/ConeCollider.d.ts +1 -1
- package/dist/behaviours/physics/ConvexMeshCollider.d.ts +1 -1
- package/dist/behaviours/physics/CuboidCollider.d.ts +1 -1
- package/dist/behaviours/physics/CylinderCollider.d.ts +1 -1
- package/dist/behaviours/physics/HalfspaceCollider.d.ts +1 -1
- package/dist/behaviours/physics/_required-patch.d.ts +10 -8
- package/dist/behaviours/registry.d.ts +9 -2
- package/dist/chat.module-descriptor-BTsep-Kq.js +107 -0
- package/dist/{get-scale-from-obj-QKv3Fig5.js → get-scale-from-obj-B7JlVPni.js} +1 -1
- package/dist/index.d.ts +26 -14
- package/dist/index.js +594 -202
- package/dist/lib-registry-D1VyVPBg.js +142 -0
- package/dist/modules/HtmlHudModule.d.ts +5 -1
- package/dist/modules/InputSystemModule.d.ts +14 -32
- package/dist/modules/chat/ChatDom.d.ts +100 -0
- package/dist/modules/chat/ChatModule.d.ts +36 -0
- package/dist/modules/chat/chat.module-descriptor.d.ts +43 -0
- package/dist/modules/contracts/addons.module-api.d.ts +15 -0
- package/dist/modules/contracts/chat.module-api.d.ts +52 -0
- package/dist/modules/contracts/controls.module-api.d.ts +58 -0
- package/dist/modules/contracts/html.module-api.d.ts +22 -2
- package/dist/modules/contracts/input.module-api.d.ts +11 -11
- package/dist/modules/contracts/module-events.d.ts +17 -0
- package/dist/modules/contracts/rapier.module-api.d.ts +13 -1
- package/dist/modules/controls/ControlsModule.d.ts +45 -0
- package/dist/modules/controls/KeyboardControlsDriver.d.ts +12 -0
- package/dist/modules/index.d.ts +30 -3
- package/dist/modules/optional-module-descriptor.d.ts +39 -0
- package/dist/modules/optional-modules.d.ts +11 -0
- package/dist/modules/physics/RapierDebugRenderer.d.ts +19 -0
- package/dist/{behaviours/physics/rapier-addon-core → modules/physics}/RapierPhysics.d.ts +13 -3
- package/dist/modules/physics/physics.module-descriptor.d.ts +16 -0
- package/dist/modules/registry.d.ts +7 -3
- package/dist/rendering/SceneBloom.d.ts +1 -1
- package/dist/rendering/renderer-apply.d.ts +1 -1
- package/dist/{settings → rendering}/types.d.ts +1 -12
- package/dist/types.d.ts +10 -3
- package/dist/utils/lazy.d.ts +7 -0
- package/dist/version.gen.d.ts +1 -1
- package/dist/world-stores.d.ts +39 -0
- package/package.json +10 -1
- package/dist/RapierDebugRenderer-sURZDLP4.js +0 -55
- package/dist/behaviours/physics/rapier-addon-core/RapierDebugRenderer.d.ts +0 -17
- package/dist/modules/contracts/rapierDebug.module-api.d.ts +0 -5
- package/dist/rolldown-runtime-D7D4PA-g.js +0 -13
- package/dist/settings/AddonsRuntime.d.ts +0 -19
- package/dist/settings/lib-loaders.d.ts +0 -7
- package/dist/settings/lib-registry.d.ts +0 -24
- package/dist/settings/module-registry.d.ts +0 -25
- /package/dist/{settings → addons}/externals.d.ts +0 -0
- /package/dist/behaviours/physics/{rapier-addon-core/Collider.d.ts → Collider.d.ts} +0 -0
- /package/dist/behaviours/physics/{rapier-addon-core/get-scale-from-obj.d.ts → get-scale-from-obj.d.ts} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ContextModule } from "three-start";
|
|
2
|
+
import * as THREE from "three/webgpu";
|
|
3
|
+
import type { ControlsDriver, ControlsEvents, ControlsModuleApi, ControlsSource } from "../contracts/controls.module-api";
|
|
4
|
+
/**
|
|
5
|
+
* The player's movement intent — what they want to do, whatever the hardware is.
|
|
6
|
+
* Input sources register as drivers (`addDriver`); the module polls them once a
|
|
7
|
+
* frame and decides which one is driving. Details — `./README.md`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ControlsModule extends ContextModule<ControlsEvents> implements ControlsModuleApi {
|
|
10
|
+
/** x — strafe, y — forward. Reused vector: copy it before storing. */
|
|
11
|
+
readonly move: THREE.Vector2;
|
|
12
|
+
private readonly _drivers;
|
|
13
|
+
private readonly _state;
|
|
14
|
+
private _keyboard;
|
|
15
|
+
private _active;
|
|
16
|
+
private _source;
|
|
17
|
+
private _force;
|
|
18
|
+
private _run;
|
|
19
|
+
private _jump;
|
|
20
|
+
onAwake(): void;
|
|
21
|
+
/** Speed multiplier: 1 is a normal walk, higher means a stronger stick tilt. */
|
|
22
|
+
get force(): number;
|
|
23
|
+
/** Run modifier: shift, a stick pushed past its ring, a UI button. */
|
|
24
|
+
get run(): boolean;
|
|
25
|
+
/** Kind of the device driving right now. */
|
|
26
|
+
get source(): ControlsSource;
|
|
27
|
+
get drivers(): readonly ControlsDriver[];
|
|
28
|
+
/** The built-in keyboard driver — detach it with `removeDriver`. */
|
|
29
|
+
get keyboard(): ControlsDriver;
|
|
30
|
+
addDriver(driver: ControlsDriver): () => void;
|
|
31
|
+
removeDriver(driver: ControlsDriver): void;
|
|
32
|
+
jump(): void;
|
|
33
|
+
onUpdate(): void;
|
|
34
|
+
/**
|
|
35
|
+
* The active driver keeps the channel while it produces input — otherwise the
|
|
36
|
+
* keyboard and a stick would steal control from each other every frame. Once it
|
|
37
|
+
* goes quiet, the first driver with input takes over. The state is left filled
|
|
38
|
+
* by the winner, so nobody is read twice.
|
|
39
|
+
*/
|
|
40
|
+
private _readActiveDriver;
|
|
41
|
+
private _readDriver;
|
|
42
|
+
private _resetState;
|
|
43
|
+
private _apply;
|
|
44
|
+
}
|
|
45
|
+
export default ControlsModule;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InputSystemModule } from "../InputSystemModule";
|
|
2
|
+
import type { ControlsDriver, ControlsState } from "../contracts/controls.module-api";
|
|
3
|
+
/**
|
|
4
|
+
* Keyboard driver for `controls`: WASD/arrows, shift to run, Space to jump.
|
|
5
|
+
* Reads key state from the `input` module and binds no listeners of its own.
|
|
6
|
+
*/
|
|
7
|
+
export declare class KeyboardControlsDriver implements ControlsDriver {
|
|
8
|
+
private readonly _input;
|
|
9
|
+
readonly kind = "keyboard";
|
|
10
|
+
constructor(_input: InputSystemModule);
|
|
11
|
+
read(state: ControlsState): void;
|
|
12
|
+
}
|
package/dist/modules/index.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { ControlsModule } from "./controls/ControlsModule";
|
|
1
2
|
import { EnvModule } from "./EnvModule";
|
|
2
3
|
import { HtmlHudModule } from "./HtmlHudModule";
|
|
3
4
|
import { InputSystemModule } from "./InputSystemModule";
|
|
4
5
|
import { SoundsModule } from "./SoundsModule";
|
|
5
6
|
import { UtilsModule } from "./UtilsModule";
|
|
7
|
+
import type { AddonsRuntime } from "../addons/AddonsRuntime";
|
|
8
|
+
import type { AddonsConfig } from "../addons/types";
|
|
6
9
|
import type { EnvMode } from "./EnvModule";
|
|
10
|
+
import type { KvyverseModules } from "./registry";
|
|
11
|
+
export type { ChatModule } from "./chat/ChatModule";
|
|
12
|
+
export type { ChatDom, ChatDomOptions } from "./chat/ChatDom";
|
|
13
|
+
export { ControlsModule } from "./controls/ControlsModule";
|
|
7
14
|
export { EnvModule } from "./EnvModule";
|
|
8
15
|
export { HtmlHudModule } from "./HtmlHudModule";
|
|
9
16
|
export { InputSystemModule } from "./InputSystemModule";
|
|
@@ -11,12 +18,32 @@ export { SoundsModule } from "./SoundsModule";
|
|
|
11
18
|
export { UtilsModule } from "./UtilsModule";
|
|
12
19
|
export { isMobileDevice } from "./is-mobile-device";
|
|
13
20
|
export type { EnvMode } from "./EnvModule";
|
|
14
|
-
|
|
21
|
+
/** Modules every world has — no toggle for them. */
|
|
22
|
+
export type CoreWorldModules = {
|
|
23
|
+
addons: AddonsRuntime;
|
|
24
|
+
controls: ControlsModule;
|
|
15
25
|
env: EnvModule;
|
|
16
26
|
html: HtmlHudModule;
|
|
17
27
|
input: InputSystemModule;
|
|
18
28
|
sounds: SoundsModule;
|
|
19
29
|
utils: UtilsModule;
|
|
20
30
|
};
|
|
21
|
-
/**
|
|
22
|
-
export
|
|
31
|
+
/** @deprecated kept for compatibility; see `CoreWorldModules`. */
|
|
32
|
+
export type WorldModules = CoreWorldModules;
|
|
33
|
+
export interface CreateWorldModulesOptions {
|
|
34
|
+
/** The world's external dependencies, already loaded (libs, externals, rapier). */
|
|
35
|
+
addons: AddonsRuntime;
|
|
36
|
+
/** `settings.addons.json → modules`: which pluggable modules are on, and how. */
|
|
37
|
+
modules?: AddonsConfig["modules"];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Assembles the world's ctx modules: core ones always, pluggable ones per config.
|
|
41
|
+
* Pluggable classes are pulled dynamically, so a disabled module never reaches
|
|
42
|
+
* the bundle. Call strictly before `start()` and with addons already loaded: the
|
|
43
|
+
* physics module takes rapier from `ctx.modules.addons`.
|
|
44
|
+
*
|
|
45
|
+
* A module the scene needs without a line in the config (physics when a physics
|
|
46
|
+
* behaviour is present) is added separately — through the behaviour's
|
|
47
|
+
* `meta.requiredPatch`, with the same descriptor and idempotently.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createWorldModules(mode: EnvMode | undefined, options: CreateWorldModulesOptions): Promise<CoreWorldModules & Partial<KvyverseModules>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ContextModule } from "three-start";
|
|
2
|
+
import type { LibId } from "../addons/lib-registry";
|
|
3
|
+
/**
|
|
4
|
+
* Keys of the pluggable modules — the same keys as in
|
|
5
|
+
* `settings.addons.json → modules`. Core modules (`addons`/`env`/`html`/`input`/
|
|
6
|
+
* `controls`/`sounds`/`utils`) are not here: every world has them, with no toggle.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum OptionalModuleId {
|
|
9
|
+
Physics = "physics",
|
|
10
|
+
Chat = "chat"
|
|
11
|
+
}
|
|
12
|
+
export declare const OPTIONAL_MODULE_IDS: OptionalModuleId[];
|
|
13
|
+
/** A JSON Schema (draft-07) fragment; structurally the platform's `JSONSchema`. */
|
|
14
|
+
export type ModuleJsonSchema = Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Describes a pluggable module: how to read its value from the world config, how
|
|
17
|
+
* to create it and how to validate the config in the code editor. Defaults (is
|
|
18
|
+
* it on, in which mode) live in `normalize` — the registry knows nothing of them.
|
|
19
|
+
*
|
|
20
|
+
* Rule: `create` pulls the module class through a **dynamic** import, otherwise a
|
|
21
|
+
* disabled module still ends up in the bundle.
|
|
22
|
+
*/
|
|
23
|
+
export interface OptionalModuleDescriptor<TConfig = unknown> {
|
|
24
|
+
id: OptionalModuleId;
|
|
25
|
+
/** Config value → normalized config; `null` means the module is off. */
|
|
26
|
+
normalize: (raw: unknown) => TConfig | null;
|
|
27
|
+
/** Config for an on-demand enable (a behaviour pulled the module in without config). */
|
|
28
|
+
defaultConfig: () => TConfig;
|
|
29
|
+
/** The module class is pulled here — a disabled module never reaches the bundle. */
|
|
30
|
+
create: (config: TConfig) => Promise<ContextModule>;
|
|
31
|
+
/** Libs the module cannot work without: enabling it loads them (physics → rapier). */
|
|
32
|
+
requiredLibs?: LibId[];
|
|
33
|
+
/**
|
|
34
|
+
* JSON Schema fragment for `modules.<id>`: the platform assembles the
|
|
35
|
+
* `settings.addons.json` schema from these, so module keys never drift from the
|
|
36
|
+
* registry. The type is deliberately wide — the package knows nothing of Monaco.
|
|
37
|
+
*/
|
|
38
|
+
schema: ModuleJsonSchema;
|
|
39
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { OptionalModuleDescriptor, OptionalModuleId } from "./optional-module-descriptor";
|
|
2
|
+
/**
|
|
3
|
+
* Table of contents for the world's pluggable modules: what can be enabled from
|
|
4
|
+
* `settings.addons.json → modules`. The descriptors themselves live next to
|
|
5
|
+
* their module code; this is only the list.
|
|
6
|
+
*
|
|
7
|
+
* Add a descriptor here and the module shows up both in the runtime and in the
|
|
8
|
+
* config's JSON schema (the platform builds it from `descriptor.schema`).
|
|
9
|
+
*/
|
|
10
|
+
export declare const OPTIONAL_MODULES: ReadonlyArray<OptionalModuleDescriptor<any>>;
|
|
11
|
+
export declare function getOptionalModuleDescriptor(id: OptionalModuleId): OptionalModuleDescriptor<any>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RapierPhysics } from "./RapierPhysics";
|
|
2
|
+
import type { ThreeContext } from "three-start";
|
|
3
|
+
/**
|
|
4
|
+
* Draws rapier colliders as lines. Not a ctx module: it lives inside
|
|
5
|
+
* `RapierPhysics` (`enableDebug`/`disableDebug`) and is pulled dynamically —
|
|
6
|
+
* worlds without debug never load this code.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://github.com/vladkrutenyuk/three-kvy-core/blob/main/src/addons/RapierDebugRenderer.ts | Source}
|
|
9
|
+
*/
|
|
10
|
+
export declare class RapierDebugRenderer {
|
|
11
|
+
private readonly _ctx;
|
|
12
|
+
private readonly _rapier;
|
|
13
|
+
private _clear;
|
|
14
|
+
constructor(ctx: ThreeContext, rapier: RapierPhysics);
|
|
15
|
+
get enabled(): boolean;
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
}
|
|
19
|
+
export default RapierDebugRenderer;
|
|
@@ -2,7 +2,7 @@ import { ContextModule } from "three-start";
|
|
|
2
2
|
import type { ThreeContext } from "three-start";
|
|
3
3
|
import type * as THREE from "three/webgpu";
|
|
4
4
|
import type * as RAPIER from "@dimforge/rapier3d-compat";
|
|
5
|
-
import type { RapierModuleApi } from "
|
|
5
|
+
import type { RapierModuleApi } from "../contracts/rapier.module-api";
|
|
6
6
|
export type ModulesWithRapierPhysics = {
|
|
7
7
|
rapier: RapierPhysics;
|
|
8
8
|
};
|
|
@@ -18,8 +18,17 @@ export declare class RapierPhysics extends ContextModule<{
|
|
|
18
18
|
/** @default "vary" */
|
|
19
19
|
timeStep: RapierPhysicsOptions["timeStep"];
|
|
20
20
|
private _steppingState;
|
|
21
|
-
|
|
21
|
+
private _debug;
|
|
22
|
+
private readonly _debugOnStart;
|
|
23
|
+
private readonly _gravity;
|
|
24
|
+
constructor(options?: Partial<RapierPhysicsOptions>);
|
|
25
|
+
onAwake(): void;
|
|
22
26
|
onStart(): void;
|
|
27
|
+
/** Whether collider outlines are being drawn right now. */
|
|
28
|
+
get isDebugEnabled(): boolean;
|
|
29
|
+
/** Turn on collider debug drawing; the renderer is fetched on demand. */
|
|
30
|
+
enableDebug(): Promise<void>;
|
|
31
|
+
disableDebug(): void;
|
|
23
32
|
/** three-start ContextModule has no onDestroy; teardown is explicit. */
|
|
24
33
|
dispose(): void;
|
|
25
34
|
private update;
|
|
@@ -124,7 +133,8 @@ export interface RapierPhysicsOptions {
|
|
|
124
133
|
**/
|
|
125
134
|
interpolate: boolean;
|
|
126
135
|
/**
|
|
127
|
-
*
|
|
136
|
+
* Start with the collider debug renderer on. The renderer itself is loaded
|
|
137
|
+
* on demand (`enableDebug()`), so worlds without debug never fetch it.
|
|
128
138
|
* @defaultValue false
|
|
129
139
|
*/
|
|
130
140
|
debug: boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { OptionalModuleDescriptor } from "../optional-module-descriptor";
|
|
2
|
+
export type PhysicsEngine = "rapier";
|
|
3
|
+
/** `modules.physics`: off | engine shorthand | an object with options. */
|
|
4
|
+
export type PhysicsConfig = false | PhysicsEngine | {
|
|
5
|
+
engine: PhysicsEngine;
|
|
6
|
+
debug?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export interface NormalizedPhysics {
|
|
9
|
+
engine: PhysicsEngine;
|
|
10
|
+
/** Turn collider debug drawing on right away (the renderer loads on demand). */
|
|
11
|
+
debug: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const PHYSICS_ENGINES: readonly PhysicsEngine[];
|
|
14
|
+
/** Physics defaults: the rapier engine, debug off. */
|
|
15
|
+
export declare function normalizePhysics(value: PhysicsConfig | undefined): NormalizedPhysics | null;
|
|
16
|
+
export declare const physicsModuleDescriptor: OptionalModuleDescriptor<NormalizedPhysics>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { RapierPhysics } from "./physics/RapierPhysics";
|
|
2
|
+
import type { AddonsRuntime } from "../addons/AddonsRuntime";
|
|
3
|
+
import type { ChatModule } from "./chat/ChatModule";
|
|
4
|
+
import type { ControlsModule } from "./controls/ControlsModule";
|
|
3
5
|
import type { EnvModule } from "./EnvModule";
|
|
4
6
|
import type { HtmlHudModule } from "./HtmlHudModule";
|
|
5
7
|
import type { InputSystemModule } from "./InputSystemModule";
|
|
@@ -15,13 +17,15 @@ import type { UtilsModule } from "./UtilsModule";
|
|
|
15
17
|
* here may be missing in a particular ctx (e.g. editor-ctx registers only `input`).
|
|
16
18
|
*/
|
|
17
19
|
export interface KvyverseModules {
|
|
20
|
+
addons: AddonsRuntime;
|
|
18
21
|
input: InputSystemModule;
|
|
22
|
+
chat: ChatModule;
|
|
23
|
+
controls: ControlsModule;
|
|
19
24
|
env: EnvModule;
|
|
20
25
|
html: HtmlHudModule;
|
|
21
26
|
sounds: SoundsModule;
|
|
22
27
|
utils: UtilsModule;
|
|
23
28
|
rapier: RapierPhysics;
|
|
24
|
-
rapierDebug: RapierDebugRenderer;
|
|
25
29
|
}
|
|
26
30
|
declare module "three-start" {
|
|
27
31
|
interface ThreeStartRegister {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type BloomNode from "three/addons/tsl/display/BloomNode.js";
|
|
2
2
|
import type * as THREE from "three/webgpu";
|
|
3
3
|
import type { BloomModeName } from "./renderer-options";
|
|
4
|
-
import type { BloomConfig } from "
|
|
4
|
+
import type { BloomConfig } from "./types";
|
|
5
5
|
/**
|
|
6
6
|
* Enables MRT `{ output, emissive }` on the scenePass. Idempotent. IMPORTANT:
|
|
7
7
|
* MRT is part of the WebGPU pipelines' attachment state; enable it either before
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as THREE from "three/webgpu";
|
|
2
|
-
import type { RendererConfig } from "
|
|
2
|
+
import type { RendererConfig } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Applies the runtime part of `RendererConfig` to an already created WebGPURenderer
|
|
5
5
|
* (shadowMap, toneMapping, pixelRatio). Used by game (once on load) and editor
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { LibId } from "./lib-registry";
|
|
3
|
-
import type { PhysicsConfig } from "./module-registry";
|
|
4
|
-
import type { BloomModeName, ShadowMapTypeName, ToneMappingName } from "../rendering/renderer-options";
|
|
5
|
-
/** `settings.addons.json` — pluggable modules, built-in libs, external scripts. */
|
|
6
|
-
export interface AddonsConfig {
|
|
7
|
-
modules?: {
|
|
8
|
-
physics?: PhysicsConfig;
|
|
9
|
-
};
|
|
10
|
-
libs?: Partial<Record<LibId, boolean>>;
|
|
11
|
-
externals?: ExternalDescriptor[];
|
|
12
|
-
}
|
|
1
|
+
import type { BloomModeName, ShadowMapTypeName, ToneMappingName } from "./renderer-options";
|
|
13
2
|
/** Subset of `WebGPURendererParameters` configurable via the config. */
|
|
14
3
|
export interface RendererParams {
|
|
15
4
|
antialias?: boolean;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Object3DBehaviourConstructor } from "three-start";
|
|
2
|
-
import type { AddonsConfig,
|
|
2
|
+
import type { AddonsConfig, WorldImports } from "./addons/types";
|
|
3
|
+
import type { RendererConfig } from "./rendering/types";
|
|
3
4
|
import type * as THREE from "three/webgpu";
|
|
4
5
|
/** World assets: asset path in the project (`/Folder/name.ext`) → URL. */
|
|
5
6
|
export type AssetUrlTable = Record<string, string>;
|
|
@@ -22,8 +23,8 @@ export interface WorldLoadProgress {
|
|
|
22
23
|
* scripts and behaviours. The only object the world hooks receive.
|
|
23
24
|
*/
|
|
24
25
|
export interface RuntimeApi {
|
|
25
|
-
/** Asset URL by
|
|
26
|
-
getUrl: (
|
|
26
|
+
/** Asset URL by project path or by a resource returned by `require`. */
|
|
27
|
+
getUrl: (source: string | object) => string;
|
|
27
28
|
/** `require` value by asset path or addon key. */
|
|
28
29
|
require: (key: string) => unknown;
|
|
29
30
|
/** Built-in behaviour class by uuid (preloaded by bootstrap). */
|
|
@@ -51,6 +52,12 @@ export interface WorldDefinition<TAssets = unknown> {
|
|
|
51
52
|
renderer?: RendererConfig;
|
|
52
53
|
/** `settings.addons.json`: built-in libs and external scripts for `require`. */
|
|
53
54
|
addons?: AddonsConfig;
|
|
55
|
+
/**
|
|
56
|
+
* How to import the optional packages this world uses (rapier, built-in
|
|
57
|
+
* libs). The build emits only what the world needs, so your bundler never
|
|
58
|
+
* has to resolve a package you did not install.
|
|
59
|
+
*/
|
|
60
|
+
imports?: WorldImports;
|
|
54
61
|
/** User scripts keyed by asset paths — same keys as `require`. */
|
|
55
62
|
scripts?: ScriptTable;
|
|
56
63
|
/** Path of the world entry script (`main.ts`). */
|
package/dist/utils/lazy.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object that forwards every access to `resolve()`. For script globals that are
|
|
3
|
+
* shortcuts into something created later (`modules` → `ctx.modules`): the script
|
|
4
|
+
* bag is destructured eagerly, so a plain reference or a getter would be read
|
|
5
|
+
* before the target exists.
|
|
6
|
+
*/
|
|
7
|
+
export declare function lazyProxy<T extends object>(resolve: () => T): T;
|
|
1
8
|
/** Lazy cached value: the factory is called once on the first `get()`. */
|
|
2
9
|
export declare function lazy<T>(factory: () => T): {
|
|
3
10
|
get: () => T;
|
package/dist/version.gen.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const RUNTIME_VERSION = "0.
|
|
1
|
+
export declare const RUNTIME_VERSION = "0.4.2";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single reactive value of `world.stores`. Narrow facade over a nanostores
|
|
3
|
+
* atom: scripts see exactly these four methods.
|
|
4
|
+
*/
|
|
5
|
+
export interface WorldStore<T> {
|
|
6
|
+
get: () => T | undefined;
|
|
7
|
+
set: (value: T | undefined) => void;
|
|
8
|
+
/** Fires on every change; returns unsubscribe. */
|
|
9
|
+
listen: (listener: (value: T | undefined) => void) => () => void;
|
|
10
|
+
/** Same as `listen`, but also fires immediately with the current value. */
|
|
11
|
+
subscribe: (listener: (value: T | undefined) => void) => () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Shared reactive key-value state of a world (`world.stores` in scripts) — the
|
|
15
|
+
* state counterpart of the `world.events` bus. Stores are created lazily on
|
|
16
|
+
* first touch; `undefined` means "no value", so `delete`/`clear` only reset
|
|
17
|
+
* values and never invalidate a reference taken from `of()`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class WorldStores {
|
|
20
|
+
private readonly _stores;
|
|
21
|
+
/** The store behind a key, created on first touch. */
|
|
22
|
+
of<T = unknown>(key: string): WorldStore<T>;
|
|
23
|
+
get<T = unknown>(key: string): T | undefined;
|
|
24
|
+
set<T = unknown>(key: string, value: T | undefined): void;
|
|
25
|
+
/** Subscribe to a key; returns unsubscribe. Not called with the current value. */
|
|
26
|
+
listen<T = unknown>(key: string, listener: (value: T | undefined) => void): () => void;
|
|
27
|
+
/** Same as `listen`, but also fires immediately with the current value. */
|
|
28
|
+
subscribe<T = unknown>(key: string, listener: (value: T | undefined) => void): () => void;
|
|
29
|
+
/** A value has been written to the key and not deleted since. */
|
|
30
|
+
has(key: string): boolean;
|
|
31
|
+
/** Keys that currently hold a value. */
|
|
32
|
+
keys(): string[];
|
|
33
|
+
/** Plain object with all current values — for debugging and saves. */
|
|
34
|
+
snapshot(): Record<string, unknown>;
|
|
35
|
+
/** Resets the key to `undefined`; listeners are notified. */
|
|
36
|
+
delete(key: string): void;
|
|
37
|
+
/** Resets every key; listeners are notified. */
|
|
38
|
+
clear(): void;
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kvyverse/world-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Runtime for worlds exported from the Kvyverse platform for self-hosting",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"author": "Vladislav Kruteniuk",
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"animejs": "^4.5.0",
|
|
36
36
|
"eventemitter3": "^5.0.1",
|
|
37
37
|
"howler": "^2.2.4",
|
|
38
|
+
"nanostores": "^1.3.0",
|
|
39
|
+
"nipplejs": "^0.10.2",
|
|
40
|
+
"stats.js": "^0.17.0",
|
|
38
41
|
"three": "^0.184.0",
|
|
39
42
|
"three-start": "^0.1.2",
|
|
40
43
|
"vanjs-core": "^1.6.0"
|
|
@@ -48,6 +51,12 @@
|
|
|
48
51
|
},
|
|
49
52
|
"animejs": {
|
|
50
53
|
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"nipplejs": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"stats.js": {
|
|
59
|
+
"optional": true
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
62
|
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { t as RapierPhysics } from "./RapierPhysics-C_3b7QOn.js";
|
|
2
|
-
import * as THREE from "three/webgpu";
|
|
3
|
-
import { ContextModule } from "three-start";
|
|
4
|
-
//#region packages/world-runtime/src/behaviours/physics/rapier-addon-core/RapierDebugRenderer.ts
|
|
5
|
-
/**
|
|
6
|
-
* @see {@link https://github.com/vladkrutenyuk/three-kvy-core/blob/main/src/addons/RapierDebugRenderer.ts | Source}
|
|
7
|
-
*/
|
|
8
|
-
var RapierDebugRenderer = class extends ContextModule {
|
|
9
|
-
_lines;
|
|
10
|
-
get enabled() {
|
|
11
|
-
return this._enabled;
|
|
12
|
-
}
|
|
13
|
-
set enabled(value) {
|
|
14
|
-
const lines = this._lines;
|
|
15
|
-
if (lines) lines.visible = value;
|
|
16
|
-
this._enabled = value;
|
|
17
|
-
}
|
|
18
|
-
_enabled = true;
|
|
19
|
-
_clear;
|
|
20
|
-
_inited = false;
|
|
21
|
-
/** three-start ContextModule has no onDestroy; teardown is explicit. */
|
|
22
|
-
dispose() {
|
|
23
|
-
this._clear?.();
|
|
24
|
-
}
|
|
25
|
-
init() {
|
|
26
|
-
if (this._inited) return;
|
|
27
|
-
this._inited = true;
|
|
28
|
-
const ctx = this.ctx;
|
|
29
|
-
const rapier = RapierPhysics.findInCtx(ctx);
|
|
30
|
-
if (!rapier) return;
|
|
31
|
-
const lines = new THREE.LineSegments(new THREE.BufferGeometry(), new THREE.LineBasicMaterial({
|
|
32
|
-
color: 16777215,
|
|
33
|
-
vertexColors: true
|
|
34
|
-
}));
|
|
35
|
-
lines.frustumCulled = false;
|
|
36
|
-
lines.visible = this._enabled;
|
|
37
|
-
ctx.scene.add(lines);
|
|
38
|
-
const draw = () => {
|
|
39
|
-
const { vertices, colors } = rapier.world.debugRender();
|
|
40
|
-
lines.geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
|
|
41
|
-
lines.geometry.setAttribute("color", new THREE.BufferAttribute(colors, 4));
|
|
42
|
-
lines.visible = true;
|
|
43
|
-
};
|
|
44
|
-
rapier.on("stepafter", draw);
|
|
45
|
-
this._clear = () => {
|
|
46
|
-
this._lines = void 0;
|
|
47
|
-
lines.removeFromParent();
|
|
48
|
-
lines.geometry.dispose();
|
|
49
|
-
lines.material.dispose();
|
|
50
|
-
rapier.off("stepafter", draw);
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
//#endregion
|
|
55
|
-
export { RapierDebugRenderer, RapierDebugRenderer as default };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ContextModule } from "three-start";
|
|
2
|
-
import type { RapierDebugModuleApi } from "../../../modules/contracts/rapierDebug.module-api";
|
|
3
|
-
/**
|
|
4
|
-
* @see {@link https://github.com/vladkrutenyuk/three-kvy-core/blob/main/src/addons/RapierDebugRenderer.ts | Source}
|
|
5
|
-
*/
|
|
6
|
-
export declare class RapierDebugRenderer extends ContextModule implements RapierDebugModuleApi {
|
|
7
|
-
private _lines?;
|
|
8
|
-
get enabled(): boolean;
|
|
9
|
-
set enabled(value: boolean);
|
|
10
|
-
private _enabled;
|
|
11
|
-
private _clear?;
|
|
12
|
-
private _inited;
|
|
13
|
-
/** three-start ContextModule has no onDestroy; teardown is explicit. */
|
|
14
|
-
dispose(): void;
|
|
15
|
-
init(): void;
|
|
16
|
-
}
|
|
17
|
-
export default RapierDebugRenderer;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll as t };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AddonsConfig } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Runtime loading of addons (game-only): enabled built-in libs + external
|
|
4
|
-
* scripts (externals). Exposes them to user scripts via `resolve(key)`
|
|
5
|
-
* (used in `ScriptsRuntime.require`). Replaces the old
|
|
6
|
-
* `GameLoader.loadExternalsAsync` / `getExternalLib`.
|
|
7
|
-
*/
|
|
8
|
-
export declare class AddonsRuntime {
|
|
9
|
-
/** libs — by requireKey (`@tweenjs/tween.js`), externals — by accessor (`Tone`). */
|
|
10
|
-
private readonly _byKey;
|
|
11
|
-
private readonly _scriptTags;
|
|
12
|
-
load(addons: AddonsConfig): Promise<void>;
|
|
13
|
-
/** Resolves a require key: enabled lib or external accessor; undefined otherwise. */
|
|
14
|
-
resolve(key: string): unknown;
|
|
15
|
-
private _loadLibs;
|
|
16
|
-
private _loadExternals;
|
|
17
|
-
private _mountScript;
|
|
18
|
-
dispose(): void;
|
|
19
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { LibId } from "./lib-registry";
|
|
2
|
-
/**
|
|
3
|
-
* Dynamic loaders of built-in libs (game-only). Key — `LibId` from the registry;
|
|
4
|
-
* the value resolves for the user via `require("<requireKey>")`. Imports are lazy —
|
|
5
|
-
* bundled only when the lib is enabled in `settings.addons.json`.
|
|
6
|
-
*/
|
|
7
|
-
export declare const LIB_LOADERS: Record<LibId, () => Promise<unknown>>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry of built-in libraries enabled via `settings.addons.json → libs`.
|
|
3
|
-
*
|
|
4
|
-
* Separates two keys: `id` (short config key under `libs`) and `requireKey`
|
|
5
|
-
* (what the user writes in `require(...)` in scripts). Single source for:
|
|
6
|
-
* - game: dynamic loading (`lib-loaders`),
|
|
7
|
-
* - editor: JSON schema (`libs` props) + require typings (`AddonsRequireTypings`).
|
|
8
|
-
*
|
|
9
|
-
* Adding a lib = add an entry here (+ loader in game, + d.ts loader in editor).
|
|
10
|
-
*/
|
|
11
|
-
export declare enum LibId {
|
|
12
|
-
Tween = "tween",
|
|
13
|
-
Anime = "anime"
|
|
14
|
-
}
|
|
15
|
-
export interface LibDescriptor {
|
|
16
|
-
readonly id: LibId;
|
|
17
|
-
/** Key the user gets the lib by: `require("<requireKey>")`. */
|
|
18
|
-
readonly requireKey: string;
|
|
19
|
-
readonly label: string;
|
|
20
|
-
}
|
|
21
|
-
export declare const LIBS: Readonly<Record<LibId, LibDescriptor>>;
|
|
22
|
-
export declare const LIB_IDS: LibId[];
|
|
23
|
-
export declare const LIB_DESCRIPTORS: LibDescriptor[];
|
|
24
|
-
export declare function libByRequireKey(requireKey: string): LibDescriptor | undefined;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Registry of pluggable engine modules (`settings.addons.json → modules`).
|
|
3
|
-
* These are three-start modules that must be registered before `start()`.
|
|
4
|
-
* Feature toggles (chat/joystick/debugPerf) are NOT here — they live in
|
|
5
|
-
* `settings.json` (see `../features/feature-registry`).
|
|
6
|
-
*
|
|
7
|
-
* The only module so far is physics.
|
|
8
|
-
* Installation lives in game (`game/settings/module-installers`).
|
|
9
|
-
*/
|
|
10
|
-
export declare enum ModuleId {
|
|
11
|
-
Physics = "physics"
|
|
12
|
-
}
|
|
13
|
-
export type PhysicsEngine = "rapier";
|
|
14
|
-
/** `modules.physics` value: off | engine shorthand | object with options. */
|
|
15
|
-
export type PhysicsConfig = false | PhysicsEngine | {
|
|
16
|
-
engine: PhysicsEngine;
|
|
17
|
-
debug?: boolean;
|
|
18
|
-
};
|
|
19
|
-
export declare const PHYSICS_ENGINES: readonly PhysicsEngine[];
|
|
20
|
-
export declare const MODULE_IDS: ModuleId.Physics[];
|
|
21
|
-
/** Normalizes the physics config to an object (or null if disabled). */
|
|
22
|
-
export declare function normalizePhysics(value: PhysicsConfig | undefined): {
|
|
23
|
-
engine: PhysicsEngine;
|
|
24
|
-
debug: boolean;
|
|
25
|
-
} | null;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|