@kvyverse/world-runtime 0.1.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.
Files changed (96) hide show
  1. package/LICENSE.md +57 -0
  2. package/README.md +87 -0
  3. package/dist/BallCollider-8ZrxReEd.js +16 -0
  4. package/dist/CapsuleCollider-bynyf6Mc.js +20 -0
  5. package/dist/Collider-4_rCTHVA.js +82 -0
  6. package/dist/ConeCollider-DtRZmgK8.js +20 -0
  7. package/dist/ConvexMeshCollider-BSmDM4o3.js +14 -0
  8. package/dist/CuboidCollider-CJvq7--s.js +27 -0
  9. package/dist/CylinderCollider-CQPSh4tu.js +24 -0
  10. package/dist/FpsCameraController-BE2EirRj.js +55 -0
  11. package/dist/MeshInstansing-Bxij0Yc9.js +42 -0
  12. package/dist/PointerLockCameraControls-DYxxMeSw.js +104 -0
  13. package/dist/RapierDebugRenderer-sURZDLP4.js +55 -0
  14. package/dist/RapierFpsPlayerController-VsNfQl6v.js +142 -0
  15. package/dist/RapierPhysics-C_3b7QOn.js +74 -0
  16. package/dist/Rigidbody-b7QNF4ev.js +107 -0
  17. package/dist/ScalingToFro-BD-E5-uR.js +21 -0
  18. package/dist/SightInteractableArea-DrqyB41W.js +79 -0
  19. package/dist/SimpleWASDMovement-C2m53YYH.js +17 -0
  20. package/dist/Spinning-sgUhHld8.js +10 -0
  21. package/dist/StartAnimation-B9eomOS2.js +37 -0
  22. package/dist/TrimeshCollider-7dIs_xtZ.js +62 -0
  23. package/dist/World.d.ts +19 -0
  24. package/dist/WorldRuntime.d.ts +94 -0
  25. package/dist/behaviours/animation/ScalingToFro.d.ts +8 -0
  26. package/dist/behaviours/animation/Spinning.d.ts +5 -0
  27. package/dist/behaviours/animation/StartAnimation.d.ts +9 -0
  28. package/dist/behaviours/controls/FpsCameraController.d.ts +10 -0
  29. package/dist/behaviours/controls/PointerLockCameraControls.d.ts +28 -0
  30. package/dist/behaviours/controls/SimpleWASDMovement.d.ts +5 -0
  31. package/dist/behaviours/physics/BallCollider.d.ts +10 -0
  32. package/dist/behaviours/physics/CapsuleCollider.d.ts +14 -0
  33. package/dist/behaviours/physics/ConeCollider.d.ts +14 -0
  34. package/dist/behaviours/physics/ConvexMeshCollider.d.ts +6 -0
  35. package/dist/behaviours/physics/CuboidCollider.d.ts +22 -0
  36. package/dist/behaviours/physics/CylinderCollider.d.ts +18 -0
  37. package/dist/behaviours/physics/HalfspaceCollider.d.ts +7 -0
  38. package/dist/behaviours/physics/RapierFpsPlayerController.d.ts +35 -0
  39. package/dist/behaviours/physics/Rigidbody.d.ts +24 -0
  40. package/dist/behaviours/physics/TrimeshCollider.d.ts +9 -0
  41. package/dist/behaviours/physics/_required-patch.d.ts +10 -0
  42. package/dist/behaviours/physics/rapier-addon-core/Collider.d.ts +14 -0
  43. package/dist/behaviours/physics/rapier-addon-core/RapierDebugRenderer.d.ts +17 -0
  44. package/dist/behaviours/physics/rapier-addon-core/RapierPhysics.d.ts +131 -0
  45. package/dist/behaviours/physics/rapier-addon-core/get-scale-from-obj.d.ts +8 -0
  46. package/dist/behaviours/player/SightInteractableArea.d.ts +23 -0
  47. package/dist/behaviours/registry.d.ts +16 -0
  48. package/dist/behaviours/utils/MeshInstansing.d.ts +12 -0
  49. package/dist/bootstrap.d.ts +8 -0
  50. package/dist/define-world.d.ts +9 -0
  51. package/dist/get-scale-from-obj-QKv3Fig5.js +22 -0
  52. package/dist/index.d.ts +48 -0
  53. package/dist/index.js +1707 -0
  54. package/dist/modules/EnvModule.d.ts +11 -0
  55. package/dist/modules/HtmlHudModule.d.ts +14 -0
  56. package/dist/modules/InputSystemModule.d.ts +87 -0
  57. package/dist/modules/SoundsModule.d.ts +7 -0
  58. package/dist/modules/UtilsModule.d.ts +9 -0
  59. package/dist/modules/contracts/env.module-api.d.ts +7 -0
  60. package/dist/modules/contracts/html.module-api.d.ts +7 -0
  61. package/dist/modules/contracts/input.module-api.d.ts +31 -0
  62. package/dist/modules/contracts/rapier.module-api.d.ts +11 -0
  63. package/dist/modules/contracts/rapierDebug.module-api.d.ts +5 -0
  64. package/dist/modules/contracts/sounds.module-api.d.ts +5 -0
  65. package/dist/modules/contracts/utils.module-api.d.ts +7 -0
  66. package/dist/modules/index.d.ts +22 -0
  67. package/dist/modules/is-mobile-device.d.ts +1 -0
  68. package/dist/modules/registry.d.ts +31 -0
  69. package/dist/rendering/SceneBloom.d.ts +40 -0
  70. package/dist/rendering/renderer-apply.d.ts +14 -0
  71. package/dist/rendering/renderer-options.d.ts +11 -0
  72. package/dist/rendering/tsl-node.d.ts +21 -0
  73. package/dist/rendering/tsl-uniforms.d.ts +18 -0
  74. package/dist/resources/audio.d.ts +15 -0
  75. package/dist/resources/default-resources.d.ts +36 -0
  76. package/dist/resources/font.d.ts +32 -0
  77. package/dist/resources/geometry.d.ts +5 -0
  78. package/dist/resources/hdr.d.ts +6 -0
  79. package/dist/resources/loaders.d.ts +45 -0
  80. package/dist/resources/model.d.ts +24 -0
  81. package/dist/resources/texture.d.ts +8 -0
  82. package/dist/resources/video.d.ts +14 -0
  83. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  84. package/dist/settings/AddonsRuntime.d.ts +19 -0
  85. package/dist/settings/externals.d.ts +14 -0
  86. package/dist/settings/lib-loaders.d.ts +7 -0
  87. package/dist/settings/lib-registry.d.ts +24 -0
  88. package/dist/settings/module-registry.d.ts +25 -0
  89. package/dist/settings/types.d.ts +46 -0
  90. package/dist/types.d.ts +80 -0
  91. package/dist/utils/lazy.d.ts +4 -0
  92. package/dist/values.d.ts +6 -0
  93. package/dist/version.d.ts +10 -0
  94. package/dist/version.gen.d.ts +1 -0
  95. package/dist/world-events.d.ts +13 -0
  96. package/package.json +53 -0
