@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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { create } from "zustand";
|
|
3
|
-
import { JointRegistryContext, cloneKhrBundle, isJointOpen,
|
|
4
|
-
import {
|
|
5
|
-
import { useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
3
|
+
import { JointRegistryContext, cloneKhrBundle, isJointOpen, toggleDrivenJoint, useKhrGlb } from "@khr3/core";
|
|
4
|
+
import { STEP_METRES, canPlace, latticePose, poseEq, poseToFloat, snapPose, socketFor, worldSockets, wrapYaw } from "@khr3/c12";
|
|
5
|
+
import React, { useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
6
6
|
import { createPortal, useFrame, useThree } from "@react-three/fiber";
|
|
7
|
-
import {
|
|
7
|
+
import { useRapier } from "@react-three/rapier";
|
|
8
8
|
import { easing } from "maath";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { b as useActiveKolmoWorld, t as ActorTrait, v as pilotedVehicleQuery } from "./traits-Dp1ey_4w.js";
|
|
10
|
+
import { c as useKolmoGame, d as KolmoVehicle, l as KolmoProp } from "./world-BDhBihjW.js";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
// src/toolgun/store.ts
|
|
13
13
|
var TOOLGUN_MODES = [
|
|
@@ -29,50 +29,6 @@ var TOOLGUN_BUILD_KINDS = [
|
|
|
29
29
|
"RoofTriangle",
|
|
30
30
|
"Stairs"
|
|
31
31
|
];
|
|
32
|
-
var TOOLGUN_SKIN_PRESETS = {
|
|
33
|
-
cobalt: {
|
|
34
|
-
bodyHex: "#1e293b",
|
|
35
|
-
accentHex: "#38bdf8",
|
|
36
|
-
emissiveHex: "#0ea5e9",
|
|
37
|
-
metalness: .65,
|
|
38
|
-
roughness: .32
|
|
39
|
-
},
|
|
40
|
-
hazard: {
|
|
41
|
-
bodyHex: "#292524",
|
|
42
|
-
accentHex: "#f59e0b",
|
|
43
|
-
emissiveHex: "#d97706",
|
|
44
|
-
metalness: .55,
|
|
45
|
-
roughness: .38
|
|
46
|
-
},
|
|
47
|
-
stealth: {
|
|
48
|
-
bodyHex: "#0f172a",
|
|
49
|
-
accentHex: "#64748b",
|
|
50
|
-
emissiveHex: "#38bdf8",
|
|
51
|
-
metalness: .72,
|
|
52
|
-
roughness: .28
|
|
53
|
-
},
|
|
54
|
-
chrome: {
|
|
55
|
-
bodyHex: "#cbd5e1",
|
|
56
|
-
accentHex: "#0284c7",
|
|
57
|
-
emissiveHex: "#38bdf8",
|
|
58
|
-
metalness: .92,
|
|
59
|
-
roughness: .14
|
|
60
|
-
},
|
|
61
|
-
arctic: {
|
|
62
|
-
bodyHex: "#f1f5f9",
|
|
63
|
-
accentHex: "#06b6d4",
|
|
64
|
-
emissiveHex: "#22d3ee",
|
|
65
|
-
metalness: .35,
|
|
66
|
-
roughness: .42
|
|
67
|
-
},
|
|
68
|
-
ember: {
|
|
69
|
-
bodyHex: "#1c1917",
|
|
70
|
-
accentHex: "#ef4444",
|
|
71
|
-
emissiveHex: "#f97316",
|
|
72
|
-
metalness: .62,
|
|
73
|
-
roughness: .34
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
32
|
var _upDefault = new THREE.Vector3(0, 1, 0);
|
|
77
33
|
var _nrmVec = new THREE.Vector3();
|
|
78
34
|
var _alignQuat = new THREE.Quaternion();
|
|
@@ -86,35 +42,71 @@ var _vA = new THREE.Vector3();
|
|
|
86
42
|
var _vB = new THREE.Vector3();
|
|
87
43
|
var _axLocal = new THREE.Vector3();
|
|
88
44
|
var _axWorldB = new THREE.Vector3();
|
|
45
|
+
var _sharedRay = null;
|
|
46
|
+
function readVecX(v) {
|
|
47
|
+
return Array.isArray(v) ? v[0] : v.x;
|
|
48
|
+
}
|
|
49
|
+
function readVecY(v) {
|
|
50
|
+
return Array.isArray(v) ? v[1] : v.y;
|
|
51
|
+
}
|
|
52
|
+
function readVecZ(v) {
|
|
53
|
+
return Array.isArray(v) ? v[2] : v.z;
|
|
54
|
+
}
|
|
89
55
|
/**
|
|
90
|
-
* Casts a solid ray against Rapier WASM colliders
|
|
56
|
+
* Casts a solid ray against Rapier WASM colliders using `QueryFilterFlags.EXCLUDE_SENSORS`,
|
|
57
|
+
* ignoring the optional actor `RigidBody`. Pass `out` on hot `useFrame` paths for zero heap allocations.
|
|
91
58
|
*/
|
|
92
|
-
function castToolgunRay(rapier, world, origin, direction, maxRange = 80, excludeBody) {
|
|
93
|
-
const
|
|
59
|
+
function castToolgunRay(rapier, world, origin, direction, maxRange = 80, excludeBody, out) {
|
|
60
|
+
const ox = readVecX(origin), oy = readVecY(origin), oz = readVecZ(origin);
|
|
61
|
+
const rx = readVecX(direction), ry = readVecY(direction), rz = readVecZ(direction);
|
|
62
|
+
const dirLen = Math.hypot(rx, ry, rz);
|
|
94
63
|
if (dirLen < 1e-8 || maxRange <= 0) return null;
|
|
95
|
-
const dx =
|
|
96
|
-
const dy =
|
|
97
|
-
const dz =
|
|
98
|
-
|
|
99
|
-
x:
|
|
100
|
-
y:
|
|
101
|
-
z:
|
|
64
|
+
const dx = rx / dirLen;
|
|
65
|
+
const dy = ry / dirLen;
|
|
66
|
+
const dz = rz / dirLen;
|
|
67
|
+
if (!_sharedRay) _sharedRay = new rapier.Ray({
|
|
68
|
+
x: ox,
|
|
69
|
+
y: oy,
|
|
70
|
+
z: oz
|
|
102
71
|
}, {
|
|
103
72
|
x: dx,
|
|
104
73
|
y: dy,
|
|
105
74
|
z: dz
|
|
106
75
|
});
|
|
107
|
-
|
|
76
|
+
else {
|
|
77
|
+
_sharedRay.origin.x = ox;
|
|
78
|
+
_sharedRay.origin.y = oy;
|
|
79
|
+
_sharedRay.origin.z = oz;
|
|
80
|
+
_sharedRay.dir.x = dx;
|
|
81
|
+
_sharedRay.dir.y = dy;
|
|
82
|
+
_sharedRay.dir.z = dz;
|
|
83
|
+
}
|
|
84
|
+
const hit = world.castRayAndGetNormal(_sharedRay, maxRange, true, rapier.QueryFilterFlags.EXCLUDE_SENSORS, void 0, void 0, excludeBody ?? void 0);
|
|
108
85
|
if (!hit) return null;
|
|
109
86
|
const nLen = Math.hypot(hit.normal.x, hit.normal.y, hit.normal.z);
|
|
110
87
|
const nx = nLen > 1e-6 ? hit.normal.x / nLen : 0;
|
|
111
88
|
const ny = nLen > 1e-6 ? hit.normal.y / nLen : 1;
|
|
112
89
|
const nz = nLen > 1e-6 ? hit.normal.z / nLen : 0;
|
|
90
|
+
const px = ox + dx * hit.timeOfImpact;
|
|
91
|
+
const py = oy + dy * hit.timeOfImpact;
|
|
92
|
+
const pz = oz + dz * hit.timeOfImpact;
|
|
93
|
+
if (out) {
|
|
94
|
+
out.point[0] = px;
|
|
95
|
+
out.point[1] = py;
|
|
96
|
+
out.point[2] = pz;
|
|
97
|
+
out.normal[0] = nx;
|
|
98
|
+
out.normal[1] = ny;
|
|
99
|
+
out.normal[2] = nz;
|
|
100
|
+
out.toi = hit.timeOfImpact;
|
|
101
|
+
out.collider = hit.collider;
|
|
102
|
+
out.body = hit.collider.parent();
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
113
105
|
return {
|
|
114
106
|
point: [
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
px,
|
|
108
|
+
py,
|
|
109
|
+
pz
|
|
118
110
|
],
|
|
119
111
|
normal: [
|
|
120
112
|
nx,
|
|
@@ -127,7 +119,7 @@ function castToolgunRay(rapier, world, origin, direction, maxRange = 80, exclude
|
|
|
127
119
|
};
|
|
128
120
|
}
|
|
129
121
|
/**
|
|
130
|
-
* Aligns a spawned asset's +Y axis to `surfaceNormal` (when sloped) composed with exact 30° `yaw12` turn.
|
|
122
|
+
* Aligns a spawned asset's +Y axis to `surfaceNormal` (when sloped <= 55°) composed with exact 30° `yaw12` turn.
|
|
131
123
|
*/
|
|
132
124
|
function computeAlignedSpawnPose(point, yaw12, surfaceNormal = [
|
|
133
125
|
0,
|
|
@@ -262,16 +254,19 @@ function rigJointRuntime(rt, severBreakaway = false) {
|
|
|
262
254
|
if (severBreakaway) {
|
|
263
255
|
if (rt.applyImpactImpulse(Number.POSITIVE_INFINITY) === "detached") return `Detached ${rt.nodeName}`;
|
|
264
256
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const nextOpen = !isJointOpen(rt);
|
|
268
|
-
const target = nextOpen ? openTargetForLimits(limits) : Math.min(limits[1], Math.max(limits[0], 0));
|
|
269
|
-
rt.applyTarget(target);
|
|
270
|
-
return `${nextOpen ? "Opened" : "Closed"} ${rt.nodeName}`;
|
|
271
|
-
}
|
|
257
|
+
const wasOpen = isJointOpen(rt);
|
|
258
|
+
if (toggleDrivenJoint(rt)) return `${wasOpen ? "Closed" : "Opened"} ${rt.nodeName}`;
|
|
272
259
|
return rt.applyImpactImpulse(Number.POSITIVE_INFINITY) === "detached" ? `Detached ${rt.nodeName}` : `Joint ${rt.nodeName} (${rt.kind})`;
|
|
273
260
|
}
|
|
274
261
|
/**
|
|
262
|
+
* Exact equality check for `BuildSnapCandidate` using `@khr3/c12`'s `poseEq`
|
|
263
|
+
* (avoiding float quaternion sign collisions such as 60° vs 300° where `qy === 0.5`).
|
|
264
|
+
*/
|
|
265
|
+
function isSameBuildPreview(a, b) {
|
|
266
|
+
if (!a) return false;
|
|
267
|
+
return a.kind === b.kind && a.valid === b.valid && a.snappedSocket === b.snappedSocket && a.reason === b.reason && poseEq(a.pose, b.pose);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
275
270
|
* Computes the nearest exact `@khr3/c12` socket-snapped or ground-lattice `BuildSnapCandidate` for `kind`.
|
|
276
271
|
*/
|
|
277
272
|
function computeBuildCandidate(placedPieces, aimPoint, kind, yaw12, snapRadiusM = 2.6) {
|
|
@@ -327,16 +322,18 @@ function computeBuildCandidate(placedPieces, aimPoint, kind, yaw12, snapRadiusM
|
|
|
327
322
|
reason: check.reason
|
|
328
323
|
};
|
|
329
324
|
}
|
|
325
|
+
function bodyMatchesSpawnedId(body, spawnedId) {
|
|
326
|
+
if (!body) return false;
|
|
327
|
+
return body.userData?.kolmoSpawnedId === spawnedId;
|
|
328
|
+
}
|
|
330
329
|
var nextSeq = 1;
|
|
331
330
|
function createToolgunStore() {
|
|
332
331
|
return create((set, get) => ({
|
|
333
332
|
mode: "spawn",
|
|
334
|
-
skinPreset: "cobalt",
|
|
335
333
|
yaw12: 0,
|
|
336
334
|
buildKind: "FoundationSquare",
|
|
337
335
|
zoomed: false,
|
|
338
336
|
armedAsset: null,
|
|
339
|
-
target: null,
|
|
340
337
|
buildPreview: null,
|
|
341
338
|
pendingAnchor: null,
|
|
342
339
|
spawnedEntities: [],
|
|
@@ -358,7 +355,6 @@ function createToolgunStore() {
|
|
|
358
355
|
statusText: `MODE: ${next.toUpperCase()}`
|
|
359
356
|
});
|
|
360
357
|
},
|
|
361
|
-
setSkinPreset: (skinPreset) => set({ skinPreset }),
|
|
362
358
|
rotateYaw12: (stepsDelta = 1) => {
|
|
363
359
|
const nextYaw = wrapYaw(get().yaw12 + stepsDelta);
|
|
364
360
|
set({
|
|
@@ -383,7 +379,6 @@ function createToolgunStore() {
|
|
|
383
379
|
armedAsset,
|
|
384
380
|
...armedAsset ? { statusText: `ARMED: ${armedAsset.name}` } : {}
|
|
385
381
|
}),
|
|
386
|
-
setTarget: (target) => set({ target }),
|
|
387
382
|
setBuildPreview: (buildPreview) => set({ buildPreview }),
|
|
388
383
|
setPendingAnchor: (pendingAnchor) => set({ pendingAnchor }),
|
|
389
384
|
recordSpawn: (entry) => set((s) => ({
|
|
@@ -431,11 +426,32 @@ function createToolgunStore() {
|
|
|
431
426
|
statusText: `${entry.kind === "weld" ? "WELDED" : "HINGED"} #${entry.handle}`,
|
|
432
427
|
fireCount: s.fireCount + 1
|
|
433
428
|
})),
|
|
434
|
-
removeEntityById: (id) => {
|
|
435
|
-
|
|
429
|
+
removeEntityById: (id, world) => {
|
|
430
|
+
const st = get();
|
|
431
|
+
if (!st.spawnedEntities.some((e) => e.id === id)) return false;
|
|
432
|
+
const removedJointIds = /* @__PURE__ */ new Set();
|
|
433
|
+
const keptJoints = [];
|
|
434
|
+
for (const cj of st.createdJoints) {
|
|
435
|
+
if (!world || cj.world !== world) {
|
|
436
|
+
if (!world || cj.world !== world) keptJoints.push(cj);
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
const live = world.getImpulseJoint(cj.joint.handle);
|
|
440
|
+
if (!live) {
|
|
441
|
+
removedJointIds.add(cj.id);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (bodyMatchesSpawnedId(live.body1(), id) || bodyMatchesSpawnedId(live.body2(), id)) {
|
|
445
|
+
world.removeImpulseJoint(live, true);
|
|
446
|
+
removedJointIds.add(cj.id);
|
|
447
|
+
} else keptJoints.push(cj);
|
|
448
|
+
}
|
|
449
|
+
const clearPending = st.pendingAnchor && (!world || st.pendingAnchor.world === world) ? bodyMatchesSpawnedId(st.pendingAnchor.body, id) : false;
|
|
436
450
|
set((s) => ({
|
|
437
451
|
spawnedEntities: s.spawnedEntities.filter((e) => e.id !== id),
|
|
438
|
-
|
|
452
|
+
createdJoints: keptJoints,
|
|
453
|
+
...clearPending ? { pendingAnchor: null } : {},
|
|
454
|
+
history: s.history.filter((h) => !(h.type === "spawn" && h.id === id) && !(h.type === "joint" && removedJointIds.has(h.id))),
|
|
439
455
|
statusText: `DELETED ${id}`,
|
|
440
456
|
fireCount: s.fireCount + 1
|
|
441
457
|
}));
|
|
@@ -455,6 +471,10 @@ function createToolgunStore() {
|
|
|
455
471
|
const keep = [];
|
|
456
472
|
const removedIds = /* @__PURE__ */ new Set();
|
|
457
473
|
for (const cj of get().createdJoints) {
|
|
474
|
+
if (cj.world !== world) {
|
|
475
|
+
keep.push(cj);
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
458
478
|
const live = world.getImpulseJoint(cj.joint.handle);
|
|
459
479
|
if (!live) {
|
|
460
480
|
removedIds.add(cj.id);
|
|
@@ -473,19 +493,28 @@ function createToolgunStore() {
|
|
|
473
493
|
}));
|
|
474
494
|
return removedIds.size;
|
|
475
495
|
},
|
|
496
|
+
clearWorldHandles: (world) => {
|
|
497
|
+
const st = get();
|
|
498
|
+
const clearPending = st.pendingAnchor?.world === world;
|
|
499
|
+
const hasWorldJoints = st.createdJoints.some((cj) => cj.world === world);
|
|
500
|
+
if (!clearPending && !hasWorldJoints) return;
|
|
501
|
+
const removedIds = new Set(st.createdJoints.filter((cj) => cj.world === world).map((cj) => cj.id));
|
|
502
|
+
set((s) => ({
|
|
503
|
+
...clearPending ? { pendingAnchor: null } : {},
|
|
504
|
+
createdJoints: s.createdJoints.filter((cj) => cj.world !== world),
|
|
505
|
+
history: s.history.filter((h) => !(h.type === "joint" && removedIds.has(h.id)))
|
|
506
|
+
}));
|
|
507
|
+
},
|
|
476
508
|
undoLast: (world) => {
|
|
477
509
|
const st = get();
|
|
478
510
|
const last = st.history[st.history.length - 1];
|
|
479
511
|
if (!last) return "NOTHING TO UNDO";
|
|
480
|
-
const nextHistory = st.history.slice(0, -1);
|
|
481
512
|
if (last.type === "spawn") {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
history: nextHistory,
|
|
485
|
-
statusText: `UNDO SPAWN ${last.id}`
|
|
486
|
-
});
|
|
513
|
+
get().removeEntityById(last.id, world);
|
|
514
|
+
set({ statusText: `UNDO SPAWN ${last.id}` });
|
|
487
515
|
return `UNDO SPAWN ${last.id}`;
|
|
488
516
|
}
|
|
517
|
+
const nextHistory = st.history.slice(0, -1);
|
|
489
518
|
if (last.type === "piece") {
|
|
490
519
|
set({
|
|
491
520
|
placedPieces: st.placedPieces.filter((p) => p.id !== last.id),
|
|
@@ -495,7 +524,10 @@ function createToolgunStore() {
|
|
|
495
524
|
return `UNDO PIECE ${last.id}`;
|
|
496
525
|
}
|
|
497
526
|
const jEntry = st.createdJoints.find((j) => j.id === last.id);
|
|
498
|
-
if (jEntry && world &&
|
|
527
|
+
if (jEntry && world && jEntry.world === world) {
|
|
528
|
+
const liveJoint = world.getImpulseJoint(jEntry.joint.handle);
|
|
529
|
+
if (liveJoint) world.removeImpulseJoint(liveJoint, true);
|
|
530
|
+
}
|
|
499
531
|
set({
|
|
500
532
|
createdJoints: st.createdJoints.filter((j) => j.id !== last.id),
|
|
501
533
|
history: nextHistory,
|
|
@@ -508,8 +540,10 @@ function createToolgunStore() {
|
|
|
508
540
|
fireCount: s.fireCount + 1
|
|
509
541
|
})),
|
|
510
542
|
resetAll: (world) => {
|
|
511
|
-
if (world) {
|
|
512
|
-
|
|
543
|
+
if (world) for (const cj of get().createdJoints) {
|
|
544
|
+
if (cj.world !== world) continue;
|
|
545
|
+
const liveJoint = world.getImpulseJoint(cj.joint.handle);
|
|
546
|
+
if (liveJoint) world.removeImpulseJoint(liveJoint, true);
|
|
513
547
|
}
|
|
514
548
|
set({
|
|
515
549
|
pendingAnchor: null,
|
|
@@ -526,12 +560,30 @@ var useToolgunStore = createToolgunStore();
|
|
|
526
560
|
// src/toolgun/Toolgun.tsx
|
|
527
561
|
var LCD_W = 256;
|
|
528
562
|
var LCD_H = 192;
|
|
529
|
-
var
|
|
530
|
-
var
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
563
|
+
var DEFAULT_ACCENT_HEX = "#38bdf8";
|
|
564
|
+
var VAULT_CITY_BASE = "https://khr3.optimuspi.workers.dev/assets/city";
|
|
565
|
+
var DEFAULT_VAULT_C12_URLS = Object.freeze({
|
|
566
|
+
FoundationSquare: `${VAULT_CITY_BASE}/foundation_square_3x3.glb`,
|
|
567
|
+
FoundationTriangle: `${VAULT_CITY_BASE}/foundation_triangle_3m.glb`,
|
|
568
|
+
Street: `${VAULT_CITY_BASE}/R_Straight_6x6.glb`,
|
|
569
|
+
Wall: `${VAULT_CITY_BASE}/wall_solid_3x3x200mm.glb`,
|
|
570
|
+
Doorway: `${VAULT_CITY_BASE}/wall_clapboard_doorframe_3x3.glb`,
|
|
571
|
+
DoorLeaf: `${VAULT_CITY_BASE}/door_hinged_single_900x2100.glb`,
|
|
572
|
+
Floor: `${VAULT_CITY_BASE}/floor_square_3x3.glb`,
|
|
573
|
+
FloorTriangle: `${VAULT_CITY_BASE}/floor_triangle_3m.glb`,
|
|
574
|
+
Roof: `${VAULT_CITY_BASE}/roof_flat_3x3.glb`,
|
|
575
|
+
RoofTriangle: `${VAULT_CITY_BASE}/roof_triangle_3m.glb`,
|
|
576
|
+
Stairs: `${VAULT_CITY_BASE}/stairs_3x3.glb`
|
|
577
|
+
});
|
|
578
|
+
/**
|
|
579
|
+
* Measures grip, muzzle, and optional LCD bezel (`screen_rect` / `lcd_screen`) sockets on an already-cloned viewmodel scene.
|
|
580
|
+
* Offsets the LCD quad 1mm along `screen_rect`'s local +Z normal in root space so arbitrary bezel orientations never z-fight.
|
|
581
|
+
*/
|
|
582
|
+
function measureToolgunViewmodel(clonedScene) {
|
|
583
|
+
clonedScene.updateMatrixWorld(true);
|
|
584
|
+
const invRoot = clonedScene.matrixWorld.clone().invert();
|
|
585
|
+
const invRootQuat = clonedScene.getWorldQuaternion(new THREE.Quaternion()).invert();
|
|
586
|
+
const rootScale = clonedScene.getWorldScale(new THREE.Vector3());
|
|
535
587
|
let grip = [
|
|
536
588
|
0,
|
|
537
589
|
0,
|
|
@@ -542,23 +594,16 @@ function measureToolgunViewmodel(sourceScene) {
|
|
|
542
594
|
.04,
|
|
543
595
|
-.24
|
|
544
596
|
];
|
|
545
|
-
let
|
|
546
|
-
0,
|
|
547
|
-
.068,
|
|
548
|
-
.095
|
|
549
|
-
];
|
|
550
|
-
let screenQuat = [
|
|
551
|
-
0,
|
|
552
|
-
0,
|
|
553
|
-
0,
|
|
554
|
-
1
|
|
555
|
-
];
|
|
556
|
-
let screenSize = [.068, .051];
|
|
597
|
+
let screen = null;
|
|
557
598
|
const tmpPos = new THREE.Vector3();
|
|
558
599
|
const tmpQuat = new THREE.Quaternion();
|
|
559
|
-
|
|
600
|
+
const tmpPlaneRot = new THREE.Quaternion();
|
|
601
|
+
const tmpNormal = new THREE.Vector3();
|
|
602
|
+
const tmpSize = new THREE.Vector3();
|
|
603
|
+
const tmpScale = new THREE.Vector3();
|
|
604
|
+
clonedScene.traverse((node) => {
|
|
560
605
|
const low = node.name.toLowerCase();
|
|
561
|
-
if (low === "ik_palm_primary" || low === "grip" || low === "socket_grip") {
|
|
606
|
+
if (low === "ik_palm_primary" || low === "grip" || low === "socket_grip" || low === "piezo_grip") {
|
|
562
607
|
node.getWorldPosition(tmpPos).applyMatrix4(invRoot);
|
|
563
608
|
grip = [
|
|
564
609
|
-tmpPos.x,
|
|
@@ -574,36 +619,56 @@ function measureToolgunViewmodel(sourceScene) {
|
|
|
574
619
|
];
|
|
575
620
|
} else if (low === "screen_rect" || low === "lcd_screen") {
|
|
576
621
|
node.getWorldPosition(tmpPos).applyMatrix4(invRoot);
|
|
577
|
-
node.getWorldQuaternion(tmpQuat);
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
];
|
|
583
|
-
screenQuat = [
|
|
584
|
-
tmpQuat.x,
|
|
585
|
-
tmpQuat.y,
|
|
586
|
-
tmpQuat.z,
|
|
587
|
-
tmpQuat.w
|
|
588
|
-
];
|
|
622
|
+
node.getWorldQuaternion(tmpQuat).premultiply(invRootQuat).normalize();
|
|
623
|
+
node.getWorldScale(tmpScale);
|
|
624
|
+
const sx = Math.abs(rootScale.x) > 1e-6 ? Math.abs(tmpScale.x / rootScale.x) : 1;
|
|
625
|
+
const sy = Math.abs(rootScale.y) > 1e-6 ? Math.abs(tmpScale.y / rootScale.y) : 1;
|
|
626
|
+
const sz = Math.abs(rootScale.z) > 1e-6 ? Math.abs(tmpScale.z / rootScale.z) : 1;
|
|
589
627
|
const mesh = node;
|
|
628
|
+
let screenSize = [.068, .051];
|
|
629
|
+
tmpPlaneRot.identity();
|
|
590
630
|
if (mesh.isMesh && mesh.geometry) {
|
|
591
631
|
mesh.geometry.computeBoundingBox();
|
|
592
632
|
const bb = mesh.geometry.boundingBox;
|
|
593
633
|
if (bb) {
|
|
594
|
-
|
|
595
|
-
|
|
634
|
+
bb.getSize(tmpSize);
|
|
635
|
+
const ex = tmpSize.x * sx;
|
|
636
|
+
const ey = tmpSize.y * sy;
|
|
637
|
+
const ez = tmpSize.z * sz;
|
|
638
|
+
if (ez <= ex && ez <= ey) screenSize = [Math.max(.025, ex), Math.max(.02, ey)];
|
|
639
|
+
else if (ey <= ex && ey <= ez) {
|
|
640
|
+
tmpPlaneRot.setFromAxisAngle(new THREE.Vector3(1, 0, 0), -Math.PI / 2);
|
|
641
|
+
screenSize = [Math.max(.025, ex), Math.max(.02, ez)];
|
|
642
|
+
} else {
|
|
643
|
+
tmpPlaneRot.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 2);
|
|
644
|
+
screenSize = [Math.max(.025, ez), Math.max(.02, ey)];
|
|
645
|
+
}
|
|
596
646
|
}
|
|
647
|
+
mesh.visible = false;
|
|
597
648
|
}
|
|
649
|
+
tmpQuat.multiply(tmpPlaneRot).normalize();
|
|
650
|
+
tmpNormal.set(0, 0, 1).applyQuaternion(tmpQuat);
|
|
651
|
+
screen = {
|
|
652
|
+
pos: [
|
|
653
|
+
tmpPos.x + tmpNormal.x * .001,
|
|
654
|
+
tmpPos.y + tmpNormal.y * .001,
|
|
655
|
+
tmpPos.z + tmpNormal.z * .001
|
|
656
|
+
],
|
|
657
|
+
quat: [
|
|
658
|
+
tmpQuat.x,
|
|
659
|
+
tmpQuat.y,
|
|
660
|
+
tmpQuat.z,
|
|
661
|
+
tmpQuat.w
|
|
662
|
+
],
|
|
663
|
+
size: screenSize
|
|
664
|
+
};
|
|
598
665
|
}
|
|
599
666
|
});
|
|
600
667
|
return {
|
|
601
|
-
scene:
|
|
668
|
+
scene: clonedScene,
|
|
602
669
|
gripOffset: grip,
|
|
603
670
|
muzzleLocal: muzzle,
|
|
604
|
-
|
|
605
|
-
screenQuat,
|
|
606
|
-
screenSize
|
|
671
|
+
screen
|
|
607
672
|
};
|
|
608
673
|
}
|
|
609
674
|
function createLcdSurface() {
|
|
@@ -624,17 +689,17 @@ function createLcdSurface() {
|
|
|
624
689
|
let prevSig = "";
|
|
625
690
|
return {
|
|
626
691
|
texture,
|
|
627
|
-
draw: ({ mode, yawDeg, detail, targetLabel, status,
|
|
692
|
+
draw: ({ mode, yawDeg, detail, targetLabel, status, accentColor }) => {
|
|
628
693
|
if (!ctx) return;
|
|
629
|
-
const sig = `${mode}|${yawDeg}|${detail}|${targetLabel}|${status}|${
|
|
694
|
+
const sig = `${mode}|${yawDeg}|${detail}|${targetLabel}|${status}|${accentColor}`;
|
|
630
695
|
if (sig === prevSig) return;
|
|
631
696
|
prevSig = sig;
|
|
632
697
|
ctx.fillStyle = "#070d19";
|
|
633
698
|
ctx.fillRect(0, 0, LCD_W, LCD_H);
|
|
634
|
-
ctx.strokeStyle =
|
|
699
|
+
ctx.strokeStyle = accentColor;
|
|
635
700
|
ctx.lineWidth = 3;
|
|
636
701
|
ctx.strokeRect(4, 4, 248, 184);
|
|
637
|
-
ctx.fillStyle =
|
|
702
|
+
ctx.fillStyle = accentColor;
|
|
638
703
|
ctx.fillRect(4, 4, 248, 28);
|
|
639
704
|
ctx.fillStyle = "#040812";
|
|
640
705
|
ctx.font = "bold 15px ui-monospace, SFMono-Regular, Menlo, monospace";
|
|
@@ -668,437 +733,99 @@ function createLcdSurface() {
|
|
|
668
733
|
}
|
|
669
734
|
};
|
|
670
735
|
}
|
|
671
|
-
function
|
|
672
|
-
const
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const geo = new THREE.BufferGeometry();
|
|
697
|
-
geo.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
|
|
698
|
-
geo.computeVertexNormals();
|
|
699
|
-
return geo;
|
|
700
|
-
}
|
|
701
|
-
function buildTriangleHullVertices(thicknessM) {
|
|
702
|
-
const corners = triangleCorners();
|
|
703
|
-
const verts = [];
|
|
704
|
-
for (const [x, , z] of corners) verts.push(x, 0, z, x, thicknessM, z);
|
|
705
|
-
return new Float32Array(verts);
|
|
706
|
-
}
|
|
707
|
-
function C12PieceColliderAndMesh({ piece }) {
|
|
736
|
+
var SpawnedToolgunOutlet = React.memo(function SpawnedToolgunOutlet({ entry }) {
|
|
737
|
+
const userData = useMemo(() => ({
|
|
738
|
+
kolmoSpawnedId: entry.id,
|
|
739
|
+
name: entry.name
|
|
740
|
+
}), [entry.id, entry.name]);
|
|
741
|
+
const rigidBodyProps = useMemo(() => ({ userData }), [userData]);
|
|
742
|
+
if (entry.kind === "vehicle") return /* @__PURE__ */ jsx(KolmoVehicle, {
|
|
743
|
+
id: entry.id,
|
|
744
|
+
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
745
|
+
...entry.src ? { src: entry.src } : {},
|
|
746
|
+
position: entry.position,
|
|
747
|
+
quaternion: entry.quaternion,
|
|
748
|
+
userData
|
|
749
|
+
});
|
|
750
|
+
return /* @__PURE__ */ jsx(KolmoProp, {
|
|
751
|
+
id: entry.id,
|
|
752
|
+
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
753
|
+
...entry.src ? { src: entry.src } : {},
|
|
754
|
+
fixed: entry.fixed,
|
|
755
|
+
position: entry.position,
|
|
756
|
+
quaternion: entry.quaternion,
|
|
757
|
+
rigidBodyProps
|
|
758
|
+
});
|
|
759
|
+
});
|
|
760
|
+
var PlacedC12Outlet = React.memo(function PlacedC12Outlet({ piece, bundle, src }) {
|
|
708
761
|
const flt = useMemo(() => poseToFloat(piece.pose), [piece.pose]);
|
|
709
762
|
const userData = useMemo(() => ({
|
|
710
763
|
kolmoPlacedPieceId: piece.id,
|
|
711
764
|
name: piece.kind
|
|
712
765
|
}), [piece.id, piece.kind]);
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
720
|
-
type: "fixed",
|
|
721
|
-
colliders: false,
|
|
722
|
-
position: flt.position,
|
|
723
|
-
quaternion: flt.quaternion,
|
|
724
|
-
friction: .6,
|
|
725
|
-
restitution: .1,
|
|
726
|
-
userData,
|
|
727
|
-
children: [/* @__PURE__ */ jsx(CuboidCollider, {
|
|
728
|
-
args: [
|
|
729
|
-
SIDE_METRES * .5,
|
|
730
|
-
SLAB_THICK * .5,
|
|
731
|
-
SIDE_METRES * .5
|
|
732
|
-
],
|
|
733
|
-
position: [
|
|
734
|
-
0,
|
|
735
|
-
yOff,
|
|
736
|
-
0
|
|
737
|
-
]
|
|
738
|
-
}), /* @__PURE__ */ jsxs("mesh", {
|
|
739
|
-
position: [
|
|
740
|
-
0,
|
|
741
|
-
yOff,
|
|
742
|
-
0
|
|
743
|
-
],
|
|
744
|
-
castShadow: true,
|
|
745
|
-
receiveShadow: true,
|
|
746
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
747
|
-
SIDE_METRES,
|
|
748
|
-
SLAB_THICK,
|
|
749
|
-
SIDE_METRES
|
|
750
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
751
|
-
color,
|
|
752
|
-
roughness: .82,
|
|
753
|
-
metalness: .08
|
|
754
|
-
})]
|
|
755
|
-
})]
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
if (triGeo && triVerts) return /* @__PURE__ */ jsxs(RigidBody, {
|
|
759
|
-
type: "fixed",
|
|
760
|
-
colliders: false,
|
|
766
|
+
const rigidBodyProps = useMemo(() => ({ userData }), [userData]);
|
|
767
|
+
if (!bundle && !src) return null;
|
|
768
|
+
return /* @__PURE__ */ jsx(KolmoProp, {
|
|
769
|
+
id: piece.id,
|
|
770
|
+
...bundle ? { bundle } : { src },
|
|
771
|
+
fixed: true,
|
|
761
772
|
position: flt.position,
|
|
762
773
|
quaternion: flt.quaternion,
|
|
763
|
-
|
|
764
|
-
restitution: .1,
|
|
765
|
-
userData,
|
|
766
|
-
children: [/* @__PURE__ */ jsx(ConvexHullCollider, { args: [triVerts] }), /* @__PURE__ */ jsx("mesh", {
|
|
767
|
-
geometry: triGeo,
|
|
768
|
-
castShadow: true,
|
|
769
|
-
receiveShadow: true,
|
|
770
|
-
children: /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
771
|
-
color: "#64748b",
|
|
772
|
-
roughness: .82,
|
|
773
|
-
metalness: .08
|
|
774
|
-
})
|
|
775
|
-
})]
|
|
774
|
+
rigidBodyProps
|
|
776
775
|
});
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
SIDE_METRES * .5,
|
|
788
|
-
STOREY_METRES * .5,
|
|
789
|
-
WALL_THICK * .5
|
|
790
|
-
],
|
|
791
|
-
position: [
|
|
792
|
-
0,
|
|
793
|
-
STOREY_METRES * .5,
|
|
794
|
-
0
|
|
795
|
-
]
|
|
796
|
-
}), /* @__PURE__ */ jsxs("mesh", {
|
|
797
|
-
position: [
|
|
798
|
-
0,
|
|
799
|
-
STOREY_METRES * .5,
|
|
800
|
-
0
|
|
801
|
-
],
|
|
802
|
-
castShadow: true,
|
|
803
|
-
receiveShadow: true,
|
|
804
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
805
|
-
SIDE_METRES,
|
|
806
|
-
STOREY_METRES,
|
|
807
|
-
WALL_THICK
|
|
808
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
809
|
-
color: "#94a3b8",
|
|
810
|
-
roughness: .78,
|
|
811
|
-
metalness: .06
|
|
812
|
-
})]
|
|
813
|
-
})]
|
|
814
|
-
});
|
|
815
|
-
if (piece.kind === "Doorway") {
|
|
816
|
-
const openW = DOOR_HINGE_SPEC.openingWidthM;
|
|
817
|
-
const openH = DOOR_HINGE_SPEC.openingHeightM;
|
|
818
|
-
const jambW = (SIDE_METRES - openW) * .5;
|
|
819
|
-
const lintelH = STOREY_METRES - openH;
|
|
820
|
-
const jambX = openW * .5 + jambW * .5;
|
|
821
|
-
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
822
|
-
type: "fixed",
|
|
823
|
-
colliders: false,
|
|
824
|
-
position: flt.position,
|
|
825
|
-
quaternion: flt.quaternion,
|
|
826
|
-
friction: .6,
|
|
827
|
-
restitution: .1,
|
|
828
|
-
userData,
|
|
829
|
-
children: [
|
|
830
|
-
/* @__PURE__ */ jsx(CuboidCollider, {
|
|
831
|
-
args: [
|
|
832
|
-
jambW * .5,
|
|
833
|
-
openH * .5,
|
|
834
|
-
WALL_THICK * .5
|
|
835
|
-
],
|
|
836
|
-
position: [
|
|
837
|
-
-jambX,
|
|
838
|
-
openH * .5,
|
|
839
|
-
0
|
|
840
|
-
]
|
|
841
|
-
}),
|
|
842
|
-
/* @__PURE__ */ jsx(CuboidCollider, {
|
|
843
|
-
args: [
|
|
844
|
-
jambW * .5,
|
|
845
|
-
openH * .5,
|
|
846
|
-
WALL_THICK * .5
|
|
847
|
-
],
|
|
848
|
-
position: [
|
|
849
|
-
jambX,
|
|
850
|
-
openH * .5,
|
|
851
|
-
0
|
|
852
|
-
]
|
|
853
|
-
}),
|
|
854
|
-
/* @__PURE__ */ jsx(CuboidCollider, {
|
|
855
|
-
args: [
|
|
856
|
-
SIDE_METRES * .5,
|
|
857
|
-
lintelH * .5,
|
|
858
|
-
WALL_THICK * .5
|
|
859
|
-
],
|
|
860
|
-
position: [
|
|
861
|
-
0,
|
|
862
|
-
openH + lintelH * .5,
|
|
863
|
-
0
|
|
864
|
-
]
|
|
865
|
-
}),
|
|
866
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
867
|
-
position: [
|
|
868
|
-
-jambX,
|
|
869
|
-
openH * .5,
|
|
870
|
-
0
|
|
871
|
-
],
|
|
872
|
-
castShadow: true,
|
|
873
|
-
receiveShadow: true,
|
|
874
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
875
|
-
jambW,
|
|
876
|
-
openH,
|
|
877
|
-
WALL_THICK
|
|
878
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
879
|
-
color: "#94a3b8",
|
|
880
|
-
roughness: .78
|
|
881
|
-
})]
|
|
882
|
-
}),
|
|
883
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
884
|
-
position: [
|
|
885
|
-
jambX,
|
|
886
|
-
openH * .5,
|
|
887
|
-
0
|
|
888
|
-
],
|
|
889
|
-
castShadow: true,
|
|
890
|
-
receiveShadow: true,
|
|
891
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
892
|
-
jambW,
|
|
893
|
-
openH,
|
|
894
|
-
WALL_THICK
|
|
895
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
896
|
-
color: "#94a3b8",
|
|
897
|
-
roughness: .78
|
|
898
|
-
})]
|
|
899
|
-
}),
|
|
900
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
901
|
-
position: [
|
|
902
|
-
0,
|
|
903
|
-
openH + lintelH * .5,
|
|
904
|
-
0
|
|
905
|
-
],
|
|
906
|
-
castShadow: true,
|
|
907
|
-
receiveShadow: true,
|
|
908
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
909
|
-
SIDE_METRES,
|
|
910
|
-
lintelH,
|
|
911
|
-
WALL_THICK
|
|
912
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
913
|
-
color: "#94a3b8",
|
|
914
|
-
roughness: .78
|
|
915
|
-
})]
|
|
916
|
-
})
|
|
917
|
-
]
|
|
776
|
+
});
|
|
777
|
+
var _ghostValidMat = null;
|
|
778
|
+
var _ghostInvalidMat = null;
|
|
779
|
+
function getGhostMaterial(valid) {
|
|
780
|
+
if (valid) {
|
|
781
|
+
if (!_ghostValidMat) _ghostValidMat = new THREE.MeshBasicMaterial({
|
|
782
|
+
color: "#34d399",
|
|
783
|
+
transparent: true,
|
|
784
|
+
opacity: .38,
|
|
785
|
+
depthWrite: false
|
|
918
786
|
});
|
|
787
|
+
return _ghostValidMat;
|
|
919
788
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
position: flt.position,
|
|
926
|
-
quaternion: flt.quaternion,
|
|
927
|
-
friction: .85,
|
|
928
|
-
restitution: .05,
|
|
929
|
-
userData,
|
|
930
|
-
children: [/* @__PURE__ */ jsx(CuboidCollider, {
|
|
931
|
-
args: [
|
|
932
|
-
SIDE_METRES * .45,
|
|
933
|
-
SLAB_THICK * .5,
|
|
934
|
-
rampLen * .5
|
|
935
|
-
],
|
|
936
|
-
position: [
|
|
937
|
-
0,
|
|
938
|
-
STOREY_METRES * .5,
|
|
939
|
-
0
|
|
940
|
-
],
|
|
941
|
-
rotation: [
|
|
942
|
-
rampPitch,
|
|
943
|
-
0,
|
|
944
|
-
0
|
|
945
|
-
]
|
|
946
|
-
}), /* @__PURE__ */ jsxs("mesh", {
|
|
947
|
-
position: [
|
|
948
|
-
0,
|
|
949
|
-
STOREY_METRES * .5,
|
|
950
|
-
0
|
|
951
|
-
],
|
|
952
|
-
rotation: [
|
|
953
|
-
rampPitch,
|
|
954
|
-
0,
|
|
955
|
-
0
|
|
956
|
-
],
|
|
957
|
-
castShadow: true,
|
|
958
|
-
receiveShadow: true,
|
|
959
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
960
|
-
SIDE_METRES * .9,
|
|
961
|
-
SLAB_THICK,
|
|
962
|
-
rampLen
|
|
963
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
964
|
-
color: "#cbd5e1",
|
|
965
|
-
roughness: .75
|
|
966
|
-
})]
|
|
967
|
-
})]
|
|
789
|
+
if (!_ghostInvalidMat) _ghostInvalidMat = new THREE.MeshBasicMaterial({
|
|
790
|
+
color: "#ef4444",
|
|
791
|
+
transparent: true,
|
|
792
|
+
opacity: .38,
|
|
793
|
+
depthWrite: false
|
|
968
794
|
});
|
|
795
|
+
return _ghostInvalidMat;
|
|
969
796
|
}
|
|
970
|
-
function
|
|
971
|
-
const
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
SIDE_METRES
|
|
984
|
-
] : [
|
|
985
|
-
SIDE_METRES,
|
|
986
|
-
STOREY_METRES,
|
|
987
|
-
WALL_THICK
|
|
988
|
-
];
|
|
989
|
-
const yCenter = isSlab ? SLAB_THICK * .5 : STOREY_METRES * .5;
|
|
797
|
+
function C12BundleGhostPreview({ candidate, bundle }) {
|
|
798
|
+
const ghostRoot = useMemo(() => bundle.scene.clone(true), [bundle]);
|
|
799
|
+
useEffect(() => {
|
|
800
|
+
const mat = getGhostMaterial(candidate.valid);
|
|
801
|
+
ghostRoot.traverse((child) => {
|
|
802
|
+
const mesh = child;
|
|
803
|
+
if (mesh.isMesh) {
|
|
804
|
+
mesh.material = mat;
|
|
805
|
+
mesh.castShadow = false;
|
|
806
|
+
mesh.receiveShadow = false;
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
}, [ghostRoot, candidate.valid]);
|
|
990
810
|
return /* @__PURE__ */ jsx("group", {
|
|
991
811
|
position: candidate.position,
|
|
992
812
|
quaternion: candidate.quaternion,
|
|
993
|
-
children:
|
|
994
|
-
geometry: triGeo,
|
|
995
|
-
children: /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
996
|
-
color,
|
|
997
|
-
transparent: true,
|
|
998
|
-
opacity: .36,
|
|
999
|
-
depthWrite: false
|
|
1000
|
-
})
|
|
1001
|
-
}) : /* @__PURE__ */ jsxs("mesh", {
|
|
1002
|
-
position: [
|
|
1003
|
-
0,
|
|
1004
|
-
yCenter,
|
|
1005
|
-
0
|
|
1006
|
-
],
|
|
1007
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: dims }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
1008
|
-
color,
|
|
1009
|
-
transparent: true,
|
|
1010
|
-
opacity: .36,
|
|
1011
|
-
depthWrite: false
|
|
1012
|
-
})]
|
|
1013
|
-
})
|
|
813
|
+
children: /* @__PURE__ */ jsx("primitive", { object: ghostRoot })
|
|
1014
814
|
});
|
|
1015
815
|
}
|
|
1016
|
-
function
|
|
1017
|
-
const
|
|
1018
|
-
return /* @__PURE__ */
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
.032,
|
|
1023
|
-
-.04
|
|
1024
|
-
],
|
|
1025
|
-
castShadow: true,
|
|
1026
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
1027
|
-
.056,
|
|
1028
|
-
.062,
|
|
1029
|
-
.22
|
|
1030
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1031
|
-
color: skin.bodyHex,
|
|
1032
|
-
metalness: skin.metalness,
|
|
1033
|
-
roughness: skin.roughness
|
|
1034
|
-
})]
|
|
1035
|
-
}),
|
|
1036
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1037
|
-
position: [
|
|
1038
|
-
0,
|
|
1039
|
-
.038,
|
|
1040
|
-
-.2
|
|
1041
|
-
],
|
|
1042
|
-
rotation: [
|
|
1043
|
-
Math.PI / 2,
|
|
1044
|
-
0,
|
|
1045
|
-
0
|
|
1046
|
-
],
|
|
1047
|
-
castShadow: true,
|
|
1048
|
-
children: [/* @__PURE__ */ jsx("cylinderGeometry", { args: [
|
|
1049
|
-
.014,
|
|
1050
|
-
.018,
|
|
1051
|
-
.14,
|
|
1052
|
-
12
|
|
1053
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1054
|
-
color: skin.accentHex,
|
|
1055
|
-
emissive: skin.emissiveHex,
|
|
1056
|
-
emissiveIntensity: .6,
|
|
1057
|
-
metalness: .8,
|
|
1058
|
-
roughness: .2
|
|
1059
|
-
})]
|
|
1060
|
-
}),
|
|
1061
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1062
|
-
position: [
|
|
1063
|
-
0,
|
|
1064
|
-
-.042,
|
|
1065
|
-
.03
|
|
1066
|
-
],
|
|
1067
|
-
rotation: [
|
|
1068
|
-
.24,
|
|
1069
|
-
0,
|
|
1070
|
-
0
|
|
1071
|
-
],
|
|
1072
|
-
castShadow: true,
|
|
1073
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
1074
|
-
.042,
|
|
1075
|
-
.11,
|
|
1076
|
-
.048
|
|
1077
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1078
|
-
color: "#0f172a",
|
|
1079
|
-
roughness: .75,
|
|
1080
|
-
metalness: .2
|
|
1081
|
-
})]
|
|
1082
|
-
}),
|
|
1083
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1084
|
-
position: [
|
|
1085
|
-
0,
|
|
1086
|
-
.052,
|
|
1087
|
-
.072
|
|
1088
|
-
],
|
|
1089
|
-
children: [/* @__PURE__ */ jsx("planeGeometry", { args: [.064, .048] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
1090
|
-
...lcdTexture ? { map: lcdTexture } : { color: skin.accentHex },
|
|
1091
|
-
toneMapped: false
|
|
1092
|
-
})]
|
|
1093
|
-
})
|
|
1094
|
-
] });
|
|
816
|
+
function C12UrlGhostPreview({ candidate, src }) {
|
|
817
|
+
const bundle = useKhrGlb(src);
|
|
818
|
+
return /* @__PURE__ */ jsx(C12BundleGhostPreview, {
|
|
819
|
+
candidate,
|
|
820
|
+
bundle
|
|
821
|
+
});
|
|
1095
822
|
}
|
|
1096
823
|
var _camPos = new THREE.Vector3();
|
|
1097
824
|
var _camDir = new THREE.Vector3();
|
|
1098
825
|
var _muzzleWorld = new THREE.Vector3();
|
|
1099
826
|
var _beamEndVec = new THREE.Vector3();
|
|
1100
827
|
var _targetOffset = new THREE.Vector3();
|
|
1101
|
-
function ToolgunCore({ ref, viewmodelBundle, actorRef,
|
|
828
|
+
function ToolgunCore({ ref, viewmodelBundle, c12Bundles, c12Urls, actorRef, accentColor = DEFAULT_ACCENT_HEX, defaultArmedAsset, maxRangeM = 75, hipOffset = [
|
|
1102
829
|
.24,
|
|
1103
830
|
-.21,
|
|
1104
831
|
-.42
|
|
@@ -1107,20 +834,27 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1107
834
|
-.055,
|
|
1108
835
|
-.22
|
|
1109
836
|
], enableShortcuts = true, mountWorldOutlets = true, enable = true }) {
|
|
837
|
+
const resolvedC12Urls = useMemo(() => c12Urls === null ? {} : {
|
|
838
|
+
...DEFAULT_VAULT_C12_URLS,
|
|
839
|
+
...c12Urls
|
|
840
|
+
}, [c12Urls]);
|
|
1110
841
|
const { rapier, world: rapierWorld } = useRapier();
|
|
1111
842
|
const camera = useThree((s) => s.camera);
|
|
1112
843
|
const gl = useThree((s) => s.gl);
|
|
1113
844
|
const kootaWorld = useActiveKolmoWorld();
|
|
845
|
+
const { mode: controlMode } = useKolmoGame(kootaWorld);
|
|
846
|
+
const isPiloted = controlMode !== "foot";
|
|
1114
847
|
const jointRegistry = useContext(JointRegistryContext);
|
|
1115
848
|
const mode = useToolgunStore((s) => s.mode);
|
|
1116
|
-
const storeSkin = useToolgunStore((s) => s.skinPreset);
|
|
1117
849
|
const buildPreview = useToolgunStore((s) => s.buildPreview);
|
|
1118
850
|
const spawnedEntities = useToolgunStore((s) => s.spawnedEntities);
|
|
1119
851
|
const placedPieces = useToolgunStore((s) => s.placedPieces);
|
|
1120
|
-
const effSkin = skinProp ?? storeSkin;
|
|
1121
852
|
useEffect(() => {
|
|
1122
853
|
if (defaultArmedAsset && !useToolgunStore.getState().armedAsset) useToolgunStore.getState().armAsset(defaultArmedAsset);
|
|
1123
854
|
}, [defaultArmedAsset]);
|
|
855
|
+
useEffect(() => () => {
|
|
856
|
+
useToolgunStore.getState().clearWorldHandles(rapierWorld);
|
|
857
|
+
}, [rapierWorld]);
|
|
1124
858
|
const measured = useMemo(() => viewmodelBundle ? measureToolgunViewmodel(viewmodelBundle.scene) : null, [viewmodelBundle]);
|
|
1125
859
|
const lcd = useMemo(createLcdSurface, []);
|
|
1126
860
|
useEffect(() => () => lcd.dispose(), [lcd]);
|
|
@@ -1128,6 +862,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1128
862
|
const recoilRef = useRef(0);
|
|
1129
863
|
const beamTimerRef = useRef(0);
|
|
1130
864
|
const beamMatRef = useRef(null);
|
|
865
|
+
const rayScratchRef = useRef(null);
|
|
1131
866
|
const beamGeo = useMemo(() => {
|
|
1132
867
|
const g = new THREE.BufferGeometry();
|
|
1133
868
|
g.setAttribute("position", new THREE.Float32BufferAttribute([
|
|
@@ -1142,7 +877,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1142
877
|
}, []);
|
|
1143
878
|
const beamLine = useMemo(() => {
|
|
1144
879
|
const mat = new THREE.LineBasicMaterial({
|
|
1145
|
-
color:
|
|
880
|
+
color: accentColor,
|
|
1146
881
|
transparent: true,
|
|
1147
882
|
opacity: 0,
|
|
1148
883
|
depthTest: false
|
|
@@ -1152,15 +887,19 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1152
887
|
line.frustumCulled = false;
|
|
1153
888
|
line.visible = false;
|
|
1154
889
|
return line;
|
|
1155
|
-
}, [beamGeo]);
|
|
890
|
+
}, [beamGeo, accentColor]);
|
|
1156
891
|
useEffect(() => () => {
|
|
1157
|
-
beamGeo.dispose();
|
|
1158
892
|
beamMatRef.current?.dispose();
|
|
1159
|
-
}, [
|
|
893
|
+
}, [beamLine]);
|
|
894
|
+
useEffect(() => () => beamGeo.dispose(), [beamGeo]);
|
|
1160
895
|
const resolvePlayerBody = useCallback(() => {
|
|
1161
|
-
|
|
1162
|
-
return
|
|
1163
|
-
}, [
|
|
896
|
+
const raw = actorRef?.current?.body ?? kootaWorld.queryFirst(ActorTrait)?.get(ActorTrait)?.handle?.body ?? null;
|
|
897
|
+
return raw ? rapierWorld.getRigidBody(raw.handle) : null;
|
|
898
|
+
}, [
|
|
899
|
+
actorRef,
|
|
900
|
+
kootaWorld,
|
|
901
|
+
rapierWorld
|
|
902
|
+
]);
|
|
1164
903
|
const findJointForBody = useCallback((body) => {
|
|
1165
904
|
if (!body || !jointRegistry) return null;
|
|
1166
905
|
for (const rt of jointRegistry) if (!rt.detached && rt.childBody?.handle === body.handle) return rt;
|
|
@@ -1171,50 +910,43 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1171
910
|
camera.getWorldDirection(_camDir);
|
|
1172
911
|
const st = useToolgunStore.getState();
|
|
1173
912
|
const playerBody = resolvePlayerBody();
|
|
1174
|
-
const rawHit = castToolgunRay(rapier, rapierWorld,
|
|
1175
|
-
|
|
1176
|
-
_camPos.
|
|
1177
|
-
_camPos.
|
|
1178
|
-
|
|
1179
|
-
_camDir.x,
|
|
1180
|
-
_camDir.y,
|
|
1181
|
-
_camDir.z
|
|
1182
|
-
], maxRangeM, playerBody);
|
|
1183
|
-
let fallbackPoint = [
|
|
1184
|
-
_camPos.x + _camDir.x * 5,
|
|
1185
|
-
Math.max(0, _camPos.y + _camDir.y * 5),
|
|
1186
|
-
_camPos.z + _camDir.z * 5
|
|
1187
|
-
];
|
|
1188
|
-
if (_camDir.y < -.02 && _camPos.y > 0) {
|
|
1189
|
-
const tGround = -_camPos.y / _camDir.y;
|
|
1190
|
-
if (tGround > .1 && tGround <= maxRangeM) fallbackPoint = [
|
|
1191
|
-
_camPos.x + _camDir.x * tGround,
|
|
1192
|
-
0,
|
|
1193
|
-
_camPos.z + _camDir.z * tGround
|
|
1194
|
-
];
|
|
1195
|
-
}
|
|
1196
|
-
const aimPoint = rawHit ? rawHit.point : fallbackPoint;
|
|
1197
|
-
const aimNormal = rawHit ? rawHit.normal : [
|
|
1198
|
-
0,
|
|
1199
|
-
1,
|
|
1200
|
-
0
|
|
913
|
+
const rawHit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody);
|
|
914
|
+
const missEnd = [
|
|
915
|
+
_camPos.x + _camDir.x * maxRangeM,
|
|
916
|
+
_camPos.y + _camDir.y * maxRangeM,
|
|
917
|
+
_camPos.z + _camDir.z * maxRangeM
|
|
1201
918
|
];
|
|
919
|
+
const aimPoint = rawHit ? rawHit.point : missEnd;
|
|
1202
920
|
recoilRef.current = 1;
|
|
1203
921
|
beamTimerRef.current = .09;
|
|
1204
922
|
_beamEndVec.set(aimPoint[0], aimPoint[1], aimPoint[2]);
|
|
1205
|
-
if (holderRef.current) {
|
|
1206
|
-
const mLocal = measured
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
-.26
|
|
1210
|
-
];
|
|
1211
|
-
_muzzleWorld.set(mLocal[0], mLocal[1], mLocal[2]).applyMatrix4(holderRef.current.matrixWorld);
|
|
923
|
+
if (holderRef.current && measured) {
|
|
924
|
+
const mLocal = measured.muzzleLocal;
|
|
925
|
+
const gOff = measured.gripOffset;
|
|
926
|
+
_muzzleWorld.set(mLocal[0] + gOff[0], mLocal[1] + gOff[1], mLocal[2] + gOff[2]).applyMatrix4(holderRef.current.matrixWorld);
|
|
1212
927
|
} else _muzzleWorld.copy(_camPos).addScaledVector(_camDir, .35);
|
|
1213
928
|
const posAttr = beamGeo.getAttribute("position");
|
|
1214
929
|
posAttr.setXYZ(0, _muzzleWorld.x, _muzzleWorld.y, _muzzleWorld.z);
|
|
1215
930
|
posAttr.setXYZ(1, _beamEndVec.x, _beamEndVec.y, _beamEndVec.z);
|
|
1216
931
|
posAttr.needsUpdate = true;
|
|
1217
932
|
beamLine.visible = true;
|
|
933
|
+
if (!rawHit) {
|
|
934
|
+
if (st.mode === "weld" || st.mode === "hinge") {
|
|
935
|
+
st.setPendingAnchor(null);
|
|
936
|
+
st.bumpFire("MISS — CLEARED ANCHOR");
|
|
937
|
+
return {
|
|
938
|
+
ok: false,
|
|
939
|
+
status: "MISS — CLEARED ANCHOR",
|
|
940
|
+
beamEnd: missEnd
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
st.bumpFire("NO SURFACE HIT");
|
|
944
|
+
return {
|
|
945
|
+
ok: false,
|
|
946
|
+
status: "NO SURFACE HIT",
|
|
947
|
+
beamEnd: missEnd
|
|
948
|
+
};
|
|
949
|
+
}
|
|
1218
950
|
if (st.mode === "spawn") {
|
|
1219
951
|
const asset = st.armedAsset;
|
|
1220
952
|
if (!asset || !asset.bundle && !asset.src) {
|
|
@@ -1222,10 +954,10 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1222
954
|
return {
|
|
1223
955
|
ok: false,
|
|
1224
956
|
status: "NO ASSET ARMED",
|
|
1225
|
-
beamEnd:
|
|
957
|
+
beamEnd: rawHit.point
|
|
1226
958
|
};
|
|
1227
959
|
}
|
|
1228
|
-
const pose = computeAlignedSpawnPose(
|
|
960
|
+
const pose = computeAlignedSpawnPose(rawHit.point, st.yaw12, rawHit.normal, .08);
|
|
1229
961
|
const isVehicle = asset.kind === "vehicle" || asset.kind !== "prop" && Boolean(asset.bundle && (asset.bundle.wheels.length > 0 || asset.bundle.propellers.length > 0));
|
|
1230
962
|
const id = `tg_ent_${Date.now().toString(36)}_${st.fireCount}`;
|
|
1231
963
|
st.recordSpawn({
|
|
@@ -1241,11 +973,19 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1241
973
|
return {
|
|
1242
974
|
ok: true,
|
|
1243
975
|
status: `SPAWNED ${asset.name}`,
|
|
1244
|
-
beamEnd:
|
|
976
|
+
beamEnd: rawHit.point
|
|
1245
977
|
};
|
|
1246
978
|
}
|
|
1247
979
|
if (st.mode === "build") {
|
|
1248
|
-
|
|
980
|
+
if (mountWorldOutlets && !c12Bundles?.[st.buildKind] && !resolvedC12Urls[st.buildKind]) {
|
|
981
|
+
st.bumpFire(`MISSING ${st.buildKind} GLB`);
|
|
982
|
+
return {
|
|
983
|
+
ok: false,
|
|
984
|
+
status: `MISSING ${st.buildKind} GLB`,
|
|
985
|
+
beamEnd: rawHit.point
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
const candidate = computeBuildCandidate(st.placedPieces, rawHit.point, st.buildKind, st.yaw12);
|
|
1249
989
|
const placed = st.placeBuildPiece(candidate);
|
|
1250
990
|
return {
|
|
1251
991
|
ok: placed !== null,
|
|
@@ -1254,13 +994,13 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1254
994
|
};
|
|
1255
995
|
}
|
|
1256
996
|
if (st.mode === "rig") {
|
|
1257
|
-
const hitJoint = findJointForBody(rawHit
|
|
997
|
+
const hitJoint = findJointForBody(rawHit.body);
|
|
1258
998
|
if (!hitJoint) {
|
|
1259
999
|
st.bumpFire("NO KHR JOINT HIT");
|
|
1260
1000
|
return {
|
|
1261
1001
|
ok: false,
|
|
1262
1002
|
status: "NO KHR JOINT HIT",
|
|
1263
|
-
beamEnd:
|
|
1003
|
+
beamEnd: rawHit.point
|
|
1264
1004
|
};
|
|
1265
1005
|
}
|
|
1266
1006
|
const status = rigJointRuntime(hitJoint, shiftKey);
|
|
@@ -1268,23 +1008,25 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1268
1008
|
return {
|
|
1269
1009
|
ok: true,
|
|
1270
1010
|
status,
|
|
1271
|
-
beamEnd:
|
|
1011
|
+
beamEnd: rawHit.point
|
|
1272
1012
|
};
|
|
1273
1013
|
}
|
|
1274
1014
|
if (st.mode === "weld" || st.mode === "hinge") {
|
|
1275
|
-
if (!rawHit
|
|
1015
|
+
if (!rawHit.body) {
|
|
1276
1016
|
st.setPendingAnchor(null);
|
|
1277
1017
|
st.bumpFire("MISS — CLEARED ANCHOR");
|
|
1278
1018
|
return {
|
|
1279
1019
|
ok: false,
|
|
1280
1020
|
status: "MISS — CLEARED ANCHOR",
|
|
1281
|
-
beamEnd:
|
|
1021
|
+
beamEnd: rawHit.point
|
|
1282
1022
|
};
|
|
1283
1023
|
}
|
|
1284
1024
|
const pending = st.pendingAnchor;
|
|
1285
|
-
|
|
1025
|
+
const liveBodyA = pending && pending.world === rapierWorld ? rapierWorld.getRigidBody(pending.body.handle) : null;
|
|
1026
|
+
if (!pending || !liveBodyA) {
|
|
1286
1027
|
const label = rawHit.body.userData?.name ?? `body_${rawHit.body.handle}`;
|
|
1287
1028
|
st.setPendingAnchor({
|
|
1029
|
+
world: rapierWorld,
|
|
1288
1030
|
body: rawHit.body,
|
|
1289
1031
|
worldPoint: rawHit.point,
|
|
1290
1032
|
worldNormal: rawHit.normal,
|
|
@@ -1294,16 +1036,16 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1294
1036
|
return {
|
|
1295
1037
|
ok: true,
|
|
1296
1038
|
status: `LOCKED A: ${label}`,
|
|
1297
|
-
beamEnd:
|
|
1039
|
+
beamEnd: rawHit.point
|
|
1298
1040
|
};
|
|
1299
1041
|
}
|
|
1300
|
-
if (
|
|
1042
|
+
if (liveBodyA.handle === rawHit.body.handle) {
|
|
1301
1043
|
st.setPendingAnchor(null);
|
|
1302
1044
|
st.bumpFire("SAME BODY — CANCELLED");
|
|
1303
1045
|
return {
|
|
1304
1046
|
ok: false,
|
|
1305
1047
|
status: "SAME BODY — CANCELLED",
|
|
1306
|
-
beamEnd:
|
|
1048
|
+
beamEnd: rawHit.point
|
|
1307
1049
|
};
|
|
1308
1050
|
}
|
|
1309
1051
|
const anchorMid = [
|
|
@@ -1311,11 +1053,12 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1311
1053
|
.5 * (pending.worldPoint[1] + rawHit.point[1]),
|
|
1312
1054
|
.5 * (pending.worldPoint[2] + rawHit.point[2])
|
|
1313
1055
|
];
|
|
1314
|
-
const imp = st.mode === "weld" ? createWeldImpulseJoint(rapier, rapierWorld,
|
|
1056
|
+
const imp = st.mode === "weld" ? createWeldImpulseJoint(rapier, rapierWorld, liveBodyA, rawHit.body, anchorMid) : createHingeImpulseJoint(rapier, rapierWorld, liveBodyA, rawHit.body, anchorMid, pending.worldNormal);
|
|
1315
1057
|
const id = `tg_${st.mode}_${imp.handle}`;
|
|
1316
1058
|
st.recordJoint({
|
|
1317
1059
|
id,
|
|
1318
1060
|
kind: st.mode,
|
|
1061
|
+
world: rapierWorld,
|
|
1319
1062
|
handle: imp.handle,
|
|
1320
1063
|
joint: imp,
|
|
1321
1064
|
anchorWorld: anchorMid
|
|
@@ -1326,38 +1069,30 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1326
1069
|
beamEnd: anchorMid
|
|
1327
1070
|
};
|
|
1328
1071
|
}
|
|
1329
|
-
if (!rawHit) {
|
|
1330
|
-
st.bumpFire("NOTHING HIT");
|
|
1331
|
-
return {
|
|
1332
|
-
ok: false,
|
|
1333
|
-
status: "NOTHING HIT",
|
|
1334
|
-
beamEnd: aimPoint
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
1072
|
const ud = rawHit.body?.userData ?? {};
|
|
1338
1073
|
if (ud.kolmoPlacedPieceId && st.removePieceById(ud.kolmoPlacedPieceId)) return {
|
|
1339
1074
|
ok: true,
|
|
1340
1075
|
status: `REMOVED ${ud.kolmoPlacedPieceId}`,
|
|
1341
|
-
beamEnd:
|
|
1076
|
+
beamEnd: rawHit.point
|
|
1342
1077
|
};
|
|
1343
|
-
if (ud.kolmoSpawnedId && st.removeEntityById(ud.kolmoSpawnedId)) return {
|
|
1078
|
+
if (ud.kolmoSpawnedId && st.removeEntityById(ud.kolmoSpawnedId, rapierWorld)) return {
|
|
1344
1079
|
ok: true,
|
|
1345
1080
|
status: `DELETED ${ud.kolmoSpawnedId}`,
|
|
1346
|
-
beamEnd:
|
|
1081
|
+
beamEnd: rawHit.point
|
|
1347
1082
|
};
|
|
1348
1083
|
if (rawHit.body) {
|
|
1349
1084
|
const removedJoints = st.removeJointByBody(rapierWorld, rawHit.body);
|
|
1350
1085
|
if (removedJoints > 0) return {
|
|
1351
1086
|
ok: true,
|
|
1352
1087
|
status: `REMOVED ${removedJoints} JOINT(S)`,
|
|
1353
|
-
beamEnd:
|
|
1088
|
+
beamEnd: rawHit.point
|
|
1354
1089
|
};
|
|
1355
1090
|
}
|
|
1356
1091
|
st.bumpFire("STATIC WORLD TARGET");
|
|
1357
1092
|
return {
|
|
1358
1093
|
ok: false,
|
|
1359
1094
|
status: "STATIC WORLD TARGET",
|
|
1360
|
-
beamEnd:
|
|
1095
|
+
beamEnd: rawHit.point
|
|
1361
1096
|
};
|
|
1362
1097
|
}, [
|
|
1363
1098
|
camera,
|
|
@@ -1368,7 +1103,10 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1368
1103
|
findJointForBody,
|
|
1369
1104
|
measured,
|
|
1370
1105
|
beamGeo,
|
|
1371
|
-
beamLine
|
|
1106
|
+
beamLine,
|
|
1107
|
+
mountWorldOutlets,
|
|
1108
|
+
c12Bundles,
|
|
1109
|
+
resolvedC12Urls
|
|
1372
1110
|
]);
|
|
1373
1111
|
useImperativeHandle(ref, () => ({
|
|
1374
1112
|
fire,
|
|
@@ -1382,8 +1120,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1382
1120
|
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || Boolean(el.isContentEditable);
|
|
1383
1121
|
};
|
|
1384
1122
|
const onKeyDown = (e) => {
|
|
1385
|
-
if (isEditable(document.activeElement)) return;
|
|
1386
|
-
if (kootaWorld.queryFirst(pilotedVehicleQuery)) return;
|
|
1123
|
+
if (isEditable(document.activeElement) || kootaWorld.queryFirst(pilotedVehicleQuery)) return;
|
|
1387
1124
|
const st = useToolgunStore.getState();
|
|
1388
1125
|
if (e.code >= "Digit1" && e.code <= "Digit6") {
|
|
1389
1126
|
const idx = Number(e.code.slice(5)) - 1;
|
|
@@ -1464,38 +1201,18 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1464
1201
|
camera.getWorldPosition(_camPos);
|
|
1465
1202
|
camera.getWorldDirection(_camDir);
|
|
1466
1203
|
const playerBody = resolvePlayerBody();
|
|
1467
|
-
const hit = castToolgunRay(rapier, rapierWorld,
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
_camPos.z
|
|
1471
|
-
], [
|
|
1472
|
-
_camDir.x,
|
|
1473
|
-
_camDir.y,
|
|
1474
|
-
_camDir.z
|
|
1475
|
-
], maxRangeM, playerBody);
|
|
1204
|
+
const hit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody, rayScratchRef.current ?? void 0);
|
|
1205
|
+
if (hit && !rayScratchRef.current) rayScratchRef.current = hit;
|
|
1206
|
+
else if (!hit && rayScratchRef.current) rayScratchRef.current.body = null;
|
|
1476
1207
|
let targetLabel = "NO TARGET";
|
|
1477
1208
|
if (hit) {
|
|
1478
1209
|
const jRt = findJointForBody(hit.body);
|
|
1479
1210
|
const ud = hit.body?.userData ?? {};
|
|
1480
1211
|
targetLabel = `${jRt ? `JOINT:${jRt.nodeName}` : ud.name ?? ud.kolmoPlacedPieceId ?? ud.kolmoSpawnedId ?? "SURFACE"} (${hit.toi.toFixed(1)}m)`;
|
|
1481
1212
|
}
|
|
1482
|
-
if (st.mode === "build") {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
Math.max(0, _camPos.y + _camDir.y * 5),
|
|
1486
|
-
_camPos.z + _camDir.z * 5
|
|
1487
|
-
];
|
|
1488
|
-
if (!hit && _camDir.y < -.02 && _camPos.y > 0) {
|
|
1489
|
-
const tFloor = -_camPos.y / _camDir.y;
|
|
1490
|
-
if (tFloor > .1 && tFloor <= maxRangeM) fallbackPt = [
|
|
1491
|
-
_camPos.x + _camDir.x * tFloor,
|
|
1492
|
-
0,
|
|
1493
|
-
_camPos.z + _camDir.z * tFloor
|
|
1494
|
-
];
|
|
1495
|
-
}
|
|
1496
|
-
const cand = computeBuildCandidate(st.placedPieces, hit ? hit.point : fallbackPt, st.buildKind, st.yaw12);
|
|
1497
|
-
const prev = st.buildPreview;
|
|
1498
|
-
if (!prev || prev.kind !== cand.kind || prev.valid !== cand.valid || Math.abs(prev.position[0] - cand.position[0]) > 1e-4 || Math.abs(prev.position[1] - cand.position[1]) > 1e-4 || Math.abs(prev.position[2] - cand.position[2]) > 1e-4 || Math.abs(prev.quaternion[1] - cand.quaternion[1]) > 1e-4) st.setBuildPreview(cand);
|
|
1213
|
+
if (st.mode === "build" && hit) {
|
|
1214
|
+
const cand = computeBuildCandidate(st.placedPieces, hit.point, st.buildKind, st.yaw12);
|
|
1215
|
+
if (!isSameBuildPreview(st.buildPreview, cand)) st.setBuildPreview(cand);
|
|
1499
1216
|
} else if (st.buildPreview !== null) st.setBuildPreview(null);
|
|
1500
1217
|
const detail = st.mode === "build" ? st.buildKind : st.mode === "spawn" ? st.armedAsset?.name ?? "UNARMED" : st.pendingAnchor ? `A: ${st.pendingAnchor.label}` : `${st.mode.toUpperCase()} READY`;
|
|
1501
1218
|
lcd.draw({
|
|
@@ -1504,58 +1221,59 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1504
1221
|
detail,
|
|
1505
1222
|
targetLabel,
|
|
1506
1223
|
status: st.statusText,
|
|
1507
|
-
|
|
1224
|
+
accentColor
|
|
1508
1225
|
});
|
|
1509
1226
|
});
|
|
1510
|
-
const
|
|
1227
|
+
const ghostBundle = buildPreview ? c12Bundles?.[buildPreview.kind] : void 0;
|
|
1228
|
+
const ghostUrl = buildPreview && !ghostBundle ? resolvedC12Urls[buildPreview.kind] : void 0;
|
|
1511
1229
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1512
|
-
createPortal(/* @__PURE__ */ jsx("group", {
|
|
1230
|
+
measured && createPortal(/* @__PURE__ */ jsx("group", {
|
|
1513
1231
|
ref: holderRef,
|
|
1514
1232
|
position: [
|
|
1515
1233
|
hipOffset[0],
|
|
1516
1234
|
hipOffset[1],
|
|
1517
1235
|
hipOffset[2]
|
|
1518
1236
|
],
|
|
1519
|
-
children:
|
|
1237
|
+
children: /* @__PURE__ */ jsxs("group", {
|
|
1520
1238
|
position: measured.gripOffset,
|
|
1521
|
-
children: [/* @__PURE__ */ jsx("primitive", { object: measured.scene }), /* @__PURE__ */ jsxs("mesh", {
|
|
1522
|
-
position: measured.
|
|
1523
|
-
quaternion: measured.
|
|
1524
|
-
children: [/* @__PURE__ */ jsx("planeGeometry", { args: measured.
|
|
1525
|
-
...lcd.texture ? { map: lcd.texture } : { color:
|
|
1239
|
+
children: [/* @__PURE__ */ jsx("primitive", { object: measured.scene }), measured.screen && /* @__PURE__ */ jsxs("mesh", {
|
|
1240
|
+
position: measured.screen.pos,
|
|
1241
|
+
quaternion: measured.screen.quat,
|
|
1242
|
+
children: [/* @__PURE__ */ jsx("planeGeometry", { args: measured.screen.size }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
1243
|
+
...lcd.texture ? { map: lcd.texture } : { color: accentColor },
|
|
1526
1244
|
toneMapped: false
|
|
1527
1245
|
})]
|
|
1528
1246
|
})]
|
|
1529
|
-
}) : /* @__PURE__ */ jsx(ProceduralToolgunBody, {
|
|
1530
|
-
skinPreset: effSkin,
|
|
1531
|
-
lcdTexture: lcd.texture
|
|
1532
1247
|
})
|
|
1533
1248
|
}), camera),
|
|
1534
1249
|
/* @__PURE__ */ jsx("primitive", { object: beamLine }),
|
|
1535
|
-
enable && !isPiloted && mode === "build" && buildPreview && /* @__PURE__ */ jsx(
|
|
1250
|
+
enable && !isPiloted && mode === "build" && buildPreview && (ghostBundle ? /* @__PURE__ */ jsx(C12BundleGhostPreview, {
|
|
1251
|
+
candidate: buildPreview,
|
|
1252
|
+
bundle: ghostBundle
|
|
1253
|
+
}) : ghostUrl ? /* @__PURE__ */ jsx(React.Suspense, {
|
|
1254
|
+
fallback: null,
|
|
1255
|
+
children: /* @__PURE__ */ jsx(C12UrlGhostPreview, {
|
|
1256
|
+
candidate: buildPreview,
|
|
1257
|
+
src: ghostUrl
|
|
1258
|
+
})
|
|
1259
|
+
}) : null),
|
|
1536
1260
|
mountWorldOutlets && /* @__PURE__ */ jsxs("group", {
|
|
1537
1261
|
name: "kolmo_toolgun_outlets",
|
|
1538
|
-
children: [spawnedEntities.map((entry) =>
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
quaternion: entry.quaternion,
|
|
1554
|
-
rigidBodyProps: { userData: {
|
|
1555
|
-
kolmoSpawnedId: entry.id,
|
|
1556
|
-
name: entry.name
|
|
1557
|
-
} }
|
|
1558
|
-
}, entry.id)), placedPieces.map((piece) => /* @__PURE__ */ jsx(C12PieceColliderAndMesh, { piece }, piece.id))]
|
|
1262
|
+
children: [spawnedEntities.map((entry) => /* @__PURE__ */ jsx(React.Suspense, {
|
|
1263
|
+
fallback: null,
|
|
1264
|
+
children: /* @__PURE__ */ jsx(SpawnedToolgunOutlet, { entry })
|
|
1265
|
+
}, entry.id)), placedPieces.map((piece) => {
|
|
1266
|
+
const b = c12Bundles?.[piece.kind];
|
|
1267
|
+
const u = b ? void 0 : resolvedC12Urls[piece.kind];
|
|
1268
|
+
return b || u ? /* @__PURE__ */ jsx(React.Suspense, {
|
|
1269
|
+
fallback: null,
|
|
1270
|
+
children: /* @__PURE__ */ jsx(PlacedC12Outlet, {
|
|
1271
|
+
piece,
|
|
1272
|
+
bundle: b,
|
|
1273
|
+
src: u
|
|
1274
|
+
})
|
|
1275
|
+
}, piece.id) : null;
|
|
1276
|
+
})]
|
|
1559
1277
|
})
|
|
1560
1278
|
] });
|
|
1561
1279
|
}
|
|
@@ -1577,6 +1295,6 @@ function KolmoToolgun({ src, bundle, ...rest }) {
|
|
|
1577
1295
|
viewmodelBundle: cloned
|
|
1578
1296
|
});
|
|
1579
1297
|
}
|
|
1580
|
-
export {
|
|
1298
|
+
export { TOOLGUN_MODES as a, computeBuildCandidate as c, createWeldImpulseJoint as d, isSameBuildPreview as f, TOOLGUN_BUILD_KINDS as i, createHingeImpulseJoint as l, useToolgunStore as m, KolmoToolgun as n, castToolgunRay as o, rigJointRuntime as p, measureToolgunViewmodel as r, computeAlignedSpawnPose as s, DEFAULT_VAULT_C12_URLS as t, createToolgunStore as u };
|
|
1581
1299
|
|
|
1582
|
-
//# sourceMappingURL=toolgun-
|
|
1300
|
+
//# sourceMappingURL=toolgun-COu_5SxS.js.map
|