@pinkaphant/kolmo 0.5.1 → 0.5.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/README.md +92 -14
- package/dist/engine/actor.d.ts +1 -1
- package/dist/engine/index.d.ts +3 -0
- package/dist/engine/index.js +94 -441
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/surface.d.ts +5 -6
- package/dist/engine/traits.d.ts +27 -0
- package/dist/engine/world.d.ts +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +10 -6
- package/dist/physics/index.d.ts +2 -1
- package/dist/physics/index.js +3 -1
- package/dist/physics-KYWAXctg.js +233 -0
- package/dist/physics-KYWAXctg.js.map +1 -0
- package/dist/replay/index.d.ts +84 -0
- package/dist/replay/index.js +380 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/terrain/index.d.ts +119 -0
- package/dist/terrain/index.js +495 -0
- package/dist/terrain/index.js.map +1 -0
- package/dist/toolgun/Toolgun.d.ts +17 -6
- package/dist/toolgun/index.d.ts +2 -2
- package/dist/toolgun/index.js +1 -1
- package/dist/toolgun/store.d.ts +25 -75
- package/dist/{toolgun-BfcCIAQx.js → toolgun-COu_5SxS.js} +391 -673
- package/dist/toolgun-COu_5SxS.js.map +1 -0
- package/dist/traits-Dp1ey_4w.js +267 -0
- package/dist/traits-Dp1ey_4w.js.map +1 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/index.js.map +1 -1
- package/dist/water/index.d.ts +71 -0
- package/dist/water/index.js +442 -0
- package/dist/water/index.js.map +1 -0
- package/dist/{surface-DUol_5ml.js → world-BDhBihjW.js} +442 -57
- package/dist/world-BDhBihjW.js.map +1 -0
- package/docs/api-reference.md +201 -0
- package/package.json +25 -8
- package/dist/physics-ZDFXaCli.js +0 -475
- package/dist/physics-ZDFXaCli.js.map +0 -1
- package/dist/surface-DUol_5ml.js.map +0 -1
- package/dist/toolgun-BfcCIAQx.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolgun-COu_5SxS.js","names":["_jsx","_jsxs","_Fragment"],"sources":["../src/toolgun/store.ts","../src/toolgun/Toolgun.tsx"],"sourcesContent":["import * as THREE from \"three\";\nimport type RAPIER from \"@dimforge/rapier3d-compat\";\nimport { create, type StoreApi, type UseBoundStore } from \"zustand\";\nimport { isJointOpen, toggleDrivenJoint, type JointRuntime, type KhrAssetBundle } from \"@khr3/core\";\nimport {\n STEP_METRES,\n canPlace,\n latticePose,\n poseEq,\n poseToFloat,\n snapPose,\n socketFor,\n wrapYaw,\n worldSockets,\n type PieceKind,\n type PiecePose,\n type PlacedPiece,\n type Socket,\n} from \"@khr3/c12\";\n\nexport const TOOLGUN_MODES = [\"spawn\", \"weld\", \"hinge\", \"rig\", \"build\", \"delete\"] as const;\nexport type ToolgunMode = (typeof TOOLGUN_MODES)[number];\n\nexport const TOOLGUN_BUILD_KINDS = [\n \"FoundationSquare\",\n \"FoundationTriangle\",\n \"Wall\",\n \"Doorway\",\n \"Floor\",\n \"FloorTriangle\",\n \"Roof\",\n \"RoofTriangle\",\n \"Stairs\",\n] as const satisfies readonly PieceKind[];\nexport type ToolgunBuildKind = (typeof TOOLGUN_BUILD_KINDS)[number];\n\nexport interface ArmedToolgunAsset {\n readonly id: string;\n readonly name: string;\n readonly src?: string;\n readonly bundle?: KhrAssetBundle;\n readonly kind?: \"auto\" | \"vehicle\" | \"prop\";\n readonly fixed?: boolean;\n}\n\nexport interface SpawnedToolgunEntity {\n readonly id: string;\n readonly name: string;\n readonly kind: \"vehicle\" | \"prop\";\n readonly src?: string;\n readonly bundle?: KhrAssetBundle;\n readonly fixed: boolean;\n readonly position: [number, number, number];\n readonly quaternion: [number, number, number, number];\n}\n\nexport interface CreatedToolgunJoint {\n readonly id: string;\n readonly kind: \"weld\" | \"hinge\";\n readonly world: RAPIER.World;\n readonly handle: number;\n readonly joint: RAPIER.ImpulseJoint;\n readonly anchorWorld: [number, number, number];\n}\n\nexport interface ToolgunRaycastResult {\n point: [number, number, number];\n normal: [number, number, number];\n toi: number;\n collider: RAPIER.Collider;\n body: RAPIER.RigidBody | null;\n}\n\nexport interface PendingJointAnchor {\n readonly world: RAPIER.World;\n readonly body: RAPIER.RigidBody;\n readonly worldPoint: [number, number, number];\n readonly worldNormal: [number, number, number];\n readonly label: string;\n}\n\nexport interface BuildSnapCandidate {\n readonly kind: ToolgunBuildKind;\n readonly pose: PiecePose;\n readonly position: [number, number, number];\n readonly quaternion: [number, number, number, number];\n readonly snappedSocket: boolean;\n readonly valid: boolean;\n readonly reason: string;\n}\n\nexport type ToolgunHistoryEntry =\n | { readonly type: \"spawn\"; readonly id: string }\n | { readonly type: \"piece\"; readonly id: string }\n | { readonly type: \"joint\"; readonly id: string };\n\nexport interface ToolgunActionOutcome {\n readonly ok: boolean;\n readonly status: string;\n readonly beamEnd: [number, number, number];\n}\n\ntype Vec3Input = { readonly x: number; readonly y: number; readonly z: number } | readonly [number, number, number];\n\nconst _upDefault = new THREE.Vector3(0, 1, 0);\nconst _nrmVec = new THREE.Vector3();\nconst _alignQuat = new THREE.Quaternion();\nconst _yawQuat = new THREE.Quaternion();\nconst _qA = new THREE.Quaternion();\nconst _qB = new THREE.Quaternion();\nconst _qInvA = new THREE.Quaternion();\nconst _qInvB = new THREE.Quaternion();\nconst _qRel = new THREE.Quaternion();\nconst _vA = new THREE.Vector3();\nconst _vB = new THREE.Vector3();\nconst _axLocal = new THREE.Vector3();\nconst _axWorldB = new THREE.Vector3();\n\nlet _sharedRay: RAPIER.Ray | null = null;\n\nfunction readVecX(v: Vec3Input): number {\n return Array.isArray(v) ? v[0] : (v as { readonly x: number }).x;\n}\nfunction readVecY(v: Vec3Input): number {\n return Array.isArray(v) ? v[1] : (v as { readonly y: number }).y;\n}\nfunction readVecZ(v: Vec3Input): number {\n return Array.isArray(v) ? v[2] : (v as { readonly z: number }).z;\n}\n\n/**\n * Casts a solid ray against Rapier WASM colliders using `QueryFilterFlags.EXCLUDE_SENSORS`,\n * ignoring the optional actor `RigidBody`. Pass `out` on hot `useFrame` paths for zero heap allocations.\n */\nexport function castToolgunRay(\n rapier: typeof RAPIER,\n world: RAPIER.World,\n origin: Vec3Input,\n direction: Vec3Input,\n maxRange = 80,\n excludeBody?: RAPIER.RigidBody | null,\n out?: ToolgunRaycastResult,\n): ToolgunRaycastResult | null {\n const ox = readVecX(origin), oy = readVecY(origin), oz = readVecZ(origin);\n const rx = readVecX(direction), ry = readVecY(direction), rz = readVecZ(direction);\n const dirLen = Math.hypot(rx, ry, rz);\n if (dirLen < 1e-8 || maxRange <= 0)\n return null;\n const dx = rx / dirLen;\n const dy = ry / dirLen;\n const dz = rz / dirLen;\n\n if (!_sharedRay) {\n _sharedRay = new rapier.Ray({ x: ox, y: oy, z: oz }, { x: dx, y: dy, z: dz });\n }\n else {\n _sharedRay.origin.x = ox;\n _sharedRay.origin.y = oy;\n _sharedRay.origin.z = oz;\n _sharedRay.dir.x = dx;\n _sharedRay.dir.y = dy;\n _sharedRay.dir.z = dz;\n }\n\n const hit = world.castRayAndGetNormal(\n _sharedRay,\n maxRange,\n true,\n rapier.QueryFilterFlags.EXCLUDE_SENSORS,\n undefined,\n undefined,\n excludeBody ?? undefined,\n );\n if (!hit)\n return null;\n\n const nLen = Math.hypot(hit.normal.x, hit.normal.y, hit.normal.z);\n const nx = nLen > 1e-6 ? hit.normal.x / nLen : 0;\n const ny = nLen > 1e-6 ? hit.normal.y / nLen : 1;\n const nz = nLen > 1e-6 ? hit.normal.z / nLen : 0;\n const px = ox + dx * hit.timeOfImpact;\n const py = oy + dy * hit.timeOfImpact;\n const pz = oz + dz * hit.timeOfImpact;\n\n if (out) {\n out.point[0] = px;\n out.point[1] = py;\n out.point[2] = pz;\n out.normal[0] = nx;\n out.normal[1] = ny;\n out.normal[2] = nz;\n out.toi = hit.timeOfImpact;\n out.collider = hit.collider;\n out.body = hit.collider.parent();\n return out;\n }\n\n return {\n point: [px, py, pz],\n normal: [nx, ny, nz],\n toi: hit.timeOfImpact,\n collider: hit.collider,\n body: hit.collider.parent(),\n };\n}\n\n/**\n * Aligns a spawned asset's +Y axis to `surfaceNormal` (when sloped <= 55°) composed with exact 30° `yaw12` turn.\n */\nexport function computeAlignedSpawnPose(\n point: readonly [number, number, number],\n yaw12: number,\n surfaceNormal: readonly [number, number, number] = [0, 1, 0],\n clearanceM = 0.04,\n): { position: [number, number, number]; quaternion: [number, number, number, number] } {\n _nrmVec.set(surfaceNormal[0], surfaceNormal[1], surfaceNormal[2]);\n if (_nrmVec.lengthSq() < 1e-6)\n _nrmVec.set(0, 1, 0);\n else\n _nrmVec.normalize();\n if (_nrmVec.y < 0.57)\n _nrmVec.set(0, 1, 0);\n _alignQuat.setFromUnitVectors(_upDefault, _nrmVec);\n const yawRad = (wrapYaw(yaw12) * Math.PI) / 6;\n _yawQuat.setFromAxisAngle(_upDefault, yawRad);\n _alignQuat.multiply(_yawQuat).normalize();\n return {\n position: [\n point[0] + _nrmVec.x * clearanceM,\n point[1] + _nrmVec.y * clearanceM,\n point[2] + _nrmVec.z * clearanceM,\n ],\n quaternion: [_alignQuat.x, _alignQuat.y, _alignQuat.z, _alignQuat.w],\n };\n}\n\n/**\n * Creates a real Rapier WASM Fixed `ImpulseJoint` locking `bodyA` and `bodyB` at their current relative 6-DOF pose.\n */\nexport function createWeldImpulseJoint(\n rapier: typeof RAPIER,\n world: RAPIER.World,\n bodyA: RAPIER.RigidBody,\n bodyB: RAPIER.RigidBody,\n worldAnchor: readonly [number, number, number],\n): RAPIER.ImpulseJoint {\n const tA = bodyA.translation();\n const rA = bodyA.rotation();\n const tB = bodyB.translation();\n const rB = bodyB.rotation();\n\n _qA.set(rA.x, rA.y, rA.z, rA.w).normalize();\n _qB.set(rB.x, rB.y, rB.z, rB.w).normalize();\n _qInvA.copy(_qA).invert();\n _qInvB.copy(_qB).invert();\n\n _vA.set(worldAnchor[0] - tA.x, worldAnchor[1] - tA.y, worldAnchor[2] - tA.z).applyQuaternion(_qInvA);\n _vB.set(worldAnchor[0] - tB.x, worldAnchor[1] - tB.y, worldAnchor[2] - tB.z).applyQuaternion(_qInvB);\n _qRel.copy(_qInvA).multiply(_qB).normalize();\n\n const data = rapier.JointData.fixed(\n { x: _vA.x, y: _vA.y, z: _vA.z },\n { x: _qRel.x, y: _qRel.y, z: _qRel.z, w: _qRel.w },\n { x: _vB.x, y: _vB.y, z: _vB.z },\n { x: 0, y: 0, z: 0, w: 1 },\n );\n const imp = world.createImpulseJoint(data, bodyA, bodyB, true);\n imp.setContactsEnabled(false);\n if (bodyA.isDynamic())\n bodyA.wakeUp();\n if (bodyB.isDynamic())\n bodyB.wakeUp();\n return imp;\n}\n\n/**\n * Creates a real Rapier WASM Revolute `ImpulseJoint` around `worldAxis` through `worldAnchor`.\n * Aligns `bodyB`'s hinge shaft to `worldAxis` about `worldAnchor` when `bodyB` is tilted off-axis so `t=0` has zero snap error.\n */\nexport function createHingeImpulseJoint(\n rapier: typeof RAPIER,\n world: RAPIER.World,\n bodyA: RAPIER.RigidBody,\n bodyB: RAPIER.RigidBody,\n worldAnchor: readonly [number, number, number],\n worldAxis: readonly [number, number, number] = [0, 1, 0],\n): RAPIER.ImpulseJoint {\n _nrmVec.set(worldAxis[0], worldAxis[1], worldAxis[2]);\n if (_nrmVec.lengthSq() < 1e-8)\n _nrmVec.set(0, 1, 0);\n else\n _nrmVec.normalize();\n\n const tA = bodyA.translation();\n const rA = bodyA.rotation();\n const tB = bodyB.translation();\n const rB = bodyB.rotation();\n\n _qA.set(rA.x, rA.y, rA.z, rA.w).normalize();\n _qB.set(rB.x, rB.y, rB.z, rB.w).normalize();\n _qInvA.copy(_qA).invert();\n _qInvB.copy(_qB).invert();\n\n _vA.set(worldAnchor[0] - tA.x, worldAnchor[1] - tA.y, worldAnchor[2] - tA.z).applyQuaternion(_qInvA);\n _vB.set(worldAnchor[0] - tB.x, worldAnchor[1] - tB.y, worldAnchor[2] - tB.z).applyQuaternion(_qInvB);\n _axLocal.copy(_nrmVec).applyQuaternion(_qInvA).normalize();\n\n _axWorldB.copy(_axLocal).applyQuaternion(_qB).normalize();\n if (_axWorldB.dot(_nrmVec) < 1 - 1e-5 && bodyB.isDynamic()) {\n _alignQuat.setFromUnitVectors(_axWorldB, _nrmVec).multiply(_qB).normalize();\n const worldOffsetB = _axWorldB.copy(_vB).applyQuaternion(_alignQuat);\n bodyB.setRotation({ x: _alignQuat.x, y: _alignQuat.y, z: _alignQuat.z, w: _alignQuat.w }, true);\n bodyB.setTranslation(\n {\n x: worldAnchor[0] - worldOffsetB.x,\n y: worldAnchor[1] - worldOffsetB.y,\n z: worldAnchor[2] - worldOffsetB.z,\n },\n true,\n );\n }\n\n const data = rapier.JointData.revolute(\n { x: _vA.x, y: _vA.y, z: _vA.z },\n { x: _vB.x, y: _vB.y, z: _vB.z },\n { x: _axLocal.x, y: _axLocal.y, z: _axLocal.z },\n );\n const imp = world.createImpulseJoint(data, bodyA, bodyB, true);\n imp.setContactsEnabled(false);\n if (bodyA.isDynamic())\n bodyA.wakeUp();\n if (bodyB.isDynamic())\n bodyB.wakeUp();\n return imp;\n}\n\n/**\n * Toggles or breaks an articulated `@khr3/core` `JointRuntime`.\n */\nexport function rigJointRuntime(rt: JointRuntime, severBreakaway = false): string {\n if (rt.detached)\n return `${rt.nodeName} already detached`;\n if (severBreakaway) {\n const res = rt.applyImpactImpulse(Number.POSITIVE_INFINITY);\n if (res === \"detached\")\n return `Detached ${rt.nodeName}`;\n }\n const wasOpen = isJointOpen(rt);\n if (toggleDrivenJoint(rt))\n return `${wasOpen ? \"Closed\" : \"Opened\"} ${rt.nodeName}`;\n const res = rt.applyImpactImpulse(Number.POSITIVE_INFINITY);\n return res === \"detached\" ? `Detached ${rt.nodeName}` : `Joint ${rt.nodeName} (${rt.kind})`;\n}\n\n/**\n * Exact equality check for `BuildSnapCandidate` using `@khr3/c12`'s `poseEq`\n * (avoiding float quaternion sign collisions such as 60° vs 300° where `qy === 0.5`).\n */\nexport function isSameBuildPreview(a: BuildSnapCandidate | null, b: BuildSnapCandidate): boolean {\n if (!a)\n return false;\n return (\n a.kind === b.kind &&\n a.valid === b.valid &&\n a.snappedSocket === b.snappedSocket &&\n a.reason === b.reason &&\n poseEq(a.pose, b.pose)\n );\n}\n\n/**\n * Computes the nearest exact `@khr3/c12` socket-snapped or ground-lattice `BuildSnapCandidate` for `kind`.\n */\nexport function computeBuildCandidate(\n placedPieces: readonly PlacedPiece[],\n aimPoint: readonly [number, number, number],\n kind: ToolgunBuildKind,\n yaw12: number,\n snapRadiusM = 2.6,\n): BuildSnapCandidate {\n const wantedSocketKind = socketFor(kind);\n const maxDistSq = snapRadiusM * snapRadiusM;\n let bestSocket: Socket | null = null;\n let bestDistSq = maxDistSq;\n\n for (const placed of placedPieces) {\n const socks = worldSockets(placed.kind, placed.pose);\n for (const s of socks) {\n if (kind === \"FoundationSquare\" || kind === \"FoundationTriangle\") {\n if (s.kind !== \"edge\")\n continue;\n }\n else if (s.kind !== wantedSocketKind) {\n continue;\n }\n const flt = poseToFloat({ pos: s.mid, yaw: s.yaw });\n const dx = flt.position[0] - aimPoint[0];\n const dy = flt.position[1] - aimPoint[1];\n const dz = flt.position[2] - aimPoint[2];\n const dSq = dx * dx + dy * dy + dz * dz;\n if (dSq < bestDistSq) {\n const testOwn = kind === \"Stairs\" ? Math.floor(wrapYaw(yaw12) / 3) : wrapYaw(yaw12);\n const candidatePose = snapPose(kind, s, testOwn);\n if (canPlace(placedPieces, kind, candidatePose).ok) {\n bestDistSq = dSq;\n bestSocket = s;\n }\n }\n }\n }\n\n let pose: PiecePose;\n let snappedSocket = false;\n if (bestSocket) {\n const own = kind === \"Stairs\" ? Math.floor(wrapYaw(yaw12) / 3) : wrapYaw(yaw12);\n pose = snapPose(kind, bestSocket, own);\n snappedSocket = true;\n }\n else {\n const xSteps = Math.round(aimPoint[0] / STEP_METRES);\n const ySteps = Math.max(0, Math.round(aimPoint[1] / STEP_METRES));\n const zSteps = Math.round(aimPoint[2] / STEP_METRES);\n pose = latticePose(xSteps, zSteps, wrapYaw(yaw12), ySteps);\n }\n\n const check = canPlace(placedPieces, kind, pose);\n const flt = poseToFloat(pose);\n return {\n kind,\n pose,\n position: flt.position,\n quaternion: flt.quaternion,\n snappedSocket,\n valid: check.ok,\n reason: check.reason,\n };\n}\n\nfunction bodyMatchesSpawnedId(body: RAPIER.RigidBody | null | undefined, spawnedId: string): boolean {\n if (!body)\n return false;\n const ud = body.userData as { kolmoSpawnedId?: string } | undefined;\n return ud?.kolmoSpawnedId === spawnedId;\n}\n\nexport interface ToolgunStoreState {\n readonly mode: ToolgunMode;\n readonly yaw12: number;\n readonly buildKind: ToolgunBuildKind;\n readonly zoomed: boolean;\n readonly armedAsset: ArmedToolgunAsset | null;\n readonly buildPreview: BuildSnapCandidate | null;\n readonly pendingAnchor: PendingJointAnchor | null;\n readonly spawnedEntities: readonly SpawnedToolgunEntity[];\n readonly placedPieces: readonly PlacedPiece[];\n readonly createdJoints: readonly CreatedToolgunJoint[];\n readonly history: readonly ToolgunHistoryEntry[];\n readonly statusText: string;\n readonly fireCount: number;\n\n setMode: (mode: ToolgunMode) => void;\n cycleMode: (delta?: number) => void;\n rotateYaw12: (stepsDelta?: number) => void;\n setBuildKind: (kind: ToolgunBuildKind) => void;\n cycleBuildKind: (delta?: number) => void;\n setZoomed: (zoomed: boolean) => void;\n armAsset: (asset: ArmedToolgunAsset | null) => void;\n setBuildPreview: (candidate: BuildSnapCandidate | null) => void;\n setPendingAnchor: (anchor: PendingJointAnchor | null) => void;\n recordSpawn: (entry: SpawnedToolgunEntity) => void;\n placeBuildPiece: (candidate: BuildSnapCandidate) => PlacedPiece | null;\n recordJoint: (entry: CreatedToolgunJoint) => void;\n removeEntityById: (id: string, world?: RAPIER.World | null) => boolean;\n removePieceById: (id: string) => boolean;\n removeJointByBody: (world: RAPIER.World, body: RAPIER.RigidBody) => number;\n clearWorldHandles: (world: RAPIER.World) => void;\n undoLast: (world?: RAPIER.World | null) => string;\n bumpFire: (status: string) => void;\n resetAll: (world?: RAPIER.World | null) => void;\n}\n\nlet nextSeq = 1;\n\nexport function createToolgunStore(): UseBoundStore<StoreApi<ToolgunStoreState>> {\n return create<ToolgunStoreState>((set, get) => ({\n mode: \"spawn\",\n yaw12: 0,\n buildKind: \"FoundationSquare\",\n zoomed: false,\n armedAsset: null,\n buildPreview: null,\n pendingAnchor: null,\n spawnedEntities: [],\n placedPieces: [],\n createdJoints: [],\n history: [],\n statusText: \"READY\",\n fireCount: 0,\n\n setMode: (mode) => set({ mode, pendingAnchor: null, statusText: `MODE: ${mode.toUpperCase()}` }),\n cycleMode: (delta = 1) => {\n const idx = TOOLGUN_MODES.indexOf(get().mode);\n const next = TOOLGUN_MODES[((idx + delta) % TOOLGUN_MODES.length + TOOLGUN_MODES.length) % TOOLGUN_MODES.length];\n set({ mode: next, pendingAnchor: null, statusText: `MODE: ${next.toUpperCase()}` });\n },\n rotateYaw12: (stepsDelta = 1) => {\n const nextYaw = wrapYaw(get().yaw12 + stepsDelta);\n set({ yaw12: nextYaw, statusText: `YAW: ${nextYaw * 30}°` });\n },\n setBuildKind: (buildKind) => set({ buildKind, mode: \"build\", statusText: `BUILD: ${buildKind}` }),\n cycleBuildKind: (delta = 1) => {\n const idx = TOOLGUN_BUILD_KINDS.indexOf(get().buildKind);\n const next = TOOLGUN_BUILD_KINDS[((idx + delta) % TOOLGUN_BUILD_KINDS.length + TOOLGUN_BUILD_KINDS.length) % TOOLGUN_BUILD_KINDS.length];\n set({ buildKind: next, statusText: `BUILD: ${next}` });\n },\n setZoomed: (zoomed) => set({ zoomed }),\n armAsset: (armedAsset) => set({\n armedAsset,\n ...(armedAsset ? { statusText: `ARMED: ${armedAsset.name}` } : {}),\n }),\n setBuildPreview: (buildPreview) => set({ buildPreview }),\n setPendingAnchor: (pendingAnchor) => set({ pendingAnchor }),\n\n recordSpawn: (entry) => set((s) => ({\n spawnedEntities: [...s.spawnedEntities, entry],\n history: [...s.history, { type: \"spawn\", id: entry.id }],\n statusText: `SPAWNED ${entry.name}`,\n fireCount: s.fireCount + 1,\n })),\n\n placeBuildPiece: (candidate) => {\n const st = get();\n const check = canPlace(st.placedPieces, candidate.kind, candidate.pose);\n if (!check.ok) {\n set({ statusText: check.reason.toUpperCase(), fireCount: st.fireCount + 1 });\n return null;\n }\n const piece: PlacedPiece = {\n id: `c12_${nextSeq++}`,\n kind: candidate.kind,\n pose: candidate.pose,\n };\n set((s) => ({\n placedPieces: [...s.placedPieces, piece],\n history: [...s.history, { type: \"piece\", id: piece.id }],\n statusText: `PLACED ${piece.kind}`,\n fireCount: s.fireCount + 1,\n }));\n return piece;\n },\n\n recordJoint: (entry) => set((s) => ({\n createdJoints: [...s.createdJoints, entry],\n history: [...s.history, { type: \"joint\", id: entry.id }],\n pendingAnchor: null,\n statusText: `${entry.kind === \"weld\" ? \"WELDED\" : \"HINGED\"} #${entry.handle}`,\n fireCount: s.fireCount + 1,\n })),\n\n removeEntityById: (id, world) => {\n const st = get();\n if (!st.spawnedEntities.some((e) => e.id === id))\n return false;\n const removedJointIds = new Set<string>();\n const keptJoints: CreatedToolgunJoint[] = [];\n for (const cj of st.createdJoints) {\n if (!world || cj.world !== world) {\n if (!world || cj.world !== world)\n keptJoints.push(cj);\n continue;\n }\n const live = world.getImpulseJoint(cj.joint.handle);\n if (!live) {\n removedJointIds.add(cj.id);\n continue;\n }\n if (bodyMatchesSpawnedId(live.body1(), id) || bodyMatchesSpawnedId(live.body2(), id)) {\n world.removeImpulseJoint(live, true);\n removedJointIds.add(cj.id);\n }\n else {\n keptJoints.push(cj);\n }\n }\n const clearPending = st.pendingAnchor && (!world || st.pendingAnchor.world === world)\n ? bodyMatchesSpawnedId(st.pendingAnchor.body, id)\n : false;\n set((s) => ({\n spawnedEntities: s.spawnedEntities.filter((e) => e.id !== id),\n createdJoints: keptJoints,\n ...(clearPending ? { pendingAnchor: null } : {}),\n history: s.history.filter((h) => !(h.type === \"spawn\" && h.id === id) && !(h.type === \"joint\" && removedJointIds.has(h.id))),\n statusText: `DELETED ${id}`,\n fireCount: s.fireCount + 1,\n }));\n return true;\n },\n\n removePieceById: (id) => {\n const before = get().placedPieces;\n if (!before.some((p) => p.id === id))\n return false;\n set((s) => ({\n placedPieces: s.placedPieces.filter((p) => p.id !== id),\n history: s.history.filter((h) => !(h.type === \"piece\" && h.id === id)),\n statusText: `REMOVED ${id}`,\n fireCount: s.fireCount + 1,\n }));\n return true;\n },\n\n removeJointByBody: (world, body) => {\n const keep: CreatedToolgunJoint[] = [];\n const removedIds = new Set<string>();\n for (const cj of get().createdJoints) {\n if (cj.world !== world) {\n keep.push(cj);\n continue;\n }\n const live = world.getImpulseJoint(cj.joint.handle);\n if (!live) {\n removedIds.add(cj.id);\n continue;\n }\n if (live.body1().handle === body.handle || live.body2().handle === body.handle) {\n world.removeImpulseJoint(live, true);\n removedIds.add(cj.id);\n }\n else {\n keep.push(cj);\n }\n }\n if (removedIds.size > 0) {\n set((s) => ({\n createdJoints: keep,\n history: s.history.filter((h) => !(h.type === \"joint\" && removedIds.has(h.id))),\n statusText: `UNWELDED (${removedIds.size})`,\n fireCount: s.fireCount + 1,\n }));\n }\n return removedIds.size;\n },\n\n clearWorldHandles: (world) => {\n const st = get();\n const clearPending = st.pendingAnchor?.world === world;\n const hasWorldJoints = st.createdJoints.some((cj) => cj.world === world);\n if (!clearPending && !hasWorldJoints)\n return;\n const removedIds = new Set(st.createdJoints.filter((cj) => cj.world === world).map((cj) => cj.id));\n set((s) => ({\n ...(clearPending ? { pendingAnchor: null } : {}),\n createdJoints: s.createdJoints.filter((cj) => cj.world !== world),\n history: s.history.filter((h) => !(h.type === \"joint\" && removedIds.has(h.id))),\n }));\n },\n\n undoLast: (world) => {\n const st = get();\n const last = st.history[st.history.length - 1];\n if (!last)\n return \"NOTHING TO UNDO\";\n if (last.type === \"spawn\") {\n get().removeEntityById(last.id, world);\n set({ statusText: `UNDO SPAWN ${last.id}` });\n return `UNDO SPAWN ${last.id}`;\n }\n const nextHistory = st.history.slice(0, -1);\n if (last.type === \"piece\") {\n set({\n placedPieces: st.placedPieces.filter((p) => p.id !== last.id),\n history: nextHistory,\n statusText: `UNDO PIECE ${last.id}`,\n });\n return `UNDO PIECE ${last.id}`;\n }\n const jEntry = st.createdJoints.find((j) => j.id === last.id);\n if (jEntry && world && jEntry.world === world) {\n const liveJoint = world.getImpulseJoint(jEntry.joint.handle);\n if (liveJoint)\n world.removeImpulseJoint(liveJoint, true);\n }\n set({\n createdJoints: st.createdJoints.filter((j) => j.id !== last.id),\n history: nextHistory,\n statusText: `UNDO JOINT ${last.id}`,\n });\n return `UNDO JOINT ${last.id}`;\n },\n\n bumpFire: (statusText) => set((s) => ({ statusText, fireCount: s.fireCount + 1 })),\n\n resetAll: (world) => {\n if (world) {\n for (const cj of get().createdJoints) {\n if (cj.world !== world)\n continue;\n const liveJoint = world.getImpulseJoint(cj.joint.handle);\n if (liveJoint)\n world.removeImpulseJoint(liveJoint, true);\n }\n }\n set({\n pendingAnchor: null,\n spawnedEntities: [],\n placedPieces: [],\n createdJoints: [],\n history: [],\n statusText: \"CLEARED\",\n });\n },\n }));\n}\n\nexport const useToolgunStore = createToolgunStore();\n","import React, { useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef } from \"react\";\nimport * as THREE from \"three\";\nimport { createPortal, useFrame, useThree } from \"@react-three/fiber\";\nimport { useRapier } from \"@react-three/rapier\";\nimport type RAPIER from \"@dimforge/rapier3d-compat\";\nimport { easing } from \"maath\";\nimport type { EcctrlHandle } from \"@pinkaphant/ecctrl\";\nimport { JointRegistryContext, cloneKhrBundle, useKhrGlb, type JointRuntime, type KhrAssetBundle } from \"@khr3/core\";\nimport { poseToFloat, type PieceKind, type PlacedPiece } from \"@khr3/c12\";\nimport { ActorTrait, pilotedVehicleQuery, useActiveKolmoWorld } from \"../engine/traits.js\";\nimport { KolmoProp } from \"../engine/surface.js\";\nimport { KolmoVehicle } from \"../engine/vehicle.js\";\nimport { useKolmoGame } from \"../engine/world.js\";\nimport {\n TOOLGUN_MODES,\n castToolgunRay,\n computeAlignedSpawnPose,\n computeBuildCandidate,\n createHingeImpulseJoint,\n createWeldImpulseJoint,\n isSameBuildPreview,\n rigJointRuntime,\n useToolgunStore,\n type ArmedToolgunAsset,\n type BuildSnapCandidate,\n type SpawnedToolgunEntity,\n type ToolgunActionOutcome,\n type ToolgunMode,\n type ToolgunRaycastResult,\n} from \"./store.js\";\n\nconst LCD_W = 256;\nconst LCD_H = 192;\nconst DEFAULT_ACCENT_HEX = \"#38bdf8\";\nconst VAULT_CITY_BASE = \"https://khr3.optimuspi.workers.dev/assets/city\";\n\nexport const DEFAULT_VAULT_C12_URLS: Readonly<Record<PieceKind, string>> = Object.freeze({\n FoundationSquare: `${VAULT_CITY_BASE}/foundation_square_3x3.glb`,\n FoundationTriangle: `${VAULT_CITY_BASE}/foundation_triangle_3m.glb`,\n Street: `${VAULT_CITY_BASE}/R_Straight_6x6.glb`,\n Wall: `${VAULT_CITY_BASE}/wall_solid_3x3x200mm.glb`,\n Doorway: `${VAULT_CITY_BASE}/wall_clapboard_doorframe_3x3.glb`,\n DoorLeaf: `${VAULT_CITY_BASE}/door_hinged_single_900x2100.glb`,\n Floor: `${VAULT_CITY_BASE}/floor_square_3x3.glb`,\n FloorTriangle: `${VAULT_CITY_BASE}/floor_triangle_3m.glb`,\n Roof: `${VAULT_CITY_BASE}/roof_flat_3x3.glb`,\n RoofTriangle: `${VAULT_CITY_BASE}/roof_triangle_3m.glb`,\n Stairs: `${VAULT_CITY_BASE}/stairs_3x3.glb`,\n});\n\nexport interface MeasuredToolgunScreen {\n readonly pos: [number, number, number];\n readonly quat: [number, number, number, number];\n readonly size: [number, number];\n}\n\nexport interface MeasuredToolgunViewmodel {\n readonly scene: THREE.Object3D;\n readonly gripOffset: [number, number, number];\n readonly muzzleLocal: [number, number, number];\n readonly screen: MeasuredToolgunScreen | null;\n}\n\n/**\n * Measures grip, muzzle, and optional LCD bezel (`screen_rect` / `lcd_screen`) sockets on an already-cloned viewmodel scene.\n * Offsets the LCD quad 1mm along `screen_rect`'s local +Z normal in root space so arbitrary bezel orientations never z-fight.\n */\nexport function measureToolgunViewmodel(clonedScene: THREE.Object3D): MeasuredToolgunViewmodel {\n clonedScene.updateMatrixWorld(true);\n const invRoot = clonedScene.matrixWorld.clone().invert();\n const invRootQuat = clonedScene.getWorldQuaternion(new THREE.Quaternion()).invert();\n const rootScale = clonedScene.getWorldScale(new THREE.Vector3());\n let grip: [number, number, number] = [0, 0, 0];\n let muzzle: [number, number, number] = [0, 0.04, -0.24];\n let screen: MeasuredToolgunScreen | null = null;\n const tmpPos = new THREE.Vector3();\n const tmpQuat = new THREE.Quaternion();\n const tmpPlaneRot = new THREE.Quaternion();\n const tmpNormal = new THREE.Vector3();\n const tmpSize = new THREE.Vector3();\n const tmpScale = new THREE.Vector3();\n\n clonedScene.traverse((node) => {\n const low = node.name.toLowerCase();\n if (low === \"ik_palm_primary\" || low === \"grip\" || low === \"socket_grip\" || low === \"piezo_grip\") {\n node.getWorldPosition(tmpPos).applyMatrix4(invRoot);\n grip = [-tmpPos.x, -tmpPos.y, -tmpPos.z];\n }\n else if (low === \"socket_muzzle\" || low === \"muzzle\") {\n node.getWorldPosition(tmpPos).applyMatrix4(invRoot);\n muzzle = [tmpPos.x, tmpPos.y, tmpPos.z];\n }\n else if (low === \"screen_rect\" || low === \"lcd_screen\") {\n node.getWorldPosition(tmpPos).applyMatrix4(invRoot);\n node.getWorldQuaternion(tmpQuat).premultiply(invRootQuat).normalize();\n node.getWorldScale(tmpScale);\n const sx = Math.abs(rootScale.x) > 1e-6 ? Math.abs(tmpScale.x / rootScale.x) : 1;\n const sy = Math.abs(rootScale.y) > 1e-6 ? Math.abs(tmpScale.y / rootScale.y) : 1;\n const sz = Math.abs(rootScale.z) > 1e-6 ? Math.abs(tmpScale.z / rootScale.z) : 1;\n const mesh = node as THREE.Mesh;\n let screenSize: [number, number] = [0.068, 0.051];\n tmpPlaneRot.identity();\n if (mesh.isMesh && mesh.geometry) {\n mesh.geometry.computeBoundingBox();\n const bb = mesh.geometry.boundingBox;\n if (bb) {\n bb.getSize(tmpSize);\n const ex = tmpSize.x * sx;\n const ey = tmpSize.y * sy;\n const ez = tmpSize.z * sz;\n if (ez <= ex && ez <= ey) {\n screenSize = [Math.max(0.025, ex), Math.max(0.02, ey)];\n }\n else if (ey <= ex && ey <= ez) {\n tmpPlaneRot.setFromAxisAngle(new THREE.Vector3(1, 0, 0), -Math.PI / 2);\n screenSize = [Math.max(0.025, ex), Math.max(0.02, ez)];\n }\n else {\n tmpPlaneRot.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 2);\n screenSize = [Math.max(0.025, ez), Math.max(0.02, ey)];\n }\n }\n mesh.visible = false;\n }\n tmpQuat.multiply(tmpPlaneRot).normalize();\n tmpNormal.set(0, 0, 1).applyQuaternion(tmpQuat);\n screen = {\n pos: [tmpPos.x + tmpNormal.x * 0.001, tmpPos.y + tmpNormal.y * 0.001, tmpPos.z + tmpNormal.z * 0.001],\n quat: [tmpQuat.x, tmpQuat.y, tmpQuat.z, tmpQuat.w],\n size: screenSize,\n };\n }\n });\n\n return { scene: clonedScene, gripOffset: grip, muzzleLocal: muzzle, screen };\n}\n\ninterface LcdSurface {\n readonly texture: THREE.CanvasTexture | null;\n draw: (state: {\n mode: ToolgunMode;\n yawDeg: number;\n detail: string;\n targetLabel: string;\n status: string;\n accentColor: string;\n }) => void;\n dispose: () => void;\n}\n\nfunction createLcdSurface(): LcdSurface {\n if (typeof document === \"undefined\") {\n return { texture: null, draw: () => {}, dispose: () => {} };\n }\n const canvas = document.createElement(\"canvas\");\n canvas.width = LCD_W;\n canvas.height = LCD_H;\n const ctx = canvas.getContext(\"2d\");\n const texture = new THREE.CanvasTexture(canvas);\n texture.colorSpace = THREE.SRGBColorSpace;\n texture.minFilter = THREE.LinearFilter;\n texture.magFilter = THREE.LinearFilter;\n texture.generateMipmaps = false;\n\n let prevSig = \"\";\n return {\n texture,\n draw: ({ mode, yawDeg, detail, targetLabel, status, accentColor }) => {\n if (!ctx)\n return;\n const sig = `${mode}|${yawDeg}|${detail}|${targetLabel}|${status}|${accentColor}`;\n if (sig === prevSig)\n return;\n prevSig = sig;\n\n ctx.fillStyle = \"#070d19\";\n ctx.fillRect(0, 0, LCD_W, LCD_H);\n\n ctx.strokeStyle = accentColor;\n ctx.lineWidth = 3;\n ctx.strokeRect(4, 4, LCD_W - 8, LCD_H - 8);\n\n ctx.fillStyle = accentColor;\n ctx.fillRect(4, 4, LCD_W - 8, 28);\n ctx.fillStyle = \"#040812\";\n ctx.font = \"bold 15px ui-monospace, SFMono-Regular, Menlo, monospace\";\n ctx.fillText(`KOLMO // ${mode.toUpperCase()}`, 12, 23);\n ctx.textAlign = \"right\";\n ctx.fillText(`${yawDeg}°`, LCD_W - 12, 23);\n ctx.textAlign = \"left\";\n\n ctx.fillStyle = \"#e2e8f0\";\n ctx.font = \"bold 13px ui-monospace, SFMono-Regular, Menlo, monospace\";\n ctx.fillText(detail.slice(0, 26), 12, 58);\n\n ctx.fillStyle = \"#7dd3fc\";\n ctx.font = \"12px ui-monospace, SFMono-Regular, Menlo, monospace\";\n ctx.fillText(targetLabel.slice(0, 28), 12, 86);\n\n ctx.strokeStyle = \"rgba(148, 163, 184, 0.28)\";\n ctx.lineWidth = 1;\n ctx.beginPath();\n ctx.moveTo(12, 106);\n ctx.lineTo(LCD_W - 12, 106);\n ctx.stroke();\n\n ctx.fillStyle = \"#34d399\";\n ctx.font = \"bold 12px ui-monospace, SFMono-Regular, Menlo, monospace\";\n ctx.fillText(status.slice(0, 28), 12, 130);\n\n ctx.fillStyle = \"#94a3b8\";\n ctx.font = \"10px ui-monospace, SFMono-Regular, Menlo, monospace\";\n ctx.fillText(\"[1-6/Q] MODE [R] +30° [Z] UNDO\", 12, 160);\n ctx.fillText(\"[LMB] FIRE [RMB] ZOOM [[/]] C12\", 12, 176);\n\n texture.needsUpdate = true;\n },\n dispose: () => {\n texture.dispose();\n },\n };\n}\n\nexport interface KolmoToolgunHandle {\n fire: (shiftKey?: boolean) => ToolgunActionOutcome;\n undo: () => string;\n}\n\nexport interface KolmoToolgunProps {\n readonly ref?: React.Ref<KolmoToolgunHandle>;\n readonly src?: string;\n readonly bundle?: KhrAssetBundle | null;\n readonly c12Bundles?: Partial<Record<PieceKind, KhrAssetBundle>>;\n readonly c12Urls?: Partial<Record<PieceKind, string>> | null;\n readonly actorRef?: React.RefObject<EcctrlHandle | null>;\n readonly accentColor?: string;\n readonly defaultArmedAsset?: ArmedToolgunAsset | null;\n readonly maxRangeM?: number;\n readonly hipOffset?: readonly [number, number, number];\n readonly zoomOffset?: readonly [number, number, number];\n readonly enableShortcuts?: boolean;\n readonly mountWorldOutlets?: boolean;\n readonly enable?: boolean;\n}\n\nconst SpawnedToolgunOutlet = React.memo(function SpawnedToolgunOutlet({\n entry,\n}: {\n entry: SpawnedToolgunEntity;\n}): React.JSX.Element {\n const userData = useMemo(() => ({ kolmoSpawnedId: entry.id, name: entry.name }), [entry.id, entry.name]);\n const rigidBodyProps = useMemo(() => ({ userData }), [userData]);\n if (entry.kind === \"vehicle\") {\n return (\n <KolmoVehicle\n id={entry.id}\n {...(entry.bundle ? { bundle: entry.bundle } : {})}\n {...(entry.src ? { src: entry.src } : {})}\n position={entry.position}\n quaternion={entry.quaternion}\n userData={userData}\n />\n );\n }\n return (\n <KolmoProp\n id={entry.id}\n {...(entry.bundle ? { bundle: entry.bundle } : {})}\n {...(entry.src ? { src: entry.src } : {})}\n fixed={entry.fixed}\n position={entry.position}\n quaternion={entry.quaternion}\n rigidBodyProps={rigidBodyProps}\n />\n );\n});\n\nconst PlacedC12Outlet = React.memo(function PlacedC12Outlet({\n piece,\n bundle,\n src,\n}: {\n piece: PlacedPiece;\n bundle?: KhrAssetBundle;\n src?: string;\n}): React.JSX.Element | null {\n const flt = useMemo(() => poseToFloat(piece.pose), [piece.pose]);\n const userData = useMemo(() => ({ kolmoPlacedPieceId: piece.id, name: piece.kind }), [piece.id, piece.kind]);\n const rigidBodyProps = useMemo(() => ({ userData }), [userData]);\n if (!bundle && !src)\n return null;\n return (\n <KolmoProp\n id={piece.id}\n {...(bundle ? { bundle } : { src })}\n fixed\n position={flt.position}\n quaternion={flt.quaternion}\n rigidBodyProps={rigidBodyProps}\n />\n );\n});\n\nlet _ghostValidMat: THREE.MeshBasicMaterial | null = null;\nlet _ghostInvalidMat: THREE.MeshBasicMaterial | null = null;\n\nfunction getGhostMaterial(valid: boolean): THREE.MeshBasicMaterial {\n if (valid) {\n if (!_ghostValidMat) {\n _ghostValidMat = new THREE.MeshBasicMaterial({ color: \"#34d399\", transparent: true, opacity: 0.38, depthWrite: false });\n }\n return _ghostValidMat;\n }\n if (!_ghostInvalidMat) {\n _ghostInvalidMat = new THREE.MeshBasicMaterial({ color: \"#ef4444\", transparent: true, opacity: 0.38, depthWrite: false });\n }\n return _ghostInvalidMat;\n}\n\nfunction C12BundleGhostPreview({\n candidate,\n bundle,\n}: {\n candidate: BuildSnapCandidate;\n bundle: KhrAssetBundle;\n}): React.JSX.Element {\n const ghostRoot = useMemo(() => bundle.scene.clone(true), [bundle]);\n useEffect(() => {\n const mat = getGhostMaterial(candidate.valid);\n ghostRoot.traverse((child) => {\n const mesh = child as THREE.Mesh;\n if (mesh.isMesh) {\n mesh.material = mat;\n mesh.castShadow = false;\n mesh.receiveShadow = false;\n }\n });\n }, [ghostRoot, candidate.valid]);\n\n return (\n <group position={candidate.position} quaternion={candidate.quaternion}>\n <primitive object={ghostRoot} />\n </group>\n );\n}\n\nfunction C12UrlGhostPreview({\n candidate,\n src,\n}: {\n candidate: BuildSnapCandidate;\n src: string;\n}): React.JSX.Element {\n const bundle = useKhrGlb(src);\n return <C12BundleGhostPreview candidate={candidate} bundle={bundle} />;\n}\n\nconst _camPos = new THREE.Vector3();\nconst _camDir = new THREE.Vector3();\nconst _muzzleWorld = new THREE.Vector3();\nconst _beamEndVec = new THREE.Vector3();\nconst _targetOffset = new THREE.Vector3();\n\nfunction ToolgunCore({\n ref,\n viewmodelBundle,\n c12Bundles,\n c12Urls,\n actorRef,\n accentColor = DEFAULT_ACCENT_HEX,\n defaultArmedAsset,\n maxRangeM = 75,\n hipOffset = [0.24, -0.21, -0.42],\n zoomOffset = [0, -0.055, -0.22],\n enableShortcuts = true,\n mountWorldOutlets = true,\n enable = true,\n}: Omit<KolmoToolgunProps, \"src\" | \"bundle\"> & { viewmodelBundle: KhrAssetBundle | null }): React.JSX.Element | null {\n const resolvedC12Urls = useMemo<Partial<Record<PieceKind, string>>>(\n () => (c12Urls === null ? {} : { ...DEFAULT_VAULT_C12_URLS, ...c12Urls }),\n [c12Urls],\n );\n const { rapier, world: rapierWorld } = useRapier();\n const camera = useThree((s) => s.camera);\n const gl = useThree((s) => s.gl);\n const kootaWorld = useActiveKolmoWorld();\n const { mode: controlMode } = useKolmoGame(kootaWorld);\n const isPiloted = controlMode !== \"foot\";\n const jointRegistry = useContext(JointRegistryContext);\n\n const mode = useToolgunStore((s) => s.mode);\n const buildPreview = useToolgunStore((s) => s.buildPreview);\n const spawnedEntities = useToolgunStore((s) => s.spawnedEntities);\n const placedPieces = useToolgunStore((s) => s.placedPieces);\n\n useEffect(() => {\n if (defaultArmedAsset && !useToolgunStore.getState().armedAsset) {\n useToolgunStore.getState().armAsset(defaultArmedAsset);\n }\n }, [defaultArmedAsset]);\n\n useEffect(() => () => {\n useToolgunStore.getState().clearWorldHandles(rapierWorld);\n }, [rapierWorld]);\n\n const measured = useMemo(\n () => (viewmodelBundle ? measureToolgunViewmodel(viewmodelBundle.scene) : null),\n [viewmodelBundle],\n );\n const lcd = useMemo(createLcdSurface, []);\n useEffect(() => () => lcd.dispose(), [lcd]);\n\n const holderRef = useRef<THREE.Group | null>(null);\n const recoilRef = useRef(0);\n const beamTimerRef = useRef(0);\n const beamMatRef = useRef<THREE.LineBasicMaterial | null>(null);\n const rayScratchRef = useRef<ToolgunRaycastResult | null>(null);\n\n const beamGeo = useMemo(() => {\n const g = new THREE.BufferGeometry();\n g.setAttribute(\"position\", new THREE.Float32BufferAttribute([0, 0, 0, 0, 0, -1], 3));\n return g;\n }, []);\n const beamLine = useMemo(() => {\n const mat = new THREE.LineBasicMaterial({ color: accentColor, transparent: true, opacity: 0, depthTest: false });\n beamMatRef.current = mat;\n const line = new THREE.Line(beamGeo, mat);\n line.frustumCulled = false;\n line.visible = false;\n return line;\n }, [beamGeo, accentColor]);\n useEffect(() => () => {\n beamMatRef.current?.dispose();\n }, [beamLine]);\n useEffect(() => () => beamGeo.dispose(), [beamGeo]);\n\n const resolvePlayerBody = useCallback((): RAPIER.RigidBody | null => {\n const raw = actorRef?.current?.body ?? kootaWorld.queryFirst(ActorTrait)?.get(ActorTrait)?.handle?.body ?? null;\n return raw ? rapierWorld.getRigidBody(raw.handle) : null;\n }, [actorRef, kootaWorld, rapierWorld]);\n\n const findJointForBody = useCallback((body: RAPIER.RigidBody | null): JointRuntime | null => {\n if (!body || !jointRegistry)\n return null;\n for (const rt of jointRegistry) {\n if (!rt.detached && rt.childBody?.handle === body.handle)\n return rt;\n }\n return null;\n }, [jointRegistry]);\n\n const fire = useCallback((shiftKey = false): ToolgunActionOutcome => {\n camera.getWorldPosition(_camPos);\n camera.getWorldDirection(_camDir);\n const st = useToolgunStore.getState();\n const playerBody = resolvePlayerBody();\n const rawHit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody);\n const missEnd: [number, number, number] = [\n _camPos.x + _camDir.x * maxRangeM,\n _camPos.y + _camDir.y * maxRangeM,\n _camPos.z + _camDir.z * maxRangeM,\n ];\n\n const aimPoint = rawHit ? rawHit.point : missEnd;\n recoilRef.current = 1;\n beamTimerRef.current = 0.09;\n _beamEndVec.set(aimPoint[0], aimPoint[1], aimPoint[2]);\n\n if (holderRef.current && measured) {\n const mLocal = measured.muzzleLocal;\n const gOff = measured.gripOffset;\n _muzzleWorld.set(mLocal[0] + gOff[0], mLocal[1] + gOff[1], mLocal[2] + gOff[2]).applyMatrix4(holderRef.current.matrixWorld);\n }\n else {\n _muzzleWorld.copy(_camPos).addScaledVector(_camDir, 0.35);\n }\n const posAttr = beamGeo.getAttribute(\"position\") as THREE.BufferAttribute;\n posAttr.setXYZ(0, _muzzleWorld.x, _muzzleWorld.y, _muzzleWorld.z);\n posAttr.setXYZ(1, _beamEndVec.x, _beamEndVec.y, _beamEndVec.z);\n posAttr.needsUpdate = true;\n beamLine.visible = true;\n\n if (!rawHit) {\n if (st.mode === \"weld\" || st.mode === \"hinge\") {\n st.setPendingAnchor(null);\n st.bumpFire(\"MISS — CLEARED ANCHOR\");\n return { ok: false, status: \"MISS — CLEARED ANCHOR\", beamEnd: missEnd };\n }\n st.bumpFire(\"NO SURFACE HIT\");\n return { ok: false, status: \"NO SURFACE HIT\", beamEnd: missEnd };\n }\n\n if (st.mode === \"spawn\") {\n const asset = st.armedAsset;\n if (!asset || (!asset.bundle && !asset.src)) {\n st.bumpFire(\"NO ASSET ARMED\");\n return { ok: false, status: \"NO ASSET ARMED\", beamEnd: rawHit.point };\n }\n const pose = computeAlignedSpawnPose(rawHit.point, st.yaw12, rawHit.normal, 0.08);\n const isVehicle = asset.kind === \"vehicle\" || (\n asset.kind !== \"prop\" &&\n Boolean(asset.bundle && (asset.bundle.wheels.length > 0 || asset.bundle.propellers.length > 0))\n );\n const id = `tg_ent_${Date.now().toString(36)}_${st.fireCount}`;\n st.recordSpawn({\n id,\n name: asset.name,\n kind: isVehicle ? \"vehicle\" : \"prop\",\n ...(asset.src ? { src: asset.src } : {}),\n ...(asset.bundle ? { bundle: asset.bundle } : {}),\n fixed: Boolean(asset.fixed),\n position: pose.position,\n quaternion: pose.quaternion,\n });\n return { ok: true, status: `SPAWNED ${asset.name}`, beamEnd: rawHit.point };\n }\n\n if (st.mode === \"build\") {\n if (mountWorldOutlets && !c12Bundles?.[st.buildKind] && !resolvedC12Urls[st.buildKind]) {\n st.bumpFire(`MISSING ${st.buildKind} GLB`);\n return { ok: false, status: `MISSING ${st.buildKind} GLB`, beamEnd: rawHit.point };\n }\n const candidate = computeBuildCandidate(st.placedPieces, rawHit.point, st.buildKind, st.yaw12);\n const placed = st.placeBuildPiece(candidate);\n return {\n ok: placed !== null,\n status: placed ? `PLACED ${placed.kind}` : candidate.reason.toUpperCase(),\n beamEnd: candidate.position,\n };\n }\n\n if (st.mode === \"rig\") {\n const hitJoint = findJointForBody(rawHit.body);\n if (!hitJoint) {\n st.bumpFire(\"NO KHR JOINT HIT\");\n return { ok: false, status: \"NO KHR JOINT HIT\", beamEnd: rawHit.point };\n }\n const status = rigJointRuntime(hitJoint, shiftKey);\n st.bumpFire(status.toUpperCase());\n return { ok: true, status, beamEnd: rawHit.point };\n }\n\n if (st.mode === \"weld\" || st.mode === \"hinge\") {\n if (!rawHit.body) {\n st.setPendingAnchor(null);\n st.bumpFire(\"MISS — CLEARED ANCHOR\");\n return { ok: false, status: \"MISS — CLEARED ANCHOR\", beamEnd: rawHit.point };\n }\n const pending = st.pendingAnchor;\n const liveBodyA = pending && pending.world === rapierWorld\n ? rapierWorld.getRigidBody(pending.body.handle)\n : null;\n if (!pending || !liveBodyA) {\n const ud = rawHit.body.userData as { name?: string } | undefined;\n const label = ud?.name ?? `body_${rawHit.body.handle}`;\n st.setPendingAnchor({\n world: rapierWorld,\n body: rawHit.body,\n worldPoint: rawHit.point,\n worldNormal: rawHit.normal,\n label,\n });\n st.bumpFire(`LOCKED A: ${label}`);\n return { ok: true, status: `LOCKED A: ${label}`, beamEnd: rawHit.point };\n }\n if (liveBodyA.handle === rawHit.body.handle) {\n st.setPendingAnchor(null);\n st.bumpFire(\"SAME BODY — CANCELLED\");\n return { ok: false, status: \"SAME BODY — CANCELLED\", beamEnd: rawHit.point };\n }\n const anchorMid: [number, number, number] = [\n 0.5 * (pending.worldPoint[0] + rawHit.point[0]),\n 0.5 * (pending.worldPoint[1] + rawHit.point[1]),\n 0.5 * (pending.worldPoint[2] + rawHit.point[2]),\n ];\n const imp = st.mode === \"weld\"\n ? createWeldImpulseJoint(rapier, rapierWorld, liveBodyA, rawHit.body, anchorMid)\n : createHingeImpulseJoint(rapier, rapierWorld, liveBodyA, rawHit.body, anchorMid, pending.worldNormal);\n const id = `tg_${st.mode}_${imp.handle}`;\n st.recordJoint({\n id,\n kind: st.mode,\n world: rapierWorld,\n handle: imp.handle,\n joint: imp,\n anchorWorld: anchorMid,\n });\n return { ok: true, status: `${st.mode.toUpperCase()} CREATED`, beamEnd: anchorMid };\n }\n\n const ud = (rawHit.body?.userData ?? {}) as { kolmoSpawnedId?: string; kolmoPlacedPieceId?: string };\n if (ud.kolmoPlacedPieceId && st.removePieceById(ud.kolmoPlacedPieceId)) {\n return { ok: true, status: `REMOVED ${ud.kolmoPlacedPieceId}`, beamEnd: rawHit.point };\n }\n if (ud.kolmoSpawnedId && st.removeEntityById(ud.kolmoSpawnedId, rapierWorld)) {\n return { ok: true, status: `DELETED ${ud.kolmoSpawnedId}`, beamEnd: rawHit.point };\n }\n if (rawHit.body) {\n const removedJoints = st.removeJointByBody(rapierWorld, rawHit.body);\n if (removedJoints > 0)\n return { ok: true, status: `REMOVED ${removedJoints} JOINT(S)`, beamEnd: rawHit.point };\n }\n st.bumpFire(\"STATIC WORLD TARGET\");\n return { ok: false, status: \"STATIC WORLD TARGET\", beamEnd: rawHit.point };\n }, [camera, rapier, rapierWorld, maxRangeM, resolvePlayerBody, findJointForBody, measured, beamGeo, beamLine, mountWorldOutlets, c12Bundles, resolvedC12Urls]);\n\n useImperativeHandle(ref, () => ({\n fire,\n undo: () => useToolgunStore.getState().undoLast(rapierWorld),\n }), [fire, rapierWorld]);\n\n useEffect(() => {\n if (!enable || !enableShortcuts || typeof window === \"undefined\")\n return;\n const isEditable = (el: Element | null): boolean => {\n if (!el)\n return false;\n const tag = (el as HTMLElement).tagName;\n return tag === \"INPUT\" || tag === \"TEXTAREA\" || tag === \"SELECT\" || Boolean((el as HTMLElement).isContentEditable);\n };\n\n const onKeyDown = (e: KeyboardEvent): void => {\n if (isEditable(document.activeElement) || kootaWorld.queryFirst(pilotedVehicleQuery))\n return;\n const st = useToolgunStore.getState();\n if (e.code >= \"Digit1\" && e.code <= \"Digit6\") {\n const idx = Number(e.code.slice(5)) - 1;\n if (TOOLGUN_MODES[idx])\n st.setMode(TOOLGUN_MODES[idx]);\n return;\n }\n if (e.code === \"KeyQ\" && !e.metaKey && !e.ctrlKey) {\n st.cycleMode(e.shiftKey ? -1 : 1);\n }\n else if (e.code === \"KeyR\" && !e.metaKey && !e.ctrlKey) {\n st.rotateYaw12(e.shiftKey ? -1 : 1);\n }\n else if (e.code === \"BracketLeft\") {\n st.cycleBuildKind(-1);\n }\n else if (e.code === \"BracketRight\") {\n st.cycleBuildKind(1);\n }\n else if (e.code === \"KeyZ\" && !e.metaKey && !e.ctrlKey) {\n st.undoLast(rapierWorld);\n }\n else if (e.code === \"Tab\") {\n e.preventDefault();\n st.setZoomed(!st.zoomed);\n }\n };\n\n const dom = gl?.domElement;\n let downPos: [number, number] | null = null;\n const onPointerDown = (e: PointerEvent): void => {\n if (kootaWorld.queryFirst(pilotedVehicleQuery))\n return;\n if (e.button === 2) {\n useToolgunStore.getState().setZoomed(true);\n }\n else if (e.button === 0) {\n downPos = [e.clientX, e.clientY];\n }\n };\n const onPointerUp = (e: PointerEvent): void => {\n if (e.button === 2) {\n useToolgunStore.getState().setZoomed(false);\n return;\n }\n if (e.button === 0 && downPos && !kootaWorld.queryFirst(pilotedVehicleQuery)) {\n const moved = Math.hypot(e.clientX - downPos[0], e.clientY - downPos[1]);\n downPos = null;\n if (moved <= 6)\n fire(e.shiftKey);\n }\n };\n const onContextMenu = (e: MouseEvent): void => {\n if (!kootaWorld.queryFirst(pilotedVehicleQuery))\n e.preventDefault();\n };\n\n window.addEventListener(\"keydown\", onKeyDown);\n dom?.addEventListener(\"pointerdown\", onPointerDown);\n window.addEventListener(\"pointerup\", onPointerUp);\n dom?.addEventListener(\"contextmenu\", onContextMenu);\n return () => {\n window.removeEventListener(\"keydown\", onKeyDown);\n dom?.removeEventListener(\"pointerdown\", onPointerDown);\n window.removeEventListener(\"pointerup\", onPointerUp);\n dom?.removeEventListener(\"contextmenu\", onContextMenu);\n };\n }, [enable, enableShortcuts, gl, kootaWorld, rapierWorld, fire]);\n\n useFrame((_, delta) => {\n const dt = Math.min(Math.max(delta, 1e-4), 1 / 20);\n const piloted = Boolean(kootaWorld.queryFirst(pilotedVehicleQuery));\n const holder = holderRef.current;\n if (holder)\n holder.visible = enable && !piloted;\n if (!enable || piloted) {\n beamLine.visible = false;\n return;\n }\n\n const st = useToolgunStore.getState();\n if (recoilRef.current > 0)\n recoilRef.current = Math.max(0, recoilRef.current - dt * 7.5);\n if (beamTimerRef.current > 0) {\n beamTimerRef.current = Math.max(0, beamTimerRef.current - dt);\n if (beamMatRef.current)\n beamMatRef.current.opacity = Math.min(1, beamTimerRef.current * 12);\n if (beamTimerRef.current <= 0)\n beamLine.visible = false;\n }\n\n if (holder) {\n const goal = st.zoomed ? zoomOffset : hipOffset;\n _targetOffset.set(goal[0], goal[1] - recoilRef.current * 0.012, goal[2] + recoilRef.current * 0.038);\n easing.damp3(holder.position, _targetOffset, 0.09, dt);\n holder.rotation.set(recoilRef.current * 0.14, 0, 0);\n }\n\n camera.getWorldPosition(_camPos);\n camera.getWorldDirection(_camDir);\n const playerBody = resolvePlayerBody();\n const hit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody, rayScratchRef.current ?? undefined);\n if (hit && !rayScratchRef.current)\n rayScratchRef.current = hit;\n else if (!hit && rayScratchRef.current)\n rayScratchRef.current.body = null;\n\n let targetLabel = \"NO TARGET\";\n if (hit) {\n const jRt = findJointForBody(hit.body);\n const ud = (hit.body?.userData ?? {}) as { name?: string; kolmoPlacedPieceId?: string; kolmoSpawnedId?: string };\n const name = jRt ? `JOINT:${jRt.nodeName}` : (ud.name ?? ud.kolmoPlacedPieceId ?? ud.kolmoSpawnedId ?? \"SURFACE\");\n targetLabel = `${name} (${hit.toi.toFixed(1)}m)`;\n }\n\n if (st.mode === \"build\" && hit) {\n const cand = computeBuildCandidate(st.placedPieces, hit.point, st.buildKind, st.yaw12);\n if (!isSameBuildPreview(st.buildPreview, cand))\n st.setBuildPreview(cand);\n }\n else if (st.buildPreview !== null) {\n st.setBuildPreview(null);\n }\n\n const detail = st.mode === \"build\"\n ? st.buildKind\n : st.mode === \"spawn\"\n ? (st.armedAsset?.name ?? \"UNARMED\")\n : st.pendingAnchor\n ? `A: ${st.pendingAnchor.label}`\n : `${st.mode.toUpperCase()} READY`;\n\n lcd.draw({\n mode: st.mode,\n yawDeg: st.yaw12 * 30,\n detail,\n targetLabel,\n status: st.statusText,\n accentColor,\n });\n });\n\n const ghostBundle = buildPreview ? c12Bundles?.[buildPreview.kind] : undefined;\n const ghostUrl = buildPreview && !ghostBundle ? resolvedC12Urls[buildPreview.kind] : undefined;\n\n return (\n <>\n {measured &&\n createPortal(\n <group ref={holderRef} position={[hipOffset[0], hipOffset[1], hipOffset[2]]}>\n <group position={measured.gripOffset}>\n <primitive object={measured.scene} />\n {measured.screen && (\n <mesh position={measured.screen.pos} quaternion={measured.screen.quat}>\n <planeGeometry args={measured.screen.size} />\n <meshBasicMaterial\n {...(lcd.texture ? { map: lcd.texture } : { color: accentColor })}\n toneMapped={false}\n />\n </mesh>\n )}\n </group>\n </group>,\n camera,\n )}\n <primitive object={beamLine} />\n {enable && !isPiloted && mode === \"build\" && buildPreview && (\n ghostBundle ? (\n <C12BundleGhostPreview candidate={buildPreview} bundle={ghostBundle} />\n ) : ghostUrl ? (\n <React.Suspense fallback={null}>\n <C12UrlGhostPreview candidate={buildPreview} src={ghostUrl} />\n </React.Suspense>\n ) : null\n )}\n {mountWorldOutlets && (\n <group name=\"kolmo_toolgun_outlets\">\n {spawnedEntities.map((entry) => (\n <React.Suspense key={entry.id} fallback={null}>\n <SpawnedToolgunOutlet entry={entry} />\n </React.Suspense>\n ))}\n {placedPieces.map((piece) => {\n const b = c12Bundles?.[piece.kind];\n const u = b ? undefined : resolvedC12Urls[piece.kind];\n return b || u ? (\n <React.Suspense key={piece.id} fallback={null}>\n <PlacedC12Outlet piece={piece} bundle={b} src={u} />\n </React.Suspense>\n ) : null;\n })}\n </group>\n )}\n </>\n );\n}\n\nfunction ToolgunFromUrl({ src, ...rest }: Omit<KolmoToolgunProps, \"src\" | \"bundle\"> & { src: string }): React.JSX.Element | null {\n const bundle = useKhrGlb(src);\n return <ToolgunCore {...rest} viewmodelBundle={bundle} />;\n}\n\nexport function KolmoToolgun({ src, bundle, ...rest }: KolmoToolgunProps): React.JSX.Element | null {\n const cloned = useMemo(() => (bundle ? cloneKhrBundle(bundle) : null), [bundle]);\n if (src)\n return <ToolgunFromUrl src={src} {...rest} />;\n return <ToolgunCore {...rest} viewmodelBundle={cloned} />;\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAa,gBAAgB;CAAC;CAAS;CAAQ;CAAS;CAAO;CAAS;AAAQ;AAGhF,IAAa,sBAAsB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AAuEA,IAAM,aAAa,IAAI,MAAM,QAAQ,GAAG,GAAG,CAAC;AAC5C,IAAM,UAAU,IAAI,MAAM,QAAQ;AAClC,IAAM,aAAa,IAAI,MAAM,WAAW;AACxC,IAAM,WAAW,IAAI,MAAM,WAAW;AACtC,IAAM,MAAM,IAAI,MAAM,WAAW;AACjC,IAAM,MAAM,IAAI,MAAM,WAAW;AACjC,IAAM,SAAS,IAAI,MAAM,WAAW;AACpC,IAAM,SAAS,IAAI,MAAM,WAAW;AACpC,IAAM,QAAQ,IAAI,MAAM,WAAW;AACnC,IAAM,MAAM,IAAI,MAAM,QAAQ;AAC9B,IAAM,MAAM,IAAI,MAAM,QAAQ;AAC9B,IAAM,WAAW,IAAI,MAAM,QAAQ;AACnC,IAAM,YAAY,IAAI,MAAM,QAAQ;AAEpC,IAAI,aAAgC;AAEpC,SAAS,SAAS,GAAsB;CACpC,OAAO,MAAM,QA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,qBAAC,SAAD;GAAO,MAAK;GAAZ,UAAA,CACK,gBAAgB,KAAK,UAClBD,oBAAC,MAAM,UAAP;IAA+B,UAAU;IACrC,UAAAA,oBAAC,sBAAD,EAA6B,MAAQ,CAAA;GACzB,GAFK,MAAM,EAEX,CACnB,GACA,aAAa,KAAK,UAAU;IACzB,MAAM,IAAI,aAAa,MAAM;IAC7B,MAAM,IAAI,IAAI,KAAA,IAAY,gBAAgB,MAAM;IAChD,OAAO,KAAK,IACRA,oBAAC,MAAM,UAAP;KAA+B,UAAU;KACrC,UAAAA,oBAAC,iBAAD;MAAwB;MAAO,QAAQ;MAAG,KAAK;KAAI,CAAA;IACvC,GAFK,MAAM,EAEX,IAChB;GACR,CAAC,CACE;;CAEb,EAAA,CAAA;AAEV;AAEA,SAAS,eAAe,EAAE,KAAK,GAAG,QAA+F;CAC7H,MAAM,SAAS,UAAU,GAAG;CAC5B,OAAOA,oBAAC,aAAD;EAAa,GAAI;EAAM,iBAAiB;CAAS,CAAA;AAC5D;AAEA,SAAgB,aAAa,EAAE,KAAK,QAAQ,GAAG,QAAqD;CAChG,MAAM,SAAS,cAAe,SAAS,eAAe,MAAM,IAAI,MAAO,CAAC,MAAM,CAAC;CAC/E,IAAI,KACA,OAAOA,oBAAC,gBAAD;EAAqB;EAAK,GAAI;CAAO,CAAA;CAChD,OAAOA,oBAAC,aAAD;EAAa,GAAI;EAAM,iBAAiB;CAAS,CAAA;AAC5D"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import { createActions, createQuery, createWorld, getStore, relation, trait, unpackEntity } from "koota";
|
|
4
|
+
// src/engine/traits.ts
|
|
5
|
+
/**
|
|
6
|
+
* Verifies that `handle.body` is a live `RigidBody` registered in `rapierWorld` (`live === candidate`),
|
|
7
|
+
* preventing React 19 `<StrictMode>` pass-1 freed WASM arena handle panics (`RuntimeError: unreachable`).
|
|
8
|
+
*/
|
|
9
|
+
function getLiveActorBody(rapierWorld, handle) {
|
|
10
|
+
const candidate = handle?.body ?? null;
|
|
11
|
+
if (!candidate) return null;
|
|
12
|
+
const live = rapierWorld.getRigidBody(candidate.handle);
|
|
13
|
+
return live === candidate ? live : null;
|
|
14
|
+
}
|
|
15
|
+
var VehicleTrait = trait(() => ({
|
|
16
|
+
id: "",
|
|
17
|
+
handle: null,
|
|
18
|
+
jointsHandle: null,
|
|
19
|
+
seatOffset: [
|
|
20
|
+
0,
|
|
21
|
+
.55,
|
|
22
|
+
0
|
|
23
|
+
],
|
|
24
|
+
exitOffset: [
|
|
25
|
+
-1.5,
|
|
26
|
+
.45,
|
|
27
|
+
0
|
|
28
|
+
],
|
|
29
|
+
isFlight: false
|
|
30
|
+
}));
|
|
31
|
+
var ActorTrait = trait(() => ({
|
|
32
|
+
id: "pilot",
|
|
33
|
+
handle: null,
|
|
34
|
+
exitSpawnPos: null,
|
|
35
|
+
exitSpawnYaw: 0,
|
|
36
|
+
exitLinVel: null
|
|
37
|
+
}));
|
|
38
|
+
var PropTrait = trait(() => ({
|
|
39
|
+
id: "",
|
|
40
|
+
handle: null,
|
|
41
|
+
fixed: false
|
|
42
|
+
}));
|
|
43
|
+
var TransformTrait = trait({
|
|
44
|
+
x: 0,
|
|
45
|
+
y: 0,
|
|
46
|
+
z: 0,
|
|
47
|
+
qx: 0,
|
|
48
|
+
qy: 0,
|
|
49
|
+
qz: 0,
|
|
50
|
+
qw: 1
|
|
51
|
+
});
|
|
52
|
+
var VelocityTrait = trait({
|
|
53
|
+
vx: 0,
|
|
54
|
+
vy: 0,
|
|
55
|
+
vz: 0,
|
|
56
|
+
speedKmh: 0
|
|
57
|
+
});
|
|
58
|
+
var VehicleTelemetryTrait = trait({
|
|
59
|
+
rpm: 0,
|
|
60
|
+
gear: 1,
|
|
61
|
+
throttle: 0,
|
|
62
|
+
boost: 0,
|
|
63
|
+
slip: 0
|
|
64
|
+
});
|
|
65
|
+
var InteractableTrait = trait({
|
|
66
|
+
id: "",
|
|
67
|
+
radius: 4,
|
|
68
|
+
kind: "vehicle"
|
|
69
|
+
});
|
|
70
|
+
var PilotedTag = trait();
|
|
71
|
+
var PilotLink = relation({ exclusive: true });
|
|
72
|
+
var WorldSessionTrait = trait({ nearVehicleId: "" });
|
|
73
|
+
var vehicleSimQuery = createQuery(VehicleTrait, TransformTrait, VelocityTrait, VehicleTelemetryTrait);
|
|
74
|
+
var propSimQuery = createQuery(PropTrait, TransformTrait, VelocityTrait);
|
|
75
|
+
var pilotedVehicleQuery = createQuery(VehicleTrait, PilotedTag);
|
|
76
|
+
var kolmoWorld = createWorld(WorldSessionTrait);
|
|
77
|
+
var KolmoWorldContext = createContext(null);
|
|
78
|
+
function useOptionalKootaWorld() {
|
|
79
|
+
return useContext(KolmoWorldContext);
|
|
80
|
+
}
|
|
81
|
+
function useActiveKolmoWorld() {
|
|
82
|
+
return useContext(KolmoWorldContext) ?? kolmoWorld;
|
|
83
|
+
}
|
|
84
|
+
function ensureWorldSession(w) {
|
|
85
|
+
if (!w.has(WorldSessionTrait)) w.add(WorldSessionTrait);
|
|
86
|
+
}
|
|
87
|
+
function createEmptyVehicleCmd(brake = false) {
|
|
88
|
+
return {
|
|
89
|
+
forward: false,
|
|
90
|
+
backward: false,
|
|
91
|
+
steerLeft: false,
|
|
92
|
+
steerRight: false,
|
|
93
|
+
brake,
|
|
94
|
+
throttleUp: false,
|
|
95
|
+
throttleDown: false,
|
|
96
|
+
yawLeft: false,
|
|
97
|
+
yawRight: false,
|
|
98
|
+
pitchForward: false,
|
|
99
|
+
pitchBackward: false,
|
|
100
|
+
rollLeft: false,
|
|
101
|
+
rollRight: false,
|
|
102
|
+
joystickL: {
|
|
103
|
+
x: 0,
|
|
104
|
+
y: 0
|
|
105
|
+
},
|
|
106
|
+
joystickR: {
|
|
107
|
+
x: 0,
|
|
108
|
+
y: 0
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Zero-allocation SoA typed-array writer using Koota's public `unpackEntity` + `getStore`. */
|
|
113
|
+
function writeEntityKinematics(world, entity, pos, quat, linVel, speedKmh) {
|
|
114
|
+
const { entityId } = unpackEntity(entity);
|
|
115
|
+
if (entity.has(TransformTrait)) {
|
|
116
|
+
const xf = getStore(world, TransformTrait);
|
|
117
|
+
xf.x[entityId] = pos.x;
|
|
118
|
+
xf.y[entityId] = pos.y;
|
|
119
|
+
xf.z[entityId] = pos.z;
|
|
120
|
+
xf.qx[entityId] = quat.x;
|
|
121
|
+
xf.qy[entityId] = quat.y;
|
|
122
|
+
xf.qz[entityId] = quat.z;
|
|
123
|
+
xf.qw[entityId] = quat.w;
|
|
124
|
+
}
|
|
125
|
+
if (entity.has(VelocityTrait)) {
|
|
126
|
+
const vl = getStore(world, VelocityTrait);
|
|
127
|
+
vl.vx[entityId] = linVel.x;
|
|
128
|
+
vl.vy[entityId] = linVel.y;
|
|
129
|
+
vl.vz[entityId] = linVel.z;
|
|
130
|
+
vl.speedKmh[entityId] = speedKmh;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Zero-allocation SoA typed-array writer for `VehicleTelemetryTrait` inside `useFrame`. */
|
|
134
|
+
function writeVehicleTelemetry(world, entity, rpm, gear, throttle, boost, slip) {
|
|
135
|
+
if (!entity.has(VehicleTelemetryTrait)) return;
|
|
136
|
+
const { entityId } = unpackEntity(entity);
|
|
137
|
+
const st = getStore(world, VehicleTelemetryTrait);
|
|
138
|
+
st.rpm[entityId] = rpm;
|
|
139
|
+
st.gear[entityId] = gear;
|
|
140
|
+
st.throttle[entityId] = throttle;
|
|
141
|
+
st.boost[entityId] = boost;
|
|
142
|
+
st.slip[entityId] = slip;
|
|
143
|
+
}
|
|
144
|
+
var _exitPos = new THREE.Vector3();
|
|
145
|
+
var _exitFwd = new THREE.Vector3();
|
|
146
|
+
var _flipUp = new THREE.Vector3();
|
|
147
|
+
var _flipFwd = new THREE.Vector3();
|
|
148
|
+
var _flipRight = new THREE.Vector3();
|
|
149
|
+
var _flipMat = new THREE.Matrix4();
|
|
150
|
+
var _flipQuat = new THREE.Quaternion();
|
|
151
|
+
function flipVehicleBodyUpright(veh, joints) {
|
|
152
|
+
const body = veh.body;
|
|
153
|
+
if (!body) return;
|
|
154
|
+
const pos = body.translation();
|
|
155
|
+
_flipUp.copy(veh.upAxis);
|
|
156
|
+
if (_flipUp.lengthSq() < 1e-6) _flipUp.set(0, 1, 0);
|
|
157
|
+
else _flipUp.normalize();
|
|
158
|
+
_flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);
|
|
159
|
+
if (_flipFwd.lengthSq() < 1e-6) {
|
|
160
|
+
if (Math.abs(_flipUp.y) < .9) _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);
|
|
161
|
+
else _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);
|
|
162
|
+
}
|
|
163
|
+
_flipFwd.normalize();
|
|
164
|
+
_flipRight.crossVectors(_flipUp, _flipFwd).normalize();
|
|
165
|
+
_flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);
|
|
166
|
+
_flipQuat.setFromRotationMatrix(_flipMat);
|
|
167
|
+
body.setTranslation({
|
|
168
|
+
x: pos.x + _flipUp.x * 1.35,
|
|
169
|
+
y: pos.y + _flipUp.y * 1.35,
|
|
170
|
+
z: pos.z + _flipUp.z * 1.35
|
|
171
|
+
}, true);
|
|
172
|
+
body.setRotation({
|
|
173
|
+
x: _flipQuat.x,
|
|
174
|
+
y: _flipQuat.y,
|
|
175
|
+
z: _flipQuat.z,
|
|
176
|
+
w: _flipQuat.w
|
|
177
|
+
}, true);
|
|
178
|
+
body.setLinvel({
|
|
179
|
+
x: 0,
|
|
180
|
+
y: 0,
|
|
181
|
+
z: 0
|
|
182
|
+
}, true);
|
|
183
|
+
body.setAngvel({
|
|
184
|
+
x: 0,
|
|
185
|
+
y: 0,
|
|
186
|
+
z: 0
|
|
187
|
+
}, true);
|
|
188
|
+
joints?.syncBodiesToParent();
|
|
189
|
+
}
|
|
190
|
+
var kolmoActions = createActions((world) => ({
|
|
191
|
+
boardVehicle: (vehicleId) => {
|
|
192
|
+
if (!vehicleId) return;
|
|
193
|
+
ensureWorldSession(world);
|
|
194
|
+
let targetEnt;
|
|
195
|
+
for (const vehEnt of world.query(VehicleTrait)) if (vehEnt.get(VehicleTrait)?.id === vehicleId) {
|
|
196
|
+
targetEnt = vehEnt;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
if (!targetEnt) return;
|
|
200
|
+
for (const prev of world.query(pilotedVehicleQuery)) if (prev !== targetEnt && prev.has(PilotedTag)) prev.remove(PilotedTag);
|
|
201
|
+
if (!targetEnt.has(PilotedTag)) targetEnt.add(PilotedTag);
|
|
202
|
+
const pilot = world.queryFirst(ActorTrait);
|
|
203
|
+
if (pilot) pilot.add(PilotLink(targetEnt));
|
|
204
|
+
if (world.get(WorldSessionTrait)?.nearVehicleId) world.set(WorldSessionTrait, { nearVehicleId: "" });
|
|
205
|
+
},
|
|
206
|
+
exitVehicle: () => {
|
|
207
|
+
ensureWorldSession(world);
|
|
208
|
+
const pilot = world.queryFirst(ActorTrait);
|
|
209
|
+
const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);
|
|
210
|
+
if (linked) {
|
|
211
|
+
const v = linked.get(VehicleTrait);
|
|
212
|
+
if (pilot) {
|
|
213
|
+
if (pilot.has(PilotLink(linked))) pilot.remove(PilotLink(linked));
|
|
214
|
+
if (v?.handle) {
|
|
215
|
+
_exitPos.set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2]).applyQuaternion(v.handle.currQuat).add(v.handle.currPos);
|
|
216
|
+
_exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();
|
|
217
|
+
const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;
|
|
218
|
+
const lv = v.handle.currLinVel;
|
|
219
|
+
const curActor = pilot.get(ActorTrait);
|
|
220
|
+
pilot.set(ActorTrait, {
|
|
221
|
+
id: curActor?.id ?? "pilot",
|
|
222
|
+
handle: curActor?.handle ?? null,
|
|
223
|
+
exitSpawnPos: [
|
|
224
|
+
_exitPos.x,
|
|
225
|
+
_exitPos.y,
|
|
226
|
+
_exitPos.z
|
|
227
|
+
],
|
|
228
|
+
exitSpawnYaw: yaw,
|
|
229
|
+
exitLinVel: [
|
|
230
|
+
lv.x,
|
|
231
|
+
lv.y,
|
|
232
|
+
lv.z
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (linked.has(PilotedTag)) linked.remove(PilotedTag);
|
|
238
|
+
v?.handle?.setMovement(createEmptyVehicleCmd(!v.isFlight));
|
|
239
|
+
}
|
|
240
|
+
for (const extra of world.query(pilotedVehicleQuery)) if (extra.has(PilotedTag)) extra.remove(PilotedTag);
|
|
241
|
+
},
|
|
242
|
+
resetVehicle: (vehicleId) => {
|
|
243
|
+
let target;
|
|
244
|
+
if (vehicleId) for (const ent of world.query(VehicleTrait)) {
|
|
245
|
+
const v = ent.get(VehicleTrait);
|
|
246
|
+
if (v?.id === vehicleId && v.handle?.body) {
|
|
247
|
+
target = v;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (!target) {
|
|
252
|
+
const pv = (world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery))?.get(VehicleTrait);
|
|
253
|
+
if (pv?.handle?.body) target = pv;
|
|
254
|
+
}
|
|
255
|
+
if (!target) for (const ent of world.query(VehicleTrait)) {
|
|
256
|
+
const v = ent.get(VehicleTrait);
|
|
257
|
+
if (v?.handle?.body) {
|
|
258
|
+
target = v;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (target?.handle) flipVehicleBodyUpright(target.handle, target.jointsHandle);
|
|
263
|
+
}
|
|
264
|
+
}));
|
|
265
|
+
export { writeEntityKinematics as C, vehicleSimQuery as S, kolmoWorld as _, PilotedTag as a, useActiveKolmoWorld as b, VehicleTelemetryTrait as c, WorldSessionTrait as d, createEmptyVehicleCmd as f, kolmoActions as g, getLiveActorBody as h, PilotLink as i, VehicleTrait as l, flipVehicleBodyUpright as m, InteractableTrait as n, PropTrait as o, ensureWorldSession as p, KolmoWorldContext as r, TransformTrait as s, ActorTrait as t, VelocityTrait as u, pilotedVehicleQuery as v, writeVehicleTelemetry as w, useOptionalKootaWorld as x, propSimQuery as y };
|
|
266
|
+
|
|
267
|
+
//# sourceMappingURL=traits-Dp1ey_4w.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traits-Dp1ey_4w.js","names":[],"sources":["../src/engine/traits.ts"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport * as THREE from \"three\";\nimport {\n createActions,\n createQuery,\n createWorld,\n getStore,\n relation,\n trait,\n unpackEntity,\n type Entity,\n type World,\n} from \"koota\";\nimport type RAPIER from \"@dimforge/rapier3d-compat\";\nimport type { EcctrlHandle } from \"@pinkaphant/ecctrl\";\nimport type { EcctrlVehicleHandle, VehicleInput } from \"@pinkaphant/ecctrl/vehicle\";\nimport type { KhrAssemblyHandle } from \"@khr3/core\";\nimport type { KhrVehicleJointsHandle } from \"@khr3/core/vehicle\";\n\n/**\n * Verifies that `handle.body` is a live `RigidBody` registered in `rapierWorld` (`live === candidate`),\n * preventing React 19 `<StrictMode>` pass-1 freed WASM arena handle panics (`RuntimeError: unreachable`).\n */\nexport function getLiveActorBody(\n rapierWorld: Pick<RAPIER.World, \"getRigidBody\">,\n handle: Pick<EcctrlHandle, \"body\"> | null | undefined,\n): RAPIER.RigidBody | null {\n const candidate = handle?.body ?? null;\n if (!candidate)\n return null;\n const live = rapierWorld.getRigidBody(candidate.handle);\n return live === candidate ? live : null;\n}\n\nexport type KolmoControlMode = \"foot\" | \"car\" | \"flight\";\n\nexport interface PropTraitData {\n id: string;\n handle: KhrAssemblyHandle | null;\n fixed: boolean;\n}\n\nexport interface VehicleTraitData {\n id: string;\n handle: EcctrlVehicleHandle | null;\n jointsHandle?: KhrVehicleJointsHandle | null;\n seatOffset: [number, number, number];\n exitOffset: [number, number, number];\n isFlight: boolean;\n}\n\nexport interface ActorTraitData {\n id: string;\n handle: EcctrlHandle | null;\n exitSpawnPos: [number, number, number] | null;\n exitSpawnYaw: number;\n exitLinVel: [number, number, number] | null;\n}\n\nexport const VehicleTrait = trait((): VehicleTraitData => ({\n id: \"\",\n handle: null,\n jointsHandle: null,\n seatOffset: [0, 0.55, 0],\n exitOffset: [-1.5, 0.45, 0],\n isFlight: false,\n}));\n\nexport const ActorTrait = trait((): ActorTraitData => ({\n id: \"pilot\",\n handle: null,\n exitSpawnPos: null,\n exitSpawnYaw: 0,\n exitLinVel: null,\n}));\n\nexport const PropTrait = trait((): PropTraitData => ({\n id: \"\",\n handle: null,\n fixed: false,\n}));\n\nexport const TransformTrait = trait({ x: 0, y: 0, z: 0, qx: 0, qy: 0, qz: 0, qw: 1 });\nexport const VelocityTrait = trait({ vx: 0, vy: 0, vz: 0, speedKmh: 0 });\nexport const VehicleTelemetryTrait = trait({ rpm: 0, gear: 1, throttle: 0, boost: 0, slip: 0 });\nexport const InteractableTrait = trait({ id: \"\", radius: 4, kind: \"vehicle\" as \"vehicle\" | \"prop\" });\nexport const PilotedTag = trait();\nexport const PilotLink = relation({ exclusive: true });\nexport const WorldSessionTrait = trait({ nearVehicleId: \"\" });\n\nexport const vehicleSimQuery = createQuery(VehicleTrait, TransformTrait, VelocityTrait, VehicleTelemetryTrait);\nexport const propSimQuery = createQuery(PropTrait, TransformTrait, VelocityTrait);\nexport const pilotedVehicleQuery = createQuery(VehicleTrait, PilotedTag);\n\nexport const kolmoWorld: World = createWorld(WorldSessionTrait);\nexport const KolmoWorldContext = createContext<World | null>(null);\n\nexport function useOptionalKootaWorld(): World | null {\n return useContext(KolmoWorldContext);\n}\n\nexport function useActiveKolmoWorld(): World {\n return useContext(KolmoWorldContext) ?? kolmoWorld;\n}\n\nexport function ensureWorldSession(w: World): void {\n if (!w.has(WorldSessionTrait))\n w.add(WorldSessionTrait);\n}\n\nexport function createEmptyVehicleCmd(brake = false): VehicleInput {\n return {\n forward: false,\n backward: false,\n steerLeft: false,\n steerRight: false,\n brake,\n throttleUp: false,\n throttleDown: false,\n yawLeft: false,\n yawRight: false,\n pitchForward: false,\n pitchBackward: false,\n rollLeft: false,\n rollRight: false,\n joystickL: { x: 0, y: 0 },\n joystickR: { x: 0, y: 0 },\n };\n}\n\n/** Zero-allocation SoA typed-array writer using Koota's public `unpackEntity` + `getStore`. */\nexport function writeEntityKinematics(\n world: World,\n entity: Entity,\n pos: { readonly x: number; readonly y: number; readonly z: number },\n quat: { readonly x: number; readonly y: number; readonly z: number; readonly w: number },\n linVel: { readonly x: number; readonly y: number; readonly z: number },\n speedKmh: number,\n): void {\n const { entityId } = unpackEntity(entity);\n if (entity.has(TransformTrait)) {\n const xf = getStore(world, TransformTrait);\n xf.x[entityId] = pos.x;\n xf.y[entityId] = pos.y;\n xf.z[entityId] = pos.z;\n xf.qx[entityId] = quat.x;\n xf.qy[entityId] = quat.y;\n xf.qz[entityId] = quat.z;\n xf.qw[entityId] = quat.w;\n }\n if (entity.has(VelocityTrait)) {\n const vl = getStore(world, VelocityTrait);\n vl.vx[entityId] = linVel.x;\n vl.vy[entityId] = linVel.y;\n vl.vz[entityId] = linVel.z;\n vl.speedKmh[entityId] = speedKmh;\n }\n}\n\n/** Zero-allocation SoA typed-array writer for `VehicleTelemetryTrait` inside `useFrame`. */\nexport function writeVehicleTelemetry(\n world: World,\n entity: Entity,\n rpm: number,\n gear: number,\n throttle: number,\n boost: number,\n slip: number,\n): void {\n if (!entity.has(VehicleTelemetryTrait))\n return;\n const { entityId } = unpackEntity(entity);\n const st = getStore(world, VehicleTelemetryTrait);\n st.rpm[entityId] = rpm;\n st.gear[entityId] = gear;\n st.throttle[entityId] = throttle;\n st.boost[entityId] = boost;\n st.slip[entityId] = slip;\n}\n\nconst _exitPos = new THREE.Vector3();\nconst _exitFwd = new THREE.Vector3();\nconst _flipUp = new THREE.Vector3();\nconst _flipFwd = new THREE.Vector3();\nconst _flipRight = new THREE.Vector3();\nconst _flipMat = new THREE.Matrix4();\nconst _flipQuat = new THREE.Quaternion();\n\nexport function flipVehicleBodyUpright(veh: EcctrlVehicleHandle, joints?: KhrVehicleJointsHandle | null): void {\n const body = veh.body;\n if (!body)\n return;\n const pos = body.translation();\n _flipUp.copy(veh.upAxis);\n if (_flipUp.lengthSq() < 1e-6)\n _flipUp.set(0, 1, 0);\n else\n _flipUp.normalize();\n\n _flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);\n if (_flipFwd.lengthSq() < 1e-6) {\n if (Math.abs(_flipUp.y) < 0.9)\n _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);\n else\n _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);\n }\n _flipFwd.normalize();\n _flipRight.crossVectors(_flipUp, _flipFwd).normalize();\n _flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);\n _flipQuat.setFromRotationMatrix(_flipMat);\n\n body.setTranslation({ x: pos.x + _flipUp.x * 1.35, y: pos.y + _flipUp.y * 1.35, z: pos.z + _flipUp.z * 1.35 }, true);\n body.setRotation({ x: _flipQuat.x, y: _flipQuat.y, z: _flipQuat.z, w: _flipQuat.w }, true);\n body.setLinvel({ x: 0, y: 0, z: 0 }, true);\n body.setAngvel({ x: 0, y: 0, z: 0 }, true);\n joints?.syncBodiesToParent();\n}\n\nexport const kolmoActions = createActions((world) => ({\n boardVehicle: (vehicleId: string) => {\n if (!vehicleId)\n return;\n ensureWorldSession(world);\n let targetEnt: Entity | undefined;\n for (const vehEnt of world.query(VehicleTrait)) {\n const v = vehEnt.get(VehicleTrait);\n if (v?.id === vehicleId) {\n targetEnt = vehEnt;\n break;\n }\n }\n if (!targetEnt)\n return;\n\n for (const prev of world.query(pilotedVehicleQuery)) {\n if (prev !== targetEnt && prev.has(PilotedTag))\n prev.remove(PilotedTag);\n }\n if (!targetEnt.has(PilotedTag))\n targetEnt.add(PilotedTag);\n\n const pilot = world.queryFirst(ActorTrait);\n if (pilot)\n pilot.add(PilotLink(targetEnt));\n\n if (world.get(WorldSessionTrait)?.nearVehicleId) {\n world.set(WorldSessionTrait, { nearVehicleId: \"\" });\n }\n },\n exitVehicle: () => {\n ensureWorldSession(world);\n const pilot = world.queryFirst(ActorTrait);\n const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n if (linked) {\n const v = linked.get(VehicleTrait);\n if (pilot) {\n if (pilot.has(PilotLink(linked)))\n pilot.remove(PilotLink(linked));\n if (v?.handle) {\n _exitPos\n .set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2])\n .applyQuaternion(v.handle.currQuat)\n .add(v.handle.currPos);\n _exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();\n const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;\n const lv = v.handle.currLinVel;\n const curActor = pilot.get(ActorTrait);\n pilot.set(ActorTrait, {\n id: curActor?.id ?? \"pilot\",\n handle: curActor?.handle ?? null,\n exitSpawnPos: [_exitPos.x, _exitPos.y, _exitPos.z],\n exitSpawnYaw: yaw,\n exitLinVel: [lv.x, lv.y, lv.z],\n });\n }\n }\n if (linked.has(PilotedTag))\n linked.remove(PilotedTag);\n v?.handle?.setMovement(createEmptyVehicleCmd(!v.isFlight));\n }\n for (const extra of world.query(pilotedVehicleQuery)) {\n if (extra.has(PilotedTag))\n extra.remove(PilotedTag);\n }\n },\n resetVehicle: (vehicleId?: string) => {\n let target: VehicleTraitData | undefined;\n if (vehicleId) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.id === vehicleId && v.handle?.body) {\n target = v;\n break;\n }\n }\n }\n if (!target) {\n const piloted = world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n const pv = piloted?.get(VehicleTrait);\n if (pv?.handle?.body)\n target = pv;\n }\n if (!target) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.handle?.body) {\n target = v;\n break;\n }\n }\n }\n if (target?.handle)\n flipVehicleBodyUpright(target.handle, target.jointsHandle);\n },\n}));\n"],"mappings":";;;;;;;;AAuBA,SAAgB,iBACZ,aACA,QACuB;CACvB,MAAM,YAAY,QAAQ,QAAQ;CAClC,IAAI,CAAC,WACD,OAAO;CACX,MAAM,OAAO,YAAY,aAAa,UAAU,MAAM;CACtD,OAAO,SAAS,YAAY,OAAO;AACvC;AA2BA,IAAa,eAAe,aAA+B;CACvD,IAAI;CACJ,QAAQ;CACR,cAAc;CACd,YAAY;EAAC;EAAG;EAAM;CAAC;CACvB,YAAY;EAAC;EAAM;EAAM;CAAC;CAC1B,UAAU;AACd,EAAE;AAEF,IAAa,aAAa,aAA6B;CACnD,IAAI;CACJ,QAAQ;CACR,cAAc;CACd,cAAc;CACd,YAAY;AAChB,EAAE;AAEF,IAAa,YAAY,aAA4B;CACjD,IAAI;CACJ,QAAQ;CACR,OAAO;AACX,EAAE;AAEF,IAAa,iBAAiB,MAAM;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,IAAI;CAAG,IAAI;CAAG,IAAI;CAAG,IAAI;AAAE,CAAC;AACpF,IAAa,gBAAgB,MAAM;CAAE,IAAI;CAAG,IAAI;CAAG,IAAI;CAAG,UAAU;AAAE,CAAC;AACvE,IAAa,wBAAwB,MAAM;CAAE,KAAK;CAAG,MAAM;CAAG,UAAU;CAAG,OAAO;CAAG,MAAM;AAAE,CAAC;AAC9F,IAAa,oBAAoB,MAAM;CAAE,IAAI;CAAI,QAAQ;CAAG,MAAM;AAAgC,CAAC;AACnG,IAAa,aAAa,MAAM;AAChC,IAAa,YAAY,SAAS,EAAE,WAAW,KAAK,CAAC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IAAI,CAAC,QAAQ;GAET,MAAM,MADU,MAAM,WAAW,UAAU,CAAC,EAAE,UAAU,SAAS,KAAK,MAAM,WAAW,mBAAmB,EAAA,EACtF,IAAI,YAAY;GACpC,IAAI,IAAI,QAAQ,MACZ,SAAS;EACjB;EACA,IAAI,CAAC,QACD,KAAK,MAAM,OAAO,MAAM,MAAM,YAAY,GAAG;GACzC,MAAM,IAAI,IAAI,IAAI,YAAY;GAC9B,IAAI,GAAG,QAAQ,MAAM;IACjB,SAAS;IACT;GACJ;EACJ;EAEJ,IAAI,QAAQ,QACR,uBAAuB,OAAO,QAAQ,OAAO,YAAY;CACjE;AACJ,EAAE"}
|
package/dist/vite/index.js
CHANGED
package/dist/vite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["export const KOLMO_SINGLETON_DEDUPE: string[] = [\n \"react\",\n \"react-dom\",\n \"three\",\n \"@react-three/fiber\",\n \"@react-three/drei\",\n \"@react-three/rapier\",\n \"@dimforge/rapier3d-compat\",\n \"@pinkaphant/ecctrl\",\n \"@khr3/core\",\n \"@khr3/c12\",\n \"koota\",\n \"maath\",\n \"zustand\",\n];\n"],"mappings":";AAAA,IAAa,yBAAmC;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/vite/index.ts"],"sourcesContent":["export const KOLMO_SINGLETON_DEDUPE: string[] = [\n \"react\",\n \"react-dom\",\n \"three\",\n \"@react-three/fiber\",\n \"@react-three/drei\",\n \"@react-three/rapier\",\n \"@dimforge/rapier3d-compat\",\n \"@pinkaphant/ecctrl\",\n \"@khr3/core\",\n \"@khr3/c12\",\n \"@khr3/roads\",\n \"koota\",\n \"maath\",\n \"zustand\",\n];\n"],"mappings":";AAAA,IAAa,yBAAmC;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import type RAPIER from "@dimforge/rapier3d-compat";
|
|
4
|
+
export interface WaterWaveComponent {
|
|
5
|
+
readonly dirX: number;
|
|
6
|
+
readonly dirZ: number;
|
|
7
|
+
readonly amplitudeM: number;
|
|
8
|
+
readonly wavelengthM: number;
|
|
9
|
+
readonly speedRadPerSec?: number;
|
|
10
|
+
readonly phaseRad?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface KolmoWaterFieldOptions {
|
|
13
|
+
readonly levelY?: number;
|
|
14
|
+
readonly densityKgM3?: number;
|
|
15
|
+
readonly linearDrag?: number;
|
|
16
|
+
readonly quadraticDrag?: number;
|
|
17
|
+
readonly angularDrag?: number;
|
|
18
|
+
readonly boundsXZ?: readonly [halfExtentX: number, halfExtentZ: number] | null;
|
|
19
|
+
readonly originXZ?: readonly [number, number];
|
|
20
|
+
readonly waves?: readonly WaterWaveComponent[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Exact Archimedes submerged-volume buoyancy + quadratic hydrodynamic drag field over Rapier WASM colliders.
|
|
24
|
+
*/
|
|
25
|
+
export declare class KolmoWaterField {
|
|
26
|
+
levelY: number;
|
|
27
|
+
readonly densityKgM3: number;
|
|
28
|
+
readonly linearDrag: number;
|
|
29
|
+
readonly quadraticDrag: number;
|
|
30
|
+
readonly angularDrag: number;
|
|
31
|
+
readonly originX: number;
|
|
32
|
+
readonly originZ: number;
|
|
33
|
+
readonly halfExtentX: number;
|
|
34
|
+
readonly halfExtentZ: number;
|
|
35
|
+
private readonly waves;
|
|
36
|
+
constructor(options?: KolmoWaterFieldOptions);
|
|
37
|
+
containsXZ(x: number, z: number): boolean;
|
|
38
|
+
sampleSurfaceY(x: number, z: number, timeSec?: number): number;
|
|
39
|
+
sampleNormal(x: number, z: number, timeSec?: number, out?: THREE.Vector3): THREE.Vector3;
|
|
40
|
+
sampleFluidVelocity(x: number, z: number, timeSec?: number, out?: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
z: number;
|
|
44
|
+
}): {
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
z: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Exact spherical cap volume for a sphere of radius `r` submerged by `depth` (`0 <= depth <= 2r`).
|
|
52
|
+
*/
|
|
53
|
+
export declare function sphericalCapVolume(radius: number, depth: number): number;
|
|
54
|
+
/**
|
|
55
|
+
* Steps Archimedes buoyancy, hydrostatic righting moments (8-subcell world-space quadrature on cuboids/hulls),
|
|
56
|
+
* and linear + quadratic drag across all dynamic bodies in `world`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function stepWaterHydrodynamics(rapier: typeof RAPIER, world: RAPIER.World, water: KolmoWaterField, timeSec: number, dt: number): number;
|
|
59
|
+
export interface KolmoWaterHandle {
|
|
60
|
+
readonly field: KolmoWaterField;
|
|
61
|
+
}
|
|
62
|
+
export interface KolmoWaterProps extends Omit<KolmoWaterFieldOptions, "boundsXZ"> {
|
|
63
|
+
readonly ref?: React.Ref<KolmoWaterHandle>;
|
|
64
|
+
readonly field?: KolmoWaterField;
|
|
65
|
+
readonly size?: readonly [widthX: number, depthZ: number];
|
|
66
|
+
readonly segments?: readonly [segsX: number, segsZ: number];
|
|
67
|
+
readonly color?: string;
|
|
68
|
+
readonly opacity?: number;
|
|
69
|
+
readonly material?: THREE.Material;
|
|
70
|
+
}
|
|
71
|
+
export declare function KolmoWater({ ref, field: externalField, levelY, densityKgM3, linearDrag, quadraticDrag, angularDrag, originXZ, waves, size, segments, color, opacity, material: externalMaterial, }: KolmoWaterProps): React.JSX.Element;
|