@@ -0,0 +1,24 @@
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;
@@ -0,0 +1,25 @@
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;
@@ -0,0 +1,46 @@
1
+ import type { ExternalDescriptor } from "./externals";
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
+ }
13
+ /** Subset of `WebGPURendererParameters` configurable via the config. */
14
+ export interface RendererParams {
15
+ antialias?: boolean;
16
+ alpha?: boolean;
17
+ depth?: boolean;
18
+ stencil?: boolean;
19
+ logarithmicDepthBuffer?: boolean;
20
+ reverseDepthBuffer?: boolean;
21
+ preserveDrawingBuffer?: boolean;
22
+ premultipliedAlpha?: boolean;
23
+ failIfMajorPerformanceCaveat?: boolean;
24
+ }
25
+ /**
26
+ * Bloom post-effect. `mode` (default `threshold`): threshold — full-frame by
27
+ * brightness; emissive — selective via MRT, only emissive materials glow.
28
+ */
29
+ export interface BloomConfig {
30
+ enabled?: boolean;
31
+ mode?: BloomModeName;
32
+ strength?: number;
33
+ radius?: number;
34
+ threshold?: number;
35
+ }
36
+ /** `settings.renderer.json` — WebGPURenderer parameters. */
37
+ export interface RendererConfig {
38
+ renderer?: RendererParams;
39
+ pixelResolution?: number;
40
+ bloom?: BloomConfig;
41
+ shadowMap?: {
42
+ enabled?: boolean;
43
+ type?: ShadowMapTypeName;
44
+ };
45
+ toneMapping?: ToneMappingName;
46
+ }
@@ -0,0 +1,80 @@
1
+ import type { Object3DBehaviourConstructor } from "three-start";
2
+ import type { AddonsConfig, RendererConfig } from "./settings/types";
3
+ import type * as THREE from "three/webgpu";
4
+ /** World assets: asset path in the project (`/Folder/name.ext`) → URL. */
5
+ export type AssetUrlTable = Record<string, string>;
6
+ /** User script: the body runs with a context object, returns `output`. */
7
+ export type ScriptModule = (context: Record<string, unknown>) => unknown;
8
+ /** World scripts keyed by the same paths as in `require`. */
9
+ export type ScriptTable = Record<string, ScriptModule>;
10
+ /** Result of constructing the scene hierarchy (before values are applied). */
11
+ export interface SceneBuildResult {
12
+ children: THREE.Object3D[];
13
+ camera?: THREE.PerspectiveCamera | null;
14
+ }
15
+ /** Load-step details for the user's UI. */
16
+ export interface WorldLoadProgress {
17
+ stage: string;
18
+ details?: string;
19
+ }
20
+ /**
21
+ * Runtime API for the generated code: asset resolving, resource factories,
22
+ * scripts and behaviours. The only object the world hooks receive.
23
+ */
24
+ export interface RuntimeApi {
25
+ /** Asset URL by its project path. Same resolving as `getUrl` in scripts. */
26
+ getUrl: (path: string) => string;
27
+ /** `require` value by asset path or addon key. */
28
+ require: (key: string) => unknown;
29
+ /** Built-in behaviour class by uuid (preloaded by bootstrap). */
30
+ builtin: (uuid: string) => Object3DBehaviourConstructor;
31
+ }
32
+ /**
33
+ * A world unrolled by the codegen into imperative code. The artifact supplies
34
+ * the data and steps; the runtime owns their call order (see `bootstrap.ts`).
35
+ */
36
+ export interface WorldDefinition<TAssets = unknown> {
37
+ formatVersion: number;
38
+ assets: AssetUrlTable;
39
+ /** Loads world resources; the result is passed to the remaining steps. */
40
+ loadAssets: (rt: RuntimeApi) => Promise<TAssets>;
41
+ /**
42
+ * Scene assembly: object construction, then applying values and attaching
43
+ * behaviours. Both passes live in one function — forward references
44
+ * (`$O` to an object created later) are closed by applying values after
45
+ * all objects are declared.
46
+ */
47
+ buildScene: (rt: RuntimeApi, assets: TAssets) => SceneBuildResult;
48
+ /** Scene settings: background, fog, environment. */
49
+ applySceneSettings?: (rt: RuntimeApi, scene: THREE.Scene) => void;
50
+ /** `settings.renderer.json`: renderer params, shadow map, tone mapping, bloom. */
51
+ renderer?: RendererConfig;
52
+ /** `settings.addons.json`: built-in libs and external scripts for `require`. */
53
+ addons?: AddonsConfig;
54
+ /** User scripts keyed by asset paths — same keys as `require`. */
55
+ scripts?: ScriptTable;
56
+ /** Path of the world entry script (`main.ts`). */
57
+ entryScript?: string;
58
+ /** Contents of the world's css scripts. */
59
+ styles?: string[];
60
+ /** Font asset paths — the runtime mounts their `@font-face` in a single tag. */
61
+ fontPaths?: string[];
62
+ /** Uuids of built-in behaviours used by the world: their classes are preloaded
63
+ * and their required patches are applied before `start()`. */
64
+ usedBuiltins?: string[];
65
+ }
66
+ /** World load options. */
67
+ export interface LoadWorldOptions {
68
+ /**
69
+ * Prefix for relative paths in the asset table. Not needed when assets
70
+ * stay on the Kvyverse CDN (the table contains absolute URLs).
71
+ */
72
+ assetsBaseUrl?: string;
73
+ /**
74
+ * Folder with the draco decoder for compressed models. Defaults to the
75
+ * public Google decoder; set your own if you host the decoder yourself
76
+ * (offline, CSP).
77
+ */
78
+ dracoPath?: string;
79
+ onProgress?: (progress: WorldLoadProgress) => void;
80
+ }
@@ -0,0 +1,4 @@
1
+ /** Lazy cached value: the factory is called once on the first `get()`. */
2
+ export declare function lazy<T>(factory: () => T): {
3
+ get: () => T;
4
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Writes a color into an object field, creating a `Color` if the slot is empty.
3
+ * Mirrors the `$C` branch of `applyValues` — needed by generated code for fields
4
+ * like `scene.background` that may be `null`.
5
+ */
6
+ export declare function setColor(target: object, key: string, hex: string | number): void;
@@ -0,0 +1,10 @@
1
+ export { RUNTIME_VERSION } from "./version.gen";
2
+ /**
3
+ * Format version of the generated world. The codegen stamps it into the artifact,
4
+ * the runtime checks it on load. A breaking format change = package major bump.
5
+ * Not to be confused with {@link RUNTIME_VERSION} — the package's own version
6
+ * (from package.json, generated into version.gen.ts by gen-runtime-version).
7
+ */
8
+ export declare const WORLD_FORMAT_VERSION = 1;
9
+ /** Throws if the artifact was built by an incompatible generator version. */
10
+ export declare function assertFormatVersion(version: number): void;
@@ -0,0 +1 @@
1
+ export declare const RUNTIME_VERSION = "0.1.0";
@@ -0,0 +1,13 @@
1
+ /**
2
+ * World lifecycle events, emitted on `game.emitter` (`world.events` in scripts)
3
+ * during classic-load. The entry script runs BEFORE them (step 9) — subscriptions
4
+ * from `main.ts` catch all three. See `docs/scripting/game-runtime.md`.
5
+ */
6
+ export declare enum WorldEvent {
7
+ /** Scene parsed, values applied; objects are NOT yet added to `ctx.scene`. */
8
+ BeforeSceneReady = "before-scene-ready",
9
+ /** Hierarchy added to `ctx.scene` — scene is ready; lifecycle not started yet. */
10
+ SceneReady = "scene-ready",
11
+ /** `start()` called: behaviours woke up, the render loop is running. */
12
+ Started = "started"
13
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@kvyverse/world-runtime",
3
+ "version": "0.1.0",
4
+ "description": "Runtime for worlds exported from the Kvyverse platform for self-hosting",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "author": "Vladislav Kruteniuk",
7
+ "homepage": "https://kvyverse.com",
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE.md"
22
+ ],
23
+ "sideEffects": false,
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "vite build && tsc -p tsconfig.build.json",
29
+ "typecheck": "tsc -p tsconfig.build.json --noEmit",
30
+ "prepublishOnly": "node -e \"require('fs').accessSync('dist/index.js')\" || (echo 'run npm run build:world-runtime from repo root first' && exit 1)"
31
+ },
32
+ "peerDependencies": {
33
+ "@dimforge/rapier3d-compat": "0.19.3",
34
+ "@tweenjs/tween.js": "^25.0.0",
35
+ "animejs": "^4.5.0",
36
+ "eventemitter3": "^5.0.1",
37
+ "howler": "^2.2.4",
38
+ "three": "^0.184.0",
39
+ "three-start": "^0.1.2",
40
+ "vanjs-core": "^1.6.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@dimforge/rapier3d-compat": {
44
+ "optional": true
45
+ },
46
+ "@tweenjs/tween.js": {
47
+ "optional": true
48
+ },
49
+ "animejs": {
50
+ "optional": true
51
+ }
52
+ }
53
+ }