@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
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
|
-
| `@
|
|
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
|
@@ -23,13 +23,6 @@ if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
|
23
23
|
fs.mkdirSync(path.join(targetDir, "src"), { recursive: true });
|
|
24
24
|
const pkgName = path.basename(targetDir).toLowerCase().replace(/[^a-z0-9-_]/g, "-");
|
|
25
25
|
|
|
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
26
|
fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
34
27
|
name: pkgName,
|
|
35
28
|
version: "0.1.0",
|
|
@@ -38,21 +31,21 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
38
31
|
scripts: {
|
|
39
32
|
dev: "vite",
|
|
40
33
|
typecheck: "tsc --noEmit",
|
|
34
|
+
test: "node --import tsx --test \"src/**/*.test.ts*\"",
|
|
41
35
|
build: "vite build",
|
|
42
36
|
deploy: "npm run build && wrangler deploy",
|
|
43
37
|
},
|
|
44
38
|
dependencies: {
|
|
45
|
-
"@dimforge/rapier3d-compat": "
|
|
46
|
-
"@khr3/assets": "^0.2.
|
|
47
|
-
"@khr3/
|
|
48
|
-
"@khr3/
|
|
49
|
-
"@khr3/
|
|
50
|
-
"@khr3/
|
|
51
|
-
"@khr3/vehicles": "^0.1.2",
|
|
39
|
+
"@dimforge/rapier3d-compat": "0.19.2",
|
|
40
|
+
"@khr3/assets": "^0.2.2",
|
|
41
|
+
"@khr3/c12": "^0.3.1",
|
|
42
|
+
"@khr3/core": "^0.1.2",
|
|
43
|
+
"@khr3/launchers": "^0.2.2",
|
|
44
|
+
"@khr3/vehicles": "^0.1.3",
|
|
52
45
|
"@pinkaphant/ecctrl": "^2.0.4-beta.3",
|
|
53
|
-
"@pinkaphant/kolmo": "^0.1.
|
|
46
|
+
"@pinkaphant/kolmo": "^0.1.3",
|
|
54
47
|
"@pmndrs/uikit": "^1.0.78",
|
|
55
|
-
"@preact/signals-core": "^1.5
|
|
48
|
+
"@preact/signals-core": "^1.14.5",
|
|
56
49
|
"@react-three/drei": "^10.7.7",
|
|
57
50
|
"@react-three/fiber": "^9.6.1",
|
|
58
51
|
"@react-three/rapier": "^2.2.0",
|
|
@@ -69,52 +62,21 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
69
62
|
"@types/react-dom": "^19.2.3",
|
|
70
63
|
"@types/three": "^0.184.0",
|
|
71
64
|
"@vitejs/plugin-react": "^6.1.1",
|
|
65
|
+
"tsx": "^4.23.15",
|
|
72
66
|
"typescript": "^6.0.3",
|
|
73
67
|
"vite": "^8.3.8",
|
|
74
68
|
"wrangler": "^4.164.0",
|
|
75
69
|
},
|
|
76
70
|
}, null, 2));
|
|
77
71
|
|
|
78
|
-
fs.writeFileSync(path.join(targetDir, "vite.config.ts"), `import
|
|
79
|
-
import
|
|
80
|
-
import
|
|
81
|
-
import { defineConfig, type Plugin } from "vite";
|
|
82
|
-
|
|
83
|
-
function externalizeRapierWasm(): Plugin {
|
|
84
|
-
return {
|
|
85
|
-
name: "kolmo-externalize-rapier-wasm",
|
|
86
|
-
apply: "build",
|
|
87
|
-
transform(code, id) {
|
|
88
|
-
if (!id.replace(/\\\\/g, "/").endsWith("/@dimforge/rapier3d-compat/rapier.mjs")) return null;
|
|
89
|
-
const wasmPath = path.join(path.dirname(id), "rapier_wasm3d_bg.wasm");
|
|
90
|
-
if (!fs.existsSync(wasmPath)) return null;
|
|
91
|
-
const refId = this.emitFile({ type: "asset", name: "rapier_wasm3d_bg.wasm", source: fs.readFileSync(wasmPath) });
|
|
92
|
-
return {
|
|
93
|
-
code: code.replace(/[\\w$]+\\.toByteArray\\(["']AGFzbQE[A-Za-z0-9+/=]+["']\\)\\.buffer/, \`import.meta.ROLLUP_FILE_URL_\${refId}\`),
|
|
94
|
-
map: null,
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
72
|
+
fs.writeFileSync(path.join(targetDir, "vite.config.ts"), `import react from "@vitejs/plugin-react";
|
|
73
|
+
import { defineConfig } from "vite";
|
|
74
|
+
import { KOLMO_ROLLDOWN_BUILD, KOLMO_SINGLETON_DEDUPE, externalizeRapierWasm } from "@pinkaphant/kolmo/vite";
|
|
99
75
|
|
|
100
76
|
export default defineConfig({
|
|
101
77
|
plugins: [react(), externalizeRapierWasm()],
|
|
102
|
-
resolve: { dedupe:
|
|
103
|
-
build:
|
|
104
|
-
chunkSizeWarningLimit: 1100,
|
|
105
|
-
rolldownOptions: {
|
|
106
|
-
output: {
|
|
107
|
-
codeSplitting: {
|
|
108
|
-
groups: [
|
|
109
|
-
{ name: "vendor-react", test: /[\\\\/]node_modules[\\\\/](react|react-dom|scheduler)[\\\\/]/, priority: 40 },
|
|
110
|
-
{ name: "vendor-three", test: /[\\\\/]node_modules[\\\\/](three|three-stdlib|maath|camera-controls)[\\\\/]/, priority: 30, includeDependenciesRecursively: false },
|
|
111
|
-
{ name: "vendor-physics", test: /[\\\\/]node_modules[\\\\/](@dimforge\\/rapier3d-compat|@react-three\\/rapier|@pinkaphant\\/ecctrl)[\\\\/]/, priority: 20, includeDependenciesRecursively: false },
|
|
112
|
-
{ name: "vendor-r3f", test: /[\\\\/]node_modules[\\\\/]/, priority: 10, includeDependenciesRecursively: false },
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
78
|
+
resolve: { dedupe: KOLMO_SINGLETON_DEDUPE },
|
|
79
|
+
build: KOLMO_ROLLDOWN_BUILD,
|
|
118
80
|
});\n`);
|
|
119
81
|
|
|
120
82
|
fs.writeFileSync(path.join(targetDir, "tsconfig.json"), JSON.stringify({
|
|
@@ -122,6 +84,8 @@ fs.writeFileSync(path.join(targetDir, "tsconfig.json"), JSON.stringify({
|
|
|
122
84
|
target: "ES2022",
|
|
123
85
|
module: "ESNext",
|
|
124
86
|
moduleResolution: "Bundler",
|
|
87
|
+
allowImportingTsExtensions: true,
|
|
88
|
+
types: ["node"],
|
|
125
89
|
jsx: "react-jsx",
|
|
126
90
|
strict: true,
|
|
127
91
|
skipLibCheck: true,
|
|
@@ -136,7 +100,7 @@ fs.writeFileSync(path.join(targetDir, "wrangler.jsonc"), JSON.stringify({
|
|
|
136
100
|
assets: { directory: "./dist", not_found_handling: "single-page-application" },
|
|
137
101
|
}, null, 2));
|
|
138
102
|
|
|
139
|
-
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
|
|
103
|
+
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"/>'));
|
|
140
104
|
|
|
141
105
|
const appSrc = template === "garage"
|
|
142
106
|
? `import { GlbImportGate } from "@pinkaphant/kolmo/importer";\nexport function App() {\n return <GlbImportGate />;\n}\n`
|
|
@@ -146,5 +110,6 @@ const appSrc = template === "garage"
|
|
|
146
110
|
|
|
147
111
|
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), appSrc);
|
|
148
112
|
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`);
|
|
113
|
+
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`);
|
|
149
114
|
|
|
150
115
|
console.log(`Scaffolded ${template} project in ${targetDir}\nNext: cd ${dirArg} && npm install && npm run dev`);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type KhrAssetBundle } from "@khr3/core";
|
|
2
|
+
import { type RapierRigidBody } from "@react-three/rapier";
|
|
3
|
+
import { type Ref, type RefObject } from "react";
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
import { type BodySocketId } from "./bodySi.js";
|
|
6
|
+
import type { KhrBodyHandle } from "./KhrBody.js";
|
|
7
|
+
export interface HeldItemHandle {
|
|
8
|
+
readonly socket: BodySocketId;
|
|
9
|
+
readonly rigidBody: RapierRigidBody | null;
|
|
10
|
+
setRoleTarget(role: string, target: number): number;
|
|
11
|
+
setJointTarget(nodeName: string, target: number): number;
|
|
12
|
+
getRoleValue(role: string): number;
|
|
13
|
+
}
|
|
14
|
+
export interface HeldItemProps {
|
|
15
|
+
readonly ref?: Ref<HeldItemHandle>;
|
|
16
|
+
readonly bundle: KhrAssetBundle;
|
|
17
|
+
readonly socket: BodySocketId;
|
|
18
|
+
readonly bodyRef?: RefObject<KhrBodyHandle | null>;
|
|
19
|
+
readonly parentSocketObject?: THREE.Object3D | null;
|
|
20
|
+
readonly userData?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export declare function HeldItem({ ref, bundle, socket, bodyRef, parentSocketObject, userData }: HeldItemProps): import("react").JSX.Element;
|
|
@@ -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(() => {
|
|
57
|
+
let e = F.current, t = A ?? k?.current?.socket(x) ?? I.current;
|
|
58
|
+
e && t && (b.scene.parent !== t && t.add(b.scene), b.scene.updateWorldMatrix(!0, !1), S.multiplyMatrices(b.scene.matrixWorld, z), S.decompose(C, w, T), w.normalize(), e.setTranslation(C, !0), e.setRotation(w, !0), e.setNextKinematicTranslation(C), e.setNextKinematicRotation(w), M.propagateModifiedBodyPositionsToColliders());
|
|
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(), () => {
|
|
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();
|
|
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,26 @@
|
|
|
1
|
+
import { type EcctrlHandle, type EcctrlProps } from "@pinkaphant/ecctrl";
|
|
2
|
+
import { type EcctrlCameraControlsHandle } from "@pinkaphant/ecctrl/camera";
|
|
3
|
+
import { type ReactNode, type Ref } from "react";
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
import { stepCameraSync, type BodySiConstants, type BodySocketId } from "./bodySi.js";
|
|
6
|
+
export { stepCameraSync };
|
|
7
|
+
export interface KhrBodyHandle {
|
|
8
|
+
readonly ecctrl: EcctrlHandle | null;
|
|
9
|
+
readonly cameraControls: EcctrlCameraControlsHandle | null;
|
|
10
|
+
socket(id: BodySocketId): THREE.Object3D | null;
|
|
11
|
+
syncCameraStep(pos: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
}): void;
|
|
16
|
+
}
|
|
17
|
+
export interface KhrBodyProps extends Omit<EcctrlProps, "ref"> {
|
|
18
|
+
readonly ref?: Ref<KhrBodyHandle>;
|
|
19
|
+
readonly si?: BodySiConstants;
|
|
20
|
+
readonly smoothCamera?: boolean;
|
|
21
|
+
readonly makeDefaultCamera?: boolean;
|
|
22
|
+
readonly enableInput?: boolean;
|
|
23
|
+
readonly viewModelChildren?: ReactNode;
|
|
24
|
+
readonly socketOffsets?: Partial<Record<BodySocketId, readonly [number, number, number]>>;
|
|
25
|
+
}
|
|
26
|
+
export declare function KhrBody({ ref, si, smoothCamera, makeDefaultCamera, enableInput, enable, viewModelChildren, socketOffsets, children, userData: callerUserData, position, ...ecctrlProps }: KhrBodyProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { BODY_MOVE_TUNE as e, BODY_SI as t, BODY_SOCKET_IDS as n, bodyEyeOffsetY as r, bodyRestCenterY as i, stepCameraSync as a } from "./bodySi.js";
|
|
2
|
+
import { useEffect as o, useImperativeHandle as s, useMemo as c, useRef as l } from "react";
|
|
3
|
+
import { useFrame as u, useThree as d } from "@react-three/fiber";
|
|
4
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
5
|
+
import { Ecctrl as h } from "@pinkaphant/ecctrl";
|
|
6
|
+
import { EcctrlCameraControls as g } from "@pinkaphant/ecctrl/camera";
|
|
7
|
+
// src/body/KhrBody.tsx
|
|
8
|
+
var _ = 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
|
+
}), v = {
|
|
30
|
+
forward: !1,
|
|
31
|
+
backward: !1,
|
|
32
|
+
leftward: !1,
|
|
33
|
+
rightward: !1,
|
|
34
|
+
run: !1,
|
|
35
|
+
jump: !1
|
|
36
|
+
};
|
|
37
|
+
function y({ active: e, ecctrlRef: t }) {
|
|
38
|
+
let n = l({
|
|
39
|
+
w: !1,
|
|
40
|
+
s: !1,
|
|
41
|
+
a: !1,
|
|
42
|
+
d: !1,
|
|
43
|
+
shift: !1,
|
|
44
|
+
space: !1,
|
|
45
|
+
dirty: !1
|
|
46
|
+
}), r = l(e);
|
|
47
|
+
return o(() => {
|
|
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]), u(() => {
|
|
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, v.forward = !1, v.backward = !1, v.leftward = !1, v.rightward = !1, v.run = !1, v.jump = !1, i.setMovement(v), r.current = !1;
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
r.current = !0;
|
|
70
|
+
let a = n.current;
|
|
71
|
+
a.dirty && (a.dirty = !1, v.forward = a.w, v.backward = a.s, v.leftward = a.a, v.rightward = a.d, v.run = a.shift, v.jump = a.space, i.setMovement(v));
|
|
72
|
+
}), null;
|
|
73
|
+
}
|
|
74
|
+
function b({ ref: o, si: u = t, smoothCamera: v = !1, makeDefaultCamera: b = !0, enableInput: S = !0, enable: C = !0, viewModelChildren: w, socketOffsets: T, children: E, userData: D, position: O, ...k }) {
|
|
75
|
+
let A = l(null), j = l(null), M = l(null), N = l({
|
|
76
|
+
Socket_Hand_R: null,
|
|
77
|
+
Socket_Hand_L: null,
|
|
78
|
+
Socket_Head: null,
|
|
79
|
+
Socket_Back: null
|
|
80
|
+
}), P = c(() => r(u), [u]), F = c(() => [
|
|
81
|
+
0,
|
|
82
|
+
i(u),
|
|
83
|
+
0
|
|
84
|
+
], [u]), I = d((e) => typeof e.gl?.domElement?.setAttribute == "function"), L = c(() => {
|
|
85
|
+
let e = D ?? {}, t = e.ecctrl ?? {};
|
|
86
|
+
return {
|
|
87
|
+
...e,
|
|
88
|
+
ecctrl: {
|
|
89
|
+
excludeVehicleRay: !0,
|
|
90
|
+
...t
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}, [D]);
|
|
94
|
+
return s(o, () => ({
|
|
95
|
+
get ecctrl() {
|
|
96
|
+
return A.current;
|
|
97
|
+
},
|
|
98
|
+
get cameraControls() {
|
|
99
|
+
return j.current;
|
|
100
|
+
},
|
|
101
|
+
socket(e) {
|
|
102
|
+
return N.current[e] ?? null;
|
|
103
|
+
},
|
|
104
|
+
syncCameraStep(e) {
|
|
105
|
+
a(j.current, e, P, v, A.current?.bodyYAxis);
|
|
106
|
+
}
|
|
107
|
+
}), [P, v]), /* @__PURE__ */ m(f, { children: [
|
|
108
|
+
/* @__PURE__ */ p(y, {
|
|
109
|
+
active: !!(C && S),
|
|
110
|
+
ecctrlRef: A
|
|
111
|
+
}),
|
|
112
|
+
/* @__PURE__ */ p(h, {
|
|
113
|
+
ref: A,
|
|
114
|
+
enable: C,
|
|
115
|
+
position: O ?? F,
|
|
116
|
+
capsuleHalfHeight: u.capsuleHalfHeight,
|
|
117
|
+
capsuleRadius: u.capsuleRadius,
|
|
118
|
+
floatHeight: u.floatHeight,
|
|
119
|
+
maxWalkVel: e.maxWalkVel,
|
|
120
|
+
maxRunVel: e.maxRunVel,
|
|
121
|
+
accDeltaTime: e.accDeltaTime,
|
|
122
|
+
decDeltaTime: e.decDeltaTime,
|
|
123
|
+
slideGripFactor: e.slideGripFactor,
|
|
124
|
+
moveImpulsePointOffset: e.moveImpulsePointOffset,
|
|
125
|
+
airDragFactor: e.airDragFactor,
|
|
126
|
+
enableToggleRun: e.enableToggleRun,
|
|
127
|
+
...k,
|
|
128
|
+
userData: L,
|
|
129
|
+
children: E
|
|
130
|
+
}),
|
|
131
|
+
I ? /* @__PURE__ */ p(g, {
|
|
132
|
+
ref: j,
|
|
133
|
+
makeDefault: b
|
|
134
|
+
}) : null,
|
|
135
|
+
/* @__PURE__ */ p(x, {
|
|
136
|
+
enable: C,
|
|
137
|
+
makeDefaultCamera: b,
|
|
138
|
+
ecctrlRef: A,
|
|
139
|
+
camControlsRef: j,
|
|
140
|
+
viewModelGroupRef: M,
|
|
141
|
+
eyeOffsetY: P,
|
|
142
|
+
smoothCamera: v
|
|
143
|
+
}),
|
|
144
|
+
/* @__PURE__ */ m("group", {
|
|
145
|
+
ref: M,
|
|
146
|
+
name: "KhrBody_ViewModel",
|
|
147
|
+
children: [n.map((e) => {
|
|
148
|
+
let t = T?.[e] ?? _[e];
|
|
149
|
+
return /* @__PURE__ */ p("group", {
|
|
150
|
+
name: e,
|
|
151
|
+
position: [
|
|
152
|
+
t[0],
|
|
153
|
+
t[1],
|
|
154
|
+
t[2]
|
|
155
|
+
],
|
|
156
|
+
ref: (t) => {
|
|
157
|
+
N.current[e] = t;
|
|
158
|
+
}
|
|
159
|
+
}, e);
|
|
160
|
+
}), w]
|
|
161
|
+
})
|
|
162
|
+
] });
|
|
163
|
+
}
|
|
164
|
+
function x({ enable: e, makeDefaultCamera: t, ecctrlRef: n, camControlsRef: r, viewModelGroupRef: i, eyeOffsetY: o, smoothCamera: s }) {
|
|
165
|
+
return u((c) => {
|
|
166
|
+
if (!e) return;
|
|
167
|
+
let l = n.current;
|
|
168
|
+
if (l) {
|
|
169
|
+
if (r.current) a(r.current, l.currPos, o, s, l.bodyYAxis);
|
|
170
|
+
else if (t) {
|
|
171
|
+
let e = l.bodyYAxis;
|
|
172
|
+
c.camera.position.set(l.currPos.x + e.x * o, l.currPos.y + e.y * o, l.currPos.z + e.z * o);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
let u = i.current;
|
|
176
|
+
u && (u.position.copy(c.camera.position), u.quaternion.copy(c.camera.quaternion));
|
|
177
|
+
}), null;
|
|
178
|
+
}
|
|
179
|
+
export { b as KhrBody, a as stepCameraSync };
|