@pinkaphant/kolmo 0.1.1 → 0.1.3
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/LICENSE +21 -0
- package/README.md +16 -14
- package/bin/kolmo.mjs +19 -54
- package/dist/body/HeldItem.d.ts +22 -0
- package/dist/body/HeldItem.js +171 -0
- package/dist/body/KhrBody.d.ts +26 -0
- package/dist/body/KhrBody.js +179 -0
- package/dist/body/bodySi.d.ts +59 -0
- package/dist/body/bodySi.js +61 -0
- package/dist/body/index.d.ts +3 -0
- package/dist/body/index.js +4 -0
- package/dist/engine/index.d.ts +4 -4
- package/dist/engine/index.js +12 -3
- package/dist/engine/kolmoActor.d.ts +11 -4
- package/dist/engine/kolmoActor.js +197 -0
- package/dist/engine/kolmoInput.d.ts +12 -0
- package/dist/engine/kolmoInput.js +80 -0
- package/dist/engine/kolmoIsland.d.ts +3 -1
- package/dist/engine/kolmoIsland.js +311 -0
- package/dist/engine/kolmoLongDrive.js +223 -0
- package/dist/engine/kolmoRigs.js +59 -0
- package/dist/engine/kolmoStore.d.ts +53 -27
- package/dist/engine/kolmoStore.js +211 -0
- package/dist/engine/kolmoSurface.d.ts +1 -1
- package/dist/engine/kolmoSurface.js +182 -0
- package/dist/engine/kolmoVehicle.d.ts +2 -1
- package/dist/engine/kolmoVehicle.js +244 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
- package/dist/engine/kolmoVehicleDriver.js +38 -0
- package/dist/engine/kolmoWorld.d.ts +7 -15
- package/dist/engine/kolmoWorld.js +136 -0
- package/dist/engine/longDriveKit.d.ts +4 -2
- package/dist/engine/longDriveKit.js +254 -0
- package/dist/engine/mainlandMacroCell.d.ts +3 -7
- package/dist/engine/mainlandMacroCell.js +247 -0
- package/dist/engine/shiftedFixedBody.d.ts +13 -0
- package/dist/engine/shiftedFixedBody.js +64 -0
- package/dist/importer/ChopShopPanel.js +465 -0
- package/dist/importer/DomainWorkshopPanel.d.ts +9 -4
- package/dist/importer/DomainWorkshopPanel.js +385 -0
- package/dist/importer/GateHudBar.js +312 -0
- package/dist/importer/GlbImportGate.js +250 -0
- package/dist/importer/ImperativeVehicleRig.js +336 -0
- package/dist/importer/ImporterPlinthUikitTags.js +112 -0
- package/dist/importer/Step1CalibrationPlinth.js +275 -0
- package/dist/importer/Step2UniversalPad.js +244 -0
- package/dist/importer/VfxEmitterPool.js +91 -0
- package/dist/importer/chopShopActions.d.ts +22 -2
- package/dist/importer/chopShopActions.js +232 -0
- package/dist/importer/gateStore.d.ts +1 -1
- package/dist/importer/gateStore.js +92 -0
- package/dist/importer/glbNormalizer.js +133 -0
- package/dist/importer/importerWebMcp.d.ts +17 -6
- package/dist/importer/importerWebMcp.js +343 -0
- package/dist/importer/index.js +22 -3
- package/dist/importer/khrCompiler.d.ts +1 -1
- package/dist/importer/khrCompiler.js +434 -0
- package/dist/importer/launcherBake.js +51 -0
- package/dist/importer/meshIslands.d.ts +1 -1
- package/dist/importer/meshIslands.js +301 -0
- package/dist/importer/surfaceCutter.js +254 -0
- package/dist/importer/surfaceTopology.js +183 -0
- package/dist/importer/universalGateBake.js +162 -0
- package/dist/importer/usdToGlb.js +294 -0
- package/dist/importer/useChopShopController.d.ts +11 -2
- package/dist/importer/useChopShopController.js +364 -0
- package/dist/importer/vehiclePanelAnim.js +214 -0
- package/dist/importer/wheelAxlePairing.d.ts +1 -2
- package/dist/importer/wheelAxlePairing.js +102 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +69 -14
- package/dist/junk/DestructibleTarget.js +154 -0
- package/dist/junk/KolmoJunk.js +65 -0
- package/dist/junk/ShardPieces.d.ts +6 -4
- package/dist/junk/ShardPieces.js +74 -0
- package/dist/junk/TargetDecals.js +51 -0
- package/dist/junk/bvhShatter.js +55 -0
- package/dist/junk/bvhTriCollector.js +78 -0
- package/dist/junk/index.js +11 -1
- package/dist/junk/junkGeometry.js +69 -0
- package/dist/junk/junkImportSanitize.js +54 -0
- package/dist/junk/junkImporter.js +95 -0
- package/dist/junk/junkLabelCanvas.js +67 -0
- package/dist/junk/junkLabels.js +35 -0
- package/dist/junk/targetHelpers.js +103 -0
- package/dist/junk/targetHitLogic.js +128 -0
- package/dist/junk/useTargetAssets.js +102 -0
- package/dist/physics/index.d.ts +26 -0
- package/dist/physics/index.js +84 -0
- package/dist/schema/kolmoSchema.d.ts +2 -1
- package/dist/schema/kolmoSchema.js +184 -0
- package/dist/shaders/celestialBackdrop.d.ts +1 -1
- package/dist/shaders/celestialBackdrop.js +344 -0
- package/dist/shaders/index.d.ts +0 -1
- package/dist/shaders/index.js +9 -1
- package/dist/shaders/plumeAndSparkle.js +271 -0
- package/dist/shaders/ps2GlslShared.d.ts +1 -1
- package/dist/shaders/ps2GlslShared.js +3 -0
- package/dist/shaders/ps2MaterialsTSL.js +65 -0
- package/dist/shaders/ps2MaterialsWebGL.js +40 -0
- package/dist/shaders/ps2RoadWebGL.js +101 -0
- package/dist/shaders/ps2TerrainWebGL.js +54 -0
- package/dist/shaders/ps2Textures.js +224 -0
- package/dist/shaders/retroPalettes.js +188 -0
- package/dist/shaders/retroShader.d.ts +31 -3
- package/dist/shaders/retroShader.js +249 -0
- package/dist/shaders/tsl.d.ts +1 -0
- package/dist/shaders/tsl.js +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.js +90 -0
- package/dist/world/frontage.js +32 -0
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +11 -3
- package/dist/world/infiniteWorld2D.js +244 -0
- package/dist/world/island.js +201 -0
- package/dist/world/macroCellSchema.js +27 -0
- package/dist/world/macroKnightAStar.js +171 -0
- package/dist/world/random.js +33 -0
- package/dist/world/road.js +136 -0
- package/dist/world/roadRibbon.d.ts +6 -6
- package/dist/world/roadRibbon.js +161 -0
- package/dist/world/terrain.js +87 -0
- package/dist/world/worldTypes.js +111 -0
- package/package.json +36 -19
- package/dist/engine-BeKvBM8d.js +0 -1745
- package/dist/importer-D9bdcGTh.js +0 -5113
- package/dist/junk-B4bC1zAl.js +0 -1049
- package/dist/kolmoSurface-DTnrFXH0.js +0 -558
- package/dist/shaders-GS71Ek1A.js +0 -1383
- package/dist/world-PRWPYrlx.js +0 -947
- package/dist/worldTypes-Z0KfdCd0.js +0 -226
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SI first-person and third-person body dimensions and zero-allocation camera helpers
|
|
3
|
+
* for `@pinkaphant/ecctrl` `<Ecctrl>` and `<EcctrlCameraControls>`.
|
|
4
|
+
*/
|
|
5
|
+
export interface BodySiConstants {
|
|
6
|
+
/** `<Ecctrl capsuleHalfHeight>` in metres. */
|
|
7
|
+
readonly capsuleHalfHeight: number;
|
|
8
|
+
/** `<Ecctrl capsuleRadius>` in metres. */
|
|
9
|
+
readonly capsuleRadius: number;
|
|
10
|
+
/** `<Ecctrl floatHeight>` in metres. */
|
|
11
|
+
readonly floatHeight: number;
|
|
12
|
+
/** Eye height above the floor in metres. */
|
|
13
|
+
readonly eyeHeight: number;
|
|
14
|
+
/** Camera dolly distance in first person (metres). */
|
|
15
|
+
readonly firstPersonDistance: number;
|
|
16
|
+
/** Camera dolly distance in third person (metres). */
|
|
17
|
+
readonly thirdPersonDistance: number;
|
|
18
|
+
}
|
|
19
|
+
/** 1.75 m standing adult: 2 * 0.50 + 2 * 0.30 + 0.15. */
|
|
20
|
+
export declare const BODY_SI: BodySiConstants;
|
|
21
|
+
/** Ecctrl movement tuning for the standing SI body. */
|
|
22
|
+
export declare const BODY_MOVE_TUNE: Readonly<{
|
|
23
|
+
readonly maxWalkVel: 2.5;
|
|
24
|
+
readonly maxRunVel: 9;
|
|
25
|
+
readonly accDeltaTime: 0.25;
|
|
26
|
+
readonly decDeltaTime: 0.25;
|
|
27
|
+
readonly slideGripFactor: 1;
|
|
28
|
+
readonly moveImpulsePointOffset: 0;
|
|
29
|
+
readonly airDragFactor: 0.85;
|
|
30
|
+
readonly enableToggleRun: false;
|
|
31
|
+
}>;
|
|
32
|
+
export type BodySocketId = "Socket_Hand_R" | "Socket_Hand_L" | "Socket_Head" | "Socket_Back";
|
|
33
|
+
export declare const BODY_SOCKET_IDS: readonly BodySocketId[];
|
|
34
|
+
/** Rigid-body centre height when standing at rest on flat ground. */
|
|
35
|
+
export declare function bodyRestCenterY(b?: BodySiConstants): number;
|
|
36
|
+
/** Total standing height from floor to the top of the capsule. */
|
|
37
|
+
export declare function bodyStandingHeight(b?: BodySiConstants): number;
|
|
38
|
+
/** Camera target offset above the rigid-body centre. */
|
|
39
|
+
export declare function bodyEyeOffsetY(b?: BodySiConstants): number;
|
|
40
|
+
/** Spawn position whose feet rest on `floorY`. */
|
|
41
|
+
export declare function bodySpawnPosition(x: number, floorY: number, z: number, b?: BodySiConstants): [number, number, number];
|
|
42
|
+
/**
|
|
43
|
+
* Merges `ecctrl.excludeCharacterRay: true` into a RigidBody `userData` object for held-item colliders
|
|
44
|
+
* so `@pinkaphant/ecctrl` ground casts ignore held items (`collider.parent()?.userData`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function withExcludeCharacterRay(userData?: Record<string, unknown>): Record<string, unknown>;
|
|
47
|
+
/** Zero-allocation camera step sync from live handle position (and optional local Y axis) to camera controls at eye height. */
|
|
48
|
+
export declare function stepCameraSync(controls: {
|
|
49
|
+
moveTo?: (x: number, y: number, z: number, smooth: boolean) => unknown;
|
|
50
|
+
update?: (dt: number) => unknown;
|
|
51
|
+
} | null, pos: {
|
|
52
|
+
x: number;
|
|
53
|
+
y: number;
|
|
54
|
+
z: number;
|
|
55
|
+
}, eyeOffsetY: number, smooth: boolean, bodyYAxis?: {
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
z: number;
|
|
59
|
+
}): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/body/bodySi.ts
|
|
2
|
+
var e = Object.freeze({
|
|
3
|
+
capsuleHalfHeight: .5,
|
|
4
|
+
capsuleRadius: .3,
|
|
5
|
+
floatHeight: .15,
|
|
6
|
+
eyeHeight: 1.62,
|
|
7
|
+
firstPersonDistance: .02,
|
|
8
|
+
thirdPersonDistance: 3.2
|
|
9
|
+
}), t = Object.freeze({
|
|
10
|
+
maxWalkVel: 2.5,
|
|
11
|
+
maxRunVel: 9,
|
|
12
|
+
accDeltaTime: .25,
|
|
13
|
+
decDeltaTime: .25,
|
|
14
|
+
slideGripFactor: 1,
|
|
15
|
+
moveImpulsePointOffset: 0,
|
|
16
|
+
airDragFactor: .85,
|
|
17
|
+
enableToggleRun: !1
|
|
18
|
+
}), n = Object.freeze([
|
|
19
|
+
"Socket_Hand_R",
|
|
20
|
+
"Socket_Hand_L",
|
|
21
|
+
"Socket_Head",
|
|
22
|
+
"Socket_Back"
|
|
23
|
+
]);
|
|
24
|
+
function r(e) {
|
|
25
|
+
for (let [t, n] of Object.entries(e)) if (!(typeof n == "number" && Number.isFinite(n) && n >= 0)) throw RangeError(`kolmo/body: ${t} must be a finite non-negative number, got ${String(n)}`);
|
|
26
|
+
if (!(e.capsuleRadius > 0)) throw RangeError("kolmo/body: capsuleRadius must be > 0");
|
|
27
|
+
}
|
|
28
|
+
function i(t = e) {
|
|
29
|
+
return r(t), t.floatHeight + t.capsuleRadius + t.capsuleHalfHeight;
|
|
30
|
+
}
|
|
31
|
+
function a(t = e) {
|
|
32
|
+
return i(t) + t.capsuleHalfHeight + t.capsuleRadius;
|
|
33
|
+
}
|
|
34
|
+
function o(t = e) {
|
|
35
|
+
let n = t.eyeHeight - i(t);
|
|
36
|
+
if (!(n > 0)) throw RangeError("kolmo/body: eyeHeight must sit above the body centre");
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
function s(t, n, r, a = e) {
|
|
40
|
+
return [
|
|
41
|
+
t,
|
|
42
|
+
n + i(a),
|
|
43
|
+
r
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
function c(e) {
|
|
47
|
+
let t = e?.ecctrl ?? {};
|
|
48
|
+
return {
|
|
49
|
+
...e ?? {},
|
|
50
|
+
ecctrl: {
|
|
51
|
+
...t,
|
|
52
|
+
excludeCharacterRay: !0
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function l(e, t, n, r, i) {
|
|
57
|
+
if (!e) return;
|
|
58
|
+
let a = i ? t.x + i.x * n : t.x, o = i ? t.y + i.y * n : t.y + n, s = i ? t.z + i.z * n : t.z;
|
|
59
|
+
e.moveTo?.(a, o, s, r);
|
|
60
|
+
}
|
|
61
|
+
export { t as BODY_MOVE_TUNE, e as BODY_SI, n as BODY_SOCKET_IDS, o as bodyEyeOffsetY, i as bodyRestCenterY, s as bodySpawnPosition, a as bodyStandingHeight, l as stepCameraSync, c as withExcludeCharacterRay };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { BODY_MOVE_TUNE, BODY_SI, BODY_SOCKET_IDS, bodyEyeOffsetY, bodyRestCenterY, bodySpawnPosition, bodyStandingHeight, stepCameraSync, withExcludeCharacterRay, type BodySiConstants, type BodySocketId, } from "./bodySi.js";
|
|
2
|
+
export { KhrBody, type KhrBodyHandle, type KhrBodyProps } from "./KhrBody.js";
|
|
3
|
+
export { HeldItem, type HeldItemHandle, type HeldItemProps } from "./HeldItem.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BODY_MOVE_TUNE as e, BODY_SI as t, BODY_SOCKET_IDS as n, bodyEyeOffsetY as r, bodyRestCenterY as i, bodySpawnPosition as a, bodyStandingHeight as o, stepCameraSync as s, withExcludeCharacterRay as c } from "./bodySi.js";
|
|
2
|
+
import { KhrBody as l } from "./KhrBody.js";
|
|
3
|
+
import { HeldItem as u } from "./HeldItem.js";
|
|
4
|
+
export { e as BODY_MOVE_TUNE, t as BODY_SI, n as BODY_SOCKET_IDS, u as HeldItem, l as KhrBody, r as bodyEyeOffsetY, i as bodyRestCenterY, a as bodySpawnPosition, o as bodyStandingHeight, s as stepCameraSync, c as withExcludeCharacterRay };
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { EMPTY_KOLMO_INPUT, KOLMO_KEY_MAP, KolmoCanvas, KolmoGravityContext, KolmoPhysics, KolmoWorld, RetroViewportSync, RoomEnvRig, ShadowSnapRig, useIsKolmoCustomGravity, useKolmoInput, useOptionalKootaWorld, type KolmoCanvasProps, type KolmoGravityCallback, type KolmoGravitySpec, type KolmoInputGetter, type KolmoInputState, type KolmoKeyAction, type KolmoPhysicsProps, type KolmoPointGravity, type KolmoTimeControlValue, type KolmoWorldProps, type RetroViewportSyncProps, type RoomEnvRigProps, } from "./kolmoWorld.js";
|
|
2
2
|
export { KolmoVehicle, type KolmoVehicleProps } from "./kolmoVehicle.js";
|
|
3
3
|
export { KolmoActor, type KolmoActorProps } from "./kolmoActor.js";
|
|
4
|
-
export {
|
|
4
|
+
export { KolmoProp, KolmoSurface, togglePropJoint, type KolmoPropProps, type KolmoSurfaceProps, } from "./kolmoSurface.js";
|
|
5
5
|
export { KolmoIsland, computeIslandSpawnPose, getCachedIslandPlan, type IslandSpawnPose, type KolmoIslandProps, } from "./kolmoIsland.js";
|
|
6
6
|
export { KolmoLongDrive, computeLongDriveBridgeheadSpawn, computeLongDriveMainlandSpawn, type KolmoLongDriveProps, } from "./kolmoLongDrive.js";
|
|
7
|
-
export { ShiftedFixedBody } from "./mainlandMacroCell.js";
|
|
8
|
-
export {
|
|
7
|
+
export { ShiftedFixedBody, type ShiftedFixedBodyProps } from "./mainlandMacroCell.js";
|
|
8
|
+
export { ActorTrait, FloatingBodyTrait, InteractableTrait, PilotLink, VehicleTrait, WorldSessionTrait, ensureWorldSession, kolmoActions, kolmoTelemetry, kolmoWorld, readFloatingOriginAnchorXZ, shiftFloatingOriginEntities, useActiveKolmoWorld, useWorldTrait, type FloatingOriginRapierSync, type KolmoControlMode, type KolmoTelemetryState, } from "./kolmoStore.js";
|
package/dist/engine/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { KolmoGravityContext as e, KolmoPhysics as t, useIsKolmoCustomGravity as n, useOptionalKootaWorld as r } from "../physics/index.js";
|
|
2
|
+
import { EMPTY_KOLMO_INPUT as i, KOLMO_KEY_MAP as a, useKolmoInput as o } from "./kolmoInput.js";
|
|
3
|
+
import { RetroViewportSync as s, RoomEnvRig as c, ShadowSnapRig as l } from "./kolmoRigs.js";
|
|
4
|
+
import { KolmoCanvas as u, KolmoWorld as d } from "./kolmoWorld.js";
|
|
5
|
+
import { KolmoVehicle as f } from "./kolmoVehicle.js";
|
|
6
|
+
import { KolmoActor as p } from "./kolmoActor.js";
|
|
7
|
+
import { KolmoProp as m, KolmoSurface as h, togglePropJoint as g } from "./kolmoSurface.js";
|
|
8
|
+
import { KolmoIsland as _, computeIslandSpawnPose as v, getCachedIslandPlan as y } from "./kolmoIsland.js";
|
|
9
|
+
import { KolmoLongDrive as b, computeLongDriveBridgeheadSpawn as x, computeLongDriveMainlandSpawn as S } from "./kolmoLongDrive.js";
|
|
10
|
+
import { ShiftedFixedBody as C } from "./shiftedFixedBody.js";
|
|
11
|
+
import { ActorTrait as w, FloatingBodyTrait as T, InteractableTrait as E, PilotLink as D, VehicleTrait as O, WorldSessionTrait as k, ensureWorldSession as A, kolmoActions as j, kolmoTelemetry as M, kolmoWorld as N, readFloatingOriginAnchorXZ as P, shiftFloatingOriginEntities as F, useActiveKolmoWorld as I, useWorldTrait as L } from "./kolmoStore.js";
|
|
12
|
+
export { w as ActorTrait, i as EMPTY_KOLMO_INPUT, T as FloatingBodyTrait, E as InteractableTrait, a as KOLMO_KEY_MAP, p as KolmoActor, u as KolmoCanvas, e as KolmoGravityContext, _ as KolmoIsland, b as KolmoLongDrive, t as KolmoPhysics, m as KolmoProp, h as KolmoSurface, f as KolmoVehicle, d as KolmoWorld, D as PilotLink, s as RetroViewportSync, c as RoomEnvRig, l as ShadowSnapRig, C as ShiftedFixedBody, O as VehicleTrait, k as WorldSessionTrait, v as computeIslandSpawnPose, x as computeLongDriveBridgeheadSpawn, S as computeLongDriveMainlandSpawn, A as ensureWorldSession, y as getCachedIslandPlan, j as kolmoActions, M as kolmoTelemetry, N as kolmoWorld, P as readFloatingOriginAnchorXZ, F as shiftFloatingOriginEntities, g as togglePropJoint, I as useActiveKolmoWorld, n as useIsKolmoCustomGravity, o as useKolmoInput, r as useOptionalKootaWorld, L as useWorldTrait };
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { type ComponentProps, type ReactNode } from "react";
|
|
2
|
+
import { type EcctrlProps } from "@pinkaphant/ecctrl";
|
|
3
|
+
import { EcctrlCameraControls } from "@pinkaphant/ecctrl/camera";
|
|
4
|
+
import { type KolmoInputGetter } from "./kolmoInput.js";
|
|
2
5
|
export interface KolmoActorProps {
|
|
3
|
-
position?: [number, number, number];
|
|
4
|
-
enabled?: boolean;
|
|
6
|
+
readonly position?: [number, number, number];
|
|
7
|
+
readonly enabled?: boolean;
|
|
8
|
+
readonly getInput?: KolmoInputGetter;
|
|
9
|
+
readonly ecctrlProps?: Omit<EcctrlProps, "ref">;
|
|
10
|
+
readonly cameraProps?: Omit<ComponentProps<typeof EcctrlCameraControls>, "ref"> | null | false;
|
|
11
|
+
readonly children?: ReactNode;
|
|
5
12
|
}
|
|
6
|
-
export declare function KolmoActor({ position, enabled }: KolmoActorProps): React.JSX.Element | null;
|
|
13
|
+
export declare function KolmoActor({ position, enabled, getInput, ecctrlProps, cameraProps, children, }: KolmoActorProps): React.JSX.Element | null;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { KolmoGravityContext as e } from "../physics/index.js";
|
|
2
|
+
import { applyRetroMaterial as t } from "../shaders/retroShader.js";
|
|
3
|
+
import { useKolmoInput as n } from "./kolmoInput.js";
|
|
4
|
+
import { ActorTrait as r, InteractableTrait as i, VehicleTrait as a, WorldSessionTrait as o, ensureWorldSession as s, kolmoActions as c, kolmoTelemetry as l, useActiveKolmoWorld as u, useWorldTrait as d } from "./kolmoStore.js";
|
|
5
|
+
import { useCallback as f, useContext as p, useLayoutEffect as m, useMemo as h, useRef as g } from "react";
|
|
6
|
+
import * as _ from "three";
|
|
7
|
+
import { useFrame as v, useThree as y } from "@react-three/fiber";
|
|
8
|
+
import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
|
|
9
|
+
import { Ecctrl as C } from "@pinkaphant/ecctrl";
|
|
10
|
+
import { EcctrlCameraControls as w } from "@pinkaphant/ecctrl/camera";
|
|
11
|
+
// src/engine/kolmoActor.tsx
|
|
12
|
+
var T = new _.Vector3(), E = new _.Vector3(), D = new _.Vector3();
|
|
13
|
+
function O() {
|
|
14
|
+
let e = h(() => ({
|
|
15
|
+
suitGeo: new _.CapsuleGeometry(.28, .56, 6, 12),
|
|
16
|
+
visorGeo: new _.BoxGeometry(.34, .16, .14),
|
|
17
|
+
packGeo: new _.BoxGeometry(.32, .42, .16),
|
|
18
|
+
suitMat: t(new _.MeshStandardMaterial({
|
|
19
|
+
color: "#e2e8f0",
|
|
20
|
+
roughness: .55,
|
|
21
|
+
metalness: .15
|
|
22
|
+
})),
|
|
23
|
+
visorMat: t(new _.MeshStandardMaterial({
|
|
24
|
+
color: "#38bdf8",
|
|
25
|
+
emissive: "#0284c7",
|
|
26
|
+
emissiveIntensity: .55,
|
|
27
|
+
roughness: .2
|
|
28
|
+
})),
|
|
29
|
+
packMat: t(new _.MeshStandardMaterial({
|
|
30
|
+
color: "#334155",
|
|
31
|
+
roughness: .7
|
|
32
|
+
}))
|
|
33
|
+
}), []);
|
|
34
|
+
return m(() => () => {
|
|
35
|
+
e.suitGeo.dispose(), e.visorGeo.dispose(), e.packGeo.dispose(), e.suitMat.dispose(), e.visorMat.dispose(), e.packMat.dispose();
|
|
36
|
+
}, [e]), /* @__PURE__ */ S("group", { children: [
|
|
37
|
+
/* @__PURE__ */ x("mesh", {
|
|
38
|
+
castShadow: !0,
|
|
39
|
+
geometry: e.suitGeo,
|
|
40
|
+
material: e.suitMat
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ x("mesh", {
|
|
43
|
+
position: [
|
|
44
|
+
0,
|
|
45
|
+
.24,
|
|
46
|
+
.22
|
|
47
|
+
],
|
|
48
|
+
geometry: e.visorGeo,
|
|
49
|
+
material: e.visorMat
|
|
50
|
+
}),
|
|
51
|
+
/* @__PURE__ */ x("mesh", {
|
|
52
|
+
position: [
|
|
53
|
+
0,
|
|
54
|
+
.06,
|
|
55
|
+
-.24
|
|
56
|
+
],
|
|
57
|
+
castShadow: !0,
|
|
58
|
+
geometry: e.packGeo,
|
|
59
|
+
material: e.packMat
|
|
60
|
+
})
|
|
61
|
+
] });
|
|
62
|
+
}
|
|
63
|
+
function k({ position: t = [
|
|
64
|
+
0,
|
|
65
|
+
1.4,
|
|
66
|
+
0
|
|
67
|
+
], enabled: k = !0, getInput: A, ecctrlProps: j, cameraProps: M, children: N }) {
|
|
68
|
+
let P = p(e), F = u();
|
|
69
|
+
m(() => {
|
|
70
|
+
s(F);
|
|
71
|
+
}, [F]);
|
|
72
|
+
let I = d(F, o), L = n(A), R = y((e) => typeof e.gl?.domElement?.setAttribute == "function"), z = g(null), B = g(null), V = g(new _.Vector3()), H = g(new _.Vector3(0, 1, 0)), U = g(!1), W = g(0), G = g({
|
|
73
|
+
pos: null,
|
|
74
|
+
yaw: 0
|
|
75
|
+
}), K = g(null), q = g({
|
|
76
|
+
forward: !1,
|
|
77
|
+
backward: !1,
|
|
78
|
+
leftward: !1,
|
|
79
|
+
rightward: !1,
|
|
80
|
+
run: !1,
|
|
81
|
+
jump: !1
|
|
82
|
+
}), J = f((e, t) => {
|
|
83
|
+
V.current.x -= e, V.current.z -= t, z.current && (z.current.currPos.x -= e, z.current.currPos.z -= t);
|
|
84
|
+
let n = B.current;
|
|
85
|
+
n?.getPosition && n?.getTarget && n?.setLookAt && (n.getPosition(E), n.getTarget(D), n.setLookAt(E.x - e, E.y, E.z - t, D.x - e, D.y, D.z - t, !1));
|
|
86
|
+
}, []);
|
|
87
|
+
m(() => {
|
|
88
|
+
let e = F.spawn(r({
|
|
89
|
+
id: "pilot",
|
|
90
|
+
handle: z.current,
|
|
91
|
+
exitSpawnPos: null,
|
|
92
|
+
exitSpawnYaw: 0,
|
|
93
|
+
exitLinVel: null,
|
|
94
|
+
onOriginShift: J
|
|
95
|
+
})), t = F.onChange(r, (t) => {
|
|
96
|
+
if (t !== e) return;
|
|
97
|
+
let n = e.get(r);
|
|
98
|
+
n && (G.current = {
|
|
99
|
+
pos: n.exitSpawnPos,
|
|
100
|
+
yaw: n.exitSpawnYaw
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
return () => {
|
|
104
|
+
t(), e.destroy();
|
|
105
|
+
};
|
|
106
|
+
}, [F, J]);
|
|
107
|
+
let Y = f((e) => {
|
|
108
|
+
z.current = e;
|
|
109
|
+
let t = F.queryFirst(r);
|
|
110
|
+
if (!t) return;
|
|
111
|
+
let n = t.get(r);
|
|
112
|
+
e?.body && n?.exitLinVel && e.body.setLinvel({
|
|
113
|
+
x: n.exitLinVel[0],
|
|
114
|
+
y: n.exitLinVel[1],
|
|
115
|
+
z: n.exitLinVel[2]
|
|
116
|
+
}, !0), e?.body && (G.current.pos = null), t.set(r, {
|
|
117
|
+
id: n?.id ?? "pilot",
|
|
118
|
+
handle: e,
|
|
119
|
+
exitSpawnPos: e?.body ? null : n?.exitSpawnPos ?? null,
|
|
120
|
+
exitSpawnYaw: n?.exitSpawnYaw ?? 0,
|
|
121
|
+
exitLinVel: e?.body ? null : n?.exitLinVel ?? null,
|
|
122
|
+
onOriginShift: J
|
|
123
|
+
});
|
|
124
|
+
}, [F, J]), X = I?.activeVehicleId || "", Z = k && !X;
|
|
125
|
+
if (!Z) K.current = null;
|
|
126
|
+
else if (!K.current) {
|
|
127
|
+
let e = G.current.pos ?? j?.position ?? t, n = j?.rotation ?? [
|
|
128
|
+
0,
|
|
129
|
+
G.current.yaw,
|
|
130
|
+
0
|
|
131
|
+
];
|
|
132
|
+
K.current = {
|
|
133
|
+
pos: [
|
|
134
|
+
e[0],
|
|
135
|
+
e[1],
|
|
136
|
+
e[2]
|
|
137
|
+
],
|
|
138
|
+
rot: [
|
|
139
|
+
n[0],
|
|
140
|
+
n[1],
|
|
141
|
+
n[2]
|
|
142
|
+
]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
let Q = h(() => {
|
|
146
|
+
let e = j?.userData ?? {}, t = e.ecctrl ?? {};
|
|
147
|
+
return {
|
|
148
|
+
...e,
|
|
149
|
+
ecctrl: {
|
|
150
|
+
excludeVehicleRay: !0,
|
|
151
|
+
...t
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}, [j?.userData]);
|
|
155
|
+
return v((e, t) => {
|
|
156
|
+
if (!k) return;
|
|
157
|
+
let n = Math.min(Math.max(t, 1e-4), .05);
|
|
158
|
+
W.current > 0 && (W.current = Math.max(0, W.current - n));
|
|
159
|
+
let r = L(), o = r.interact && !U.current;
|
|
160
|
+
if (U.current = r.interact, X) {
|
|
161
|
+
o && W.current === 0 && (W.current = .25, c(F).exitVehicle());
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
let s = z.current;
|
|
165
|
+
if (!s || !s.body) return;
|
|
166
|
+
let u = q.current;
|
|
167
|
+
u.forward = r.forward, u.backward = r.backward, u.leftward = r.left, u.rightward = r.right, u.run = r.boost, u.jump = r.brake, s.setMovement(u), l.mode = "foot", l.speedKmh = s.moveSpeed * 3.6, l.rpm = 0, l.gear = 0, l.throttle = +!!s.isMoving, l.boost = r.boost && s.isMoving ? 1 : 0;
|
|
168
|
+
let d = null, f = Infinity;
|
|
169
|
+
for (let e of F.query(a, i)) {
|
|
170
|
+
let t = e.get(a), n = e.get(i);
|
|
171
|
+
if (!t?.handle || !n) continue;
|
|
172
|
+
T.set(t.seatOffset[0] - t.centerOfMass[0], t.seatOffset[1] - t.centerOfMass[1], t.seatOffset[2] - t.centerOfMass[2]).applyQuaternion(t.handle.currQuat).add(t.handle.currPos);
|
|
173
|
+
let r = s.currPos.distanceToSquared(T);
|
|
174
|
+
r <= n.radius * n.radius && r < f && (f = r, d = t.id);
|
|
175
|
+
}
|
|
176
|
+
l.nearVehicleId = d, o && d && W.current === 0 ? (W.current = .25, c(F).boardVehicle(d)) : B.current && s.currPos.lengthSq() > 0 && (V.current.copy(s.currPos).addScaledVector(s.bodyYAxis, .55), H.current.copy(s.upAxis), B.current.moveTo(V.current.x, V.current.y, V.current.z, !0), e.camera.up.lerp(H.current, .14), B.current.setUp(e.camera.up));
|
|
177
|
+
}), Z ? /* @__PURE__ */ S(b, { children: [R && M !== !1 && M !== null && /* @__PURE__ */ x(w, {
|
|
178
|
+
ref: B,
|
|
179
|
+
makeDefault: !0,
|
|
180
|
+
minPolarAngle: .12,
|
|
181
|
+
maxPolarAngle: Math.PI - .12,
|
|
182
|
+
smoothTime: .08,
|
|
183
|
+
...M ?? {}
|
|
184
|
+
}), /* @__PURE__ */ x(C, {
|
|
185
|
+
ref: Y,
|
|
186
|
+
enableCustomGravity: P,
|
|
187
|
+
maxWalkVel: 3.2,
|
|
188
|
+
maxRunVel: 7.2,
|
|
189
|
+
jumpVel: 5.8,
|
|
190
|
+
...j,
|
|
191
|
+
position: K.current.pos,
|
|
192
|
+
rotation: K.current.rot,
|
|
193
|
+
userData: Q,
|
|
194
|
+
children: N ?? /* @__PURE__ */ x(O, {})
|
|
195
|
+
})] }) : null;
|
|
196
|
+
}
|
|
197
|
+
export { k as KolmoActor };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type KeyboardControlsEntry } from "@react-three/drei";
|
|
2
|
+
export type KolmoKeyAction = "forward" | "backward" | "left" | "right" | "brake" | "boost" | "interact" | "turnLeft" | "turnRight" | "descend" | "cameraView";
|
|
3
|
+
export type KolmoInputState = Record<KolmoKeyAction, boolean>;
|
|
4
|
+
export type KolmoInputGetter = () => Partial<KolmoInputState>;
|
|
5
|
+
export declare const EMPTY_KOLMO_INPUT: Readonly<KolmoInputState>;
|
|
6
|
+
export declare const KOLMO_KEY_MAP: KeyboardControlsEntry<KolmoKeyAction>[];
|
|
7
|
+
/**
|
|
8
|
+
* Safe zero-allocation input reader that falls back cleanly to `EMPTY_KOLMO_INPUT`
|
|
9
|
+
* when `<KeyboardControls>` is omitted (`keyboardMap={null}` or `<KolmoPhysics>`),
|
|
10
|
+
* and merges optional caller `getInput()` overrides.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useKolmoInput(getInput?: KolmoInputGetter): () => Readonly<KolmoInputState>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useCallback as e, useRef as t } from "react";
|
|
2
|
+
import { useKeyboardControls as n } from "@react-three/drei";
|
|
3
|
+
// src/engine/kolmoInput.ts
|
|
4
|
+
var r = Object.freeze({
|
|
5
|
+
forward: !1,
|
|
6
|
+
backward: !1,
|
|
7
|
+
left: !1,
|
|
8
|
+
right: !1,
|
|
9
|
+
brake: !1,
|
|
10
|
+
boost: !1,
|
|
11
|
+
interact: !1,
|
|
12
|
+
turnLeft: !1,
|
|
13
|
+
turnRight: !1,
|
|
14
|
+
descend: !1,
|
|
15
|
+
cameraView: !1
|
|
16
|
+
}), i = [
|
|
17
|
+
{
|
|
18
|
+
name: "forward",
|
|
19
|
+
keys: ["KeyW", "ArrowUp"]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "backward",
|
|
23
|
+
keys: ["KeyS", "ArrowDown"]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "left",
|
|
27
|
+
keys: ["KeyA", "ArrowLeft"]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "right",
|
|
31
|
+
keys: ["KeyD", "ArrowRight"]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "brake",
|
|
35
|
+
keys: ["Space"]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "boost",
|
|
39
|
+
keys: ["ShiftLeft", "ShiftRight"]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "interact",
|
|
43
|
+
keys: ["KeyF", "KeyE"]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "turnLeft",
|
|
47
|
+
keys: ["KeyQ"]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "turnRight",
|
|
51
|
+
keys: ["KeyC"]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "descend",
|
|
55
|
+
keys: ["KeyX", "ControlLeft"]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "cameraView",
|
|
59
|
+
keys: ["KeyV"]
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
function a(i) {
|
|
63
|
+
let a = null;
|
|
64
|
+
try {
|
|
65
|
+
let [, e] = n();
|
|
66
|
+
a = e;
|
|
67
|
+
} catch {
|
|
68
|
+
a = null;
|
|
69
|
+
}
|
|
70
|
+
let o = t(i);
|
|
71
|
+
o.current = i;
|
|
72
|
+
let s = t({ ...r });
|
|
73
|
+
return e(() => {
|
|
74
|
+
let e = o.current?.();
|
|
75
|
+
if (!a && !e) return r;
|
|
76
|
+
let t = a ? a() : r, n = s.current;
|
|
77
|
+
return n.forward = !!(e?.forward ?? t.forward), n.backward = !!(e?.backward ?? t.backward), n.left = !!(e?.left ?? t.left), n.right = !!(e?.right ?? t.right), n.brake = !!(e?.brake ?? t.brake), n.boost = !!(e?.boost ?? t.boost), n.interact = !!(e?.interact ?? t.interact), n.turnLeft = !!(e?.turnLeft ?? t.turnLeft), n.turnRight = !!(e?.turnRight ?? t.turnRight), n.descend = !!(e?.descend ?? t.descend), n.cameraView = !!(e?.cameraView ?? t.cameraView), n;
|
|
78
|
+
}, [a]);
|
|
79
|
+
}
|
|
80
|
+
export { r as EMPTY_KOLMO_INPUT, i as KOLMO_KEY_MAP, a as useKolmoInput };
|
|
@@ -13,5 +13,7 @@ export interface KolmoIslandProps {
|
|
|
13
13
|
readonly size?: number;
|
|
14
14
|
readonly segments?: number;
|
|
15
15
|
readonly settlementTier?: SettlementTier;
|
|
16
|
+
readonly offX?: number;
|
|
17
|
+
readonly offZ?: number;
|
|
16
18
|
}
|
|
17
|
-
export declare function KolmoIsland({ seed, size, segments, settlementTier, }: KolmoIslandProps): React.JSX.Element;
|
|
19
|
+
export declare function KolmoIsland({ seed, size, segments, settlementTier, offX, offZ, }: KolmoIslandProps): React.JSX.Element;
|