@pinkaphant/kolmo 0.5.2 → 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 +44 -34
- 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 +9 -5
- 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 +11 -4
- package/dist/toolgun/index.d.ts +2 -2
- package/dist/toolgun/index.js +1 -1
- package/dist/{toolgun-CFCNO00q.js → toolgun-COu_5SxS.js} +202 -542
- 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/{world-BljtS6Fb.js → world-BDhBihjW.js} +114 -139
- package/dist/world-BDhBihjW.js.map +1 -0
- package/docs/api-reference.md +201 -0
- package/package.json +23 -6
- package/dist/physics-CA1abDCY.js +0 -476
- package/dist/physics-CA1abDCY.js.map +0 -1
- package/dist/toolgun/c12Outlets.d.ts +0 -36
- package/dist/toolgun-CFCNO00q.js.map +0 -1
- package/dist/world-BljtS6Fb.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { JointRegistryContext, cloneKhrBundle, isJointOpen, toggleDrivenJoint, useKhrGlb } from "@khr3/core";
|
|
4
|
-
import {
|
|
4
|
+
import { STEP_METRES, canPlace, latticePose, poseEq, poseToFloat, snapPose, socketFor, worldSockets, wrapYaw } from "@khr3/c12";
|
|
5
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 { c as useKolmoGame, d as KolmoVehicle, l as KolmoProp } from "./world-
|
|
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 = [
|
|
@@ -557,354 +557,26 @@ function createToolgunStore() {
|
|
|
557
557
|
}));
|
|
558
558
|
}
|
|
559
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
|
-
}
|
|
902
560
|
// src/toolgun/Toolgun.tsx
|
|
903
561
|
var LCD_W = 256;
|
|
904
562
|
var LCD_H = 192;
|
|
905
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
|
+
});
|
|
906
578
|
/**
|
|
907
|
-
* Measures grip, muzzle, and LCD bezel sockets on an already-cloned viewmodel scene
|
|
579
|
+
* Measures grip, muzzle, and optional LCD bezel (`screen_rect` / `lcd_screen`) sockets on an already-cloned viewmodel scene.
|
|
908
580
|
* Offsets the LCD quad 1mm along `screen_rect`'s local +Z normal in root space so arbitrary bezel orientations never z-fight.
|
|
909
581
|
*/
|
|
910
582
|
function measureToolgunViewmodel(clonedScene) {
|
|
@@ -922,18 +594,7 @@ function measureToolgunViewmodel(clonedScene) {
|
|
|
922
594
|
.04,
|
|
923
595
|
-.24
|
|
924
596
|
];
|
|
925
|
-
let
|
|
926
|
-
0,
|
|
927
|
-
.068,
|
|
928
|
-
.095
|
|
929
|
-
];
|
|
930
|
-
let screenQuat = [
|
|
931
|
-
0,
|
|
932
|
-
0,
|
|
933
|
-
0,
|
|
934
|
-
1
|
|
935
|
-
];
|
|
936
|
-
let screenSize = [.068, .051];
|
|
597
|
+
let screen = null;
|
|
937
598
|
const tmpPos = new THREE.Vector3();
|
|
938
599
|
const tmpQuat = new THREE.Quaternion();
|
|
939
600
|
const tmpPlaneRot = new THREE.Quaternion();
|
|
@@ -942,7 +603,7 @@ function measureToolgunViewmodel(clonedScene) {
|
|
|
942
603
|
const tmpScale = new THREE.Vector3();
|
|
943
604
|
clonedScene.traverse((node) => {
|
|
944
605
|
const low = node.name.toLowerCase();
|
|
945
|
-
if (low === "ik_palm_primary" || low === "grip" || low === "socket_grip") {
|
|
606
|
+
if (low === "ik_palm_primary" || low === "grip" || low === "socket_grip" || low === "piezo_grip") {
|
|
946
607
|
node.getWorldPosition(tmpPos).applyMatrix4(invRoot);
|
|
947
608
|
grip = [
|
|
948
609
|
-tmpPos.x,
|
|
@@ -964,6 +625,7 @@ function measureToolgunViewmodel(clonedScene) {
|
|
|
964
625
|
const sy = Math.abs(rootScale.y) > 1e-6 ? Math.abs(tmpScale.y / rootScale.y) : 1;
|
|
965
626
|
const sz = Math.abs(rootScale.z) > 1e-6 ? Math.abs(tmpScale.z / rootScale.z) : 1;
|
|
966
627
|
const mesh = node;
|
|
628
|
+
let screenSize = [.068, .051];
|
|
967
629
|
tmpPlaneRot.identity();
|
|
968
630
|
if (mesh.isMesh && mesh.geometry) {
|
|
969
631
|
mesh.geometry.computeBoundingBox();
|
|
@@ -986,26 +648,27 @@ function measureToolgunViewmodel(clonedScene) {
|
|
|
986
648
|
}
|
|
987
649
|
tmpQuat.multiply(tmpPlaneRot).normalize();
|
|
988
650
|
tmpNormal.set(0, 0, 1).applyQuaternion(tmpQuat);
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
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
|
+
};
|
|
1000
665
|
}
|
|
1001
666
|
});
|
|
1002
667
|
return {
|
|
1003
668
|
scene: clonedScene,
|
|
1004
669
|
gripOffset: grip,
|
|
1005
670
|
muzzleLocal: muzzle,
|
|
1006
|
-
|
|
1007
|
-
screenQuat,
|
|
1008
|
-
screenSize
|
|
671
|
+
screen
|
|
1009
672
|
};
|
|
1010
673
|
}
|
|
1011
674
|
function createLcdSurface() {
|
|
@@ -1070,85 +733,6 @@ function createLcdSurface() {
|
|
|
1070
733
|
}
|
|
1071
734
|
};
|
|
1072
735
|
}
|
|
1073
|
-
function DefaultToolgunMesh({ accentColor, lcdTexture }) {
|
|
1074
|
-
return /* @__PURE__ */ jsxs("group", { children: [
|
|
1075
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1076
|
-
position: [
|
|
1077
|
-
0,
|
|
1078
|
-
.032,
|
|
1079
|
-
-.04
|
|
1080
|
-
],
|
|
1081
|
-
castShadow: true,
|
|
1082
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
1083
|
-
.056,
|
|
1084
|
-
.062,
|
|
1085
|
-
.22
|
|
1086
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1087
|
-
color: "#1e293b",
|
|
1088
|
-
metalness: .65,
|
|
1089
|
-
roughness: .32
|
|
1090
|
-
})]
|
|
1091
|
-
}),
|
|
1092
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1093
|
-
position: [
|
|
1094
|
-
0,
|
|
1095
|
-
.038,
|
|
1096
|
-
-.2
|
|
1097
|
-
],
|
|
1098
|
-
rotation: [
|
|
1099
|
-
Math.PI / 2,
|
|
1100
|
-
0,
|
|
1101
|
-
0
|
|
1102
|
-
],
|
|
1103
|
-
castShadow: true,
|
|
1104
|
-
children: [/* @__PURE__ */ jsx("cylinderGeometry", { args: [
|
|
1105
|
-
.014,
|
|
1106
|
-
.018,
|
|
1107
|
-
.14,
|
|
1108
|
-
12
|
|
1109
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1110
|
-
color: accentColor,
|
|
1111
|
-
emissive: accentColor,
|
|
1112
|
-
emissiveIntensity: .45,
|
|
1113
|
-
metalness: .8,
|
|
1114
|
-
roughness: .2
|
|
1115
|
-
})]
|
|
1116
|
-
}),
|
|
1117
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1118
|
-
position: [
|
|
1119
|
-
0,
|
|
1120
|
-
-.042,
|
|
1121
|
-
.03
|
|
1122
|
-
],
|
|
1123
|
-
rotation: [
|
|
1124
|
-
.24,
|
|
1125
|
-
0,
|
|
1126
|
-
0
|
|
1127
|
-
],
|
|
1128
|
-
castShadow: true,
|
|
1129
|
-
children: [/* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
1130
|
-
.042,
|
|
1131
|
-
.11,
|
|
1132
|
-
.048
|
|
1133
|
-
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
1134
|
-
color: "#0f172a",
|
|
1135
|
-
roughness: .75,
|
|
1136
|
-
metalness: .2
|
|
1137
|
-
})]
|
|
1138
|
-
}),
|
|
1139
|
-
/* @__PURE__ */ jsxs("mesh", {
|
|
1140
|
-
position: [
|
|
1141
|
-
0,
|
|
1142
|
-
.052,
|
|
1143
|
-
.072
|
|
1144
|
-
],
|
|
1145
|
-
children: [/* @__PURE__ */ jsx("planeGeometry", { args: [.064, .048] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
1146
|
-
...lcdTexture ? { map: lcdTexture } : { color: accentColor },
|
|
1147
|
-
toneMapped: false
|
|
1148
|
-
})]
|
|
1149
|
-
})
|
|
1150
|
-
] });
|
|
1151
|
-
}
|
|
1152
736
|
var SpawnedToolgunOutlet = React.memo(function SpawnedToolgunOutlet({ entry }) {
|
|
1153
737
|
const userData = useMemo(() => ({
|
|
1154
738
|
kolmoSpawnedId: entry.id,
|
|
@@ -1164,6 +748,7 @@ var SpawnedToolgunOutlet = React.memo(function SpawnedToolgunOutlet({ entry }) {
|
|
|
1164
748
|
userData
|
|
1165
749
|
});
|
|
1166
750
|
return /* @__PURE__ */ jsx(KolmoProp, {
|
|
751
|
+
id: entry.id,
|
|
1167
752
|
...entry.bundle ? { bundle: entry.bundle } : {},
|
|
1168
753
|
...entry.src ? { src: entry.src } : {},
|
|
1169
754
|
fixed: entry.fixed,
|
|
@@ -1172,12 +757,75 @@ var SpawnedToolgunOutlet = React.memo(function SpawnedToolgunOutlet({ entry }) {
|
|
|
1172
757
|
rigidBodyProps
|
|
1173
758
|
});
|
|
1174
759
|
});
|
|
760
|
+
var PlacedC12Outlet = React.memo(function PlacedC12Outlet({ piece, bundle, src }) {
|
|
761
|
+
const flt = useMemo(() => poseToFloat(piece.pose), [piece.pose]);
|
|
762
|
+
const userData = useMemo(() => ({
|
|
763
|
+
kolmoPlacedPieceId: piece.id,
|
|
764
|
+
name: piece.kind
|
|
765
|
+
}), [piece.id, piece.kind]);
|
|
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,
|
|
772
|
+
position: flt.position,
|
|
773
|
+
quaternion: flt.quaternion,
|
|
774
|
+
rigidBodyProps
|
|
775
|
+
});
|
|
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
|
|
786
|
+
});
|
|
787
|
+
return _ghostValidMat;
|
|
788
|
+
}
|
|
789
|
+
if (!_ghostInvalidMat) _ghostInvalidMat = new THREE.MeshBasicMaterial({
|
|
790
|
+
color: "#ef4444",
|
|
791
|
+
transparent: true,
|
|
792
|
+
opacity: .38,
|
|
793
|
+
depthWrite: false
|
|
794
|
+
});
|
|
795
|
+
return _ghostInvalidMat;
|
|
796
|
+
}
|
|
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]);
|
|
810
|
+
return /* @__PURE__ */ jsx("group", {
|
|
811
|
+
position: candidate.position,
|
|
812
|
+
quaternion: candidate.quaternion,
|
|
813
|
+
children: /* @__PURE__ */ jsx("primitive", { object: ghostRoot })
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
function C12UrlGhostPreview({ candidate, src }) {
|
|
817
|
+
const bundle = useKhrGlb(src);
|
|
818
|
+
return /* @__PURE__ */ jsx(C12BundleGhostPreview, {
|
|
819
|
+
candidate,
|
|
820
|
+
bundle
|
|
821
|
+
});
|
|
822
|
+
}
|
|
1175
823
|
var _camPos = new THREE.Vector3();
|
|
1176
824
|
var _camDir = new THREE.Vector3();
|
|
1177
825
|
var _muzzleWorld = new THREE.Vector3();
|
|
1178
826
|
var _beamEndVec = new THREE.Vector3();
|
|
1179
827
|
var _targetOffset = new THREE.Vector3();
|
|
1180
|
-
function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACCENT_HEX, defaultArmedAsset, maxRangeM = 75, hipOffset = [
|
|
828
|
+
function ToolgunCore({ ref, viewmodelBundle, c12Bundles, c12Urls, actorRef, accentColor = DEFAULT_ACCENT_HEX, defaultArmedAsset, maxRangeM = 75, hipOffset = [
|
|
1181
829
|
.24,
|
|
1182
830
|
-.21,
|
|
1183
831
|
-.42
|
|
@@ -1186,6 +834,10 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1186
834
|
-.055,
|
|
1187
835
|
-.22
|
|
1188
836
|
], enableShortcuts = true, mountWorldOutlets = true, enable = true }) {
|
|
837
|
+
const resolvedC12Urls = useMemo(() => c12Urls === null ? {} : {
|
|
838
|
+
...DEFAULT_VAULT_C12_URLS,
|
|
839
|
+
...c12Urls
|
|
840
|
+
}, [c12Urls]);
|
|
1189
841
|
const { rapier, world: rapierWorld } = useRapier();
|
|
1190
842
|
const camera = useThree((s) => s.camera);
|
|
1191
843
|
const gl = useThree((s) => s.gl);
|
|
@@ -1211,11 +863,6 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1211
863
|
const beamTimerRef = useRef(0);
|
|
1212
864
|
const beamMatRef = useRef(null);
|
|
1213
865
|
const rayScratchRef = useRef(null);
|
|
1214
|
-
const fallbackPtRef = useRef([
|
|
1215
|
-
0,
|
|
1216
|
-
0,
|
|
1217
|
-
0
|
|
1218
|
-
]);
|
|
1219
866
|
const beamGeo = useMemo(() => {
|
|
1220
867
|
const g = new THREE.BufferGeometry();
|
|
1221
868
|
g.setAttribute("position", new THREE.Float32BufferAttribute([
|
|
@@ -1246,9 +893,13 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1246
893
|
}, [beamLine]);
|
|
1247
894
|
useEffect(() => () => beamGeo.dispose(), [beamGeo]);
|
|
1248
895
|
const resolvePlayerBody = useCallback(() => {
|
|
1249
|
-
|
|
1250
|
-
return
|
|
1251
|
-
}, [
|
|
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
|
+
]);
|
|
1252
903
|
const findJointForBody = useCallback((body) => {
|
|
1253
904
|
if (!body || !jointRegistry) return null;
|
|
1254
905
|
for (const rt of jointRegistry) if (!rt.detached && rt.childBody?.handle === body.handle) return rt;
|
|
@@ -1260,39 +911,18 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1260
911
|
const st = useToolgunStore.getState();
|
|
1261
912
|
const playerBody = resolvePlayerBody();
|
|
1262
913
|
const rawHit = castToolgunRay(rapier, rapierWorld, _camPos, _camDir, maxRangeM, playerBody);
|
|
1263
|
-
|
|
1264
|
-
_camPos.x + _camDir.x *
|
|
1265
|
-
|
|
1266
|
-
_camPos.z + _camDir.z *
|
|
1267
|
-
];
|
|
1268
|
-
if (_camDir.y < -.02 && _camPos.y > 0) {
|
|
1269
|
-
const tGround = -_camPos.y / _camDir.y;
|
|
1270
|
-
if (tGround > .1 && tGround <= maxRangeM) fallbackPoint = [
|
|
1271
|
-
_camPos.x + _camDir.x * tGround,
|
|
1272
|
-
0,
|
|
1273
|
-
_camPos.z + _camDir.z * tGround
|
|
1274
|
-
];
|
|
1275
|
-
}
|
|
1276
|
-
const aimPoint = rawHit ? rawHit.point : fallbackPoint;
|
|
1277
|
-
const aimNormal = rawHit ? rawHit.normal : [
|
|
1278
|
-
0,
|
|
1279
|
-
1,
|
|
1280
|
-
0
|
|
914
|
+
const missEnd = [
|
|
915
|
+
_camPos.x + _camDir.x * maxRangeM,
|
|
916
|
+
_camPos.y + _camDir.y * maxRangeM,
|
|
917
|
+
_camPos.z + _camDir.z * maxRangeM
|
|
1281
918
|
];
|
|
919
|
+
const aimPoint = rawHit ? rawHit.point : missEnd;
|
|
1282
920
|
recoilRef.current = 1;
|
|
1283
921
|
beamTimerRef.current = .09;
|
|
1284
922
|
_beamEndVec.set(aimPoint[0], aimPoint[1], aimPoint[2]);
|
|
1285
|
-
if (holderRef.current) {
|
|
1286
|
-
const mLocal = measured
|
|
1287
|
-
|
|
1288
|
-
.038,
|
|
1289
|
-
-.26
|
|
1290
|
-
];
|
|
1291
|
-
const gOff = measured?.gripOffset ?? [
|
|
1292
|
-
0,
|
|
1293
|
-
0,
|
|
1294
|
-
0
|
|
1295
|
-
];
|
|
923
|
+
if (holderRef.current && measured) {
|
|
924
|
+
const mLocal = measured.muzzleLocal;
|
|
925
|
+
const gOff = measured.gripOffset;
|
|
1296
926
|
_muzzleWorld.set(mLocal[0] + gOff[0], mLocal[1] + gOff[1], mLocal[2] + gOff[2]).applyMatrix4(holderRef.current.matrixWorld);
|
|
1297
927
|
} else _muzzleWorld.copy(_camPos).addScaledVector(_camDir, .35);
|
|
1298
928
|
const posAttr = beamGeo.getAttribute("position");
|
|
@@ -1300,6 +930,23 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1300
930
|
posAttr.setXYZ(1, _beamEndVec.x, _beamEndVec.y, _beamEndVec.z);
|
|
1301
931
|
posAttr.needsUpdate = true;
|
|
1302
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
|
+
}
|
|
1303
950
|
if (st.mode === "spawn") {
|
|
1304
951
|
const asset = st.armedAsset;
|
|
1305
952
|
if (!asset || !asset.bundle && !asset.src) {
|
|
@@ -1307,10 +954,10 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1307
954
|
return {
|
|
1308
955
|
ok: false,
|
|
1309
956
|
status: "NO ASSET ARMED",
|
|
1310
|
-
beamEnd:
|
|
957
|
+
beamEnd: rawHit.point
|
|
1311
958
|
};
|
|
1312
959
|
}
|
|
1313
|
-
const pose = computeAlignedSpawnPose(
|
|
960
|
+
const pose = computeAlignedSpawnPose(rawHit.point, st.yaw12, rawHit.normal, .08);
|
|
1314
961
|
const isVehicle = asset.kind === "vehicle" || asset.kind !== "prop" && Boolean(asset.bundle && (asset.bundle.wheels.length > 0 || asset.bundle.propellers.length > 0));
|
|
1315
962
|
const id = `tg_ent_${Date.now().toString(36)}_${st.fireCount}`;
|
|
1316
963
|
st.recordSpawn({
|
|
@@ -1326,11 +973,19 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1326
973
|
return {
|
|
1327
974
|
ok: true,
|
|
1328
975
|
status: `SPAWNED ${asset.name}`,
|
|
1329
|
-
beamEnd:
|
|
976
|
+
beamEnd: rawHit.point
|
|
1330
977
|
};
|
|
1331
978
|
}
|
|
1332
979
|
if (st.mode === "build") {
|
|
1333
|
-
|
|
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);
|
|
1334
989
|
const placed = st.placeBuildPiece(candidate);
|
|
1335
990
|
return {
|
|
1336
991
|
ok: placed !== null,
|
|
@@ -1339,13 +994,13 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1339
994
|
};
|
|
1340
995
|
}
|
|
1341
996
|
if (st.mode === "rig") {
|
|
1342
|
-
const hitJoint = findJointForBody(rawHit
|
|
997
|
+
const hitJoint = findJointForBody(rawHit.body);
|
|
1343
998
|
if (!hitJoint) {
|
|
1344
999
|
st.bumpFire("NO KHR JOINT HIT");
|
|
1345
1000
|
return {
|
|
1346
1001
|
ok: false,
|
|
1347
1002
|
status: "NO KHR JOINT HIT",
|
|
1348
|
-
beamEnd:
|
|
1003
|
+
beamEnd: rawHit.point
|
|
1349
1004
|
};
|
|
1350
1005
|
}
|
|
1351
1006
|
const status = rigJointRuntime(hitJoint, shiftKey);
|
|
@@ -1353,17 +1008,17 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1353
1008
|
return {
|
|
1354
1009
|
ok: true,
|
|
1355
1010
|
status,
|
|
1356
|
-
beamEnd:
|
|
1011
|
+
beamEnd: rawHit.point
|
|
1357
1012
|
};
|
|
1358
1013
|
}
|
|
1359
1014
|
if (st.mode === "weld" || st.mode === "hinge") {
|
|
1360
|
-
if (!rawHit
|
|
1015
|
+
if (!rawHit.body) {
|
|
1361
1016
|
st.setPendingAnchor(null);
|
|
1362
1017
|
st.bumpFire("MISS — CLEARED ANCHOR");
|
|
1363
1018
|
return {
|
|
1364
1019
|
ok: false,
|
|
1365
1020
|
status: "MISS — CLEARED ANCHOR",
|
|
1366
|
-
beamEnd:
|
|
1021
|
+
beamEnd: rawHit.point
|
|
1367
1022
|
};
|
|
1368
1023
|
}
|
|
1369
1024
|
const pending = st.pendingAnchor;
|
|
@@ -1381,7 +1036,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1381
1036
|
return {
|
|
1382
1037
|
ok: true,
|
|
1383
1038
|
status: `LOCKED A: ${label}`,
|
|
1384
|
-
beamEnd:
|
|
1039
|
+
beamEnd: rawHit.point
|
|
1385
1040
|
};
|
|
1386
1041
|
}
|
|
1387
1042
|
if (liveBodyA.handle === rawHit.body.handle) {
|
|
@@ -1390,7 +1045,7 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1390
1045
|
return {
|
|
1391
1046
|
ok: false,
|
|
1392
1047
|
status: "SAME BODY — CANCELLED",
|
|
1393
|
-
beamEnd:
|
|
1048
|
+
beamEnd: rawHit.point
|
|
1394
1049
|
};
|
|
1395
1050
|
}
|
|
1396
1051
|
const anchorMid = [
|
|
@@ -1414,38 +1069,30 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1414
1069
|
beamEnd: anchorMid
|
|
1415
1070
|
};
|
|
1416
1071
|
}
|
|
1417
|
-
if (!rawHit) {
|
|
1418
|
-
st.bumpFire("NOTHING HIT");
|
|
1419
|
-
return {
|
|
1420
|
-
ok: false,
|
|
1421
|
-
status: "NOTHING HIT",
|
|
1422
|
-
beamEnd: aimPoint
|
|
1423
|
-
};
|
|
1424
|
-
}
|
|
1425
1072
|
const ud = rawHit.body?.userData ?? {};
|
|
1426
1073
|
if (ud.kolmoPlacedPieceId && st.removePieceById(ud.kolmoPlacedPieceId)) return {
|
|
1427
1074
|
ok: true,
|
|
1428
1075
|
status: `REMOVED ${ud.kolmoPlacedPieceId}`,
|
|
1429
|
-
beamEnd:
|
|
1076
|
+
beamEnd: rawHit.point
|
|
1430
1077
|
};
|
|
1431
1078
|
if (ud.kolmoSpawnedId && st.removeEntityById(ud.kolmoSpawnedId, rapierWorld)) return {
|
|
1432
1079
|
ok: true,
|
|
1433
1080
|
status: `DELETED ${ud.kolmoSpawnedId}`,
|
|
1434
|
-
beamEnd:
|
|
1081
|
+
beamEnd: rawHit.point
|
|
1435
1082
|
};
|
|
1436
1083
|
if (rawHit.body) {
|
|
1437
1084
|
const removedJoints = st.removeJointByBody(rapierWorld, rawHit.body);
|
|
1438
1085
|
if (removedJoints > 0) return {
|
|
1439
1086
|
ok: true,
|
|
1440
1087
|
status: `REMOVED ${removedJoints} JOINT(S)`,
|
|
1441
|
-
beamEnd:
|
|
1088
|
+
beamEnd: rawHit.point
|
|
1442
1089
|
};
|
|
1443
1090
|
}
|
|
1444
1091
|
st.bumpFire("STATIC WORLD TARGET");
|
|
1445
1092
|
return {
|
|
1446
1093
|
ok: false,
|
|
1447
1094
|
status: "STATIC WORLD TARGET",
|
|
1448
|
-
beamEnd:
|
|
1095
|
+
beamEnd: rawHit.point
|
|
1449
1096
|
};
|
|
1450
1097
|
}, [
|
|
1451
1098
|
camera,
|
|
@@ -1456,7 +1103,10 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1456
1103
|
findJointForBody,
|
|
1457
1104
|
measured,
|
|
1458
1105
|
beamGeo,
|
|
1459
|
-
beamLine
|
|
1106
|
+
beamLine,
|
|
1107
|
+
mountWorldOutlets,
|
|
1108
|
+
c12Bundles,
|
|
1109
|
+
resolvedC12Urls
|
|
1460
1110
|
]);
|
|
1461
1111
|
useImperativeHandle(ref, () => ({
|
|
1462
1112
|
fire,
|
|
@@ -1560,20 +1210,8 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1560
1210
|
const ud = hit.body?.userData ?? {};
|
|
1561
1211
|
targetLabel = `${jRt ? `JOINT:${jRt.nodeName}` : ud.name ?? ud.kolmoPlacedPieceId ?? ud.kolmoSpawnedId ?? "SURFACE"} (${hit.toi.toFixed(1)}m)`;
|
|
1562
1212
|
}
|
|
1563
|
-
if (st.mode === "build") {
|
|
1564
|
-
const
|
|
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;
|
|
1568
|
-
if (!hit && _camDir.y < -.02 && _camPos.y > 0) {
|
|
1569
|
-
const tFloor = -_camPos.y / _camDir.y;
|
|
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
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
const cand = computeBuildCandidate(st.placedPieces, hit ? hit.point : fb, st.buildKind, st.yaw12);
|
|
1213
|
+
if (st.mode === "build" && hit) {
|
|
1214
|
+
const cand = computeBuildCandidate(st.placedPieces, hit.point, st.buildKind, st.yaw12);
|
|
1577
1215
|
if (!isSameBuildPreview(st.buildPreview, cand)) st.setBuildPreview(cand);
|
|
1578
1216
|
} else if (st.buildPreview !== null) st.setBuildPreview(null);
|
|
1579
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`;
|
|
@@ -1586,34 +1224,56 @@ function ToolgunCore({ ref, viewmodelBundle, actorRef, accentColor = DEFAULT_ACC
|
|
|
1586
1224
|
accentColor
|
|
1587
1225
|
});
|
|
1588
1226
|
});
|
|
1227
|
+
const ghostBundle = buildPreview ? c12Bundles?.[buildPreview.kind] : void 0;
|
|
1228
|
+
const ghostUrl = buildPreview && !ghostBundle ? resolvedC12Urls[buildPreview.kind] : void 0;
|
|
1589
1229
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1590
|
-
createPortal(/* @__PURE__ */ jsx("group", {
|
|
1230
|
+
measured && createPortal(/* @__PURE__ */ jsx("group", {
|
|
1591
1231
|
ref: holderRef,
|
|
1592
1232
|
position: [
|
|
1593
1233
|
hipOffset[0],
|
|
1594
1234
|
hipOffset[1],
|
|
1595
1235
|
hipOffset[2]
|
|
1596
1236
|
],
|
|
1597
|
-
children:
|
|
1237
|
+
children: /* @__PURE__ */ jsxs("group", {
|
|
1598
1238
|
position: measured.gripOffset,
|
|
1599
|
-
children: [/* @__PURE__ */ jsx("primitive", { object: measured.scene }), /* @__PURE__ */ jsxs("mesh", {
|
|
1600
|
-
position: measured.
|
|
1601
|
-
quaternion: measured.
|
|
1602
|
-
children: [/* @__PURE__ */ jsx("planeGeometry", { args: measured.
|
|
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", {
|
|
1603
1243
|
...lcd.texture ? { map: lcd.texture } : { color: accentColor },
|
|
1604
1244
|
toneMapped: false
|
|
1605
1245
|
})]
|
|
1606
1246
|
})]
|
|
1607
|
-
}) : /* @__PURE__ */ jsx(DefaultToolgunMesh, {
|
|
1608
|
-
accentColor,
|
|
1609
|
-
lcdTexture: lcd.texture
|
|
1610
1247
|
})
|
|
1611
1248
|
}), camera),
|
|
1612
1249
|
/* @__PURE__ */ jsx("primitive", { object: beamLine }),
|
|
1613
|
-
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),
|
|
1614
1260
|
mountWorldOutlets && /* @__PURE__ */ jsxs("group", {
|
|
1615
1261
|
name: "kolmo_toolgun_outlets",
|
|
1616
|
-
children: [spawnedEntities.map((entry) => /* @__PURE__ */ jsx(
|
|
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
|
+
})]
|
|
1617
1277
|
})
|
|
1618
1278
|
] });
|
|
1619
1279
|
}
|
|
@@ -1635,6 +1295,6 @@ function KolmoToolgun({ src, bundle, ...rest }) {
|
|
|
1635
1295
|
viewmodelBundle: cloned
|
|
1636
1296
|
});
|
|
1637
1297
|
}
|
|
1638
|
-
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 };
|
|
1639
1299
|
|
|
1640
|
-
//# sourceMappingURL=toolgun-
|
|
1300
|
+
//# sourceMappingURL=toolgun-COu_5SxS.js.map
|