@pinkaphant/kolmo 0.5.1 → 0.5.2
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/dist/engine/index.js +80 -437
- package/dist/engine/index.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/physics/index.js +1 -1
- package/dist/{physics-ZDFXaCli.js → physics-CA1abDCY.js} +8 -7
- package/dist/physics-CA1abDCY.js.map +1 -0
- package/dist/toolgun/Toolgun.d.ts +7 -3
- package/dist/toolgun/c12Outlets.d.ts +36 -0
- package/dist/toolgun/index.d.ts +1 -1
- package/dist/toolgun/index.js +1 -1
- package/dist/toolgun/store.d.ts +25 -75
- package/dist/{toolgun-BfcCIAQx.js → toolgun-CFCNO00q.js} +597 -539
- package/dist/toolgun-CFCNO00q.js.map +1 -0
- package/dist/{surface-DUol_5ml.js → world-BljtS6Fb.js} +419 -9
- package/dist/world-BljtS6Fb.js.map +1 -0
- package/package.json +5 -5
- 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 { DOOR_HINGE_SPEC, SIDE_METRES, STEP_METRES, STOREY_METRES, canPlace, latticePose, poseToFloat, snapPose, socketFor, triangleCorners, worldSockets, wrapYaw } from "@khr3/c12";
|
|
5
|
-
import { useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
3
|
+
import { JointRegistryContext, cloneKhrBundle, isJointOpen, toggleDrivenJoint, useKhrGlb } from "@khr3/core";
|
|
4
|
+
import { DOOR_HINGE_SPEC, SIDE_METRES, STEP_METRES, STOREY_METRES, canPlace, latticePose, poseEq, poseToFloat, snapPose, socketFor, triangleCorners, 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
7
|
import { ConvexHullCollider, CuboidCollider, RigidBody, useRapier } from "@react-three/rapier";
|
|
8
8
|
import { easing } from "maath";
|
|
9
|
-
import { D as useActiveKolmoWorld, E as pilotedVehicleQuery, d as ActorTrait
|
|
10
|
-
import {
|
|
9
|
+
import { D as useActiveKolmoWorld, E as pilotedVehicleQuery, d as ActorTrait } from "./physics-CA1abDCY.js";
|
|
10
|
+
import { c as useKolmoGame, d as KolmoVehicle, l as KolmoProp } from "./world-BljtS6Fb.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,
|
|
@@ -523,15 +557,361 @@ function createToolgunStore() {
|
|
|
523
557
|
}));
|
|
524
558
|
}
|
|
525
559
|
var useToolgunStore = createToolgunStore();
|
|
560
|
+
// src/toolgun/c12Outlets.tsx
|
|
561
|
+
var WALL_THICK = .2;
|
|
562
|
+
var SLAB_THICK = .2;
|
|
563
|
+
var OPEN_W = DOOR_HINGE_SPEC.openingWidthM;
|
|
564
|
+
var OPEN_H = DOOR_HINGE_SPEC.openingHeightM;
|
|
565
|
+
var JAMB_W = (SIDE_METRES - OPEN_W) * .5;
|
|
566
|
+
var LINTEL_H = STOREY_METRES - OPEN_H;
|
|
567
|
+
var JAMB_X = OPEN_W * .5 + JAMB_W * .5;
|
|
568
|
+
var RAMP_LEN = Math.hypot(SIDE_METRES, STOREY_METRES);
|
|
569
|
+
var RAMP_PITCH = -Math.atan2(STOREY_METRES, SIDE_METRES);
|
|
570
|
+
function createTriangleSlabGeometry(yMin, yMax) {
|
|
571
|
+
const corners = triangleCorners();
|
|
572
|
+
const positions = [];
|
|
573
|
+
const pushTri = (a, b, c) => {
|
|
574
|
+
positions.push(a[0], a[1], a[2], b[0], b[1], b[2], c[0], c[1], c[2]);
|
|
575
|
+
};
|
|
576
|
+
const bot = corners.map(([x, , z]) => [
|
|
577
|
+
x,
|
|
578
|
+
yMin,
|
|
579
|
+
z
|
|
580
|
+
]);
|
|
581
|
+
const top = corners.map(([x, , z]) => [
|
|
582
|
+
x,
|
|
583
|
+
yMax,
|
|
584
|
+
z
|
|
585
|
+
]);
|
|
586
|
+
pushTri(top[0], top[1], top[2]);
|
|
587
|
+
pushTri(bot[0], bot[2], bot[1]);
|
|
588
|
+
for (let i = 0; i < 3; i++) {
|
|
589
|
+
const j = (i + 1) % 3;
|
|
590
|
+
pushTri(bot[i], bot[j], top[j]);
|
|
591
|
+
pushTri(bot[i], top[j], top[i]);
|
|
592
|
+
}
|
|
593
|
+
const geo = new THREE.BufferGeometry();
|
|
594
|
+
geo.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
|
|
595
|
+
geo.computeVertexNormals();
|
|
596
|
+
return geo;
|
|
597
|
+
}
|
|
598
|
+
function buildTriangleHullVertices(yMin, yMax) {
|
|
599
|
+
const corners = triangleCorners();
|
|
600
|
+
const verts = [];
|
|
601
|
+
for (const [x, , z] of corners) verts.push(x, yMin, z, x, yMax, z);
|
|
602
|
+
return new Float32Array(verts);
|
|
603
|
+
}
|
|
604
|
+
var _c12Resources = null;
|
|
605
|
+
function getSharedC12Resources() {
|
|
606
|
+
if (_c12Resources) return _c12Resources;
|
|
607
|
+
_c12Resources = {
|
|
608
|
+
slabGeo: new THREE.BoxGeometry(SIDE_METRES, SLAB_THICK, SIDE_METRES),
|
|
609
|
+
wallGeo: new THREE.BoxGeometry(SIDE_METRES, STOREY_METRES, WALL_THICK),
|
|
610
|
+
jambGeo: new THREE.BoxGeometry(JAMB_W, OPEN_H, WALL_THICK),
|
|
611
|
+
lintelGeo: new THREE.BoxGeometry(SIDE_METRES, LINTEL_H, WALL_THICK),
|
|
612
|
+
rampGeo: new THREE.BoxGeometry(SIDE_METRES * .9, SLAB_THICK, RAMP_LEN),
|
|
613
|
+
triGroundGeo: createTriangleSlabGeometry(0, SLAB_THICK),
|
|
614
|
+
triUpperGeo: createTriangleSlabGeometry(-.2, 0),
|
|
615
|
+
triGroundVerts: buildTriangleHullVertices(0, SLAB_THICK),
|
|
616
|
+
triUpperVerts: buildTriangleHullVertices(-.2, 0),
|
|
617
|
+
slabMat: new THREE.MeshStandardMaterial({
|
|
618
|
+
color: "#64748b",
|
|
619
|
+
roughness: .82,
|
|
620
|
+
metalness: .08
|
|
621
|
+
}),
|
|
622
|
+
roofMat: new THREE.MeshStandardMaterial({
|
|
623
|
+
color: "#475569",
|
|
624
|
+
roughness: .82,
|
|
625
|
+
metalness: .08
|
|
626
|
+
}),
|
|
627
|
+
streetMat: new THREE.MeshStandardMaterial({
|
|
628
|
+
color: "#334155",
|
|
629
|
+
roughness: .88,
|
|
630
|
+
metalness: .04
|
|
631
|
+
}),
|
|
632
|
+
wallMat: new THREE.MeshStandardMaterial({
|
|
633
|
+
color: "#94a3b8",
|
|
634
|
+
roughness: .78,
|
|
635
|
+
metalness: .06
|
|
636
|
+
}),
|
|
637
|
+
stairMat: new THREE.MeshStandardMaterial({
|
|
638
|
+
color: "#cbd5e1",
|
|
639
|
+
roughness: .75,
|
|
640
|
+
metalness: .06
|
|
641
|
+
}),
|
|
642
|
+
ghostValidMat: new THREE.MeshBasicMaterial({
|
|
643
|
+
color: "#34d399",
|
|
644
|
+
transparent: true,
|
|
645
|
+
opacity: .36,
|
|
646
|
+
depthWrite: false
|
|
647
|
+
}),
|
|
648
|
+
ghostInvalidMat: new THREE.MeshBasicMaterial({
|
|
649
|
+
color: "#ef4444",
|
|
650
|
+
transparent: true,
|
|
651
|
+
opacity: .36,
|
|
652
|
+
depthWrite: false
|
|
653
|
+
})
|
|
654
|
+
};
|
|
655
|
+
return _c12Resources;
|
|
656
|
+
}
|
|
657
|
+
function C12PieceMeshes({ kind, overrideMaterial }) {
|
|
658
|
+
const res = getSharedC12Resources();
|
|
659
|
+
const cast = !overrideMaterial;
|
|
660
|
+
if (kind === "FoundationSquare" || kind === "Floor" || kind === "Roof" || kind === "Street") {
|
|
661
|
+
const yOff = kind === "FoundationSquare" || kind === "Street" ? SLAB_THICK * .5 : -.1;
|
|
662
|
+
const mat = overrideMaterial ?? (kind === "Roof" ? res.roofMat : kind === "Street" ? res.streetMat : res.slabMat);
|
|
663
|
+
return /* @__PURE__ */ jsx("mesh", {
|
|
664
|
+
position: [
|
|
665
|
+
0,
|
|
666
|
+
yOff,
|
|
667
|
+
0
|
|
668
|
+
],
|
|
669
|
+
geometry: res.slabGeo,
|
|
670
|
+
material: mat,
|
|
671
|
+
castShadow: cast,
|
|
672
|
+
receiveShadow: cast
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
if (kind === "FoundationTriangle" || kind === "FloorTriangle" || kind === "RoofTriangle") {
|
|
676
|
+
const geo = kind === "FoundationTriangle" ? res.triGroundGeo : res.triUpperGeo;
|
|
677
|
+
const mat = overrideMaterial ?? (kind === "RoofTriangle" ? res.roofMat : res.slabMat);
|
|
678
|
+
return /* @__PURE__ */ jsx("mesh", {
|
|
679
|
+
geometry: geo,
|
|
680
|
+
material: mat,
|
|
681
|
+
castShadow: cast,
|
|
682
|
+
receiveShadow: cast
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
if (kind === "Wall") return /* @__PURE__ */ jsx("mesh", {
|
|
686
|
+
position: [
|
|
687
|
+
0,
|
|
688
|
+
STOREY_METRES * .5,
|
|
689
|
+
0
|
|
690
|
+
],
|
|
691
|
+
geometry: res.wallGeo,
|
|
692
|
+
material: overrideMaterial ?? res.wallMat,
|
|
693
|
+
castShadow: cast,
|
|
694
|
+
receiveShadow: cast
|
|
695
|
+
});
|
|
696
|
+
if (kind === "Doorway") {
|
|
697
|
+
const mat = overrideMaterial ?? res.wallMat;
|
|
698
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
699
|
+
/* @__PURE__ */ jsx("mesh", {
|
|
700
|
+
position: [
|
|
701
|
+
-JAMB_X,
|
|
702
|
+
OPEN_H * .5,
|
|
703
|
+
0
|
|
704
|
+
],
|
|
705
|
+
geometry: res.jambGeo,
|
|
706
|
+
material: mat,
|
|
707
|
+
castShadow: cast,
|
|
708
|
+
receiveShadow: cast
|
|
709
|
+
}),
|
|
710
|
+
/* @__PURE__ */ jsx("mesh", {
|
|
711
|
+
position: [
|
|
712
|
+
JAMB_X,
|
|
713
|
+
OPEN_H * .5,
|
|
714
|
+
0
|
|
715
|
+
],
|
|
716
|
+
geometry: res.jambGeo,
|
|
717
|
+
material: mat,
|
|
718
|
+
castShadow: cast,
|
|
719
|
+
receiveShadow: cast
|
|
720
|
+
}),
|
|
721
|
+
/* @__PURE__ */ jsx("mesh", {
|
|
722
|
+
position: [
|
|
723
|
+
0,
|
|
724
|
+
OPEN_H + LINTEL_H * .5,
|
|
725
|
+
0
|
|
726
|
+
],
|
|
727
|
+
geometry: res.lintelGeo,
|
|
728
|
+
material: mat,
|
|
729
|
+
castShadow: cast,
|
|
730
|
+
receiveShadow: cast
|
|
731
|
+
})
|
|
732
|
+
] });
|
|
733
|
+
}
|
|
734
|
+
return /* @__PURE__ */ jsx("mesh", {
|
|
735
|
+
position: [
|
|
736
|
+
0,
|
|
737
|
+
STOREY_METRES * .5,
|
|
738
|
+
0
|
|
739
|
+
],
|
|
740
|
+
rotation: [
|
|
741
|
+
RAMP_PITCH,
|
|
742
|
+
0,
|
|
743
|
+
0
|
|
744
|
+
],
|
|
745
|
+
geometry: res.rampGeo,
|
|
746
|
+
material: overrideMaterial ?? res.stairMat,
|
|
747
|
+
castShadow: cast,
|
|
748
|
+
receiveShadow: cast
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
function C12PieceColliderAndMesh({ piece }) {
|
|
752
|
+
const flt = useMemo(() => poseToFloat(piece.pose), [piece.pose]);
|
|
753
|
+
const userData = useMemo(() => ({
|
|
754
|
+
kolmoPlacedPieceId: piece.id,
|
|
755
|
+
name: piece.kind
|
|
756
|
+
}), [piece.id, piece.kind]);
|
|
757
|
+
const res = getSharedC12Resources();
|
|
758
|
+
if (piece.kind === "FoundationSquare" || piece.kind === "Floor" || piece.kind === "Roof" || piece.kind === "Street") {
|
|
759
|
+
const yOff = piece.kind === "FoundationSquare" || piece.kind === "Street" ? SLAB_THICK * .5 : -.1;
|
|
760
|
+
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
761
|
+
type: "fixed",
|
|
762
|
+
colliders: false,
|
|
763
|
+
position: flt.position,
|
|
764
|
+
quaternion: flt.quaternion,
|
|
765
|
+
friction: .6,
|
|
766
|
+
restitution: .1,
|
|
767
|
+
userData,
|
|
768
|
+
children: [/* @__PURE__ */ jsx(CuboidCollider, {
|
|
769
|
+
args: [
|
|
770
|
+
SIDE_METRES * .5,
|
|
771
|
+
SLAB_THICK * .5,
|
|
772
|
+
SIDE_METRES * .5
|
|
773
|
+
],
|
|
774
|
+
position: [
|
|
775
|
+
0,
|
|
776
|
+
yOff,
|
|
777
|
+
0
|
|
778
|
+
]
|
|
779
|
+
}), /* @__PURE__ */ jsx(C12PieceMeshes, { kind: piece.kind })]
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
if (piece.kind === "FoundationTriangle" || piece.kind === "FloorTriangle" || piece.kind === "RoofTriangle") {
|
|
783
|
+
const hullVerts = piece.kind === "FoundationTriangle" ? res.triGroundVerts : res.triUpperVerts;
|
|
784
|
+
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
785
|
+
type: "fixed",
|
|
786
|
+
colliders: false,
|
|
787
|
+
position: flt.position,
|
|
788
|
+
quaternion: flt.quaternion,
|
|
789
|
+
friction: .6,
|
|
790
|
+
restitution: .1,
|
|
791
|
+
userData,
|
|
792
|
+
children: [/* @__PURE__ */ jsx(ConvexHullCollider, { args: [hullVerts] }), /* @__PURE__ */ jsx(C12PieceMeshes, { kind: piece.kind })]
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
if (piece.kind === "Wall") return /* @__PURE__ */ jsxs(RigidBody, {
|
|
796
|
+
type: "fixed",
|
|
797
|
+
colliders: false,
|
|
798
|
+
position: flt.position,
|
|
799
|
+
quaternion: flt.quaternion,
|
|
800
|
+
friction: .6,
|
|
801
|
+
restitution: .1,
|
|
802
|
+
userData,
|
|
803
|
+
children: [/* @__PURE__ */ jsx(CuboidCollider, {
|
|
804
|
+
args: [
|
|
805
|
+
SIDE_METRES * .5,
|
|
806
|
+
STOREY_METRES * .5,
|
|
807
|
+
WALL_THICK * .5
|
|
808
|
+
],
|
|
809
|
+
position: [
|
|
810
|
+
0,
|
|
811
|
+
STOREY_METRES * .5,
|
|
812
|
+
0
|
|
813
|
+
]
|
|
814
|
+
}), /* @__PURE__ */ jsx(C12PieceMeshes, { kind: "Wall" })]
|
|
815
|
+
});
|
|
816
|
+
if (piece.kind === "Doorway") return /* @__PURE__ */ jsxs(RigidBody, {
|
|
817
|
+
type: "fixed",
|
|
818
|
+
colliders: false,
|
|
819
|
+
position: flt.position,
|
|
820
|
+
quaternion: flt.quaternion,
|
|
821
|
+
friction: .6,
|
|
822
|
+
restitution: .1,
|
|
823
|
+
userData,
|
|
824
|
+
children: [
|
|
825
|
+
/* @__PURE__ */ jsx(CuboidCollider, {
|
|
826
|
+
args: [
|
|
827
|
+
JAMB_W * .5,
|
|
828
|
+
OPEN_H * .5,
|
|
829
|
+
WALL_THICK * .5
|
|
830
|
+
],
|
|
831
|
+
position: [
|
|
832
|
+
-JAMB_X,
|
|
833
|
+
OPEN_H * .5,
|
|
834
|
+
0
|
|
835
|
+
]
|
|
836
|
+
}),
|
|
837
|
+
/* @__PURE__ */ jsx(CuboidCollider, {
|
|
838
|
+
args: [
|
|
839
|
+
JAMB_W * .5,
|
|
840
|
+
OPEN_H * .5,
|
|
841
|
+
WALL_THICK * .5
|
|
842
|
+
],
|
|
843
|
+
position: [
|
|
844
|
+
JAMB_X,
|
|
845
|
+
OPEN_H * .5,
|
|
846
|
+
0
|
|
847
|
+
]
|
|
848
|
+
}),
|
|
849
|
+
/* @__PURE__ */ jsx(CuboidCollider, {
|
|
850
|
+
args: [
|
|
851
|
+
SIDE_METRES * .5,
|
|
852
|
+
LINTEL_H * .5,
|
|
853
|
+
WALL_THICK * .5
|
|
854
|
+
],
|
|
855
|
+
position: [
|
|
856
|
+
0,
|
|
857
|
+
OPEN_H + LINTEL_H * .5,
|
|
858
|
+
0
|
|
859
|
+
]
|
|
860
|
+
}),
|
|
861
|
+
/* @__PURE__ */ jsx(C12PieceMeshes, { kind: "Doorway" })
|
|
862
|
+
]
|
|
863
|
+
});
|
|
864
|
+
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
865
|
+
type: "fixed",
|
|
866
|
+
colliders: false,
|
|
867
|
+
position: flt.position,
|
|
868
|
+
quaternion: flt.quaternion,
|
|
869
|
+
friction: .85,
|
|
870
|
+
restitution: .05,
|
|
871
|
+
userData,
|
|
872
|
+
children: [/* @__PURE__ */ jsx(CuboidCollider, {
|
|
873
|
+
args: [
|
|
874
|
+
SIDE_METRES * .45,
|
|
875
|
+
SLAB_THICK * .5,
|
|
876
|
+
RAMP_LEN * .5
|
|
877
|
+
],
|
|
878
|
+
position: [
|
|
879
|
+
0,
|
|
880
|
+
STOREY_METRES * .5,
|
|
881
|
+
0
|
|
882
|
+
],
|
|
883
|
+
rotation: [
|
|
884
|
+
RAMP_PITCH,
|
|
885
|
+
0,
|
|
886
|
+
0
|
|
887
|
+
]
|
|
888
|
+
}), /* @__PURE__ */ jsx(C12PieceMeshes, { kind: "Stairs" })]
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
function BuildGhostPreview({ candidate }) {
|
|
892
|
+
const res = getSharedC12Resources();
|
|
893
|
+
return /* @__PURE__ */ jsx("group", {
|
|
894
|
+
position: candidate.position,
|
|
895
|
+
quaternion: candidate.quaternion,
|
|
896
|
+
children: /* @__PURE__ */ jsx(C12PieceMeshes, {
|
|
897
|
+
kind: candidate.kind,
|
|
898
|
+
overrideMaterial: candidate.valid ? res.ghostValidMat : res.ghostInvalidMat
|
|
899
|
+
})
|
|
900
|
+
});
|
|
901
|
+
}
|
|
526
902
|
// src/toolgun/Toolgun.tsx
|
|
527
903
|
var LCD_W = 256;
|
|
528
904
|
var LCD_H = 192;
|
|
529
|
-
var
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
905
|
+
var DEFAULT_ACCENT_HEX = "#38bdf8";
|
|
906
|
+
/**
|
|
907
|
+
* Measures grip, muzzle, and LCD bezel sockets on an already-cloned viewmodel scene without duplicating it.
|
|
908
|
+
* Offsets the LCD quad 1mm along `screen_rect`'s local +Z normal in root space so arbitrary bezel orientations never z-fight.
|
|
909
|
+
*/
|
|
910
|
+
function measureToolgunViewmodel(clonedScene) {
|
|
911
|
+
clonedScene.updateMatrixWorld(true);
|
|
912
|
+
const invRoot = clonedScene.matrixWorld.clone().invert();
|
|
913
|
+
const invRootQuat = clonedScene.getWorldQuaternion(new THREE.Quaternion()).invert();
|
|
914
|
+
const rootScale = clonedScene.getWorldScale(new THREE.Vector3());
|
|
535
915
|
let grip = [
|
|
536
916
|
0,
|
|
537
917
|
0,
|
|
@@ -556,7 +936,11 @@ function measureToolgunViewmodel(sourceScene) {
|
|
|
556
936
|
let screenSize = [.068, .051];
|
|
557
937
|
const tmpPos = new THREE.Vector3();
|
|
558
938
|
const tmpQuat = new THREE.Quaternion();
|
|
559
|
-
|
|
939
|
+
const tmpPlaneRot = new THREE.Quaternion();
|
|
940
|
+
const tmpNormal = new THREE.Vector3();
|
|
941
|
+
const tmpSize = new THREE.Vector3();
|
|
942
|
+
const tmpScale = new THREE.Vector3();
|
|
943
|
+
clonedScene.traverse((node) => {
|
|
560
944
|
const low = node.name.toLowerCase();
|
|
561
945
|
if (low === "ik_palm_primary" || low === "grip" || low === "socket_grip") {
|
|
562
946
|
node.getWorldPosition(tmpPos).applyMatrix4(invRoot);
|
|
@@ -574,11 +958,38 @@ function measureToolgunViewmodel(sourceScene) {
|
|
|
574
958
|
];
|
|
575
959
|
} else if (low === "screen_rect" || low === "lcd_screen") {
|
|
576
960
|
node.getWorldPosition(tmpPos).applyMatrix4(invRoot);
|
|
577
|
-
node.getWorldQuaternion(tmpQuat);
|
|
961
|
+
node.getWorldQuaternion(tmpQuat).premultiply(invRootQuat).normalize();
|
|
962
|
+
node.getWorldScale(tmpScale);
|
|
963
|
+
const sx = Math.abs(rootScale.x) > 1e-6 ? Math.abs(tmpScale.x / rootScale.x) : 1;
|
|
964
|
+
const sy = Math.abs(rootScale.y) > 1e-6 ? Math.abs(tmpScale.y / rootScale.y) : 1;
|
|
965
|
+
const sz = Math.abs(rootScale.z) > 1e-6 ? Math.abs(tmpScale.z / rootScale.z) : 1;
|
|
966
|
+
const mesh = node;
|
|
967
|
+
tmpPlaneRot.identity();
|
|
968
|
+
if (mesh.isMesh && mesh.geometry) {
|
|
969
|
+
mesh.geometry.computeBoundingBox();
|
|
970
|
+
const bb = mesh.geometry.boundingBox;
|
|
971
|
+
if (bb) {
|
|
972
|
+
bb.getSize(tmpSize);
|
|
973
|
+
const ex = tmpSize.x * sx;
|
|
974
|
+
const ey = tmpSize.y * sy;
|
|
975
|
+
const ez = tmpSize.z * sz;
|
|
976
|
+
if (ez <= ex && ez <= ey) screenSize = [Math.max(.025, ex), Math.max(.02, ey)];
|
|
977
|
+
else if (ey <= ex && ey <= ez) {
|
|
978
|
+
tmpPlaneRot.setFromAxisAngle(new THREE.Vector3(1, 0, 0), -Math.PI / 2);
|
|
979
|
+
screenSize = [Math.max(.025, ex), Math.max(.02, ez)];
|
|
980
|
+
} else {
|
|
981
|
+
tmpPlaneRot.setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 2);
|
|
982
|
+
screenSize = [Math.max(.025, ez), Math.max(.02, ey)];
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
mesh.visible = false;
|
|
986
|
+
}
|
|
987
|
+
tmpQuat.multiply(tmpPlaneRot).normalize();
|
|
988
|
+
tmpNormal.set(0, 0, 1).applyQuaternion(tmpQuat);
|
|
578
989
|
screenPos = [
|
|
579
|
-
tmpPos.x,
|
|
580
|
-
tmpPos.y,
|
|
581
|
-
tmpPos.z + .001
|
|
990
|
+
tmpPos.x + tmpNormal.x * .001,
|
|
991
|
+
tmpPos.y + tmpNormal.y * .001,
|
|
992
|
+
tmpPos.z + tmpNormal.z * .001
|
|
582
993
|
];
|
|
583
994
|
screenQuat = [
|
|
584
995
|
tmpQuat.x,
|
|
@@ -586,19 +997,10 @@ function measureToolgunViewmodel(sourceScene) {
|
|
|
586
997
|
tmpQuat.z,
|
|
587
998
|
tmpQuat.w
|
|
588
999
|
];
|
|
589
|
-
const mesh = node;
|
|
590
|
-
if (mesh.isMesh && mesh.geometry) {
|
|
591
|
-
mesh.geometry.computeBoundingBox();
|
|
592
|
-
const bb = mesh.geometry.boundingBox;
|
|
593
|
-
if (bb) {
|
|
594
|
-
const sz = bb.getSize(new THREE.Vector3());
|
|
595
|
-
screenSize = [Math.max(.025, sz.x), Math.max(.02, sz.y)];
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
1000
|
}
|
|
599
1001
|
});
|
|
600
1002
|
return {
|
|
601
|
-
scene:
|
|
1003
|
+
scene: clonedScene,
|
|
602
1004
|
gripOffset: grip,
|
|
603
1005
|
muzzleLocal: muzzle,
|
|
604
1006
|
screenPos,
|
|
@@ -624,17 +1026,17 @@ function createLcdSurface() {
|
|
|
624
1026
|
let prevSig = "";
|
|
625
1027
|
return {
|
|
626
1028
|
texture,
|
|
627
|
-
draw: ({ mode, yawDeg, detail, targetLabel, status,
|
|
1029
|
+
draw: ({ mode, yawDeg, detail, targetLabel, status, accentColor }) => {
|
|
628
1030
|
if (!ctx) return;
|
|
629
|
-
const sig = `${mode}|${yawDeg}|${detail}|${targetLabel}|${status}|${
|
|
1031
|
+
const sig = `${mode}|${yawDeg}|${detail}|${targetLabel}|${status}|${accentColor}`;
|
|
630
1032
|
if (sig === prevSig) return;
|
|
631
1033
|
prevSig = sig;
|
|
632
1034
|
ctx.fillStyle = "#070d19";
|
|
633
1035
|
ctx.fillRect(0, 0, LCD_W, LCD_H);
|
|
634
|
-
ctx.strokeStyle =
|
|
1036
|
+
ctx.strokeStyle = accentColor;
|
|
635
1037
|
ctx.lineWidth = 3;
|
|
636
1038
|
ctx.strokeRect(4, 4, 248, 184);
|
|
637
|
-
ctx.fillStyle =
|
|
1039
|
+
ctx.fillStyle = accentColor;
|
|
638
1040
|
ctx.fillRect(4, 4, 248, 28);
|
|
639
1041
|
ctx.fillStyle = "#040812";
|
|
640
1042
|
ctx.font = "bold 15px ui-monospace, SFMono-Regular, Menlo, monospace";
|
|
@@ -668,353 +1070,7 @@ function createLcdSurface() {
|
|
|
668
1070
|
}
|
|
669
1071
|
};
|
|
670
1072
|
}
|
|
671
|
-
function
|
|
672
|
-
const corners = triangleCorners();
|
|
673
|
-
const y0 = 0;
|
|
674
|
-
const y1 = thicknessM;
|
|
675
|
-
const positions = [];
|
|
676
|
-
const pushTri = (a, b, c) => {
|
|
677
|
-
positions.push(a[0], a[1], a[2], b[0], b[1], b[2], c[0], c[1], c[2]);
|
|
678
|
-
};
|
|
679
|
-
const bot = corners.map(([x, , z]) => [
|
|
680
|
-
x,
|
|
681
|
-
y0,
|
|
682
|
-
z
|
|
683
|
-
]);
|
|
684
|
-
const top = corners.map(([x, , z]) => [
|
|
685
|
-
x,
|
|
686
|
-
y1,
|
|
687
|
-
z
|
|
688
|
-
]);
|
|
689
|
-
pushTri(top[0], top[1], top[2]);
|
|
690
|
-
pushTri(bot[0], bot[2], bot[1]);
|
|
691
|
-
for (let i = 0; i < 3; i++) {
|
|
692
|
-
const j = (i + 1) % 3;
|
|
693
|
-
pushTri(bot[i], bot[j], top[j]);
|
|
694
|
-
pushTri(bot[i], top[j], top[i]);
|
|
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 }) {
|
|
708
|
-
const flt = useMemo(() => poseToFloat(piece.pose), [piece.pose]);
|
|
709
|
-
const userData = useMemo(() => ({
|
|
710
|
-
kolmoPlacedPieceId: piece.id,
|
|
711
|
-
name: piece.kind
|
|
712
|
-
}), [piece.id, piece.kind]);
|
|
713
|
-
const triGeo = useMemo(() => piece.kind === "FoundationTriangle" || piece.kind === "FloorTriangle" || piece.kind === "RoofTriangle" ? createTriangleExtrudedGeometry(SLAB_THICK) : null, [piece.kind]);
|
|
714
|
-
const triVerts = useMemo(() => triGeo ? buildTriangleHullVertices(SLAB_THICK) : null, [triGeo]);
|
|
715
|
-
useEffect(() => () => triGeo?.dispose(), [triGeo]);
|
|
716
|
-
if (piece.kind === "FoundationSquare" || piece.kind === "Floor" || piece.kind === "Roof" || piece.kind === "Street") {
|
|
717
|
-
const yOff = piece.kind === "FoundationSquare" || piece.kind === "Street" ? SLAB_THICK * .5 : -.1;
|
|
718
|
-
const color = piece.kind === "Roof" ? "#475569" : piece.kind === "Street" ? "#334155" : "#64748b";
|
|
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,
|
|
761
|
-
position: flt.position,
|
|
762
|
-
quaternion: flt.quaternion,
|
|
763
|
-
friction: .6,
|
|
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
|
-
})]
|
|
776
|
-
});
|
|
777
|
-
if (piece.kind === "Wall") return /* @__PURE__ */ jsxs(RigidBody, {
|
|
778
|
-
type: "fixed",
|
|
779
|
-
colliders: false,
|
|
780
|
-
position: flt.position,
|
|
781
|
-
quaternion: flt.quaternion,
|
|
782
|
-
friction: .6,
|
|
783
|
-
restitution: .1,
|
|
784
|
-
userData,
|
|
785
|
-
children: [/* @__PURE__ */ jsx(CuboidCollider, {
|
|
786
|
-
args: [
|
|
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
|
-
]
|
|
918
|
-
});
|
|
919
|
-
}
|
|
920
|
-
const rampLen = Math.hypot(SIDE_METRES, STOREY_METRES);
|
|
921
|
-
const rampPitch = -Math.atan2(STOREY_METRES, SIDE_METRES);
|
|
922
|
-
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
923
|
-
type: "fixed",
|
|
924
|
-
colliders: false,
|
|
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
|
-
})]
|
|
968
|
-
});
|
|
969
|
-
}
|
|
970
|
-
function BuildGhostPreview({ candidate }) {
|
|
971
|
-
const color = candidate.valid ? "#34d399" : "#ef4444";
|
|
972
|
-
const isSlab = candidate.kind === "FoundationSquare" || candidate.kind === "Floor" || candidate.kind === "Roof";
|
|
973
|
-
const isTri = candidate.kind === "FoundationTriangle" || candidate.kind === "FloorTriangle" || candidate.kind === "RoofTriangle";
|
|
974
|
-
const triGeo = useMemo(() => isTri ? createTriangleExtrudedGeometry(SLAB_THICK) : null, [isTri]);
|
|
975
|
-
useEffect(() => () => triGeo?.dispose(), [triGeo]);
|
|
976
|
-
const dims = isSlab ? [
|
|
977
|
-
SIDE_METRES,
|
|
978
|
-
SLAB_THICK,
|
|
979
|
-
SIDE_METRES
|
|
980
|
-
] : candidate.kind === "Stairs" ? [
|
|
981
|
-
SIDE_METRES * .9,
|
|
982
|
-
STOREY_METRES,
|
|
983
|
-
SIDE_METRES
|
|
984
|
-
] : [
|
|
985
|
-
SIDE_METRES,
|
|
986
|
-
STOREY_METRES,
|
|
987
|
-
WALL_THICK
|
|
988
|
-
];
|
|
989
|
-
const yCenter = isSlab ? SLAB_THICK * .5 : STOREY_METRES * .5;
|
|
990
|
-
return /* @__PURE__ */ jsx("group", {
|
|
991
|
-
position: candidate.position,
|
|
992
|
-
quaternion: candidate.quaternion,
|
|
993
|
-
children: triGeo ? /* @__PURE__ */ jsx("mesh", {
|
|
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
|
-
})
|
|
1014
|
-
});
|
|
1015
|
-
}
|
|
1016
|
-
function ProceduralToolgunBody({ skinPreset, lcdTexture }) {
|
|
1017
|
-
const skin = TOOLGUN_SKIN_PRESETS[skinPreset];
|
|
1073
|
+
function DefaultToolgunMesh({ accentColor, lcdTexture }) {
|
|
1018
1074
|
return /* @__PURE__ */ jsxs("group", { children: [
|
|
1019
1075
|
/* @__PURE__ */ jsxs("mesh", {
|
|
1020
1076
|
position: [
|
|
@@ -1028,9 +1084,9 @@ function ProceduralToolgunBody({ skinPreset, lcdTexture }) {
|
|
|
1028
1084
|
.062,
|
|
1029
1085
|
.22
|
|
1030
1086
|
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1031
|
-
color:
|
|
1032
|
-
metalness:
|
|
1033
|
-
roughness:
|
|
1087
|
+
color: "#1e293b",
|
|
1088
|
+
metalness: .65,
|
|
1089
|
+
roughness: .32
|
|
1034
1090
|
})]
|
|
1035
1091
|
}),
|
|
1036
1092
|
/* @__PURE__ */ jsxs("mesh", {
|
|
@@ -1051,9 +1107,9 @@ function ProceduralToolgunBody({ skinPreset, lcdTexture }) {
|
|
|
1051
1107
|
.14,
|
|
1052
1108
|
12
|
|
1053
1109
|
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1054
|
-
color:
|
|
1055
|
-
emissive:
|
|
1056
|
-
emissiveIntensity: .
|
|
1110
|
+
color: accentColor,
|
|
1111
|
+
emissive: accentColor,
|
|
1112
|
+
emissiveIntensity: .45,
|
|
1057
1113
|
metalness: .8,
|
|
1058
1114
|
roughness: .2
|
|
1059
1115
|
})]
|
|
@@ -1087,18 +1143,41 @@ function ProceduralToolgunBody({ skinPreset, lcdTexture }) {
|
|
|
1087
1143
|
.072
|
|
1088
1144
|
],
|
|
1089
1145
|
children: [/* @__PURE__ */ jsx("planeGeometry", { args: [.064, .048] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
1090
|
-
...lcdTexture ? { map: lcdTexture } : { color:
|
|
1146
|
+
...lcdTexture ? { map: lcdTexture } : { color: accentColor },
|
|
1091
1147
|
toneMapped: false
|
|
1092
1148
|
})]
|
|
1093
1149
|
})
|
|
1094
1150
|
] });
|
|
1095
1151
|
}
|
|
1152
|
+
var SpawnedToolgunOutlet = React.memo(function SpawnedToolgunOutlet({ entry }) {
|
|
1153
|
+
const userData = useMemo(() => ({
|
|
1154
|
+
kolmoSpawnedId: entry.id,
|
|
1155
|
+
name: entry.name
|
|
1156
|
+
}), [entry.id, entry.name]);
|
|
1157
|
+
const rigidBodyProps = useMemo(() => ({ userData }), [userData]);
|
|
1158
|
+
if (entry.kind === "vehicle") return /* @__PURE__ */ jsx(KolmoVehicle, {
|
|
1159
|
+
id: entry.id,
|
|
1160
|
+
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
1161
|
+
...entry.src ? { src: entry.src } : {},
|
|
1162
|
+
position: entry.position,
|
|
1163
|
+
quaternion: entry.quaternion,
|
|
1164
|
+
userData
|
|
1165
|
+
});
|
|
1166
|
+
return /* @__PURE__ */ jsx(KolmoProp, {
|
|
1167
|
+
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
1168
|
+
...entry.src ? { src: entry.src } : {},
|
|
1169
|
+
fixed: entry.fixed,
|
|
1170
|
+
position: entry.position,
|
|
1171
|
+
quaternion: entry.quaternion,
|
|
1172
|
+
rigidBodyProps
|
|
1173
|
+
});
|
|
1174
|
+
});
|
|
1096
1175
|
var _camPos = new THREE.Vector3();
|
|
1097
1176
|
var _camDir = new THREE.Vector3();
|
|
1098
1177
|
var _muzzleWorld = new THREE.Vector3();
|
|
1099
1178
|
var _beamEndVec = new THREE.Vector3();
|
|
1100
1179
|
var _targetOffset = new THREE.Vector3();
|
|
1101
|
-
function ToolgunCore({ ref, viewmodelBundle, actorRef,
|
|
1180
|
+
function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACCENT_HEX, defaultArmedAsset, maxRangeM = 75, hipOffset = [
|
|
1102
1181
|
.24,
|
|
1103
1182
|
-.21,
|
|
1104
1183
|
-.42
|
|
@@ -1111,16 +1190,19 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1111
1190
|
const camera = useThree((s) => s.camera);
|
|
1112
1191
|
const gl = useThree((s) => s.gl);
|
|
1113
1192
|
const kootaWorld = useActiveKolmoWorld();
|
|
1193
|
+
const { mode: controlMode } = useKolmoGame(kootaWorld);
|
|
1194
|
+
const isPiloted = controlMode !== "foot";
|
|
1114
1195
|
const jointRegistry = useContext(JointRegistryContext);
|
|
1115
1196
|
const mode = useToolgunStore((s) => s.mode);
|
|
1116
|
-
const storeSkin = useToolgunStore((s) => s.skinPreset);
|
|
1117
1197
|
const buildPreview = useToolgunStore((s) => s.buildPreview);
|
|
1118
1198
|
const spawnedEntities = useToolgunStore((s) => s.spawnedEntities);
|
|
1119
1199
|
const placedPieces = useToolgunStore((s) => s.placedPieces);
|
|
1120
|
-
const effSkin = skinProp ?? storeSkin;
|
|
1121
1200
|
useEffect(() => {
|
|
1122
1201
|
if (defaultArmedAsset && !useToolgunStore.getState().armedAsset) useToolgunStore.getState().armAsset(defaultArmedAsset);
|
|
1123
1202
|
}, [defaultArmedAsset]);
|
|
1203
|
+
useEffect(() => () => {
|
|
1204
|
+
useToolgunStore.getState().clearWorldHandles(rapierWorld);
|
|
1205
|
+
}, [rapierWorld]);
|
|
1124
1206
|
const measured = useMemo(() => viewmodelBundle ? measureToolgunViewmodel(viewmodelBundle.scene) : null, [viewmodelBundle]);
|
|
1125
1207
|
const lcd = useMemo(createLcdSurface, []);
|
|
1126
1208
|
useEffect(() => () => lcd.dispose(), [lcd]);
|
|
@@ -1128,6 +1210,12 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1128
1210
|
const recoilRef = useRef(0);
|
|
1129
1211
|
const beamTimerRef = useRef(0);
|
|
1130
1212
|
const beamMatRef = useRef(null);
|
|
1213
|
+
const rayScratchRef = useRef(null);
|
|
1214
|
+
const fallbackPtRef = useRef([
|
|
1215
|
+
0,
|
|
1216
|
+
0,
|
|
1217
|
+
0
|
|
1218
|
+
]);
|
|
1131
1219
|
const beamGeo = useMemo(() => {
|
|
1132
1220
|
const g = new THREE.BufferGeometry();
|
|
1133
1221
|
g.setAttribute("position", new THREE.Float32BufferAttribute([
|
|
@@ -1142,7 +1230,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1142
1230
|
}, []);
|
|
1143
1231
|
const beamLine = useMemo(() => {
|
|
1144
1232
|
const mat = new THREE.LineBasicMaterial({
|
|
1145
|
-
color:
|
|
1233
|
+
color: accentColor,
|
|
1146
1234
|
transparent: true,
|
|
1147
1235
|
opacity: 0,
|
|
1148
1236
|
depthTest: false
|
|
@@ -1152,11 +1240,11 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1152
1240
|
line.frustumCulled = false;
|
|
1153
1241
|
line.visible = false;
|
|
1154
1242
|
return line;
|
|
1155
|
-
}, [beamGeo]);
|
|
1243
|
+
}, [beamGeo, accentColor]);
|
|
1156
1244
|
useEffect(() => () => {
|
|
1157
|
-
beamGeo.dispose();
|
|
1158
1245
|
beamMatRef.current?.dispose();
|
|
1159
|
-
}, [
|
|
1246
|
+
}, [beamLine]);
|
|
1247
|
+
useEffect(() => () => beamGeo.dispose(), [beamGeo]);
|
|
1160
1248
|
const resolvePlayerBody = useCallback(() => {
|
|
1161
1249
|
if (actorRef?.current?.body) return actorRef.current.body;
|
|
1162
1250
|
return kootaWorld.queryFirst(ActorTrait)?.get(ActorTrait)?.handle?.body ?? null;
|
|
@@ -1171,15 +1259,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1171
1259
|
camera.getWorldDirection(_camDir);
|
|
1172
1260
|
const st = useToolgunStore.getState();
|
|
1173
1261
|
const playerBody = resolvePlayerBody();
|
|
1174
|
-
const rawHit = castToolgunRay(rapier, rapierWorld,
|
|
1175
|
-
_camPos.x,
|
|
1176
|
-
_camPos.y,
|
|
1177
|
-
_camPos.z
|
|
1178
|
-
], [
|
|
1179
|
-
_camDir.x,
|
|
1180
|
-
_camDir.y,
|
|
1181
|
-
_camDir.z
|
|
1182
|
-
], maxRangeM, playerBody);
|
|
1262
|
+
const rawHit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody);
|
|
1183
1263
|
let fallbackPoint = [
|
|
1184
1264
|
_camPos.x + _camDir.x * 5,
|
|
1185
1265
|
Math.max(0, _camPos.y + _camDir.y * 5),
|
|
@@ -1208,7 +1288,12 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1208
1288
|
.038,
|
|
1209
1289
|
-.26
|
|
1210
1290
|
];
|
|
1211
|
-
|
|
1291
|
+
const gOff = measured?.gripOffset ?? [
|
|
1292
|
+
0,
|
|
1293
|
+
0,
|
|
1294
|
+
0
|
|
1295
|
+
];
|
|
1296
|
+
_muzzleWorld.set(mLocal[0] + gOff[0], mLocal[1] + gOff[1], mLocal[2] + gOff[2]).applyMatrix4(holderRef.current.matrixWorld);
|
|
1212
1297
|
} else _muzzleWorld.copy(_camPos).addScaledVector(_camDir, .35);
|
|
1213
1298
|
const posAttr = beamGeo.getAttribute("position");
|
|
1214
1299
|
posAttr.setXYZ(0, _muzzleWorld.x, _muzzleWorld.y, _muzzleWorld.z);
|
|
@@ -1282,9 +1367,11 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1282
1367
|
};
|
|
1283
1368
|
}
|
|
1284
1369
|
const pending = st.pendingAnchor;
|
|
1285
|
-
|
|
1370
|
+
const liveBodyA = pending && pending.world === rapierWorld ? rapierWorld.getRigidBody(pending.body.handle) : null;
|
|
1371
|
+
if (!pending || !liveBodyA) {
|
|
1286
1372
|
const label = rawHit.body.userData?.name ?? `body_${rawHit.body.handle}`;
|
|
1287
1373
|
st.setPendingAnchor({
|
|
1374
|
+
world: rapierWorld,
|
|
1288
1375
|
body: rawHit.body,
|
|
1289
1376
|
worldPoint: rawHit.point,
|
|
1290
1377
|
worldNormal: rawHit.normal,
|
|
@@ -1297,7 +1384,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1297
1384
|
beamEnd: aimPoint
|
|
1298
1385
|
};
|
|
1299
1386
|
}
|
|
1300
|
-
if (
|
|
1387
|
+
if (liveBodyA.handle === rawHit.body.handle) {
|
|
1301
1388
|
st.setPendingAnchor(null);
|
|
1302
1389
|
st.bumpFire("SAME BODY — CANCELLED");
|
|
1303
1390
|
return {
|
|
@@ -1311,11 +1398,12 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1311
1398
|
.5 * (pending.worldPoint[1] + rawHit.point[1]),
|
|
1312
1399
|
.5 * (pending.worldPoint[2] + rawHit.point[2])
|
|
1313
1400
|
];
|
|
1314
|
-
const imp = st.mode === "weld" ? createWeldImpulseJoint(rapier, rapierWorld,
|
|
1401
|
+
const imp = st.mode === "weld" ? createWeldImpulseJoint(rapier, rapierWorld, liveBodyA, rawHit.body, anchorMid) : createHingeImpulseJoint(rapier, rapierWorld, liveBodyA, rawHit.body, anchorMid, pending.worldNormal);
|
|
1315
1402
|
const id = `tg_${st.mode}_${imp.handle}`;
|
|
1316
1403
|
st.recordJoint({
|
|
1317
1404
|
id,
|
|
1318
1405
|
kind: st.mode,
|
|
1406
|
+
world: rapierWorld,
|
|
1319
1407
|
handle: imp.handle,
|
|
1320
1408
|
joint: imp,
|
|
1321
1409
|
anchorWorld: anchorMid
|
|
@@ -1340,7 +1428,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1340
1428
|
status: `REMOVED ${ud.kolmoPlacedPieceId}`,
|
|
1341
1429
|
beamEnd: aimPoint
|
|
1342
1430
|
};
|
|
1343
|
-
if (ud.kolmoSpawnedId && st.removeEntityById(ud.kolmoSpawnedId)) return {
|
|
1431
|
+
if (ud.kolmoSpawnedId && st.removeEntityById(ud.kolmoSpawnedId, rapierWorld)) return {
|
|
1344
1432
|
ok: true,
|
|
1345
1433
|
status: `DELETED ${ud.kolmoSpawnedId}`,
|
|
1346
1434
|
beamEnd: aimPoint
|
|
@@ -1382,8 +1470,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1382
1470
|
return tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT" || Boolean(el.isContentEditable);
|
|
1383
1471
|
};
|
|
1384
1472
|
const onKeyDown = (e) => {
|
|
1385
|
-
if (isEditable(document.activeElement)) return;
|
|
1386
|
-
if (kootaWorld.queryFirst(pilotedVehicleQuery)) return;
|
|
1473
|
+
if (isEditable(document.activeElement) || kootaWorld.queryFirst(pilotedVehicleQuery)) return;
|
|
1387
1474
|
const st = useToolgunStore.getState();
|
|
1388
1475
|
if (e.code >= "Digit1" && e.code <= "Digit6") {
|
|
1389
1476
|
const idx = Number(e.code.slice(5)) - 1;
|
|
@@ -1464,15 +1551,9 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1464
1551
|
camera.getWorldPosition(_camPos);
|
|
1465
1552
|
camera.getWorldDirection(_camDir);
|
|
1466
1553
|
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);
|
|
1554
|
+
const hit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody, rayScratchRef.current ?? void 0);
|
|
1555
|
+
if (hit && !rayScratchRef.current) rayScratchRef.current = hit;
|
|
1556
|
+
else if (!hit && rayScratchRef.current) rayScratchRef.current.body = null;
|
|
1476
1557
|
let targetLabel = "NO TARGET";
|
|
1477
1558
|
if (hit) {
|
|
1478
1559
|
const jRt = findJointForBody(hit.body);
|
|
@@ -1480,22 +1561,20 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1480
1561
|
targetLabel = `${jRt ? `JOINT:${jRt.nodeName}` : ud.name ?? ud.kolmoPlacedPieceId ?? ud.kolmoSpawnedId ?? "SURFACE"} (${hit.toi.toFixed(1)}m)`;
|
|
1481
1562
|
}
|
|
1482
1563
|
if (st.mode === "build") {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
];
|
|
1564
|
+
const fb = fallbackPtRef.current;
|
|
1565
|
+
fb[0] = _camPos.x + _camDir.x * 5;
|
|
1566
|
+
fb[1] = Math.max(0, _camPos.y + _camDir.y * 5);
|
|
1567
|
+
fb[2] = _camPos.z + _camDir.z * 5;
|
|
1488
1568
|
if (!hit && _camDir.y < -.02 && _camPos.y > 0) {
|
|
1489
1569
|
const tFloor = -_camPos.y / _camDir.y;
|
|
1490
|
-
if (tFloor > .1 && tFloor <= maxRangeM)
|
|
1491
|
-
_camPos.x + _camDir.x * tFloor
|
|
1492
|
-
0
|
|
1493
|
-
_camPos.z + _camDir.z * tFloor
|
|
1494
|
-
|
|
1570
|
+
if (tFloor > .1 && tFloor <= maxRangeM) {
|
|
1571
|
+
fb[0] = _camPos.x + _camDir.x * tFloor;
|
|
1572
|
+
fb[1] = 0;
|
|
1573
|
+
fb[2] = _camPos.z + _camDir.z * tFloor;
|
|
1574
|
+
}
|
|
1495
1575
|
}
|
|
1496
|
-
const cand = computeBuildCandidate(st.placedPieces, hit ? hit.point :
|
|
1497
|
-
|
|
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);
|
|
1576
|
+
const cand = computeBuildCandidate(st.placedPieces, hit ? hit.point : fb, st.buildKind, st.yaw12);
|
|
1577
|
+
if (!isSameBuildPreview(st.buildPreview, cand)) st.setBuildPreview(cand);
|
|
1499
1578
|
} else if (st.buildPreview !== null) st.setBuildPreview(null);
|
|
1500
1579
|
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
1580
|
lcd.draw({
|
|
@@ -1504,10 +1583,9 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1504
1583
|
detail,
|
|
1505
1584
|
targetLabel,
|
|
1506
1585
|
status: st.statusText,
|
|
1507
|
-
|
|
1586
|
+
accentColor
|
|
1508
1587
|
});
|
|
1509
1588
|
});
|
|
1510
|
-
const isPiloted = Boolean(useActiveKolmoWorld().queryFirst(VehicleTrait, PilotedTag));
|
|
1511
1589
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1512
1590
|
createPortal(/* @__PURE__ */ jsx("group", {
|
|
1513
1591
|
ref: holderRef,
|
|
@@ -1522,12 +1600,12 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1522
1600
|
position: measured.screenPos,
|
|
1523
1601
|
quaternion: measured.screenQuat,
|
|
1524
1602
|
children: [/* @__PURE__ */ jsx("planeGeometry", { args: measured.screenSize }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
1525
|
-
...lcd.texture ? { map: lcd.texture } : { color:
|
|
1603
|
+
...lcd.texture ? { map: lcd.texture } : { color: accentColor },
|
|
1526
1604
|
toneMapped: false
|
|
1527
1605
|
})]
|
|
1528
1606
|
})]
|
|
1529
|
-
}) : /* @__PURE__ */ jsx(
|
|
1530
|
-
|
|
1607
|
+
}) : /* @__PURE__ */ jsx(DefaultToolgunMesh, {
|
|
1608
|
+
accentColor,
|
|
1531
1609
|
lcdTexture: lcd.texture
|
|
1532
1610
|
})
|
|
1533
1611
|
}), camera),
|
|
@@ -1535,27 +1613,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, skinPreset: skinProp, def
|
|
|
1535
1613
|
enable && !isPiloted && mode === "build" && buildPreview && /* @__PURE__ */ jsx(BuildGhostPreview, { candidate: buildPreview }),
|
|
1536
1614
|
mountWorldOutlets && /* @__PURE__ */ jsxs("group", {
|
|
1537
1615
|
name: "kolmo_toolgun_outlets",
|
|
1538
|
-
children: [spawnedEntities.map((entry) => entry.
|
|
1539
|
-
id: entry.id,
|
|
1540
|
-
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
1541
|
-
...entry.src ? { src: entry.src } : {},
|
|
1542
|
-
position: entry.position,
|
|
1543
|
-
quaternion: entry.quaternion,
|
|
1544
|
-
userData: {
|
|
1545
|
-
kolmoSpawnedId: entry.id,
|
|
1546
|
-
name: entry.name
|
|
1547
|
-
}
|
|
1548
|
-
}, entry.id) : /* @__PURE__ */ jsx(KolmoProp, {
|
|
1549
|
-
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
1550
|
-
...entry.src ? { src: entry.src } : {},
|
|
1551
|
-
fixed: entry.fixed,
|
|
1552
|
-
position: entry.position,
|
|
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))]
|
|
1616
|
+
children: [spawnedEntities.map((entry) => /* @__PURE__ */ jsx(SpawnedToolgunOutlet, { entry }, entry.id)), placedPieces.map((piece) => /* @__PURE__ */ jsx(C12PieceColliderAndMesh, { piece }, piece.id))]
|
|
1559
1617
|
})
|
|
1560
1618
|
] });
|
|
1561
1619
|
}
|
|
@@ -1577,6 +1635,6 @@ function KolmoToolgun({ src, bundle, ...rest }) {
|
|
|
1577
1635
|
viewmodelBundle: cloned
|
|
1578
1636
|
});
|
|
1579
1637
|
}
|
|
1580
|
-
export {
|
|
1638
|
+
export { castToolgunRay as a, createHingeImpulseJoint as c, isSameBuildPreview as d, rigJointRuntime as f, TOOLGUN_MODES as i, createToolgunStore as l, measureToolgunViewmodel as n, computeAlignedSpawnPose as o, useToolgunStore as p, TOOLGUN_BUILD_KINDS as r, computeBuildCandidate as s, KolmoToolgun as t, createWeldImpulseJoint as u };
|
|
1581
1639
|
|
|
1582
|
-
//# sourceMappingURL=toolgun-
|
|
1640
|
+
//# sourceMappingURL=toolgun-CFCNO00q.js.map
|