@pinkaphant/kolmo 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -6
- package/bin/kolmo.mjs +455 -15
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.js +7 -5
- package/dist/engine/kolmoActions.js +24 -9
- package/dist/engine/kolmoActions.js.map +1 -1
- package/dist/engine/kolmoActor.js +19 -31
- package/dist/engine/kolmoActor.js.map +1 -1
- package/dist/engine/kolmoActorHelpers.d.ts +24 -0
- package/dist/engine/kolmoActorHelpers.js +64 -0
- package/dist/engine/kolmoActorHelpers.js.map +1 -0
- package/dist/engine/kolmoGame.js +4 -1
- package/dist/engine/kolmoGame.js.map +1 -1
- package/dist/engine/kolmoHud.js +34 -15
- package/dist/engine/kolmoHud.js.map +1 -1
- package/dist/engine/kolmoInput.d.ts +2 -0
- package/dist/engine/kolmoInput.js +12 -12
- package/dist/engine/kolmoInput.js.map +1 -1
- package/dist/engine/kolmoLongDrive.d.ts +1 -1
- package/dist/engine/kolmoLongDrive.js +10 -8
- package/dist/engine/kolmoLongDrive.js.map +1 -1
- package/dist/engine/kolmoPilotMesh.js +189 -48
- package/dist/engine/kolmoPilotMesh.js.map +1 -1
- package/dist/engine/kolmoTouchOverlay.d.ts +21 -0
- package/dist/engine/kolmoTouchOverlay.js +326 -0
- package/dist/engine/kolmoTouchOverlay.js.map +1 -0
- package/dist/engine/kolmoTouchState.d.ts +50 -0
- package/dist/engine/kolmoTouchState.js +210 -0
- package/dist/engine/kolmoTouchState.js.map +1 -0
- package/dist/engine/kolmoVehicleConfig.d.ts +2 -0
- package/dist/engine/kolmoVehicleConfig.js +8 -4
- package/dist/engine/kolmoVehicleConfig.js.map +1 -1
- package/dist/engine/kolmoVehicleDriver.d.ts +1 -0
- package/dist/engine/kolmoVehicleDriver.js +26 -50
- package/dist/engine/kolmoVehicleDriver.js.map +1 -1
- package/dist/engine/kolmoVehicleInner.js +31 -19
- package/dist/engine/kolmoVehicleInner.js.map +1 -1
- package/dist/engine/kolmoWorld.js +6 -2
- package/dist/engine/kolmoWorld.js.map +1 -1
- package/dist/engine/longDriveKit.d.ts +6 -1
- package/dist/engine/longDriveKit.js +8 -5
- package/dist/engine/longDriveKit.js.map +1 -1
- package/dist/engine/macroCellBuilder.d.ts +10 -0
- package/dist/engine/macroCellBuilder.js +101 -18
- package/dist/engine/macroCellBuilder.js.map +1 -1
- package/dist/engine/mainlandMacroCell.js +18 -9
- package/dist/engine/mainlandMacroCell.js.map +1 -1
- package/dist/importer/DomainWorkshopPanel.d.ts +3 -3
- package/dist/importer/DomainWorkshopPanel.js +148 -44
- package/dist/importer/DomainWorkshopPanel.js.map +1 -1
- package/dist/importer/GateHudBar.d.ts +2 -0
- package/dist/importer/GateHudBar.js +113 -35
- package/dist/importer/GateHudBar.js.map +1 -1
- package/dist/importer/GlbImportGate.js +16 -3
- package/dist/importer/GlbImportGate.js.map +1 -1
- package/dist/importer/LiveDrivePads.js +5 -3
- package/dist/importer/LiveDrivePads.js.map +1 -1
- package/dist/importer/Step1CalibrationPlinth.js +2 -2
- package/dist/importer/WheelRingHandles3D.js +2 -1
- package/dist/importer/WheelRingHandles3D.js.map +1 -1
- package/dist/importer/chopShopActions.js +20 -16
- package/dist/importer/chopShopActions.js.map +1 -1
- package/dist/importer/chopShopHandlers.js +16 -9
- package/dist/importer/chopShopHandlers.js.map +1 -1
- package/dist/importer/chopShopIoActions.d.ts +2 -0
- package/dist/importer/chopShopIoActions.js +33 -2
- package/dist/importer/chopShopIoActions.js.map +1 -1
- package/dist/importer/cylinderBooleanSlice.js.map +1 -1
- package/dist/importer/fusedWheelDetect.d.ts +2 -2
- package/dist/importer/fusedWheelDetect.js +227 -106
- package/dist/importer/fusedWheelDetect.js.map +1 -1
- package/dist/importer/fusedWheelFit.d.ts +6 -0
- package/dist/importer/fusedWheelFit.js +82 -1
- package/dist/importer/fusedWheelFit.js.map +1 -1
- package/dist/importer/gateStore.d.ts +2 -2
- package/dist/importer/gateStore.js +4 -3
- package/dist/importer/gateStore.js.map +1 -1
- package/dist/importer/glbNormalizer.js +5 -0
- package/dist/importer/glbNormalizer.js.map +1 -1
- package/dist/importer/importerWebMcpTools.js +3 -2
- package/dist/importer/importerWebMcpTools.js.map +1 -1
- package/dist/importer/index.d.ts +4 -2
- package/dist/importer/index.js +7 -3
- package/dist/importer/khrCarGeometryMass.d.ts +20 -0
- package/dist/importer/khrCarGeometryMass.js +125 -0
- package/dist/importer/khrCarGeometryMass.js.map +1 -0
- package/dist/importer/khrCarPlanHelpers.js +12 -22
- package/dist/importer/khrCarPlanHelpers.js.map +1 -1
- package/dist/importer/khrCarPlanner.js +52 -85
- package/dist/importer/khrCarPlanner.js.map +1 -1
- package/dist/importer/proceduralC12AndCraft.d.ts +18 -0
- package/dist/importer/proceduralC12AndCraft.js +302 -0
- package/dist/importer/proceduralC12AndCraft.js.map +1 -0
- package/dist/importer/proceduralDomainBuilders.d.ts +10 -0
- package/dist/importer/proceduralDomainBuilders.js +346 -0
- package/dist/importer/proceduralDomainBuilders.js.map +1 -0
- package/dist/importer/proceduralPersonAndProp.d.ts +8 -0
- package/dist/importer/proceduralPersonAndProp.js +303 -0
- package/dist/importer/proceduralPersonAndProp.js.map +1 -0
- package/dist/importer/starterScene.d.ts +3 -1
- package/dist/importer/starterScene.js +69 -13
- package/dist/importer/starterScene.js.map +1 -1
- package/dist/importer/universalGateBake.js +43 -11
- package/dist/importer/universalGateBake.js.map +1 -1
- package/dist/importer/useChopShopController.d.ts +3 -1
- package/dist/importer/useChopShopController.js +33 -18
- package/dist/importer/useChopShopController.js.map +1 -1
- package/dist/importer/useChopShopState.d.ts +1 -1
- package/dist/importer/useChopShopState.js +35 -9
- package/dist/importer/useChopShopState.js.map +1 -1
- package/dist/importer/wheelCutterHelpers.d.ts +7 -4
- package/dist/importer/wheelCutterHelpers.js +58 -28
- package/dist/importer/wheelCutterHelpers.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20 -7
- package/dist/junk/DestructibleTarget.js +9 -3
- package/dist/junk/DestructibleTarget.js.map +1 -1
- package/dist/junk/ShardPieces.js +10 -2
- package/dist/junk/ShardPieces.js.map +1 -1
- package/dist/junk/index.d.ts +1 -0
- package/dist/junk/index.js +2 -1
- package/dist/junk/junkProceduralScenes.d.ts +12 -0
- package/dist/junk/junkProceduralScenes.js +220 -0
- package/dist/junk/junkProceduralScenes.js.map +1 -0
- package/dist/sand3d/KolmoSand3D.d.ts +19 -0
- package/dist/sand3d/KolmoSand3D.js +92 -0
- package/dist/sand3d/KolmoSand3D.js.map +1 -0
- package/dist/sand3d/Sand3dWorkshopSection.d.ts +8 -0
- package/dist/sand3d/Sand3dWorkshopSection.js +117 -0
- package/dist/sand3d/Sand3dWorkshopSection.js.map +1 -0
- package/dist/sand3d/gateBakeHelpers.d.ts +21 -0
- package/dist/sand3d/gateBakeHelpers.js +225 -0
- package/dist/sand3d/gateBakeHelpers.js.map +1 -0
- package/dist/sand3d/gateDoorwayBake.d.ts +12 -0
- package/dist/sand3d/gateDoorwayBake.js +203 -0
- package/dist/sand3d/gateDoorwayBake.js.map +1 -0
- package/dist/sand3d/index.d.ts +3 -0
- package/dist/sand3d/index.js +4 -0
- package/dist/sand3d/index.js.map +1 -0
- package/dist/sand3d/sand3dAssetLoader.d.ts +28 -0
- package/dist/sand3d/sand3dAssetLoader.js +177 -0
- package/dist/sand3d/sand3dAssetLoader.js.map +1 -0
- package/dist/suika/KolmoSuikaOrb.d.ts +33 -0
- package/dist/suika/KolmoSuikaOrb.js +375 -0
- package/dist/suika/KolmoSuikaOrb.js.map +1 -0
- package/dist/suika/index.d.ts +4 -0
- package/dist/suika/index.js +5 -0
- package/dist/suika/index.js.map +1 -0
- package/dist/suika/suikaArbiter.d.ts +60 -0
- package/dist/suika/suikaArbiter.js +265 -0
- package/dist/suika/suikaArbiter.js.map +1 -0
- package/dist/suika/suikaGeometry.d.ts +10 -0
- package/dist/suika/suikaGeometry.js +251 -0
- package/dist/suika/suikaGeometry.js.map +1 -0
- package/dist/suika/suikaTypes.d.ts +74 -0
- package/dist/suika/suikaTypes.js +196 -0
- package/dist/suika/suikaTypes.js.map +1 -0
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +2 -2
- package/dist/world/worldTypes.d.ts +4 -0
- package/dist/world/worldTypes.js +21 -1
- package/dist/world/worldTypes.js.map +1 -1
- package/docs/api-reference.md +82 -125
- package/package.json +14 -6
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# `@pinkaphant/kolmo`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Declarative 3D game runtime for React Three Fiber and Rapier (`@pinkaphant/ecctrl`), combining procedural C12 island and highway world generation, PS1/Dreamcast/PS2 shaders, destructible BVH props, golden-ratio `<SuikaOrb>` and `<SuikaSystem>` rigid bodies, declarative `<Sand3D>` Code-CAD assemblies, and an 8-domain GLB/USD/Sand3D calibration workbench (`vehicle | c12 | launcher | person | prop | junk | suika | sand3d`).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @pinkaphant/kolmo @khr3/core @khr3/c12 @khr3/assets @khr3/vehicles @khr3/launchers @pinkaphant/ecctrl@2.0.4-beta.2 @dimforge/rapier3d-compat@0.19.2
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Pin physics runtime versions in `package.json` `overrides`:
|
|
12
12
|
|
|
13
13
|
```json
|
|
14
14
|
{
|
|
@@ -19,7 +19,9 @@ Add exact `overrides` pins in your app `package.json`:
|
|
|
19
19
|
}
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
## Vite
|
|
22
|
+
## Vite Configuration (`@pinkaphant/kolmo/vite`)
|
|
23
|
+
|
|
24
|
+
[`externalizeRapierWasm`](./src/vite/index.ts) emits `rapier_wasm3d_bg.wasm` as a standalone binary asset during Rollup builds, [`KOLMO_SINGLETON_DEDUPE`](./src/vite/index.ts) unifies React, Three.js, R3F, Rapier, Koota, and Zustand module instances, and [`KOLMO_ROLLDOWN_BUILD`](./src/vite/index.ts) configures layered vendor chunk groups.
|
|
23
25
|
|
|
24
26
|
```ts
|
|
25
27
|
import react from "@vitejs/plugin-react";
|
|
@@ -37,10 +39,62 @@ export default defineConfig({
|
|
|
37
39
|
});
|
|
38
40
|
```
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
## CLI Project Scaffolder
|
|
43
|
+
|
|
44
|
+
[`bin/kolmo.mjs`](./bin/kolmo.mjs) scaffolds runnable Vite + TypeScript applications for four starter templates (`game | longline | dust | garage`):
|
|
41
45
|
|
|
42
46
|
```bash
|
|
43
47
|
npx @pinkaphant/kolmo create my-game --template game
|
|
44
48
|
```
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
- `game` mounts `<Game>`, `<Island>`, `<Vehicle piloted>`, `<Actor>`, `<Hud>`, and `<MobileTouchOverlay />`.
|
|
51
|
+
- `dust` mounts `<Game>`, `<Island>`, `<Vehicle>`, `<Actor>`, `<Hud>`, `<MobileTouchOverlay />`, resource harvesting, `<Junk>`, and 3 m C12 `yaw12` wall construction.
|
|
52
|
+
- `longline` mounts `<Game>`, `<LongDrive pureMainland>`, `<Vehicle piloted>`, `<Actor>`, `<Hud>`, `<MobileTouchOverlay />`, `<SuikaSystem>`, floating-origin odometer tracking, roadside jerrycan pickups, and C12 building.
|
|
53
|
+
- `garage` mounts `<GlbImportGate>` from `@pinkaphant/kolmo/importer`.
|
|
54
|
+
|
|
55
|
+
## Architecture & `pmndrs` Conventions
|
|
56
|
+
|
|
57
|
+
- **Frame Loop Updates**: Frame callbacks use `useFrame((_, delta) => ...)` to update Three.js object refs, Koota traits, and mutable telemetry structures scaled by `delta`.
|
|
58
|
+
- **Transient State Reads**: Render-loop consumers read Zustand state via `useGateStore.getState()` and Koota queries via `kolmoWorld`, updating HUD DOM refs directly at 60 Hz or at throttled intervals.
|
|
59
|
+
- **Physics, Sand3D & Vehicle Rigs**: Assets combine `KHR_physics_rigid_bodies`, `KHR_implicit_shapes`, `KOLMO_emitter` sockets, `<ShapeCastWheel>`, `<ThrustPropeller>`, and declarative `s3d` Code-CAD scripts from `@khr3/core/sand3d`.
|
|
60
|
+
|
|
61
|
+
## Package Subpaths & Source Directory
|
|
62
|
+
|
|
63
|
+
Full symbol signatures and option defaults live in [docs/api-reference.md](./docs/api-reference.md).
|
|
64
|
+
|
|
65
|
+
### Root Barrel (`@pinkaphant/kolmo` & `@pinkaphant/kolmo/all`)
|
|
66
|
+
- Entry & integration suite: [index.ts](./src/index.ts), [kolmo.test.ts](./src/kolmo.test.ts)
|
|
67
|
+
|
|
68
|
+
### Engine (`@pinkaphant/kolmo/engine`)
|
|
69
|
+
- Shell, world, HUD, and touch overlay: [index.ts](./src/engine/index.ts), [kolmoGame.tsx](./src/engine/kolmoGame.tsx), [kolmoHud.tsx](./src/engine/kolmoHud.tsx), [kolmoTouchOverlay.tsx](./src/engine/kolmoTouchOverlay.tsx), [kolmoWorld.tsx](./src/engine/kolmoWorld.tsx), [kolmoRigs.tsx](./src/engine/kolmoRigs.tsx)
|
|
70
|
+
- Vehicles, actors, and props: [kolmoVehicle.tsx](./src/engine/kolmoVehicle.tsx), [kolmoVehicleInner.tsx](./src/engine/kolmoVehicleInner.tsx), [kolmoVehicleAutoCompile.ts](./src/engine/kolmoVehicleAutoCompile.ts), [kolmoVehicleConfig.ts](./src/engine/kolmoVehicleConfig.ts), [kolmoVehicleDriver.ts](./src/engine/kolmoVehicleDriver.ts), [kolmoProcedural.ts](./src/engine/kolmoProcedural.ts), [kolmoActor.tsx](./src/engine/kolmoActor.tsx), [kolmoActorHelpers.ts](./src/engine/kolmoActorHelpers.ts), [kolmoPilotMesh.tsx](./src/engine/kolmoPilotMesh.tsx), [kolmoSurface.tsx](./src/engine/kolmoSurface.tsx)
|
|
71
|
+
- Koota state, input, touch state, and floating origin: [kolmoStore.ts](./src/engine/kolmoStore.ts), [kolmoTraits.ts](./src/engine/kolmoTraits.ts), [kolmoActions.ts](./src/engine/kolmoActions.ts), [kolmoFloatingOrigin.ts](./src/engine/kolmoFloatingOrigin.ts), [kolmoInput.ts](./src/engine/kolmoInput.ts), [kolmoTouchState.ts](./src/engine/kolmoTouchState.ts), [shiftedFixedBody.tsx](./src/engine/shiftedFixedBody.tsx)
|
|
72
|
+
- Island & mainland streaming: [kolmoIsland.tsx](./src/engine/kolmoIsland.tsx), [islandSettlementMesh.tsx](./src/engine/islandSettlementMesh.tsx), [causewayBridge.tsx](./src/engine/causewayBridge.tsx), [kolmoLongDrive.tsx](./src/engine/kolmoLongDrive.tsx), [longDriveKit.tsx](./src/engine/longDriveKit.tsx), [longDriveRoadside.tsx](./src/engine/longDriveRoadside.tsx), [macroCellBuilder.ts](./src/engine/macroCellBuilder.ts), [mainlandMacroCell.tsx](./src/engine/mainlandMacroCell.tsx)
|
|
73
|
+
- Engine verification: [hybridZeroGFlight.test.ts](./src/engine/hybridZeroGFlight.test.ts), [kolmoTouch.test.ts](./src/engine/kolmoTouch.test.ts), [kolmoTouchOverlay.test.tsx](./src/engine/kolmoTouchOverlay.test.tsx), [kolmoVehicleAutoCompile.test.ts](./src/engine/kolmoVehicleAutoCompile.test.ts), [longDriveCurb.test.ts](./src/engine/longDriveCurb.test.ts)
|
|
74
|
+
|
|
75
|
+
### Physics & Vite (`@pinkaphant/kolmo/physics`, `@pinkaphant/kolmo/vite`)
|
|
76
|
+
- Physics world & gravity context: [index.tsx](./src/physics/index.tsx)
|
|
77
|
+
- Rapier WASM asset plugin & Rolldown chunk preset: [index.ts](./src/vite/index.ts)
|
|
78
|
+
|
|
79
|
+
### Procedural World (`@pinkaphant/kolmo/world`)
|
|
80
|
+
- Island, terrain, and road splines: [index.ts](./src/world/index.ts), [island.ts](./src/world/island.ts), [islandPathing.ts](./src/world/islandPathing.ts), [terrain.ts](./src/world/terrain.ts), [terrainGeometry.ts](./src/world/terrainGeometry.ts), [road.ts](./src/world/road.ts), [roadRibbon.ts](./src/world/roadRibbon.ts), [frontage.ts](./src/world/frontage.ts), [random.ts](./src/world/random.ts), [worldTypes.ts](./src/world/worldTypes.ts), [seed8.test.ts](./src/world/seed8.test.ts)
|
|
81
|
+
- Macro-cell C12 highway planner: [infiniteWorld2D.ts](./src/world/infiniteWorld2D.ts), [macroCellSchema.ts](./src/world/macroCellSchema.ts), [macroKnightAStar.ts](./src/world/macroKnightAStar.ts), [macroSettlementZones.ts](./src/world/macroSettlementZones.ts)
|
|
82
|
+
|
|
83
|
+
### Shaders (`@pinkaphant/kolmo/shaders` & `@pinkaphant/kolmo/shaders/tsl`)
|
|
84
|
+
- Retro quantize, palettes, and uniforms: [index.ts](./src/shaders/index.ts), [retroShader.ts](./src/shaders/retroShader.ts), [retroPalettes.ts](./src/shaders/retroPalettes.ts), [retroUniforms.ts](./src/shaders/retroUniforms.ts)
|
|
85
|
+
- Skybox, exoplanet, and emitters: [celestialBackdrop.tsx](./src/shaders/celestialBackdrop.tsx), [skyboxShaders.tsx](./src/shaders/skyboxShaders.tsx), [plumeAndSparkle.tsx](./src/shaders/plumeAndSparkle.tsx), [emitterShaders.ts](./src/shaders/emitterShaders.ts)
|
|
86
|
+
- PS2 terrain & road materials (WebGL & TSL): [ps2Textures.ts](./src/shaders/ps2Textures.ts), [ps2GlslShared.ts](./src/shaders/ps2GlslShared.ts), [ps2MaterialsWebGL.ts](./src/shaders/ps2MaterialsWebGL.ts), [ps2TerrainWebGL.ts](./src/shaders/ps2TerrainWebGL.ts), [ps2RoadWebGL.ts](./src/shaders/ps2RoadWebGL.ts), [tsl.ts](./src/shaders/tsl.ts), [ps2MaterialsTSL.ts](./src/shaders/ps2MaterialsTSL.ts)
|
|
87
|
+
|
|
88
|
+
### GLB / USD / Sand3D Import Gate (`@pinkaphant/kolmo/importer`)
|
|
89
|
+
- Workbench & 3D plinth UI: [index.ts](./src/importer/index.ts), [GlbImportGate.tsx](./src/importer/GlbImportGate.tsx), [GateHudBar.tsx](./src/importer/GateHudBar.tsx), [Step1CalibrationPlinth.tsx](./src/importer/Step1CalibrationPlinth.tsx), [Step1ExplodedIslands.tsx](./src/importer/Step1ExplodedIslands.tsx), [Step2UniversalPad.tsx](./src/importer/Step2UniversalPad.tsx), [LiveDrivePads.tsx](./src/importer/LiveDrivePads.tsx), [ImperativeVehicleRig.tsx](./src/importer/ImperativeVehicleRig.tsx), [PaperShellDebrisRig.tsx](./src/importer/PaperShellDebrisRig.tsx), [ChopShopPanel.tsx](./src/importer/ChopShopPanel.tsx), [DomainWorkshopPanel.tsx](./src/importer/DomainWorkshopPanel.tsx), [R2VaultDrawer.tsx](./src/importer/R2VaultDrawer.tsx), [VfxEmitterPool.tsx](./src/importer/VfxEmitterPool.tsx), [WheelRingHandles3D.tsx](./src/importer/WheelRingHandles3D.tsx)
|
|
90
|
+
- Procedural domain builders & starters: [starterScene.ts](./src/importer/starterScene.ts), [proceduralDomainBuilders.ts](./src/importer/proceduralDomainBuilders.ts), [proceduralC12AndCraft.ts](./src/importer/proceduralC12AndCraft.ts), [proceduralPersonAndProp.ts](./src/importer/proceduralPersonAndProp.ts)
|
|
91
|
+
- Controllers & Zustand store: [gateStore.ts](./src/importer/gateStore.ts), [useChopShopController.ts](./src/importer/useChopShopController.ts), [useChopShopState.ts](./src/importer/useChopShopState.ts), [useWasdKeyRef.ts](./src/importer/useWasdKeyRef.ts), [chopShopActions.ts](./src/importer/chopShopActions.ts), [chopShopHandlers.ts](./src/importer/chopShopHandlers.ts), [chopShopIoActions.ts](./src/importer/chopShopIoActions.ts), [chopShopMcpAction.ts](./src/importer/chopShopMcpAction.ts), [importerWebMcp.ts](./src/importer/importerWebMcp.ts), [importerWebMcpTools.ts](./src/importer/importerWebMcpTools.ts)
|
|
92
|
+
- Wheel coring & boolean slicing: [fusedWheelDetect.ts](./src/importer/fusedWheelDetect.ts), [fusedWheelFit.ts](./src/importer/fusedWheelFit.ts), [wheelAxlePairing.ts](./src/importer/wheelAxlePairing.ts), [wheelCutterHelpers.ts](./src/importer/wheelCutterHelpers.ts), [wheelRingHandleMath.ts](./src/importer/wheelRingHandleMath.ts), [cylinderBooleanSlice.ts](./src/importer/cylinderBooleanSlice.ts), [cylinderSliceMath.ts](./src/importer/cylinderSliceMath.ts), [archLinerGeom.ts](./src/importer/archLinerGeom.ts), [polygonEarClipYZ.ts](./src/importer/polygonEarClipYZ.ts)
|
|
93
|
+
- Surface cutter, SI normalization & KHR/USD compilers: [meshIslands.ts](./src/importer/meshIslands.ts), [meshSliceBuffers.ts](./src/importer/meshSliceBuffers.ts), [sceneSiNormalize.ts](./src/importer/sceneSiNormalize.ts), [glbNormalizer.ts](./src/importer/glbNormalizer.ts), [vehiclePartSplit.ts](./src/importer/vehiclePartSplit.ts), [surfaceCutter.ts](./src/importer/surfaceCutter.ts), [surfaceGeodesic.ts](./src/importer/surfaceGeodesic.ts), [surfaceLoopRefine.ts](./src/importer/surfaceLoopRefine.ts), [surfacePeel.ts](./src/importer/surfacePeel.ts), [surfaceTopology.ts](./src/importer/surfaceTopology.ts), [chopHingeHelpers.ts](./src/importer/chopHingeHelpers.ts), [khrCarGeometryMass.ts](./src/importer/khrCarGeometryMass.ts), [khrCarPlanHelpers.ts](./src/importer/khrCarPlanHelpers.ts), [khrCarPlanner.ts](./src/importer/khrCarPlanner.ts), [khrCompiler.ts](./src/importer/khrCompiler.ts), [khrCraftPropCompiler.ts](./src/importer/khrCraftPropCompiler.ts), [khrNodeNameGuard.ts](./src/importer/khrNodeNameGuard.ts), [universalGateBake.ts](./src/importer/universalGateBake.ts), [launcherBake.ts](./src/importer/launcherBake.ts), [launcherCadGeometry.ts](./src/importer/launcherCadGeometry.ts), [usdPhysicsSpecs.ts](./src/importer/usdPhysicsSpecs.ts), [usdTextParse.ts](./src/importer/usdTextParse.ts), [usdToGlb.ts](./src/importer/usdToGlb.ts)
|
|
94
|
+
- Importer verification: [chopShopDomain.test.ts](./src/importer/chopShopDomain.test.ts), [domainBake.test.ts](./src/importer/domainBake.test.ts), [dualThreeCompat.test.ts](./src/importer/dualThreeCompat.test.ts), [emitterReimportGuard.test.ts](./src/importer/emitterReimportGuard.test.ts), [multiWheelAndMass.test.ts](./src/importer/multiWheelAndMass.test.ts), [proceduralDomains.test.ts](./src/importer/proceduralDomains.test.ts), [r10WheelReimport.test.ts](./src/importer/r10WheelReimport.test.ts), [r11DupAndCoreOrder.test.ts](./src/importer/r11DupAndCoreOrder.test.ts), [r12PatchCollision.test.ts](./src/importer/r12PatchCollision.test.ts), [realRapierDrive.test.ts](./src/importer/realRapierDrive.test.ts), [reimportCollision.test.ts](./src/importer/reimportCollision.test.ts), [sceneSiNormalize.test.ts](./src/importer/sceneSiNormalize.test.ts), [surfacePeelActions.test.ts](./src/importer/surfacePeelActions.test.ts), [usdRoundTrip.test.ts](./src/importer/usdRoundTrip.test.ts), [wheelCutter.test.ts](./src/importer/wheelCutter.test.ts), [wheelCutterEdge.test.ts](./src/importer/wheelCutterEdge.test.ts), [wheelCutterOffCenter.test.ts](./src/importer/wheelCutterOffCenter.test.ts), [wheelRingHandleMath.test.ts](./src/importer/wheelRingHandleMath.test.ts)
|
|
95
|
+
|
|
96
|
+
### Sand3D, Destructible Junk, Suika Orbs & Schema (`@pinkaphant/kolmo/sand3d`, `@pinkaphant/kolmo/junk`, `@pinkaphant/kolmo/suika`, `@pinkaphant/kolmo/schema`)
|
|
97
|
+
- Sand3D Code-CAD & universal asset ingestion: [index.ts](./src/sand3d/index.ts), [KolmoSand3D.tsx](./src/sand3d/KolmoSand3D.tsx), [Sand3dWorkshopSection.tsx](./src/sand3d/Sand3dWorkshopSection.tsx), [sand3dAssetLoader.ts](./src/sand3d/sand3dAssetLoader.ts), [gateBakeHelpers.ts](./src/sand3d/gateBakeHelpers.ts), [gateDoorwayBake.ts](./src/sand3d/gateDoorwayBake.ts), [sand3d.test.ts](./src/sand3d/sand3d.test.ts)
|
|
98
|
+
- Junk targets & BVH shattering: [index.ts](./src/junk/index.ts), [KolmoJunk.tsx](./src/junk/KolmoJunk.tsx), [DestructibleTarget.tsx](./src/junk/DestructibleTarget.tsx), [ShardPieces.tsx](./src/junk/ShardPieces.tsx), [TargetDecals.tsx](./src/junk/TargetDecals.tsx), [bvhShatter.ts](./src/junk/bvhShatter.ts), [bvhTriCollector.ts](./src/junk/bvhTriCollector.ts), [junkGeometry.ts](./src/junk/junkGeometry.ts), [junkImportSanitize.ts](./src/junk/junkImportSanitize.ts), [junkImporter.ts](./src/junk/junkImporter.ts), [junkLabelCanvas.ts](./src/junk/junkLabelCanvas.ts), [junkLabels.ts](./src/junk/junkLabels.ts), [junkProceduralScenes.ts](./src/junk/junkProceduralScenes.ts), [junkTypes.ts](./src/junk/junkTypes.ts), [targetHelpers.ts](./src/junk/targetHelpers.ts), [targetHitLogic.ts](./src/junk/targetHitLogic.ts), [useTargetAssets.ts](./src/junk/useTargetAssets.ts)
|
|
99
|
+
- Suika orb tiers & merge arbiter: [index.ts](./src/suika/index.ts), [KolmoSuikaOrb.tsx](./src/suika/KolmoSuikaOrb.tsx), [suikaArbiter.ts](./src/suika/suikaArbiter.ts), [suikaGeometry.ts](./src/suika/suikaGeometry.ts), [suikaTypes.ts](./src/suika/suikaTypes.ts), [suika.test.ts](./src/suika/suika.test.ts)
|
|
100
|
+
- `KOLMO_emitter` GLB schema & stamping: [kolmoSchema.ts](./src/schema/kolmoSchema.ts), [kolmoStamp.ts](./src/schema/kolmoStamp.ts), [kolmoTypes.ts](./src/schema/kolmoTypes.ts)
|
package/bin/kolmo.mjs
CHANGED
|
@@ -18,7 +18,7 @@ const template = rawTpl === "dust" || rawTpl === "garage" || rawTpl === "longlin
|
|
|
18
18
|
const targetDir = path.resolve(process.cwd(), dirArg);
|
|
19
19
|
|
|
20
20
|
if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
|
|
21
|
-
console.error(`Error: Target directory "${targetDir}" already
|
|
21
|
+
console.error(`Error: Target directory "${targetDir}" already contains files. Choose a fresh directory path.`);
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -39,11 +39,6 @@ fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify({
|
|
|
39
39
|
},
|
|
40
40
|
dependencies: {
|
|
41
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
42
|
"@pinkaphant/ecctrl": kolmoPkg.peerDependencies["@pinkaphant/ecctrl"],
|
|
48
43
|
"@pinkaphant/kolmo": `^${kolmoPkg.version}`,
|
|
49
44
|
"@react-three/drei": "^10.7.7",
|
|
@@ -103,17 +98,462 @@ fs.writeFileSync(path.join(targetDir, "wrangler.jsonc"), JSON.stringify({
|
|
|
103
98
|
assets: { directory: "./dist", not_found_handling: "single-page-application" },
|
|
104
99
|
}, null, 2));
|
|
105
100
|
|
|
106
|
-
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:
|
|
101
|
+
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,viewport-fit=cover"/><title>${pkgName}</title><style>html,body,#root{margin:0;width:100%;height:100dvh;overflow:hidden;background:#05070e;touch-action:none;user-select:none;-webkit-user-select:none}canvas{touch-action:none;display:block}</style></head><body><div id="root"></div><script type="module" src="/src/main.tsx"></script></body></html>\n`);
|
|
107
102
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
103
|
+
const DUST_WORLD_SRC = `import { useEffect, useMemo, useRef, useState } from "react";
|
|
104
|
+
import * as THREE from "three";
|
|
105
|
+
import { useFrame, useThree } from "@react-three/fiber";
|
|
106
|
+
import { CuboidCollider, RigidBody } from "@react-three/rapier";
|
|
107
|
+
import { Junk, computeIslandSpawnPose, getCachedIslandPlan } from "@pinkaphant/kolmo";
|
|
108
|
+
|
|
109
|
+
export interface BuiltWall { id: number; pos: [number, number, number]; yaw: number; tier: "wood" | "stone"; }
|
|
110
|
+
|
|
111
|
+
const _fwd = new THREE.Vector3();
|
|
112
|
+
|
|
113
|
+
export function DustGameplay({
|
|
114
|
+
tool, yawStep, tier, onHarvest, walls, onPlaceWall,
|
|
115
|
+
}: {
|
|
116
|
+
tool: "harvest" | "build";
|
|
117
|
+
yawStep: number;
|
|
118
|
+
tier: "wood" | "stone";
|
|
119
|
+
onHarvest: (kind: "wood" | "stone", amount: number) => void;
|
|
120
|
+
walls: readonly BuiltWall[];
|
|
121
|
+
onPlaceWall: (pos: [number, number, number], yaw: number) => void;
|
|
122
|
+
}) {
|
|
123
|
+
const camera = useThree((s) => s.camera);
|
|
124
|
+
const plan = useMemo(() => getCachedIslandPlan(77, 960), []);
|
|
125
|
+
const spawn = useMemo(() => computeIslandSpawnPose(77, 960), []);
|
|
126
|
+
const ghostRef = useRef<THREE.Mesh | null>(null);
|
|
127
|
+
const ghostPose = useRef<[number, number, number]>([spawn.actorPos[0], spawn.actorPos[1] + 1.5, spawn.actorPos[2] + 6]);
|
|
128
|
+
const [depleted, setDepleted] = useState<Record<number, number>>({});
|
|
129
|
+
|
|
130
|
+
const nodes = useMemo(() => {
|
|
131
|
+
const list: { id: number; kind: "wood" | "stone"; pos: [number, number, number] }[] = [];
|
|
132
|
+
for (let i = 0; i < 24; i++) {
|
|
133
|
+
const ang = (i / 24) * Math.PI * 2, r = 10 + (i % 4) * 6;
|
|
134
|
+
const x = spawn.actorPos[0] + Math.cos(ang) * r, z = spawn.actorPos[2] + Math.sin(ang) * r;
|
|
135
|
+
const y = plan.terrain.height(x, z);
|
|
136
|
+
list.push({ id: i + 1, kind: i % 3 === 0 ? "stone" : "wood", pos: [x, y, z] });
|
|
137
|
+
}
|
|
138
|
+
return list;
|
|
139
|
+
}, [plan, spawn]);
|
|
140
|
+
|
|
141
|
+
const yawRad = (yawStep * Math.PI) / 6;
|
|
142
|
+
|
|
143
|
+
useFrame(() => {
|
|
144
|
+
_fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
145
|
+
const gx = Math.round((camera.position.x + _fwd.x * 5.5) / 3) * 3;
|
|
146
|
+
const gz = Math.round((camera.position.z + _fwd.z * 5.5) / 3) * 3;
|
|
147
|
+
const gy = plan.terrain.height(gx, gz) + 1.5;
|
|
148
|
+
ghostPose.current[0] = gx;
|
|
149
|
+
ghostPose.current[1] = gy;
|
|
150
|
+
ghostPose.current[2] = gz;
|
|
151
|
+
if (ghostRef.current) {
|
|
152
|
+
ghostRef.current.position.set(gx, gy, gz);
|
|
153
|
+
ghostRef.current.rotation.set(0, yawRad, 0);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
const act = () => {
|
|
159
|
+
if (tool === "build") {
|
|
160
|
+
onPlaceWall([...ghostPose.current], yawRad);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const now = Date.now();
|
|
164
|
+
let best: (typeof nodes)[number] | null = null, bestD = 9.5;
|
|
165
|
+
for (const n of nodes) {
|
|
166
|
+
if ((depleted[n.id] ?? 0) > now) continue;
|
|
167
|
+
const d = Math.hypot(n.pos[0] - camera.position.x, n.pos[1] + 1 - camera.position.y, n.pos[2] - camera.position.z);
|
|
168
|
+
if (d < bestD) { bestD = d; best = n; }
|
|
169
|
+
}
|
|
170
|
+
if (best) {
|
|
171
|
+
onHarvest(best.kind, best.kind === "wood" ? 25 : 20);
|
|
172
|
+
setDepleted((prev) => ({ ...prev, [best!.id]: now + 8000 }));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const onClick = (e: MouseEvent) => { if ((e.target as HTMLElement)?.tagName === "CANVAS") act(); };
|
|
176
|
+
const onKey = (e: KeyboardEvent) => { if (e.code === "KeyE") act(); };
|
|
177
|
+
window.addEventListener("pointerdown", onClick);
|
|
178
|
+
window.addEventListener("keydown", onKey);
|
|
179
|
+
return () => { window.removeEventListener("pointerdown", onClick); window.removeEventListener("keydown", onKey); };
|
|
180
|
+
}, [tool, yawRad, nodes, depleted, camera, onHarvest, onPlaceWall]);
|
|
181
|
+
|
|
182
|
+
const now = Date.now();
|
|
183
|
+
return (
|
|
184
|
+
<group>
|
|
185
|
+
{nodes.map((n) => (depleted[n.id] ?? 0) > now ? null : (
|
|
186
|
+
<RigidBody key={n.id} type="fixed" position={n.pos}>
|
|
187
|
+
<CuboidCollider args={n.kind === "wood" ? [0.45, 1.8, 0.45] : [0.85, 0.65, 0.85]} position={[0, n.kind === "wood" ? 1.8 : 0.65, 0]} />
|
|
188
|
+
{n.kind === "wood" ? (
|
|
189
|
+
<group>
|
|
190
|
+
<mesh position={[0, 1.1, 0]}><cylinderGeometry args={[0.22, 0.3, 2.2, 7]} /><meshStandardMaterial color="#5c3a21" flatShading /></mesh>
|
|
191
|
+
<mesh position={[0, 2.9, 0]}><coneGeometry args={[1.35, 2.8, 7]} /><meshStandardMaterial color="#2d5a27" flatShading /></mesh>
|
|
192
|
+
</group>
|
|
193
|
+
) : (
|
|
194
|
+
<mesh position={[0, 0.65, 0]}><dodecahedronGeometry args={[0.95, 0]} /><meshStandardMaterial color="#64748b" flatShading /></mesh>
|
|
195
|
+
)}
|
|
196
|
+
</RigidBody>
|
|
197
|
+
))}
|
|
198
|
+
<Junk id="dust_salvage_1" position={[spawn.actorPos[0] + 3, spawn.actorPos[1] + 1.2, spawn.actorPos[2] - 4]} />
|
|
199
|
+
{tool === "build" && (
|
|
200
|
+
<mesh ref={ghostRef}>
|
|
201
|
+
<boxGeometry args={[3.0, 3.0, 0.28]} />
|
|
202
|
+
<meshStandardMaterial color={tier === "wood" ? "#f59e0b" : "#38bdf8"} transparent opacity={0.42} depthWrite={false} />
|
|
203
|
+
</mesh>
|
|
204
|
+
)}
|
|
205
|
+
{walls.map((w) => (
|
|
206
|
+
<RigidBody key={w.id} type="fixed" position={w.pos} rotation={[0, w.yaw, 0]}>
|
|
207
|
+
<CuboidCollider args={[1.5, 1.5, 0.14]} />
|
|
208
|
+
<mesh castShadow receiveShadow>
|
|
209
|
+
<boxGeometry args={[3.0, 3.0, 0.28]} />
|
|
210
|
+
<meshStandardMaterial color={w.tier === "wood" ? "#8b5a2b" : "#475569"} flatShading />
|
|
211
|
+
</mesh>
|
|
212
|
+
</RigidBody>
|
|
213
|
+
))}
|
|
214
|
+
</group>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
`;
|
|
218
|
+
|
|
219
|
+
const DUST_APP_SRC = `import { useCallback, useEffect, useState } from "react";
|
|
220
|
+
import { Actor, Game, Hud, Island, MobileTouchOverlay, RETRO_PS2_SHINOBI, Vehicle } from "@pinkaphant/kolmo";
|
|
221
|
+
import { DustGameplay, type BuiltWall } from "./DustGameplay.tsx";
|
|
222
|
+
|
|
223
|
+
export function App() {
|
|
224
|
+
const [wood, setWood] = useState(45);
|
|
225
|
+
const [stone, setStone] = useState(30);
|
|
226
|
+
const [tool, setTool] = useState<"harvest" | "build">("harvest");
|
|
227
|
+
const [tier, setTier] = useState<"wood" | "stone">("wood");
|
|
228
|
+
const [yawStep, setYawStep] = useState(0);
|
|
229
|
+
const [walls, setWalls] = useState<BuiltWall[]>([]);
|
|
230
|
+
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
const onKey = (e: KeyboardEvent) => {
|
|
233
|
+
if (e.code === "Digit1") setTool("harvest");
|
|
234
|
+
else if (e.code === "Digit2") setTool("build");
|
|
235
|
+
else if (e.code === "KeyQ") setYawStep((s) => (s + 11) % 12);
|
|
236
|
+
else if (e.code === "KeyT") setTier((t) => (t === "wood" ? "stone" : "wood"));
|
|
237
|
+
};
|
|
238
|
+
window.addEventListener("keydown", onKey);
|
|
239
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
240
|
+
}, []);
|
|
241
|
+
|
|
242
|
+
const handleHarvest = useCallback((kind: "wood" | "stone", amt: number) => {
|
|
243
|
+
if (kind === "wood") setWood((w) => w + amt);
|
|
244
|
+
else setStone((s) => s + amt);
|
|
245
|
+
}, []);
|
|
246
|
+
|
|
247
|
+
const handlePlaceWall = useCallback((pos: [number, number, number], yaw: number) => {
|
|
248
|
+
if (tier === "wood" && wood < 15) return;
|
|
249
|
+
if (tier === "stone" && stone < 15) return;
|
|
250
|
+
if (tier === "wood") setWood((w) => w - 15);
|
|
251
|
+
else setStone((s) => s - 15);
|
|
252
|
+
setWalls((prev) => [...prev, { id: prev.length + 1, pos, yaw, tier }]);
|
|
253
|
+
}, [tier, wood, stone]);
|
|
254
|
+
|
|
255
|
+
const tierLabel = tier === "wood" ? "Wood" : "Stone";
|
|
256
|
+
return (
|
|
257
|
+
<div style={{ position: "relative", width: "100vw", height: "100dvh", overflow: "hidden", touchAction: "none", userSelect: "none", WebkitUserSelect: "none" }}>
|
|
258
|
+
<Game retro={RETRO_PS2_SHINOBI}>
|
|
259
|
+
<Island seed={77} size={960} settlementTier="town" />
|
|
260
|
+
<Vehicle />
|
|
261
|
+
<Actor />
|
|
262
|
+
<DustGameplay tool={tool} yawStep={yawStep} tier={tier} onHarvest={handleHarvest} walls={walls} onPlaceWall={handlePlaceWall} />
|
|
263
|
+
<Hud />
|
|
264
|
+
<MobileTouchOverlay />
|
|
265
|
+
</Game>
|
|
266
|
+
<div style={{ position: "fixed", top: "max(12px, env(safe-area-inset-top))", right: "max(12px, env(safe-area-inset-right))", zIndex: 40, padding: "8px 12px", background: "rgba(9,13,22,0.86)", border: "1px solid #f59e0b", borderRadius: 6, color: "#f8fafc", fontFamily: "ui-monospace, monospace", fontSize: 12 }}>
|
|
267
|
+
<div style={{ fontWeight: 700, color: "#fbbf24", marginBottom: 4 }}>Kolmo Dust · C12 Survival</div>
|
|
268
|
+
<div>Wood <b>{wood}</b> · Stone <b>{stone}</b> · Walls <b>{walls.length}</b></div>
|
|
269
|
+
<div style={{ color: "#94a3b8", marginTop: 4 }}>[1] Harvest ({tool === "harvest" ? "active" : "idle"}) · [2] Build C12 ({tool === "build" ? tierLabel : "idle"}) · [Q] Rotate 30° · [T] Tier · [Click/E] Use</div>
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
`;
|
|
275
|
+
|
|
276
|
+
const LONGLINE_WORLD_SRC = `import { useEffect, useMemo, useRef, useState } from "react";
|
|
277
|
+
import * as THREE from "three";
|
|
278
|
+
import { useFrame, useThree } from "@react-three/fiber";
|
|
279
|
+
import { CuboidCollider, RigidBody } from "@react-three/rapier";
|
|
280
|
+
import {
|
|
281
|
+
Junk,
|
|
282
|
+
SuikaSystem,
|
|
283
|
+
computeLongDriveMainlandSpawn,
|
|
284
|
+
hashSeed,
|
|
285
|
+
kolmoTelemetry,
|
|
286
|
+
readFloatingOriginAnchorXZ,
|
|
287
|
+
spawnSuikaOrb,
|
|
288
|
+
useActiveKolmoWorld,
|
|
289
|
+
} from "@pinkaphant/kolmo";
|
|
290
|
+
|
|
291
|
+
export interface HighwayHudState { km: number; fuelL: number; targetKm: number; cash: number; stage: number; scrap: number; }
|
|
292
|
+
export type BuildTier = "wood" | "stone" | "metal";
|
|
293
|
+
export interface BuiltC12Wall { id: number; wx: number; y: number; wz: number; yaw: number; tier: BuildTier; }
|
|
294
|
+
interface FuelCanItem { id: number; wx: number; wz: number; y: number; }
|
|
295
|
+
|
|
296
|
+
const _mat4 = new THREE.Matrix4();
|
|
297
|
+
const _quat = new THREE.Quaternion();
|
|
298
|
+
const _pos = new THREE.Vector3();
|
|
299
|
+
const _scale = new THREE.Vector3(1, 1, 1);
|
|
300
|
+
const _up = new THREE.Vector3(0, 1, 0);
|
|
301
|
+
const _fwd = new THREE.Vector3();
|
|
302
|
+
|
|
303
|
+
function InstancedC12Walls({ walls, origin, tier, color }: {
|
|
304
|
+
walls: readonly BuiltC12Wall[];
|
|
305
|
+
origin: readonly [number, number];
|
|
306
|
+
tier: BuildTier;
|
|
307
|
+
color: string;
|
|
308
|
+
}) {
|
|
309
|
+
const ref = useRef<THREE.InstancedMesh>(null);
|
|
310
|
+
const filtered = useMemo(() => walls.filter((w) => w.tier === tier), [walls, tier]);
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
const mesh = ref.current;
|
|
313
|
+
if (!mesh) return;
|
|
314
|
+
filtered.forEach((w, i) => {
|
|
315
|
+
_pos.set(w.wx - origin[0], w.y, w.wz - origin[1]);
|
|
316
|
+
_quat.setFromAxisAngle(_up, w.yaw);
|
|
317
|
+
_mat4.compose(_pos, _quat, _scale);
|
|
318
|
+
mesh.setMatrixAt(i, _mat4);
|
|
319
|
+
});
|
|
320
|
+
mesh.count = filtered.length;
|
|
321
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
322
|
+
}, [filtered, origin]);
|
|
323
|
+
if (filtered.length === 0) return null;
|
|
324
|
+
return (
|
|
325
|
+
<>
|
|
326
|
+
<instancedMesh ref={ref} args={[undefined, undefined, Math.max(1, filtered.length)]} castShadow receiveShadow>
|
|
327
|
+
<boxGeometry args={[3, 3, 0.28]} />
|
|
328
|
+
<meshStandardMaterial color={color} flatShading />
|
|
329
|
+
</instancedMesh>
|
|
330
|
+
{filtered.map((w) => (
|
|
331
|
+
<RigidBody key={w.id} type="fixed" position={[w.wx - origin[0], w.y, w.wz - origin[1]]} rotation={[0, w.yaw, 0]}>
|
|
332
|
+
<CuboidCollider args={[1.5, 1.5, 0.14]} />
|
|
333
|
+
</RigidBody>
|
|
334
|
+
))}
|
|
335
|
+
</>
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function LonglineGameplay({
|
|
340
|
+
seed, origin, tool, yawStep, tier, walls, onPlaceWall, onSyncHud,
|
|
341
|
+
}: {
|
|
342
|
+
seed: string;
|
|
343
|
+
origin: readonly [number, number];
|
|
344
|
+
tool: "drive" | "build";
|
|
345
|
+
yawStep: number;
|
|
346
|
+
tier: BuildTier;
|
|
347
|
+
walls: readonly BuiltC12Wall[];
|
|
348
|
+
onPlaceWall: (wx: number, y: number, wz: number, yaw: number) => void;
|
|
349
|
+
onSyncHud: (s: HighwayHudState) => void;
|
|
350
|
+
}) {
|
|
351
|
+
const world = useActiveKolmoWorld();
|
|
352
|
+
const camera = useThree((s) => s.camera);
|
|
353
|
+
const spawn = useMemo(() => computeLongDriveMainlandSpawn(hashSeed(seed), 1, 0), [seed]);
|
|
354
|
+
const anchorBuf = useRef<[number, number]>([0, 0]);
|
|
355
|
+
const prevWorld = useRef<[number, number] | null>(null);
|
|
356
|
+
const ghostRef = useRef<THREE.Mesh>(null);
|
|
357
|
+
const stats = useRef<HighwayHudState>({ km: 0, fuelL: 45, targetKm: 0.5, cash: 100, stage: 1, scrap: 60 });
|
|
358
|
+
const lastUiPush = useRef(0);
|
|
359
|
+
|
|
360
|
+
const initialCans = useMemo<FuelCanItem[]>(() =>
|
|
361
|
+
[1, 2, 3, 4].map((i) => ({
|
|
362
|
+
id: i,
|
|
363
|
+
wx: spawn.vehiclePos[0] + Math.sin(spawn.vehicleRot[1]) * i * 85 + 2.4,
|
|
364
|
+
wz: spawn.vehiclePos[2] + Math.cos(spawn.vehicleRot[1]) * i * 85,
|
|
365
|
+
y: spawn.vehiclePos[1] + 0.35,
|
|
366
|
+
})), [spawn]);
|
|
367
|
+
|
|
368
|
+
const cansRef = useRef<FuelCanItem[]>(initialCans);
|
|
369
|
+
const [cans, setCans] = useState<FuelCanItem[]>(initialCans);
|
|
370
|
+
const nextCanId = useRef(5);
|
|
371
|
+
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
const onDown = (e: MouseEvent) => {
|
|
374
|
+
if (e.button !== 0 || (e.target as HTMLElement)?.tagName !== "CANVAS") return;
|
|
375
|
+
const a = readFloatingOriginAnchorXZ(world, camera, anchorBuf.current);
|
|
376
|
+
_fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
377
|
+
if (tool === "build") {
|
|
378
|
+
const wx = Math.round((origin[0] + a[0] + _fwd.x * 6) / 3) * 3;
|
|
379
|
+
const wz = Math.round((origin[1] + a[1] + _fwd.z * 6) / 3) * 3;
|
|
380
|
+
onPlaceWall(wx, camera.position.y + 0.4, wz, (yawStep * Math.PI) / 6);
|
|
381
|
+
} else {
|
|
382
|
+
spawnSuikaOrb({
|
|
383
|
+
tier: 0,
|
|
384
|
+
position: [a[0] + _fwd.x * 2.2, camera.position.y + 0.5, a[1] + _fwd.z * 2.2],
|
|
385
|
+
velocity: [_fwd.x * 24, _fwd.y * 24 + 3, _fwd.z * 24],
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
window.addEventListener("mousedown", onDown);
|
|
390
|
+
return () => window.removeEventListener("mousedown", onDown);
|
|
391
|
+
}, [tool, yawStep, origin, world, camera, onPlaceWall]);
|
|
392
|
+
|
|
393
|
+
useFrame((_, delta) => {
|
|
394
|
+
const a = readFloatingOriginAnchorXZ(world, camera, anchorBuf.current);
|
|
395
|
+
const wx = origin[0] + a[0], wz = origin[1] + a[1];
|
|
396
|
+
if (ghostRef.current && tool === "build") {
|
|
397
|
+
_fwd.set(0, 0, -1).applyQuaternion(camera.quaternion);
|
|
398
|
+
const gx = Math.round((wx + _fwd.x * 6) / 3) * 3 - origin[0];
|
|
399
|
+
const gz = Math.round((wz + _fwd.z * 6) / 3) * 3 - origin[1];
|
|
400
|
+
ghostRef.current.position.set(gx, camera.position.y + 0.4, gz);
|
|
401
|
+
ghostRef.current.rotation.set(0, (yawStep * Math.PI) / 6, 0);
|
|
402
|
+
}
|
|
403
|
+
const prevX = prevWorld.current?.[0] ?? wx;
|
|
404
|
+
const prevZ = prevWorld.current?.[1] ?? wz - 1;
|
|
405
|
+
if (prevWorld.current) {
|
|
406
|
+
const stepM = Math.hypot(wx - prevX, wz - prevZ);
|
|
407
|
+
if (stepM > 0.01 && stepM < 60) {
|
|
408
|
+
stats.current.km += stepM / 1000;
|
|
409
|
+
stats.current.fuelL = Math.max(0, stats.current.fuelL - stepM * (kolmoTelemetry.boost > 0 ? 0.018 : 0.009));
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
prevWorld.current = [wx, wz];
|
|
413
|
+
|
|
414
|
+
if (stats.current.km >= stats.current.targetKm) {
|
|
415
|
+
stats.current.cash += 250 * stats.current.stage;
|
|
416
|
+
stats.current.scrap += 40;
|
|
417
|
+
stats.current.stage += 1;
|
|
418
|
+
stats.current.targetKm = +(stats.current.targetKm + 0.75).toFixed(2);
|
|
419
|
+
stats.current.fuelL = Math.min(60, stats.current.fuelL + 12);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
let picked = false;
|
|
423
|
+
for (let i = 0; i < cansRef.current.length; i++) {
|
|
424
|
+
if (Math.hypot(cansRef.current[i].wx - wx, cansRef.current[i].wz - wz) < 5.2) {
|
|
425
|
+
picked = true;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (picked) {
|
|
430
|
+
const fwdX = wx - prevX, fwdZ = wz - prevZ;
|
|
431
|
+
const len = Math.hypot(fwdX, fwdZ) || 1;
|
|
432
|
+
const next = cansRef.current.filter((c) => {
|
|
433
|
+
if (Math.hypot(c.wx - wx, c.wz - wz) < 5.2) {
|
|
434
|
+
stats.current.fuelL = Math.min(60, stats.current.fuelL + 18);
|
|
435
|
+
stats.current.cash += 50;
|
|
436
|
+
stats.current.scrap += 15;
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
});
|
|
441
|
+
next.push({ id: nextCanId.current++, wx: wx + (fwdX / len) * 220, wz: wz + (fwdZ / len) * 220, y: camera.position.y - 1.1 });
|
|
442
|
+
cansRef.current = next;
|
|
443
|
+
setCans(next);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
lastUiPush.current += delta;
|
|
447
|
+
if (lastUiPush.current >= 0.12) {
|
|
448
|
+
lastUiPush.current = 0;
|
|
449
|
+
onSyncHud({ ...stats.current });
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
return (
|
|
454
|
+
<group>
|
|
455
|
+
<SuikaSystem />
|
|
456
|
+
<Junk id="salvage_1" kind="tin-can" position={[spawn.vehiclePos[0] - origin[0] + 4, spawn.vehiclePos[1] + 0.5, spawn.vehiclePos[2] - origin[1] + 18]} />
|
|
457
|
+
<Junk id="salvage_2" kind="glass-bottle" position={[spawn.vehiclePos[0] - origin[0] - 4, spawn.vehiclePos[1] + 0.5, spawn.vehiclePos[2] - origin[1] + 24]} />
|
|
458
|
+
{tool === "build" && (
|
|
459
|
+
<mesh ref={ghostRef}>
|
|
460
|
+
<boxGeometry args={[3, 3, 0.28]} />
|
|
461
|
+
<meshStandardMaterial color={tier === "wood" ? "#f59e0b" : tier === "stone" ? "#94a3b8" : "#38bdf8"} transparent opacity={0.42} depthWrite={false} />
|
|
462
|
+
</mesh>
|
|
463
|
+
)}
|
|
464
|
+
<InstancedC12Walls walls={walls} origin={origin} tier="wood" color="#9a6324" />
|
|
465
|
+
<InstancedC12Walls walls={walls} origin={origin} tier="stone" color="#64748b" />
|
|
466
|
+
<InstancedC12Walls walls={walls} origin={origin} tier="metal" color="#334155" />
|
|
467
|
+
{cans.map((c) => (
|
|
468
|
+
<group key={c.id} position={[c.wx - origin[0], c.y, c.wz - origin[1]]}>
|
|
469
|
+
<mesh castShadow>
|
|
470
|
+
<boxGeometry args={[0.55, 0.75, 0.36]} />
|
|
471
|
+
<meshStandardMaterial color="#ef4444" emissive="#7f1d1d" flatShading />
|
|
472
|
+
</mesh>
|
|
473
|
+
<mesh position={[0, 1.6, 0]}>
|
|
474
|
+
<octahedronGeometry args={[0.35, 0]} />
|
|
475
|
+
<meshStandardMaterial color="#fbbf24" emissive="#f59e0b" flatShading />
|
|
476
|
+
</mesh>
|
|
477
|
+
</group>
|
|
478
|
+
))}
|
|
479
|
+
</group>
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
`;
|
|
483
|
+
|
|
484
|
+
const LONGLINE_APP_SRC = `import { useCallback, useEffect, useState } from "react";
|
|
485
|
+
import { Actor, Game, Hud, LongDrive, MobileTouchOverlay, PAPER_SHELL_PRESETS, RETRO_DREAMCAST, Vehicle, generateSeed8, normalizeSeed8 } from "@pinkaphant/kolmo";
|
|
486
|
+
import { LonglineGameplay, type BuildTier, type BuiltC12Wall, type HighwayHudState } from "./LonglineGameplay.tsx";
|
|
487
|
+
|
|
488
|
+
export function App() {
|
|
489
|
+
const [seed, setSeed] = useState<string>(() => generateSeed8());
|
|
490
|
+
const [seedInput, setSeedInput] = useState<string>(seed);
|
|
491
|
+
const [origin, setOrigin] = useState<[number, number]>([0, 0]);
|
|
492
|
+
const [tool, setTool] = useState<"drive" | "build">("drive");
|
|
493
|
+
const [tier, setTier] = useState<BuildTier>("wood");
|
|
494
|
+
const [yawStep, setYawStep] = useState(0);
|
|
495
|
+
const [walls, setWalls] = useState<BuiltC12Wall[]>([]);
|
|
496
|
+
const [hud, setHud] = useState<HighwayHudState>({ km: 0, fuelL: 45, targetKm: 0.5, cash: 100, stage: 1, scrap: 60 });
|
|
497
|
+
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
const onKey = (e: KeyboardEvent) => {
|
|
500
|
+
if ((e.target as HTMLElement)?.tagName === "INPUT") return;
|
|
501
|
+
if (e.code === "Digit1") setTool("drive");
|
|
502
|
+
else if (e.code === "Digit2") setTool("build");
|
|
503
|
+
else if (e.code === "KeyQ") setYawStep((s) => (s + 11) % 12);
|
|
504
|
+
else if (e.code === "KeyT") setTier((t) => (t === "wood" ? "stone" : t === "stone" ? "metal" : "wood"));
|
|
505
|
+
};
|
|
506
|
+
window.addEventListener("keydown", onKey);
|
|
507
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
508
|
+
}, []);
|
|
509
|
+
|
|
510
|
+
const handlePlaceWall = useCallback((wx: number, y: number, wz: number, yaw: number) => {
|
|
511
|
+
setWalls((prev) => [...prev, { id: prev.length + 1, wx, y, wz, yaw, tier }]);
|
|
512
|
+
}, [tier]);
|
|
513
|
+
|
|
514
|
+
const tierLabel = tier === "wood" ? "Wood" : tier === "stone" ? "Stone" : "Metal";
|
|
515
|
+
return (
|
|
516
|
+
<div style={{ position: "relative", width: "100vw", height: "100dvh", overflow: "hidden", touchAction: "none", userSelect: "none", WebkitUserSelect: "none" }}>
|
|
517
|
+
<Game key={seed} retro={RETRO_DREAMCAST}>
|
|
518
|
+
<LongDrive seed={seed} pureMainland onOriginRebase={(ox, oz) => setOrigin([ox, oz])} />
|
|
519
|
+
<Vehicle preset={PAPER_SHELL_PRESETS.sedan_92} piloted />
|
|
520
|
+
<Actor />
|
|
521
|
+
<LonglineGameplay seed={seed} origin={origin} tool={tool} yawStep={yawStep} tier={tier} walls={walls} onPlaceWall={handlePlaceWall} onSyncHud={setHud} />
|
|
522
|
+
<Hud />
|
|
523
|
+
<MobileTouchOverlay />
|
|
524
|
+
</Game>
|
|
525
|
+
<div style={{ position: "fixed", top: "max(12px, env(safe-area-inset-top))", right: "max(12px, env(safe-area-inset-right))", zIndex: 40, padding: "8px 12px", background: "rgba(9,13,22,0.88)", border: "1px solid #38bdf8", borderRadius: 6, color: "#f8fafc", fontFamily: "ui-monospace, monospace", fontSize: 12 }}>
|
|
526
|
+
<div style={{ display: "flex", alignItems: "center", gap: 6, marginBottom: 4 }}>
|
|
527
|
+
<b style={{ color: "#38bdf8" }}>Kolmo Longline · Stage {hud.stage} · Blind</b>
|
|
528
|
+
<input
|
|
529
|
+
value={seedInput}
|
|
530
|
+
maxLength={8}
|
|
531
|
+
onChange={(e) => setSeedInput(e.target.value.toUpperCase().replace(/0/g, "O").replace(/[^1-9A-Z]/g, ""))}
|
|
532
|
+
style={{ width: 82, background: "#0f172a", color: "#38bdf8", border: "1px solid #334155", borderRadius: 4, padding: "2px 6px", fontFamily: "inherit", fontWeight: 700 }}
|
|
533
|
+
/>
|
|
534
|
+
<button type="button" onClick={() => { const s = normalizeSeed8(seedInput); setSeedInput(s); setSeed(s); setWalls([]); }} style={{ cursor: "pointer", background: "#1e293b", color: "#e2e8f0", border: "1px solid #475569", borderRadius: 4, padding: "2px 6px" }}>Load</button>
|
|
535
|
+
<button type="button" onClick={() => { const s = generateSeed8(); setSeedInput(s); setSeed(s); setWalls([]); }} style={{ cursor: "pointer", background: "#0369a1", color: "#fff", border: "1px solid #0284c7", borderRadius: 4, padding: "2px 6px" }}>New seed</button>
|
|
536
|
+
</div>
|
|
537
|
+
<div>Odometer <b>{hud.km.toFixed(2)}/{hud.targetKm.toFixed(2)} km</b> · Fuel <b style={{ color: hud.fuelL < 10 ? "#f87171" : "#34d399" }}>{hud.fuelL.toFixed(1)} L</b> · Scrap <b>{hud.scrap}</b> · C12 walls <b>{walls.length}</b></div>
|
|
538
|
+
<div style={{ color: "#94a3b8", marginTop: 4 }}>[1] Drive/Orb ({tool === "drive" ? "active" : "idle"}) · [2] C12 build ({tool === "build" ? tierLabel : "idle"}) · [Q] 30° snap · [T] Tier · Click to place/launch</div>
|
|
539
|
+
</div>
|
|
540
|
+
</div>
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
`;
|
|
544
|
+
|
|
545
|
+
if (template === "dust") {
|
|
546
|
+
fs.writeFileSync(path.join(targetDir, "src/DustGameplay.tsx"), DUST_WORLD_SRC);
|
|
547
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), DUST_APP_SRC);
|
|
548
|
+
} else if (template === "longline") {
|
|
549
|
+
fs.writeFileSync(path.join(targetDir, "src/LonglineGameplay.tsx"), LONGLINE_WORLD_SRC);
|
|
550
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), LONGLINE_APP_SRC);
|
|
551
|
+
} else if (template === "garage") {
|
|
552
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), `import { GlbImportGate } from "@pinkaphant/kolmo/importer";\nexport function App() {\n return <GlbImportGate />;\n}\n`);
|
|
553
|
+
} else {
|
|
554
|
+
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), `import { Actor, Game, Hud, Island, MobileTouchOverlay, Vehicle } from "@pinkaphant/kolmo";\nexport function App() {\n return (\n <Game>\n <Island />\n <Vehicle piloted />\n <Actor />\n <Hud />\n <MobileTouchOverlay />\n </Game>\n );\n}\n`);
|
|
555
|
+
}
|
|
115
556
|
|
|
116
|
-
fs.writeFileSync(path.join(targetDir, "src/App.tsx"), appSrc);
|
|
117
557
|
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`);
|
|
118
558
|
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`);
|
|
119
559
|
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { ActorTrait, FloatingBodyTrait, InteractableTrait, PilotLink, PilotedTag
|
|
|
9
9
|
export { buildProceduralCarGlb, type ProceduralCarOptions } from "./kolmoProcedural.js";
|
|
10
10
|
export { loadOrAutoCompileVehicleGlb, type AutoCompileVehicleOptions } from "./kolmoVehicleAutoCompile.js";
|
|
11
11
|
export { KolmoGame, KolmoHud, KolmoOverlayContext, useKolmoGame, type KolmoGameHookState, type KolmoGameProps, type KolmoHudProps, } from "./kolmoGame.js";
|
|
12
|
+
export { KOLMO_STICK_DEADZONE, applyKolmoTouchLook, computeVirtualStick, defaultTouchActionsForMode, detectTouchDevice, kolmoTouchInput, resetKolmoTouchInput, resetKolmoTouchStick, snapshotKolmoTouchInput, writeKolmoTouchAction, type KolmoLookControls, type KolmoTouchActionButton, type KolmoTouchInputState, type VirtualStickSample, } from "./kolmoTouchState.js";
|
|
13
|
+
export { MobileTouchOverlay, type MobileTouchOverlayProps } from "./kolmoTouchOverlay.js";
|