@pinkaphant/kolmo 0.1.2 → 0.2.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/LICENSE +21 -0
- package/README.md +16 -14
- package/bin/kolmo.mjs +22 -54
- package/dist/body/HeldItem.js +171 -0
- package/dist/body/KhrBody.js +171 -0
- package/dist/body/bodySi.d.ts +0 -11
- package/dist/body/bodySi.js +52 -0
- package/dist/body/index.d.ts +1 -1
- package/dist/body/index.js +4 -1
- 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 +17 -0
- package/dist/engine/kolmoInput.js +78 -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 +3 -1
- package/dist/engine/kolmoVehicle.js +250 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +30 -0
- package/dist/engine/kolmoVehicleDriver.js +29 -0
- package/dist/engine/kolmoWorld.d.ts +7 -15
- package/dist/engine/kolmoWorld.js +139 -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 +1 -1
- package/dist/index.js +69 -13
- 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 +32 -18
- package/dist/body-B7FTf67o.js +0 -362
- package/dist/engine-BeKvBM8d.js +0 -1745
- package/dist/importer-B2-S-N_e.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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pinkaphant
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# `@pinkaphant/kolmo` — 3D Game Engine (`ecctrl 2` + `khr3`), `Longline`, `Dust` & Universal KHR3 Gate
|
|
2
2
|
|
|
3
|
-
`@pinkaphant/kolmo` is the publishable 3D game engine and browser asset studio built on `@khr3/*` and `@pinkaphant/ecctrl` (`^2.0.4-beta.3`). Every module in `src/` and `games/` stays strictly `<=
|
|
3
|
+
`@pinkaphant/kolmo` is the publishable 3D game engine and browser asset studio built on `@khr3/*` and `@pinkaphant/ecctrl` (`^2.0.4-beta.3`). Every module in `src/` and `games/` stays strictly `<= 300` SLOC with 60Hz imperative `useFrame` + ref discipline, Zustand for discrete UI, and Koota for ECS.
|
|
4
4
|
|
|
5
5
|
## Quickstart (`npm install` or `npx` Scaffolder)
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
# Install into an existing R3F / Vite app:
|
|
9
|
-
npm install @pinkaphant/kolmo @pinkaphant/ecctrl@^2.0.4-beta.3 @khr3/core @khr3/assets @khr3/c12 @khr3/vehicles @khr3/launchers
|
|
9
|
+
npm install @pinkaphant/kolmo @pinkaphant/ecctrl@^2.0.4-beta.3 @dimforge/rapier3d-compat@0.19.2 @khr3/core @khr3/assets @khr3/c12 @khr3/vehicles @khr3/launchers
|
|
10
10
|
|
|
11
11
|
# Or scaffold your own standalone game (configured for your own Cloudflare Workers/R2 account):
|
|
12
12
|
npx @pinkaphant/kolmo create my-road-game --template longline
|
|
@@ -16,30 +16,32 @@ npx @pinkaphant/kolmo create my-chop-shop --template garage
|
|
|
16
16
|
|
|
17
17
|
## Subpath Exports & Architecture Map
|
|
18
18
|
|
|
19
|
-
All `@khr3/*` packages are **zero-`koota`** reusable libraries. **`@pinkaphant/kolmo` owns `koota`**, uniting all
|
|
19
|
+
All five `@khr3/*` packages (`@khr3/core`, `@khr3/assets`, `@khr3/c12`, `@khr3/vehicles`, `@khr3/launchers`) are **zero-`koota`** reusable libraries. **`@pinkaphant/kolmo` owns `koota`**, uniting all five `@khr3/*` packages with ECS state, spatial gravity physics, procedural floating-origin worlds, character body, destructible junk, retro shaders, Vite 8 WASM/Rolldown helpers, and the Universal KHR3 Gate:
|
|
20
20
|
|
|
21
21
|
| Import Subpath | Source Entrypoint | Owns |
|
|
22
22
|
| --- | --- | --- |
|
|
23
|
-
| `@pinkaphant/kolmo` | [src/index.ts](./src/index.ts) | Unified barrel + unprefixed JSX aliases (`<Canvas>`, `<World>`, `<Vehicle>`, `<Actor>`, `<Island>`, `<LongDrive>`, `<Skybox>`, `<Exoplanet>`, `<Junk>`) + `@khr3/*` re-exports (`VAULT_CARS`, `VAULT_WEAPONS`, `VAULT_CITY`) |
|
|
24
|
-
| `@pinkaphant/kolmo/
|
|
25
|
-
| `@pinkaphant/kolmo/
|
|
26
|
-
| `@pinkaphant/kolmo/
|
|
27
|
-
| `@pinkaphant/kolmo/
|
|
28
|
-
| `@pinkaphant/kolmo/
|
|
29
|
-
| `@pinkaphant/kolmo/
|
|
23
|
+
| `@pinkaphant/kolmo` | [src/index.ts](./src/index.ts) | Unified barrel + unprefixed JSX aliases (`<Canvas>`, `<World>`, `<Physics>`, `<Vehicle>`, `<Actor>`, `<Surface>`, `<Prop>`, `<EmitterRig>`, `<Island>`, `<LongDrive>`, `<Skybox>`, `<Exoplanet>`, `<Junk>`) + `@khr3/*` re-exports (`VAULT_CARS`, `VAULT_WEAPONS`, `VAULT_CITY`) |
|
|
24
|
+
| `@pinkaphant/kolmo/physics` | [src/physics/index.tsx](./src/physics/index.tsx) | `<KolmoPhysics>` (`planar`, `point`, `zero`, `custom`, `[gx,gy,gz]`, or `(pos) => g` spatial gravity + `timeScale` ref support over `<PhysicsWorld>` without retro shaders, skybox, or terrain) |
|
|
25
|
+
| `@pinkaphant/kolmo/vite` | [src/vite/index.ts](./src/vite/index.ts) | `externalizeRapierWasm()` (`{ module_or_path }` WASM init + concurrent-init guard), `KOLMO_SINGLETON_DEDUPE`, and `KOLMO_ROLLDOWN_BUILD` (cycle-free DAG leaf chunks) |
|
|
26
|
+
| `@pinkaphant/kolmo/engine` | [src/engine/index.ts](./src/engine/index.ts) | `koota` ECS (`kolmoWorld`, [kolmoStore.ts](./src/engine/kolmoStore.ts)), `<KolmoCanvas>`, `<KolmoWorld>` (`world={null}` safe, `keyboardMap={null}` safe), `<KolmoVehicle>` (`drive`/`rocket` live switch + `getInput`), `<KolmoActor>` (`children`, `ecctrlProps`, `cameraProps`, `getInput`), `<KolmoIsland>`, `<KolmoLongDrive>` (`192 m` floating-origin + 3×3 Macro-Cell streamer) |
|
|
27
|
+
| `@pinkaphant/kolmo/world` | [src/world/index.ts](./src/world/index.ts) | Spline roads ([road.ts](./src/world/road.ts)), carved terrain ([terrain.ts](./src/world/terrain.ts)), 8-way A* island ring ([island.ts](./src/world/island.ts)), 7-vertex road ribbons & world-space chunk UVs ([roadRibbon.ts](./src/world/roadRibbon.ts)), `2304 m` Macro-Lattice ([infiniteWorld2D.ts](./src/world/infiniteWorld2D.ts)), 16-way Knight A* ([macroKnightAStar.ts](./src/world/macroKnightAStar.ts)) |
|
|
28
|
+
| `@pinkaphant/kolmo/shaders` | [src/shaders/index.ts](./src/shaders/index.ts) | 6-mode retro quantizer ([retroShader.ts](./src/shaders/retroShader.ts)), `192 m`-periodic PS2 world-locked splat shaders ([ps2TerrainWebGL.ts](./src/shaders/ps2TerrainWebGL.ts), [ps2RoadWebGL.ts](./src/shaders/ps2RoadWebGL.ts)), `<KolmoSkybox>`, `<KolmoExoplanet>`, plus WebGPU TSL opt-in at `@pinkaphant/kolmo/shaders/tsl` |
|
|
29
|
+
| `@pinkaphant/kolmo/importer` | [src/importer/index.ts](./src/importer/index.ts) | `<GlbImportGate>` ([GlbImportGate.tsx](./src/importer/GlbImportGate.tsx)), `<ChopShopPanel>`, `<DomainWorkshopPanel>` (`c12`, `launcher`, `person`, authenticated R2 vault upload), zero-WASM USD intake ([usdToGlb.ts](./src/importer/usdToGlb.ts)), and W3C WebMCP (`importer_*` tools in [importerWebMcp.ts](./src/importer/importerWebMcp.ts)) |
|
|
30
|
+
| `@pinkaphant/kolmo/junk` | [src/junk/index.ts](./src/junk/index.ts) | `<KolmoJunk>` ([KolmoJunk.tsx](./src/junk/KolmoJunk.tsx)), `<DestructibleTarget>`, multi-LOD cans & bottles, world-space decals, and BVH shattering (`<ShardPieces>`) |
|
|
31
|
+
| `@pinkaphant/kolmo/body` | [src/body/index.ts](./src/body/index.ts) | `1.75 m` SI standing capsule (`BODY_SI`, `bodySpawnPosition`, `withExcludeCharacterRay`), `<KhrBody>`, and zero-lag `<HeldItem>` |
|
|
30
32
|
|
|
31
33
|
## Flagship Games Inside `Kolmo/games/` (Excluded from npm Tarball)
|
|
32
34
|
|
|
33
|
-
1. **`Longline`** ([games/longline/LonglineGame.tsx](./games/longline/LonglineGame.tsx) · `vite.longline.config.ts`): Endless highway survival road trip on pure mainland `2304 m` Macro-Cells with `192 m` floating-origin rebasing (`FloatingBodyTrait`
|
|
34
|
-
2. **`Dust`** ([games/dust/DustGame.tsx](./games/dust/DustGame.tsx) · `vite.dust.config.ts`): `4096 m × 4096 m` procedural continent (`192 m` chunks, 4 biomes: Coastal Beach, Temperate Pine, Arid Desert, Alpine Snow, 5 C12 monuments), exact zero-drift `@khr3/c12` base building + Tool Cupboard privilege + Hammer upgrades (`Twig → Armored`), `5.56` Carbine + C4 splash raiding,
|
|
35
|
+
1. **`Longline`** ([games/longline/LonglineGame.tsx](./games/longline/LonglineGame.tsx) · `vite.longline.config.ts`): Endless highway survival road trip on pure mainland `2304 m` Macro-Cells with `192 m` floating-origin rebasing (`FloatingBodyTrait` + `ShiftedFixedBody`), `VehicleVitalsTrait` (petrol, coolant, 10W-40 oil, radiator temp, battery, stall), enterable C12 roadside garages/gas stations with hinged `DOOR_HINGE_SPEC` doors, physical jerrycans, sun arc, and IndexedDB delta saves.
|
|
36
|
+
2. **`Dust`** ([games/dust/DustGame.tsx](./games/dust/DustGame.tsx) · `vite.dust.config.ts`): `4096 m × 4096 m` procedural continent (`192 m` chunks, 4 biomes: Coastal Beach, Temperate Pine, Arid Desert, Alpine Snow, 5 solid C12 monuments), exact zero-drift `@khr3/c12` base building + Tool Cupboard privilege + Hammer upgrades (`Twig → Armored`), `5.56` Carbine + C4 splash raiding, critically-damped **Laser Gravity Toolgun**, and Cloudflare SQLite Durable Object (`DustWorldDO`) multiplayer sync with RS256 Cloudflare Access JWT security.
|
|
35
37
|
|
|
36
38
|
## Commands
|
|
37
39
|
|
|
38
40
|
```sh
|
|
39
41
|
npm run dev # Launch Kolmo Studio: Sandbox + Longline + Dust + 2-Step Gate
|
|
40
42
|
npm run typecheck # tsc --noEmit
|
|
41
|
-
npm run build:lib # Build publishable @pinkaphant/kolmo dist/ + .d.ts
|
|
43
|
+
npm run build:lib # Build publishable @pinkaphant/kolmo dist/ + .d.ts (preserveModules)
|
|
42
44
|
npx vite build -c vite.longline.config.ts # Build standalone Longline Worker bundle
|
|
43
45
|
npx vite build -c vite.dust.config.ts # Build standalone Dust Worker bundle
|
|
44
|
-
npm test # Full headless Rapier + C12 + Longline (>2500m) + Dust + DO suite
|
|
46
|
+
npm test # Full headless R3F + Rapier + C12 + Longline (>2500m) + Dust + DO suite
|
|
45
47
|
```
|
package/bin/kolmo.mjs
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
+
const kolmoPkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
6
|
+
|
|
5
7
|
const args = process.argv.slice(2);
|
|
6
8
|
const cmd = args[0];
|
|
7
9
|
if (cmd !== "create" && cmd !== "init") {
|
|
@@ -23,13 +25,6 @@ if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
|
23
25
|
fs.mkdirSync(path.join(targetDir, "src"), { recursive: true });
|
|
24
26
|
const pkgName = path.basename(targetDir).toLowerCase().replace(/[^a-z0-9-_]/g, "-");
|
|
25
27
|
|
|
26
|
-
const SINGLETON_DEDUPE = [
|
|
27
|
-
"react", "react-dom", "three", "@react-three/fiber",
|
|
28
|
-
"@react-three/drei", "@react-three/rapier", "@react-three/uikit",
|
|
29
|
-
"@pmndrs/uikit", "@preact/signals-core", "@dimforge/rapier3d-compat",
|
|
30
|
-
"@pinkaphant/ecctrl", "koota", "zustand",
|
|
31
|
-
];
|
|
32
|
-
|
|
33
28
|
fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
34
29
|
name: pkgName,
|
|
35
30
|
version: "0.1.0",
|
|
@@ -38,20 +33,21 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
38
33
|
scripts: {
|
|
39
34
|
dev: "vite",
|
|
40
35
|
typecheck: "tsc --noEmit",
|
|
36
|
+
test: "node --import tsx --test \"src/**/*.test.ts*\"",
|
|
41
37
|
build: "vite build",
|
|
42
38
|
deploy: "npm run build && wrangler deploy",
|
|
43
39
|
},
|
|
44
40
|
dependencies: {
|
|
45
|
-
"@dimforge/rapier3d-compat": "
|
|
46
|
-
"@khr3/assets":
|
|
47
|
-
"@khr3/c12":
|
|
48
|
-
"@khr3/core":
|
|
49
|
-
"@khr3/launchers":
|
|
50
|
-
"@khr3/vehicles":
|
|
51
|
-
"@pinkaphant/ecctrl":
|
|
52
|
-
"@pinkaphant/kolmo":
|
|
41
|
+
"@dimforge/rapier3d-compat": "0.19.2",
|
|
42
|
+
"@khr3/assets": kolmoPkg.dependencies["@khr3/assets"],
|
|
43
|
+
"@khr3/c12": kolmoPkg.dependencies["@khr3/c12"],
|
|
44
|
+
"@khr3/core": kolmoPkg.dependencies["@khr3/core"],
|
|
45
|
+
"@khr3/launchers": kolmoPkg.dependencies["@khr3/launchers"],
|
|
46
|
+
"@khr3/vehicles": kolmoPkg.dependencies["@khr3/vehicles"],
|
|
47
|
+
"@pinkaphant/ecctrl": kolmoPkg.peerDependencies["@pinkaphant/ecctrl"],
|
|
48
|
+
"@pinkaphant/kolmo": `^${kolmoPkg.version}`,
|
|
53
49
|
"@pmndrs/uikit": "^1.0.78",
|
|
54
|
-
"@preact/signals-core": "^1.5
|
|
50
|
+
"@preact/signals-core": "^1.14.5",
|
|
55
51
|
"@react-three/drei": "^10.7.7",
|
|
56
52
|
"@react-three/fiber": "^9.6.1",
|
|
57
53
|
"@react-three/rapier": "^2.2.0",
|
|
@@ -68,52 +64,21 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
68
64
|
"@types/react-dom": "^19.2.3",
|
|
69
65
|
"@types/three": "^0.184.0",
|
|
70
66
|
"@vitejs/plugin-react": "^6.1.1",
|
|
67
|
+
"tsx": "^4.23.15",
|
|
71
68
|
"typescript": "^6.0.3",
|
|
72
69
|
"vite": "^8.3.8",
|
|
73
70
|
"wrangler": "^4.164.0",
|
|
74
71
|
},
|
|
75
72
|
}, null, 2));
|
|
76
73
|
|
|
77
|
-
fs.writeFileSync(path.join(targetDir, "vite.config.ts"), `import
|
|
78
|
-
import
|
|
79
|
-
import
|
|
80
|
-
import { defineConfig, type Plugin } from "vite";
|
|
81
|
-
|
|
82
|
-
function externalizeRapierWasm(): Plugin {
|
|
83
|
-
return {
|
|
84
|
-
name: "kolmo-externalize-rapier-wasm",
|
|
85
|
-
apply: "build",
|
|
86
|
-
transform(code, id) {
|
|
87
|
-
if (!id.replace(/\\\\/g, "/").endsWith("/@dimforge/rapier3d-compat/rapier.mjs")) return null;
|
|
88
|
-
const wasmPath = path.join(path.dirname(id), "rapier_wasm3d_bg.wasm");
|
|
89
|
-
if (!fs.existsSync(wasmPath)) return null;
|
|
90
|
-
const refId = this.emitFile({ type: "asset", name: "rapier_wasm3d_bg.wasm", source: fs.readFileSync(wasmPath) });
|
|
91
|
-
return {
|
|
92
|
-
code: code.replace(/[\\w$]+\\.toByteArray\\(["']AGFzbQE[A-Za-z0-9+/=]+["']\\)\\.buffer/, \`import.meta.ROLLUP_FILE_URL_\${refId}\`),
|
|
93
|
-
map: null,
|
|
94
|
-
};
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
}
|
|
74
|
+
fs.writeFileSync(path.join(targetDir, "vite.config.ts"), `import react from "@vitejs/plugin-react";
|
|
75
|
+
import { defineConfig } from "vite";
|
|
76
|
+
import { KOLMO_ROLLDOWN_BUILD, KOLMO_SINGLETON_DEDUPE, externalizeRapierWasm } from "@pinkaphant/kolmo/vite";
|
|
98
77
|
|
|
99
78
|
export default defineConfig({
|
|
100
79
|
plugins: [react(), externalizeRapierWasm()],
|
|
101
|
-
resolve: { dedupe:
|
|
102
|
-
build:
|
|
103
|
-
chunkSizeWarningLimit: 1100,
|
|
104
|
-
rolldownOptions: {
|
|
105
|
-
output: {
|
|
106
|
-
codeSplitting: {
|
|
107
|
-
groups: [
|
|
108
|
-
{ name: "vendor-react", test: /[\\\\/]node_modules[\\\\/](react|react-dom|scheduler)[\\\\/]/, priority: 40 },
|
|
109
|
-
{ name: "vendor-three", test: /[\\\\/]node_modules[\\\\/](three|three-stdlib|maath|camera-controls)[\\\\/]/, priority: 30, includeDependenciesRecursively: false },
|
|
110
|
-
{ name: "vendor-physics", test: /[\\\\/]node_modules[\\\\/](@dimforge\\/rapier3d-compat|@react-three\\/rapier|@pinkaphant\\/ecctrl)[\\\\/]/, priority: 20, includeDependenciesRecursively: false },
|
|
111
|
-
{ name: "vendor-r3f", test: /[\\\\/]node_modules[\\\\/]/, priority: 10, includeDependenciesRecursively: false },
|
|
112
|
-
],
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
80
|
+
resolve: { dedupe: KOLMO_SINGLETON_DEDUPE },
|
|
81
|
+
build: KOLMO_ROLLDOWN_BUILD,
|
|
117
82
|
});\n`);
|
|
118
83
|
|
|
119
84
|
fs.writeFileSync(path.join(targetDir, "tsconfig.json"), JSON.stringify({
|
|
@@ -121,6 +86,8 @@ fs.writeFileSync(path.join(targetDir, "tsconfig.json"), JSON.stringify({
|
|
|
121
86
|
target: "ES2022",
|
|
122
87
|
module: "ESNext",
|
|
123
88
|
moduleResolution: "Bundler",
|
|
89
|
+
allowImportingTsExtensions: true,
|
|
90
|
+
types: ["node"],
|
|
124
91
|
jsx: "react-jsx",
|
|
125
92
|
strict: true,
|
|
126
93
|
skipLibCheck: true,
|
|
@@ -135,7 +102,7 @@ fs.writeFileSync(path.join(targetDir, "wrangler.jsonc"), JSON.stringify({
|
|
|
135
102
|
assets: { directory: "./dist", not_found_handling: "single-page-application" },
|
|
136
103
|
}, null, 2));
|
|
137
104
|
|
|
138
|
-
fs.writeFileSync(path.join(targetDir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:100%;overflow:hidden;background:#05070e}</style></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>\n
|
|
105
|
+
fs.writeFileSync(path.join(targetDir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"/><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:100%;overflow:hidden;background:#05070e}</style></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>\n`.replace('<meta charset="utf-8"/><meta charset="utf-8"/>', '<meta charset="utf-8"/>'));
|
|
139
106
|
|
|
140
107
|
const appSrc = template === "garage"
|
|
141
108
|
? `import { GlbImportGate } from "@pinkaphant/kolmo/importer";\nexport function App() {\n return <GlbImportGate />;\n}\n`
|
|
@@ -145,5 +112,6 @@ const appSrc = template === "garage"
|
|
|
145
112
|
|
|
146
113
|
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), appSrc);
|
|
147
114
|
fs.writeFileSync(path.join(targetDir, "src/main.tsx"), `import { createRoot } from "react-dom/client";\nimport { App } from "./App.tsx";\ncreateRoot(document.getElementById("root")!).render(<App />);\n`);
|
|
115
|
+
fs.writeFileSync(path.join(targetDir, "src/App.test.ts"), `import assert from "node:assert/strict";\nimport { describe, it } from "node:test";\nimport { App } from "./App.tsx";\n\ndescribe("${pkgName} smoke test", () => {\n it("exports App component", () => {\n assert.equal(typeof App, "function");\n });\n});\n`);
|
|
148
116
|
|
|
149
117
|
console.log(`Scaffolded ${template} project in ${targetDir}\nNext: cd ${dirArg} && npm install && npm run dev`);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { withExcludeCharacterRay as e } from "./bodySi.js";
|
|
2
|
+
import { useCallback as t, useContext as n, useImperativeHandle as r, useLayoutEffect as i, useMemo as a, useRef as o } from "react";
|
|
3
|
+
import * as s from "three";
|
|
4
|
+
import { useFrame as c } from "@react-three/fiber";
|
|
5
|
+
import { JointRegistryContext as l, KhrCollider as u, KhrValidationError as d, claimBundleMount as f, releaseBundleMount as p } from "@khr3/core";
|
|
6
|
+
import { Fragment as m, jsx as h, jsxs as g } from "react/jsx-runtime";
|
|
7
|
+
import { RigidBody as _, useRapier as v } from "@react-three/rapier";
|
|
8
|
+
// src/body/HeldItem.tsx
|
|
9
|
+
var y = new s.Vector3(), b = new s.Vector3(), x = new s.Quaternion(), S = new s.Matrix4(), C = new s.Vector3(), w = new s.Quaternion(), T = new s.Vector3(), E = 1e5;
|
|
10
|
+
function D(e, t) {
|
|
11
|
+
if (t.kind === "fixed") return 0;
|
|
12
|
+
if (t.kind === "prismatic") {
|
|
13
|
+
if (!(e.mass > 0)) throw new d(`kolmo/body: Prismatic joint "${e.nodeName}" requires positive mass, got ${e.mass}`);
|
|
14
|
+
return e.mass;
|
|
15
|
+
}
|
|
16
|
+
y.fromArray(t.axis).normalize(), x.fromArray(e.inertiaOrientation).invert();
|
|
17
|
+
let n = y.clone().applyQuaternion(x), [r, i, a] = e.inertiaDiagonal, o = r * n.x * n.x + i * n.y * n.y + a * n.z * n.z;
|
|
18
|
+
b.fromArray(e.centerOfMass);
|
|
19
|
+
let s = b.dot(y), c = o + e.mass * (b.lengthSq() - s * s);
|
|
20
|
+
if (!(c > 0)) throw new d(`kolmo/body: Revolute joint "${e.nodeName}" requires positive inertia, got ${c}`);
|
|
21
|
+
return c;
|
|
22
|
+
}
|
|
23
|
+
var O = (e) => new s.Matrix4().compose(new s.Vector3().fromArray(e.localPosition), new s.Quaternion().fromArray(e.localQuaternion), new s.Vector3(1, 1, 1));
|
|
24
|
+
function k({ ref: y, bundle: b, socket: x, bodyRef: k, parentSocketObject: A, userData: j }) {
|
|
25
|
+
let { world: M } = v(), N = n(l), P = a(() => E++, []), F = o(null), I = o(null), L = o(/* @__PURE__ */ new Map()), R = a(() => e(j), [j]), { rootPose: z, invRoot: B, colliderEntries: V } = a(() => {
|
|
26
|
+
let e = b.bodies.find((e) => !e.joint) ?? b.bodies[0], t = e ? O(e) : new s.Matrix4(), n = t.clone().invert(), r = new s.Vector3(), i = new s.Quaternion(), a = new s.Vector3(), o = [];
|
|
27
|
+
for (let e of b.bodies) {
|
|
28
|
+
let t = n.clone().multiply(O(e));
|
|
29
|
+
for (let n = 0; n < e.colliders.length; n++) {
|
|
30
|
+
let c = e.colliders[n], l = new s.Matrix4().compose(new s.Vector3().fromArray(c.localPosition), new s.Quaternion().fromArray(c.localQuaternion), new s.Vector3(1, 1, 1));
|
|
31
|
+
t.clone().multiply(l).decompose(r, i, a), i.normalize(), o.push({
|
|
32
|
+
key: `${e.nodeName}:${n}`,
|
|
33
|
+
nodeName: e.nodeName,
|
|
34
|
+
spec: c,
|
|
35
|
+
local: l,
|
|
36
|
+
restPos: [
|
|
37
|
+
r.x,
|
|
38
|
+
r.y,
|
|
39
|
+
r.z
|
|
40
|
+
],
|
|
41
|
+
restQuat: [
|
|
42
|
+
i.x,
|
|
43
|
+
i.y,
|
|
44
|
+
i.z,
|
|
45
|
+
i.w
|
|
46
|
+
],
|
|
47
|
+
ref: { current: null }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
rootPose: t,
|
|
53
|
+
invRoot: n,
|
|
54
|
+
colliderEntries: o
|
|
55
|
+
};
|
|
56
|
+
}, [b]), H = t((e) => {
|
|
57
|
+
let t = F.current, n = A ?? k?.current?.socket(x) ?? I.current;
|
|
58
|
+
t && n && (b.scene.parent !== n && n.add(b.scene), b.scene.updateWorldMatrix(!0, !1), S.multiplyMatrices(b.scene.matrixWorld, z), S.decompose(C, w, T), w.normalize(), e ? (t.setTranslation(C, !0), t.setRotation(w, !0), t.setNextKinematicTranslation(C), t.setNextKinematicRotation(w), M.propagateModifiedBodyPositionsToColliders()) : (t.setNextKinematicTranslation(C), t.setNextKinematicRotation(w)));
|
|
59
|
+
}, [
|
|
60
|
+
b,
|
|
61
|
+
z,
|
|
62
|
+
A,
|
|
63
|
+
k,
|
|
64
|
+
x,
|
|
65
|
+
M
|
|
66
|
+
]);
|
|
67
|
+
return i(() => {
|
|
68
|
+
f(b, "HeldItem");
|
|
69
|
+
let e = b.scene.position.clone(), t = b.scene.quaternion.clone(), n = b.scene.parent, r = b.sockets.grip_primary ?? b.sockets.IK_Palm_Primary;
|
|
70
|
+
r ? b.scene.position.set(-r[0], -r[1], -r[2]) : b.scene.position.set(0, 0, 0);
|
|
71
|
+
let i = A ?? k?.current?.socket(x) ?? I.current;
|
|
72
|
+
i && b.scene.parent !== i && i.add(b.scene);
|
|
73
|
+
let a = new Map(b.bodies.map((e) => [e.nodeName, e])), o = /* @__PURE__ */ new Map();
|
|
74
|
+
for (let e of b.bodies) {
|
|
75
|
+
let t = e.joint;
|
|
76
|
+
if (!t) continue;
|
|
77
|
+
let n = a.get(t.connectedNodeName), r = B.clone().multiply(O(e)), i = n?.joint ? O(n).invert().multiply(O(e)) : r, c = V.filter((t) => t.nodeName === e.nodeName).map((e) => ({
|
|
78
|
+
ref: e.ref,
|
|
79
|
+
local: e.local
|
|
80
|
+
})), l = t.drive;
|
|
81
|
+
o.set(e.nodeName, {
|
|
82
|
+
assemblyId: P,
|
|
83
|
+
nodeName: e.nodeName,
|
|
84
|
+
role: t.role ?? e.role,
|
|
85
|
+
kind: t.kind,
|
|
86
|
+
object: e.object,
|
|
87
|
+
axis: new s.Vector3().fromArray(t.axis).normalize(),
|
|
88
|
+
restPosition: e.object.position.clone(),
|
|
89
|
+
restQuaternion: e.object.quaternion.clone(),
|
|
90
|
+
q: 0,
|
|
91
|
+
v: 0,
|
|
92
|
+
positionTarget: l?.positionTarget ?? null,
|
|
93
|
+
velocityTarget: l?.velocityTarget ?? 0,
|
|
94
|
+
drive: l,
|
|
95
|
+
limits: t.limits ? [t.limits[0], t.limits[1]] : null,
|
|
96
|
+
limitStiffness: t.limitStiffness ?? null,
|
|
97
|
+
limitDamping: t.limitDamping ?? 0,
|
|
98
|
+
inertia: D(e, t),
|
|
99
|
+
parent: null,
|
|
100
|
+
restRelParent: i,
|
|
101
|
+
current: i.clone(),
|
|
102
|
+
stamp: -1,
|
|
103
|
+
colliders: c
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
for (let e of b.bodies) {
|
|
107
|
+
if (!e.joint) continue;
|
|
108
|
+
let t = o.get(e.nodeName);
|
|
109
|
+
t.parent = o.get(e.joint.connectedNodeName) ?? null, N?.add(t);
|
|
110
|
+
}
|
|
111
|
+
return L.current = o, H(!0), () => {
|
|
112
|
+
for (let e of o.values()) N?.delete(e), e.object.position.copy(e.restPosition), e.object.quaternion.copy(e.restQuaternion);
|
|
113
|
+
L.current = /* @__PURE__ */ new Map(), b.scene.parent && b.scene.parent.remove(b.scene), n && n.add(b.scene), b.scene.position.copy(e), b.scene.quaternion.copy(t), p(b);
|
|
114
|
+
};
|
|
115
|
+
}, [
|
|
116
|
+
b,
|
|
117
|
+
x,
|
|
118
|
+
k,
|
|
119
|
+
A,
|
|
120
|
+
N,
|
|
121
|
+
P,
|
|
122
|
+
B,
|
|
123
|
+
V,
|
|
124
|
+
H
|
|
125
|
+
]), c(() => {
|
|
126
|
+
H(!1);
|
|
127
|
+
}), r(y, () => {
|
|
128
|
+
let e = (e, t) => {
|
|
129
|
+
if (!e.drive || e.drive.stiffness === void 0) throw new d(`Joint "${e.nodeName}" has no authored drive stiffness; cannot set a position target`);
|
|
130
|
+
let n = e.limits ? Math.max(e.limits[0], Math.min(e.limits[1], t)) : t;
|
|
131
|
+
return e.positionTarget = n, n;
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
socket: x,
|
|
135
|
+
get rigidBody() {
|
|
136
|
+
return F.current;
|
|
137
|
+
},
|
|
138
|
+
setJointTarget(t, n) {
|
|
139
|
+
let r = L.current.get(t);
|
|
140
|
+
if (!r) throw new d(`kolmo/body: HeldItem has no joint named "${t}"`);
|
|
141
|
+
return e(r, n);
|
|
142
|
+
},
|
|
143
|
+
setRoleTarget(t, n) {
|
|
144
|
+
let r = !1, i = n;
|
|
145
|
+
for (let a of L.current.values()) a.role === t && (i = e(a, n), r = !0);
|
|
146
|
+
if (!r) throw new d(`kolmo/body: HeldItem has no joint with role "${t}"`);
|
|
147
|
+
return i;
|
|
148
|
+
},
|
|
149
|
+
getRoleValue(e) {
|
|
150
|
+
for (let t of L.current.values()) if (t.role === e) return t.q;
|
|
151
|
+
throw new d(`kolmo/body: HeldItem has no joint with role "${e}"`);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}, [x]), /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h("group", {
|
|
155
|
+
ref: I,
|
|
156
|
+
name: `HeldItem_Fallback_${x}`
|
|
157
|
+
}), /* @__PURE__ */ h(_, {
|
|
158
|
+
ref: F,
|
|
159
|
+
type: "kinematicPosition",
|
|
160
|
+
colliders: !1,
|
|
161
|
+
sensor: !0,
|
|
162
|
+
userData: R,
|
|
163
|
+
children: V.map((e) => /* @__PURE__ */ h(u, {
|
|
164
|
+
ref: e.ref,
|
|
165
|
+
c: e.spec,
|
|
166
|
+
position: e.restPos,
|
|
167
|
+
quaternion: e.restQuat
|
|
168
|
+
}, e.key))
|
|
169
|
+
})] });
|
|
170
|
+
}
|
|
171
|
+
export { k as HeldItem };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { BODY_SI as e, BODY_SOCKET_IDS as t, bodyEyeOffsetY as n, bodyRestCenterY as r, stepCameraSync as i } from "./bodySi.js";
|
|
2
|
+
import { useEffect as a, useImperativeHandle as o, useMemo as s, useRef as c } from "react";
|
|
3
|
+
import { useFrame as l, useThree as u } from "@react-three/fiber";
|
|
4
|
+
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
5
|
+
import { Ecctrl as m } from "@pinkaphant/ecctrl";
|
|
6
|
+
import { EcctrlCameraControls as h } from "@pinkaphant/ecctrl/camera";
|
|
7
|
+
// src/body/KhrBody.tsx
|
|
8
|
+
var g = Object.freeze({
|
|
9
|
+
Socket_Hand_R: [
|
|
10
|
+
.22,
|
|
11
|
+
-.18,
|
|
12
|
+
-.38
|
|
13
|
+
],
|
|
14
|
+
Socket_Hand_L: [
|
|
15
|
+
-.22,
|
|
16
|
+
-.18,
|
|
17
|
+
-.38
|
|
18
|
+
],
|
|
19
|
+
Socket_Head: [
|
|
20
|
+
0,
|
|
21
|
+
0,
|
|
22
|
+
-.12
|
|
23
|
+
],
|
|
24
|
+
Socket_Back: [
|
|
25
|
+
0,
|
|
26
|
+
-.25,
|
|
27
|
+
.28
|
|
28
|
+
]
|
|
29
|
+
}), _ = {
|
|
30
|
+
forward: !1,
|
|
31
|
+
backward: !1,
|
|
32
|
+
leftward: !1,
|
|
33
|
+
rightward: !1,
|
|
34
|
+
run: !1,
|
|
35
|
+
jump: !1
|
|
36
|
+
};
|
|
37
|
+
function v({ active: e, ecctrlRef: t }) {
|
|
38
|
+
let n = c({
|
|
39
|
+
w: !1,
|
|
40
|
+
s: !1,
|
|
41
|
+
a: !1,
|
|
42
|
+
d: !1,
|
|
43
|
+
shift: !1,
|
|
44
|
+
space: !1,
|
|
45
|
+
dirty: !1
|
|
46
|
+
}), r = c(e);
|
|
47
|
+
return a(() => {
|
|
48
|
+
if (!e || typeof window > "u" || typeof window.addEventListener != "function") return;
|
|
49
|
+
let t = (e) => (t) => {
|
|
50
|
+
let r = n.current;
|
|
51
|
+
t.code === "KeyW" || t.code === "ArrowUp" ? r.w !== e && (r.w = e, r.dirty = !0) : t.code === "KeyS" || t.code === "ArrowDown" ? r.s !== e && (r.s = e, r.dirty = !0) : t.code === "KeyA" || t.code === "ArrowLeft" ? r.a !== e && (r.a = e, r.dirty = !0) : t.code === "KeyD" || t.code === "ArrowRight" ? r.d !== e && (r.d = e, r.dirty = !0) : t.code === "ShiftLeft" || t.code === "ShiftRight" ? r.shift !== e && (r.shift = e, r.dirty = !0) : t.code === "Space" && r.space !== e && (r.space = e, r.dirty = !0);
|
|
52
|
+
}, r = () => {
|
|
53
|
+
let e = n.current;
|
|
54
|
+
(e.w || e.s || e.a || e.d || e.shift || e.space) && (e.w = !1, e.s = !1, e.a = !1, e.d = !1, e.shift = !1, e.space = !1, e.dirty = !0);
|
|
55
|
+
}, i = t(!0), a = t(!1);
|
|
56
|
+
return window.addEventListener("keydown", i), window.addEventListener("keyup", a), window.addEventListener("blur", r), () => {
|
|
57
|
+
window.removeEventListener("keydown", i), window.removeEventListener("keyup", a), window.removeEventListener("blur", r);
|
|
58
|
+
};
|
|
59
|
+
}, [e]), l(() => {
|
|
60
|
+
let i = t.current;
|
|
61
|
+
if (!i) return;
|
|
62
|
+
if (!e) {
|
|
63
|
+
if (r.current) {
|
|
64
|
+
let e = n.current;
|
|
65
|
+
e.w = !1, e.s = !1, e.a = !1, e.d = !1, e.shift = !1, e.space = !1, e.dirty = !1, _.forward = !1, _.backward = !1, _.leftward = !1, _.rightward = !1, _.run = !1, _.jump = !1, i.setMovement(_), r.current = !1;
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
r.current = !0;
|
|
70
|
+
let a = n.current;
|
|
71
|
+
a.dirty && (a.dirty = !1, _.forward = a.w, _.backward = a.s, _.leftward = a.a, _.rightward = a.d, _.run = a.shift, _.jump = a.space, i.setMovement(_));
|
|
72
|
+
}), null;
|
|
73
|
+
}
|
|
74
|
+
function y({ ref: a, si: l = e, smoothCamera: _ = !1, makeDefaultCamera: y = !0, enableInput: x = !0, enable: S = !0, viewModelChildren: C, socketOffsets: w, children: T, userData: E, position: D, ...O }) {
|
|
75
|
+
let k = c(null), A = c(null), j = c(null), M = c({
|
|
76
|
+
Socket_Hand_R: null,
|
|
77
|
+
Socket_Hand_L: null,
|
|
78
|
+
Socket_Head: null,
|
|
79
|
+
Socket_Back: null
|
|
80
|
+
}), N = s(() => n(l), [l]), P = s(() => [
|
|
81
|
+
0,
|
|
82
|
+
r(l),
|
|
83
|
+
0
|
|
84
|
+
], [l]), F = u((e) => typeof e.gl?.domElement?.setAttribute == "function"), I = s(() => {
|
|
85
|
+
let e = E ?? {}, t = e.ecctrl ?? {};
|
|
86
|
+
return {
|
|
87
|
+
...e,
|
|
88
|
+
ecctrl: {
|
|
89
|
+
excludeVehicleRay: !0,
|
|
90
|
+
...t
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}, [E]);
|
|
94
|
+
return o(a, () => ({
|
|
95
|
+
get ecctrl() {
|
|
96
|
+
return k.current;
|
|
97
|
+
},
|
|
98
|
+
get cameraControls() {
|
|
99
|
+
return A.current;
|
|
100
|
+
},
|
|
101
|
+
socket(e) {
|
|
102
|
+
return M.current[e] ?? null;
|
|
103
|
+
},
|
|
104
|
+
syncCameraStep(e) {
|
|
105
|
+
i(A.current, e, N, _, k.current?.bodyYAxis);
|
|
106
|
+
}
|
|
107
|
+
}), [N, _]), /* @__PURE__ */ p(d, { children: [
|
|
108
|
+
/* @__PURE__ */ f(v, {
|
|
109
|
+
active: !!(S && x),
|
|
110
|
+
ecctrlRef: k
|
|
111
|
+
}),
|
|
112
|
+
/* @__PURE__ */ f(m, {
|
|
113
|
+
ref: k,
|
|
114
|
+
enable: S,
|
|
115
|
+
position: D ?? P,
|
|
116
|
+
capsuleHalfHeight: l.capsuleHalfHeight,
|
|
117
|
+
capsuleRadius: l.capsuleRadius,
|
|
118
|
+
floatHeight: l.floatHeight,
|
|
119
|
+
...O,
|
|
120
|
+
userData: I,
|
|
121
|
+
children: T
|
|
122
|
+
}),
|
|
123
|
+
F ? /* @__PURE__ */ f(h, {
|
|
124
|
+
ref: A,
|
|
125
|
+
makeDefault: y
|
|
126
|
+
}) : null,
|
|
127
|
+
/* @__PURE__ */ f(b, {
|
|
128
|
+
enable: S,
|
|
129
|
+
makeDefaultCamera: y,
|
|
130
|
+
ecctrlRef: k,
|
|
131
|
+
camControlsRef: A,
|
|
132
|
+
viewModelGroupRef: j,
|
|
133
|
+
eyeOffsetY: N,
|
|
134
|
+
smoothCamera: _
|
|
135
|
+
}),
|
|
136
|
+
/* @__PURE__ */ p("group", {
|
|
137
|
+
ref: j,
|
|
138
|
+
name: "KhrBody_ViewModel",
|
|
139
|
+
children: [t.map((e) => {
|
|
140
|
+
let t = w?.[e] ?? g[e];
|
|
141
|
+
return /* @__PURE__ */ f("group", {
|
|
142
|
+
name: e,
|
|
143
|
+
position: [
|
|
144
|
+
t[0],
|
|
145
|
+
t[1],
|
|
146
|
+
t[2]
|
|
147
|
+
],
|
|
148
|
+
ref: (t) => {
|
|
149
|
+
M.current[e] = t;
|
|
150
|
+
}
|
|
151
|
+
}, e);
|
|
152
|
+
}), C]
|
|
153
|
+
})
|
|
154
|
+
] });
|
|
155
|
+
}
|
|
156
|
+
function b({ enable: e, makeDefaultCamera: t, ecctrlRef: n, camControlsRef: r, viewModelGroupRef: a, eyeOffsetY: o, smoothCamera: s }) {
|
|
157
|
+
return l((c) => {
|
|
158
|
+
if (!e) return;
|
|
159
|
+
let l = n.current;
|
|
160
|
+
if (l) {
|
|
161
|
+
if (r.current) i(r.current, l.currPos, o, s, l.bodyYAxis);
|
|
162
|
+
else if (t) {
|
|
163
|
+
let e = l.bodyYAxis;
|
|
164
|
+
c.camera.position.set(l.currPos.x + e.x * o, l.currPos.y + e.y * o, l.currPos.z + e.z * o);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
let u = a.current;
|
|
168
|
+
u && (u.position.copy(c.camera.position), u.quaternion.copy(c.camera.quaternion));
|
|
169
|
+
}), null;
|
|
170
|
+
}
|
|
171
|
+
export { y as KhrBody, i as stepCameraSync };
|
package/dist/body/bodySi.d.ts
CHANGED
|
@@ -18,17 +18,6 @@ export interface BodySiConstants {
|
|
|
18
18
|
}
|
|
19
19
|
/** 1.75 m standing adult: 2 * 0.50 + 2 * 0.30 + 0.15. */
|
|
20
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.96;
|
|
26
|
-
readonly decDeltaTime: 0.9;
|
|
27
|
-
readonly slideGripFactor: 1;
|
|
28
|
-
readonly moveImpulsePointOffset: 0;
|
|
29
|
-
readonly airDragFactor: 0.85;
|
|
30
|
-
readonly enableToggleRun: false;
|
|
31
|
-
}>;
|
|
32
21
|
export type BodySocketId = "Socket_Hand_R" | "Socket_Hand_L" | "Socket_Head" | "Socket_Back";
|
|
33
22
|
export declare const BODY_SOCKET_IDS: readonly BodySocketId[];
|
|
34
23
|
/** Rigid-body centre height when standing at rest on flat ground. */
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
"Socket_Hand_R",
|
|
11
|
+
"Socket_Hand_L",
|
|
12
|
+
"Socket_Head",
|
|
13
|
+
"Socket_Back"
|
|
14
|
+
]);
|
|
15
|
+
function n(e) {
|
|
16
|
+
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)}`);
|
|
17
|
+
if (!(e.capsuleRadius > 0)) throw RangeError("kolmo/body: capsuleRadius must be > 0");
|
|
18
|
+
}
|
|
19
|
+
function r(t = e) {
|
|
20
|
+
return n(t), t.floatHeight + t.capsuleRadius + t.capsuleHalfHeight;
|
|
21
|
+
}
|
|
22
|
+
function i(t = e) {
|
|
23
|
+
return r(t) + t.capsuleHalfHeight + t.capsuleRadius;
|
|
24
|
+
}
|
|
25
|
+
function a(t = e) {
|
|
26
|
+
let n = t.eyeHeight - r(t);
|
|
27
|
+
if (!(n > 0)) throw RangeError("kolmo/body: eyeHeight must sit above the body centre");
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
function o(t, n, i, a = e) {
|
|
31
|
+
return [
|
|
32
|
+
t,
|
|
33
|
+
n + r(a),
|
|
34
|
+
i
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
function s(e) {
|
|
38
|
+
let t = e?.ecctrl ?? {};
|
|
39
|
+
return {
|
|
40
|
+
...e ?? {},
|
|
41
|
+
ecctrl: {
|
|
42
|
+
...t,
|
|
43
|
+
excludeCharacterRay: !0
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function c(e, t, n, r, i) {
|
|
48
|
+
if (!e) return;
|
|
49
|
+
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;
|
|
50
|
+
e.moveTo?.(a, o, s, r);
|
|
51
|
+
}
|
|
52
|
+
export { e as BODY_SI, t as BODY_SOCKET_IDS, a as bodyEyeOffsetY, r as bodyRestCenterY, o as bodySpawnPosition, i as bodyStandingHeight, c as stepCameraSync, s as withExcludeCharacterRay };
|
package/dist/body/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BODY_SI, BODY_SOCKET_IDS, bodyEyeOffsetY, bodyRestCenterY, bodySpawnPosition, bodyStandingHeight, stepCameraSync, withExcludeCharacterRay, type BodySiConstants, type BodySocketId, } from "./bodySi.js";
|
|
2
2
|
export { KhrBody, type KhrBodyHandle, type KhrBodyProps } from "./KhrBody.js";
|
|
3
3
|
export { HeldItem, type HeldItemHandle, type HeldItemProps } from "./HeldItem.js";
|