Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
perf(verse): draw the first-person viewmodel as one skinned mesh, reframe hip and sprint, index finger on the trigger (#914)
Ruben Lütke0b8c4c0c6b9c
diff --git a/docs/verse/realtime.md b/docs/verse/realtime.mdindex 9c0203e57c..6a2f01196a 100644--- a/docs/verse/realtime.md+++ b/docs/verse/realtime.md@@ -271,8 +271,9 @@ blaster in the right hand with the left supporting it. Code:| File | Role ||---|---|| `motion.ts` | Pure: who is drawn (`viewmodelVisibility`: arms in exactly where the third-person body goes out, past 30 % of the blend; the body also goes when a wall pushes the shoulder camera within 0.55 m), the walk bob (a dip per footfall, a sway per stride, scaled by ground speed / walk speed up to 1.7), idle breathing, look lag (the arms trail a turn by up to 0.07 rad and settle in ~0.1 s) and the recoil spring (a shot kicks the blaster back ~2 cm and the muzzle up ~2.5°, settling in ~0.25 s). prefers-reduced-motion drops bob, sway and lag and halves the recoil. |-| `arms.ts` | The arms, procedural: sleeves in the commander's uniform colour (the rank tier's `M_Uniform`), a gauntleted glove (rounded palm, armoured knuckle plate, a panel in the uniform's trim, two-segment lathe-turned fingers and thumb that curl by a parameter), two-bone IK from shoulder to wrist (`solveElbow`), the forearm turned so its back follows the back of the hand. The left forearm carries the shield emitter. |-| `viewmodel.ts` | The rig, its own scene and camera, posed every frame in the camera's space; the layout (`VIEWMODEL`: poses, holds, shoulders, field of view, light). |+| `arms.ts` | The arms, procedural: sleeves in the commander's uniform colour (the rank tier's `M_Uniform`), a gauntleted glove (rounded palm, armoured knuckle plate, a panel in the uniform's trim, two-segment lathe-turned fingers and thumb), a hand pose (`HandPose`: the three outer fingers, the index finger and the thumb apart, so the right index rests on the trigger), two-bone IK from shoulder to wrist (`solveElbow`), the forearm turned so its back follows the back of the hand. The left forearm carries the shield emitter. |+| `viewmodel.ts` | The rig, its own scene and camera, posed every frame in the camera's space; the layout (`VIEWMODEL`: poses, holds, hand poses, shoulders, field of view, light). |+| `rigMesh.ts` | One draw for the whole rig: `RigBuilder` bakes every part into one skinned geometry on its bone, `RigPalette` holds every surface as a texel of three float textures under one material; `chamferBox` (44 triangles). || `viewmodelPass.ts` | The draw: a pass in the eye view's post chain after the deck's render pass, into the same multisampled HDR target with depth cleared first (so the arms get the deck's anti-aliasing, bloom and AgX and never meet a wall); on the low tier the same draw straight to the screen. No full-screen pass of its own. || `ViewmodelLayer.tsx` | Mounts the viewmodel on a stage with an eye-level view (`runtime.viewmodel`) and tells it each frame what to show: the deck's hands, the duel's blaster, or nothing. |@@ -287,16 +288,29 @@ it reads the same on every deck) keeps dark uniforms and gloves legible.In a duel the blaster is the duel's own model (`buildBlaster`, chamferededges for the close view, the stock left out so it never hides the righthand, the sight's glowing pane swapped for a see-through reticle). Poses,-blended over ~0.1 s: hip (bottom right, canted in), sights (`ads` moves the-sight's window onto the view axis 0.3 m ahead; the field of view narrows),-sprint (carried low and turned in), shield (Q: the blaster drops, the left+blended over ~0.1 s: hip (low on the right, the right hand on the grip with+the index finger on the trigger, the support arm coming up from the bottom+edge; the centre of the screen and its left half stay clear), sights (`ads`+moves the sight's window onto the view axis 0.3 m ahead; the field of view+narrows), sprint (lowered, turned in and canted across the bottom of the+frame, still in view), shield (Q: the blaster drops, the leftforearm comes up before the face, palm forward, its emitter lit with theshield's energy and flaring on a parry), vent (R: the blaster tips up and theleft hand slaps the receiver's side), knocked out (the arms drop away). Adodge dips the arms. Each shot kicks the recoil spring and flashes at themuzzle (a sprite and a short light on the hands); the world's own muzzle-flash and vent steam for the person are skipped in first person. About-6,500 triangles and ~65 small draws in a duel (fewer on the deck); the world pass is unchanged.+flash and vent steam for the person are skipped in first person.++Budget: both arms and the blaster are one skinned mesh (`rigMesh.ts`): every+rigid part is baked into one geometry with each vertex bound at full weight+to the bone it moves with (sleeves, forearm, gauntlet, hand, each finger+segment, the blaster), and every surface is a texel of a small float palette+(albedo, roughness and metalness, emission) under one material. The+blaster's glowing parts copy its heat colours into the palette each frame;+on the deck its vertices collapse to a point. That is one draw on the deck+and two or three in a duel (the rig, the sight's reticle, the muzzle flash),+about 2,900 triangles (chamfered boxes are 44 triangles each). The rig test+holds it to 3 draws and 3,000 triangles.Development handle (dev builds only): `window.__verseViewmodel = { layout,arm, motion, retune(), viewmodel }` tunes the layout live: change `layout`@@ -378,8 +392,9 @@ packing rebuild the bridge's pages held 3-15 %. The bridge numbers in## Open work-- The viewmodel's arms are procedural (no skinned mesh): the fingers curl as- one per hand, there is no reload or inspect animation beyond the vent slap.+- The viewmodel's arms are procedural rigid parts on bones (no authored skin+ weights, so joints do not bend their surfaces); there is no reload or+ inspect animation beyond the vent slap.- There are no strafe or backwards clips: strafing leans the walk up to 45°,backwards plays the walk in reverse.diff --git a/dodaios/ui/web/frontend/src/components/society/verse/duel/blaster.ts b/dodaios/ui/web/frontend/src/components/society/verse/duel/blaster.tsindex ec0d6dfae9..ef796d7fe8 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/duel/blaster.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/duel/blaster.ts@@ -12,7 +12,7 @@import {BoxGeometry, Color, CylinderGeometry, Group, Mesh, MeshStandardMaterial, TorusGeometry, Vector3, type BufferGeometry, type Material,} from "three";-import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";+import { chamferBox } from "../viewmodel/rigMesh";export interface Blaster {group: Group;@@ -78,7 +78,7 @@ export function buildBlaster(accent: Color, options: BlasterOptions = {}): Blastreturn m;};const box = (w: number, h: number, d: number): BufferGeometry =>- options.bevel ? new RoundedBoxGeometry(w, h, d, 1, Math.min(w, h, d) * 0.22) : new BoxGeometry(w, h, d);+ options.bevel ? chamferBox(w, h, d, Math.min(w, h, d) * 0.22) : new BoxGeometry(w, h, d);const alongZ = (geo: BufferGeometry) => geo.rotateX(Math.PI / 2);// Receiver: a long, slightly tapered block, a gold spine on top.@@ -90,11 +90,11 @@ export function buildBlaster(accent: Color, options: BlasterOptions = {}): Blastadd(box(0.004, 0.016, 0.17), cells, -0.0295, 0.016, 0.07);// Shroud and barrel: an octagonal sleeve with vents, a slim barrel inside.add(alongZ(new CylinderGeometry(0.026, 0.03, 0.22, 8)), graphite, 0, 0.012, 0.31);- add(alongZ(new CylinderGeometry(0.012, 0.012, 0.3, 10)), steel, 0, 0.012, 0.34);+ add(alongZ(new CylinderGeometry(0.012, 0.012, 0.3, options.bevel ? 8 : 10)), steel, 0, 0.012, 0.34);for (let i = 0; i < 3; i++) add(box(0.03, 0.006, 0.022), vents, 0, 0.04, 0.25 + i * 0.045);add(box(0.006, 0.022, 0.16), gold, 0, -0.018, 0.31);// Emitter ring and muzzle.- add(new TorusGeometry(0.022, 0.005, 6, 16), emitter, 0, 0.012, 0.43);+ add(new TorusGeometry(0.022, 0.005, options.bevel ? 5 : 6, options.bevel ? 12 : 16), emitter, 0, 0.012, 0.43);add(alongZ(new CylinderGeometry(0.02, 0.016, 0.04, 10)), steel, 0, 0.012, 0.47);// Optic: a low rail and a small holographic sight.add(box(0.028, 0.012, 0.08), steel, 0, 0.058, 0.0);diff --git a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/arms.ts b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/arms.tsindex 09f757ea04..2d301ec7f8 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/arms.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/arms.ts@@ -1,15 +1,21 @@/*** The commander's own arms for the first-person viewmodel, built- * procedurally (a few hundred triangles each): an upper arm and a tapered- * forearm in the uniform's cloth, a cuff in the uniform's trim, and a gloved- * hand (palm, knuckle roll, four two-segment fingers and a thumb) whose- * fingers curl by a parameter, so one hand closes around a grip, cradles a- * shroud or hangs loose. The left forearm carries the shield emitter.+ * procedurally: an upper arm and a tapered forearm in the uniform's cloth, a+ * gauntlet with a strap in the uniform's trim, and a gloved hand (palm,+ * knuckle plate, four two-segment fingers and a two-segment thumb). The+ * index finger and the thumb pose apart from the other three fingers, so a+ * hand can hold a grip with the index on the trigger. The left forearm+ * carries the shield emitter.*- * Hand frame (the `hand` group, origin at the wrist): +Z runs to the+ * The arm is a chain of bones (Object3Ds); its parts are not meshes of their+ * own but go into the viewmodel's one skinned mesh (`RigBuilder`), each bound+ * to the bone it moves with, so the whole rig is one draw call.+ *+ * Hand frame (the `hand` bone, origin at the wrist): +Z runs to the* knuckles, +Y is the back of the hand, +X the thumb's side for the right- * hand; the left hand is the same hand mirrored (thumb on −X). Fingers curl- * toward −Y (the palm).+ * hand; the left hand is the same hand mirrored (thumb on −X: its parts are+ * baked mirrored and its finger bones placed mirrored). Fingers curl toward+ * −Y (the palm).** `pose` places the arm for a frame: shoulder, wrist and the hand's frame* given, the elbow is solved by two-bone IK toward a pole (it hangs down and@@ -17,22 +23,24 @@* the emitter) faces the way the back of the hand does.*/import {- BoxGeometry, CapsuleGeometry, CylinderGeometry, Group, LatheGeometry, Matrix4, Mesh, SphereGeometry, TorusGeometry, Vector2, Vector3,- type BufferGeometry, type Material, type Quaternion,+ Bone, CylinderGeometry, Euler, Group, LatheGeometry, Matrix4, Object3D, Quaternion, SphereGeometry, TorusGeometry, Vector2, Vector3,+ type BufferGeometry,} from "three";-import { RoundedBoxGeometry } from "three/examples/jsm/geometries/RoundedBoxGeometry.js";import { solveElbow } from "../duel/figure";+import { chamferBox, type RigBuilder, type Slot } from "./rigMesh";-export interface ArmMaterials {+/** The arm's surfaces in the rig's palette. */+export interface ArmSlots {/** The uniform's cloth (sleeves). */- sleeve: Material;- /** The uniform's trim (the sleeve's cuff band, the glove's seam). */- trim: Material;+ sleeve: Slot;+ /** The uniform's trim (the gauntlet's strap, the panel on the back of the hand). */+ trim: Slot;/** Glove leather. */- glove: Material;- /** The shield emitter's housing and its glowing strip (left forearm only). */- housing: Material;- emitter: Material;+ glove: Slot;+ /** Armour and the shield emitter's housing. */+ housing: Slot;+ /** The shield emitter's glowing strip and lens (left forearm only). */+ emitter: Slot;}export const ARM = {@@ -43,158 +51,188 @@ export const ARM = {rShoulder: 0.05,rElbow: 0.043,rWrist: 0.035,- /** Finger capsule radius and segment lengths. */- finger: 0.0092,+ /** Finger segment lengths. */seg1: 0.042,seg2: 0.036,/** The forearm's sleeve stops this far short of the wrist, inside the glove's gauntlet. */sleeveShort: 0.06,};+/**+ * A hand's pose: the three outer fingers' two joints, the index finger's two joints (radians toward the palm), and+ * the thumb's bend (0 open .. 1 closed) and its swing across the palm (radians).+ */+export interface HandPose {+ fingers: [number, number];+ index: [number, number];+ thumb: [number, number];+}++export function handPose(c1: number, c2: number, thumb: number, index: [number, number] = [c1, c2], across = 0): HandPose {+ return { fingers: [c1, c2], index, thumb: [thumb, across] };+}++/** `out` moved toward `to` by `t` (0..1). */+export function lerpHand(out: HandPose, to: HandPose, t: number): HandPose {+ if (t <= 0) return out;+ for (let i = 0; i < 2; i++) {+ out.fingers[i] += (to.fingers[i] - out.fingers[i]) * t;+ out.index[i] += (to.index[i] - out.index[i]) * t;+ out.thumb[i] += (to.thumb[i] - out.thumb[i]) * t;+ }+ return out;+}++export function copyHand(out: HandPose, from: HandPose): HandPose {+ out.fingers[0] = from.fingers[0];+ out.fingers[1] = from.fingers[1];+ out.index[0] = from.index[0];+ out.index[1] = from.index[1];+ out.thumb[0] = from.thumb[0];+ out.thumb[1] = from.thumb[1];+ return out;+}+const SCRATCH_X = new Vector3();const SCRATCH_Y = new Vector3();const SCRATCH_Z = new Vector3();const SCRATCH_M = new Matrix4();+const M_POS = new Vector3();+const M_SCALE = new Vector3();+const M_Q = new Quaternion();+const M_E = new Euler();++/** A part's placement in its bone's frame: translate, turn (XYZ Euler), scale. */+function at(x: number, y: number, z: number, rx = 0, ry = 0, rz = 0, sx = 1, sy = 1, sz = 1): Matrix4 {+ return new Matrix4().compose(M_POS.set(x, y, z), M_Q.setFromEuler(M_E.set(rx, ry, rz)), M_SCALE.set(sx, sy, sz));+}/*** A finger segment along +Z from the origin: a tube tapering from radius `r0`* to `r1` over `length`, both ends rounded (a lathe-turned profile). Pure.*/-export function fingerSegment(r0: number, r1: number, length: number, radial = 7): LatheGeometry {+export function fingerSegment(r0: number, r1: number, length: number, radial = 6): LatheGeometry {const profile = [- new Vector2(0, 0), new Vector2(r0 * 0.75, r0 * 0.33), new Vector2(r0, r0),- new Vector2(r1, length - r1), new Vector2(r1 * 0.75, length - r1 * 0.33), new Vector2(0, length),+ new Vector2(0, 0), new Vector2(r0 * 0.8, r0 * 0.4), new Vector2(r0, r0 * 1.1),+ new Vector2(r1, length - r1 * 0.9), new Vector2(0, length),];return new LatheGeometry(profile, radial).rotateX(Math.PI / 2);}-/** Position a cuff part along the forearm (y) and squash it to the forearm's oval (x across, z front to back). */-function placed(mesh: Mesh, y: number, sx: number, sz: number): Mesh {- mesh.position.set(0, y, 0);- mesh.scale.set(sx, 1, sz);- return mesh;-}-/** A finger: two segments in a chain, the second hinged at the end of the first. */-interface Finger { base: Group; joint: Group }+interface Finger { base: Bone; joint: Bone }export class ViewArm {readonly group = new Group();/** The hand: place it with `pose`; its children are in the hand frame. */- readonly hand = new Group();+ readonly hand = new Bone();/** The bones (unscaled, turned along shoulder → elbow and elbow → wrist). */- readonly upper = new Group();- readonly fore = new Group();- /** The glove's gauntlet, on the forearm at the wrist. */- private readonly cuff = new Group();- /** The left forearm's emitter strip (null on the right arm). */- readonly emitterStrip: Mesh | null = null;- private readonly upperSleeve: Mesh;- private readonly foreSleeve: Mesh;- private readonly housing: Mesh | null = null;+ readonly upper = new Bone();+ readonly fore = new Bone();+ /** Landmarks in the hand frame (for layout checks): the knuckle plate, and the index finger's tip. */+ readonly knuckles = new Object3D();+ readonly indexTip = new Object3D();+ /** The sleeves (scaled along the bone to its length) and the gauntlet, at the wrist end of the forearm. */+ private readonly upperSleeve = new Bone();+ private readonly foreSleeve = new Bone();+ private readonly cuff = new Bone();+ private readonly housing: Bone | null = null;private readonly fingers: Finger[] = [];private readonly thumb: Finger;- private readonly geometries: BufferGeometry[] = [];+ /** −1 for the left arm: the hand is mirrored. */+ private readonly sx: number;private readonly elbow = new Vector3();private readonly axis = new Vector3();private readonly back = new Vector3();private readonly across = new Vector3();private readonly m4 = new Matrix4();- constructor(readonly side: "left" | "right", mats: ArmMaterials) {+ constructor(readonly side: "left" | "right", rig: RigBuilder, slots: ArmSlots) {this.group.name = `ViewArm_${side}`;- const g = <T extends BufferGeometry>(geo: T): T => { this.geometries.push(geo); return geo; };+ const sx = side === "left" ? -1 : 1;+ this.sx = sx;+ const mirror = sx < 0;+ // In the hand: placed for the right hand, mirrored for the left.+ const handPart = (geo: BufferGeometry, bone: Object3D, slot: Slot, m: Matrix4 | null = null) => rig.add(geo, bone, slot, m, mirror);+// Sleeves: unit-height cylinders along +Y from the joint, scaled to the bone's length by `pose`.- this.upperSleeve = new Mesh(g(new CylinderGeometry(ARM.rElbow, ARM.rShoulder, 1, 12, 1, true).translate(0, 0.5, 0)), mats.sleeve);- this.foreSleeve = new Mesh(g(new CylinderGeometry(ARM.rWrist, ARM.rElbow, 1, 12, 1, true).translate(0, 0.5, 0)), mats.sleeve);this.upper.add(this.upperSleeve);this.fore.add(this.foreSleeve);+ rig.add(new CylinderGeometry(ARM.rElbow, ARM.rShoulder, 1, 10, 1, true).translate(0, 0.5, 0), this.upperSleeve, slots.sleeve);+ rig.add(new CylinderGeometry(ARM.rWrist, ARM.rElbow, 1, 10, 1, true).translate(0, 0.5, 0), this.foreSleeve, slots.sleeve);// An elbow cap closes the joint between the two sleeves (at the forearm's start).- const elbowCap = new Mesh(g(new CapsuleGeometry(ARM.rElbow * 0.98, 0.001, 3, 10)), mats.sleeve);- this.fore.add(elbowCap);+ rig.add(new SphereGeometry(ARM.rElbow * 0.98, 6, 4), this.fore, slots.sleeve);this.group.add(this.upper, this.fore, this.hand);// The glove's gauntlet rides on the forearm (it follows the arm, not the bent wrist): it flares over the sleeve's- // end (the sleeve stops inside it) with a rolled rim and a strap. `pose` puts `cuff` at the wrist.- this.cuff.add(- placed(new Mesh(g(new CylinderGeometry(0.036, 0.0415, 0.08, 18, 1, true).translate(0, -0.04, 0)), mats.glove), 0, 1.08, 0.9),- placed(new Mesh(g(new TorusGeometry(0.0415, 0.0042, 6, 18).rotateX(Math.PI / 2)), mats.glove), -0.08, 1.08, 0.9),- placed(new Mesh(g(new CylinderGeometry(0.0408, 0.0418, 0.012, 18, 1, true)), mats.housing), -0.058, 1.1, 0.92),- );+ // end (the sleeve stops inside it) with a rolled rim and a strap in the trim. `pose` puts `cuff` at the wrist.this.fore.add(this.cuff);- // The wrist: a rounded joint between the gauntlet and the palm.- const wristBall = new Mesh(g(new SphereGeometry(0.031, 10, 7)), mats.glove);- wristBall.position.set(0, -0.002, 0.006);- wristBall.scale.set(1.12, 0.82, 1);- // Palm: a rounded slab; an armoured plate over the knuckles and a panel on the back of the hand.- const palm = new Mesh(g(new RoundedBoxGeometry(0.08, 0.03, 0.084, 2, 0.013)), mats.glove);- palm.position.set(0, 0, 0.05);- const plate = new Mesh(g(new RoundedBoxGeometry(0.07, 0.01, 0.026, 2, 0.0045)), mats.housing);- plate.position.set(0, 0.0145, 0.08);- plate.rotation.set(0.12, 0, 0);- const panel = new Mesh(g(new RoundedBoxGeometry(0.052, 0.006, 0.038, 2, 0.0028)), mats.trim);- panel.position.set(0, 0.0138, 0.042);- this.hand.add(wristBall, palm, plate, panel);+ rig.add(new CylinderGeometry(0.036, 0.0415, 0.08, 12, 1, true), this.cuff, slots.glove, at(0, -0.04, 0, 0, 0, 0, 1.08, 1, 0.9));+ rig.add(new TorusGeometry(0.0415, 0.0042, 4, 12).rotateX(Math.PI / 2), this.cuff, slots.glove, at(0, -0.08, 0, 0, 0, 0, 1.08, 1, 0.9));+ rig.add(new CylinderGeometry(0.0408, 0.0418, 0.012, 12, 1, true), this.cuff, slots.trim, at(0, -0.058, 0, 0, 0, 0, 1.1, 1, 0.92));++ // The wrist: a rounded joint between the gauntlet and the palm. Palm: a chamfered slab; an armoured plate over the+ // knuckles and a panel in the trim on the back of the hand.+ handPart(new SphereGeometry(0.031, 8, 6), this.hand, slots.glove, at(0, -0.002, 0.006, 0, 0, 0, 1.12, 0.82, 1));+ handPart(chamferBox(0.08, 0.03, 0.084, 0.011, true), this.hand, slots.glove, at(0, 0, 0.05));+ handPart(chamferBox(0.07, 0.01, 0.026, 0.004), this.hand, slots.housing, at(0, 0.0145, 0.08, 0.12));+ handPart(chamferBox(0.052, 0.006, 0.038, 0.0025), this.hand, slots.trim, at(0, 0.0138, 0.042));+ this.knuckles.position.set(0, 0.0145, 0.08);+ this.hand.add(this.knuckles);// Fingers: two tapered, round-ended segments each; index on the thumb's side (+X), little finger outside.- const seg1 = g(fingerSegment(0.0098, 0.009, ARM.seg1));- const seg2 = g(fingerSegment(0.009, 0.0078, ARM.seg2));const lengths = [1, 1.08, 1.02, 0.84];const xs = [0.0265, 0.0088, -0.0088, -0.0262];for (let i = 0; i < 4; i++) {- const base = new Group();- base.position.set(xs[i], -0.001, 0.086);- const s1 = new Mesh(seg1, mats.glove);- s1.scale.set(1, 1, lengths[i]);- const joint = new Group();+ const base = new Bone();+ base.position.set(xs[i] * sx, -0.001, 0.086);+ const joint = new Bone();joint.position.set(0, 0, ARM.seg1 * lengths[i] - 0.008);- const s2 = new Mesh(seg2, mats.glove);- s2.scale.set(1, 1, lengths[i]);- joint.add(s2);- base.add(s1, joint);+ base.add(joint);this.hand.add(base);+ handPart(fingerSegment(0.0098, 0.009, ARM.seg1), base, slots.glove, at(0, 0, 0, 0, 0, 0, 1, 1, lengths[i]));+ handPart(fingerSegment(0.009, 0.0078, ARM.seg2), joint, slots.glove, at(0, 0, 0, 0, 0, 0, 1, 1, lengths[i]));this.fingers.push({ base, joint });}+ this.indexTip.position.set(0, -0.004, ARM.seg2 * lengths[0]);+ this.fingers[0].joint.add(this.indexTip);// Thumb: from the heel of the palm on the thumb's side, angled forward and in.- const tb = new Group();- tb.position.set(0.034, -0.007, 0.028);- const t1 = new Mesh(g(fingerSegment(0.0118, 0.0105, 0.042)), mats.glove);- const tj = new Group();+ const tb = new Bone();+ tb.position.set(0.034 * sx, -0.007, 0.028);+ const tj = new Bone();tj.position.set(0, 0, 0.034);- const t2 = new Mesh(g(fingerSegment(0.0105, 0.009, 0.036)), mats.glove);- tj.add(t2);- tb.add(t1, tj);+ tb.add(tj);this.hand.add(tb);+ handPart(fingerSegment(0.0118, 0.0105, 0.042), tb, slots.glove);+ handPart(fingerSegment(0.0105, 0.009, 0.036), tj, slots.glove);this.thumb = { base: tb, joint: tj };if (side === "left") {// The shield emitter: a flat housing along the back of the forearm with a glowing strip and a lens.- const housing = new Mesh(g(new BoxGeometry(0.052, 0.13, 0.02)), mats.housing);- const strip = new Mesh(g(new BoxGeometry(0.012, 0.1, 0.004)), mats.emitter);- strip.position.set(0, -0.005, 0.011);- const lens = new Mesh(g(new CylinderGeometry(0.011, 0.013, 0.006, 12).rotateX(Math.PI / 2)), mats.emitter);- lens.position.set(0, 0.05, 0.012);- housing.add(strip, lens);+ const housing = new Bone();this.fore.add(housing);+ rig.add(chamferBox(0.052, 0.13, 0.02, 0.005), housing, slots.housing);+ rig.add(chamferBox(0.012, 0.1, 0.004, 0.0015), housing, slots.emitter, at(0, -0.005, 0.011));+ rig.add(new CylinderGeometry(0.011, 0.013, 0.006, 10).rotateX(Math.PI / 2), housing, slots.emitter, at(0, 0.05, 0.012));this.housing = housing;- this.emitterStrip = strip;- this.hand.scale.x = -1;}- this.group.traverse((o) => { o.frustumCulled = false; });- this.curl(1.2, 1.1, 0.4);+ this.curl(handPose(1.2, 1.1, 0.4));}- /** Curl the fingers: first and second joints (radians toward the palm), and the thumb's bend (0 open .. 1 closed). */- curl(c1: number, c2: number, thumb: number): void {+ /** Curl the fingers, the index finger and the thumb (see `HandPose`). */+ curl(p: HandPose): void {for (let i = 0; i < this.fingers.length; i++) {const f = this.fingers[i];// The little finger curls a touch more, as a real grip does.const extra = i * 0.05;- f.base.rotation.set(c1 + extra, 0, 0);- f.joint.rotation.set(c2 + extra, 0, 0);+ const c = i === 0 ? p.index : p.fingers;+ f.base.rotation.set(c[0] + extra, 0, 0);+ f.joint.rotation.set(c[1] + extra, 0, 0);}- this.thumb.base.rotation.set(0.35 + thumb * 0.5, -0.55 - thumb * 0.25, 0);- this.thumb.joint.rotation.set(thumb * 0.6, -0.2, 0);+ // The thumb turns about Y and Z too: mirrored for the left hand.+ const [bend, across] = p.thumb;+ this.thumb.base.rotation.set(0.35 + bend * 0.5, (-0.55 - bend * 0.25 - across) * this.sx, 0);+ this.thumb.joint.rotation.set(bend * 0.6, -0.2 * this.sx, 0);}/**@@ -206,16 +244,18 @@ export class ViewArm {this.hand.position.copy(wrist);this.hand.quaternion.copy(handQuat);const elbow = solveElbow(shoulder, wrist, ARM.upper, ARM.fore, pole, this.elbow);- this.place(this.upper, this.upperSleeve, shoulder, elbow, pole);+ const upper = this.place(this.upper, shoulder, elbow, pole);+ this.upperSleeve.scale.set(1, Math.max(0.01, upper), 1);this.back.set(0, 1, 0).applyQuaternion(handQuat);- const length = this.place(this.fore, this.foreSleeve, elbow, wrist, this.back, ARM.sleeveShort);+ const length = this.place(this.fore, elbow, wrist, this.back);+ this.foreSleeve.scale.set(1, Math.max(0.01, length - ARM.sleeveShort), 1);// The emitter lies along the forearm's back, a hand's width short of the wrist.this.cuff.position.set(0, length, 0);if (this.housing) this.housing.position.set(0, Math.max(0, length - 0.15), ARM.rWrist + 0.008);}- /** Turn `bone` along `a` → `b` (its +Y) with its +Z toward `up`; the sleeve scales to the length. Returns the length. */- private place(bone: Group, sleeve: Mesh, a: Vector3, b: Vector3, up: Vector3, short = 0): number {+ /** Turn `bone` along `a` → `b` (its +Y) with its +Z toward `up`. Returns the length. */+ private place(bone: Object3D, a: Vector3, b: Vector3, up: Vector3): number {const axis = this.axis.subVectors(b, a);const length = axis.length();if (length < 1e-5) return 0;@@ -227,7 +267,6 @@ export class ViewArm {this.m4.makeBasis(x, axis, z);bone.quaternion.setFromRotationMatrix(this.m4);bone.position.copy(a);- sleeve.scale.set(1, Math.max(0.01, length - short), 1);return length;}@@ -238,8 +277,4 @@ export class ViewArm {const x = SCRATCH_X.crossVectors(y, z);return out.setFromRotationMatrix(SCRATCH_M.makeBasis(x, y, z));}-- dispose(): void {- for (const geo of this.geometries) geo.dispose();- }}diff --git a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/rigMesh.ts b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/rigMesh.tsnew file mode 100644index 0000000000..efdc58e536--- /dev/null+++ b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/rigMesh.ts@@ -0,0 +1,238 @@+/**+ * The viewmodel drawn as one mesh: every rigid part of the arms and the+ * blaster is baked into a single skinned geometry (each vertex bound with+ * full weight to the bone it moves with), and every surface is one slot of a+ * tiny palette (albedo, roughness, metalness and emission in three float+ * textures, one texel per slot) under one material. So both arms, their+ * fingers and the blaster cost one draw call, whatever the number of parts.+ *+ * Bones are plain Object3Ds in the rig's graph, posed as before; the mesh+ * sits at the scene's origin with identity bind matrices, so a vertex lands+ * at `bone.matrixWorld × (its position in the bone's frame)`.+ */+import {+ BufferAttribute, Color, DataTexture, DoubleSide, FloatType, Matrix4, MeshStandardMaterial, NearestFilter, RGBAFormat, Skeleton,+ SkinnedMesh, Vector3, type Bone, type BufferGeometry, type Object3D,+} from "three";+import { ConvexGeometry } from "three/examples/jsm/geometries/ConvexGeometry.js";+import { mergeGeometries, mergeVertices } from "three/examples/jsm/utils/BufferGeometryUtils.js";++/** A surface of the palette (an index into its textures). */+export type Slot = number;++const SIZE = 16;++function paletteTexture(): DataTexture {+ const t = new DataTexture(new Float32Array(SIZE * 4), SIZE, 1, RGBAFormat, FloatType);+ t.magFilter = NearestFilter;+ t.minFilter = NearestFilter;+ t.generateMipmaps = false;+ t.needsUpdate = true;+ return t;+}++/** The rig's surfaces: one material, one texel per surface. */+export class RigPalette {+ readonly material: MeshStandardMaterial;+ private readonly albedo = paletteTexture();+ /** Roughness in green, metalness in blue (three's channel convention). */+ private readonly rm = paletteTexture();+ private readonly glow = paletteTexture();+ private readonly names = new Map<string, Slot>();++ constructor(name: string) {+ this.material = new MeshStandardMaterial({+ name, map: this.albedo, roughnessMap: this.rm, metalnessMap: this.rm, emissiveMap: this.glow,+ color: 0xffffff, emissive: 0xffffff, roughness: 1, metalness: 1, side: DoubleSide,+ });+ }++ /** The slot named `name` (allocated on first use). */+ slot(name: string): Slot {+ let s = this.names.get(name);+ if (s === undefined) {+ s = this.names.size;+ if (s >= SIZE) throw new Error(`rig palette full (${SIZE} surfaces)`);+ this.names.set(name, s);+ }+ return s;+ }++ /** The texture coordinate that reads `slot`. */+ static u(slot: Slot): number {+ return (slot + 0.5) / SIZE;+ }++ /** A surface's colour (linear), roughness and metalness. */+ surface(slot: Slot, color: Color, roughness: number, metalness: number): void {+ const a = this.albedo.image.data as Float32Array;+ a[slot * 4] = color.r;+ a[slot * 4 + 1] = color.g;+ a[slot * 4 + 2] = color.b;+ a[slot * 4 + 3] = 1;+ const r = this.rm.image.data as Float32Array;+ r[slot * 4 + 1] = roughness;+ r[slot * 4 + 2] = metalness;+ r[slot * 4 + 3] = 1;+ this.albedo.needsUpdate = true;+ this.rm.needsUpdate = true;+ }++ /** A surface's emission: colour (linear) times intensity. Only uploads when it changed. */+ emit(slot: Slot, color: Color, intensity: number): void {+ const g = this.glow.image.data as Float32Array;+ const r = color.r * intensity;+ const gg = color.g * intensity;+ const b = color.b * intensity;+ const i = slot * 4;+ if (g[i] === r && g[i + 1] === gg && g[i + 2] === b) return;+ g[i] = r;+ g[i + 1] = gg;+ g[i + 2] = b;+ g[i + 3] = 1;+ this.glow.needsUpdate = true;+ }++ /** The emission written for `slot` (its strongest channel). */+ emission(slot: Slot): number {+ const g = this.glow.image.data as Float32Array;+ return Math.max(g[slot * 4], g[slot * 4 + 1], g[slot * 4 + 2]);+ }++ dispose(): void {+ this.material.dispose();+ this.albedo.dispose();+ this.rm.dispose();+ this.glow.dispose();+ }+}++interface Part {+ geometry: BufferGeometry;+ bone: number;+ slot: Slot;+ matrix: Matrix4 | null;+ mirror: boolean;+}++const MIRROR_X = new Matrix4().makeScale(-1, 1, 1);++/** Collects the rig's parts per bone and bakes them into one skinned mesh. */+export class RigBuilder {+ readonly bones: Object3D[] = [];+ private readonly parts: Part[] = [];++ /**+ * Add a part: `geometry` (taken over: it is disposed once baked) placed by `matrix` in `bone`'s frame, painted with+ * `slot`. `mirror` reflects it across the bone frame's YZ plane after placing (the left hand is the right one mirrored).+ */+ add(geometry: BufferGeometry, bone: Object3D, slot: Slot, matrix: Matrix4 | null = null, mirror = false): void {+ let b = this.bones.indexOf(bone);+ if (b < 0) {+ b = this.bones.length;+ this.bones.push(bone);+ }+ this.parts.push({ geometry, bone: b, slot, matrix, mirror });+ }++ /** Bake every part into one geometry (position, normal, uv into the palette, skin index and weight). */+ bake(): BufferGeometry {+ const baked: BufferGeometry[] = [];+ for (const p of this.parts) {+ const src = p.geometry.index ? p.geometry.toNonIndexed() : p.geometry.clone();+ if (!src.getAttribute("normal")) src.computeVertexNormals();+ for (const name of Object.keys(src.attributes)) if (name !== "position" && name !== "normal") src.deleteAttribute(name);+ src.morphAttributes = {};+ src.clearGroups();+ if (p.matrix) src.applyMatrix4(p.matrix);+ if (p.mirror) {+ src.applyMatrix4(MIRROR_X);+ flipWinding(src);+ }+ const n = src.getAttribute("position").count;+ const uv = new Float32Array(n * 2);+ const u = RigPalette.u(p.slot);+ for (let i = 0; i < n; i++) {+ uv[i * 2] = u;+ uv[i * 2 + 1] = 0.5;+ }+ const index = new Uint16Array(n * 4);+ const weight = new Float32Array(n * 4);+ for (let i = 0; i < n; i++) {+ index[i * 4] = p.bone;+ weight[i * 4] = 1;+ }+ src.setAttribute("uv", new BufferAttribute(uv, 2));+ src.setAttribute("skinIndex", new BufferAttribute(index, 4));+ src.setAttribute("skinWeight", new BufferAttribute(weight, 4));+ baked.push(src);+ if (src !== p.geometry) p.geometry.dispose();+ }+ const merged = mergeGeometries(baked, false);+ for (const g of baked) g.dispose();+ if (!merged) throw new Error("viewmodel rig: parts could not be merged");+ merged.name = "ViewmodelRig";+ return merged;+ }++ /** Bake and bind: one skinned mesh over the collected bones (identity bind pose). */+ build(material: MeshStandardMaterial): SkinnedMesh {+ const mesh = new SkinnedMesh(this.bake(), material);+ mesh.name = "ViewmodelRig";+ mesh.frustumCulled = false;+ const skeleton = new Skeleton(this.bones as Bone[], this.bones.map(() => new Matrix4()));+ mesh.bind(skeleton, new Matrix4());+ return mesh;+ }+}++/** Reverse each triangle's winding (non-indexed geometry), after a mirror. */+function flipWinding(g: BufferGeometry): void {+ for (const name of ["position", "normal"]) {+ const a = g.getAttribute(name);+ if (!a) continue;+ const arr = a.array as Float32Array;+ const s = a.itemSize;+ for (let t = 0; t + 2 < a.count; t += 3) {+ for (let k = 0; k < s; k++) {+ const i1 = (t + 1) * s + k;+ const i2 = (t + 2) * s + k;+ const tmp = arr[i1];+ arr[i1] = arr[i2];+ arr[i2] = tmp;+ }+ }+ a.needsUpdate = true;+ }+}++/**+ * A box with its edges chamfered at `c` (flat faces, a narrow facet on every edge, a triangle on every corner):+ * 44 triangles, where a rounded box with one segment costs 108. Centred on the origin. `smooth` shades it soft+ * (normals shared across the facets: a padded glove rather than machined metal).+ */+export function chamferBox(w: number, h: number, d: number, c: number, smooth = false): BufferGeometry {+ const x = w / 2;+ const y = h / 2;+ const z = d / 2;+ const k = Math.min(c, x * 0.9, y * 0.9, z * 0.9);+ const pts: Vector3[] = [];+ for (const sx of [-1, 1]) {+ for (const sy of [-1, 1]) {+ for (const sz of [-1, 1]) {+ pts.push(+ new Vector3(sx * x, sy * (y - k), sz * (z - k)),+ new Vector3(sx * (x - k), sy * y, sz * (z - k)),+ new Vector3(sx * (x - k), sy * (y - k), sz * z),+ );+ }+ }+ }+ const hull = new ConvexGeometry(pts);+ if (!smooth) return hull;+ hull.deleteAttribute("normal");+ const soft = mergeVertices(hull);+ hull.dispose();+ soft.computeVertexNormals();+ return soft;+}diff --git a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.test.ts b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.test.tsindex d6e50d2235..ed494b81db 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.test.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.test.ts@@ -5,9 +5,10 @@* duel (hip, sights, shield, a shot).*/import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";-import { Box3, Color, Frustum, Matrix4, MeshStandardMaterial, PerspectiveCamera, Quaternion, Vector3 } from "three";+import { Box3, Color, Frustum, Matrix4, Mesh, PerspectiveCamera, Quaternion, Sprite, Vector3 } from "three";import type { PlayerView } from "../combat/view";-import { ARM, fingerSegment, ViewArm } from "./arms";+import { ARM, fingerSegment, handPose, ViewArm } from "./arms";+import { chamferBox, RigBuilder } from "./rigMesh";import {HIDE_BODY_BELOW_M, HIDE_BODY_FIRST_SHARE, idleSway, MOTION, springStep, turnBetween, ViewmodelMotion, viewmodelVisibility,walkBob, zeroOffsets, type MotionInput,@@ -165,13 +166,37 @@ describe("viewmodel arms", () => {const box = geo.boundingBox as Box3;expect(box.min.z).toBeCloseTo(0, 6);expect(box.max.z).toBeCloseTo(0.04, 6);- expect(box.max.x).toBeCloseTo(0.01, 3);+ expect(box.max.x).toBeLessThanOrEqual(0.01);+ expect(box.max.x).toBeGreaterThan(0.008);geo.dispose();});+ it("chamfers a box with 44 flat triangles", () => {+ const geo = chamferBox(0.1, 0.04, 0.2, 0.01);+ expect(geo.getAttribute("position").count / 3).toBe(44);+ geo.computeBoundingBox();+ expect(geo.boundingBox?.max.z).toBeCloseTo(0.1, 6);+ expect(geo.boundingBox?.max.y).toBeCloseTo(0.02, 6);+ geo.dispose();+ });++ it("poses the index finger and the thumb apart from the other fingers", () => {+ const arm = new ViewArm("right", new RigBuilder(), SLOTS);+ const bones = arm as unknown as { fingers: { base: { rotation: { x: number } } }[]; thumb: { base: { rotation: { y: number } } } };+ arm.curl(handPose(1.5, 1.4, 0.7, [0.3, 0.7], 0.2));+ expect(bones.fingers[0].base.rotation.x).toBeCloseTo(0.3, 6);+ expect(bones.fingers[1].base.rotation.x).toBeGreaterThan(1.5);+ const thumbY = bones.thumb.base.rotation.y;+ arm.curl(handPose(1.5, 1.4, 0.7, [0.3, 0.7], 0));+ expect(bones.thumb.base.rotation.y).not.toBeCloseTo(thumbY, 3);+ // The left hand is the right one mirrored: its thumb swings the other way.+ const left = new ViewArm("left", new RigBuilder(), SLOTS);+ left.curl(handPose(1.5, 1.4, 0.7, [0.3, 0.7], 0));+ expect((left as unknown as typeof bones).thumb.base.rotation.y).toBeCloseTo(-bones.thumb.base.rotation.y, 6);+ });+it("reaches the wrist with a two-bone arm whose elbow bends toward the pole", () => {- const mats = { sleeve: new MeshMat(), trim: new MeshMat(), glove: new MeshMat(), housing: new MeshMat(), emitter: new MeshMat() };- const arm = new ViewArm("right", mats);+ const arm = new ViewArm("right", new RigBuilder(), SLOTS);const shoulder = new Vector3(0.2, -0.38, 0);const wrist = new Vector3(0.12, -0.12, -0.4);const q = ViewArm.handFrame(new Vector3(0, 0, -1), new Vector3(0, 1, 0), new Quaternion());@@ -186,11 +211,11 @@ describe("viewmodel arms", () => {// The hand frame: knuckles ahead (−Z), back of the hand up.const knuckles = new Vector3(0, 0, 1).applyQuaternion(q);expect(knuckles.z).toBeCloseTo(-1, 6);- arm.dispose();+});});-const MeshMat = MeshStandardMaterial;+const SLOTS = { sleeve: 0, trim: 1, glove: 2, housing: 3, emitter: 4 };function player(over: Partial<PlayerView> = {}): PlayerView {return {@@ -252,8 +277,8 @@ describe("viewmodel rig", () => {expect(parts.gun.visible).toBe(false);vm.scene.updateMatrixWorld(true);// The knuckles are in view; the right hand right of centre, the left hand left of it, both below the eye line.- const r = world(parts.right.hand.children[2]);- const l = world(parts.left.hand.children[2]);+ const r = world(parts.right.knuckles);+ const l = world(parts.left.knuckles);expect(inView(vm, r)).toBe(true);expect(inView(vm, l)).toBe(true);const toCam = (p: Vector3) => p.clone().applyMatrix4(vm.camera.matrixWorldInverse);@@ -304,7 +329,7 @@ describe("viewmodel rig", () => {vm.scene.updateMatrixWorld(true);expect(world(parts.left.hand).applyMatrix4(vm.camera.matrixWorldInverse).y).toBeGreaterThan(restY + 0.03);// The emitter's strip lights.- expect((parts.left.emitterStrip?.material as unknown as { emissiveIntensity: number }).emissiveIntensity).toBeGreaterThan(3);+ expect(vm.emitterGlow).toBeGreaterThan(3);vm.set(duelFrame(player()));for (let i = 0; i < 30; i++) vm.prepare(cam, 1 / 60, null);vm.shot(1, false);@@ -313,4 +338,86 @@ describe("viewmodel rig", () => {expect(back).toBeGreaterThan(restZ + 0.01);vm.dispose();});++ /** The rig's skinned vertices in normalised device coordinates, split into the blaster's and the arms'. */+ function screen(vm: Viewmodel): { gun: Vector3[]; arms: Vector3[] } {+ vm.scene.updateMatrixWorld(true);+ vm.camera.updateMatrixWorld();+ const mesh = vm.mesh;+ const gunBone = (vm as unknown as { gunBone: object }).gunBone;+ const gunIndex = mesh.skeleton.bones.indexOf(gunBone as never);+ const skin = mesh.geometry.getAttribute("skinIndex");+ const out = { gun: [] as Vector3[], arms: [] as Vector3[] };+ for (let i = 0; i < skin.count; i += 3) {+ const p = mesh.getVertexPosition(i, new Vector3()).project(vm.camera);+ (skin.getX(i) === gunIndex ? out.gun : out.arms).push(p);+ }+ return out;+ }+ const onScreen = (p: Vector3) => Math.abs(p.x) <= 1 && Math.abs(p.y) <= 1 && p.z < 1;+ const duelFrame = (p: PlayerView) => frameFor({ visibility: { arms: true, mode: "duel", hideOwnBody: true, raise: 1 }, player: p });++ it("draws the arms and the blaster as one skinned mesh within the budget", () => {+ const vm = new Viewmodel({ uniform: "#3b3f47", trim: "#5a5f68" }, new Color(1, 0.6, 0.15));+ vm.set(duelFrame(player()));+ vm.shot(1, false);+ vm.shot(2, false);+ for (let i = 0; i < 3; i++) vm.prepare(eye(), 1 / 60, null);+ let draws = 0;+ let triangles = 0;+ vm.scene.traverseVisible((o) => {+ if ((o as Mesh).isMesh) {+ const g = (o as Mesh).geometry;+ draws += Array.isArray((o as Mesh).material) ? g.groups.length : 1;+ triangles += (g.index ? g.index.count : g.getAttribute("position").count) / 3;+ } else if ((o as Sprite).isSprite) {+ draws++;+ }+ });+ // The rig, the sight's reticle and the muzzle flash.+ expect(draws).toBeLessThanOrEqual(3);+ expect(triangles).toBeLessThanOrEqual(3000);+ expect(vm.mesh.isSkinnedMesh).toBe(true);+ vm.dispose();+ });++ it("keeps the centre of the screen clear at the hip, the blaster low on the right", () => {+ const vm = new Viewmodel({ uniform: "#3b3f47", trim: "#5a5f68" }, new Color(1, 0.6, 0.15));+ vm.set(duelFrame(player()));+ for (let i = 0; i < 30; i++) vm.prepare(eye(), 1 / 60, null);+ const { gun, arms } = screen(vm);+ const all = [...gun, ...arms].filter(onScreen);+ // Nothing of the rig around the crosshair: the middle fifth across, down to below the screen's middle.+ expect(all.filter((p) => Math.abs(p.x) < 0.12 && p.y > -0.2)).toHaveLength(0);+ // The left half of the screen stays clear above its bottom quarter (the support arm comes up from below).+ expect(all.filter((p) => p.x < -0.05 && p.y > -0.5)).toHaveLength(0);+ // The blaster is right of centre and below the crosshair.+ const seen = gun.filter(onScreen);+ expect(seen.reduce((s, p) => s + p.x, 0) / seen.length).toBeGreaterThan(0.2);+ expect(Math.max(...gun.map((p) => p.y))).toBeLessThan(0);+ vm.dispose();+ });++ it("keeps the blaster in view, lowered and canted, in a sprint", () => {+ const vm = new Viewmodel({ uniform: "#3b3f47", trim: "#5a5f68" }, new Color(1, 0.6, 0.15));+ const parts = vm as unknown as { blaster: { group: { localToWorld(v: Vector3): Vector3 }; muzzle: Vector3 } };+ vm.set(duelFrame(player({ sprinting: true, speed: 6 })));+ for (let i = 0; i < 60; i++) vm.prepare(eye(), 1 / 60, null);+ const { gun } = screen(vm);+ // Most of the blaster is on screen, and its muzzle too.+ expect(gun.filter(onScreen).length / gun.length).toBeGreaterThan(0.6);+ expect(inView(vm, parts.blaster.group.localToWorld(parts.blaster.muzzle.clone()))).toBe(true);+ vm.dispose();+ });++ it("rests the right index finger on the trigger", () => {+ const vm = new Viewmodel({ uniform: "#3b3f47", trim: "#5a5f68" }, new Color(1, 0.6, 0.15));+ const parts = vm as unknown as { right: ViewArm };+ vm.set(duelFrame(player()));+ for (let i = 0; i < 30; i++) vm.prepare(eye(), 1 / 60, null);+ vm.scene.updateMatrixWorld(true);+ const tip = world(parts.right.indexTip);+ expect(tip.distanceTo(world(vm.trigger))).toBeLessThan(0.012);+ vm.dispose();+ });});diff --git a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.ts b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.tsindex 18dc755f34..064bda54a8 100644--- a/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.ts+++ b/dodaios/ui/web/frontend/src/components/society/verse/viewmodel/viewmodel.ts@@ -9,19 +9,24 @@* field of view, and the pass clears depth before it draws, so the arms never* sink into a wall and never stretch with a wide field-of-view setting.*+ * Both arms and the blaster are one skinned mesh under one palette material+ * (`rigMesh.ts`): one draw call, plus the sight's reticle and the muzzle+ * flash in a duel.+ ** The rig is posed in the camera's space every frame (x right, y up, −z ahead):* on the deck both hands hang loose low in the frame and swing with the walk;- * in a duel the right hand holds the blaster's grip and the left its shroud,- * blended between hip, sights (the sight's window moves onto the eye line),- * sprint (carried low), shield (the left forearm comes up with its emitter- * lit, the blaster lowered) and vent (the blaster tips up, the left hand- * slaps the receiver). Walk bob, idle sway, look lag and recoil- * (`motion.ts`) ride on top; a shot also flashes at the muzzle and lights- * the hands. The frame path allocates nothing.+ * in a duel the right hand holds the blaster's grip with the index finger on+ * the trigger and the left clamps its shroud, blended between hip (low on the+ * right, the centre of the screen clear), sights (the sight's window moves+ * onto the eye line), sprint (lowered and canted, still in view), shield (the+ * left forearm comes up with its emitter lit, the blaster lowered) and vent+ * (the blaster tips up, the left hand slaps the receiver). Walk bob, idle+ * sway, look lag and recoil (`motion.ts`) ride on top; a shot also flashes at+ * the muzzle and lights the hands. The frame path allocates nothing.*/import {- AdditiveBlending, CanvasTexture, Color, DirectionalLight, DoubleSide, Euler, Group, MeshBasicMaterial, MeshStandardMaterial,- PerspectiveCamera, PointLight, Quaternion, Scene, Sprite, SpriteMaterial, Vector3, type Texture,+ AdditiveBlending, Bone, CanvasTexture, Color, DirectionalLight, Euler, Group, Matrix4, Mesh, MeshBasicMaterial, MeshStandardMaterial,+ PerspectiveCamera, PointLight, Quaternion, Scene, Sprite, SpriteMaterial, Vector3, type SkinnedMesh, type Texture,} from "three";import type { Deck } from "../content/deck";import { RoomLight } from "../actors/roomLight";@@ -29,8 +34,9 @@ import type { PlayerView } from "../combat/view";import { buildBlaster, type Blaster } from "../duel/blaster";import { radialTexture } from "../duel/effects";import { verticalFov } from "../engine/realtime/shoulderRig";-import { ViewArm, type ArmMaterials } from "./arms";+import { copyHand, handPose, lerpHand, ViewArm, type ArmSlots, type HandPose } from "./arms";import { turnBetween, ViewmodelMotion, type Visibility } from "./motion";+import { chamferBox, RigBuilder, RigPalette, type Slot } from "./rigMesh";/** A pose of the blaster (its grip, the right hand's hold) in the camera's space. */export interface GunPose { x: number; y: number; z: number; pitch: number; yaw: number; roll: number }@@ -47,7 +53,7 @@ export const VIEWMODEL = {near: 0.01,far: 4,/** The blaster's size in the hands, relative to the duel's model. */- gunScale: 0.65,+ gunScale: 0.6,/** Distance from the eye to the sight's window when aiming down the sights, metres. */adsDistance: 0.3,/** Time constant of the pose blends (sprint, shield, vent), seconds. */@@ -62,43 +68,58 @@ export const VIEWMODEL = {* exposure, it lights the arms the same on every deck.*/fill: 1.2,- /** The blaster at the hip, carried low in a sprint, lowered behind the shield, rolled over to vent, dropped when knocked out. */- hip: { x: 0.14, y: -0.09, z: -0.33, pitch: 0.05, yaw: 0.06, roll: 0.22 } as GunPose,- sprint: { x: 0.17, y: -0.16, z: -0.31, pitch: -0.3, yaw: 0.45, roll: 0.45 } as GunPose,+ /**+ * The blaster at the hip (low on the right, the muzzle toward the crosshair, the centre clear), lowered and canted+ * in a sprint (still in view), lowered behind the shield, rolled over to vent, dropped when knocked out.+ */+ hip: { x: 0.155, y: -0.115, z: -0.46, pitch: 0.08, yaw: 0.07, roll: 0.1 } as GunPose,+ sprint: { x: 0.15, y: -0.135, z: -0.36, pitch: -0.12, yaw: 0.62, roll: 0.62 } as GunPose,shield: { x: 0.2, y: -0.22, z: -0.32, pitch: -0.45, yaw: 0.3, roll: 0.35 } as GunPose,- vent: { x: 0.11, y: -0.11, z: -0.33, pitch: 0.25, yaw: 0.2, roll: -0.4 } as GunPose,+ vent: { x: 0.12, y: -0.12, z: -0.34, pitch: 0.25, yaw: 0.2, roll: -0.4 } as GunPose,down: { x: 0.16, y: -0.7, z: -0.25, pitch: -0.9, yaw: 0.3, roll: 0.3 } as GunPose,/** The left wrist with the shield up, camera space. */shieldWrist: { x: -0.13, y: -0.07, z: -0.42 },/** The wrists on the deck (the left mirrors x), camera space. */deckWrist: { x: 0.2, y: -0.2, z: -0.42 },- /** Shoulders, below and behind the eyes, and the elbows' pull (down and out); the support arm reaches in from further out. */+ /**+ * Shoulders, below and behind the eyes, and the elbows' pull (down and out). The support arm's shoulder sits in+ * toward the middle and low, so its forearm comes up from the bottom edge to the shroud instead of across the screen.+ */shoulderR: new Vector3(0.22, -0.38, -0.02),- shoulderL: new Vector3(-0.3, -0.38, -0.02),+ shoulderL: new Vector3(-0.02, -0.52, 0.06),poleR: new Vector3(1, -0.6, 0.1),- poleL: new Vector3(-1, -0.6, 0.1),+ poleL: new Vector3(-0.4, -1, 0.2),/*** The hands: the right hand's hold on the grip (along the grip, along the knuckles, out to the side), the left's- * beside the shroud (out to its left, up, ahead), hand frames as knuckle and back-of-hand directions, finger curls (two joints and- * the thumb).+ * beside the shroud (out to its left, up, ahead), hand frames as knuckle and back-of-hand directions, and the hand+ * poses (`HandPose`: three fingers, the index finger, the thumb).*/hands: {- grip: [0.012, -0.06, 0.036],- gripCurl: [1.45, 1.35, 0.7],+ grip: [-0.03, -0.075, 0.036],+ /** The right hand on the grip: three fingers wrapped, the index finger straight along the guard onto the trigger, the thumb over the far side. */+ gripPose: handPose(1.5, 1.4, 0.75, [0, 1.5], 0.15),fore: [0.042, 0.012, -0.06],foreKnuckles: [-0.15, 0.25, 1],foreBack: [1, -0.15, 0],- foreCurl: [1.25, 1.0, 0.5],+ /** The left hand under the shroud: fingers curled round it, the thumb along its top. */+ forePose: handPose(1.25, 1.0, 0.35, [1.1, 0.9], -0.2),ventKnuckles: [0, 0.35, 1],ventBack: [1, 0.1, 0],+ /** The open hand slapping the receiver, and raised palm forward behind the shield. */+ ventPose: handPose(0.35, 0.3, 0.1, [0.3, 0.25], -0.3),+ shieldPose: handPose(0.15, 0.1, 0.2, [0.1, 0.05], -0.4),deckKnuckles: [-0.35, 0.25, -1],deckBack: [0.35, 1, 0.1],- deckCurl: [1.3, 1.15, 0.6],+ /** Relaxed hands: the index a little straighter than the rest, the thumb resting along it. */+ deckPose: handPose(1.3, 1.15, 0.6, [1.05, 0.95], 0),shieldKnuckles: [0.15, 1, -0.2],shieldBack: [0.2, 0.15, 1],},};+/** The trigger blade, in the blaster model's own (unscaled) frame: in front of the grip, under the receiver. */+const TRIGGER = { x: 0, y: -0.049, z: 0.04, rx: 0.3 };+const SHOULDER_R = new Vector3();const SHOULDER_L = new Vector3();const POLE_R = new Vector3();@@ -157,17 +178,28 @@ function reticleTexture(): Texture {return new CanvasTexture(canvas);}+/** A glowing surface of the blaster mirrored into the palette each frame. */+interface Glow { slot: Slot; material: MeshStandardMaterial }+export class Viewmodel {readonly scene = new Scene();readonly camera: PerspectiveCamera;/** Draw the pass this frame (set by `prepare`). */visible = false;+ /** Both arms and the blaster: one skinned mesh. */+ readonly mesh: SkinnedMesh;private readonly rig = new Group();private readonly right: ViewArm;private readonly left: ViewArm;private readonly blaster: Blaster;private readonly gun = new Group();- private readonly mats: ArmMaterials & { sleeve: MeshStandardMaterial; trim: MeshStandardMaterial; emitter: MeshStandardMaterial };+ /** The blaster's bone (inside its scaled group): collapsed to a point when the hands are empty. */+ private readonly gunBone = new Bone();+ /** A landmark on the trigger, in the blaster's frame. */+ readonly trigger = new Group();+ private readonly palette = new RigPalette("M_View_Rig");+ private readonly slots: ArmSlots;+ private readonly glows: Glow[] = [];private readonly reticle: MeshBasicMaterial;private readonly flash: Sprite;private readonly flashLight = new PointLight(0xffa040, 0, 1.2, 2);@@ -175,9 +207,8 @@ export class Viewmodel {private readonly light = new RoomLight();private readonly motion = new ViewmodelMotion();private readonly textures: Texture[] = [];- /** The lit materials (the room's reflections are scaled on them) and the blaster's glowing ones. */- private readonly lit: MeshStandardMaterial[];- private readonly glowing: MeshStandardMaterial[];+ private readonly emitterColour = new Color(0.35, 0.75, 1.6);+ private readonly tmpColour = new Color();private frame: ViewmodelFrame | null = null;private shots = 0;private flashT = 0;@@ -190,6 +221,7 @@ export class Viewmodel {// Scratch, reused every frame.private readonly pose: GunPose = { ...VIEWMODEL.hip };private readonly ads: GunPose = { ...VIEWMODEL.hip };+ private readonly handL: HandPose = handPose(0, 0, 0);private readonly euler = new Euler(0, 0, 0, "YXZ");private readonly qGun = new Quaternion();private readonly qTmp = new Quaternion();@@ -207,53 +239,90 @@ export class Viewmodel {private readonly holdR = { at: new Vector3(), q: new Quaternion() };private readonly holdL = { at: new Vector3(), q: new Quaternion() };private readonly ventL = { at: new Vector3(), q: new Quaternion() };+ /** The emitter strip's glow this frame (for checks). */+ emitterGlow = 0;constructor(colours: ArmColours, accent: Color) {this.camera = new PerspectiveCamera(60, 1, VIEWMODEL.near, VIEWMODEL.far);this.scene.name = "Viewmodel";- const sleeve = new MeshStandardMaterial({ name: "M_View_Sleeve", color: colours.uniform, roughness: 0.78, metalness: 0, side: DoubleSide });- const trim = new MeshStandardMaterial({ name: "M_View_Trim", color: colours.trim, roughness: 0.55, metalness: 0.2 });- const glove = new MeshStandardMaterial({ name: "M_View_Glove", color: 0x2b2c31, roughness: 0.46, metalness: 0.05, side: DoubleSide });- const housing = new MeshStandardMaterial({ name: "M_View_Emitter_Housing", color: 0x2a2e34, roughness: 0.35, metalness: 0.85 });- const emitter = new MeshStandardMaterial({ name: "M_View_Emitter", color: 0x050505, emissive: new Color(0.35, 0.75, 1.6), emissiveIntensity: 0.6, roughness: 0.4 });- this.mats = { sleeve, trim, glove, housing, emitter };- this.right = new ViewArm("right", this.mats);- this.left = new ViewArm("left", this.mats);+ const pal = this.palette;+ this.slots = {+ sleeve: pal.slot("sleeve"), trim: pal.slot("trim"), glove: pal.slot("glove"), housing: pal.slot("housing"), emitter: pal.slot("emitter"),+ };+ pal.surface(this.slots.glove, new Color(0x2b2c31), 0.46, 0.05);+ pal.surface(this.slots.housing, new Color(0x2a2e34), 0.35, 0.85);+ pal.surface(this.slots.emitter, new Color(0x050505), 0.4, 0);+ this.setColours(colours);++ const rig = new RigBuilder();+ this.right = new ViewArm("right", rig, this.slots);+ this.left = new ViewArm("left", rig, this.slots);++ // The blaster: the duel's model (chamfered for the close view). Its parts are baked into the rig on the gun's+ // bone; the stock stays out (it would hide the right hand); the sight's pane becomes a see-through reticle.this.blaster = buildBlaster(accent, { bevel: true });- // The sight's pane becomes a see-through reticle.+ const bg = this.blaster.group;+ bg.updateMatrixWorld(true);+ const baked: Mesh[] = [];+ bg.traverse((o) => {+ const m = o as Mesh;+ if (!m.isMesh || m === this.blaster.sightGlass) return;+ baked.push(m);+ if (this.blaster.stock.includes(m)) return;+ const mat = m.material as MeshStandardMaterial;+ const slot = pal.slot(mat.name);+ pal.surface(slot, mat.color, mat.roughness, mat.metalness);+ if (mat.emissiveIntensity > 0 && mat.emissive.getHex() !== 0) {+ if (!this.glows.some((g) => g.slot === slot)) this.glows.push({ slot, material: mat });+ }+ rig.add(m.geometry.clone(), this.gunBone, slot, m.matrixWorld.clone());+ });+ for (const m of baked) m.removeFromParent();+ // The trigger (the duel's model has none: from metres away it never shows).+ const steel = pal.slot("M_Blaster_Steel");+ const s = this.blasterScale();+ rig.add(chamferBox(0.006, 0.018, 0.007, 0.002), this.gunBone, steel, new Matrix4().makeScale(s, s, s)+ .multiply(new Matrix4().makeTranslation(TRIGGER.x, TRIGGER.y, TRIGGER.z)).multiply(new Matrix4().makeRotationX(TRIGGER.rx)));+ this.trigger.position.set(TRIGGER.x, TRIGGER.y - 0.004, TRIGGER.z + 0.002).multiplyScalar(s);+ bg.add(this.gunBone, this.trigger);+const reticleMap = reticleTexture();this.textures.push(reticleMap);this.reticle = new MeshBasicMaterial({map: reticleMap, color: new Color(1.6, 0.85, 0.25), transparent: true, blending: AdditiveBlending, depthWrite: false,});this.blaster.sightGlass.material = this.reticle;- for (const m of this.blaster.stock) m.visible = false;- this.gun.add(this.blaster.group);+ this.gun.add(bg);// The muzzle flash: a short additive burst at the muzzle, and the light it throws on the hands.const flashMap = radialTexture([[0, "rgba(255,255,255,1)"], [0.25, "rgba(255,190,90,0.9)"], [1, "rgba(255,120,30,0)"]]);this.textures.push(flashMap);this.flash = new Sprite(new SpriteMaterial({ map: flashMap, color: new Color(2.4, 1.5, 0.6), blending: AdditiveBlending, depthWrite: false, transparent: true }));this.flash.scale.setScalar(0.11);this.flash.visible = false;- this.blaster.group.add(this.flash);+ bg.add(this.flash);this.flash.position.copy(this.blaster.muzzle).setZ(this.blaster.muzzle.z + 0.04);- this.blaster.group.add(this.flashLight);+ bg.add(this.flashLight);this.flashLight.position.copy(this.blaster.muzzle);this.rig.add(this.right.group, this.left.group, this.gun, this.key, this.key.target);this.key.position.set(-0.4, 1, 0.5);- this.scene.add(this.rig);+ this.mesh = rig.build(pal.material);+ // The mesh stays at the origin: its vertices follow the bones in the rig.+ this.scene.add(this.rig, this.mesh);this.rig.traverse((o) => { o.frustumCulled = false; });- this.lit = [sleeve, trim, glove, housing, ...this.blaster.materials].filter((m): m is MeshStandardMaterial => (m as MeshStandardMaterial).isMeshStandardMaterial === true);- this.glowing = this.lit.filter((m) => /Cells|Vents|Emitter$/.test(m.name) && m.name.startsWith("M_Blaster"));- this.light.attach(this.lit);+ this.light.attach([pal.material]);this.retune();}+ /** The blaster model's own scale (the duel draws it a little larger than true size): its muzzle over its unscaled one. */+ private blasterScale(): number {+ return this.blaster.muzzle.z / 0.49;+ }+/** The person's colours changed (a promotion): repaint the sleeves. */setColours(colours: ArmColours): void {- this.mats.sleeve.color.set(colours.uniform);- this.mats.trim.color.set(colours.trim);+ this.palette.surface(this.slots.sleeve, this.tmpColour.set(colours.uniform), 0.78, 0);+ this.palette.surface(this.slots.trim, this.tmpColour.set(colours.trim), 0.55, 0.2);}/** This frame's state (the layer fills it before the eye view renders). */@@ -287,7 +356,7 @@ export class Viewmodel {const knR = new Vector3().crossVectors(up, backR);const h = VIEWMODEL.hands;const vec = (a: readonly number[]) => new Vector3(a[0], a[1], a[2]);- const grip = new Vector3(0, -0.06, -0.01).multiplyScalar(1.3 * s);+ const grip = new Vector3(0, -0.06, -0.01).multiplyScalar(this.blasterScale() * s);this.holdR.at.copy(grip).addScaledVector(up, h.grip[0]).addScaledVector(knR, h.grip[1]).addScaledVector(backR, h.grip[2]);ViewArm.handFrame(knR, backR, this.holdR.q);// Left hand: a clamp on the shroud from its left, the thumb over the top, the knuckles along the barrel, the back@@ -298,7 +367,7 @@ export class Viewmodel {this.holdL.at.set(fore.x + h.fore[0], fore.y + h.fore[1], fore.z + h.fore[2]).addScaledVector(knL, -0.05);ViewArm.handFrame(knL, backL, this.holdL.q);// Venting: the left hand leaves the shroud and slaps the receiver's side, palm flat against it.- const vents = new Vector3(0.05, 0.02, 0.12).multiplyScalar(1.3 * s);+ const vents = new Vector3(0.05, 0.02, 0.12).multiplyScalar(this.blasterScale() * s);const knV = vec(h.ventKnuckles).normalize();const backV = vec(h.ventBack).normalize();this.ventL.at.copy(vents).addScaledVector(backV, 0.018).addScaledVector(knV, -0.05);@@ -378,7 +447,9 @@ export class Viewmodel {const exposure = Math.pow(2, f.deck?.exposure ?? 0);const dip = (1 - raise) * 0.35 + (p?.dodging ? Math.sin(p.dodgeProgress * Math.PI) * 0.12 : 0);+ // Empty hands on the deck: the blaster's part of the mesh collapses to a point, its reticle and flash hide.this.gun.visible = duel;+ this.gunBone.scale.setScalar(duel ? 1 : 1e-5);if (duel && p) this.poseDuel(p, o, dip);else this.poseDeck(o, dip);@@ -390,15 +461,16 @@ export class Viewmodel {this.flashLight.intensity = duel ? (fl * 1.6) / exposure : 0;this.key.intensity = VIEWMODEL.fill / exposure;// The left forearm's emitter: dim at rest, bright while the shield is up.- const e = this.mats.emitter;- e.emissiveIntensity = 0.5 + w.shield * (4 + (p ? p.shieldEnergy * 4 : 0)) + (p?.parrying ? 6 : 0);+ this.emitterGlow = 0.5 + w.shield * (4 + (p ? p.shieldEnergy * 4 : 0)) + (p?.parrying ? 6 : 0);+ this.palette.emit(this.slots.emitter, this.emitterColour, this.emitterGlow);if (duel && p) {+ // The duel model's heat drives its materials; their glow goes into the palette, toned down: a hand's breadth+ // from the eye the glow tuned to read at shoulder distance would flood the bloom.this.blaster.setHeat(p.heat, p.venting, p.overheated, this.time);- // A hand's breadth from the eye the duel model's glow (tuned to read at shoulder distance) would flood the bloom.- for (const m of this.glowing) m.emissiveIntensity *= VIEWMODEL.glowGain;+ for (const g of this.glows) this.palette.emit(g.slot, g.material.emissive, g.material.emissiveIntensity * VIEWMODEL.glowGain);}// The room's reflections: the deck's environment is captured in the open room, the hands are in the body's shade.- for (const m of this.lit) m.envMapIntensity = VIEWMODEL.envGain;+ this.palette.material.envMapIntensity = VIEWMODEL.envGain;if (f.deck) this.light.update(f.deck, f.x, f.y, f.z, step);}@@ -421,18 +493,17 @@ export class Viewmodel {this.gun.quaternion.copy(this.qGun);this.gun.updateMatrixWorld();- // Right hand on the grip.+ // Right hand on the grip, the index finger on the trigger.this.wristR.copy(this.holdR.at).applyQuaternion(this.qGun).add(this.gun.position);this.qHandR.copy(this.qGun).multiply(this.holdR.q);const h = VIEWMODEL.hands;- this.right.curl(h.gripCurl[0], h.gripCurl[1], h.gripCurl[2]);+ this.right.curl(h.gripPose);this.right.pose(SHOULDER_R, this.wristR, this.qHandR, POLE_R);// Left hand: on the shroud, against the receiver while venting, up before the face behind the shield.this.wristL.copy(this.holdL.at).applyQuaternion(this.qGun).add(this.gun.position);this.qHandL.copy(this.qGun).multiply(this.holdL.q);- let c1 = h.foreCurl[0];- let c2 = h.foreCurl[1];+ const hand = copyHand(this.handL, h.forePose);if (w.vent > 1e-3) {// A slap: the hand swings out and in against the receiver in the first quarter second, then rests there.const t = Math.min(1, this.ventT / 0.2);@@ -441,41 +512,43 @@ export class Viewmodel {this.wristL.lerp(this.v, w.vent);this.qTmp.copy(this.qGun).multiply(this.ventL.q);this.qHandL.slerp(this.qTmp, w.vent);- c1 += (0.35 - c1) * w.vent;- c2 += (0.3 - c2) * w.vent;+ lerpHand(hand, h.ventPose, w.vent);}if (w.shield > 1e-3) {const sw = VIEWMODEL.shieldWrist;this.v.set(sw.x + o.x, sw.y + o.y - dip, sw.z + o.z);this.wristL.lerp(this.v, w.shield);this.qHandL.slerp(this.qShieldL, w.shield);- c1 += (0.15 - c1) * w.shield;- c2 += (0.1 - c2) * w.shield;+ lerpHand(hand, h.shieldPose, w.shield);}if (w.down > 1e-3) this.wristL.y -= w.down * 0.5;- this.left.curl(c1, c2, h.foreCurl[2]);+ this.left.curl(hand);this.left.pose(SHOULDER_L, this.wristL, this.qHandL, POLE_L);}private poseDeck(o: { x: number; y: number; z: number; pitch: number; yaw: number; roll: number }, dip: number): void {// Loose hands low in the frame; while walking they swing against each other with the stride.const swing = Math.sin(this.motion.phase) * 0.05 * Math.min(1, this.motion.bob);- const c = VIEWMODEL.hands.deckCurl;- this.right.curl(c[0], c[1], c[2]);- this.left.curl(c[0], c[1], c[2]);+ const c = VIEWMODEL.hands.deckPose;+ this.right.curl(c);+ this.left.curl(c);const d = VIEWMODEL.deckWrist;+ // The deck's arms hang from the shoulders' usual place (the duel's support shoulder sits in for the hold).+ this.v.set(-VIEWMODEL.shoulderR.x, VIEWMODEL.shoulderR.y, VIEWMODEL.shoulderR.z);this.wristR.set(d.x + o.x, d.y + o.y - dip + Math.abs(swing) * 0.2, d.z + o.z - swing);this.wristL.set(-d.x + o.x, d.y + o.y - dip + Math.abs(swing) * 0.2, d.z + o.z + swing);this.right.pose(SHOULDER_R, this.wristR, this.qDeckR, POLE_R);- this.left.pose(SHOULDER_L, this.wristL, this.qDeckL, POLE_L);+ this.left.pose(this.v, this.wristL, this.qDeckL, DECK_POLE_L.set(-POLE_R.x, POLE_R.y, POLE_R.z));}dispose(): void {- this.right.dispose();- this.left.dispose();+ this.mesh.geometry.dispose();+ this.mesh.skeleton.dispose();+ this.palette.dispose();this.blaster.dispose();- for (const m of [this.mats.sleeve, this.mats.trim, this.mats.glove, this.mats.housing, this.mats.emitter, this.reticle, this.flash.material]) m.dispose();+ for (const m of [this.reticle, this.flash.material]) m.dispose();for (const t of this.textures) t.dispose();}}+const DECK_POLE_L = new Vector3();