@adatechnology/game-characters-three 0.9.6 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/instanced/body-geometry.ts","../src/instanced/segment-clips.ts","../src/instanced/accessory.ts","../src/instanced/impostor-batch.ts","../src/instanced/blob-shadow.ts","../src/instanced/flying-limbs.ts","../src/player/avatar.ts","../src/presets/player-avatar.json","../src/first-person/ik.ts","../src/player/arm-reach.ts","../src/player/head-hiding.ts","../src/player/room-avatar.ts","../src/first-person/arms.ts","../src/presets/first-person-arms.json","../src/first-person/hand.ts"],"sourcesContent":["import { shapeGeometries } from '@adatechnology/game-shapes-three'\nimport { TEAM_GAME } from '@adatechnology/game-characters'\nimport type { BodySpec, JointId } from '@adatechnology/game-characters'\n\nimport type { Three, THREE_NS } from '../three'\n\ntype Vec3 = readonly [number, number, number]\n\n/**\n * The joints the instanced body hangs from, by the game's names. `E` is the side with the negative x (bones 2, 4, 7 and 9), `D` the positive one\n * (bones 3, 5, 8 and 10); the shader's `side` depends on it, so the sides are told apart by the sign of x, whatever a spec calls them.\n */\nexport type BodyJoints = {\n readonly hip: Vec3\n readonly neck: Vec3\n readonly shoulderE: Vec3\n readonly shoulderD: Vec3\n readonly elbowE: Vec3\n readonly elbowD: Vec3\n readonly thighE: Vec3\n readonly thighD: Vec3\n readonly kneeE: Vec3\n readonly kneeD: Vec3\n}\n\nconst negativeFirst = (first: Vec3, second: Vec3): readonly [Vec3, Vec3] => (first[0] <= second[0] ? [first, second] : [second, first])\n\nexport const jointsOf = (body: BodySpec): BodyJoints => {\n const at = (id: JointId): Vec3 => body.joints[id]\n const [shoulderE, shoulderD] = negativeFirst(at('shoulderL'), at('shoulderR'))\n const [elbowE, elbowD] = negativeFirst(at('elbowL'), at('elbowR'))\n const [thighE, thighD] = negativeFirst(at('hipL'), at('hipR'))\n const [kneeE, kneeD] = negativeFirst(at('kneeL'), at('kneeR'))\n return { hip: at('hip'), neck: at('neck'), shoulderE, shoulderD, elbowE, elbowD, thighE, thighD, kneeE, kneeD }\n}\n\n/** The lengths the game's body was drawn with: a spec's segments scale them (1 for the game's own joints). */\nconst GAME_UPPER_ARM = 0.31\nconst GAME_THIGH = 0.42\n\n/** The ratio, or exactly 1 when the spec has the game's own length (so the game's numbers are not touched by rounding noise). */\nconst scaleOf = (length: number, gameLength: number): number => (Math.abs(length - gameLength) < 1e-9 ? 1 : length / gameLength)\n\n/** The drop from one joint to the next: the limbs hang straight down, so only the height counts. */\nconst distance = (from: Vec3, to: Vec3): number => Math.abs(from[1] - to[1])\n\ntype Geometry = THREE_NS.BufferGeometry\n\n/** Bone, material and pivots per vertex: the attributes the shader animates by (G 65341 `tagGeo`). */\nconst tagGeometry = (geometry: Geometry, bone: number, pivot: Vec3, material: number, parent: Vec3 = [0, 0, 0], three: Three): Geometry => {\n const source = geometry.index ? geometry.toNonIndexed() : geometry\n const count = source.attributes.position!.count\n source.setAttribute('bone', new three.Float32BufferAttribute(new Float32Array(count).fill(bone), 1))\n const colors = new Float32Array(count * 4)\n for (let index = 0; index < count; index++) colors[index * 4 + 3] = material\n source.setAttribute('vcol', new three.Float32BufferAttribute(colors, 4))\n const pivots = new Float32Array(count * 3)\n const parents = new Float32Array(count * 3)\n for (let index = 0; index < count; index++) {\n pivots.set(pivot, index * 3)\n parents.set(parent, index * 3)\n }\n source.setAttribute('pivot', new three.Float32BufferAttribute(pivots, 3))\n source.setAttribute('ppivot', new three.Float32BufferAttribute(parents, 3))\n source.deleteAttribute('uv')\n return source\n}\n\nconst MERGED_ATTRIBUTES: readonly (readonly [string, number])[] = [['position', 3], ['normal', 3], ['bone', 1], ['vcol', 4], ['pivot', 3], ['ppivot', 3]]\n\n/** The parts as one geometry (G 65354 `mergeBody`). */\nconst mergeBody = (list: readonly Geometry[], three: Three): Geometry => {\n const total = list.reduce((sum, geometry) => sum + geometry.attributes.position!.count, 0)\n const merged = new three.BufferGeometry()\n for (const [name, size] of MERGED_ATTRIBUTES) {\n const array = new Float32Array(total * size)\n let offset = 0\n for (const geometry of list) {\n const part = geometry.attributes[name]!.array as Float32Array\n array.set(part, offset)\n offset += part.length\n }\n merged.setAttribute(name, new three.BufferAttribute(array, size))\n }\n merged.computeBoundingSphere()\n return merged\n}\n\nexport type BuildInstancedBodyParams = {\n /** Radial segments of the torso: 16, 10 or 5 for the three levels of detail. */\n readonly segments: number\n /** Proportions (default `TEAM_GAME`, the joints the game's body was drawn with). */\n readonly body?: BodySpec\n}\n\n/**\n * The crowd body as one merged geometry, torso, head, hair, jaw, eyes, arms and legs tagged with the bone, pivot and material the shader reads\n * (G 65367 `buildBody`). The joints come from the spec, so a different `body` moves the limbs; the parts' own sizes follow the segment lengths.\n */\nexport const buildInstancedBody = (host: Three, { segments, body = TEAM_GAME }: BuildInstancedBodyParams): Geometry => {\n const three = shapeGeometries(host)\n const joints = jointsOf(body)\n const parts: Geometry[] = []\n const half = Math.max(4, segments >> 1)\n const { Vector2, LatheGeometry, CylinderGeometry, SphereGeometry } = three\n const limb = (radiusA: number, radiusB: number, length: number, radial: number): Geometry => {\n const geometry = new CylinderGeometry(radiusB, radiusA, length, radial, 1, false)\n geometry.translate(0, -length / 2, 0)\n return geometry\n }\n const ball = (radius: number, radial: number): Geometry => new SphereGeometry(radius, radial, Math.max(3, Math.round(radial * 0.75)))\n const tag = (geometry: Geometry, bone: number, pivot: Vec3, material: number, parent?: Vec3): void => void parts.push(tagGeometry(geometry, bone, pivot, material, parent, three))\n const profile = (points: readonly (readonly [number, number])[]): THREE_NS.Vector2[] => points.map(([radius, height]) => new Vector2(radius, height))\n const hip = joints.hip\n const neck = joints.neck\n const torso = new LatheGeometry(profile([[0, 0.86], [0.17, 0.88], [0.165, 0.98], [0.15, 1.1], [0.175, 1.26], [0.19, 1.38], [0.14, 1.47], [0.06, 1.52], [0, 1.53]]), segments)\n torso.scale(1.12, 1, 0.64)\n tag(torso, 0, hip, 1)\n const pelvis = new LatheGeometry(profile([[0, 0.78], [0.15, 0.8], [0.172, 0.88], [0.165, 0.97], [0, 0.98]]), segments)\n pelvis.scale(1.12, 1, 0.7)\n tag(pelvis, 0, hip, 2)\n const neckPart = limb(0.055, 0.05, 0.12, half)\n neckPart.translate(0, 1.6, 0)\n tag(neckPart, 1, neck, 0)\n const head = ball(0.13, segments)\n head.scale(0.96, 1.1, 1.02)\n head.translate(0, 1.67, 0.01)\n tag(head, 1, neck, 0)\n const hair = new SphereGeometry(0.137, segments, Math.max(3, segments >> 1), 0, Math.PI * 2, 0, Math.PI * 0.42)\n hair.scale(0.98, 1.1, 1.04)\n hair.rotateX(-0.35)\n hair.translate(0, 1.68, -0.01)\n tag(hair, 1, neck, 4)\n const jaw = ball(0.085, half)\n jaw.scale(1, 0.55, 1)\n jaw.translate(0, 1.58, 0.05)\n tag(jaw, 11, neck, 0)\n for (const side of [-1, 1]) {\n const eye = ball(0.02, 4)\n eye.scale(1.2, 0.7, 0.5)\n eye.translate(side * 0.045, 1.69, 0.125)\n tag(eye, 6, neck, 3)\n }\n const armLengthScale = scaleOf(distance(joints.shoulderE, joints.elbowE), GAME_UPPER_ARM)\n const legLengthScale = scaleOf(distance(joints.thighE, joints.kneeE), GAME_THIGH)\n const arms: readonly [number, number, number, Vec3, Vec3][] = [[-1, 2, 7, joints.shoulderE, joints.elbowE], [1, 3, 8, joints.shoulderD, joints.elbowD]]\n for (const [, bone, forearmBone, shoulder, elbow] of arms) {\n const upper = limb(0.074, 0.06, 0.31 * armLengthScale, half)\n upper.translate(shoulder[0], shoulder[1], 0)\n tag(upper, bone, shoulder, 1)\n const joint = ball(0.07, half)\n joint.translate(shoulder[0], shoulder[1], 0)\n tag(joint, bone, shoulder, 1)\n const forearm = limb(0.06, 0.046, 0.29 * armLengthScale, half)\n forearm.translate(elbow[0], elbow[1], 0)\n tag(forearm, forearmBone, elbow, 0, shoulder)\n const hand = ball(0.05, half)\n hand.scale(0.8, 1.2, 0.6)\n hand.translate(elbow[0], elbow[1] - 0.33 * armLengthScale, 0)\n tag(hand, forearmBone, elbow, 0, shoulder)\n }\n const legs: readonly [number, number, number, Vec3, Vec3][] = [[-1, 4, 9, joints.thighE, joints.kneeE], [1, 5, 10, joints.thighD, joints.kneeD]]\n for (const [, bone, shinBone, hipJoint, knee] of legs) {\n const thigh = limb(0.105, 0.078, 0.42 * legLengthScale, half)\n thigh.translate(hipJoint[0], hipJoint[1], 0)\n tag(thigh, bone, hipJoint, 2)\n const kneeJoint = ball(0.075, half)\n kneeJoint.translate(knee[0], knee[1], 0)\n tag(kneeJoint, shinBone, knee, 2, hipJoint)\n const shin = limb(0.077, 0.056, knee[1] - 0.1, half)\n shin.translate(knee[0], knee[1], 0)\n tag(shin, shinBone, knee, 2, hipJoint)\n const foot = ball(0.06, half)\n foot.scale(0.95, 0.72, 1.85)\n foot.translate(knee[0], 0.06, 0.05)\n tag(foot, shinBone, knee, 5, hipJoint)\n }\n return mergeBody(parts, three)\n}\n","import type { Three, THREE_NS } from '../three'\n\n/** Bones of the instanced body (`body-geometry.ts`) and texels per bone in the clip texture: a rotation and a displacement. */\nexport const CLIP_BONES = 12\nexport const CLIP_TEXELS = CLIP_BONES * 2\n/** Rows sampled per second of a clip (the bake rate of the D12 ladder). */\nexport const CLIP_RATE = 30\n/** Clips a texture may hold: the index is four bits of `iD.z`. */\nexport const CLIP_LIMIT = 16\n\nexport type ClipLimp = 'left' | 'right' | 'drag'\n\n/** A looping clip of the instanced body's walk, as numbers of the shader's own walk (`bodyAnim`) plus the gait styles of the identity extension. */\nexport type SegmentClipSpec = {\n readonly id: string\n /** Rows of the clip: its cycles at 30 Hz. */\n readonly frames: number\n /** Walk cycles the clip spans (a lurch is two). */\n readonly cycles?: number\n /** 0 arms hanging as the wandering zombie, 1 raised toward the prey (blended per instance by the arms). */\n readonly armRaise: number\n readonly sway?: number\n readonly bendPulse?: number\n readonly limp?: ClipLimp\n readonly stagger?: boolean\n}\n\nexport type SegmentClipSet = {\n readonly specs: readonly SegmentClipSpec[]\n /** First row of each clip. */\n readonly start: readonly number[]\n readonly frames: readonly number[]\n readonly cycles: readonly number[]\n readonly rows: number\n /** RGBA32F, `CLIP_TEXELS` wide: per bone a quaternion (x, y, z, w) and a displacement (x, y, z, 0). */\n readonly data: Float32Array\n}\n\ntype Quat = readonly [number, number, number, number]\n\nconst IDENTITY: Quat = [0, 0, 0, 1]\nconst axisAngle = (axis: 0 | 1 | 2, angle: number): Quat => {\n const half = angle / 2\n const q: [number, number, number, number] = [0, 0, 0, Math.cos(half)]\n q[axis] = Math.sin(half)\n return q\n}\nconst multiply = (a: Quat, b: Quat): Quat => [\n a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],\n a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0],\n a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3],\n a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],\n]\nconst rotateX = (angle: number): Quat => axisAngle(0, angle)\nconst rotateZ = (angle: number): Quat => axisAngle(2, angle)\n\nconst TWO_PI = Math.PI * 2\nconst WALK_FRAMES = 24\nconst LEAN_PART = 0.3\nconst ARM_FORWARD = [-0.12, -1.35] as const\nconst STAGGER_ARM = -0.95\n\n/** The clips of the kit: each gait family with its arms down and its arms raised (the crowd blends the two by how far the agent has raised its arms). */\nconst family = (id: string, rest: Omit<SegmentClipSpec, 'id' | 'frames' | 'armRaise'>, frames = WALK_FRAMES): readonly SegmentClipSpec[] => [\n { id: `${id}_down`, frames, armRaise: 0, ...rest },\n { id: `${id}_up`, frames, armRaise: 1, ...rest },\n]\n\nexport const SEGMENT_CLIPS: readonly SegmentClipSpec[] = [\n ...family('walk', {}),\n ...family('limp_left', { limp: 'left' }),\n ...family('limp_right', { limp: 'right' }),\n ...family('drag', { limp: 'drag' }),\n ...family('lurch', { bendPulse: 1, cycles: 2 }, WALK_FRAMES * 2),\n ...family('shamble', { sway: 0.1 }),\n ...family('stagger', { stagger: true }),\n]\n\nconst limpOf = (limp: ClipLimp | undefined, left: boolean, ph: number): Quat => {\n if (limp === 'drag') return left ? rotateX(0.55) : IDENTITY\n if (limp === 'left' && left) return rotateX(-0.32 * (0.5 + 0.5 * Math.sin(ph)))\n if (limp === 'right' && !left) return rotateX(-0.32 * (0.5 + 0.5 * Math.sin(ph)))\n return IDENTITY\n}\n\n/** The quaternion of every bone at a step of a clip, and the displacement of the whole body, from the maths of the shader's walk. */\nconst sampleBones = (spec: SegmentClipSpec, step: number): { readonly quats: Quat[]; readonly bounce: number } => {\n const cycles = spec.cycles ?? 1\n const ph = (step / spec.frames) * TWO_PI * cycles\n const raise = spec.armRaise\n const quats: Quat[] = Array.from({ length: CLIP_BONES }, () => IDENTITY)\n for (const bone of [4, 5]) {\n const legSign = bone === 4 ? 1 : -1\n const swing = rotateX(-Math.sin(ph) * legSign * 0.5)\n quats[bone] = multiply(limpOf(spec.limp, bone === 4, ph), swing)\n quats[bone + 5] = rotateX(Math.max(0, Math.cos(ph + (legSign > 0 ? 0 : Math.PI))) * 0.85)\n }\n for (const bone of [2, 3]) {\n const side = bone === 2 ? -1 : 1\n const armSwing = Math.sin(ph) * side\n const forward = (1 - raise) * (ARM_FORWARD[0] + armSwing * 0.3) + raise * (ARM_FORWARD[1] + armSwing * 0.18)\n const arm = multiply(rotateX(forward), rotateZ(side * 0.08))\n quats[bone] = spec.stagger ? multiply(rotateX(STAGGER_ARM + 0.25 * Math.sin(ph)), arm) : arm\n quats[bone + 5] = rotateX((1 - raise) * (-0.3 - Math.max(0, armSwing) * 0.3) + raise * -0.15)\n }\n quats[11] = rotateX(0.05)\n const bend = (spec.bendPulse ?? 0) * 0.22 * Math.max(0, Math.sin(ph * 0.5)) ** 2 + (spec.stagger ? 0.18 + 0.22 * Math.sin(2 * ph) : 0)\n const sway = (spec.sway ?? 0) * Math.sin(ph) + (spec.stagger ? 0.2 * Math.sin(ph) : 0)\n quats[0] = multiply(multiply(rotateX(bend), rotateZ(sway)), rotateX(LEAN_PART))\n return { quats, bounce: Math.abs(Math.sin(ph)) * 0.035 }\n}\n\n/** Samples the clips at 30 Hz into one table (the rows of every clip one after the other): pure, no GPU. */\nexport const bakeSegmentClips = (specs: readonly SegmentClipSpec[] = SEGMENT_CLIPS): SegmentClipSet => {\n if (specs.length > CLIP_LIMIT) throw new Error(`game-characters-three: a clip texture holds at most ${CLIP_LIMIT} clips`)\n const start: number[] = []\n let rows = 0\n for (const spec of specs) {\n start.push(rows)\n rows += spec.frames\n }\n const data = new Float32Array(rows * CLIP_TEXELS * 4)\n specs.forEach((spec, index) => {\n for (let step = 0; step < spec.frames; step++) {\n const { quats, bounce } = sampleBones(spec, step)\n const row = (start[index]! + step) * CLIP_TEXELS * 4\n quats.forEach((quat, bone) => {\n data.set(quat, row + bone * 8)\n data.set(bone === 0 ? [0, bounce, 0, 0] : [0, 0, 0, 0], row + bone * 8 + 4)\n })\n }\n })\n return { specs, start, frames: specs.map((spec) => spec.frames), cycles: specs.map((spec) => spec.cycles ?? 1), rows, data }\n}\n\n/** What a body material needs of the clips: the texture and the three tables, as shared uniforms. */\nexport type SegmentClipUniforms = {\n readonly uClips: { value: THREE_NS.DataTexture }\n readonly uClipStart: { value: number[] }\n readonly uClipFrames: { value: number[] }\n readonly uClipCycles: { value: number[] }\n}\n\nconst padded = (values: readonly number[], fill: number): number[] => Array.from({ length: CLIP_LIMIT }, (_, index) => values[index] ?? fill)\n\n/**\n * The clip texture (economy ladder, step 3): RGBA32F, `CLIP_TEXELS` (24) wide, one row per sampled step, `NearestFilter` with no mipmaps: float texels are not\n * filterable everywhere and a blend would mix neighbouring bones. The shader blends two rows itself.\n */\nexport const createSegmentClipUniforms = (three: Three, set: SegmentClipSet = bakeSegmentClips()): SegmentClipUniforms => {\n const texture = new three.DataTexture(set.data as Float32Array<ArrayBuffer>, CLIP_TEXELS, set.rows, three.RGBAFormat, three.FloatType)\n texture.minFilter = three.NearestFilter\n texture.magFilter = three.NearestFilter\n texture.generateMipmaps = false\n texture.needsUpdate = true\n return { uClips: { value: texture }, uClipStart: { value: padded(set.start, 0) }, uClipFrames: { value: padded(set.frames, 1) }, uClipCycles: { value: padded(set.cycles, 1) } }\n}\n\n/** The index of a clip by id (the crowd picks its family by name). */\nexport const clipIndexOf = (set: SegmentClipSet, id: string): number => {\n const index = set.specs.findIndex((spec) => spec.id === id)\n if (index < 0) throw new Error(`game-characters-three: no clip \"${id}\"`)\n return index\n}\n","import { createRng } from '@adatechnology/game-characters'\n\nimport { EXTRAS } from '../rich/accessories/extras'\nimport { HATS } from '../rich/accessories/hats'\nimport { createPersonKit } from '../rich/person-kit'\nimport type { Three, THREE_NS } from '../three'\n\nimport { ACCESSORY_BIT } from './identity-layout'\n\nexport type AccessoryAttach = 'head' | 'torso'\n\n/** One accessory drawn by the kit's own survivor builder: a hat of `HATS` (`hat`) or a piece of gear of `EXTRAS` (`extra`), in one colour. */\nexport type KitAccessory = {\n readonly id: string\n /** The bit of `iD.y` that says a body carries it (`ACCESSORY_BIT`). */\n readonly bit: number\n readonly attach: AccessoryAttach\n readonly hat?: string\n readonly extra?: string\n readonly color: number\n}\n\n/** The four accessory batches of the kit: a cap, a helmet, a backpack and a hood. */\nexport const KIT_ACCESSORIES: readonly KitAccessory[] = [\n { id: 'cap', bit: ACCESSORY_BIT.CAP, attach: 'head', hat: 'cap', color: 0x2f4a6a },\n { id: 'helmet', bit: ACCESSORY_BIT.HELMET, attach: 'head', hat: 'helmet', color: 0x4a5238 },\n { id: 'backpack', bit: ACCESSORY_BIT.BACKPACK, attach: 'torso', extra: 'backpack', color: 0x6a4a2a },\n { id: 'hood', bit: ACCESSORY_BIT.EXTRA, attach: 'head', extra: 'hood', color: 0x3a3a40 },\n]\n\n/** Where the survivor builder puts the head and the torso (its own frame): the accessory is normalised against these. */\nconst HEAD_REFERENCE = { center: [0, 1.8, 0], height: 0.363, pivot: [0, 1.64, 0] } as const\nconst TORSO_REFERENCE = { center: [0, 1.23, 0], height: 0.74, pivot: [0, 0.9, 0] } as const\nconst ATTACH_BONE: Readonly<Record<AccessoryAttach, number>> = { head: 1, torso: 0 }\nconst MATERIAL_OWN_COLOR = 6\n\ntype Vec3 = readonly [number, number, number]\n\n/**\n * The accessory geometry in a unit frame (the reference head or torso at the origin, one unit tall), tagged for the body shader: `bone`, `vcol` (own colour),\n * `refPivot` and `ppivot`. A batch moves and scales it per variant with `iAcc` (`accessoryPlacement`): baked once, never per variant.\n */\nexport const buildKitAccessory = (host: Three, accessory: KitAccessory): THREE_NS.BufferGeometry => {\n const kit = createPersonKit(host, { random: createRng(77), createCanvas: () => { throw new Error('game-characters-three: an accessory needs no canvas') } })\n const { THREE, PI, Bx, add, cmat, cap } = kit\n const group = new THREE.Group()\n const color = cmat(accessory.color, undefined)\n if (accessory.hat) HATS.find((hat) => hat.kinds.includes(accessory.hat as string))?.apply({ THREE, PI, Hd: group, add, Bx, cmat, cap, c: color, k: accessory.hat, sp: { hat: {} } } as never)\n if (accessory.extra) EXTRAS[accessory.extra]?.({ THREE, PI, U: group, Hd: group, root: group, add, Bx, cmat, m: color, k: accessory.extra } as never)\n group.updateMatrixWorld(true)\n const reference = accessory.attach === 'head' ? HEAD_REFERENCE : TORSO_REFERENCE\n const parts: THREE_NS.BufferGeometry[] = []\n group.traverse((object) => {\n const mesh = object as THREE_NS.Mesh\n if (!mesh.isMesh) return\n const geometry = mesh.geometry.clone()\n geometry.applyMatrix4(mesh.matrixWorld)\n const source = geometry.index ? geometry.toNonIndexed() : geometry\n const paint = (mesh.material as THREE_NS.MeshStandardMaterial).color\n parts.push(tag(host, source, { reference, bone: ATTACH_BONE[accessory.attach], paint: [paint.r, paint.g, paint.b] }))\n })\n return merge(host, parts)\n}\n\nconst tag = (host: Three, source: THREE_NS.BufferGeometry, { reference, bone, paint }: { readonly reference: typeof HEAD_REFERENCE | typeof TORSO_REFERENCE; readonly bone: number; readonly paint: Vec3 }): THREE_NS.BufferGeometry => {\n const position = source.attributes.position as THREE_NS.BufferAttribute\n const normal = source.attributes.normal as THREE_NS.BufferAttribute\n const count = position.count\n const unit = new Float32Array(count * 3)\n const pivot = new Float32Array(count * 3)\n const colors = new Float32Array(count * 4)\n const bones = new Float32Array(count).fill(bone)\n const anchor = reference.pivot.map((value, axis) => (value - reference.center[axis]!) / reference.height)\n for (let index = 0; index < count; index++) {\n unit[index * 3] = (position.getX(index) - reference.center[0]) / reference.height\n unit[index * 3 + 1] = (position.getY(index) - reference.center[1]) / reference.height\n unit[index * 3 + 2] = (position.getZ(index) - reference.center[2]) / reference.height\n pivot.set(anchor, index * 3)\n colors.set([paint[0], paint[1], paint[2], MATERIAL_OWN_COLOR], index * 4)\n }\n const geometry = new host.BufferGeometry()\n geometry.setAttribute('position', new host.BufferAttribute(unit, 3))\n geometry.setAttribute('normal', new host.BufferAttribute(Float32Array.from(normal.array), 3))\n geometry.setAttribute('bone', new host.BufferAttribute(bones, 1))\n geometry.setAttribute('vcol', new host.BufferAttribute(colors, 4))\n geometry.setAttribute('refPivot', new host.BufferAttribute(pivot, 3))\n geometry.setAttribute('ppivot', new host.BufferAttribute(new Float32Array(count * 3), 3))\n return geometry\n}\n\nconst MERGED: readonly (readonly [string, number])[] = [['position', 3], ['normal', 3], ['bone', 1], ['vcol', 4], ['refPivot', 3], ['ppivot', 3]]\n\nconst merge = (host: Three, parts: readonly THREE_NS.BufferGeometry[]): THREE_NS.BufferGeometry => {\n const total = parts.reduce((sum, part) => sum + part.attributes.position!.count, 0)\n const merged = new host.BufferGeometry()\n for (const [name, size] of MERGED) {\n const array = new Float32Array(total * size)\n let offset = 0\n for (const part of parts) {\n array.set(part.attributes[name]!.array as Float32Array, offset)\n offset += part.attributes[name]!.array.length\n }\n merged.setAttribute(name, new host.BufferAttribute(array, size))\n }\n return merged\n}\n\n/** Materials of the bone's vertices that count for the placement: a baked body marks skin, hair and trousers as one own-colour material (6), only the eyes and the shirt apart. */\nconst EYE_MATERIAL = 3\nconst HIDDEN_PLACEMENT = [0, 0, 0, 0] as const\n\n/**\n * The `iAcc` of a baked body for an accessory: where the accessory goes (the centre of the head, or of the torso) and how big (its height), read from the variant's\n * own geometry, so the same accessory sits right on every one of the 20 variants. The head is the bone-1 vertices without the eyes, the torso the bone-0 ones;\n * a body without them gets a zero scale, so the accessory is not drawn instead of showing up unscaled at the feet.\n */\nexport const accessoryPlacement = (body: THREE_NS.BufferGeometry, attach: AccessoryAttach): readonly [number, number, number, number] => {\n const position = body.attributes.position as THREE_NS.BufferAttribute\n const bone = body.attributes.bone as THREE_NS.BufferAttribute\n const paint = body.attributes.vcol as THREE_NS.BufferAttribute\n const wanted = ATTACH_BONE[attach]\n const min = [Infinity, Infinity, Infinity]\n const max = [-Infinity, -Infinity, -Infinity]\n for (let index = 0; index < position.count; index++) {\n if (bone.getX(index) !== wanted || paint.getW(index) === EYE_MATERIAL) continue\n for (let axis = 0; axis < 3; axis++) {\n const value = axis === 0 ? position.getX(index) : axis === 1 ? position.getY(index) : position.getZ(index)\n if (value < min[axis]!) min[axis] = value\n if (value > max[axis]!) max[axis] = value\n }\n }\n if (!Number.isFinite(min[0])) return HIDDEN_PLACEMENT\n return [(min[0]! + max[0]!) / 2, (min[1]! + max[1]!) / 2, (min[2]! + max[2]!) / 2, max[1]! - min[1]!]\n}\n","import type { Three, THREE_NS } from '../three'\n\nimport { TROUSER_PALETTE, glslColor } from './identity-layout'\nimport { IMPOSTOR_ANGLES, IMPOSTOR_BONE_SCALE, IMPOSTOR_FRAMES, IMPOSTOR_MATERIAL_SCALE } from './impostor-atlas'\nimport type { ImpostorAtlas } from './impostor-atlas'\n\nexport type ImpostorBatchOptions = {\n /** Instances the batch holds. */\n readonly max: number\n /** The light the baked shade is multiplied by (the impostor is not lit by the scene; default 0.85 grey). */\n readonly light?: { readonly r: number; readonly g: number; readonly b: number }\n}\n\n/** One far body: the same `iA`, `iC` and shirt as the near body, the scale of its variant, its silhouette (the atlas block) and the ground height. */\nexport type ImpostorInstance = {\n readonly a: readonly [number, number, number, number]\n /** Height and width scale (the near body's `b[0]` and `b[1]`). */\n readonly scale: readonly [number, number]\n readonly silhouette: number\n readonly y?: number\n readonly c: readonly [number, number, number, number]\n readonly color: { readonly r: number; readonly g: number; readonly b: number }\n readonly d?: readonly [number, number, number, number]\n}\n\nexport type ImpostorBatch = {\n readonly mesh: THREE_NS.Mesh & { count: number }\n readonly material: THREE_NS.ShaderMaterial\n readonly count: number\n begin(): void\n push(instance: ImpostorInstance): void\n end(): void\n}\n\nconst ATTRIBUTES: readonly (readonly [string, number])[] = [['iA', 4], ['iB', 4], ['iC', 4], ['iCol', 3], ['iD', 4]]\nconst TROUSERS = `const vec3 TROUSERS[16] = vec3[16](${TROUSER_PALETTE.map(glslColor).join(',')});`\n\nconst VERTEX = `\n attribute vec4 iA; attribute vec4 iB; attribute vec4 iC; attribute vec3 iCol; attribute vec4 iD;\n uniform vec4 uBox[SILHOUETTES]; uniform vec2 uCell; uniform vec2 uGrid;\n varying vec2 vUv; varying vec4 vC; varying vec3 vShirt; varying float vTrousers;\n void main(){\n vec3 toCam = vec3(cameraPosition.x - iA.x, 0., cameraPosition.z - iA.y);\n toCam /= max(length(toCam), 0.001);\n vec3 right = vec3(toCam.z, 0., -toCam.x);\n float c = cos(iA.z), s = sin(iA.z);\n vec3 local = vec3(c*toCam.x - s*toCam.z, 0., s*toCam.x + c*toCam.z);\n float angle = mod(floor(atan(local.x, local.z)/6.2831853*ANGLES + 0.5), ANGLES);\n float frame = floor(fract(iA.w)*FRAMES);\n float cell = (iB.z*FRAMES + frame)*ANGLES + angle;\n vec4 box = uBox[int(iB.z)];\n vec2 inset = 0.5/uCell;\n vec2 within = mix(inset, 1. - inset, position.xy);\n vUv = vec2(mod(cell, uGrid.x) + within.x, floor(cell/uGrid.x) + within.y)/uGrid;\n vec3 world = vec3(iA.x, iB.w, iA.y) + right*((position.x - 0.5)*2.*box.x*iB.y) + vec3(0., box.y + position.y*box.z, 0.)*iB.x;\n vC = iC; vShirt = iCol; vTrousers = mod(iD.y, 16.);\n gl_Position = projectionMatrix*viewMatrix*vec4(world, 1.);\n }\n`\n\nconst FRAGMENT = `\n uniform sampler2D uAtlas; uniform sampler2D uColors; uniform vec3 uLight;\n varying vec2 vUv; varying vec4 vC; varying vec3 vShirt; varying float vTrousers;\n ${TROUSERS}\n bool missing(float bit){ return mod(floor(vC.x/bit), 2.) > 0.5; }\n void main(){\n vec4 texel = texture2D(uAtlas, vUv);\n if (texel.a < 0.5) discard;\n float bone = floor(texel.r*255./${IMPOSTOR_BONE_SCALE}.0 + 0.5);\n float material = floor(texel.g*255./${IMPOSTOR_MATERIAL_SCALE}.0 + 0.5);\n if ((bone==1.||bone==6.||bone==11.) && missing(1.)) discard;\n if (bone==11. && missing(512.)) discard;\n if ((bone==2.||bone==7.) && missing(2.)) discard; if ((bone==3.||bone==8.) && missing(4.)) discard;\n if ((bone==4.||bone==9.) && missing(8.)) discard; if ((bone==5.||bone==10.) && missing(16.)) discard;\n if (bone==7. && missing(32.)) discard; if (bone==8. && missing(64.)) discard;\n if (bone==9. && missing(128.)) discard; if (bone==10. && missing(256.)) discard;\n vec3 skin = mix(vec3(0.93,0.74,0.6), vec3(0.42,0.27,0.18), vC.w);\n skin = mix(skin, vec3(0.435,0.478,0.36), vC.y);\n vec3 baked = texture2D(uColors, vUv).rgb; baked *= baked;\n vec3 tint = material==1. ? vShirt : material==2. ? mix(baked, TROUSERS[int(vTrousers)], 0.75) : material==3. ? vec3(0.08) : baked;\n gl_FragColor = vec4(tint*texel.b*uLight, 1.);\n #include <colorspace_fragment>\n }\n`\n\n/** The far bodies as one draw call: a standing quad per body that picks its cell of the atlas by the view angle and the walk phase, tinted per instance. */\nexport const createImpostorBatch = (three: Three, atlas: ImpostorAtlas, { max, light = { r: 0.85, g: 0.85, b: 0.85 } }: ImpostorBatchOptions): ImpostorBatch => {\n const geometry = new three.InstancedBufferGeometry()\n geometry.setAttribute('position', new three.Float32BufferAttribute([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], 3))\n geometry.setIndex([0, 1, 2, 0, 2, 3])\n const attributes: Record<string, THREE_NS.InstancedBufferAttribute> = {}\n for (const [name, size] of ATTRIBUTES) {\n const attribute = new three.InstancedBufferAttribute(new Float32Array(max * size), size)\n attribute.setUsage(three.DynamicDrawUsage)\n geometry.setAttribute(name, attribute)\n attributes[name] = attribute\n }\n geometry.instanceCount = 0\n const material = new three.ShaderMaterial({\n defines: { SILHOUETTES: Math.max(1, atlas.silhouettes), ANGLES: `${IMPOSTOR_ANGLES}.0`, FRAMES: `${IMPOSTOR_FRAMES}.0` },\n uniforms: {\n uAtlas: { value: atlas.texture },\n uColors: { value: atlas.colorTexture },\n uLight: { value: new three.Vector3(light.r, light.g, light.b) },\n uCell: { value: new three.Vector2(atlas.cellWidth, atlas.cellHeight) },\n uGrid: { value: new three.Vector2(atlas.columns, atlas.rows) },\n uBox: { value: atlas.boxes.map((box) => new three.Vector4(box.halfWidth, box.bottom, box.height, 0)) },\n },\n vertexShader: VERTEX,\n fragmentShader: FRAGMENT,\n side: three.DoubleSide,\n })\n material.customProgramCacheKey = () => '|impostor'\n const mesh = new three.Mesh(geometry, material) as unknown as THREE_NS.Mesh & { count: number }\n Object.defineProperty(mesh, 'count', { get: () => geometry.instanceCount, set: (value: number) => (geometry.instanceCount = value) })\n mesh.frustumCulled = false\n mesh.name = 'impostors'\n let count = 0\n return {\n mesh,\n material,\n get count() {\n return count\n },\n begin() {\n count = 0\n },\n push({ a, scale, silhouette, y = 0, c, color, d }) {\n if (count >= max) return\n const index = count++\n attributes.iA!.array.set(a, index * 4)\n attributes.iB!.array.set([scale[0], scale[1], silhouette, y], index * 4)\n attributes.iC!.array.set(c, index * 4)\n attributes.iCol!.array.set([color.r, color.g, color.b], index * 3)\n attributes.iD!.array.set(d ?? [0, 0, 0, 0], index * 4)\n },\n end() {\n geometry.instanceCount = count\n // three uploads every attribute flagged, drawn or not: an empty batch would send one empty upload per attribute each frame\n if (count === 0) return\n for (const attribute of Object.values(attributes)) {\n attribute.clearUpdateRanges()\n attribute.addUpdateRange(0, count * attribute.itemSize)\n attribute.needsUpdate = true\n }\n },\n }\n}\n","import type { Three, THREE_NS } from '../three'\n\nexport type BlobShadowOptions = {\n /** Shadows the batch can hold. */\n readonly max: number\n /** Radius in metres of a body of height 1 (default 0.55). */\n readonly radius?: number\n /** The darkness at the centre (default 0.42). */\n readonly opacity?: number\n}\n\nexport type BlobShadowBatch = {\n readonly mesh: THREE_NS.Mesh & { count: number }\n readonly count: number\n begin(): void\n /** One shadow under a body at `x`, `z` on the ground height `y`, for a body `height` metres tall. */\n push(x: number, y: number, z: number, height: number): void\n end(): void\n}\n\nconst BLOB_LIFT = 0.03\n\n/**\n * The shadow of a body that is too far for a real one (economy ladder, step 1): one dark disc per body on the ground, a single draw call.\n * No depth write and no shadow map: it costs a quad per body.\n */\nexport const createBlobShadowBatch = (three: Three, { max, radius = 0.55, opacity = 0.42 }: BlobShadowOptions): BlobShadowBatch => {\n const geometry = new three.InstancedBufferGeometry()\n geometry.setAttribute('position', new three.Float32BufferAttribute([-1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1], 3))\n geometry.setAttribute('uv', new three.Float32BufferAttribute([-1, -1, 1, -1, 1, 1, -1, 1], 2))\n geometry.setIndex([0, 2, 1, 0, 3, 2])\n const placement = new three.InstancedBufferAttribute(new Float32Array(max * 4), 4)\n placement.setUsage(three.DynamicDrawUsage)\n geometry.setAttribute('iBlob', placement)\n geometry.instanceCount = 0\n const material = new three.ShaderMaterial({\n transparent: true,\n depthWrite: false,\n polygonOffset: true,\n polygonOffsetFactor: -2,\n polygonOffsetUnits: -2,\n uniforms: { uOpacity: { value: opacity } },\n vertexShader: `attribute vec4 iBlob; varying vec2 vUv;\n void main(){ vUv = uv; vec3 p = position*iBlob.w + iBlob.xyz; gl_Position = projectionMatrix*viewMatrix*vec4(p, 1.); }`,\n fragmentShader: `uniform float uOpacity; varying vec2 vUv;\n void main(){ float d = dot(vUv, vUv); if (d > 1.) discard; gl_FragColor = vec4(0., 0., 0., uOpacity*(1. - smoothstep(0.15, 1., d))); }`,\n })\n const mesh = new three.Mesh(geometry, material) as unknown as THREE_NS.Mesh & { count: number }\n Object.defineProperty(mesh, 'count', { get: () => geometry.instanceCount, set: (value: number) => (geometry.instanceCount = value) })\n mesh.frustumCulled = false\n mesh.renderOrder = -1\n mesh.name = 'blob-shadows'\n let count = 0\n return {\n mesh,\n get count() {\n return count\n },\n begin() {\n count = 0\n },\n push(x, y, z, height) {\n if (count >= max) return\n placement.array.set([x, y + BLOB_LIFT, z, radius * height], count++ * 4)\n },\n end() {\n geometry.instanceCount = count\n // three uploads every attribute flagged, drawn or not: an empty batch would send one empty upload per attribute each frame\n if (count === 0) return\n placement.clearUpdateRanges()\n placement.addUpdateRange(0, count * 4)\n placement.needsUpdate = true\n },\n }\n}\n","import { shapeGeometries } from '@adatechnology/game-shapes-three'\nimport type { Three, THREE_NS } from '../three'\n\nconst GRAVITY = 9.8\nconst FLOOR_Y = 0.07\nconst BOUNCE = -0.3\nconst FRICTION = 0.6\nconst SPIN_DAMPING = 0.5\nconst REST_SPEED = 0.4\nconst LEG_COLOR = 0x2c3340\n\n/** Where a limb comes from: arms leave at chest height with the sleeve's colour, legs low and long with the trousers'. */\nexport type LimbLaunch = {\n readonly x: number\n readonly z: number\n readonly kind: 'arm' | 'leg'\n /** The sleeve colour of the owner (arms). */\n readonly color: number\n /** The blood of the owner's age: colour, dried colour and whether it bleeds at all (the oldest dead do not: they spill dust). */\n readonly blood: { readonly color: number; readonly dried: number; readonly bleeds: boolean }\n}\n\nexport type FlyingLimb = {\n x: number\n y: number\n z: number\n vx: number\n vy: number\n vz: number\n rx: number\n rz: number\n w: number\n t: number\n rest: boolean\n len: number\n col: number\n cor: number\n seco: number\n splat: boolean\n}\n\n/** The fluids bridge: where a limb bleeds when it leaves and where it splats when it lands. The host decides what that draws. */\nexport type LimbEffects = {\n onLaunch?(limb: FlyingLimb, kind: 'arm' | 'leg'): void\n onSplat?(splat: { readonly x: number; readonly z: number; readonly radius: number; readonly rotation: number; readonly color: number; readonly dried: number }): void\n}\n\nexport type FlyingLimbsOptions = {\n /** Pieces alive at once (the game's 40 per player); the oldest is reused. */\n readonly max?: number\n readonly random: () => number\n readonly effects?: LimbEffects\n}\n\nexport type FlyingLimbs = {\n readonly mesh: THREE_NS.InstancedMesh\n readonly limbs: readonly FlyingLimb[]\n launch(launch: LimbLaunch): FlyingLimb\n update(dt: number): void\n}\n\n/** Torn-off pieces that fly, bounce and stay on the ground, as one instanced mesh of capsules (G 67953 `fxLimb`, 68040 update). */\nexport const createFlyingLimbs = (host: Three, { max = 40, random, effects = {} }: FlyingLimbsOptions): FlyingLimbs => {\n const three = shapeGeometries(host)\n const limbs: FlyingLimb[] = []\n const mesh = new three.InstancedMesh(new three.CapsuleGeometry(0.065, 0.32, 2, 6), new three.MeshLambertMaterial({ color: 0xffffff }), max)\n mesh.count = 0\n mesh.castShadow = true\n mesh.setColorAt(0, new three.Color())\n const matrix = new three.Matrix4()\n const quaternion = new three.Quaternion()\n const scale = new three.Vector3()\n const position = new three.Vector3()\n const euler = new three.Euler()\n const color = new three.Color()\n return {\n mesh,\n limbs,\n launch({ x, z, kind, color: sleeve, blood }) {\n const isLeg = kind === 'leg'\n const limb = (limbs.length < max ? {} : limbs.shift()) as FlyingLimb\n Object.assign(limb, {\n x,\n y: isLeg ? 0.5 : 1.2,\n z,\n vx: (random() - 0.5) * 3,\n vy: 2 + random() * 2,\n vz: (random() - 0.5) * 3,\n rx: random() * 6,\n rz: random() * 6,\n w: (random() - 0.5) * 10,\n t: 0,\n rest: false,\n len: isLeg ? 1.3 : 1,\n col: isLeg ? LEG_COLOR : sleeve,\n })\n limbs.push(limb)\n limb.cor = blood.color\n limb.seco = blood.dried\n limb.splat = !blood.bleeds\n effects.onLaunch?.(limb, kind)\n return limb\n },\n update(dt) {\n limbs.forEach((limb, index) => {\n if (!limb.rest) {\n limb.t += dt\n limb.vy -= GRAVITY * dt\n limb.x += limb.vx * dt\n limb.y += limb.vy * dt\n limb.z += limb.vz * dt\n limb.rx += limb.w * dt\n if (limb.y < FLOOR_Y) {\n limb.y = FLOOR_Y\n limb.vy *= BOUNCE\n limb.vx *= FRICTION\n limb.vz *= FRICTION\n limb.w *= SPIN_DAMPING\n if (!limb.splat) {\n limb.splat = true\n effects.onSplat?.({ x: limb.x, z: limb.z, radius: 0.2 + random() * 0.2, rotation: random() * 6.28, color: limb.cor, dried: limb.seco })\n }\n if (Math.abs(limb.vy) < REST_SPEED) {\n limb.rest = true\n limb.rx = Math.PI / 2\n }\n }\n }\n matrix.compose(position.set(limb.x, limb.y, limb.z), quaternion.setFromEuler(euler.set(limb.rx, limb.rz, 0)), scale.set(1, limb.len, 1))\n mesh.setMatrixAt(index, matrix)\n mesh.setColorAt(index, color.set(limb.col))\n })\n mesh.count = limbs.length\n mesh.instanceMatrix.needsUpdate = true\n if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true\n },\n }\n}\n","import {\n POSE_CLIPS,\n clipEventsBetween,\n createPoseClipRegistry,\n createRng,\n filterPoseChannels,\n samplePoseClip,\n walkCadence,\n stepCascade,\n walkGait,\n} from '@adatechnology/game-characters'\nimport type { GaitProfile, PoseClip, PoseClipEvent, PoseClipRegistry } from '@adatechnology/game-characters'\nimport type { HandTargets } from '@adatechnology/game-contracts'\n\nimport preset from '../presets/player-avatar.json'\nimport { buildHand } from '../rich/accessories/hands'\nimport { createBestBuilder } from '../rich/best-builder'\nimport { createRigAnimator } from '../rich/animator'\nimport type { PoseTargets, RichRig } from '../rich/animator'\nimport type { Three, THREE_NS } from '../three'\nimport { createArmReach, type ReachView } from './arm-reach'\nimport { createHeadHider } from './head-hiding'\nimport type { AvatarViewMode } from './head-hiding'\n\nconst TWO_PI = Math.PI * 2\nconst MAX_GAIT = 1.4\nconst CLIP_BLEND = 0.12\nconst CLIP_CASCADE = 5\nconst FALL_SECONDS = 0.3\n/** The builder's eyes in the head's own frame (best-builder: eyes at y 1.815, z about 0.16). */\nconst BUILDER_EYE = [0, 1.815, 0.16] as const\nconst EYE_OFFSET = [0, -0.068, 0] as const // brings the measured standing eye (1.768 m) to about 1.70 m\nconst EYE_BOB = 0.5\n\n// Constants carried from the team game's GPU pose code, `BODY_CHUNK` (src/instanced/body-chunk.ts), whose line numbers are quoted below.\nconst HIP_HEIGHT = 0.95 // :68, :74 the trunk pivot\nconst WALK_ARM = 0.28 // arms swing naturally beside the hips, staying below the waist\nconst WALK_BOB = 0.035 // :71 `abs(sin(ph))*0.035*gait`\nconst WALK_LEAN = 0.04 // :64 `0.04*gait`\nconst RUN_LEAN = 0.16\nconst RUN_BOB = 0.05\nconst REST_ARM_Z = 0.18 // outward carrying angle: clears hips and pelvis comfortably\nconst CROUCH = { thigh: -0.95, thighWalk: 0.3, shin: 1.9, lean: 0.25, drop: -0.35 } // :29, :66, :71\nconst AIMED = { shoulder: -1.42, perAim: 0.85, swing: 0.02, zRight: -0.54, zLeft: 0.36, elbowRight: -0.04, elbowLeft: -0.12 } // :45, :47\nconst SIT = { thigh: -1.5, lean: -0.08, arm: -0.45, armZ: 0.12, elbow: -0.75 }\nconst LIE = { knee: 0.08, armZ: 0.12, elbow: -0.1 }\nconst DOWN = { thighWalk: 0.5, shinSwing: 0.85, shinBend: 1.3, armHigh: -2.8, armLow: -0.35, armWave: 0.3, armZ: 0.5, armZWave: 0.3, tilt: 1.5, roll: 0.3, hipY: 0.16, hipZ: 0.6, hipZFlip: 1.2 } // :29-:47, :74\n/** `playerHand()`: the elbow-to-hand offset of the weapon hand (the weapon hand is the puppet's right, at -x). */\n/** A hand on a handle: the shoulder over the feet and the length of the arm to the palm, metres. */\nconst DOOR_SHOULDER = 1.42\nconst DOOR_ARM = 0.62\nconst HAND_OFFSET = { x: 0, y: -0.33, z: 0.04 }\n\nexport type PlayerAvatarSpec = Record<string, unknown>\n\nexport type PlayerAvatarOptions = {\n /** The body spec for the rich builder (`createBestBuilder.build`). Default: the team game's player (`player-avatar.json`). Merged over the default. */\n readonly spec?: PlayerAvatarSpec\n /** Shirt colour, 0xRRGGBB. Default the team game's `PLAYER_COR`. */\n readonly shirtColor?: number\n /** The clips `play(id)` finds. Default: a registry with `POSE_CLIPS`. */\n readonly clips?: PoseClipRegistry\n /** Seconds to blend a clip in and out. Default 0.12. */\n readonly blend?: number\n /** Seconds the body takes to go down (the shader's `fk` smoothstep). 0 is instant. Default 0.3. */\n readonly fallSeconds?: number\n /** Smooth the joints with the Bestiário cascade (default true). */\n readonly cascade?: boolean\n /**\n * How many times faster the cascade follows while a clip that does not loop plays: a strike is over in a third of a second, and at the walk's pace the joints would\n * still be on their way when it ends (a punch that never reaches the shoulder). 1 keeps the walk's pace. Default 5.\n */\n readonly clipCascade?: number\n /** Where the eye sits against the builder's eye point, in the head's frame (so it follows the head's scale and turn). Default [0, -0.068, 0]: about 1.70 m standing. */\n readonly eyeOffset?: readonly [number, number, number]\n /** How much of the walking and running bob of the body reaches the eye: 0 none, 1 all of it. Default 0.5. */\n readonly eyeBob?: number\n}\n\nexport type AvatarEvent = PoseClipEvent & { clip: string }\n\nexport type AvatarItemUsePose = {\n readonly id: string\n readonly position: readonly [number, number, number]\n readonly rotation: readonly [number, number, number]\n /** How closed the other hand is (0 open to 1 closed) when it works on the item, as a hand turning a cap off opens between strokes; the room brings it there with `reach`. */\n readonly gripL?: number\n}\n\nexport type AvatarUpdate = {\n /** Ground speed, m/s. Ties cadence and swing to the ground (the game's `walkCad` and `walkGait`). */\n speed?: number\n /** Accepted for the game's state; the gait depends on the speed alone, as in the team game. */\n running?: boolean\n crouch?: boolean\n down?: boolean\n /**\n * Which way a body going `down` falls: true face down (pushed from behind, tripped), false on its back (pushed from the front, a blast it faced).\n * Left out, the game's own pick by the phase of the stride.\n */\n fallForward?: boolean\n /** Weapon in hand: both arms follow the aim (the game's arm code). Default false. */\n armed?: boolean\n /** The camera pitch the game's `playerArmCode()` reads (`view.pitch`). */\n pitch?: number\n /** Leg yaw toward the step while armed (the game's `P.hip`, radians). */\n hip?: number\n /** Whether the player is carrying an item in the right hand. */\n holding?: boolean\n /** Active scripted item use (`drink`, `sip`, `chug`, `pour`, `open`, `close`, `tilt`). */\n itemUse?: AvatarItemUsePose | null\n /** Hands on a piece of furniture: `grip` closes on it with `progress`, `push` walks with it, `strain` strains against what does not give. */\n push?: { readonly phase: 'grip' | 'push' | 'strain'; readonly progress: number } | null\n /** On a seat: `sit` folds the legs under hips `hip` metres above the feet, `lie` lays the body face up with the pelvis there, the head behind the facing. */\n seat?: { readonly pose: 'sit' | 'lie'; readonly hip: number } | null\n /**\n * A hand on a door, lid or drawer: `reach` to the handle, `swing` with it (`pull` toward the body or pushed away), `release` back, `rattle` on a locked one.\n * `height` is the hand over the feet, metres (a fridge handle, a car door, a low drawer).\n */\n door?: { readonly phase: 'reach' | 'swing' | 'release' | 'rattle'; readonly progress: number; readonly height: number; readonly pull: boolean } | null\n}\n\nexport type PlayPoseOptions = {\n onEvent?: (event: AvatarEvent) => void\n /** Overrides the avatar's blend for this clip. */\n blend?: number\n}\n\n/** The colours the body was drawn with, for whatever has to match it (the first-person arms): skin, shirt, trousers and shoes as 0xRRGGBB, and whether the sleeves cover the forearms. */\nexport type PlayerAvatarColors = { skin: number; shirt: number; trousers: number; shoes: number; longSleeves: boolean }\n\nexport type PlayerAvatar = {\n root: THREE_NS.Object3D\n rig: RichRig\n /** What the body wears, read from the body itself. */\n readonly colors: PlayerAvatarColors\n /** The three.js namespace the body was made with, so what is made to fit it (the first-person arms) uses the same one. */\n readonly three: Three\n update(dt: number, state?: AvatarUpdate): void\n /**\n * The world position of the eyes, as `update` left them: sampled at its end, before any `reach()` (which turns the chest and would swing the head), and kept in the\n * body's own frame so it stays right when the host moves `root` afterwards. With `out` it fills that vector instead of making one.\n */\n eye(out?: THREE_NS.Vector3): THREE_NS.Vector3\n /** In 'first' with a camera, the head and neck are not drawn for that camera only (shadows, mirrors and every other camera still see them); 'third' draws them. */\n setView(mode: AvatarViewMode, camera: THREE_NS.Object3D | null): void\n play(clip: string | PoseClip, options?: PlayPoseOptions): void\n stop(): void\n readonly playing: string | null\n /** A socket at the hand: 'R' is the weapon hand (the puppet's right, at -x), 'L' the other one. */\n hand(side: 'R' | 'L'): THREE_NS.Object3D\n /** The joint of a shoulder ('R' the weapon side, at -x): where a long gun's stock rests, just inside it. */\n shoulder(side: 'R' | 'L'): THREE_NS.Object3D\n /**\n * Brings the hands to where the tool in them asks (`HandTargets`, world space) after `update`: shoulder, elbow and wrist each bend inside the human range, the chest turns and the shoulder\n * blade slides toward a hand out of reach. Null, a strike playing or the body going down leave the arms as `update` posed them. Call it after the tool is placed and the root moved.\n * `view` (given on each call, as the camera moves) is for the body seen from its own eyes: the elbows keep their bend and the hands stay out of walls; without it nothing changes.\n */\n reach(targets: HandTargets | null, view?: ReachView | null): void\n on(type: 'event', listener: (event: AvatarEvent) => void): () => void\n dispose(): void\n}\n\nconst hexOf = (value: unknown): number => (typeof value === 'string' ? Number.parseInt(value, 16) : (value as number))\nconst clamp = (value: number, min: number, max: number): number => Math.min(max, Math.max(min, value))\nconst fract = (value: number): number => value - Math.floor(value)\n\ntype ClipRun = { clip: PoseClip; time: number; weight: number; target: 0 | 1; blend: number; onEvent?: (event: AvatarEvent) => void }\n\n/**\n * The player's body: the rich human of the Bestiário/Elenco, built with the team game's player spec (data, overridable), walking with the engine's gait tied\n * to the ground speed, with the crouch and the knock-down of the game's GPU pose code (`BODY_CHUNK`) and a pose-clip overlay (`play`).\n */\nexport const createPlayerAvatar = (THREE: Three, options: PlayerAvatarOptions = {}): PlayerAvatar => {\n const pose = {\n armL: 0,\n armR: 0,\n elbL: -0.08,\n elbR: -0.08,\n lean: 0.04,\n headX: 0,\n headZ: 0,\n ...(preset.spec as { pose?: Record<string, number> }).pose,\n ...(options.spec?.pose as Record<string, number> | undefined),\n }\n const spec = { ...preset.spec, ...options.spec, pose } as Record<string, unknown>\n for (const key of ['skin', 'hair']) if (typeof spec[key] === 'string') spec[key] = hexOf(spec[key])\n const best = createBestBuilder(THREE, { types: [{ name: String(spec.type), eye: 0 }], random: createRng(Number(spec.seed ?? 1)) })\n const body = best.build(spec) as THREE_NS.Object3D\n best.topM()?.color.setHex(options.shirtColor ?? hexOf(preset.shirtColor)) // set by the build above\n const rig = body.userData.rig as RichRig\n\n // walk: the profile follows the speed (arm swing and bob are the shader's numbers times the stride)\n const profile: { -readonly [K in keyof GaitProfile]: GaitProfile[K] } = { f: 1.1, a: 0.28, k: 0.35, arm: WALK_ARM, bob: WALK_BOB }\n const animator = createRigAnimator({ gaits: { [rig.type]: profile } })\n const clips = options.clips ?? createPoseClipRegistry(POSE_CLIPS)\n const blendDefault = options.blend ?? CLIP_BLEND\n const fallSeconds = options.fallSeconds ?? FALL_SECONDS\n const smooth = options.cascade ?? true\n const clipCascade = options.clipCascade ?? CLIP_CASCADE\n const eyeBob = options.eyeBob ?? EYE_BOB\n const eyeOffset = options.eyeOffset ?? EYE_OFFSET\n\n const root = new THREE.Group()\n const tilt = new THREE.Group()\n tilt.add(body)\n root.add(tilt)\n const colorOf = (object: THREE_NS.Object3D | undefined): number | undefined => ((object as THREE_NS.Mesh | undefined)?.material as THREE_NS.MeshLambertMaterial | undefined)?.color?.getHex()\n const meshesOf = (node: THREE_NS.Object3D): THREE_NS.Mesh[] => node.children.filter((child) => (child as THREE_NS.Mesh).isMesh) as THREE_NS.Mesh[]\n // the trousers are the first mesh of the thigh, the shoe the flattened long ball on the shin, the sleeve (or the skin of a bare arm) the first mesh of the forearm\n const shirt = options.shirtColor ?? hexOf(preset.shirtColor)\n const shoe = meshesOf(rig.legs[0]!.kn as unknown as THREE_NS.Object3D).find((mesh) => mesh.scale.z > 1.5)\n const forearm = colorOf(meshesOf(rig.arms[1]!.el as unknown as THREE_NS.Object3D)[0])\n const colors: PlayerAvatarColors = {\n skin: Number(spec.skin),\n shirt,\n trousers: colorOf(meshesOf(rig.legs[0]!.g as unknown as THREE_NS.Object3D)[0]) ?? 0x2d3440,\n shoes: colorOf(shoe) ?? 0x1c1a1a,\n longSleeves: forearm === shirt,\n }\n const sockets = { R: new THREE.Object3D(), L: new THREE.Object3D() }\n // arms[0] is at +x (the puppet's left), arms[1] at -x: the weapon hand of the game (`playerHand`: shoulder at -x)\n const armOf = { R: rig.arms[1]!, L: rig.arms[0]! }\n for (const side of ['R', 'L'] as const) {\n sockets[side].name = `hand_${side}`\n sockets[side].position.set(HAND_OFFSET.x, HAND_OFFSET.y, HAND_OFFSET.z)\n ;(armOf[side].el as unknown as THREE_NS.Object3D).add(sockets[side])\n }\n\n // Replace the single flattened sphere hand of the zombie builder on the player body with the articulated palm, four two-jointed fingers and thumb (`buildHand` of Retratos do Vale)\n const addMesh = (parent: THREE_NS.Object3D, geometry: THREE_NS.BufferGeometry, material: THREE_NS.Material, x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0): THREE_NS.Mesh => {\n const mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(x, y, z)\n if (rx || ry || rz) mesh.rotation.set(rx, ry, rz)\n mesh.castShadow = true\n mesh.receiveShadow = true\n parent.add(mesh)\n return mesh\n }\n type ThirdPersonHand = { side: 1 | -1; hg: THREE_NS.Group; fingers: THREE_NS.Object3D[]; th: THREE_NS.Object3D | null }\n const hands: ThirdPersonHand[] = []\n rig.arms.forEach((arm, index) => {\n const el = arm.el as unknown as THREE_NS.Object3D\n const side: 1 | -1 = index === 0 ? 1 : -1\n const oldHand = meshesOf(el).find((mesh) => Math.abs(mesh.position.y + 0.33) < 0.025)\n const handMaterial = (oldHand?.material as THREE_NS.Material | undefined) ?? new THREE.MeshLambertMaterial({ color: colors.skin })\n if (oldHand) {\n oldHand.geometry?.dispose()\n el.remove(oldHand)\n }\n const hg = new THREE.Group()\n hg.name = side > 0 ? 'hand_group_L' : 'hand_group_R'\n hg.position.set(side * 0.02, -0.3, 0.01)\n el.add(hg)\n const palm = addMesh(hg, new THREE.SphereGeometry(0.048, 14, 10), handMaterial, 0, -0.035, 0)\n palm.scale.set(0.6, 1.05, 1)\n const built = buildHand({ THREE, add: addMesh, hg, handM: handMaterial, s: side, detailed: true })\n hands.push({ side, hg, fingers: built.fingers as THREE_NS.Object3D[], th: built.th as THREE_NS.Object3D | null })\n })\n const armReach = createArmReach(THREE, rig, { R: hands.find((hand) => hand.side < 0)!.hg, L: hands.find((hand) => hand.side > 0)!.hg })\n const setHandGrip = (hand: ThirdPersonHand, grip: number, wristX = 0): void => {\n hand.fingers.forEach((finger, j) => {\n finger.rotation.z = -hand.side * grip * (j % 2 ? 1.1 : 0.9)\n })\n if (hand.th) hand.th.rotation.z = -hand.side * (0.32 + grip * 0.25)\n hand.hg.rotation.x = wristX\n }\n\n const eyeSocket = new THREE.Object3D()\n eyeSocket.name = 'eye'\n eyeSocket.position.set(BUILDER_EYE[0] + eyeOffset[0], BUILDER_EYE[1] + eyeOffset[1], BUILDER_EYE[2] + eyeOffset[2])\n ;(rig.headG as unknown as THREE_NS.Object3D).children[0]!.add(eyeSocket)\n const headHider = createHeadHider([rig.headG as unknown as THREE_NS.Object3D, ...(rig.neck ? [rig.neck as unknown as THREE_NS.Object3D] : [])])\n const eyeLocal = new THREE.Vector3()\n let bob = 0 // the vertical bob the gait adds to the hips target, taken off the eye by `1 - eyeBob`\n let hipWithoutBob: number | null = null // the hips' cascade run again on the target with no bob, so the bob left after smoothing can be told apart\n\n const legRestX = rig.legs.map((leg) => leg.g.position.x)\n /** Measured once with the leg straight: how far below the trunk pivot the leg hangs from, the thigh, and the knee to the sole. */\n const legLengths = (() => {\n const thigh = rig.legs[0]!.g as unknown as THREE_NS.Object3D\n const shin = rig.legs[0]!.kn as unknown as THREE_NS.Object3D\n root.updateMatrixWorld(true)\n const hipY = thigh.getWorldPosition(new THREE.Vector3()).y\n const kneeY = shin.getWorldPosition(new THREE.Vector3()).y\n return { hipBelowTrunk: HIP_HEIGHT - hipY, thigh: hipY - kneeY, shin: kneeY - new THREE.Box3().setFromObject(shin).min.y }\n })()\n const legSide = (index: number): number => (index === 0 ? 1 : -1) // the shader's `legS`: +1 for the leg at -x (legs[0])\n let cycles = 0 // the game's `player.ph`: gait cycles\n let time = 0\n let fall = 0\n let run: ClipRun | null = null\n const listeners = new Set<(event: AvatarEvent) => void>()\n\n const emit = (event: AvatarEvent, onEvent?: (event: AvatarEvent) => void): void => {\n onEvent?.(event)\n for (const listener of listeners) listener(event)\n }\n\n const readPose = (): Record<string, number> => ({\n lean: rig.upper.rotation.x,\n twist: rig.upper.rotation.y,\n side: rig.upper.rotation.z,\n drop: rig.fig.position.y - rig.dropBase,\n headX: rig.headG.rotation.x,\n headY: rig.headG.rotation.y,\n headZ: rig.headG.rotation.z,\n armR: rig.arms[0]!.g.rotation.x,\n armL: rig.arms[1]!.g.rotation.x,\n elbR: rig.arms[0]!.el.rotation.x,\n elbL: rig.arms[1]!.el.rotation.x,\n armRz: rig.arms[0]!.g.rotation.z,\n armLz: rig.arms[1]!.g.rotation.z,\n legL: rig.legs[0]!.g.rotation.x,\n legR: rig.legs[1]!.g.rotation.x,\n kneeL: rig.legs[0]!.kn.rotation.x,\n kneeR: rig.legs[1]!.kn.rotation.x,\n })\n\n /** Arms and legs of the armed human (`:45`, `:47`, `:53`): both hands on the weapon, the arms follow the aim. */\n const armed = (pitch: number, gait: number, hip: number): PoseTargets => {\n const aim = clamp((pitch + 1) / 3, 0, 0.99) * 3 - 1 // `(playerArmCode() - 2) * 3 - 1`\n const shoulder = AIMED.shoulder + aim * AIMED.perAim + AIMED.swing * Math.sin(cycles * TWO_PI) * gait\n rig.legs.forEach((leg, index) => {\n const x = legRestX[index]!\n leg.g.rotation.y = hip\n leg.g.position.x = x * Math.cos(hip)\n leg.g.position.z = -x * Math.sin(hip)\n })\n // arms[0] is the support hand (+x), arms[1] the weapon hand (-x)\n return { armR: shoulder, armL: shoulder, armRz: AIMED.zRight, armLz: AIMED.zLeft, elbR: AIMED.elbowRight, elbL: AIMED.elbowLeft }\n }\n\n /** The stretched arms of `shove_two_hands` (attack clips) held on the piece, the body leaning into it; straining, the legs brace and the arms shake. */\n const pushingPose = (push: NonNullable<AvatarUpdate['push']>): PoseTargets => {\n const on = push.phase === 'grip' ? Math.min(1, push.progress * 2.2) : 1\n const strain = push.phase === 'strain' ? 1 : 0\n const shake = strain * Math.sin(time * 40) * 0.025\n const raise = -1.5 * on\n const elbow = -0.9 + 0.72 * (push.phase === 'grip' ? push.progress : 1) + strain * 0.12\n return {\n lean: (0.2 + 0.2 * strain) * on,\n headX: (0.05 + 0.08 * strain) * on,\n armR: raise + shake,\n armL: raise - shake,\n armRz: -0.08 * on,\n armLz: 0.08 * on,\n elbR: elbow,\n elbL: elbow,\n ...(strain ? { legL: -0.5, legR: 0.4, kneeL: 0.55, kneeR: 0.08, drop: -0.05 } : {}),\n }\n }\n\n /**\n * The right arm on a handle: raised toward the hand's height, the elbow bending as the leaf comes toward the body (pulled) or straightening as it goes away (pushed),\n * shaking on a locked one; the body leans back pulling and into it pushing, and bends to a low handle.\n */\n const doorPose = (door: NonNullable<AvatarUpdate['door']>): PoseTargets => {\n const { phase, progress } = door\n const on = phase === 'reach' ? progress : phase === 'release' ? 1 - progress : 1\n const swing = phase === 'swing' ? progress : phase === 'release' ? 1 : 0\n const shake = phase === 'rattle' ? Math.sin(time * 55) * 0.06 * (1 - progress) : 0\n // the shoulder about 1.42 m over the feet, the arm 0.62 m: the angle down from the shoulder to the handle, a low handle bends the body\n const drop = clamp((DOOR_SHOULDER - door.height) / DOOR_ARM, -0.9, 1)\n const low = clamp((0.75 - door.height) / 0.5, 0, 1)\n const raise = -Math.acos(clamp(drop, -1, 1)) * on - 0.35 * low * on\n const elbow = door.pull ? -0.35 - 0.75 * swing : -0.95 + 0.75 * swing\n return {\n armR: raise + shake,\n armRz: REST_ARM_Z * (1 - on) + 0.05 * on,\n elbR: -0.12 + (elbow + 0.12) * on,\n armLz: -REST_ARM_Z,\n elbL: -0.12,\n lean: ((door.pull ? -0.06 : 0.1) * swing + 0.35 * low) * on,\n headX: 0.06 * on + 0.2 * low * on,\n }\n }\n\n /** Right-hand carry and item-use poses in third person (`arms[1]` is the puppet's right arm at `-x`, `arms[0]` is the left arm at `+x`). */\n const holdingPose = (gait: number, itemUse?: AvatarItemUsePose | null): PoseTargets => {\n const bob = Math.sin(cycles * TWO_PI) * 0.05 * gait\n if (!itemUse) {\n return { armL: -0.45 + bob, armLz: 0.22, elbL: -1.05 }\n }\n const { id, position, rotation } = itemUse\n if (id === 'drink' || id === 'sip' || id === 'chug') {\n const raise = clamp((position[1] + 0.2) / 0.22, 0, 1)\n const tilt = clamp(Math.abs(rotation[0]) / 1.22, 0, 1.15)\n return {\n armL: -0.45 - 0.95 * raise - 0.22 * tilt,\n armLz: 0.22 + 0.44 * raise,\n elbL: -1.05 - 0.85 * raise + 0.12 * tilt,\n headX: -0.26 * tilt,\n }\n }\n if (id === 'open' || id === 'close' || itemUse.gripL !== undefined) {\n const reach = clamp((0.22 - position[0]) / 0.12, 0, 1)\n return {\n armL: -0.45 - 0.35 * reach,\n armLz: 0.22 + 0.28 * reach,\n elbL: -1.05 - 0.25 * reach,\n armR: -0.78 * reach,\n armRz: -0.48 * reach,\n elbR: -1.25 * reach,\n }\n }\n // pour, pour_out, tilt\n const raise = clamp((position[1] + 0.2) / 0.25, 0, 1)\n const tilt = clamp(Math.abs(rotation[0]) / 1.75, 0, 1.2)\n const ext = Math.max(raise, tilt * 0.75)\n return {\n armL: -0.45 - 0.48 * ext,\n armLz: 0.22 + 0.08 * ext,\n elbL: -1.05 + 0.38 * ext,\n }\n }\n const resetLegYaw = (): void => {\n rig.legs.forEach((leg, index) => {\n leg.g.rotation.y = 0\n leg.g.position.x = legRestX[index]!\n leg.g.position.z = 0\n })\n }\n\n /** Running gait: forward torso lean, pronounced body drop, higher knee lift and bent-elbow arm pumping. */\n const runningPose = (gait: number, busyHands = false): PoseTargets => {\n const ph = cycles * TWO_PI\n const sine = Math.sin(ph)\n const cosine = Math.cos(ph)\n const legL = sine * 0.65 * gait\n const legR = -sine * 0.65 * gait\n const kneeL = Math.max(0, -cosine) * 1.15 * gait\n const kneeR = Math.max(0, cosine) * 1.15 * gait\n const targets: PoseTargets = {\n lean: RUN_LEAN * Math.min(1, gait),\n drop: Math.abs(cosine) * RUN_BOB * gait,\n legL,\n legR,\n kneeL,\n kneeR,\n }\n if (!busyHands) {\n targets.armR = -0.32 - sine * 0.65 * gait\n targets.armL = -0.32 + sine * 0.65 * gait\n targets.elbR = -1.25 + Math.max(0, sine) * 0.3 * gait\n targets.elbL = -1.25 + Math.max(0, -sine) * 0.3 * gait\n targets.armRz = 0.22\n targets.armLz = -0.22\n }\n return targets\n }\n\n const crouchPose = (gait: number): PoseTargets => {\n const swing = (leg: number): number => {\n const legS = legSide(leg)\n return CROUCH.thigh - Math.sin(cycles * TWO_PI) * legS * CROUCH.thighWalk * gait\n }\n return {\n legL: swing(0),\n legR: swing(1),\n kneeL: CROUCH.shin,\n kneeR: CROUCH.shin,\n lean: WALK_LEAN * gait + CROUCH.lean,\n drop: Math.abs(Math.sin(cycles * TWO_PI)) * WALK_BOB * gait + CROUCH.drop,\n }\n }\n\n /** The knocked-down limbs (`:26-:31`, `:40-:43`, `:47`) with the stride at 1, as the game pushes it while down. */\n const downPose = (): PoseTargets => {\n const ph = cycles * TWO_PI\n const gait = 1\n const leg = (index: number): { hip: number; knee: number } => {\n const legS = legSide(index)\n const walkS = Math.sin(ph) * legS\n const bend = fract(cycles * 3) * legS > 0.3 ? fract(cycles * 3) * DOWN.shinBend : Math.max(0, Math.cos(ph + (legS > 0 ? 0 : Math.PI))) * DOWN.shinSwing * gait\n return { hip: -walkS * DOWN.thighWalk * gait, knee: bend }\n }\n const arm = (index: number): { shoulder: number; z: number; elbow: number } => {\n const side = index === 0 ? 1 : -1 // arms[0] at +x\n const armS = Math.sin(ph) * (side > 0 ? 1 : -1)\n const shoulder = fract(cycles * 5) > 0.5 && side > 0 ? DOWN.armHigh : DOWN.armLow + DOWN.armWave * Math.sin(cycles * 5 + side)\n return { shoulder, z: side * (DOWN.armZ + DOWN.armZWave * Math.sin(cycles * 3)), elbow: -0.35 - Math.max(0, armS) * 0.4 * gait }\n }\n const [l, r] = [leg(0), leg(1)]\n const [a0, a1] = [arm(0), arm(1)]\n return {\n legL: l.hip,\n kneeL: l.knee,\n legR: r.hip,\n kneeR: r.knee,\n armR: a0.shoulder,\n armRz: a0.z,\n elbR: a0.elbow,\n armL: a1.shoulder,\n armLz: a1.z,\n elbL: a1.elbow,\n lean: WALK_LEAN * gait,\n drop: Math.abs(Math.sin(ph)) * WALK_BOB * gait,\n }\n }\n\n /** The knee opens until the sole reaches the floor: a low seat sends the shins forward, a high one lets them hang straight down. */\n const sitPose = (hip: number): PoseTargets => {\n const knee = hip - legLengths.hipBelowTrunk - legLengths.thigh * Math.cos(SIT.thigh)\n const shinFromVertical = Math.acos(clamp(knee / legLengths.shin, 0, 1))\n const bend = -SIT.thigh - shinFromVertical\n return {\n legL: SIT.thigh,\n legR: SIT.thigh,\n kneeL: bend,\n kneeR: bend,\n lean: SIT.lean,\n drop: hip - HIP_HEIGHT,\n armR: SIT.arm,\n armL: SIT.arm,\n armRz: SIT.armZ,\n armLz: -SIT.armZ,\n elbR: SIT.elbow,\n elbL: SIT.elbow,\n }\n }\n const liePose = (): PoseTargets => ({ legL: 0, legR: 0, kneeL: LIE.knee, kneeR: LIE.knee, lean: 0, drop: 0, armR: 0, armL: 0, armRz: LIE.armZ, armLz: -LIE.armZ, elbR: LIE.elbow, elbL: LIE.elbow })\n /** Face up, the pelvis `hip` metres above the feet: a quarter turn about the hip, head toward -z. */\n const layBody = (hip: number): void => {\n tilt.rotation.set(-Math.PI / 2, 0, 0, 'XYZ')\n const pivot = new THREE.Vector3(0, HIP_HEIGHT, 0).applyEuler(tilt.rotation)\n tilt.position.set(0, hip, 0).sub(pivot)\n }\n\n const placeBody = (progress: number, forward?: boolean): void => {\n // `:74`: the whole body turns about the hip (face down or face up by the phase) and the hip drops to the ground\n const fk = progress * progress * (3 - 2 * progress)\n // flip 0 turns the head to -z, behind the facing (on the back); 1 to +z (face down)\n const flip = forward === undefined ? (fract(cycles * 1.7) >= 0.5 ? 1 : 0) : forward ? 1 : 0\n tilt.rotation.set((-DOWN.tilt + flip * 2 * DOWN.tilt) * fk, 0, Math.sin(cycles * 7) * DOWN.roll * fk, 'XYZ')\n const hip = new THREE.Vector3(0, HIP_HEIGHT, 0)\n const target = new THREE.Vector3(0, DOWN.hipY, -DOWN.hipZ + flip * DOWN.hipZFlip)\n const place = new THREE.Vector3(0, HIP_HEIGHT * (1 - fk), 0).addScaledVector(target, fk)\n tilt.position.copy(place.sub(hip.applyEuler(tilt.rotation)))\n }\n\n const fireClipEvents = (r: ClipRun, from: number, to: number): void => {\n for (const event of clipEventsBetween(r.clip, from, to)) emit({ ...event, clip: r.clip.id }, r.onEvent)\n }\n\n const stepClip = (dt: number, down: boolean, crouch: boolean): void => {\n if (!run) return\n const r = run\n const from = r.time\n r.time += dt\n const { duration } = r.clip\n if (r.clip.loop && r.time > duration) {\n fireClipEvents(r, from, duration)\n r.time -= duration * Math.floor(r.time / duration)\n fireClipEvents(r, -1e-9, r.time)\n } else {\n fireClipEvents(r, from, Math.min(r.time, duration))\n if (r.time >= duration && !r.clip.loop) r.target = 0\n }\n r.weight = r.blend <= 0 ? r.target : clamp(r.weight + (r.target ? dt : -dt) / r.blend, 0, 1)\n if (r.target === 0 && r.weight <= 0) {\n run = null\n return\n }\n if (down) return\n // a crouched body keeps its legs bent under a punch or the guard: only a kick needs them\n const keepsCrouch = crouch && !r.clip.events?.some((event) => event.data?.kind === 'kick')\n const channels = r.clip.channels ?? 'full'\n const sampled = filterPoseChannels(filterPoseChannels(samplePoseClip(r.clip, Math.min(r.time, duration)), channels), keepsCrouch ? 'upper' : 'full')\n const current = readPose()\n const blended: Record<string, number> = {}\n for (const [name, value] of Object.entries(sampled)) if (name in current) blended[name] = current[name]! + (value - current[name]!) * r.weight\n animator.setPose(rig, blended as PoseTargets)\n }\n\n return {\n root,\n rig,\n colors,\n three: THREE,\n get playing() {\n return run ? run.clip.id : null\n },\n update(dt, state = {}) {\n armReach.restore()\n const speed = state.speed ?? 0\n const moving = speed >= 0.05 // the game: `spd < 0.05 ? 0 : walkCad(spd)`\n const down = !!state.down\n const running = Boolean(state.running && moving && !down && !state.crouch)\n if (moving) cycles += dt * (running ? walkCadence(speed) * 1.3 : walkCadence(speed))\n const gait = Math.min(MAX_GAIT, walkGait(speed))\n profile.arm = (running ? 0.55 : WALK_ARM) * gait\n profile.bob = (running ? RUN_BOB : WALK_BOB) * gait\n time = cycles / (walkCadence(Math.max(speed, 0)) * (running ? 1.3 : 1))\n animator.animate(body, time, { speed })\n bob = rig.fig.position.y - rig.dropBase\n fall = fallSeconds <= 0 ? (down ? 1 : 0) : clamp(fall + (down ? dt : -dt) / fallSeconds, 0, 1)\n resetLegYaw()\n const seat = down ? null : (state.seat ?? null)\n if (down) {\n animator.setPose(rig, downPose())\n bob = rig.fig.position.y - rig.dropBase\n } else if (seat) {\n animator.setPose(rig, seat.pose === 'lie' ? liePose() : sitPose(seat.hip))\n bob = 0\n }\n else {\n if (running) {\n animator.setPose(rig, runningPose(gait, Boolean(state.armed || state.holding || state.itemUse)))\n bob = rig.fig.position.y - rig.dropBase\n }\n if (state.crouch) {\n animator.setPose(rig, crouchPose(gait))\n bob = rig.fig.position.y - rig.dropBase - CROUCH.drop\n }\n if (state.push) animator.setPose(rig, pushingPose(state.push))\n else if (state.door) animator.setPose(rig, doorPose(state.door))\n else if (state.armed) animator.setPose(rig, armed(state.pitch ?? 0, gait, state.hip ?? 0))\n else if (state.holding || state.itemUse) animator.setPose(rig, holdingPose(gait, state.itemUse))\n else if (!running) {\n animator.setPose(rig, {\n armRz: REST_ARM_Z,\n armLz: -REST_ARM_Z,\n elbR: -0.12,\n elbL: -0.12,\n })\n }\n }\n if (seat?.pose === 'lie') layBody(seat.hip)\n else placeBody(fall, state.fallForward)\n stepClip(dt, down, Boolean(state.crouch || seat))\n const cascadeDt = run && !run.clip.loop ? dt * clipCascade : dt\n const targetWithoutBob = rig.fig.position.y - bob\n if (smooth) animator.cascade(rig, cascadeDt)\n hipWithoutBob = smooth && hipWithoutBob !== null ? stepCascade(hipWithoutBob, targetWithoutBob, cascadeDt, 'hip') : targetWithoutBob\n bob = rig.fig.position.y - hipWithoutBob\n // the hands close for a punch and open for a shove, whatever the clip is called (a combo has a jab, a cross, a hook, an uppercut); a clip with no impact,\n // such as the fighting guard, closes them with a `grip` event\n const blow = run?.clip.events?.find((event) => (event.type === 'impact' || event.type === 'grip') && event.data?.kind)?.data?.kind\n const ph = cycles * TWO_PI\n hands.forEach((hand) => {\n const isRight = hand.side < 0\n const holdRight = isRight && (!!state.holding || !!state.itemUse)\n const holdLeft = !isRight && (state.itemUse?.id === 'open' || state.itemUse?.id === 'close' || state.itemUse?.gripL !== undefined)\n const grip =\n !isRight && state.itemUse?.gripL !== undefined\n ? 1.22 * state.itemUse.gripL\n : blow === 'punch'\n ? 1.4\n : blow === 'shove'\n ? 0.15\n : state.armed || holdRight || holdLeft\n ? 1.22\n : running\n ? 0.85\n : 0.12\n const wristSwing = holdRight || state.armed || running ? 0 : -Math.min(1, gait) * Math.sin(ph - 0.6) * 0.12 * hand.side\n setHandGrip(hand, grip, wristSwing)\n })\n root.updateMatrixWorld(true)\n root.worldToLocal(eyeSocket.getWorldPosition(eyeLocal))\n eyeLocal.y -= (1 - eyeBob) * bob\n },\n eye(out = new THREE.Vector3()) {\n root.updateWorldMatrix(true, false)\n return root.localToWorld(out.copy(eyeLocal))\n },\n setView: (mode, camera) => headHider.setView(mode, camera),\n play(clip, playOptions = {}) {\n const found = typeof clip === 'string' ? clips.get(clip) : clip\n if (!found) throw new Error(`Unknown pose clip: ${String(clip)}`)\n run = { clip: found, time: 0, weight: run?.weight ?? 0, target: 1, blend: playOptions.blend ?? blendDefault, ...(playOptions.onEvent ? { onEvent: playOptions.onEvent } : {}) }\n fireClipEvents(run, -1e-9, 0) // events at t = 0 fire on the first frame\n run.time = 0\n },\n stop() {\n if (run) run.target = 0\n },\n hand: (side) => sockets[side],\n shoulder: (side) => armOf[side].g as unknown as THREE_NS.Object3D,\n reach(targets, view) {\n if (run || fall > 0) return\n root.updateMatrixWorld(true)\n armReach.apply(targets, view)\n },\n on(_type, listener) {\n listeners.add(listener)\n return () => void listeners.delete(listener)\n },\n dispose() {\n run = null\n listeners.clear()\n body.traverse((object) => {\n const mesh = object as THREE_NS.Mesh\n mesh.geometry?.dispose()\n const material = mesh.material as THREE_NS.Material | THREE_NS.Material[] | undefined\n if (Array.isArray(material)) material.forEach((m) => m.dispose())\n else material?.dispose()\n })\n root.removeFromParent()\n },\n }\n}\n","{\n \"source\": {\n \"file\": \"site/pages/jogo/zombiada-modo-livre.html\",\n \"variable\": \"PB specs[0] ('você') and PLAYER_COR\",\n \"note\": \"The team game's player body: the Bestiário/Elenco human body. Overridable by `createPlayerAvatar(THREE, { spec, shirtColor })`.\"\n },\n \"spec\": {\n \"type\": \"Lento\",\n \"human\": true,\n \"decay\": 0,\n \"seed\": 4242,\n \"skin\": \"b07a52\",\n \"fem\": false,\n \"life\": 1,\n \"hs\": \"short\",\n \"hair\": \"2a1e16\",\n \"pose\": {\n \"armL\": 0,\n \"armR\": 0,\n \"elbL\": -0.12,\n \"elbR\": -0.12,\n \"armOut\": 0.11,\n \"lean\": 0.04,\n \"headX\": 0,\n \"headZ\": 0\n }\n },\n \"shirtColor\": \"3d5a73\"\n}\n","import type { THREE_NS } from '../three'\n\nexport type TwoBone = {\n /** The middle joint (elbow, knee). */\n joint: THREE_NS.Vector3\n /** The end of the second bone: the target when it is within reach, else the point on the way to it at full stretch. */\n end: THREE_NS.Vector3\n /** The target was out of reach and `end` is short of it. */\n clamped: boolean\n /** Scratch vectors the solver works in. */\n line: THREE_NS.Vector3\n side: THREE_NS.Vector3\n}\n\n/**\n * Two-bone analytic IK. The first bone (`upper`) starts at `root`, the second (`lower`) ends at `end`; the middle joint bends toward `pole` (a direction, not a point: the part of it\n * across the root-to-target line decides which way the elbow goes). A target nearer than the bones can fold, or farther than they can stretch, is clamped to the nearest reachable point on\n * the same line. All vectors are in one space; `out` (made by `createTwoBone`) is filled and returned, so a frame allocates nothing.\n */\nexport const solveTwoBone = (root: THREE_NS.Vector3, target: THREE_NS.Vector3, upper: number, lower: number, pole: THREE_NS.Vector3, out: TwoBone): TwoBone => {\n const line = out.line.copy(target).sub(root)\n let distance = line.length()\n if (distance < 1e-6) line.set(0, 0, -1)\n else line.divideScalar(distance)\n const min = Math.abs(upper - lower) + 1e-4\n const max = upper + lower - 1e-4\n out.clamped = distance > max || distance < min\n distance = Math.min(max, Math.max(min, distance))\n // along the line: the foot of the perpendicular from the joint; across: its height\n const along = (distance * distance + upper * upper - lower * lower) / (2 * distance)\n const across = Math.sqrt(Math.max(0, upper * upper - along * along))\n const side = out.side.copy(pole)\n side.addScaledVector(line, -side.dot(line))\n if (side.lengthSq() < 1e-8) side.set(0, 1, 0).addScaledVector(line, -line.y)\n if (side.lengthSq() < 1e-8) side.set(1, 0, 0)\n side.normalize()\n out.joint.copy(root).addScaledVector(line, along).addScaledVector(side, across)\n out.end.copy(root).addScaledVector(line, distance)\n return out\n}\n\nexport const createTwoBone = (THREE: typeof THREE_NS): TwoBone => ({ joint: new THREE.Vector3(), end: new THREE.Vector3(), clamped: false, line: new THREE.Vector3(), side: new THREE.Vector3() })\n","import type { HandPose, HandTargets } from '@adatechnology/game-contracts'\n\nimport { createTwoBone, solveTwoBone } from '../first-person/ik'\nimport type { RichRig } from '../rich/animator'\nimport type { Three, THREE_NS } from '../three'\n\n/**\n * Limits of the human arm the reach respects, radians and metres. A hand farther than the arm stretches turns the chest (the support shoulder forward, as a shooter blades the body to a long\n * gun) and then protracts the shoulder blade, before the elbow is allowed to lock.\n */\nexport const ARM_REACH = {\n /** The elbow never straightens past this bend (a locked elbow reads as a stick). */\n elbowMin: 0.12,\n /** Full flexion of the elbow. */\n elbowMax: 2.5,\n /** The wrist bends (flexion, extension, deviation) up to this angle from the line of the forearm (flexion reaches about 80 degrees). */\n wristBend: 1.3,\n /** The forearm turns (pronation and supination) up to this angle about its own axis. */\n wristTwist: 1.6,\n /** The most the chest turns to bring the support shoulder toward a far hand. */\n chestTurn: 0.6,\n /** The most a shoulder blade slides toward a far hand (protraction and elevation together). */\n protraction: 0.11,\n /** A hand is within reach below this fraction of the arm's length. */\n slack: 0.96,\n /** Where the elbow points: down and out from the body, a little back (body space, x outward). */\n elbowPole: [0.55, -1, -0.25] as const,\n /** The support arm's elbow: under the gun, hardly out of the body (the first-person arms' `elbowPoleLeft`), so the forearm meets the handguard nearer the aim's line. */\n elbowPoleSupport: [0.1, -1, -0.2] as const,\n /** From the wrist joint to the middle of the palm, metres of the body. */\n palm: 0.042,\n /** In a view the elbow keeps at least this interior bend where a hand is out of reach, right then left (the first-person arms' numbers). */\n viewBend: [1.35, 0.95] as const,\n /** In a view a hand stays this far before a surface, metres. */\n contactMargin: 0.005,\n /** In a view a hand is never nearer than this to the eye, metres. */\n contactNearest: 0.12,\n /** How far in front of the eye a surface is looked for, metres. */\n contactProbe: 1.4,\n /** How far a hand reaches forward of its middle at least (the thickness of the palm), and per metre of fingers pointing ahead. */\n contactPalm: 0.03,\n /** From the middle of the palm to the fingertips. */\n contactFingers: 0.085,\n} as const\n\ntype Side = 'R' | 'L'\ntype ReachArm = { readonly g: THREE_NS.Object3D; readonly el: THREE_NS.Object3D; readonly hand: THREE_NS.Object3D; readonly outward: 1 | -1 }\n\n/**\n * The eye the hands are seen from, given per call to `apply` (null or none is the body seen from outside: nothing changes). `reachBend` keeps the elbow bent where a hand is out of reach, the hand stopping\n * short instead of the arm locking; `keepOutside` pulls a hand back so it stays in front of the surface `contact` finds along the camera's forward.\n */\nexport type ReachView = {\n readonly camera: THREE_NS.Object3D\n /** The least interior bend of the elbow, radians, right then left. Default `ARM_REACH.viewBend`. */\n readonly reachBend?: readonly [number, number]\n readonly keepOutside?: {\n /** The distance to the surface from `origin` along `direction` within `maxDistance`, or null. */\n contact(origin: [number, number, number], direction: [number, number, number], maxDistance: number): number | null\n /** Default `ARM_REACH.contactMargin`. */\n readonly margin?: number\n /** Default `ARM_REACH.contactNearest`. */\n readonly nearest?: number\n }\n}\n\nexport type ArmReach = {\n /** Brings the hands to `targets` (world space) over the pose the body already has; null leaves the arms as the pose put them. A `view` keeps the elbows bent and the hands out of walls. */\n apply(targets: HandTargets | null, view?: ReachView | null): void\n /** Puts back what the last `apply` changed, so the pose and its smoothing see only their own numbers next frame. */\n restore(): void\n}\n\n/**\n * Three-joint reach of the rich body: shoulder (ball), elbow (hinge) and wrist (bend and twist), each kept inside its human range. The hand frame is the one of `HandPose`\n * (game-contracts): x from the wrist to the knuckles, y the back of the hand, z the little-finger side of a right hand; the left hand is the mirror image.\n */\nexport const createArmReach = (THREE: Three, rig: RichRig, hands: Readonly<Record<Side, THREE_NS.Object3D>>): ArmReach => {\n // rig.arms[1] is the weapon hand (the puppet's right, at -x), rig.arms[0] the support hand (+x)\n const arms: Record<Side, ReachArm> = {\n R: { g: rig.arms[1]!.g as unknown as THREE_NS.Object3D, el: rig.arms[1]!.el as unknown as THREE_NS.Object3D, hand: hands.R, outward: -1 },\n L: { g: rig.arms[0]!.g as unknown as THREE_NS.Object3D, el: rig.arms[0]!.el as unknown as THREE_NS.Object3D, hand: hands.L, outward: 1 },\n }\n const upper = rig.upper as unknown as THREE_NS.Object3D\n // hand-local axes of `HandPose` in the hand group's space: the fingers hang along -y, the palm faces the body (+x for the right hand, -x for the left), the thumb is in front (+z)\n const handBasis = {\n R: new THREE.Quaternion().setFromRotationMatrix(new THREE.Matrix4().makeBasis(new THREE.Vector3(0, -1, 0), new THREE.Vector3(-1, 0, 0), new THREE.Vector3(0, 0, -1))).invert(),\n L: new THREE.Quaternion().setFromRotationMatrix(new THREE.Matrix4().makeBasis(new THREE.Vector3(0, -1, 0), new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 1))).invert(),\n }\n const saved = {\n twist: 0,\n arms: { R: { position: new THREE.Vector3(), g: new THREE.Quaternion(), el: new THREE.Quaternion(), hand: new THREE.Quaternion() }, L: { position: new THREE.Vector3(), g: new THREE.Quaternion(), el: new THREE.Quaternion(), hand: new THREE.Quaternion() } },\n }\n let applied = false\n const bone = createTwoBone(THREE)\n const v = { shoulder: new THREE.Vector3(), elbow: new THREE.Vector3(), wrist: new THREE.Vector3(), palm: new THREE.Vector3(), target: new THREE.Vector3(), pole: new THREE.Vector3(), a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() }\n const q = { hand: new THREE.Quaternion(), parent: new THREE.Quaternion(), body: new THREE.Quaternion(), local: new THREE.Quaternion(), swing: new THREE.Quaternion(), twist: new THREE.Quaternion(), rest: new THREE.Quaternion() }\n const basis = new THREE.Matrix4()\n const camera = { position: new THREE.Vector3(), quaternion: new THREE.Quaternion(), inverse: new THREE.Quaternion(), probe: new THREE.Vector3(), forward: new THREE.Vector3(), fingers: new THREE.Vector3(), hand: new THREE.Quaternion() }\n let bendLimit: readonly [number, number] | null = null\n const yAxis = new THREE.Vector3(0, 1, 0)\n\n const lengthsOf = (arm: ReachArm): { upper: number; fore: number; palm: number } => {\n const scale = arm.g.getWorldScale(v.a).y\n return { upper: arm.el.position.length() * scale, fore: arm.hand.position.length() * scale, palm: ARM_REACH.palm * scale }\n }\n\n /** The wrist-to-shoulder distance past which the chest and the shoulder blade move: the arm nearly straight, or with the elbow at the view's bend (law of cosines). */\n const limitOf = (side: Side, upperLength: number, fore: number): number => {\n if (!bendLimit) return (upperLength + fore) * ARM_REACH.slack\n return Math.sqrt(upperLength * upperLength + fore * fore + 2 * upperLength * fore * Math.cos(bendLimit[side === 'R' ? 0 : 1]))\n }\n\n /** The wrist joint and the world orientation of the hand group for a hand pose. */\n const wristOf = (side: Side, pose: HandPose, palm: number): void => {\n q.hand.set(...pose.quaternion).multiply(handBasis[side])\n v.palm.set(...pose.position)\n v.wrist.copy(v.palm).addScaledVector(v.a.set(0, -1, 0).applyQuaternion(q.hand), -palm)\n }\n\n /** Turns the chest so the support shoulder comes toward a hand it cannot reach. */\n const turnChest = (pose: HandPose): void => {\n const { upper: up, fore, palm } = lengthsOf(arms.L)\n wristOf('L', pose, palm)\n const excess = arms.L.g.getWorldPosition(v.shoulder).distanceTo(v.wrist) - limitOf('L', up, fore)\n if (excess <= 0) return\n // the support shoulder is at +x of the chest, the front is +z: a turn of -a about y brings it forward\n const chestRadius = Math.hypot(arms.L.g.position.x, arms.L.g.position.z) * arms.L.g.getWorldScale(v.a).y\n upper.rotation.y -= Math.min(ARM_REACH.chestTurn, excess / Math.max(0.05, chestRadius))\n upper.updateMatrixWorld(true)\n }\n\n /** Slides the shoulder blade toward a hand still out of reach. */\n const protract = (arm: ReachArm, limit: number): void => {\n const excess = arm.g.getWorldPosition(v.shoulder).distanceTo(v.wrist) - limit\n if (excess <= 0) return\n const parent = arm.g.parent!\n v.b.copy(v.wrist).sub(v.shoulder).normalize().multiplyScalar(Math.min(excess, ARM_REACH.protraction)).add(v.shoulder)\n arm.g.position.copy(parent.worldToLocal(v.b))\n arm.g.updateMatrixWorld(true)\n }\n\n /** Keeps the hand group inside the wrist's range: the bend off the forearm line and the turn about it. */\n const limitWrist = (local: THREE_NS.Quaternion): THREE_NS.Quaternion => {\n // swing-twist about the forearm axis (y): the twist is the forearm turning, the swing the wrist bending\n const projection = v.c.set(local.x, local.y, local.z).projectOnVector(yAxis)\n q.twist.set(projection.x, projection.y, projection.z, local.w).normalize()\n const twistAngle = 2 * Math.atan2(q.twist.y, q.twist.w)\n const swing = q.swing.copy(local).multiply(q.twist.invert())\n const swingAngle = 2 * Math.acos(Math.min(1, Math.abs(swing.w)))\n if (swingAngle > ARM_REACH.wristBend) swing.slerp(q.rest.identity(), 1 - ARM_REACH.wristBend / swingAngle)\n const clampedTwist = Math.max(-ARM_REACH.wristTwist, Math.min(ARM_REACH.wristTwist, Math.atan2(Math.sin(twistAngle), Math.cos(twistAngle))))\n return local.copy(swing).multiply(q.twist.setFromAxisAngle(yAxis, clampedTwist))\n }\n\n const reach = (side: Side, pose: HandPose): void => {\n const arm = arms[side]\n const { upper: up, fore, palm } = lengthsOf(arm)\n wristOf(side, pose, palm)\n protract(arm, limitOf(side, up, fore))\n arm.g.getWorldPosition(v.shoulder)\n // the elbow points down and out of the body, whichever way the body faces\n upper.getWorldQuaternion(q.body)\n const pole = side === 'L' ? ARM_REACH.elbowPoleSupport : ARM_REACH.elbowPole\n v.pole.set(pole[0] * arm.outward, pole[1], pole[2]).applyQuaternion(q.body)\n // the elbow keeps a little bend: shorten the line to the wrist rather than lock it\n const lockLimit = Math.sqrt(up * up + fore * fore + 2 * up * fore * Math.cos(ARM_REACH.elbowMin))\n const most = bendLimit ? Math.min(lockLimit, limitOf(side, up, fore)) : lockLimit\n const least = Math.sqrt(up * up + fore * fore + 2 * up * fore * Math.cos(ARM_REACH.elbowMax))\n const line = v.c.copy(v.wrist).sub(v.shoulder)\n const distance = Math.min(most, Math.max(least, line.length()))\n v.target.copy(v.shoulder).addScaledVector(line.normalize(), distance)\n solveTwoBone(v.shoulder, v.target, up, fore, v.pole, bone)\n // upper arm: local -y runs to the elbow, local +z is the side the forearm folds toward (the elbow bends about local x, negative forward)\n const along = v.a.copy(bone.joint).sub(v.shoulder).normalize()\n const forearm = v.b.copy(bone.end).sub(bone.joint).normalize()\n const fold = v.c.copy(forearm).addScaledVector(along, -forearm.dot(along))\n if (fold.lengthSq() < 1e-8) fold.copy(v.pole).addScaledVector(along, -v.pole.dot(along)).negate()\n fold.normalize()\n const yWorld = v.elbow.copy(along).negate()\n basis.makeBasis(v.pole.crossVectors(yWorld, fold), yWorld, fold)\n arm.g.parent!.getWorldQuaternion(q.parent)\n arm.g.quaternion.setFromRotationMatrix(basis).premultiply(q.parent.invert())\n arm.el.rotation.set(-Math.acos(Math.max(-1, Math.min(1, along.dot(forearm)))), 0, 0)\n arm.g.updateMatrixWorld(true)\n // the wrist sits a little off the forearm's line: turn the whole arm about the shoulder so it lands on the target, the elbow keeping its bend\n const reached = arm.hand.getWorldPosition(v.a).sub(v.shoulder).normalize()\n q.swing.setFromUnitVectors(reached, v.b.copy(v.target).sub(v.shoulder).normalize())\n arm.g.parent!.getWorldQuaternion(q.parent)\n arm.g.quaternion.premultiply(q.parent).premultiply(q.swing).premultiply(q.parent.invert())\n arm.g.updateMatrixWorld(true)\n // wrist: the hand group turns to the grip, inside the wrist's range\n arm.el.getWorldQuaternion(q.parent)\n arm.hand.quaternion.copy(limitWrist(q.local.copy(q.parent.invert()).multiply(q.hand)))\n }\n\n /** Pulls a hand back, along the camera's forward, to the surface in front of it minus what the hand reaches forward and a margin; never nearer than `nearest` to the eye. */\n const keepOutside = (pose: HandPose, outside: NonNullable<ReachView['keepOutside']>): HandPose => {\n // the hand in the camera's space: x right, y up, the view looks down -z\n const place = v.a.set(...pose.position).sub(camera.position).applyQuaternion(camera.inverse)\n camera.probe.set(place.x, place.y, 0).applyQuaternion(camera.quaternion).add(camera.position)\n camera.forward.set(0, 0, -1).applyQuaternion(camera.quaternion)\n const distance = outside.contact([camera.probe.x, camera.probe.y, camera.probe.z], [camera.forward.x, camera.forward.y, camera.forward.z], ARM_REACH.contactProbe)\n if (distance === null) return pose\n camera.hand.set(...pose.quaternion).premultiply(camera.inverse)\n const ahead = Math.max(ARM_REACH.contactPalm, -camera.fingers.set(1, 0, 0).applyQuaternion(camera.hand).z * ARM_REACH.contactFingers)\n const limit = Math.max(outside.nearest ?? ARM_REACH.contactNearest, distance - ahead - (outside.margin ?? ARM_REACH.contactMargin))\n if (-place.z <= limit) return pose\n place.z = -limit\n place.applyQuaternion(camera.quaternion).add(camera.position)\n return { ...pose, position: [place.x, place.y, place.z] }\n }\n\n const save = (): void => {\n saved.twist = upper.rotation.y\n for (const side of ['R', 'L'] as const) {\n const arm = arms[side]\n const into = saved.arms[side]\n into.position.copy(arm.g.position)\n into.g.copy(arm.g.quaternion)\n into.el.copy(arm.el.quaternion)\n into.hand.copy(arm.hand.quaternion)\n }\n }\n\n return {\n apply(targets, view) {\n if (!targets || (!targets.R && !targets.L)) return\n save()\n applied = true\n upper.updateWorldMatrix(true, true)\n let { R, L } = targets\n bendLimit = view ? (view.reachBend ?? ARM_REACH.viewBend) : null\n if (view?.keepOutside) {\n view.camera.updateWorldMatrix(true, false)\n view.camera.matrixWorld.decompose(camera.position, camera.quaternion, v.a)\n camera.inverse.copy(camera.quaternion).invert()\n if (R) R = keepOutside(R, view.keepOutside)\n if (L) L = keepOutside(L, view.keepOutside)\n }\n if (L && R) turnChest(L)\n if (R) reach('R', R)\n if (L) reach('L', L)\n bendLimit = null\n },\n restore() {\n if (!applied) return\n applied = false\n upper.rotation.y = saved.twist\n for (const side of ['R', 'L'] as const) {\n const arm = arms[side]\n const from = saved.arms[side]\n arm.g.position.copy(from.position)\n arm.g.quaternion.copy(from.g)\n arm.el.quaternion.copy(from.el)\n arm.hand.quaternion.copy(from.hand)\n }\n },\n }\n}\n","import type { THREE_NS } from '../three'\n\nexport type AvatarViewMode = 'first' | 'third'\n\nexport type HeadHider = {\n setView(mode: AvatarViewMode, camera: THREE_NS.Object3D | null): void\n}\n\ntype Drawable = THREE_NS.Object3D & { material?: THREE_NS.Material | THREE_NS.Material[] }\ntype Flags = { material: THREE_NS.Material; colorWrite: boolean; depthWrite: boolean }\n\nconst isDrawable = (object: THREE_NS.Object3D): boolean => {\n const flagged = object as THREE_NS.Object3D & { isMesh?: boolean; isSprite?: boolean; isPoints?: boolean }\n return Boolean(flagged.isMesh || flagged.isSprite || flagged.isPoints)\n}\n\n/**\n * Draws nothing of the given objects for one camera: while that camera renders, the materials write neither colour nor depth. The materials stay visible\n * and untouched for every other pass (shadow, mirror, third person), and are restored after each draw, so a material shared with the hands comes back intact.\n */\nexport const createHeadHider = (roots: readonly THREE_NS.Object3D[]): HeadHider => {\n let isHiding = false\n let viewCamera: THREE_NS.Object3D | null = null\n const drawables: Drawable[] = []\n for (const root of roots) root.traverse((object) => isDrawable(object) && drawables.push(object))\n\n for (const drawable of drawables) {\n const previousBefore = drawable.onBeforeRender\n const previousAfter = drawable.onAfterRender\n let saved: Flags[] = []\n drawable.onBeforeRender = (renderer, scene, camera, geometry, material, group) => {\n previousBefore.call(drawable, renderer, scene, camera, geometry, material, group)\n if (!isHiding || camera !== viewCamera) return\n const drawn = Array.isArray(drawable.material) ? drawable.material : [material]\n saved = drawn.map((entry) => ({ material: entry, colorWrite: entry.colorWrite, depthWrite: entry.depthWrite }))\n for (const entry of drawn) {\n entry.colorWrite = false\n entry.depthWrite = false\n }\n }\n drawable.onAfterRender = (renderer, scene, camera, geometry, material, group) => {\n previousAfter.call(drawable, renderer, scene, camera, geometry, material, group)\n for (const flags of saved) {\n flags.material.colorWrite = flags.colorWrite\n flags.material.depthWrite = flags.depthWrite\n }\n saved = []\n }\n }\n\n return {\n setView(mode, camera) {\n isHiding = mode === 'first' && camera !== null\n viewCamera = camera\n },\n }\n}\n","import { ATTACK_CLIPS } from '@adatechnology/game-characters-people'\nimport { mirrorPoseClip } from '@adatechnology/game-characters'\nimport type { PoseClip } from '@adatechnology/game-characters'\nimport type { HandTargets } from '@adatechnology/game-contracts'\n\nimport type { ReachView } from './arm-reach'\nimport type { AvatarItemUsePose, PlayerAvatar } from './avatar'\nimport type { AvatarViewMode } from './head-hiding'\nimport type { THREE_NS } from '../three'\n\n/** What `@adatechnology/game-test-room` calls a `RoomAvatar`, restated here so this package does not depend on the room. */\nexport type RoomAvatarLike = {\n root: THREE_NS.Object3D\n update(dt: number, state: { speed: number; running: boolean; crouch: boolean; down: boolean; fallForward?: boolean; armed: boolean; pitch: number; push?: { readonly phase: 'grip' | 'push' | 'strain'; readonly progress: number } | null; door?: { readonly phase: 'reach' | 'swing' | 'release' | 'rattle'; readonly progress: number; readonly height: number; readonly pull: boolean } | null; holding?: boolean; itemUse?: AvatarItemUsePose | null; seat?: { readonly pose: 'sit' | 'lie'; readonly hip: number } | null }): void\n hand(side: 'R' | 'L'): THREE_NS.Object3D\n shoulder(side: 'R' | 'L'): THREE_NS.Object3D\n /** Where the body's eyes are after its pose (`RoomAvatar.eye`): the room draws the body in both views and puts the first-person camera there. */\n eye(out?: THREE_NS.Vector3): THREE_NS.Vector3\n /** Hides the head and neck from `camera` in first person (`RoomAvatar.setView`). */\n setView(mode: AvatarViewMode, camera: THREE_NS.Object3D | null): void\n /** Brings the body's hands to the tool in them, in both views; `view` keeps them in the first-person view (`RoomAvatar.reach`). */\n reach(targets: HandTargets | null, view?: ReachView | null): void\n /** Plays a strike on the body (the only source of it, in both views) and answers the seconds to its impact (`RoomAvatar.strike`). */\n strike(clipId: string, options?: { leg?: 'left' | 'right'; hand?: 'left' | 'right' }): number | null\n /** The foot the walk put down since the last call (`RoomAvatar.footfall`), or null. */\n footfall(): 'left' | 'right' | null\n /** The avatar it wraps. */\n readonly avatar: PlayerAvatar\n}\n\nexport type ToRoomAvatarOptions = {\n /** The third-person strike clips `strike` finds by id (`defaultCharacterClips()` of game-kit-defaults, or the game's own). Default `ATTACK_CLIPS` of game-characters-people, which is deprecated: pass them. */\n strikeClips?: readonly PoseClip[]\n /** The looping clip the body holds between punches (a clip of `strikeClips`), so a combo goes guard, punch, guard instead of dropping the hands each time; `false` for none. Default `'fight_guard'`. */\n guardClip?: string | false\n /** Seconds the guard stays up after a punch ends. Default 1.2. */\n guardHold?: number\n /** Seconds a punch takes to blend in over the walk (or the guard it comes from). Default 0.05: the fist leaves at once. */\n punchBlend?: number\n}\n\n/** The impact second of a clip: the time of its first `impact` event. */\nconst impactOf = (clip: PoseClip): number | null => clip.events?.find((event) => event.type === 'impact')?.t ?? null\n/** A punch is a clip whose impact is a `punch` (the hands close for it); after one the body keeps the guard. */\nconst isPunch = (clip: PoseClip): boolean => clip.events?.some((event) => event.type === 'impact' && event.data?.kind === 'punch') ?? false\n/** Below this ground speed (m/s) the body does not walk, so its feet do not fall. */\nconst FOOTFALL_SPEED = 0.3\n/** Radians the legs must be apart at the turn for it to be a step (not the sway of standing). */\nconst FOOTFALL_SPREAD = 0.08\n/** Below this ground speed the body stands to keep the guard; walking gives the legs back to the gait. */\nconst GUARD_SPEED = 0.3\n\n/**\n * Fits the player's body to the test room's `RoomAvatar` (`room.setAvatar(toRoomAvatar(createPlayerAvatar(THREE)))`). It changes the sign of the pitch: the room\n * counts a look up as positive, the team game's `view.pitch` (what `AvatarUpdate.pitch` reads) counts a look down as positive. The same body is the first-person view (`eye`, `setView`), and `strike(clipId)` plays the strike on the body (the attack clips) and answers the seconds to its\n * impact, which are the same in both views. A kick with the left leg (`leg: 'left'`) or a punch with the left hand (`hand: 'left'`) plays the mirror of the clip written for the right.\n * After a punch the body holds the guard (`guardClip`) for `guardHold` seconds while it stands, so the next punch leaves from the guard.\n */\nexport const toRoomAvatar = (avatar: PlayerAvatar, options: ToRoomAvatarOptions = {}): RoomAvatarLike => {\n const strikes = new Map((options.strikeClips ?? ATTACK_CLIPS).map((clip) => [clip.id, clip]))\n const mirrored = new Map<string, PoseClip>()\n /** The clip for a kick with the left leg or a punch with the left hand: the mirror of the one that is written for the right. */\n const leftOf = (clip: PoseClip): PoseClip => {\n let found = mirrored.get(clip.id)\n if (!found) mirrored.set(clip.id, (found = mirrorPoseClip(clip, `${clip.id}_left`)))\n return found\n }\n const guard = options.guardClip === false ? undefined : strikes.get(options.guardClip ?? 'fight_guard')\n const guardHold = options.guardHold ?? 1.2\n const punchBlend = options.punchBlend ?? 0.05\n let strikeLeft = 0 // seconds of the punch still to play\n // Heel strikes, read off the legs the walk drew: the hip angles of the two legs (more negative is further forward) part and close; each time\n // their difference turns back, one leg is at its furthest forward and its heel is down. The left leg is `legs[0]` (+x, the body's left).\n let footDown: 'left' | 'right' | null = null\n let walking = false\n let lastSpread: number | null = null\n let lastSlope = 0\n const updateFeet = (state: Parameters<RoomAvatarLike['update']>[1]): void => {\n walking = state.speed >= FOOTFALL_SPEED && !state.down && !state.seat\n if (!walking) {\n lastSpread = null\n lastSlope = 0\n }\n }\n const readFeet = (): void => {\n if (!walking) return\n const [left, right] = avatar.rig.legs\n if (!left || !right) return\n const spread = (left.g as unknown as THREE_NS.Object3D).rotation.x - (right.g as unknown as THREE_NS.Object3D).rotation.x\n if (lastSpread !== null) {\n const slope = spread - lastSpread\n if (Math.abs(spread) > FOOTFALL_SPREAD) {\n if (lastSlope < 0 && slope >= 0) footDown = 'left'\n else if (lastSlope > 0 && slope <= 0) footDown = 'right'\n }\n if (slope !== 0) lastSlope = slope\n }\n lastSpread = spread\n }\n let guardLeft = 0 // seconds the guard stays up after it\n let guarding = false\n const stepGuard = (dt: number, state: Parameters<RoomAvatarLike['update']>[1]): void => {\n if (!guard) return\n const free = state.speed < GUARD_SPEED && !state.down && !state.armed && !state.holding && !state.push && !state.door && !state.itemUse && !state.running\n if (strikeLeft > 0) {\n strikeLeft -= dt\n if (strikeLeft <= 0 && guardLeft > 0 && free) {\n avatar.play(guard)\n guarding = true\n }\n return\n }\n guardLeft = Math.max(0, guardLeft - dt)\n if (guarding && (guardLeft <= 0 || !free || avatar.playing !== guard.id)) {\n if (avatar.playing === guard.id) avatar.stop()\n guarding = false\n }\n }\n return {\n root: avatar.root,\n avatar,\n eye: (out) => avatar.eye(out),\n setView: (mode, camera) => avatar.setView(mode, camera),\n update: (dt, state) => {\n stepGuard(dt, state)\n updateFeet(state)\n avatar.update(dt, {\n speed: state.speed,\n running: state.running,\n crouch: state.crouch,\n down: state.down,\n armed: state.armed,\n pitch: -state.pitch,\n ...(state.holding !== undefined ? { holding: state.holding } : {}),\n ...(state.itemUse !== undefined ? { itemUse: state.itemUse } : {}),\n ...(state.push !== undefined ? { push: state.push } : {}),\n ...(state.seat !== undefined ? { seat: state.seat } : {}),\n ...(state.door !== undefined ? { door: state.door } : {}),\n ...(state.fallForward !== undefined ? { fallForward: state.fallForward } : {}),\n })\n readFeet()\n },\n footfall: () => {\n const foot = footDown\n footDown = null\n return foot\n },\n hand: (side) => avatar.hand(side),\n shoulder: (side) => avatar.shoulder(side),\n reach: (targets, view) => avatar.reach(targets, view),\n strike: (clipId, strikeOptions) => {\n const clip = strikes.get(clipId)\n if (!clip) return null\n const left = strikeOptions?.leg === 'left' || strikeOptions?.hand === 'left'\n const punch = guard !== undefined && isPunch(clip)\n avatar.play(left ? leftOf(clip) : clip, punch ? { blend: punchBlend } : undefined)\n strikeLeft = punch ? clip.duration : 0\n guardLeft = punch ? guardHold : 0\n guarding = false\n return impactOf(clip)\n },\n }\n}\n","import { clipEventsBetween, sampleFirstPersonClip } from '@adatechnology/game-characters'\nimport type { FirstPersonClip, FirstPersonSampleChannel } from '@adatechnology/game-characters'\nimport { markKitOrigin } from '@adatechnology/game-contracts'\nimport type { HandPose } from '@adatechnology/game-contracts'\n\nimport playerPreset from '../presets/player-avatar.json'\nimport preset from '../presets/first-person-arms.json'\nimport type { Three, THREE_NS } from '../three'\nimport { createHandMesh } from './hand'\nimport type { HandMesh } from './hand'\nimport { createTwoBone, solveTwoBone } from './ik'\nimport type {\n FirstPersonArms,\n FirstPersonArmsOptions,\n FirstPersonBob,\n FirstPersonColors,\n FirstPersonEvent,\n FirstPersonRig,\n RestPose,\n StanceDef,\n} from './types'\n\nconst DEFAULT_BLEND = 0.18\nconst ELBOW_SEGMENTS = 8\n/** An arm is stretched to this fraction of its length before the shoulder moves toward the target. */\nconst REACH_SLACK = 0.97\n/** An elbow put in the view stays this fraction inside its edges, and is pulled in this many times (each pull keeps the forearm's length). */\nconst ELBOW_VIEW_MARGIN = 0.86\nconst ELBOW_VIEW_PASSES = 4\n\ntype View = { tanV: number; tanH: number }\n/** A foot is shown while a clip holds it by at least this much. */\n/** How far (m) the world is probed in front of the camera, the closest a hand may come to the eye, and the gap left in front of a surface. */\nconst CONTACT_PROBE = 1.4\nconst CONTACT_MIN = 0.12\nconst CONTACT_MARGIN = 0.005\nconst CONTACT_PALM = 0.03\n/** The toe of the shoe (and the corners of its sole) is this far (m) from the ankle along the shoe. */\nconst FOOT_LENGTH = 0.24\n\nconst FOOT_SHOWN = 0.001\n\n/** An idle hand drops this far (m) below its rest place and is not drawn once it is out of the view; it goes at `AWAY_OUT` per second and comes back at `AWAY_IN`. */\nconst AWAY_DROP = 0.55\nconst AWAY_OUT = 7\nconst AWAY_IN = 20\nconst AWAY_HIDDEN = 0.97\n\n/** How much of its own colour each material glows with (0..1). */\nconst FILL = 0.3\n\n/** The stances of the preset: `relaxed` and `fists` are rest poses, `hold` follows the targets of the tool in the hands. */\nexport const FIRST_PERSON_STANCES = preset.stances as unknown as Readonly<Record<string, StanceDef>>\n/** The rig of the preset: shoulders, bones, elbow pole, hips and the leg of the kick. */\nexport const FIRST_PERSON_RIG = preset.rig as unknown as FirstPersonRig\nexport const FIRST_PERSON_BOB = preset.bob as FirstPersonBob\n\nconst hexOf = (value: string | number): number => (typeof value === 'string' ? Number.parseInt(value, 16) : value)\nconst scaleHex = (hex: number, factor: number): number => {\n const channel = (shift: number): number => Math.round(((hex >> shift) & 0xff) * factor)\n return (channel(16) << 16) | (channel(8) << 8) | channel(0)\n}\nconst mix = (a: number, b: number, k: number): number => a + (b - a) * k\nconst ease = (k: number): number => k * k * (3 - 2 * k)\n\n/** The colours of the player's preset: the skin and the shirt of the team game's player, trousers and shoes of a plain outfit. */\nexport const FIRST_PERSON_COLORS: FirstPersonColors = {\n skin: hexOf(playerPreset.spec.skin),\n sleeve: hexOf(playerPreset.shirtColor),\n cuff: scaleHex(hexOf(playerPreset.shirtColor), 0.72),\n trouser: 0x2d3440,\n shoe: 0x1c1a1a,\n}\n\ntype Pose = { p: THREE_NS.Vector3; q: THREE_NS.Quaternion; grip: number; scale: number }\n\ntype Segment = THREE_NS.Mesh\ntype Arm = {\n side: 'R' | 'L'\n sign: 1 | -1\n hand: HandMesh\n /** At the middle of the palm, in the space of the arms root. */\n anchor: THREE_NS.Group\n upper: Segment\n fore: Segment\n cuff: Segment\n elbow: THREE_NS.Mesh\n /** What the hand is told to do before a clip: eased from `from` to the stance or the target. */\n shown: Pose\n from: Pose\n mode: string | null\n blend: number\n /** What is drawn. */\n drawn: Pose\n /** The joints of the arm as drawn, in the space of the arms root (the camera's). */\n joints: { shoulder: THREE_NS.Vector3; elbow: THREE_NS.Vector3; wrist: THREE_NS.Vector3 }\n /** 0 in the view, 1 dropped out of it and not drawn (`hideWhenIdle`). */\n away: number\n}\n\nconst newPose = (THREE: Three): Pose => ({ p: new THREE.Vector3(), q: new THREE.Quaternion(), grip: 0, scale: 1 })\nconst copyPose = (to: Pose, from: Pose): Pose => {\n to.p.copy(from.p)\n to.q.copy(from.q)\n to.grip = from.grip\n to.scale = from.scale\n return to\n}\nconst mixPose = (THREE: Three, out: Pose, a: Pose, b: Pose, k: number): Pose => {\n out.p.lerpVectors(a.p, b.p, k)\n out.q.copy(a.q).slerp(b.q, k)\n out.grip = mix(a.grip, b.grip, k)\n out.scale = mix(a.scale, b.scale, k)\n return out\n}\n\n/** The mirror image of a rotation across the plane x = 0 (M R M with M = diag(-1, 1, 1)): for a shoe, which is its own mirror image about its length. */\nconst mirrorRotation = (THREE: Three, q: THREE_NS.Quaternion): THREE_NS.Quaternion => {\n const m = new THREE.Matrix4().makeRotationFromQuaternion(q)\n const e = m.elements\n // column-major: element (row i, column j) is e[j * 4 + i]; the ones with exactly one of i, j equal to 0 change sign\n for (const [i, j] of [[0, 1], [0, 2], [1, 0], [2, 0]] as const) e[j * 4 + i] = -e[j * 4 + i]!\n return new THREE.Quaternion().setFromRotationMatrix(m)\n}\n\n/** The mirror image of a pose across the plane x = 0: the left hand that is the right one seen in a mirror (its frame is the right hand's with z flipped, so z is flipped back). */\nconst mirrorQuaternion = (THREE: Three, q: THREE_NS.Quaternion): THREE_NS.Quaternion => {\n const m = new THREE.Matrix4().makeRotationFromQuaternion(q)\n const e = m.elements\n // rows are x, y, z and columns the same, column-major: row 0 (x) flips, and column 2 (z) flips\n for (let column = 0; column < 3; column++) e[column * 4] = -e[column * 4]!\n for (let row = 0; row < 3; row++) e[8 + row] = -e[8 + row]!\n return new THREE.Quaternion().setFromRotationMatrix(m)\n}\n\n/**\n * The player's arms in first person, drawn in the space of the camera so they cannot leave the view. Each arm is a sleeve (upper arm and forearm, an elbow and a cuff) and a hand of skin (a palm,\n * four fingers of three segments and a thumb that close on a grip); the right leg (trouser and shoe) appears only while a kick holds it. The hands go where the stance puts them (`relaxed`, `fists`) or,\n * in the `hold` stance, where the tool in the hands asks (`HandTargets` of game-contracts, world space); a two-bone IK from fixed shoulders brings the sleeves to them, the elbow bending down and out. A\n * clip (`play`) moves the hands and the foot over that, by a weight that is 0 at its start and end.\n *\n * Hand frame (both hands, as `HandPose`): x from the wrist to the knuckles, y the back of the hand, z the little-finger side of a right hand; a left hand is the right one mirrored.\n */\nexport function createFirstPersonArms(THREE: Three, options: FirstPersonArmsOptions = {}): FirstPersonArms {\n const colors: FirstPersonColors = { ...FIRST_PERSON_COLORS, ...options.colors }\n const rig: FirstPersonRig = {\n ...FIRST_PERSON_RIG,\n ...options.rig,\n radius: { ...FIRST_PERSON_RIG.radius, ...options.rig?.radius },\n foot: options.rig?.foot ?? FIRST_PERSON_RIG.foot,\n }\n const stances: Record<string, StanceDef> = { ...FIRST_PERSON_STANCES, ...options.stances }\n const bob: FirstPersonBob = { ...FIRST_PERSON_BOB, ...options.bob }\n const blendSeconds = options.blend ?? DEFAULT_BLEND\n const clips = new Map<string, FirstPersonClip>((options.clips ?? []).map((clip) => [clip.id, clip]))\n\n const root = markKitOrigin(new THREE.Group(), { owner: 'game-characters-three', kind: 'person', id: 'first-person-arms' })\n root.name = 'first-person-arms'\n root.userData.viewmodel = true\n // a little of the colour glows by itself (`FILL`): the arms hang in the camera's space, where the scene's lights reach their undersides badly and a dark trouser would read as a hole\n const lit = (color: number): THREE_NS.MeshLambertMaterial => new THREE.MeshLambertMaterial({ color, emissive: scaleHex(color, FILL) })\n const materials = {\n skin: lit(colors.skin),\n sleeve: lit(colors.sleeve),\n cuff: lit(colors.cuff),\n trouser: lit(colors.trouser),\n shoe: lit(colors.shoe),\n sole: lit(scaleHex(colors.shoe, 0.55)),\n }\n const geometries: THREE_NS.BufferGeometry[] = []\n const Y = new THREE.Vector3(0, 1, 0)\n\n /** A tapered cylinder along +y from y = 0 (the wide end) to y = length, 8 sides. */\n const limb = (parent: THREE_NS.Object3D, wide: number, narrow: number, length: number, material: THREE_NS.Material): Segment => {\n const geometry = new THREE.CylinderGeometry(narrow, wide, length, 8, 1)\n geometry.translate(0, length / 2, 0)\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.frustumCulled = false\n mesh.userData.length = length\n parent.add(mesh)\n return mesh\n }\n const ball = (parent: THREE_NS.Object3D, radius: number, material: THREE_NS.Material): THREE_NS.Mesh => {\n const geometry = new THREE.SphereGeometry(radius, ELBOW_SEGMENTS, 6)\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.frustumCulled = false\n parent.add(mesh)\n return mesh\n }\n const place = (segment: Segment, from: THREE_NS.Vector3, to: THREE_NS.Vector3): void => {\n const direction = new THREE.Vector3().subVectors(to, from)\n const length = direction.length()\n segment.position.copy(from)\n if (length > 1e-6) segment.quaternion.setFromUnitVectors(Y, direction.divideScalar(length))\n segment.scale.y = length / (segment.userData.length as number)\n }\n\n const arms: Record<'R' | 'L', Arm> = {} as Record<'R' | 'L', Arm>\n for (const side of ['R', 'L'] as const) {\n const sign = side === 'R' ? 1 : -1\n const hand = createHandMesh(THREE, materials.skin)\n const anchor = new THREE.Group()\n anchor.name = `first-person-hand-${side}`\n const mirror = new THREE.Group()\n mirror.scale.z = sign // the left hand is the right one mirrored about its z\n mirror.add(hand.root)\n anchor.add(mirror)\n root.add(anchor)\n const upper = limb(root, rig.radius.shoulder, rig.radius.elbow, rig.upper, materials.sleeve)\n const fore = limb(root, rig.radius.elbow, rig.radius.wrist, rig.fore, materials.sleeve)\n const cuff = limb(root, rig.radius.cuff, rig.radius.cuff, 0.03, materials.cuff)\n const elbow = ball(root, rig.radius.elbow * 1.02, materials.sleeve)\n elbow.name = `first-person-elbow-${side}`\n arms[side] = { side, sign, hand, anchor, upper, fore, cuff, elbow, shown: newPose(THREE), from: newPose(THREE), mode: null, blend: 1, drawn: newPose(THREE), joints: { shoulder: new THREE.Vector3(), elbow: new THREE.Vector3(), wrist: new THREE.Vector3() }, away: options.hideWhenIdle ? 1 : 0 }\n }\n\n // the right leg, shown only while a kick holds it: a trouser, a knee, a trouser, a shoe\n const leg = new THREE.Group()\n leg.name = 'first-person-leg'\n leg.visible = false\n root.add(leg)\n const thigh = limb(leg, 0.088, 0.068, rig.thigh, materials.trouser)\n const shin = limb(leg, 0.068, 0.05, rig.shin, materials.trouser)\n const knee = ball(leg, 0.07, materials.trouser)\n const shoe = new THREE.Group()\n const shoeBox = (sx: number, sy: number, sz: number, x: number, y: number, material: THREE_NS.Material): void => {\n const geometry = new THREE.BoxGeometry(sx, sy, sz)\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(x, y, 0)\n mesh.frustumCulled = false\n shoe.add(mesh)\n }\n shoeBox(0.27, 0.07, 0.1, 0.065, -0.05, materials.shoe)\n shoeBox(0.27, 0.025, 0.104, 0.065, -0.095, materials.sole)\n shoeBox(0.1, 0.05, 0.088, 0.17, -0.005, materials.shoe)\n leg.add(shoe)\n\n const shoulderOf = (sign: 1 | -1, out: THREE_NS.Vector3): THREE_NS.Vector3 => (sign === -1 && rig.shoulderLeft ? out.set(...rig.shoulderLeft) : out.set(rig.shoulder[0] * sign, rig.shoulder[1], rig.shoulder[2]))\n const poleOf = (sign: 1 | -1): THREE_NS.Vector3 => (sign === -1 && rig.elbowPoleLeft ? new THREE.Vector3(...rig.elbowPoleLeft) : new THREE.Vector3(rig.elbowPole[0] * sign, rig.elbowPole[1], rig.elbowPole[2]))\n const kneePole = new THREE.Vector3(...rig.kneePole)\n /** The shoulder-to-wrist distance past which the shoulder comes forward: the arm with its elbow at `reachBend` (law of cosines), else nearly straight. */\n const reachOf = (sign: 1 | -1): number => {\n const bend = rig.reachBend?.[sign === 1 ? 0 : 1]\n if (bend === undefined) return (rig.upper + rig.fore) * REACH_SLACK\n return Math.sqrt(rig.upper * rig.upper + rig.fore * rig.fore + 2 * rig.upper * rig.fore * Math.cos(bend))\n }\n const hip = new THREE.Vector3(...rig.hip)\n\n const euler = new THREE.Euler(0, 0, 0, 'YZX')\n const quaternionOf = (r: readonly [number, number, number]): THREE_NS.Quaternion => new THREE.Quaternion().setFromEuler(euler.set(r[0], r[1], r[2], 'YZX'))\n const restPose = (rest: RestPose, mirror: boolean, out: Pose): Pose => {\n out.p.set(...rest.p)\n out.q.copy(quaternionOf(rest.r))\n if (mirror) {\n out.p.x = -out.p.x\n out.q.copy(mirrorQuaternion(THREE, out.q))\n }\n out.grip = rest.grip ?? 0\n out.scale = 1\n return out\n }\n const DEFAULT_REST: RestPose = { p: [0.17, -0.3, -0.3], r: [0, 1.5, 0], grip: 0.3 }\n const stanceRest = (id: string, side: 'R' | 'L', out: Pose): Pose => {\n const stance = stances[id] ?? stances.relaxed\n const right = stance?.R ?? DEFAULT_REST\n const left = stance?.L\n if (side === 'R') return restPose(right, false, out)\n return left && left !== 'mirror' ? restPose(left, false, out) : restPose(right, true, out)\n }\n\n const camPosition = new THREE.Vector3()\n const camQuaternion = new THREE.Quaternion()\n const camInverse = new THREE.Quaternion()\n const clamped = newPose(THREE)\n const probeAt = new THREE.Vector3()\n const probeForward = new THREE.Vector3()\n const probeFingers = new THREE.Vector3()\n /** Set each update when the host can answer where the world is in front of the camera (`contact` of the state). */\n let contact: ((origin: [number, number, number], direction: [number, number, number], maxDistance: number) => number | null) | undefined\n /**\n * Keeps a hand (or the foot) in front of the surface it would go into: the surface along the camera's forward through the hand's place, minus how far the hand reaches forward (its fingers when they point\n * ahead) and a few millimetres. The IK then bends the elbow instead of the hand entering the mesh. Never closer to the eye than `CONTACT_MIN`.\n */\n const keepOutside = (pose: Pose, reach: number): Pose => {\n if (!contact) return pose\n probeAt.set(pose.p.x, pose.p.y, 0).applyQuaternion(camQuaternion).add(camPosition)\n probeForward.set(0, 0, -1).applyQuaternion(camQuaternion)\n const distance = contact([probeAt.x, probeAt.y, probeAt.z], [probeForward.x, probeForward.y, probeForward.z], CONTACT_PROBE)\n if (distance === null) return pose\n const limit = Math.max(CONTACT_MIN, distance - reach - CONTACT_MARGIN)\n if (-pose.p.z <= limit) return pose\n copyPose(clamped, pose)\n clamped.p.z = -limit\n return clamped\n }\n /** How far a hand reaches forward of its middle: the fingers when they point ahead, else the thickness of the palm. */\n const forward = (pose: Pose, length: number): number => Math.max(CONTACT_PALM, -probeFingers.set(1, 0, 0).applyQuaternion(pose.q).z * length * pose.scale)\n const handReach = (pose: Pose): number => forward(pose, 0.085)\n const camScale = new THREE.Vector3()\n const toCamera = (target: HandPose, grip: number, scale: number, out: Pose): Pose => {\n out.p.set(...target.position).sub(camPosition).applyQuaternion(camInverse)\n out.q.set(...target.quaternion).premultiply(camInverse)\n out.grip = grip\n out.scale = scale\n return out\n }\n\n const listeners = new Set<(event: FirstPersonEvent) => void>()\n /** `left`: the foot is the left one; `swap`: the hands swap sides in a mirror. */\n let run: { clip: FirstPersonClip; time: number; left: boolean; swap: boolean } | null = null\n const emit = (event: FirstPersonEvent): void => {\n for (const listener of listeners) listener(event)\n }\n const fire = (clip: FirstPersonClip, from: number, to: number): void => {\n for (const event of clipEventsBetween(clip, from, to)) emit({ ...event, clip: clip.id })\n }\n\n let stanceId = 'relaxed'\n let phase = 0\n let swing = 0\n let sink = 0\n let first = true\n const bobOffset = new THREE.Vector3()\n const desired = newPose(THREE)\n const channelPose = newPose(THREE)\n const mixed = newPose(THREE)\n const dropped = newPose(THREE)\n let indexCurl: number | undefined\n const bone = createTwoBone(THREE)\n const shoulder = new THREE.Vector3()\n const wristAt = new THREE.Vector3()\n const palmAt = new THREE.Vector3()\n const fingers = new THREE.Vector3()\n const towards = new THREE.Vector3()\n\n /** The hand of the clip's channel, in the camera's space, as a pose. */\n /** `from`: the side the channel was written for (the other one when the hands swap); numbers written for the right hand, or the right's in a mirror, are mirrored onto the left and the other way round. */\n const fromChannel = (channel: FirstPersonSampleChannel, side: 'R' | 'L', base: Pose, out: Pose, from: 'R' | 'L' = side): Pose => {\n out.p.set(...channel.p)\n out.q.copy(quaternionOf(channel.r))\n const rightNumbers = from === 'R' || channel.mirror\n if (rightNumbers !== (side === 'R')) {\n out.p.x = -out.p.x\n out.q.copy(mirrorQuaternion(THREE, out.q))\n }\n out.grip = channel.grip ?? base.grip\n out.scale = base.scale\n return out\n }\n\n /** Where the elbow goes when it is put in the view (`elbowView`); the shoulder follows it, out of the view. */\n const elbowAt = new THREE.Vector3()\n const viewOf = (camera: THREE_NS.Object3D): View | null => {\n const lens = camera as THREE_NS.PerspectiveCamera\n if (!lens.isPerspectiveCamera) return null\n const tanV = Math.tan((lens.fov * Math.PI) / 360)\n return { tanV, tanH: tanV * lens.aspect }\n }\n /** Sets `elbowAt` a forearm from the wrist along `elbowView`, pulled inside the view, and `shoulder` an upper arm behind it toward the body's shoulder; false when the rig has no `elbowView`. */\n const placeElbowInView = (sign: 1 | -1, view: View): boolean => {\n const way = rig.elbowView?.[sign === 1 ? 0 : 1]\n if (!way) return false\n elbowAt.set(way[0], way[1], way[2]).setLength(rig.fore).add(wristAt)\n for (let pass = 0; pass < ELBOW_VIEW_PASSES; pass++) {\n const depth = Math.max(0.05, -elbowAt.z)\n const high = view.tanV * ELBOW_VIEW_MARGIN * depth\n const wide = view.tanH * ELBOW_VIEW_MARGIN * depth\n elbowAt.y = Math.max(elbowAt.y, -high)\n elbowAt.x = Math.min(wide, Math.max(-wide, elbowAt.x))\n elbowAt.sub(wristAt).setLength(rig.fore).add(wristAt)\n }\n shoulder.sub(elbowAt).setLength(rig.upper).add(elbowAt)\n return true\n }\n const drawArm = (arm: Arm, pose: Pose, view: View | null): void => {\n copyPose(arm.drawn, pose)\n const scale = pose.scale\n // the wrist is where the forearm ends: behind the palm along the fingers\n fingers.set(1, 0, 0).applyQuaternion(pose.q)\n wristAt.copy(pose.p).addScaledVector(fingers, -rig.wrist * scale)\n shoulderOf(arm.sign, shoulder).add(bobOffset)\n if (view && placeElbowInView(arm.sign, view)) {\n solveTwoBone(shoulder, wristAt, rig.upper, rig.fore, towards.copy(elbowAt).sub(shoulder).add(elbowAt).sub(wristAt), bone)\n finishArm(arm, pose, scale)\n return\n }\n // an arm that cannot reach brings its shoulder forward, toward the hand, up to `reachShift`: the shoulders are never on screen, so a weapon held out at the length of a rifle stays in the\n // hands, with the elbow still bent by `reachBend`\n const excess = shoulder.distanceTo(wristAt) - reachOf(arm.sign)\n if (excess > 0 && rig.reachShift > 0) shoulder.addScaledVector(towards.subVectors(wristAt, shoulder).normalize(), Math.min(excess, rig.reachShift))\n solveTwoBone(shoulder, wristAt, rig.upper, rig.fore, poleOf(arm.sign), bone)\n finishArm(arm, pose, scale)\n }\n\n /** Puts the hand on the end of the forearm (out of reach, short of the target) and the sleeve on the bones `bone` holds. */\n const finishArm = (arm: Arm, pose: Pose, scale: number): void => {\n palmAt.copy(bone.end).addScaledVector(fingers, rig.wrist * scale)\n arm.drawn.p.copy(palmAt)\n arm.anchor.position.copy(palmAt)\n arm.anchor.quaternion.copy(pose.q)\n arm.anchor.scale.setScalar(scale)\n arm.hand.setGrip(pose.grip)\n arm.hand.setIndex(arm.side === 'R' ? indexCurl : undefined)\n arm.joints.shoulder.copy(shoulder)\n arm.joints.elbow.copy(bone.joint)\n arm.joints.wrist.copy(bone.end)\n place(arm.upper, shoulder, bone.joint)\n place(arm.fore, bone.joint, bone.end)\n arm.elbow.position.copy(bone.joint)\n // the cuff sits at the end of the forearm, a little onto the wrist\n const toWrist = new THREE.Vector3().subVectors(bone.end, bone.joint).normalize()\n place(arm.cuff, new THREE.Vector3().copy(bone.end).addScaledVector(toWrist, -0.02), new THREE.Vector3().copy(bone.end).addScaledVector(toWrist, 0.012))\n }\n\n const footPose = newPose(THREE)\n const footRest = newPose(THREE)\n const ankle = new THREE.Vector3()\n const hipMirrored = new THREE.Vector3(-hip.x, hip.y, hip.z)\n const kneePoleMirrored = new THREE.Vector3(-kneePole.x, kneePole.y, kneePole.z)\n const drawLeg = (pose: Pose, left: boolean): void => {\n const origin = left ? hipMirrored : hip\n solveTwoBone(origin, pose.p, rig.thigh, rig.shin, left ? kneePoleMirrored : kneePole, bone)\n ankle.copy(bone.end)\n place(thigh, origin, bone.joint)\n place(shin, bone.joint, ankle)\n knee.position.copy(bone.joint)\n shoe.position.copy(ankle)\n shoe.quaternion.copy(pose.q)\n }\n\n const modeOf = (key: string, arm: Arm): void => {\n if (arm.mode === key) return\n copyPose(arm.from, arm.shown)\n arm.mode = key\n arm.blend = first ? 1 : 0\n }\n\n return {\n root,\n get playing() {\n return run ? run.clip.id : null\n },\n get stance() {\n return stanceId\n },\n play(id, options) {\n const clip = clips.get(id)\n if (!clip) return false\n run = { clip, time: 0, left: options?.leg === 'left', swap: options?.hand === 'left' }\n fire(clip, -1e-9, 0) // the events at t = 0 fire as the clip starts\n return true\n },\n stop() {\n run = null\n },\n update(dt, state) {\n const { camera } = state\n contact = state.contact\n camera.updateWorldMatrix(true, false)\n camera.matrixWorld.decompose(camPosition, camQuaternion, camScale)\n camInverse.copy(camQuaternion).invert()\n root.position.copy(camPosition)\n root.quaternion.copy(camQuaternion)\n root.updateMatrixWorld(true)\n\n // walk bob: the shoulders (and the hands at rest) sway and rise with the stride, more when running, less when still; crouching sinks them\n const speed = state.speed ?? 0\n const target = Math.min(1, speed / bob.fullSpeed) * (state.running ? bob.run : 1)\n swing += (target - swing) * Math.min(1, dt * 8)\n phase += dt * speed * bob.frequency\n sink += ((state.crouch ? 1 : 0) - sink) * Math.min(1, dt * 8)\n bobOffset.set(Math.sin(phase) * bob.x * swing, Math.sin(phase * 2) * bob.y * swing - bob.crouch * sink, 0)\n\n stanceId = state.stance ?? 'relaxed'\n const stance = stances[stanceId] ?? stances.relaxed\n const targets = state.targets ?? null\n\n // where the clip is now\n if (run) {\n const from = run.time\n run.time += dt\n fire(run.clip, from, Math.min(run.time, run.clip.duration))\n }\n const sample = run ? sampleFirstPersonClip(run.clip, Math.min(run.time, run.clip.duration)) : null\n\n for (const side of ['R', 'L'] as const) {\n const arm = arms[side]\n const target = targets?.[side]\n let mode: string\n if (stance?.follow && target) {\n mode = 'target'\n toCamera(target, (side === 'L' ? targets?.gripL : undefined) ?? targets?.grip ?? 1, targets?.scale ?? 1, desired)\n } else {\n mode = `rest:${stance?.follow ? (stance.fallback ?? 'relaxed') : stanceId}`\n stanceRest(stance?.follow ? (stance.fallback ?? 'relaxed') : stanceId, side, desired)\n desired.p.add(bobOffset)\n }\n modeOf(mode, arm)\n if (side === 'R') indexCurl = mode === 'target' ? targets?.fingers?.index : undefined\n arm.blend = blendSeconds <= 0 ? 1 : Math.min(1, arm.blend + dt / blendSeconds)\n if (arm.blend >= 1) copyPose(arm.shown, desired)\n else mixPose(THREE, arm.shown, arm.from, desired, ease(arm.blend))\n const from = run?.swap ? (side === 'R' ? 'L' : 'R') : side\n const channel = sample?.[from]\n let pose: Pose\n if (channel && channel.w > 0) {\n fromChannel(channel, side, arm.shown, channelPose, from)\n mixPose(THREE, mixed, arm.shown, channelPose, channel.w)\n pose = mode === 'target' ? mixed : keepOutside(mixed, handReach(mixed))\n } else pose = mode === 'target' ? arm.shown : keepOutside(arm.shown, handReach(arm.shown))\n // nothing to do with the hands (walking, standing): they drop out of the view and are not drawn, as a person's hands do not hang in front of their eyes\n const idle = options.hideWhenIdle === true && mode === 'rest:relaxed' && !(channel && channel.w > 0)\n arm.away = options.hideWhenIdle ? Math.min(1, Math.max(0, arm.away + ((idle ? 1 : 0) - arm.away) * Math.min(1, dt * (idle ? AWAY_OUT : AWAY_IN)))) : 0\n if (arm.away > 0) {\n copyPose(dropped, pose)\n dropped.p.y -= AWAY_DROP * ease(arm.away)\n pose = dropped\n }\n drawArm(arm, pose, mode === 'target' && targets?.elbows !== 'body' ? viewOf(state.camera) : null)\n const shown = arm.away < AWAY_HIDDEN\n for (const part of [arm.anchor, arm.upper, arm.fore, arm.cuff, arm.elbow]) part.visible = shown\n }\n\n // the leg of a kick\n const foot = sample?.F\n leg.visible = !!foot && foot.w > FOOT_SHOWN\n if (foot && leg.visible) {\n restPose(rig.foot, false, footRest)\n fromChannel(foot, 'R', footRest, footPose)\n mixPose(THREE, mixed, footRest, footPose, foot.w)\n copyPose(footPose, mixed)\n // the left leg is the right one in a mirror\n if (run?.left) {\n footPose.p.x = -footPose.p.x\n footPose.q.copy(mirrorRotation(THREE, footPose.q))\n }\n drawLeg(contact ? keepOutside(footPose, forward(footPose, FOOT_LENGTH)) : footPose, run?.left ?? false)\n }\n if (run && run.time >= run.clip.duration) run = null\n first = false\n },\n on(_type, listener) {\n listeners.add(listener)\n return () => void listeners.delete(listener)\n },\n joints(side) {\n const { shoulder, elbow, wrist } = arms[side].joints\n return { shoulder: shoulder.clone(), elbow: elbow.clone(), wrist: wrist.clone() }\n },\n handPose(side) {\n const pose = arms[side].drawn\n return { position: pose.p.clone(), quaternion: pose.q.clone(), grip: pose.grip }\n },\n dispose() {\n run = null\n listeners.clear()\n for (const arm of Object.values(arms)) arm.hand.dispose()\n for (const geometry of geometries) geometry.dispose()\n for (const material of Object.values(materials)) material.dispose()\n root.removeFromParent()\n },\n }\n}\n","{\n \"source\": {\n \"note\": \"Authored in the kit: no team delivered first-person arms. The rig is in metres in the camera's space (x right, y up, the view looks down -z); rest poses use the hand frame of HandPose in game-contracts, Euler [roll, yaw, pitch] in the order YZX (yaw pi/2 points the fingers forward).\"\n },\n \"rig\": {\n \"shoulder\": [0.16, -0.36, 0.18],\n \"upper\": 0.32,\n \"fore\": 0.3,\n \"reachShift\": 0.42,\n \"reachBend\": [1.35, 0.95],\n \"elbowView\": [[0.96, -0.26, -0.06], null],\n \"wrist\": 0.07,\n \"elbowPole\": [0.45, -1, 0.2],\n \"shoulderLeft\": [-0.07, -0.46, 0.18],\n \"elbowPoleLeft\": [-0.1, -1, 0.2],\n \"radius\": { \"shoulder\": 0.04, \"elbow\": 0.034, \"wrist\": 0.028, \"cuff\": 0.031 },\n \"hip\": [0.12, -0.82, 0.04],\n \"thigh\": 0.46,\n \"shin\": 0.46,\n \"kneePole\": [0.1, 0.5, -1],\n \"foot\": { \"p\": [0.13, -0.85, -0.05], \"r\": [0, 1.5708, 0] }\n },\n \"stances\": {\n \"relaxed\": {\n \"R\": { \"p\": [0.2, -0.22, -0.36], \"r\": [0.05, 1.57, -0.05], \"grip\": 0.2 },\n \"L\": \"mirror\"\n },\n \"fists\": {\n \"R\": { \"p\": [0.15, -0.12, -0.4], \"r\": [0, 1.5, 0.15], \"grip\": 1 },\n \"L\": \"mirror\"\n },\n \"hold\": { \"follow\": true, \"fallback\": \"relaxed\" }\n },\n \"bob\": { \"frequency\": 2.3, \"x\": 0.006, \"y\": 0.008, \"run\": 1.5, \"fullSpeed\": 4, \"crouch\": 0.02 }\n}\n","import { buildHand } from '../rich/accessories/hands'\nimport type { THREE_NS } from '../three'\n\ntype Three = typeof THREE_NS\n\n/** The palm of the Retratos do Vale hand (the same one the player's body wears in third person): a flattened ball this far down the hand from the wrist. */\nconst PALM = { radius: 0.048, scale: [0.6, 1.05, 1] as const, down: 0.035 }\n/** How far the fingers curl at a full grip (radians), the near and the far joint, as the body's hand (`avatar.ts`) closes them. */\nconst CURL = { closed: 1.25, near: 0.9, far: 1.1 }\nconst THUMB = { open: 0.32, closed: 0.25 }\n\nexport type HandMesh = {\n /** The hand with its origin at the middle of the palm: x to the knuckles, y the back of the hand, z the little-finger side (the thumb at -z). */\n root: THREE_NS.Group\n /** 0 open, 1 closed on a grip. */\n setGrip(grip: number): void\n /** Curls the index finger on its own (0 extended, 1 curled); `undefined` gives it back to the grip. */\n setIndex(curl: number | undefined): void\n dispose(): void\n}\n\n/**\n * The first-person hand: the Retratos do Vale hand (a rounded palm, four fingers of two joints and a thumb, `buildHand`), the one the player's body wears in third person, turned\n * to the hand frame of `HandPose`. A left hand is made by mirroring the group (`scale.z = -1`).\n */\nexport const createHandMesh = (THREE: Three, skin: THREE_NS.Material, wristSkin: THREE_NS.Material = skin): HandMesh => {\n const root = new THREE.Group()\n root.name = 'first-person-hand'\n const geometries: THREE_NS.BufferGeometry[] = []\n const add = (parent: THREE_NS.Object3D, geometry: THREE_NS.BufferGeometry, material: THREE_NS.Material, x = 0, y = 0, z = 0): THREE_NS.Mesh => {\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(x, y, z)\n mesh.frustumCulled = false\n parent.add(mesh)\n return mesh\n }\n // the team's hand hangs its fingers down -y with the palm toward +x (a right hand) and the thumb in front (+z): as the hand frame, its -y is x, its -x is y and its -z is z\n const group = new THREE.Group()\n group.quaternion.setFromRotationMatrix(new THREE.Matrix4().makeBasis(new THREE.Vector3(0, -1, 0), new THREE.Vector3(-1, 0, 0), new THREE.Vector3(0, 0, -1)))\n group.position.set(-PALM.down, 0, 0)\n root.add(group)\n add(group, new THREE.SphereGeometry(PALM.radius, 14, 10), skin, 0, -PALM.down, 0).scale.set(...PALM.scale)\n const built = buildHand({ THREE, add, hg: group, handM: skin, s: -1, detailed: true }) as { fingers: THREE_NS.Object3D[]; th: THREE_NS.Object3D | null }\n // the wrist the hand grows from, where the sleeve ends\n const wristGeometry = new THREE.CylinderGeometry(0.03, 0.033, 0.05, 10)\n wristGeometry.rotateZ(Math.PI / 2)\n add(root, wristGeometry, wristSkin, -PALM.down - 0.03, 0, 0)\n\n let lastGrip = 0\n let indexCurl: number | undefined\n const curlFinger = (finger: number, k: number): void => {\n built.fingers[finger * 2]!.rotation.z = k * CURL.closed * CURL.near\n built.fingers[finger * 2 + 1]!.rotation.z = k * CURL.closed * CURL.far\n }\n const applyIndex = (): void => curlFinger(0, indexCurl === undefined ? lastGrip : Math.min(1, Math.max(0, indexCurl)))\n const setGrip = (grip: number): void => {\n lastGrip = Math.min(1, Math.max(0, grip))\n for (let finger = 1; finger < 4; finger++) curlFinger(finger, lastGrip)\n if (built.th) built.th.rotation.z = THUMB.open + lastGrip * THUMB.closed\n applyIndex()\n }\n const setIndex = (value: number | undefined): void => {\n indexCurl = value\n applyI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KAAK;AAAA,IACjF;AAAA,IACA,UAAU;AACR,YAAM;AACN,gBAAU,MAAM;AAChB,iBAAW,OAAO,OAAO,OAAO,IAAI,EAAG,KAAI,KAAK,QAAQ;AACxD,iBAAW,YAAY,WAAY,UAAS,QAAQ;AACpD,iBAAW,YAAY,OAAO,OAAO,SAAS,EAAG,UAAS,QAAQ;AAClE,WAAK,iBAAiB;AAAA,IACxB;AAAA,EACF;AACF;","names":["tag","shapeGeometries","createRng","distance","distance","TWO_PI","createRng","bob","raise","tilt","clipEventsBetween","hexOf","distance","clipEventsBetween","options","target","shoulder"]}
1
+ {"version":3,"sources":["../src/instanced/body-geometry.ts","../src/instanced/segment-clips.ts","../src/instanced/accessory.ts","../src/instanced/impostor-batch.ts","../src/instanced/blob-shadow.ts","../src/instanced/flying-limbs.ts","../src/player/avatar.ts","../src/presets/player-avatar.json","../src/first-person/ik.ts","../src/player/arm-reach.ts","../src/player/head-hiding.ts","../src/player/room-avatar.ts","../src/first-person/arms.ts","../src/presets/first-person-arms.json","../src/first-person/hand.ts"],"sourcesContent":["import { shapeGeometries } from '@adatechnology/game-shapes-three'\nimport { TEAM_GAME } from '@adatechnology/game-characters'\nimport type { BodySpec, JointId } from '@adatechnology/game-characters'\n\nimport type { Three, THREE_NS } from '../three'\n\ntype Vec3 = readonly [number, number, number]\n\n/**\n * The joints the instanced body hangs from, by the game's names. `E` is the side with the negative x (bones 2, 4, 7 and 9), `D` the positive one\n * (bones 3, 5, 8 and 10); the shader's `side` depends on it, so the sides are told apart by the sign of x, whatever a spec calls them.\n */\nexport type BodyJoints = {\n readonly hip: Vec3\n readonly neck: Vec3\n readonly shoulderE: Vec3\n readonly shoulderD: Vec3\n readonly elbowE: Vec3\n readonly elbowD: Vec3\n readonly thighE: Vec3\n readonly thighD: Vec3\n readonly kneeE: Vec3\n readonly kneeD: Vec3\n}\n\nconst negativeFirst = (first: Vec3, second: Vec3): readonly [Vec3, Vec3] => (first[0] <= second[0] ? [first, second] : [second, first])\n\nexport const jointsOf = (body: BodySpec): BodyJoints => {\n const at = (id: JointId): Vec3 => body.joints[id]\n const [shoulderE, shoulderD] = negativeFirst(at('shoulderL'), at('shoulderR'))\n const [elbowE, elbowD] = negativeFirst(at('elbowL'), at('elbowR'))\n const [thighE, thighD] = negativeFirst(at('hipL'), at('hipR'))\n const [kneeE, kneeD] = negativeFirst(at('kneeL'), at('kneeR'))\n return { hip: at('hip'), neck: at('neck'), shoulderE, shoulderD, elbowE, elbowD, thighE, thighD, kneeE, kneeD }\n}\n\n/** The lengths the game's body was drawn with: a spec's segments scale them (1 for the game's own joints). */\nconst GAME_UPPER_ARM = 0.31\nconst GAME_THIGH = 0.42\n\n/** The ratio, or exactly 1 when the spec has the game's own length (so the game's numbers are not touched by rounding noise). */\nconst scaleOf = (length: number, gameLength: number): number => (Math.abs(length - gameLength) < 1e-9 ? 1 : length / gameLength)\n\n/** The drop from one joint to the next: the limbs hang straight down, so only the height counts. */\nconst distance = (from: Vec3, to: Vec3): number => Math.abs(from[1] - to[1])\n\ntype Geometry = THREE_NS.BufferGeometry\n\n/** Bone, material and pivots per vertex: the attributes the shader animates by (G 65341 `tagGeo`). */\nconst tagGeometry = (geometry: Geometry, bone: number, pivot: Vec3, material: number, parent: Vec3 = [0, 0, 0], three: Three): Geometry => {\n const source = geometry.index ? geometry.toNonIndexed() : geometry\n const count = source.attributes.position!.count\n source.setAttribute('bone', new three.Float32BufferAttribute(new Float32Array(count).fill(bone), 1))\n const colors = new Float32Array(count * 4)\n for (let index = 0; index < count; index++) colors[index * 4 + 3] = material\n source.setAttribute('vcol', new three.Float32BufferAttribute(colors, 4))\n const pivots = new Float32Array(count * 3)\n const parents = new Float32Array(count * 3)\n for (let index = 0; index < count; index++) {\n pivots.set(pivot, index * 3)\n parents.set(parent, index * 3)\n }\n source.setAttribute('pivot', new three.Float32BufferAttribute(pivots, 3))\n source.setAttribute('ppivot', new three.Float32BufferAttribute(parents, 3))\n source.deleteAttribute('uv')\n return source\n}\n\nconst MERGED_ATTRIBUTES: readonly (readonly [string, number])[] = [['position', 3], ['normal', 3], ['bone', 1], ['vcol', 4], ['pivot', 3], ['ppivot', 3]]\n\n/** The parts as one geometry (G 65354 `mergeBody`). */\nconst mergeBody = (list: readonly Geometry[], three: Three): Geometry => {\n const total = list.reduce((sum, geometry) => sum + geometry.attributes.position!.count, 0)\n const merged = new three.BufferGeometry()\n for (const [name, size] of MERGED_ATTRIBUTES) {\n const array = new Float32Array(total * size)\n let offset = 0\n for (const geometry of list) {\n const part = geometry.attributes[name]!.array as Float32Array\n array.set(part, offset)\n offset += part.length\n }\n merged.setAttribute(name, new three.BufferAttribute(array, size))\n }\n merged.computeBoundingSphere()\n return merged\n}\n\nexport type BuildInstancedBodyParams = {\n /** Radial segments of the torso: 16, 10 or 5 for the three levels of detail. */\n readonly segments: number\n /** Proportions (default `TEAM_GAME`, the joints the game's body was drawn with). */\n readonly body?: BodySpec\n}\n\n/**\n * The crowd body as one merged geometry, torso, head, hair, jaw, eyes, arms and legs tagged with the bone, pivot and material the shader reads\n * (G 65367 `buildBody`). The joints come from the spec, so a different `body` moves the limbs; the parts' own sizes follow the segment lengths.\n */\nexport const buildInstancedBody = (host: Three, { segments, body = TEAM_GAME }: BuildInstancedBodyParams): Geometry => {\n const three = shapeGeometries(host)\n const joints = jointsOf(body)\n const parts: Geometry[] = []\n const half = Math.max(4, segments >> 1)\n const { Vector2, LatheGeometry, CylinderGeometry, SphereGeometry } = three\n const limb = (radiusA: number, radiusB: number, length: number, radial: number): Geometry => {\n const geometry = new CylinderGeometry(radiusB, radiusA, length, radial, 1, false)\n geometry.translate(0, -length / 2, 0)\n return geometry\n }\n const ball = (radius: number, radial: number): Geometry => new SphereGeometry(radius, radial, Math.max(3, Math.round(radial * 0.75)))\n const tag = (geometry: Geometry, bone: number, pivot: Vec3, material: number, parent?: Vec3): void => void parts.push(tagGeometry(geometry, bone, pivot, material, parent, three))\n const profile = (points: readonly (readonly [number, number])[]): THREE_NS.Vector2[] => points.map(([radius, height]) => new Vector2(radius, height))\n const hip = joints.hip\n const neck = joints.neck\n const torso = new LatheGeometry(profile([[0, 0.86], [0.17, 0.88], [0.165, 0.98], [0.15, 1.1], [0.175, 1.26], [0.19, 1.38], [0.14, 1.47], [0.06, 1.52], [0, 1.53]]), segments)\n torso.scale(1.12, 1, 0.64)\n tag(torso, 0, hip, 1)\n const pelvis = new LatheGeometry(profile([[0, 0.78], [0.15, 0.8], [0.172, 0.88], [0.165, 0.97], [0, 0.98]]), segments)\n pelvis.scale(1.12, 1, 0.7)\n tag(pelvis, 0, hip, 2)\n const neckPart = limb(0.055, 0.05, 0.12, half)\n neckPart.translate(0, 1.6, 0)\n tag(neckPart, 1, neck, 0)\n const head = ball(0.13, segments)\n head.scale(0.96, 1.1, 1.02)\n head.translate(0, 1.67, 0.01)\n tag(head, 1, neck, 0)\n const hair = new SphereGeometry(0.137, segments, Math.max(3, segments >> 1), 0, Math.PI * 2, 0, Math.PI * 0.42)\n hair.scale(0.98, 1.1, 1.04)\n hair.rotateX(-0.35)\n hair.translate(0, 1.68, -0.01)\n tag(hair, 1, neck, 4)\n const jaw = ball(0.085, half)\n jaw.scale(1, 0.55, 1)\n jaw.translate(0, 1.58, 0.05)\n tag(jaw, 11, neck, 0)\n for (const side of [-1, 1]) {\n const eye = ball(0.02, 4)\n eye.scale(1.2, 0.7, 0.5)\n eye.translate(side * 0.045, 1.69, 0.125)\n tag(eye, 6, neck, 3)\n }\n const armLengthScale = scaleOf(distance(joints.shoulderE, joints.elbowE), GAME_UPPER_ARM)\n const legLengthScale = scaleOf(distance(joints.thighE, joints.kneeE), GAME_THIGH)\n const arms: readonly [number, number, number, Vec3, Vec3][] = [[-1, 2, 7, joints.shoulderE, joints.elbowE], [1, 3, 8, joints.shoulderD, joints.elbowD]]\n for (const [, bone, forearmBone, shoulder, elbow] of arms) {\n const upper = limb(0.074, 0.06, 0.31 * armLengthScale, half)\n upper.translate(shoulder[0], shoulder[1], 0)\n tag(upper, bone, shoulder, 1)\n const joint = ball(0.07, half)\n joint.translate(shoulder[0], shoulder[1], 0)\n tag(joint, bone, shoulder, 1)\n const forearm = limb(0.06, 0.046, 0.29 * armLengthScale, half)\n forearm.translate(elbow[0], elbow[1], 0)\n tag(forearm, forearmBone, elbow, 0, shoulder)\n const hand = ball(0.05, half)\n hand.scale(0.8, 1.2, 0.6)\n hand.translate(elbow[0], elbow[1] - 0.33 * armLengthScale, 0)\n tag(hand, forearmBone, elbow, 0, shoulder)\n }\n const legs: readonly [number, number, number, Vec3, Vec3][] = [[-1, 4, 9, joints.thighE, joints.kneeE], [1, 5, 10, joints.thighD, joints.kneeD]]\n for (const [, bone, shinBone, hipJoint, knee] of legs) {\n const thigh = limb(0.105, 0.078, 0.42 * legLengthScale, half)\n thigh.translate(hipJoint[0], hipJoint[1], 0)\n tag(thigh, bone, hipJoint, 2)\n const kneeJoint = ball(0.075, half)\n kneeJoint.translate(knee[0], knee[1], 0)\n tag(kneeJoint, shinBone, knee, 2, hipJoint)\n const shin = limb(0.077, 0.056, knee[1] - 0.1, half)\n shin.translate(knee[0], knee[1], 0)\n tag(shin, shinBone, knee, 2, hipJoint)\n const foot = ball(0.06, half)\n foot.scale(0.95, 0.72, 1.85)\n foot.translate(knee[0], 0.06, 0.05)\n tag(foot, shinBone, knee, 5, hipJoint)\n }\n return mergeBody(parts, three)\n}\n","import type { Three, THREE_NS } from '../three'\n\n/** Bones of the instanced body (`body-geometry.ts`) and texels per bone in the clip texture: a rotation and a displacement. */\nexport const CLIP_BONES = 12\nexport const CLIP_TEXELS = CLIP_BONES * 2\n/** Rows sampled per second of a clip (the bake rate of the D12 ladder). */\nexport const CLIP_RATE = 30\n/** Clips a texture may hold: the index is four bits of `iD.z`. */\nexport const CLIP_LIMIT = 16\n\nexport type ClipLimp = 'left' | 'right' | 'drag'\n\n/** A looping clip of the instanced body's walk, as numbers of the shader's own walk (`bodyAnim`) plus the gait styles of the identity extension. */\nexport type SegmentClipSpec = {\n readonly id: string\n /** Rows of the clip: its cycles at 30 Hz. */\n readonly frames: number\n /** Walk cycles the clip spans (a lurch is two). */\n readonly cycles?: number\n /** 0 arms hanging as the wandering zombie, 1 raised toward the prey (blended per instance by the arms). */\n readonly armRaise: number\n readonly sway?: number\n readonly bendPulse?: number\n readonly limp?: ClipLimp\n readonly stagger?: boolean\n}\n\nexport type SegmentClipSet = {\n readonly specs: readonly SegmentClipSpec[]\n /** First row of each clip. */\n readonly start: readonly number[]\n readonly frames: readonly number[]\n readonly cycles: readonly number[]\n readonly rows: number\n /** RGBA32F, `CLIP_TEXELS` wide: per bone a quaternion (x, y, z, w) and a displacement (x, y, z, 0). */\n readonly data: Float32Array\n}\n\ntype Quat = readonly [number, number, number, number]\n\nconst IDENTITY: Quat = [0, 0, 0, 1]\nconst axisAngle = (axis: 0 | 1 | 2, angle: number): Quat => {\n const half = angle / 2\n const q: [number, number, number, number] = [0, 0, 0, Math.cos(half)]\n q[axis] = Math.sin(half)\n return q\n}\nconst multiply = (a: Quat, b: Quat): Quat => [\n a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],\n a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0],\n a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3],\n a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],\n]\nconst rotateX = (angle: number): Quat => axisAngle(0, angle)\nconst rotateZ = (angle: number): Quat => axisAngle(2, angle)\n\nconst TWO_PI = Math.PI * 2\nconst WALK_FRAMES = 24\nconst LEAN_PART = 0.3\nconst ARM_FORWARD = [-0.12, -1.35] as const\nconst STAGGER_ARM = -0.95\n\n/** The clips of the kit: each gait family with its arms down and its arms raised (the crowd blends the two by how far the agent has raised its arms). */\nconst family = (id: string, rest: Omit<SegmentClipSpec, 'id' | 'frames' | 'armRaise'>, frames = WALK_FRAMES): readonly SegmentClipSpec[] => [\n { id: `${id}_down`, frames, armRaise: 0, ...rest },\n { id: `${id}_up`, frames, armRaise: 1, ...rest },\n]\n\nexport const SEGMENT_CLIPS: readonly SegmentClipSpec[] = [\n ...family('walk', {}),\n ...family('limp_left', { limp: 'left' }),\n ...family('limp_right', { limp: 'right' }),\n ...family('drag', { limp: 'drag' }),\n ...family('lurch', { bendPulse: 1, cycles: 2 }, WALK_FRAMES * 2),\n ...family('shamble', { sway: 0.1 }),\n ...family('stagger', { stagger: true }),\n]\n\nconst limpOf = (limp: ClipLimp | undefined, left: boolean, ph: number): Quat => {\n if (limp === 'drag') return left ? rotateX(0.55) : IDENTITY\n if (limp === 'left' && left) return rotateX(-0.32 * (0.5 + 0.5 * Math.sin(ph)))\n if (limp === 'right' && !left) return rotateX(-0.32 * (0.5 + 0.5 * Math.sin(ph)))\n return IDENTITY\n}\n\n/** The quaternion of every bone at a step of a clip, and the displacement of the whole body, from the maths of the shader's walk. */\nconst sampleBones = (spec: SegmentClipSpec, step: number): { readonly quats: Quat[]; readonly bounce: number } => {\n const cycles = spec.cycles ?? 1\n const ph = (step / spec.frames) * TWO_PI * cycles\n const raise = spec.armRaise\n const quats: Quat[] = Array.from({ length: CLIP_BONES }, () => IDENTITY)\n for (const bone of [4, 5]) {\n const legSign = bone === 4 ? 1 : -1\n const swing = rotateX(-Math.sin(ph) * legSign * 0.5)\n quats[bone] = multiply(limpOf(spec.limp, bone === 4, ph), swing)\n quats[bone + 5] = rotateX(Math.max(0, Math.cos(ph + (legSign > 0 ? 0 : Math.PI))) * 0.85)\n }\n for (const bone of [2, 3]) {\n const side = bone === 2 ? -1 : 1\n const armSwing = Math.sin(ph) * side\n const forward = (1 - raise) * (ARM_FORWARD[0] + armSwing * 0.3) + raise * (ARM_FORWARD[1] + armSwing * 0.18)\n const arm = multiply(rotateX(forward), rotateZ(side * 0.08))\n quats[bone] = spec.stagger ? multiply(rotateX(STAGGER_ARM + 0.25 * Math.sin(ph)), arm) : arm\n quats[bone + 5] = rotateX((1 - raise) * (-0.3 - Math.max(0, armSwing) * 0.3) + raise * -0.15)\n }\n quats[11] = rotateX(0.05)\n const bend = (spec.bendPulse ?? 0) * 0.22 * Math.max(0, Math.sin(ph * 0.5)) ** 2 + (spec.stagger ? 0.18 + 0.22 * Math.sin(2 * ph) : 0)\n const sway = (spec.sway ?? 0) * Math.sin(ph) + (spec.stagger ? 0.2 * Math.sin(ph) : 0)\n quats[0] = multiply(multiply(rotateX(bend), rotateZ(sway)), rotateX(LEAN_PART))\n return { quats, bounce: Math.abs(Math.sin(ph)) * 0.035 }\n}\n\n/** Samples the clips at 30 Hz into one table (the rows of every clip one after the other): pure, no GPU. */\nexport const bakeSegmentClips = (specs: readonly SegmentClipSpec[] = SEGMENT_CLIPS): SegmentClipSet => {\n if (specs.length > CLIP_LIMIT) throw new Error(`game-characters-three: a clip texture holds at most ${CLIP_LIMIT} clips`)\n const start: number[] = []\n let rows = 0\n for (const spec of specs) {\n start.push(rows)\n rows += spec.frames\n }\n const data = new Float32Array(rows * CLIP_TEXELS * 4)\n specs.forEach((spec, index) => {\n for (let step = 0; step < spec.frames; step++) {\n const { quats, bounce } = sampleBones(spec, step)\n const row = (start[index]! + step) * CLIP_TEXELS * 4\n quats.forEach((quat, bone) => {\n data.set(quat, row + bone * 8)\n data.set(bone === 0 ? [0, bounce, 0, 0] : [0, 0, 0, 0], row + bone * 8 + 4)\n })\n }\n })\n return { specs, start, frames: specs.map((spec) => spec.frames), cycles: specs.map((spec) => spec.cycles ?? 1), rows, data }\n}\n\n/** What a body material needs of the clips: the texture and the three tables, as shared uniforms. */\nexport type SegmentClipUniforms = {\n readonly uClips: { value: THREE_NS.DataTexture }\n readonly uClipStart: { value: number[] }\n readonly uClipFrames: { value: number[] }\n readonly uClipCycles: { value: number[] }\n}\n\nconst padded = (values: readonly number[], fill: number): number[] => Array.from({ length: CLIP_LIMIT }, (_, index) => values[index] ?? fill)\n\n/**\n * The clip texture (economy ladder, step 3): RGBA32F, `CLIP_TEXELS` (24) wide, one row per sampled step, `NearestFilter` with no mipmaps: float texels are not\n * filterable everywhere and a blend would mix neighbouring bones. The shader blends two rows itself.\n */\nexport const createSegmentClipUniforms = (three: Three, set: SegmentClipSet = bakeSegmentClips()): SegmentClipUniforms => {\n const texture = new three.DataTexture(set.data as Float32Array<ArrayBuffer>, CLIP_TEXELS, set.rows, three.RGBAFormat, three.FloatType)\n texture.minFilter = three.NearestFilter\n texture.magFilter = three.NearestFilter\n texture.generateMipmaps = false\n texture.needsUpdate = true\n return { uClips: { value: texture }, uClipStart: { value: padded(set.start, 0) }, uClipFrames: { value: padded(set.frames, 1) }, uClipCycles: { value: padded(set.cycles, 1) } }\n}\n\n/** The index of a clip by id (the crowd picks its family by name). */\nexport const clipIndexOf = (set: SegmentClipSet, id: string): number => {\n const index = set.specs.findIndex((spec) => spec.id === id)\n if (index < 0) throw new Error(`game-characters-three: no clip \"${id}\"`)\n return index\n}\n","import { createRng } from '@adatechnology/game-characters'\n\nimport { EXTRAS } from '../rich/accessories/extras'\nimport { HATS } from '../rich/accessories/hats'\nimport { createPersonKit } from '../rich/person-kit'\nimport type { Three, THREE_NS } from '../three'\n\nimport { ACCESSORY_BIT } from './identity-layout'\n\nexport type AccessoryAttach = 'head' | 'torso'\n\n/** One accessory drawn by the kit's own survivor builder: a hat of `HATS` (`hat`) or a piece of gear of `EXTRAS` (`extra`), in one colour. */\nexport type KitAccessory = {\n readonly id: string\n /** The bit of `iD.y` that says a body carries it (`ACCESSORY_BIT`). */\n readonly bit: number\n readonly attach: AccessoryAttach\n readonly hat?: string\n readonly extra?: string\n readonly color: number\n}\n\n/** The four accessory batches of the kit: a cap, a helmet, a backpack and a hood. */\nexport const KIT_ACCESSORIES: readonly KitAccessory[] = [\n { id: 'cap', bit: ACCESSORY_BIT.CAP, attach: 'head', hat: 'cap', color: 0x2f4a6a },\n { id: 'helmet', bit: ACCESSORY_BIT.HELMET, attach: 'head', hat: 'helmet', color: 0x4a5238 },\n { id: 'backpack', bit: ACCESSORY_BIT.BACKPACK, attach: 'torso', extra: 'backpack', color: 0x6a4a2a },\n { id: 'hood', bit: ACCESSORY_BIT.EXTRA, attach: 'head', extra: 'hood', color: 0x3a3a40 },\n]\n\n/** Where the survivor builder puts the head and the torso (its own frame): the accessory is normalised against these. */\nconst HEAD_REFERENCE = { center: [0, 1.8, 0], height: 0.363, pivot: [0, 1.64, 0] } as const\nconst TORSO_REFERENCE = { center: [0, 1.23, 0], height: 0.74, pivot: [0, 0.9, 0] } as const\nconst ATTACH_BONE: Readonly<Record<AccessoryAttach, number>> = { head: 1, torso: 0 }\nconst MATERIAL_OWN_COLOR = 6\n\ntype Vec3 = readonly [number, number, number]\n\n/**\n * The accessory geometry in a unit frame (the reference head or torso at the origin, one unit tall), tagged for the body shader: `bone`, `vcol` (own colour),\n * `refPivot` and `ppivot`. A batch moves and scales it per variant with `iAcc` (`accessoryPlacement`): baked once, never per variant.\n */\nexport const buildKitAccessory = (host: Three, accessory: KitAccessory): THREE_NS.BufferGeometry => {\n const kit = createPersonKit(host, { random: createRng(77), createCanvas: () => { throw new Error('game-characters-three: an accessory needs no canvas') } })\n const { THREE, PI, Bx, add, cmat, cap } = kit\n const group = new THREE.Group()\n const color = cmat(accessory.color, undefined)\n if (accessory.hat) HATS.find((hat) => hat.kinds.includes(accessory.hat as string))?.apply({ THREE, PI, Hd: group, add, Bx, cmat, cap, c: color, k: accessory.hat, sp: { hat: {} } } as never)\n if (accessory.extra) EXTRAS[accessory.extra]?.({ THREE, PI, U: group, Hd: group, root: group, add, Bx, cmat, m: color, k: accessory.extra } as never)\n group.updateMatrixWorld(true)\n const reference = accessory.attach === 'head' ? HEAD_REFERENCE : TORSO_REFERENCE\n const parts: THREE_NS.BufferGeometry[] = []\n group.traverse((object) => {\n const mesh = object as THREE_NS.Mesh\n if (!mesh.isMesh) return\n const geometry = mesh.geometry.clone()\n geometry.applyMatrix4(mesh.matrixWorld)\n const source = geometry.index ? geometry.toNonIndexed() : geometry\n const paint = (mesh.material as THREE_NS.MeshStandardMaterial).color\n parts.push(tag(host, source, { reference, bone: ATTACH_BONE[accessory.attach], paint: [paint.r, paint.g, paint.b] }))\n })\n return merge(host, parts)\n}\n\nconst tag = (host: Three, source: THREE_NS.BufferGeometry, { reference, bone, paint }: { readonly reference: typeof HEAD_REFERENCE | typeof TORSO_REFERENCE; readonly bone: number; readonly paint: Vec3 }): THREE_NS.BufferGeometry => {\n const position = source.attributes.position as THREE_NS.BufferAttribute\n const normal = source.attributes.normal as THREE_NS.BufferAttribute\n const count = position.count\n const unit = new Float32Array(count * 3)\n const pivot = new Float32Array(count * 3)\n const colors = new Float32Array(count * 4)\n const bones = new Float32Array(count).fill(bone)\n const anchor = reference.pivot.map((value, axis) => (value - reference.center[axis]!) / reference.height)\n for (let index = 0; index < count; index++) {\n unit[index * 3] = (position.getX(index) - reference.center[0]) / reference.height\n unit[index * 3 + 1] = (position.getY(index) - reference.center[1]) / reference.height\n unit[index * 3 + 2] = (position.getZ(index) - reference.center[2]) / reference.height\n pivot.set(anchor, index * 3)\n colors.set([paint[0], paint[1], paint[2], MATERIAL_OWN_COLOR], index * 4)\n }\n const geometry = new host.BufferGeometry()\n geometry.setAttribute('position', new host.BufferAttribute(unit, 3))\n geometry.setAttribute('normal', new host.BufferAttribute(Float32Array.from(normal.array), 3))\n geometry.setAttribute('bone', new host.BufferAttribute(bones, 1))\n geometry.setAttribute('vcol', new host.BufferAttribute(colors, 4))\n geometry.setAttribute('refPivot', new host.BufferAttribute(pivot, 3))\n geometry.setAttribute('ppivot', new host.BufferAttribute(new Float32Array(count * 3), 3))\n return geometry\n}\n\nconst MERGED: readonly (readonly [string, number])[] = [['position', 3], ['normal', 3], ['bone', 1], ['vcol', 4], ['refPivot', 3], ['ppivot', 3]]\n\nconst merge = (host: Three, parts: readonly THREE_NS.BufferGeometry[]): THREE_NS.BufferGeometry => {\n const total = parts.reduce((sum, part) => sum + part.attributes.position!.count, 0)\n const merged = new host.BufferGeometry()\n for (const [name, size] of MERGED) {\n const array = new Float32Array(total * size)\n let offset = 0\n for (const part of parts) {\n array.set(part.attributes[name]!.array as Float32Array, offset)\n offset += part.attributes[name]!.array.length\n }\n merged.setAttribute(name, new host.BufferAttribute(array, size))\n }\n return merged\n}\n\n/** Materials of the bone's vertices that count for the placement: a baked body marks skin, hair and trousers as one own-colour material (6), only the eyes and the shirt apart. */\nconst EYE_MATERIAL = 3\nconst HIDDEN_PLACEMENT = [0, 0, 0, 0] as const\n\n/**\n * The `iAcc` of a baked body for an accessory: where the accessory goes (the centre of the head, or of the torso) and how big (its height), read from the variant's\n * own geometry, so the same accessory sits right on every one of the 20 variants. The head is the bone-1 vertices without the eyes, the torso the bone-0 ones;\n * a body without them gets a zero scale, so the accessory is not drawn instead of showing up unscaled at the feet.\n */\nexport const accessoryPlacement = (body: THREE_NS.BufferGeometry, attach: AccessoryAttach): readonly [number, number, number, number] => {\n const position = body.attributes.position as THREE_NS.BufferAttribute\n const bone = body.attributes.bone as THREE_NS.BufferAttribute\n const paint = body.attributes.vcol as THREE_NS.BufferAttribute\n const wanted = ATTACH_BONE[attach]\n const min = [Infinity, Infinity, Infinity]\n const max = [-Infinity, -Infinity, -Infinity]\n for (let index = 0; index < position.count; index++) {\n if (bone.getX(index) !== wanted || paint.getW(index) === EYE_MATERIAL) continue\n for (let axis = 0; axis < 3; axis++) {\n const value = axis === 0 ? position.getX(index) : axis === 1 ? position.getY(index) : position.getZ(index)\n if (value < min[axis]!) min[axis] = value\n if (value > max[axis]!) max[axis] = value\n }\n }\n if (!Number.isFinite(min[0])) return HIDDEN_PLACEMENT\n return [(min[0]! + max[0]!) / 2, (min[1]! + max[1]!) / 2, (min[2]! + max[2]!) / 2, max[1]! - min[1]!]\n}\n","import type { Three, THREE_NS } from '../three'\n\nimport { TROUSER_PALETTE, glslColor } from './identity-layout'\nimport { IMPOSTOR_ANGLES, IMPOSTOR_BONE_SCALE, IMPOSTOR_FRAMES, IMPOSTOR_MATERIAL_SCALE } from './impostor-atlas'\nimport type { ImpostorAtlas } from './impostor-atlas'\n\nexport type ImpostorBatchOptions = {\n /** Instances the batch holds. */\n readonly max: number\n /** The light the baked shade is multiplied by (the impostor is not lit by the scene; default 0.85 grey). */\n readonly light?: { readonly r: number; readonly g: number; readonly b: number }\n}\n\n/** One far body: the same `iA`, `iC` and shirt as the near body, the scale of its variant, its silhouette (the atlas block) and the ground height. */\nexport type ImpostorInstance = {\n readonly a: readonly [number, number, number, number]\n /** Height and width scale (the near body's `b[0]` and `b[1]`). */\n readonly scale: readonly [number, number]\n readonly silhouette: number\n readonly y?: number\n readonly c: readonly [number, number, number, number]\n readonly color: { readonly r: number; readonly g: number; readonly b: number }\n readonly d?: readonly [number, number, number, number]\n}\n\nexport type ImpostorBatch = {\n readonly mesh: THREE_NS.Mesh & { count: number }\n readonly material: THREE_NS.ShaderMaterial\n readonly count: number\n begin(): void\n push(instance: ImpostorInstance): void\n end(): void\n}\n\nconst ATTRIBUTES: readonly (readonly [string, number])[] = [['iA', 4], ['iB', 4], ['iC', 4], ['iCol', 3], ['iD', 4]]\nconst TROUSERS = `const vec3 TROUSERS[16] = vec3[16](${TROUSER_PALETTE.map(glslColor).join(',')});`\n\nconst VERTEX = `\n attribute vec4 iA; attribute vec4 iB; attribute vec4 iC; attribute vec3 iCol; attribute vec4 iD;\n uniform vec4 uBox[SILHOUETTES]; uniform vec2 uCell; uniform vec2 uGrid;\n varying vec2 vUv; varying vec4 vC; varying vec3 vShirt; varying float vTrousers;\n void main(){\n vec3 toCam = vec3(cameraPosition.x - iA.x, 0., cameraPosition.z - iA.y);\n toCam /= max(length(toCam), 0.001);\n vec3 right = vec3(toCam.z, 0., -toCam.x);\n float c = cos(iA.z), s = sin(iA.z);\n vec3 local = vec3(c*toCam.x - s*toCam.z, 0., s*toCam.x + c*toCam.z);\n float angle = mod(floor(atan(local.x, local.z)/6.2831853*ANGLES + 0.5), ANGLES);\n float frame = floor(fract(iA.w)*FRAMES);\n float cell = (iB.z*FRAMES + frame)*ANGLES + angle;\n vec4 box = uBox[int(iB.z)];\n vec2 inset = 0.5/uCell;\n vec2 within = mix(inset, 1. - inset, position.xy);\n vUv = vec2(mod(cell, uGrid.x) + within.x, floor(cell/uGrid.x) + within.y)/uGrid;\n vec3 world = vec3(iA.x, iB.w, iA.y) + right*((position.x - 0.5)*2.*box.x*iB.y) + vec3(0., box.y + position.y*box.z, 0.)*iB.x;\n vC = iC; vShirt = iCol; vTrousers = mod(iD.y, 16.);\n gl_Position = projectionMatrix*viewMatrix*vec4(world, 1.);\n }\n`\n\nconst FRAGMENT = `\n uniform sampler2D uAtlas; uniform sampler2D uColors; uniform vec3 uLight;\n varying vec2 vUv; varying vec4 vC; varying vec3 vShirt; varying float vTrousers;\n ${TROUSERS}\n bool missing(float bit){ return mod(floor(vC.x/bit), 2.) > 0.5; }\n void main(){\n vec4 texel = texture2D(uAtlas, vUv);\n if (texel.a < 0.5) discard;\n float bone = floor(texel.r*255./${IMPOSTOR_BONE_SCALE}.0 + 0.5);\n float material = floor(texel.g*255./${IMPOSTOR_MATERIAL_SCALE}.0 + 0.5);\n if ((bone==1.||bone==6.||bone==11.) && missing(1.)) discard;\n if (bone==11. && missing(512.)) discard;\n if ((bone==2.||bone==7.) && missing(2.)) discard; if ((bone==3.||bone==8.) && missing(4.)) discard;\n if ((bone==4.||bone==9.) && missing(8.)) discard; if ((bone==5.||bone==10.) && missing(16.)) discard;\n if (bone==7. && missing(32.)) discard; if (bone==8. && missing(64.)) discard;\n if (bone==9. && missing(128.)) discard; if (bone==10. && missing(256.)) discard;\n vec3 skin = mix(vec3(0.93,0.74,0.6), vec3(0.42,0.27,0.18), vC.w);\n skin = mix(skin, vec3(0.435,0.478,0.36), vC.y);\n vec3 baked = texture2D(uColors, vUv).rgb; baked *= baked;\n vec3 tint = material==1. ? vShirt : material==2. ? mix(baked, TROUSERS[int(vTrousers)], 0.75) : material==3. ? vec3(0.08) : baked;\n gl_FragColor = vec4(tint*texel.b*uLight, 1.);\n #include <colorspace_fragment>\n }\n`\n\n/** The far bodies as one draw call: a standing quad per body that picks its cell of the atlas by the view angle and the walk phase, tinted per instance. */\nexport const createImpostorBatch = (three: Three, atlas: ImpostorAtlas, { max, light = { r: 0.85, g: 0.85, b: 0.85 } }: ImpostorBatchOptions): ImpostorBatch => {\n const geometry = new three.InstancedBufferGeometry()\n geometry.setAttribute('position', new three.Float32BufferAttribute([0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0], 3))\n geometry.setIndex([0, 1, 2, 0, 2, 3])\n const attributes: Record<string, THREE_NS.InstancedBufferAttribute> = {}\n for (const [name, size] of ATTRIBUTES) {\n const attribute = new three.InstancedBufferAttribute(new Float32Array(max * size), size)\n attribute.setUsage(three.DynamicDrawUsage)\n geometry.setAttribute(name, attribute)\n attributes[name] = attribute\n }\n geometry.instanceCount = 0\n const material = new three.ShaderMaterial({\n defines: { SILHOUETTES: Math.max(1, atlas.silhouettes), ANGLES: `${IMPOSTOR_ANGLES}.0`, FRAMES: `${IMPOSTOR_FRAMES}.0` },\n uniforms: {\n uAtlas: { value: atlas.texture },\n uColors: { value: atlas.colorTexture },\n uLight: { value: new three.Vector3(light.r, light.g, light.b) },\n uCell: { value: new three.Vector2(atlas.cellWidth, atlas.cellHeight) },\n uGrid: { value: new three.Vector2(atlas.columns, atlas.rows) },\n uBox: { value: atlas.boxes.map((box) => new three.Vector4(box.halfWidth, box.bottom, box.height, 0)) },\n },\n vertexShader: VERTEX,\n fragmentShader: FRAGMENT,\n side: three.DoubleSide,\n })\n material.customProgramCacheKey = () => '|impostor'\n const mesh = new three.Mesh(geometry, material) as unknown as THREE_NS.Mesh & { count: number }\n Object.defineProperty(mesh, 'count', { get: () => geometry.instanceCount, set: (value: number) => (geometry.instanceCount = value) })\n mesh.frustumCulled = false\n mesh.name = 'impostors'\n let count = 0\n return {\n mesh,\n material,\n get count() {\n return count\n },\n begin() {\n count = 0\n },\n push({ a, scale, silhouette, y = 0, c, color, d }) {\n if (count >= max) return\n const index = count++\n attributes.iA!.array.set(a, index * 4)\n attributes.iB!.array.set([scale[0], scale[1], silhouette, y], index * 4)\n attributes.iC!.array.set(c, index * 4)\n attributes.iCol!.array.set([color.r, color.g, color.b], index * 3)\n attributes.iD!.array.set(d ?? [0, 0, 0, 0], index * 4)\n },\n end() {\n geometry.instanceCount = count\n // three uploads every attribute flagged, drawn or not: an empty batch would send one empty upload per attribute each frame\n if (count === 0) return\n for (const attribute of Object.values(attributes)) {\n attribute.clearUpdateRanges()\n attribute.addUpdateRange(0, count * attribute.itemSize)\n attribute.needsUpdate = true\n }\n },\n }\n}\n","import type { Three, THREE_NS } from '../three'\n\nexport type BlobShadowOptions = {\n /** Shadows the batch can hold. */\n readonly max: number\n /** Radius in metres of a body of height 1 (default 0.55). */\n readonly radius?: number\n /** The darkness at the centre (default 0.42). */\n readonly opacity?: number\n}\n\nexport type BlobShadowBatch = {\n readonly mesh: THREE_NS.Mesh & { count: number }\n readonly count: number\n begin(): void\n /** One shadow under a body at `x`, `z` on the ground height `y`, for a body `height` metres tall. */\n push(x: number, y: number, z: number, height: number): void\n end(): void\n}\n\nconst BLOB_LIFT = 0.03\n\n/**\n * The shadow of a body that is too far for a real one (economy ladder, step 1): one dark disc per body on the ground, a single draw call.\n * No depth write and no shadow map: it costs a quad per body.\n */\nexport const createBlobShadowBatch = (three: Three, { max, radius = 0.55, opacity = 0.42 }: BlobShadowOptions): BlobShadowBatch => {\n const geometry = new three.InstancedBufferGeometry()\n geometry.setAttribute('position', new three.Float32BufferAttribute([-1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1], 3))\n geometry.setAttribute('uv', new three.Float32BufferAttribute([-1, -1, 1, -1, 1, 1, -1, 1], 2))\n geometry.setIndex([0, 2, 1, 0, 3, 2])\n const placement = new three.InstancedBufferAttribute(new Float32Array(max * 4), 4)\n placement.setUsage(three.DynamicDrawUsage)\n geometry.setAttribute('iBlob', placement)\n geometry.instanceCount = 0\n const material = new three.ShaderMaterial({\n transparent: true,\n depthWrite: false,\n polygonOffset: true,\n polygonOffsetFactor: -2,\n polygonOffsetUnits: -2,\n uniforms: { uOpacity: { value: opacity } },\n vertexShader: `attribute vec4 iBlob; varying vec2 vUv;\n void main(){ vUv = uv; vec3 p = position*iBlob.w + iBlob.xyz; gl_Position = projectionMatrix*viewMatrix*vec4(p, 1.); }`,\n fragmentShader: `uniform float uOpacity; varying vec2 vUv;\n void main(){ float d = dot(vUv, vUv); if (d > 1.) discard; gl_FragColor = vec4(0., 0., 0., uOpacity*(1. - smoothstep(0.15, 1., d))); }`,\n })\n const mesh = new three.Mesh(geometry, material) as unknown as THREE_NS.Mesh & { count: number }\n Object.defineProperty(mesh, 'count', { get: () => geometry.instanceCount, set: (value: number) => (geometry.instanceCount = value) })\n mesh.frustumCulled = false\n mesh.renderOrder = -1\n mesh.name = 'blob-shadows'\n let count = 0\n return {\n mesh,\n get count() {\n return count\n },\n begin() {\n count = 0\n },\n push(x, y, z, height) {\n if (count >= max) return\n placement.array.set([x, y + BLOB_LIFT, z, radius * height], count++ * 4)\n },\n end() {\n geometry.instanceCount = count\n // three uploads every attribute flagged, drawn or not: an empty batch would send one empty upload per attribute each frame\n if (count === 0) return\n placement.clearUpdateRanges()\n placement.addUpdateRange(0, count * 4)\n placement.needsUpdate = true\n },\n }\n}\n","import { shapeGeometries } from '@adatechnology/game-shapes-three'\nimport type { Three, THREE_NS } from '../three'\n\nconst GRAVITY = 9.8\nconst FLOOR_Y = 0.07\nconst BOUNCE = -0.3\nconst FRICTION = 0.6\nconst SPIN_DAMPING = 0.5\nconst REST_SPEED = 0.4\nconst LEG_COLOR = 0x2c3340\n\n/** Where a limb comes from: arms leave at chest height with the sleeve's colour, legs low and long with the trousers'. */\nexport type LimbLaunch = {\n readonly x: number\n readonly z: number\n readonly kind: 'arm' | 'leg'\n /** The sleeve colour of the owner (arms). */\n readonly color: number\n /** The blood of the owner's age: colour, dried colour and whether it bleeds at all (the oldest dead do not: they spill dust). */\n readonly blood: { readonly color: number; readonly dried: number; readonly bleeds: boolean }\n}\n\nexport type FlyingLimb = {\n x: number\n y: number\n z: number\n vx: number\n vy: number\n vz: number\n rx: number\n rz: number\n w: number\n t: number\n rest: boolean\n len: number\n col: number\n cor: number\n seco: number\n splat: boolean\n}\n\n/** The fluids bridge: where a limb bleeds when it leaves and where it splats when it lands. The host decides what that draws. */\nexport type LimbEffects = {\n onLaunch?(limb: FlyingLimb, kind: 'arm' | 'leg'): void\n onSplat?(splat: { readonly x: number; readonly z: number; readonly radius: number; readonly rotation: number; readonly color: number; readonly dried: number }): void\n}\n\nexport type FlyingLimbsOptions = {\n /** Pieces alive at once (the game's 40 per player); the oldest is reused. */\n readonly max?: number\n readonly random: () => number\n readonly effects?: LimbEffects\n}\n\nexport type FlyingLimbs = {\n readonly mesh: THREE_NS.InstancedMesh\n readonly limbs: readonly FlyingLimb[]\n launch(launch: LimbLaunch): FlyingLimb\n update(dt: number): void\n}\n\n/** Torn-off pieces that fly, bounce and stay on the ground, as one instanced mesh of capsules (G 67953 `fxLimb`, 68040 update). */\nexport const createFlyingLimbs = (host: Three, { max = 40, random, effects = {} }: FlyingLimbsOptions): FlyingLimbs => {\n const three = shapeGeometries(host)\n const limbs: FlyingLimb[] = []\n const mesh = new three.InstancedMesh(new three.CapsuleGeometry(0.065, 0.32, 2, 6), new three.MeshLambertMaterial({ color: 0xffffff }), max)\n mesh.count = 0\n mesh.castShadow = true\n mesh.setColorAt(0, new three.Color())\n const matrix = new three.Matrix4()\n const quaternion = new three.Quaternion()\n const scale = new three.Vector3()\n const position = new three.Vector3()\n const euler = new three.Euler()\n const color = new three.Color()\n return {\n mesh,\n limbs,\n launch({ x, z, kind, color: sleeve, blood }) {\n const isLeg = kind === 'leg'\n const limb = (limbs.length < max ? {} : limbs.shift()) as FlyingLimb\n Object.assign(limb, {\n x,\n y: isLeg ? 0.5 : 1.2,\n z,\n vx: (random() - 0.5) * 3,\n vy: 2 + random() * 2,\n vz: (random() - 0.5) * 3,\n rx: random() * 6,\n rz: random() * 6,\n w: (random() - 0.5) * 10,\n t: 0,\n rest: false,\n len: isLeg ? 1.3 : 1,\n col: isLeg ? LEG_COLOR : sleeve,\n })\n limbs.push(limb)\n limb.cor = blood.color\n limb.seco = blood.dried\n limb.splat = !blood.bleeds\n effects.onLaunch?.(limb, kind)\n return limb\n },\n update(dt) {\n limbs.forEach((limb, index) => {\n if (!limb.rest) {\n limb.t += dt\n limb.vy -= GRAVITY * dt\n limb.x += limb.vx * dt\n limb.y += limb.vy * dt\n limb.z += limb.vz * dt\n limb.rx += limb.w * dt\n if (limb.y < FLOOR_Y) {\n limb.y = FLOOR_Y\n limb.vy *= BOUNCE\n limb.vx *= FRICTION\n limb.vz *= FRICTION\n limb.w *= SPIN_DAMPING\n if (!limb.splat) {\n limb.splat = true\n effects.onSplat?.({ x: limb.x, z: limb.z, radius: 0.2 + random() * 0.2, rotation: random() * 6.28, color: limb.cor, dried: limb.seco })\n }\n if (Math.abs(limb.vy) < REST_SPEED) {\n limb.rest = true\n limb.rx = Math.PI / 2\n }\n }\n }\n matrix.compose(position.set(limb.x, limb.y, limb.z), quaternion.setFromEuler(euler.set(limb.rx, limb.rz, 0)), scale.set(1, limb.len, 1))\n mesh.setMatrixAt(index, matrix)\n mesh.setColorAt(index, color.set(limb.col))\n })\n mesh.count = limbs.length\n mesh.instanceMatrix.needsUpdate = true\n if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true\n },\n }\n}\n","import {\n POSE_CLIPS,\n clipEventsBetween,\n createPoseClipRegistry,\n createRng,\n filterPoseChannels,\n samplePoseClip,\n walkCadence,\n stepCascade,\n walkGait,\n} from '@adatechnology/game-characters'\nimport type { GaitProfile, PoseClip, PoseClipEvent, PoseClipRegistry } from '@adatechnology/game-characters'\nimport type { HandTargets } from '@adatechnology/game-contracts'\n\nimport preset from '../presets/player-avatar.json'\nimport { buildHand } from '../rich/accessories/hands'\nimport { createBestBuilder } from '../rich/best-builder'\nimport { createRigAnimator } from '../rich/animator'\nimport type { PoseTargets, RichRig } from '../rich/animator'\nimport type { Three, THREE_NS } from '../three'\nimport { createArmReach, type ReachView } from './arm-reach'\nimport { createHeadHider } from './head-hiding'\nimport type { AvatarViewMode } from './head-hiding'\n\nconst TWO_PI = Math.PI * 2\nconst MAX_GAIT = 1.4\nconst CLIP_BLEND = 0.12\nconst CLIP_CASCADE = 5\nconst FALL_SECONDS = 0.3\n/** The builder's eyes in the head's own frame (best-builder: eyes at y 1.815, z about 0.16). */\nconst BUILDER_EYE = [0, 1.815, 0.16] as const\nconst EYE_OFFSET = [0, -0.068, 0] as const // brings the measured standing eye (1.768 m) to about 1.70 m\nconst EYE_BOB = 0.5\n\n// Constants carried from the team game's GPU pose code, `BODY_CHUNK` (src/instanced/body-chunk.ts), whose line numbers are quoted below.\nconst HIP_HEIGHT = 0.95 // :68, :74 the trunk pivot\nconst WALK_ARM = 0.28 // arms swing naturally beside the hips, staying below the waist\nconst WALK_BOB = 0.035 // :71 `abs(sin(ph))*0.035*gait`\nconst WALK_LEAN = 0.04 // :64 `0.04*gait`\nconst RUN_LEAN = 0.16\nconst RUN_BOB = 0.05\nconst REST_ARM_Z = 0.18 // outward carrying angle: clears hips and pelvis comfortably\nconst CROUCH = { thigh: -0.95, thighWalk: 0.3, shin: 1.9, lean: 0.25, drop: -0.35 } // :29, :66, :71\nconst AIMED = { shoulder: -1.42, perAim: 0.85, swing: 0.02, zRight: -0.54, zLeft: 0.36, elbowRight: -0.04, elbowLeft: -0.12 } // :45, :47\nconst SIT = { thigh: -1.5, lean: -0.08, arm: -0.45, armZ: 0.12, elbow: -0.75 }\nconst LIE = { knee: 0.08, armZ: 0.12, elbow: -0.1 }\nconst DOWN = { thighWalk: 0.5, shinSwing: 0.85, shinBend: 1.3, armHigh: -2.8, armLow: -0.35, armWave: 0.3, armZ: 0.5, armZWave: 0.3, tilt: 1.5, roll: 0.3, hipY: 0.16, hipZ: 0.6, hipZFlip: 1.2 } // :29-:47, :74\n/** `playerHand()`: the elbow-to-hand offset of the weapon hand (the weapon hand is the puppet's right, at -x). */\n/** A hand on a handle: the shoulder over the feet and the length of the arm to the palm, metres. */\nconst DOOR_SHOULDER = 1.42\nconst DOOR_ARM = 0.62\nconst HAND_OFFSET = { x: 0, y: -0.33, z: 0.04 }\n\nexport type PlayerAvatarSpec = Record<string, unknown>\n\nexport type PlayerAvatarOptions = {\n /** The body spec for the rich builder (`createBestBuilder.build`). Default: the team game's player (`player-avatar.json`). Merged over the default. */\n readonly spec?: PlayerAvatarSpec\n /** Shirt colour, 0xRRGGBB. Default the team game's `PLAYER_COR`. */\n readonly shirtColor?: number\n /** The clips `play(id)` finds. Default: a registry with `POSE_CLIPS`. */\n readonly clips?: PoseClipRegistry\n /** Seconds to blend a clip in and out. Default 0.12. */\n readonly blend?: number\n /** Seconds the body takes to go down (the shader's `fk` smoothstep). 0 is instant. Default 0.3. */\n readonly fallSeconds?: number\n /** Smooth the joints with the Bestiário cascade (default true). */\n readonly cascade?: boolean\n /**\n * How many times faster the cascade follows while a clip that does not loop plays: a strike is over in a third of a second, and at the walk's pace the joints would\n * still be on their way when it ends (a punch that never reaches the shoulder). 1 keeps the walk's pace. Default 5.\n */\n readonly clipCascade?: number\n /** Where the eye sits against the builder's eye point, in the head's frame (so it follows the head's scale and turn). Default [0, -0.068, 0]: about 1.70 m standing. */\n readonly eyeOffset?: readonly [number, number, number]\n /** How much of the walking and running bob of the body reaches the eye: 0 none, 1 all of it. Default 0.5. */\n readonly eyeBob?: number\n}\n\nexport type AvatarEvent = PoseClipEvent & { clip: string }\n\nexport type AvatarItemUsePose = {\n readonly id: string\n readonly position: readonly [number, number, number]\n readonly rotation: readonly [number, number, number]\n /** How closed the other hand is (0 open to 1 closed) when it works on the item, as a hand turning a cap off opens between strokes; the room brings it there with `reach`. */\n readonly gripL?: number\n}\n\nexport type AvatarUpdate = {\n /** Ground speed, m/s. Ties cadence and swing to the ground (the game's `walkCad` and `walkGait`). */\n speed?: number\n /** Accepted for the game's state; the gait depends on the speed alone, as in the team game. */\n running?: boolean\n crouch?: boolean\n down?: boolean\n /**\n * Which way a body going `down` falls: true face down (pushed from behind, tripped), false on its back (pushed from the front, a blast it faced).\n * Left out, the game's own pick by the phase of the stride.\n */\n fallForward?: boolean\n /** Weapon in hand: both arms follow the aim (the game's arm code). Default false. */\n armed?: boolean\n /** The camera pitch the game's `playerArmCode()` reads (`view.pitch`). */\n pitch?: number\n /** Leg yaw toward the step while armed (the game's `P.hip`, radians). */\n hip?: number\n /** Whether the player is carrying an item in the right hand. */\n holding?: boolean\n /** Active scripted item use (`drink`, `sip`, `chug`, `pour`, `open`, `close`, `tilt`). */\n itemUse?: AvatarItemUsePose | null\n /** Hands on a piece of furniture: `grip` closes on it with `progress`, `push` walks with it, `strain` strains against what does not give. */\n push?: { readonly phase: 'grip' | 'push' | 'strain'; readonly progress: number } | null\n /** On a seat: `sit` folds the legs under hips `hip` metres above the feet, `lie` lays the body face up with the pelvis there, the head behind the facing. */\n seat?: { readonly pose: 'sit' | 'lie'; readonly hip: number } | null\n /**\n * A hand on a door, lid or drawer: `reach` to the handle, `swing` with it (`pull` toward the body or pushed away), `release` back, `rattle` on a locked one.\n * `height` is the hand over the feet, metres (a fridge handle, a car door, a low drawer).\n */\n door?: { readonly phase: 'reach' | 'swing' | 'release' | 'rattle'; readonly progress: number; readonly height: number; readonly pull: boolean } | null\n}\n\nexport type PlayPoseOptions = {\n onEvent?: (event: AvatarEvent) => void\n /** Overrides the avatar's blend for this clip. */\n blend?: number\n}\n\n/** How the first-person view draws the body: `arms` hides the body's arms from the eye too, for a view that draws arms of its own (the first-person arms of the viewmodel). */\nexport type AvatarViewOptions = { readonly arms?: boolean }\n\n/** The colours the body was drawn with, for whatever has to match it (the first-person arms): skin, shirt, trousers and shoes as 0xRRGGBB, and whether the sleeves cover the forearms. */\nexport type PlayerAvatarColors = { skin: number; shirt: number; trousers: number; shoes: number; longSleeves: boolean }\n\nexport type PlayerAvatar = {\n root: THREE_NS.Object3D\n rig: RichRig\n /** What the body wears, read from the body itself. */\n readonly colors: PlayerAvatarColors\n /** The three.js namespace the body was made with, so what is made to fit it (the first-person arms) uses the same one. */\n readonly three: Three\n update(dt: number, state?: AvatarUpdate): void\n /**\n * The world position of the eyes, as `update` left them: sampled at its end, before any `reach()` (which turns the chest and would swing the head), and kept in the\n * body's own frame so it stays right when the host moves `root` afterwards. With `out` it fills that vector instead of making one.\n */\n eye(out?: THREE_NS.Vector3): THREE_NS.Vector3\n /** In 'first' with a camera, the head and neck are not drawn for that camera only (shadows, mirrors and every other camera still see them); 'third' draws them. */\n setView(mode: AvatarViewMode, camera: THREE_NS.Object3D | null, options?: AvatarViewOptions): void\n play(clip: string | PoseClip, options?: PlayPoseOptions): void\n stop(): void\n readonly playing: string | null\n /** A socket at the hand: 'R' is the weapon hand (the puppet's right, at -x), 'L' the other one. */\n hand(side: 'R' | 'L'): THREE_NS.Object3D\n /** The joint of a shoulder ('R' the weapon side, at -x): where a long gun's stock rests, just inside it. */\n shoulder(side: 'R' | 'L'): THREE_NS.Object3D\n /**\n * Brings the hands to where the tool in them asks (`HandTargets`, world space) after `update`: shoulder, elbow and wrist each bend inside the human range, the chest turns and the shoulder\n * blade slides toward a hand out of reach. Null, a strike playing or the body going down leave the arms as `update` posed them. Call it after the tool is placed and the root moved.\n * `view` (given on each call, as the camera moves) is for the body seen from its own eyes: the elbows keep their bend and the hands stay out of walls; without it nothing changes.\n */\n reach(targets: HandTargets | null, view?: ReachView | null): void\n on(type: 'event', listener: (event: AvatarEvent) => void): () => void\n dispose(): void\n}\n\nconst hexOf = (value: unknown): number => (typeof value === 'string' ? Number.parseInt(value, 16) : (value as number))\nconst clamp = (value: number, min: number, max: number): number => Math.min(max, Math.max(min, value))\nconst fract = (value: number): number => value - Math.floor(value)\n\ntype ClipRun = { clip: PoseClip; time: number; weight: number; target: 0 | 1; blend: number; onEvent?: (event: AvatarEvent) => void }\n\n/**\n * The player's body: the rich human of the Bestiário/Elenco, built with the team game's player spec (data, overridable), walking with the engine's gait tied\n * to the ground speed, with the crouch and the knock-down of the game's GPU pose code (`BODY_CHUNK`) and a pose-clip overlay (`play`).\n */\nexport const createPlayerAvatar = (THREE: Three, options: PlayerAvatarOptions = {}): PlayerAvatar => {\n const pose = {\n armL: 0,\n armR: 0,\n elbL: -0.08,\n elbR: -0.08,\n lean: 0.04,\n headX: 0,\n headZ: 0,\n ...(preset.spec as { pose?: Record<string, number> }).pose,\n ...(options.spec?.pose as Record<string, number> | undefined),\n }\n const spec = { ...preset.spec, ...options.spec, pose } as Record<string, unknown>\n for (const key of ['skin', 'hair']) if (typeof spec[key] === 'string') spec[key] = hexOf(spec[key])\n const best = createBestBuilder(THREE, { types: [{ name: String(spec.type), eye: 0 }], random: createRng(Number(spec.seed ?? 1)) })\n const body = best.build(spec) as THREE_NS.Object3D\n best.topM()?.color.setHex(options.shirtColor ?? hexOf(preset.shirtColor)) // set by the build above\n const rig = body.userData.rig as RichRig\n\n // walk: the profile follows the speed (arm swing and bob are the shader's numbers times the stride)\n const profile: { -readonly [K in keyof GaitProfile]: GaitProfile[K] } = { f: 1.1, a: 0.28, k: 0.35, arm: WALK_ARM, bob: WALK_BOB }\n const animator = createRigAnimator({ gaits: { [rig.type]: profile } })\n const clips = options.clips ?? createPoseClipRegistry(POSE_CLIPS)\n const blendDefault = options.blend ?? CLIP_BLEND\n const fallSeconds = options.fallSeconds ?? FALL_SECONDS\n const smooth = options.cascade ?? true\n const clipCascade = options.clipCascade ?? CLIP_CASCADE\n const eyeBob = options.eyeBob ?? EYE_BOB\n const eyeOffset = options.eyeOffset ?? EYE_OFFSET\n\n const root = new THREE.Group()\n const tilt = new THREE.Group()\n tilt.add(body)\n root.add(tilt)\n const colorOf = (object: THREE_NS.Object3D | undefined): number | undefined => ((object as THREE_NS.Mesh | undefined)?.material as THREE_NS.MeshLambertMaterial | undefined)?.color?.getHex()\n const meshesOf = (node: THREE_NS.Object3D): THREE_NS.Mesh[] => node.children.filter((child) => (child as THREE_NS.Mesh).isMesh) as THREE_NS.Mesh[]\n // the trousers are the first mesh of the thigh, the shoe the flattened long ball on the shin, the sleeve (or the skin of a bare arm) the first mesh of the forearm\n const shirt = options.shirtColor ?? hexOf(preset.shirtColor)\n const shoe = meshesOf(rig.legs[0]!.kn as unknown as THREE_NS.Object3D).find((mesh) => mesh.scale.z > 1.5)\n const forearm = colorOf(meshesOf(rig.arms[1]!.el as unknown as THREE_NS.Object3D)[0])\n const colors: PlayerAvatarColors = {\n skin: Number(spec.skin),\n shirt,\n trousers: colorOf(meshesOf(rig.legs[0]!.g as unknown as THREE_NS.Object3D)[0]) ?? 0x2d3440,\n shoes: colorOf(shoe) ?? 0x1c1a1a,\n longSleeves: forearm === shirt,\n }\n const sockets = { R: new THREE.Object3D(), L: new THREE.Object3D() }\n // arms[0] is at +x (the puppet's left), arms[1] at -x: the weapon hand of the game (`playerHand`: shoulder at -x)\n const armOf = { R: rig.arms[1]!, L: rig.arms[0]! }\n for (const side of ['R', 'L'] as const) {\n sockets[side].name = `hand_${side}`\n sockets[side].position.set(HAND_OFFSET.x, HAND_OFFSET.y, HAND_OFFSET.z)\n ;(armOf[side].el as unknown as THREE_NS.Object3D).add(sockets[side])\n }\n\n // Replace the single flattened sphere hand of the zombie builder on the player body with the articulated palm, four two-jointed fingers and thumb (`buildHand` of Retratos do Vale)\n const addMesh = (parent: THREE_NS.Object3D, geometry: THREE_NS.BufferGeometry, material: THREE_NS.Material, x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0): THREE_NS.Mesh => {\n const mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(x, y, z)\n if (rx || ry || rz) mesh.rotation.set(rx, ry, rz)\n mesh.castShadow = true\n mesh.receiveShadow = true\n parent.add(mesh)\n return mesh\n }\n // the closure of an index finger fully pulled on a trigger, as the grip of a held tool closes the others\n const TRIGGER_CURL = 1.22\n type ThirdPersonHand = { side: 1 | -1; hg: THREE_NS.Group; fingers: THREE_NS.Object3D[]; th: THREE_NS.Object3D | null }\n const hands: ThirdPersonHand[] = []\n rig.arms.forEach((arm, index) => {\n const el = arm.el as unknown as THREE_NS.Object3D\n const side: 1 | -1 = index === 0 ? 1 : -1\n const oldHand = meshesOf(el).find((mesh) => Math.abs(mesh.position.y + 0.33) < 0.025)\n const handMaterial = (oldHand?.material as THREE_NS.Material | undefined) ?? new THREE.MeshLambertMaterial({ color: colors.skin })\n if (oldHand) {\n oldHand.geometry?.dispose()\n el.remove(oldHand)\n }\n const hg = new THREE.Group()\n hg.name = side > 0 ? 'hand_group_L' : 'hand_group_R'\n hg.position.set(side * 0.02, -0.3, 0.01)\n el.add(hg)\n const palm = addMesh(hg, new THREE.SphereGeometry(0.048, 14, 10), handMaterial, 0, -0.035, 0)\n palm.scale.set(0.6, 1.05, 1)\n const built = buildHand({ THREE, add: addMesh, hg, handM: handMaterial, s: side, detailed: true })\n hands.push({ side, hg, fingers: built.fingers as THREE_NS.Object3D[], th: built.th as THREE_NS.Object3D | null })\n })\n const armReach = createArmReach(THREE, rig, { R: hands.find((hand) => hand.side < 0)!.hg, L: hands.find((hand) => hand.side > 0)!.hg })\n const setHandGrip = (hand: ThirdPersonHand, grip: number, wristX = 0): void => {\n hand.fingers.forEach((finger, j) => {\n finger.rotation.z = -hand.side * grip * (j % 2 ? 1.1 : 0.9)\n })\n if (hand.th) hand.th.rotation.z = -hand.side * (0.32 + grip * 0.25)\n hand.hg.rotation.x = wristX\n }\n\n const eyeSocket = new THREE.Object3D()\n eyeSocket.name = 'eye'\n eyeSocket.position.set(BUILDER_EYE[0] + eyeOffset[0], BUILDER_EYE[1] + eyeOffset[1], BUILDER_EYE[2] + eyeOffset[2])\n ;(rig.headG as unknown as THREE_NS.Object3D).children[0]!.add(eyeSocket)\n const headHider = createHeadHider([rig.headG as unknown as THREE_NS.Object3D, ...(rig.neck ? [rig.neck as unknown as THREE_NS.Object3D] : [])])\n // the body's arms, from the shoulders: hidden from the eye when the view draws arms of its own (`AvatarViewOptions.arms`)\n const armsHider = createHeadHider(rig.arms.map((arm) => arm.g as unknown as THREE_NS.Object3D))\n const eyeLocal = new THREE.Vector3()\n let bob = 0 // the vertical bob the gait adds to the hips target, taken off the eye by `1 - eyeBob`\n let hipWithoutBob: number | null = null // the hips' cascade run again on the target with no bob, so the bob left after smoothing can be told apart\n\n const legRestX = rig.legs.map((leg) => leg.g.position.x)\n /** Measured once with the leg straight: how far below the trunk pivot the leg hangs from, the thigh, and the knee to the sole. */\n const legLengths = (() => {\n const thigh = rig.legs[0]!.g as unknown as THREE_NS.Object3D\n const shin = rig.legs[0]!.kn as unknown as THREE_NS.Object3D\n root.updateMatrixWorld(true)\n const hipY = thigh.getWorldPosition(new THREE.Vector3()).y\n const kneeY = shin.getWorldPosition(new THREE.Vector3()).y\n return { hipBelowTrunk: HIP_HEIGHT - hipY, thigh: hipY - kneeY, shin: kneeY - new THREE.Box3().setFromObject(shin).min.y }\n })()\n const legSide = (index: number): number => (index === 0 ? 1 : -1) // the shader's `legS`: +1 for the leg at -x (legs[0])\n let cycles = 0 // the game's `player.ph`: gait cycles\n let time = 0\n let fall = 0\n let run: ClipRun | null = null\n const listeners = new Set<(event: AvatarEvent) => void>()\n\n const emit = (event: AvatarEvent, onEvent?: (event: AvatarEvent) => void): void => {\n onEvent?.(event)\n for (const listener of listeners) listener(event)\n }\n\n const readPose = (): Record<string, number> => ({\n lean: rig.upper.rotation.x,\n twist: rig.upper.rotation.y,\n side: rig.upper.rotation.z,\n drop: rig.fig.position.y - rig.dropBase,\n headX: rig.headG.rotation.x,\n headY: rig.headG.rotation.y,\n headZ: rig.headG.rotation.z,\n armR: rig.arms[0]!.g.rotation.x,\n armL: rig.arms[1]!.g.rotation.x,\n elbR: rig.arms[0]!.el.rotation.x,\n elbL: rig.arms[1]!.el.rotation.x,\n armRz: rig.arms[0]!.g.rotation.z,\n armLz: rig.arms[1]!.g.rotation.z,\n legL: rig.legs[0]!.g.rotation.x,\n legR: rig.legs[1]!.g.rotation.x,\n kneeL: rig.legs[0]!.kn.rotation.x,\n kneeR: rig.legs[1]!.kn.rotation.x,\n })\n\n /** Arms and legs of the armed human (`:45`, `:47`, `:53`): both hands on the weapon, the arms follow the aim. */\n const armed = (pitch: number, gait: number, hip: number): PoseTargets => {\n const aim = clamp((pitch + 1) / 3, 0, 0.99) * 3 - 1 // `(playerArmCode() - 2) * 3 - 1`\n const shoulder = AIMED.shoulder + aim * AIMED.perAim + AIMED.swing * Math.sin(cycles * TWO_PI) * gait\n rig.legs.forEach((leg, index) => {\n const x = legRestX[index]!\n leg.g.rotation.y = hip\n leg.g.position.x = x * Math.cos(hip)\n leg.g.position.z = -x * Math.sin(hip)\n })\n // arms[0] is the support hand (+x), arms[1] the weapon hand (-x)\n return { armR: shoulder, armL: shoulder, armRz: AIMED.zRight, armLz: AIMED.zLeft, elbR: AIMED.elbowRight, elbL: AIMED.elbowLeft }\n }\n\n /** The stretched arms of `shove_two_hands` (attack clips) held on the piece, the body leaning into it; straining, the legs brace and the arms shake. */\n const pushingPose = (push: NonNullable<AvatarUpdate['push']>): PoseTargets => {\n const on = push.phase === 'grip' ? Math.min(1, push.progress * 2.2) : 1\n const strain = push.phase === 'strain' ? 1 : 0\n const shake = strain * Math.sin(time * 40) * 0.025\n const raise = -1.5 * on\n const elbow = -0.9 + 0.72 * (push.phase === 'grip' ? push.progress : 1) + strain * 0.12\n return {\n lean: (0.2 + 0.2 * strain) * on,\n headX: (0.05 + 0.08 * strain) * on,\n armR: raise + shake,\n armL: raise - shake,\n armRz: -0.08 * on,\n armLz: 0.08 * on,\n elbR: elbow,\n elbL: elbow,\n ...(strain ? { legL: -0.5, legR: 0.4, kneeL: 0.55, kneeR: 0.08, drop: -0.05 } : {}),\n }\n }\n\n /**\n * The right arm on a handle: raised toward the hand's height, the elbow bending as the leaf comes toward the body (pulled) or straightening as it goes away (pushed),\n * shaking on a locked one; the body leans back pulling and into it pushing, and bends to a low handle.\n */\n const doorPose = (door: NonNullable<AvatarUpdate['door']>): PoseTargets => {\n const { phase, progress } = door\n const on = phase === 'reach' ? progress : phase === 'release' ? 1 - progress : 1\n const swing = phase === 'swing' ? progress : phase === 'release' ? 1 : 0\n const shake = phase === 'rattle' ? Math.sin(time * 55) * 0.06 * (1 - progress) : 0\n // the shoulder about 1.42 m over the feet, the arm 0.62 m: the angle down from the shoulder to the handle, a low handle bends the body\n const drop = clamp((DOOR_SHOULDER - door.height) / DOOR_ARM, -0.9, 1)\n const low = clamp((0.75 - door.height) / 0.5, 0, 1)\n const raise = -Math.acos(clamp(drop, -1, 1)) * on - 0.35 * low * on\n const elbow = door.pull ? -0.35 - 0.75 * swing : -0.95 + 0.75 * swing\n return {\n armR: raise + shake,\n armRz: REST_ARM_Z * (1 - on) + 0.05 * on,\n elbR: -0.12 + (elbow + 0.12) * on,\n armLz: -REST_ARM_Z,\n elbL: -0.12,\n lean: ((door.pull ? -0.06 : 0.1) * swing + 0.35 * low) * on,\n headX: 0.06 * on + 0.2 * low * on,\n }\n }\n\n /** Right-hand carry and item-use poses in third person (`arms[1]` is the puppet's right arm at `-x`, `arms[0]` is the left arm at `+x`). */\n const holdingPose = (gait: number, itemUse?: AvatarItemUsePose | null): PoseTargets => {\n const bob = Math.sin(cycles * TWO_PI) * 0.05 * gait\n if (!itemUse) {\n return { armL: -0.45 + bob, armLz: 0.22, elbL: -1.05 }\n }\n const { id, position, rotation } = itemUse\n if (id === 'drink' || id === 'sip' || id === 'chug') {\n const raise = clamp((position[1] + 0.2) / 0.22, 0, 1)\n const tilt = clamp(Math.abs(rotation[0]) / 1.22, 0, 1.15)\n return {\n armL: -0.45 - 0.95 * raise - 0.22 * tilt,\n armLz: 0.22 + 0.44 * raise,\n elbL: -1.05 - 0.85 * raise + 0.12 * tilt,\n headX: -0.26 * tilt,\n }\n }\n if (id === 'open' || id === 'close' || itemUse.gripL !== undefined) {\n const reach = clamp((0.22 - position[0]) / 0.12, 0, 1)\n return {\n armL: -0.45 - 0.35 * reach,\n armLz: 0.22 + 0.28 * reach,\n elbL: -1.05 - 0.25 * reach,\n armR: -0.78 * reach,\n armRz: -0.48 * reach,\n elbR: -1.25 * reach,\n }\n }\n // pour, pour_out, tilt\n const raise = clamp((position[1] + 0.2) / 0.25, 0, 1)\n const tilt = clamp(Math.abs(rotation[0]) / 1.75, 0, 1.2)\n const ext = Math.max(raise, tilt * 0.75)\n return {\n armL: -0.45 - 0.48 * ext,\n armLz: 0.22 + 0.08 * ext,\n elbL: -1.05 + 0.38 * ext,\n }\n }\n const resetLegYaw = (): void => {\n rig.legs.forEach((leg, index) => {\n leg.g.rotation.y = 0\n leg.g.position.x = legRestX[index]!\n leg.g.position.z = 0\n })\n }\n\n /** Running gait: forward torso lean, pronounced body drop, higher knee lift and bent-elbow arm pumping. */\n const runningPose = (gait: number, busyHands = false): PoseTargets => {\n const ph = cycles * TWO_PI\n const sine = Math.sin(ph)\n const cosine = Math.cos(ph)\n const legL = sine * 0.65 * gait\n const legR = -sine * 0.65 * gait\n const kneeL = Math.max(0, -cosine) * 1.15 * gait\n const kneeR = Math.max(0, cosine) * 1.15 * gait\n const targets: PoseTargets = {\n lean: RUN_LEAN * Math.min(1, gait),\n drop: Math.abs(cosine) * RUN_BOB * gait,\n legL,\n legR,\n kneeL,\n kneeR,\n }\n if (!busyHands) {\n targets.armR = -0.32 - sine * 0.65 * gait\n targets.armL = -0.32 + sine * 0.65 * gait\n targets.elbR = -1.25 + Math.max(0, sine) * 0.3 * gait\n targets.elbL = -1.25 + Math.max(0, -sine) * 0.3 * gait\n targets.armRz = 0.22\n targets.armLz = -0.22\n }\n return targets\n }\n\n const crouchPose = (gait: number): PoseTargets => {\n const swing = (leg: number): number => {\n const legS = legSide(leg)\n return CROUCH.thigh - Math.sin(cycles * TWO_PI) * legS * CROUCH.thighWalk * gait\n }\n return {\n legL: swing(0),\n legR: swing(1),\n kneeL: CROUCH.shin,\n kneeR: CROUCH.shin,\n lean: WALK_LEAN * gait + CROUCH.lean,\n drop: Math.abs(Math.sin(cycles * TWO_PI)) * WALK_BOB * gait + CROUCH.drop,\n }\n }\n\n /** The knocked-down limbs (`:26-:31`, `:40-:43`, `:47`) with the stride at 1, as the game pushes it while down. */\n const downPose = (): PoseTargets => {\n const ph = cycles * TWO_PI\n const gait = 1\n const leg = (index: number): { hip: number; knee: number } => {\n const legS = legSide(index)\n const walkS = Math.sin(ph) * legS\n const bend = fract(cycles * 3) * legS > 0.3 ? fract(cycles * 3) * DOWN.shinBend : Math.max(0, Math.cos(ph + (legS > 0 ? 0 : Math.PI))) * DOWN.shinSwing * gait\n return { hip: -walkS * DOWN.thighWalk * gait, knee: bend }\n }\n const arm = (index: number): { shoulder: number; z: number; elbow: number } => {\n const side = index === 0 ? 1 : -1 // arms[0] at +x\n const armS = Math.sin(ph) * (side > 0 ? 1 : -1)\n const shoulder = fract(cycles * 5) > 0.5 && side > 0 ? DOWN.armHigh : DOWN.armLow + DOWN.armWave * Math.sin(cycles * 5 + side)\n return { shoulder, z: side * (DOWN.armZ + DOWN.armZWave * Math.sin(cycles * 3)), elbow: -0.35 - Math.max(0, armS) * 0.4 * gait }\n }\n const [l, r] = [leg(0), leg(1)]\n const [a0, a1] = [arm(0), arm(1)]\n return {\n legL: l.hip,\n kneeL: l.knee,\n legR: r.hip,\n kneeR: r.knee,\n armR: a0.shoulder,\n armRz: a0.z,\n elbR: a0.elbow,\n armL: a1.shoulder,\n armLz: a1.z,\n elbL: a1.elbow,\n lean: WALK_LEAN * gait,\n drop: Math.abs(Math.sin(ph)) * WALK_BOB * gait,\n }\n }\n\n /** The knee opens until the sole reaches the floor: a low seat sends the shins forward, a high one lets them hang straight down. */\n const sitPose = (hip: number): PoseTargets => {\n const knee = hip - legLengths.hipBelowTrunk - legLengths.thigh * Math.cos(SIT.thigh)\n const shinFromVertical = Math.acos(clamp(knee / legLengths.shin, 0, 1))\n const bend = -SIT.thigh - shinFromVertical\n return {\n legL: SIT.thigh,\n legR: SIT.thigh,\n kneeL: bend,\n kneeR: bend,\n lean: SIT.lean,\n drop: hip - HIP_HEIGHT,\n armR: SIT.arm,\n armL: SIT.arm,\n armRz: SIT.armZ,\n armLz: -SIT.armZ,\n elbR: SIT.elbow,\n elbL: SIT.elbow,\n }\n }\n const liePose = (): PoseTargets => ({ legL: 0, legR: 0, kneeL: LIE.knee, kneeR: LIE.knee, lean: 0, drop: 0, armR: 0, armL: 0, armRz: LIE.armZ, armLz: -LIE.armZ, elbR: LIE.elbow, elbL: LIE.elbow })\n /** Face up, the pelvis `hip` metres above the feet: a quarter turn about the hip, head toward -z. */\n const layBody = (hip: number): void => {\n tilt.rotation.set(-Math.PI / 2, 0, 0, 'XYZ')\n const pivot = new THREE.Vector3(0, HIP_HEIGHT, 0).applyEuler(tilt.rotation)\n tilt.position.set(0, hip, 0).sub(pivot)\n }\n\n const placeBody = (progress: number, forward?: boolean): void => {\n // `:74`: the whole body turns about the hip (face down or face up by the phase) and the hip drops to the ground\n const fk = progress * progress * (3 - 2 * progress)\n // flip 0 turns the head to -z, behind the facing (on the back); 1 to +z (face down)\n const flip = forward === undefined ? (fract(cycles * 1.7) >= 0.5 ? 1 : 0) : forward ? 1 : 0\n tilt.rotation.set((-DOWN.tilt + flip * 2 * DOWN.tilt) * fk, 0, Math.sin(cycles * 7) * DOWN.roll * fk, 'XYZ')\n const hip = new THREE.Vector3(0, HIP_HEIGHT, 0)\n const target = new THREE.Vector3(0, DOWN.hipY, -DOWN.hipZ + flip * DOWN.hipZFlip)\n const place = new THREE.Vector3(0, HIP_HEIGHT * (1 - fk), 0).addScaledVector(target, fk)\n tilt.position.copy(place.sub(hip.applyEuler(tilt.rotation)))\n }\n\n const fireClipEvents = (r: ClipRun, from: number, to: number): void => {\n for (const event of clipEventsBetween(r.clip, from, to)) emit({ ...event, clip: r.clip.id }, r.onEvent)\n }\n\n const stepClip = (dt: number, down: boolean, crouch: boolean): void => {\n if (!run) return\n const r = run\n const from = r.time\n r.time += dt\n const { duration } = r.clip\n if (r.clip.loop && r.time > duration) {\n fireClipEvents(r, from, duration)\n r.time -= duration * Math.floor(r.time / duration)\n fireClipEvents(r, -1e-9, r.time)\n } else {\n fireClipEvents(r, from, Math.min(r.time, duration))\n if (r.time >= duration && !r.clip.loop) r.target = 0\n }\n r.weight = r.blend <= 0 ? r.target : clamp(r.weight + (r.target ? dt : -dt) / r.blend, 0, 1)\n if (r.target === 0 && r.weight <= 0) {\n run = null\n return\n }\n if (down) return\n // a crouched body keeps its legs bent under a punch or the guard: only a kick needs them\n const keepsCrouch = crouch && !r.clip.events?.some((event) => event.data?.kind === 'kick')\n const channels = r.clip.channels ?? 'full'\n const sampled = filterPoseChannels(filterPoseChannels(samplePoseClip(r.clip, Math.min(r.time, duration)), channels), keepsCrouch ? 'upper' : 'full')\n const current = readPose()\n const blended: Record<string, number> = {}\n for (const [name, value] of Object.entries(sampled)) if (name in current) blended[name] = current[name]! + (value - current[name]!) * r.weight\n animator.setPose(rig, blended as PoseTargets)\n }\n\n return {\n root,\n rig,\n colors,\n three: THREE,\n get playing() {\n return run ? run.clip.id : null\n },\n update(dt, state = {}) {\n armReach.restore()\n const speed = state.speed ?? 0\n const moving = speed >= 0.05 // the game: `spd < 0.05 ? 0 : walkCad(spd)`\n const down = !!state.down\n const running = Boolean(state.running && moving && !down && !state.crouch)\n if (moving) cycles += dt * (running ? walkCadence(speed) * 1.3 : walkCadence(speed))\n const gait = Math.min(MAX_GAIT, walkGait(speed))\n profile.arm = (running ? 0.55 : WALK_ARM) * gait\n profile.bob = (running ? RUN_BOB : WALK_BOB) * gait\n time = cycles / (walkCadence(Math.max(speed, 0)) * (running ? 1.3 : 1))\n animator.animate(body, time, { speed })\n bob = rig.fig.position.y - rig.dropBase\n fall = fallSeconds <= 0 ? (down ? 1 : 0) : clamp(fall + (down ? dt : -dt) / fallSeconds, 0, 1)\n resetLegYaw()\n const seat = down ? null : (state.seat ?? null)\n if (down) {\n animator.setPose(rig, downPose())\n bob = rig.fig.position.y - rig.dropBase\n } else if (seat) {\n animator.setPose(rig, seat.pose === 'lie' ? liePose() : sitPose(seat.hip))\n bob = 0\n }\n else {\n if (running) {\n animator.setPose(rig, runningPose(gait, Boolean(state.armed || state.holding || state.itemUse)))\n bob = rig.fig.position.y - rig.dropBase\n }\n if (state.crouch) {\n animator.setPose(rig, crouchPose(gait))\n bob = rig.fig.position.y - rig.dropBase - CROUCH.drop\n }\n if (state.push) animator.setPose(rig, pushingPose(state.push))\n else if (state.door) animator.setPose(rig, doorPose(state.door))\n else if (state.armed) animator.setPose(rig, armed(state.pitch ?? 0, gait, state.hip ?? 0))\n else if (state.holding || state.itemUse) animator.setPose(rig, holdingPose(gait, state.itemUse))\n else if (!running) {\n animator.setPose(rig, {\n armRz: REST_ARM_Z,\n armLz: -REST_ARM_Z,\n elbR: -0.12,\n elbL: -0.12,\n })\n }\n }\n if (seat?.pose === 'lie') layBody(seat.hip)\n else placeBody(fall, state.fallForward)\n stepClip(dt, down, Boolean(state.crouch || seat))\n const cascadeDt = run && !run.clip.loop ? dt * clipCascade : dt\n const targetWithoutBob = rig.fig.position.y - bob\n if (smooth) animator.cascade(rig, cascadeDt)\n hipWithoutBob = smooth && hipWithoutBob !== null ? stepCascade(hipWithoutBob, targetWithoutBob, cascadeDt, 'hip') : targetWithoutBob\n bob = rig.fig.position.y - hipWithoutBob\n // the hands close for a punch and open for a shove, whatever the clip is called (a combo has a jab, a cross, a hook, an uppercut); a clip with no impact,\n // such as the fighting guard, closes them with a `grip` event\n const blow = run?.clip.events?.find((event) => (event.type === 'impact' || event.type === 'grip') && event.data?.kind)?.data?.kind\n const ph = cycles * TWO_PI\n hands.forEach((hand) => {\n const isRight = hand.side < 0\n const holdRight = isRight && (!!state.holding || !!state.itemUse)\n const holdLeft = !isRight && (state.itemUse?.id === 'open' || state.itemUse?.id === 'close' || state.itemUse?.gripL !== undefined)\n const grip =\n !isRight && state.itemUse?.gripL !== undefined\n ? 1.22 * state.itemUse.gripL\n : blow === 'punch'\n ? 1.4\n : blow === 'shove'\n ? 0.15\n : state.armed || holdRight || holdLeft\n ? 1.22\n : running\n ? 0.85\n : 0.12\n const wristSwing = holdRight || state.armed || running ? 0 : -Math.min(1, gait) * Math.sin(ph - 0.6) * 0.12 * hand.side\n setHandGrip(hand, grip, wristSwing)\n })\n root.updateMatrixWorld(true)\n root.worldToLocal(eyeSocket.getWorldPosition(eyeLocal))\n eyeLocal.y -= (1 - eyeBob) * bob\n },\n eye(out = new THREE.Vector3()) {\n root.updateWorldMatrix(true, false)\n return root.localToWorld(out.copy(eyeLocal))\n },\n setView: (mode, camera, viewOptions) => {\n headHider.setView(mode, camera)\n armsHider.setView(viewOptions?.arms ? mode : 'third', camera)\n },\n play(clip, playOptions = {}) {\n const found = typeof clip === 'string' ? clips.get(clip) : clip\n if (!found) throw new Error(`Unknown pose clip: ${String(clip)}`)\n run = { clip: found, time: 0, weight: run?.weight ?? 0, target: 1, blend: playOptions.blend ?? blendDefault, ...(playOptions.onEvent ? { onEvent: playOptions.onEvent } : {}) }\n fireClipEvents(run, -1e-9, 0) // events at t = 0 fire on the first frame\n run.time = 0\n },\n stop() {\n if (run) run.target = 0\n },\n hand: (side) => sockets[side],\n shoulder: (side) => armOf[side].g as unknown as THREE_NS.Object3D,\n reach(targets, view) {\n if (run || fall > 0) return\n root.updateMatrixWorld(true)\n armReach.apply(targets, view)\n // the index finger of a hand on a trigger curls by itself (`HandTargets.fingers` for the right hand, `fingersL` for the left), the other fingers keep the grip\n for (const hand of hands) {\n const curl = hand.side < 0 ? targets?.fingers?.index : targets?.fingersL?.index\n if (curl === undefined || !hand.fingers[1]) continue\n const k = TRIGGER_CURL * Math.min(1, Math.max(0, curl))\n hand.fingers[0]!.rotation.z = -hand.side * k * 0.9\n hand.fingers[1]!.rotation.z = -hand.side * k * 1.1\n }\n },\n on(_type, listener) {\n listeners.add(listener)\n return () => void listeners.delete(listener)\n },\n dispose() {\n run = null\n listeners.clear()\n body.traverse((object) => {\n const mesh = object as THREE_NS.Mesh\n mesh.geometry?.dispose()\n const material = mesh.material as THREE_NS.Material | THREE_NS.Material[] | undefined\n if (Array.isArray(material)) material.forEach((m) => m.dispose())\n else material?.dispose()\n })\n root.removeFromParent()\n },\n }\n}\n","{\n \"source\": {\n \"file\": \"site/pages/jogo/zombiada-modo-livre.html\",\n \"variable\": \"PB specs[0] ('você') and PLAYER_COR\",\n \"note\": \"The team game's player body: the Bestiário/Elenco human body. Overridable by `createPlayerAvatar(THREE, { spec, shirtColor })`.\"\n },\n \"spec\": {\n \"type\": \"Lento\",\n \"human\": true,\n \"decay\": 0,\n \"seed\": 4242,\n \"skin\": \"b07a52\",\n \"fem\": false,\n \"life\": 1,\n \"hs\": \"short\",\n \"hair\": \"2a1e16\",\n \"pose\": {\n \"armL\": 0,\n \"armR\": 0,\n \"elbL\": -0.12,\n \"elbR\": -0.12,\n \"armOut\": 0.11,\n \"lean\": 0.04,\n \"headX\": 0,\n \"headZ\": 0\n }\n },\n \"shirtColor\": \"3d5a73\"\n}\n","import type { THREE_NS } from '../three'\n\nexport type TwoBone = {\n /** The middle joint (elbow, knee). */\n joint: THREE_NS.Vector3\n /** The end of the second bone: the target when it is within reach, else the point on the way to it at full stretch. */\n end: THREE_NS.Vector3\n /** The target was out of reach and `end` is short of it. */\n clamped: boolean\n /** Scratch vectors the solver works in. */\n line: THREE_NS.Vector3\n side: THREE_NS.Vector3\n}\n\n/**\n * Two-bone analytic IK. The first bone (`upper`) starts at `root`, the second (`lower`) ends at `end`; the middle joint bends toward `pole` (a direction, not a point: the part of it\n * across the root-to-target line decides which way the elbow goes). A target nearer than the bones can fold, or farther than they can stretch, is clamped to the nearest reachable point on\n * the same line. All vectors are in one space; `out` (made by `createTwoBone`) is filled and returned, so a frame allocates nothing.\n */\nexport const solveTwoBone = (root: THREE_NS.Vector3, target: THREE_NS.Vector3, upper: number, lower: number, pole: THREE_NS.Vector3, out: TwoBone): TwoBone => {\n const line = out.line.copy(target).sub(root)\n let distance = line.length()\n if (distance < 1e-6) line.set(0, 0, -1)\n else line.divideScalar(distance)\n const min = Math.abs(upper - lower) + 1e-4\n const max = upper + lower - 1e-4\n out.clamped = distance > max || distance < min\n distance = Math.min(max, Math.max(min, distance))\n // along the line: the foot of the perpendicular from the joint; across: its height\n const along = (distance * distance + upper * upper - lower * lower) / (2 * distance)\n const across = Math.sqrt(Math.max(0, upper * upper - along * along))\n const side = out.side.copy(pole)\n side.addScaledVector(line, -side.dot(line))\n if (side.lengthSq() < 1e-8) side.set(0, 1, 0).addScaledVector(line, -line.y)\n if (side.lengthSq() < 1e-8) side.set(1, 0, 0)\n side.normalize()\n out.joint.copy(root).addScaledVector(line, along).addScaledVector(side, across)\n out.end.copy(root).addScaledVector(line, distance)\n return out\n}\n\nexport const createTwoBone = (THREE: typeof THREE_NS): TwoBone => ({ joint: new THREE.Vector3(), end: new THREE.Vector3(), clamped: false, line: new THREE.Vector3(), side: new THREE.Vector3() })\n","import type { HandPose, HandTargets } from '@adatechnology/game-contracts'\n\nimport { createTwoBone, solveTwoBone } from '../first-person/ik'\nimport type { RichRig } from '../rich/animator'\nimport type { Three, THREE_NS } from '../three'\n\n/**\n * Limits of the human arm the reach respects, radians and metres. A hand farther than the arm stretches turns the chest (the support shoulder forward, as a shooter blades the body to a long\n * gun) and then protracts the shoulder blade, before the elbow is allowed to lock.\n */\nexport const ARM_REACH = {\n /** The elbow never straightens past this bend (a locked elbow reads as a stick). */\n elbowMin: 0.12,\n /** Full flexion of the elbow. */\n elbowMax: 2.5,\n /** The wrist bends (flexion, extension, deviation) up to this angle from the line of the forearm (flexion reaches about 80 degrees). */\n wristBend: 1.3,\n /** The forearm turns (pronation and supination) up to this angle about its own axis. */\n wristTwist: 1.6,\n /** The most the chest turns to bring the support shoulder toward a far hand. */\n chestTurn: 0.6,\n /** The most a shoulder blade slides toward a far hand (protraction and elevation together). */\n protraction: 0.11,\n /** A hand is within reach below this fraction of the arm's length. */\n slack: 0.96,\n /** Where the elbow points: down and out from the body, a little back (body space, x outward). */\n elbowPole: [0.55, -1, -0.25] as const,\n /** The support arm's elbow: under the gun, hardly out of the body (the first-person arms' `elbowPoleLeft`), so the forearm meets the handguard nearer the aim's line. */\n elbowPoleSupport: [0.1, -1, -0.2] as const,\n /** From the wrist joint to the middle of the palm, metres of the body. */\n palm: 0.042,\n /** In a view the elbow keeps at least this interior bend where a hand is out of reach, right then left (the first-person arms' numbers). */\n viewBend: [1.35, 0.95] as const,\n /** In a view a hand stays this far before a surface, metres. */\n contactMargin: 0.005,\n /** In a view a hand is never nearer than this to the eye, metres. */\n contactNearest: 0.12,\n /** How far in front of the eye a surface is looked for, metres. */\n contactProbe: 1.4,\n /** How far a hand reaches forward of its middle at least (the thickness of the palm), and per metre of fingers pointing ahead. */\n contactPalm: 0.03,\n /** From the middle of the palm to the fingertips. */\n contactFingers: 0.085,\n} as const\n\ntype Side = 'R' | 'L'\ntype ReachArm = { readonly g: THREE_NS.Object3D; readonly el: THREE_NS.Object3D; readonly hand: THREE_NS.Object3D; readonly outward: 1 | -1 }\n\n/**\n * The eye the hands are seen from, given per call to `apply` (null or none is the body seen from outside: nothing changes). `reachBend` keeps the elbow bent where a hand is out of reach, the hand stopping\n * short instead of the arm locking; `keepOutside` pulls a hand back so it stays in front of the surface `contact` finds along the camera's forward.\n */\nexport type ReachView = {\n readonly camera: THREE_NS.Object3D\n /** The least interior bend of the elbow, radians, right then left. Default `ARM_REACH.viewBend`. */\n readonly reachBend?: readonly [number, number]\n readonly keepOutside?: {\n /** The distance to the surface from `origin` along `direction` within `maxDistance`, or null. */\n contact(origin: [number, number, number], direction: [number, number, number], maxDistance: number): number | null\n /** Default `ARM_REACH.contactMargin`. */\n readonly margin?: number\n /** Default `ARM_REACH.contactNearest`. */\n readonly nearest?: number\n }\n}\n\nexport type ArmReach = {\n /** Brings the hands to `targets` (world space) over the pose the body already has; null leaves the arms as the pose put them. A `view` keeps the elbows bent and the hands out of walls. */\n apply(targets: HandTargets | null, view?: ReachView | null): void\n /** Puts back what the last `apply` changed, so the pose and its smoothing see only their own numbers next frame. */\n restore(): void\n}\n\n/**\n * Three-joint reach of the rich body: shoulder (ball), elbow (hinge) and wrist (bend and twist), each kept inside its human range. The hand frame is the one of `HandPose`\n * (game-contracts): x from the wrist to the knuckles, y the back of the hand, z the little-finger side of a right hand; the left hand is the mirror image.\n */\nexport const createArmReach = (THREE: Three, rig: RichRig, hands: Readonly<Record<Side, THREE_NS.Object3D>>): ArmReach => {\n // rig.arms[1] is the weapon hand (the puppet's right, at -x), rig.arms[0] the support hand (+x)\n const arms: Record<Side, ReachArm> = {\n R: { g: rig.arms[1]!.g as unknown as THREE_NS.Object3D, el: rig.arms[1]!.el as unknown as THREE_NS.Object3D, hand: hands.R, outward: -1 },\n L: { g: rig.arms[0]!.g as unknown as THREE_NS.Object3D, el: rig.arms[0]!.el as unknown as THREE_NS.Object3D, hand: hands.L, outward: 1 },\n }\n const upper = rig.upper as unknown as THREE_NS.Object3D\n // hand-local axes of `HandPose` in the hand group's space: the fingers hang along -y, the palm faces the body (+x for the right hand, -x for the left), the thumb is in front (+z)\n const handBasis = {\n R: new THREE.Quaternion().setFromRotationMatrix(new THREE.Matrix4().makeBasis(new THREE.Vector3(0, -1, 0), new THREE.Vector3(-1, 0, 0), new THREE.Vector3(0, 0, -1))).invert(),\n L: new THREE.Quaternion().setFromRotationMatrix(new THREE.Matrix4().makeBasis(new THREE.Vector3(0, -1, 0), new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 0, 1))).invert(),\n }\n const saved = {\n twist: 0,\n arms: { R: { position: new THREE.Vector3(), g: new THREE.Quaternion(), el: new THREE.Quaternion(), hand: new THREE.Quaternion() }, L: { position: new THREE.Vector3(), g: new THREE.Quaternion(), el: new THREE.Quaternion(), hand: new THREE.Quaternion() } },\n }\n let applied = false\n const bone = createTwoBone(THREE)\n const v = { shoulder: new THREE.Vector3(), elbow: new THREE.Vector3(), wrist: new THREE.Vector3(), palm: new THREE.Vector3(), target: new THREE.Vector3(), pole: new THREE.Vector3(), a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() }\n const q = { hand: new THREE.Quaternion(), parent: new THREE.Quaternion(), body: new THREE.Quaternion(), local: new THREE.Quaternion(), swing: new THREE.Quaternion(), twist: new THREE.Quaternion(), rest: new THREE.Quaternion() }\n const basis = new THREE.Matrix4()\n const camera = { position: new THREE.Vector3(), quaternion: new THREE.Quaternion(), inverse: new THREE.Quaternion(), probe: new THREE.Vector3(), forward: new THREE.Vector3(), fingers: new THREE.Vector3(), hand: new THREE.Quaternion() }\n let bendLimit: readonly [number, number] | null = null\n const yAxis = new THREE.Vector3(0, 1, 0)\n\n const lengthsOf = (arm: ReachArm): { upper: number; fore: number; palm: number } => {\n const scale = arm.g.getWorldScale(v.a).y\n return { upper: arm.el.position.length() * scale, fore: arm.hand.position.length() * scale, palm: ARM_REACH.palm * scale }\n }\n\n /** The wrist-to-shoulder distance past which the chest and the shoulder blade move: the arm nearly straight, or with the elbow at the view's bend (law of cosines). */\n const limitOf = (side: Side, upperLength: number, fore: number): number => {\n if (!bendLimit) return (upperLength + fore) * ARM_REACH.slack\n return Math.sqrt(upperLength * upperLength + fore * fore + 2 * upperLength * fore * Math.cos(bendLimit[side === 'R' ? 0 : 1]))\n }\n\n /** The wrist joint and the world orientation of the hand group for a hand pose. */\n const wristOf = (side: Side, pose: HandPose, palm: number): void => {\n q.hand.set(...pose.quaternion).multiply(handBasis[side])\n v.palm.set(...pose.position)\n v.wrist.copy(v.palm).addScaledVector(v.a.set(0, -1, 0).applyQuaternion(q.hand), -palm)\n }\n\n /** Turns the chest so the support shoulder comes toward a hand it cannot reach. */\n const turnChest = (pose: HandPose): void => {\n const { upper: up, fore, palm } = lengthsOf(arms.L)\n wristOf('L', pose, palm)\n const excess = arms.L.g.getWorldPosition(v.shoulder).distanceTo(v.wrist) - limitOf('L', up, fore)\n if (excess <= 0) return\n // the support shoulder is at +x of the chest, the front is +z: a turn of -a about y brings it forward\n const chestRadius = Math.hypot(arms.L.g.position.x, arms.L.g.position.z) * arms.L.g.getWorldScale(v.a).y\n upper.rotation.y -= Math.min(ARM_REACH.chestTurn, excess / Math.max(0.05, chestRadius))\n upper.updateMatrixWorld(true)\n }\n\n /** Slides the shoulder blade toward a hand still out of reach. */\n const protract = (arm: ReachArm, limit: number): void => {\n const excess = arm.g.getWorldPosition(v.shoulder).distanceTo(v.wrist) - limit\n if (excess <= 0) return\n const parent = arm.g.parent!\n v.b.copy(v.wrist).sub(v.shoulder).normalize().multiplyScalar(Math.min(excess, ARM_REACH.protraction)).add(v.shoulder)\n arm.g.position.copy(parent.worldToLocal(v.b))\n arm.g.updateMatrixWorld(true)\n }\n\n /** Keeps the hand group inside the wrist's range: the bend off the forearm line and the turn about it. */\n const limitWrist = (local: THREE_NS.Quaternion): THREE_NS.Quaternion => {\n // swing-twist about the forearm axis (y): the twist is the forearm turning, the swing the wrist bending\n const projection = v.c.set(local.x, local.y, local.z).projectOnVector(yAxis)\n q.twist.set(projection.x, projection.y, projection.z, local.w).normalize()\n const twistAngle = 2 * Math.atan2(q.twist.y, q.twist.w)\n const swing = q.swing.copy(local).multiply(q.twist.invert())\n const swingAngle = 2 * Math.acos(Math.min(1, Math.abs(swing.w)))\n if (swingAngle > ARM_REACH.wristBend) swing.slerp(q.rest.identity(), 1 - ARM_REACH.wristBend / swingAngle)\n const clampedTwist = Math.max(-ARM_REACH.wristTwist, Math.min(ARM_REACH.wristTwist, Math.atan2(Math.sin(twistAngle), Math.cos(twistAngle))))\n return local.copy(swing).multiply(q.twist.setFromAxisAngle(yAxis, clampedTwist))\n }\n\n const reach = (side: Side, pose: HandPose): void => {\n const arm = arms[side]\n const { upper: up, fore, palm } = lengthsOf(arm)\n wristOf(side, pose, palm)\n protract(arm, limitOf(side, up, fore))\n arm.g.getWorldPosition(v.shoulder)\n // the elbow points down and out of the body, whichever way the body faces\n upper.getWorldQuaternion(q.body)\n const pole = side === 'L' ? ARM_REACH.elbowPoleSupport : ARM_REACH.elbowPole\n v.pole.set(pole[0] * arm.outward, pole[1], pole[2]).applyQuaternion(q.body)\n // the elbow keeps a little bend: shorten the line to the wrist rather than lock it\n const lockLimit = Math.sqrt(up * up + fore * fore + 2 * up * fore * Math.cos(ARM_REACH.elbowMin))\n const most = bendLimit ? Math.min(lockLimit, limitOf(side, up, fore)) : lockLimit\n const least = Math.sqrt(up * up + fore * fore + 2 * up * fore * Math.cos(ARM_REACH.elbowMax))\n const line = v.c.copy(v.wrist).sub(v.shoulder)\n const distance = Math.min(most, Math.max(least, line.length()))\n v.target.copy(v.shoulder).addScaledVector(line.normalize(), distance)\n solveTwoBone(v.shoulder, v.target, up, fore, v.pole, bone)\n // upper arm: local -y runs to the elbow, local +z is the side the forearm folds toward (the elbow bends about local x, negative forward)\n const along = v.a.copy(bone.joint).sub(v.shoulder).normalize()\n const forearm = v.b.copy(bone.end).sub(bone.joint).normalize()\n const fold = v.c.copy(forearm).addScaledVector(along, -forearm.dot(along))\n if (fold.lengthSq() < 1e-8) fold.copy(v.pole).addScaledVector(along, -v.pole.dot(along)).negate()\n fold.normalize()\n const yWorld = v.elbow.copy(along).negate()\n basis.makeBasis(v.pole.crossVectors(yWorld, fold), yWorld, fold)\n arm.g.parent!.getWorldQuaternion(q.parent)\n arm.g.quaternion.setFromRotationMatrix(basis).premultiply(q.parent.invert())\n arm.el.rotation.set(-Math.acos(Math.max(-1, Math.min(1, along.dot(forearm)))), 0, 0)\n arm.g.updateMatrixWorld(true)\n // the wrist sits a little off the forearm's line: turn the whole arm about the shoulder so it lands on the target, the elbow keeping its bend\n const reached = arm.hand.getWorldPosition(v.a).sub(v.shoulder).normalize()\n q.swing.setFromUnitVectors(reached, v.b.copy(v.target).sub(v.shoulder).normalize())\n arm.g.parent!.getWorldQuaternion(q.parent)\n arm.g.quaternion.premultiply(q.parent).premultiply(q.swing).premultiply(q.parent.invert())\n arm.g.updateMatrixWorld(true)\n // wrist: the hand group turns to the grip, inside the wrist's range\n arm.el.getWorldQuaternion(q.parent)\n arm.hand.quaternion.copy(limitWrist(q.local.copy(q.parent.invert()).multiply(q.hand)))\n }\n\n /** Pulls a hand back, along the camera's forward, to the surface in front of it minus what the hand reaches forward and a margin; never nearer than `nearest` to the eye. */\n const keepOutside = (pose: HandPose, outside: NonNullable<ReachView['keepOutside']>): HandPose => {\n // the hand in the camera's space: x right, y up, the view looks down -z\n const place = v.a.set(...pose.position).sub(camera.position).applyQuaternion(camera.inverse)\n camera.probe.set(place.x, place.y, 0).applyQuaternion(camera.quaternion).add(camera.position)\n camera.forward.set(0, 0, -1).applyQuaternion(camera.quaternion)\n const distance = outside.contact([camera.probe.x, camera.probe.y, camera.probe.z], [camera.forward.x, camera.forward.y, camera.forward.z], ARM_REACH.contactProbe)\n if (distance === null) return pose\n camera.hand.set(...pose.quaternion).premultiply(camera.inverse)\n const ahead = Math.max(ARM_REACH.contactPalm, -camera.fingers.set(1, 0, 0).applyQuaternion(camera.hand).z * ARM_REACH.contactFingers)\n const limit = Math.max(outside.nearest ?? ARM_REACH.contactNearest, distance - ahead - (outside.margin ?? ARM_REACH.contactMargin))\n if (-place.z <= limit) return pose\n place.z = -limit\n place.applyQuaternion(camera.quaternion).add(camera.position)\n return { ...pose, position: [place.x, place.y, place.z] }\n }\n\n const save = (): void => {\n saved.twist = upper.rotation.y\n for (const side of ['R', 'L'] as const) {\n const arm = arms[side]\n const into = saved.arms[side]\n into.position.copy(arm.g.position)\n into.g.copy(arm.g.quaternion)\n into.el.copy(arm.el.quaternion)\n into.hand.copy(arm.hand.quaternion)\n }\n }\n\n return {\n apply(targets, view) {\n if (!targets || (!targets.R && !targets.L)) return\n save()\n applied = true\n upper.updateWorldMatrix(true, true)\n let { R, L } = targets\n bendLimit = view ? (view.reachBend ?? ARM_REACH.viewBend) : null\n if (view?.keepOutside) {\n view.camera.updateWorldMatrix(true, false)\n view.camera.matrixWorld.decompose(camera.position, camera.quaternion, v.a)\n camera.inverse.copy(camera.quaternion).invert()\n if (R) R = keepOutside(R, view.keepOutside)\n if (L) L = keepOutside(L, view.keepOutside)\n }\n if (L && R) turnChest(L)\n if (R) reach('R', R)\n if (L) reach('L', L)\n bendLimit = null\n },\n restore() {\n if (!applied) return\n applied = false\n upper.rotation.y = saved.twist\n for (const side of ['R', 'L'] as const) {\n const arm = arms[side]\n const from = saved.arms[side]\n arm.g.position.copy(from.position)\n arm.g.quaternion.copy(from.g)\n arm.el.quaternion.copy(from.el)\n arm.hand.quaternion.copy(from.hand)\n }\n },\n }\n}\n","import type { THREE_NS } from '../three'\n\nexport type AvatarViewMode = 'first' | 'third'\n\nexport type HeadHider = {\n setView(mode: AvatarViewMode, camera: THREE_NS.Object3D | null): void\n}\n\ntype Drawable = THREE_NS.Object3D & { material?: THREE_NS.Material | THREE_NS.Material[] }\ntype Flags = { material: THREE_NS.Material; colorWrite: boolean; depthWrite: boolean }\n\nconst isDrawable = (object: THREE_NS.Object3D): boolean => {\n const flagged = object as THREE_NS.Object3D & { isMesh?: boolean; isSprite?: boolean; isPoints?: boolean }\n return Boolean(flagged.isMesh || flagged.isSprite || flagged.isPoints)\n}\n\n/**\n * Draws nothing of the given objects for one camera: while that camera renders, the materials write neither colour nor depth. The materials stay visible\n * and untouched for every other pass (shadow, mirror, third person), and are restored after each draw, so a material shared with the hands comes back intact.\n */\nexport const createHeadHider = (roots: readonly THREE_NS.Object3D[]): HeadHider => {\n let isHiding = false\n let viewCamera: THREE_NS.Object3D | null = null\n const drawables: Drawable[] = []\n for (const root of roots) root.traverse((object) => isDrawable(object) && drawables.push(object))\n\n for (const drawable of drawables) {\n const previousBefore = drawable.onBeforeRender\n const previousAfter = drawable.onAfterRender\n let saved: Flags[] = []\n drawable.onBeforeRender = (renderer, scene, camera, geometry, material, group) => {\n previousBefore.call(drawable, renderer, scene, camera, geometry, material, group)\n if (!isHiding || camera !== viewCamera) return\n const drawn = Array.isArray(drawable.material) ? drawable.material : [material]\n saved = drawn.map((entry) => ({ material: entry, colorWrite: entry.colorWrite, depthWrite: entry.depthWrite }))\n for (const entry of drawn) {\n entry.colorWrite = false\n entry.depthWrite = false\n }\n }\n drawable.onAfterRender = (renderer, scene, camera, geometry, material, group) => {\n previousAfter.call(drawable, renderer, scene, camera, geometry, material, group)\n for (const flags of saved) {\n flags.material.colorWrite = flags.colorWrite\n flags.material.depthWrite = flags.depthWrite\n }\n saved = []\n }\n }\n\n return {\n setView(mode, camera) {\n isHiding = mode === 'first' && camera !== null\n viewCamera = camera\n },\n }\n}\n","import { ATTACK_CLIPS } from '@adatechnology/game-characters-people'\nimport { mirrorPoseClip } from '@adatechnology/game-characters'\nimport type { PoseClip } from '@adatechnology/game-characters'\nimport type { HandTargets } from '@adatechnology/game-contracts'\n\nimport type { ReachView } from './arm-reach'\nimport type { AvatarItemUsePose, AvatarViewOptions, PlayerAvatar } from './avatar'\nimport type { AvatarViewMode } from './head-hiding'\nimport type { THREE_NS } from '../three'\n\n/** What `@adatechnology/game-test-room` calls a `RoomAvatar`, restated here so this package does not depend on the room. */\nexport type RoomAvatarLike = {\n root: THREE_NS.Object3D\n update(dt: number, state: { speed: number; running: boolean; crouch: boolean; down: boolean; fallForward?: boolean; armed: boolean; pitch: number; push?: { readonly phase: 'grip' | 'push' | 'strain'; readonly progress: number } | null; door?: { readonly phase: 'reach' | 'swing' | 'release' | 'rattle'; readonly progress: number; readonly height: number; readonly pull: boolean } | null; holding?: boolean; itemUse?: AvatarItemUsePose | null; seat?: { readonly pose: 'sit' | 'lie'; readonly hip: number } | null }): void\n hand(side: 'R' | 'L'): THREE_NS.Object3D\n shoulder(side: 'R' | 'L'): THREE_NS.Object3D\n /** Where the body's eyes are after its pose (`RoomAvatar.eye`): the room draws the body in both views and puts the first-person camera there. */\n eye(out?: THREE_NS.Vector3): THREE_NS.Vector3\n /** Hides the head and neck from `camera` in first person, and the arms with `arms` (`RoomAvatar.setView`). */\n setView(mode: AvatarViewMode, camera: THREE_NS.Object3D | null, options?: AvatarViewOptions): void\n /** Brings the body's hands to the tool in them, in both views; `view` keeps them in the first-person view (`RoomAvatar.reach`). */\n reach(targets: HandTargets | null, view?: ReachView | null): void\n /** Plays a strike on the body (the only source of it, in both views) and answers the seconds to its impact (`RoomAvatar.strike`). */\n strike(clipId: string, options?: { leg?: 'left' | 'right'; hand?: 'left' | 'right' }): number | null\n /** The foot the walk put down since the last call (`RoomAvatar.footfall`), or null. */\n footfall(): 'left' | 'right' | null\n /** The avatar it wraps. */\n readonly avatar: PlayerAvatar\n}\n\nexport type ToRoomAvatarOptions = {\n /** The third-person strike clips `strike` finds by id (`defaultCharacterClips()` of game-kit-defaults, or the game's own). Default `ATTACK_CLIPS` of game-characters-people, which is deprecated: pass them. */\n strikeClips?: readonly PoseClip[]\n /** The looping clip the body holds between punches (a clip of `strikeClips`), so a combo goes guard, punch, guard instead of dropping the hands each time; `false` for none. Default `'fight_guard'`. */\n guardClip?: string | false\n /** Seconds the guard stays up after a punch ends. Default 1.2. */\n guardHold?: number\n /** Seconds a punch takes to blend in over the walk (or the guard it comes from). Default 0.05: the fist leaves at once. */\n punchBlend?: number\n}\n\n/** The impact second of a clip: the time of its first `impact` event. */\nconst impactOf = (clip: PoseClip): number | null => clip.events?.find((event) => event.type === 'impact')?.t ?? null\n/** A punch is a clip whose impact is a `punch` (the hands close for it); after one the body keeps the guard. */\nconst isPunch = (clip: PoseClip): boolean => clip.events?.some((event) => event.type === 'impact' && event.data?.kind === 'punch') ?? false\n/** Below this ground speed (m/s) the body does not walk, so its feet do not fall. */\nconst FOOTFALL_SPEED = 0.3\n/** Radians the legs must be apart at the turn for it to be a step (not the sway of standing). */\nconst FOOTFALL_SPREAD = 0.08\n/** Below this ground speed the body stands to keep the guard; walking gives the legs back to the gait. */\nconst GUARD_SPEED = 0.3\n\n/**\n * Fits the player's body to the test room's `RoomAvatar` (`room.setAvatar(toRoomAvatar(createPlayerAvatar(THREE)))`). It changes the sign of the pitch: the room\n * counts a look up as positive, the team game's `view.pitch` (what `AvatarUpdate.pitch` reads) counts a look down as positive. The same body is the first-person view (`eye`, `setView`), and `strike(clipId)` plays the strike on the body (the attack clips) and answers the seconds to its\n * impact, which are the same in both views. A kick with the left leg (`leg: 'left'`) or a punch with the left hand (`hand: 'left'`) plays the mirror of the clip written for the right.\n * After a punch the body holds the guard (`guardClip`) for `guardHold` seconds while it stands, so the next punch leaves from the guard.\n */\nexport const toRoomAvatar = (avatar: PlayerAvatar, options: ToRoomAvatarOptions = {}): RoomAvatarLike => {\n const strikes = new Map((options.strikeClips ?? ATTACK_CLIPS).map((clip) => [clip.id, clip]))\n const mirrored = new Map<string, PoseClip>()\n /** The clip for a kick with the left leg or a punch with the left hand: the mirror of the one that is written for the right. */\n const leftOf = (clip: PoseClip): PoseClip => {\n let found = mirrored.get(clip.id)\n if (!found) mirrored.set(clip.id, (found = mirrorPoseClip(clip, `${clip.id}_left`)))\n return found\n }\n const guard = options.guardClip === false ? undefined : strikes.get(options.guardClip ?? 'fight_guard')\n const guardHold = options.guardHold ?? 1.2\n const punchBlend = options.punchBlend ?? 0.05\n let strikeLeft = 0 // seconds of the punch still to play\n // Heel strikes, read off the legs the walk drew: the hip angles of the two legs (more negative is further forward) part and close; each time\n // their difference turns back, one leg is at its furthest forward and its heel is down. The left leg is `legs[0]` (+x, the body's left).\n let footDown: 'left' | 'right' | null = null\n let walking = false\n let lastSpread: number | null = null\n let lastSlope = 0\n const updateFeet = (state: Parameters<RoomAvatarLike['update']>[1]): void => {\n walking = state.speed >= FOOTFALL_SPEED && !state.down && !state.seat\n if (!walking) {\n lastSpread = null\n lastSlope = 0\n }\n }\n const readFeet = (): void => {\n if (!walking) return\n const [left, right] = avatar.rig.legs\n if (!left || !right) return\n const spread = (left.g as unknown as THREE_NS.Object3D).rotation.x - (right.g as unknown as THREE_NS.Object3D).rotation.x\n if (lastSpread !== null) {\n const slope = spread - lastSpread\n if (Math.abs(spread) > FOOTFALL_SPREAD) {\n if (lastSlope < 0 && slope >= 0) footDown = 'left'\n else if (lastSlope > 0 && slope <= 0) footDown = 'right'\n }\n if (slope !== 0) lastSlope = slope\n }\n lastSpread = spread\n }\n let guardLeft = 0 // seconds the guard stays up after it\n let guarding = false\n const stepGuard = (dt: number, state: Parameters<RoomAvatarLike['update']>[1]): void => {\n if (!guard) return\n const free = state.speed < GUARD_SPEED && !state.down && !state.armed && !state.holding && !state.push && !state.door && !state.itemUse && !state.running\n if (strikeLeft > 0) {\n strikeLeft -= dt\n if (strikeLeft <= 0 && guardLeft > 0 && free) {\n avatar.play(guard)\n guarding = true\n }\n return\n }\n guardLeft = Math.max(0, guardLeft - dt)\n if (guarding && (guardLeft <= 0 || !free || avatar.playing !== guard.id)) {\n if (avatar.playing === guard.id) avatar.stop()\n guarding = false\n }\n }\n return {\n root: avatar.root,\n avatar,\n eye: (out) => avatar.eye(out),\n setView: (mode, camera, options) => avatar.setView(mode, camera, options),\n update: (dt, state) => {\n stepGuard(dt, state)\n updateFeet(state)\n avatar.update(dt, {\n speed: state.speed,\n running: state.running,\n crouch: state.crouch,\n down: state.down,\n armed: state.armed,\n pitch: -state.pitch,\n ...(state.holding !== undefined ? { holding: state.holding } : {}),\n ...(state.itemUse !== undefined ? { itemUse: state.itemUse } : {}),\n ...(state.push !== undefined ? { push: state.push } : {}),\n ...(state.seat !== undefined ? { seat: state.seat } : {}),\n ...(state.door !== undefined ? { door: state.door } : {}),\n ...(state.fallForward !== undefined ? { fallForward: state.fallForward } : {}),\n })\n readFeet()\n },\n footfall: () => {\n const foot = footDown\n footDown = null\n return foot\n },\n hand: (side) => avatar.hand(side),\n shoulder: (side) => avatar.shoulder(side),\n reach: (targets, view) => avatar.reach(targets, view),\n strike: (clipId, strikeOptions) => {\n const clip = strikes.get(clipId)\n if (!clip) return null\n const left = strikeOptions?.leg === 'left' || strikeOptions?.hand === 'left'\n const punch = guard !== undefined && isPunch(clip)\n avatar.play(left ? leftOf(clip) : clip, punch ? { blend: punchBlend } : undefined)\n strikeLeft = punch ? clip.duration : 0\n guardLeft = punch ? guardHold : 0\n guarding = false\n return impactOf(clip)\n },\n }\n}\n","import { clipEventsBetween, sampleFirstPersonClip } from '@adatechnology/game-characters'\nimport type { FirstPersonClip, FirstPersonSampleChannel } from '@adatechnology/game-characters'\nimport { markKitOrigin } from '@adatechnology/game-contracts'\nimport type { HandPose } from '@adatechnology/game-contracts'\n\nimport playerPreset from '../presets/player-avatar.json'\nimport preset from '../presets/first-person-arms.json'\nimport type { Three, THREE_NS } from '../three'\nimport { createHandMesh } from './hand'\nimport type { HandMesh } from './hand'\nimport { createTwoBone, solveTwoBone } from './ik'\nimport type {\n FirstPersonArms,\n FirstPersonArmsOptions,\n FirstPersonBob,\n FirstPersonColors,\n FirstPersonEvent,\n FirstPersonRig,\n RestPose,\n StanceDef,\n} from './types'\n\nconst DEFAULT_BLEND = 0.18\nconst ELBOW_SEGMENTS = 8\n/** An arm is stretched to this fraction of its length before the shoulder moves toward the target. */\nconst REACH_SLACK = 0.97\n/** An elbow put in the view stays this fraction inside its edges, and is pulled in this many times (each pull keeps the forearm's length). */\nconst ELBOW_VIEW_MARGIN = 0.86\nconst ELBOW_VIEW_PASSES = 4\n\ntype View = { tanV: number; tanH: number }\n/** A foot is shown while a clip holds it by at least this much. */\n/** How far (m) the world is probed in front of the camera, the closest a hand may come to the eye, and the gap left in front of a surface. */\nconst CONTACT_PROBE = 1.4\nconst CONTACT_MIN = 0.12\nconst CONTACT_MARGIN = 0.005\nconst CONTACT_PALM = 0.03\n/** The toe of the shoe (and the corners of its sole) is this far (m) from the ankle along the shoe. */\nconst FOOT_LENGTH = 0.24\n\nconst FOOT_SHOWN = 0.001\n\n/** An idle hand drops this far (m) below its rest place and is not drawn once it is out of the view; it goes at `AWAY_OUT` per second and comes back at `AWAY_IN`. */\nconst AWAY_DROP = 0.55\nconst AWAY_OUT = 7\nconst AWAY_IN = 20\nconst AWAY_HIDDEN = 0.97\n\n/** How much of its own colour each material glows with (0..1). */\nconst FILL = 0.3\n\n/** The stances of the preset: `relaxed` and `fists` are rest poses, `hold` follows the targets of the tool in the hands. */\nexport const FIRST_PERSON_STANCES = preset.stances as unknown as Readonly<Record<string, StanceDef>>\n/** The rig of the preset: shoulders, bones, elbow pole, hips and the leg of the kick. */\nexport const FIRST_PERSON_RIG = preset.rig as unknown as FirstPersonRig\nexport const FIRST_PERSON_BOB = preset.bob as FirstPersonBob\n\nconst hexOf = (value: string | number): number => (typeof value === 'string' ? Number.parseInt(value, 16) : value)\nconst scaleHex = (hex: number, factor: number): number => {\n const channel = (shift: number): number => Math.round(((hex >> shift) & 0xff) * factor)\n return (channel(16) << 16) | (channel(8) << 8) | channel(0)\n}\nconst mix = (a: number, b: number, k: number): number => a + (b - a) * k\nconst ease = (k: number): number => k * k * (3 - 2 * k)\n\n/** The colours of the player's preset: the skin and the shirt of the team game's player, trousers and shoes of a plain outfit. */\nexport const FIRST_PERSON_COLORS: FirstPersonColors = {\n skin: hexOf(playerPreset.spec.skin),\n sleeve: hexOf(playerPreset.shirtColor),\n cuff: scaleHex(hexOf(playerPreset.shirtColor), 0.72),\n trouser: 0x2d3440,\n shoe: 0x1c1a1a,\n}\n\ntype Pose = { p: THREE_NS.Vector3; q: THREE_NS.Quaternion; grip: number; scale: number }\n\ntype Segment = THREE_NS.Mesh\ntype Arm = {\n side: 'R' | 'L'\n sign: 1 | -1\n hand: HandMesh\n /** At the middle of the palm, in the space of the arms root. */\n anchor: THREE_NS.Group\n upper: Segment\n fore: Segment\n cuff: Segment\n elbow: THREE_NS.Mesh\n /** What the hand is told to do before a clip: eased from `from` to the stance or the target. */\n shown: Pose\n from: Pose\n mode: string | null\n blend: number\n /** What is drawn. */\n drawn: Pose\n /** The joints of the arm as drawn, in the space of the arms root (the camera's). */\n joints: { shoulder: THREE_NS.Vector3; elbow: THREE_NS.Vector3; wrist: THREE_NS.Vector3 }\n /** 0 in the view, 1 dropped out of it and not drawn (`hideWhenIdle`). */\n away: number\n}\n\nconst newPose = (THREE: Three): Pose => ({ p: new THREE.Vector3(), q: new THREE.Quaternion(), grip: 0, scale: 1 })\nconst copyPose = (to: Pose, from: Pose): Pose => {\n to.p.copy(from.p)\n to.q.copy(from.q)\n to.grip = from.grip\n to.scale = from.scale\n return to\n}\nconst mixPose = (THREE: Three, out: Pose, a: Pose, b: Pose, k: number): Pose => {\n out.p.lerpVectors(a.p, b.p, k)\n out.q.copy(a.q).slerp(b.q, k)\n out.grip = mix(a.grip, b.grip, k)\n out.scale = mix(a.scale, b.scale, k)\n return out\n}\n\n/** The mirror image of a rotation across the plane x = 0 (M R M with M = diag(-1, 1, 1)): for a shoe, which is its own mirror image about its length. */\nconst mirrorRotation = (THREE: Three, q: THREE_NS.Quaternion): THREE_NS.Quaternion => {\n const m = new THREE.Matrix4().makeRotationFromQuaternion(q)\n const e = m.elements\n // column-major: element (row i, column j) is e[j * 4 + i]; the ones with exactly one of i, j equal to 0 change sign\n for (const [i, j] of [[0, 1], [0, 2], [1, 0], [2, 0]] as const) e[j * 4 + i] = -e[j * 4 + i]!\n return new THREE.Quaternion().setFromRotationMatrix(m)\n}\n\n/** The mirror image of a pose across the plane x = 0: the left hand that is the right one seen in a mirror (its frame is the right hand's with z flipped, so z is flipped back). */\nconst mirrorQuaternion = (THREE: Three, q: THREE_NS.Quaternion): THREE_NS.Quaternion => {\n const m = new THREE.Matrix4().makeRotationFromQuaternion(q)\n const e = m.elements\n // rows are x, y, z and columns the same, column-major: row 0 (x) flips, and column 2 (z) flips\n for (let column = 0; column < 3; column++) e[column * 4] = -e[column * 4]!\n for (let row = 0; row < 3; row++) e[8 + row] = -e[8 + row]!\n return new THREE.Quaternion().setFromRotationMatrix(m)\n}\n\n/**\n * The player's arms in first person, drawn in the space of the camera so they cannot leave the view. Each arm is a sleeve (upper arm and forearm, an elbow and a cuff) and a hand of skin (a palm,\n * four fingers of three segments and a thumb that close on a grip); the right leg (trouser and shoe) appears only while a kick holds it. The hands go where the stance puts them (`relaxed`, `fists`) or,\n * in the `hold` stance, where the tool in the hands asks (`HandTargets` of game-contracts, world space); a two-bone IK from fixed shoulders brings the sleeves to them, the elbow bending down and out. A\n * clip (`play`) moves the hands and the foot over that, by a weight that is 0 at its start and end.\n *\n * Hand frame (both hands, as `HandPose`): x from the wrist to the knuckles, y the back of the hand, z the little-finger side of a right hand; a left hand is the right one mirrored.\n */\nexport function createFirstPersonArms(THREE: Three, options: FirstPersonArmsOptions = {}): FirstPersonArms {\n const colors: FirstPersonColors = { ...FIRST_PERSON_COLORS, ...options.colors }\n const rig: FirstPersonRig = {\n ...FIRST_PERSON_RIG,\n ...options.rig,\n radius: { ...FIRST_PERSON_RIG.radius, ...options.rig?.radius },\n foot: options.rig?.foot ?? FIRST_PERSON_RIG.foot,\n }\n const stances: Record<string, StanceDef> = { ...FIRST_PERSON_STANCES, ...options.stances }\n const bob: FirstPersonBob = { ...FIRST_PERSON_BOB, ...options.bob }\n const blendSeconds = options.blend ?? DEFAULT_BLEND\n const clips = new Map<string, FirstPersonClip>((options.clips ?? []).map((clip) => [clip.id, clip]))\n\n const root = markKitOrigin(new THREE.Group(), { owner: 'game-characters-three', kind: 'person', id: 'first-person-arms' })\n root.name = 'first-person-arms'\n root.userData.viewmodel = true\n // a little of the colour glows by itself (`FILL`): the arms hang in the camera's space, where the scene's lights reach their undersides badly and a dark trouser would read as a hole\n const lit = (color: number): THREE_NS.MeshLambertMaterial => new THREE.MeshLambertMaterial({ color, emissive: scaleHex(color, FILL) })\n const materials = {\n skin: lit(colors.skin),\n sleeve: lit(colors.sleeve),\n cuff: lit(colors.cuff),\n trouser: lit(colors.trouser),\n shoe: lit(colors.shoe),\n sole: lit(scaleHex(colors.shoe, 0.55)),\n }\n const geometries: THREE_NS.BufferGeometry[] = []\n const Y = new THREE.Vector3(0, 1, 0)\n\n /** A tapered cylinder along +y from y = 0 (the wide end) to y = length, 8 sides. */\n const limb = (parent: THREE_NS.Object3D, wide: number, narrow: number, length: number, material: THREE_NS.Material): Segment => {\n const geometry = new THREE.CylinderGeometry(narrow, wide, length, 8, 1)\n geometry.translate(0, length / 2, 0)\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.frustumCulled = false\n mesh.userData.length = length\n parent.add(mesh)\n return mesh\n }\n const ball = (parent: THREE_NS.Object3D, radius: number, material: THREE_NS.Material): THREE_NS.Mesh => {\n const geometry = new THREE.SphereGeometry(radius, ELBOW_SEGMENTS, 6)\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.frustumCulled = false\n parent.add(mesh)\n return mesh\n }\n const place = (segment: Segment, from: THREE_NS.Vector3, to: THREE_NS.Vector3): void => {\n const direction = new THREE.Vector3().subVectors(to, from)\n const length = direction.length()\n segment.position.copy(from)\n if (length > 1e-6) segment.quaternion.setFromUnitVectors(Y, direction.divideScalar(length))\n segment.scale.y = length / (segment.userData.length as number)\n }\n\n const arms: Record<'R' | 'L', Arm> = {} as Record<'R' | 'L', Arm>\n for (const side of ['R', 'L'] as const) {\n const sign = side === 'R' ? 1 : -1\n const hand = createHandMesh(THREE, materials.skin)\n const anchor = new THREE.Group()\n anchor.name = `first-person-hand-${side}`\n const mirror = new THREE.Group()\n mirror.scale.z = sign // the left hand is the right one mirrored about its z\n mirror.add(hand.root)\n anchor.add(mirror)\n root.add(anchor)\n const upper = limb(root, rig.radius.shoulder, rig.radius.elbow, rig.upper, materials.sleeve)\n const fore = limb(root, rig.radius.elbow, rig.radius.wrist, rig.fore, materials.sleeve)\n const cuff = limb(root, rig.radius.cuff, rig.radius.cuff, 0.03, materials.cuff)\n const elbow = ball(root, rig.radius.elbow * 1.02, materials.sleeve)\n elbow.name = `first-person-elbow-${side}`\n arms[side] = { side, sign, hand, anchor, upper, fore, cuff, elbow, shown: newPose(THREE), from: newPose(THREE), mode: null, blend: 1, drawn: newPose(THREE), joints: { shoulder: new THREE.Vector3(), elbow: new THREE.Vector3(), wrist: new THREE.Vector3() }, away: options.hideWhenIdle ? 1 : 0 }\n }\n\n // the right leg, shown only while a kick holds it: a trouser, a knee, a trouser, a shoe\n const leg = new THREE.Group()\n leg.name = 'first-person-leg'\n leg.visible = false\n root.add(leg)\n const thigh = limb(leg, 0.088, 0.068, rig.thigh, materials.trouser)\n const shin = limb(leg, 0.068, 0.05, rig.shin, materials.trouser)\n const knee = ball(leg, 0.07, materials.trouser)\n const shoe = new THREE.Group()\n const shoeBox = (sx: number, sy: number, sz: number, x: number, y: number, material: THREE_NS.Material): void => {\n const geometry = new THREE.BoxGeometry(sx, sy, sz)\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(x, y, 0)\n mesh.frustumCulled = false\n shoe.add(mesh)\n }\n shoeBox(0.27, 0.07, 0.1, 0.065, -0.05, materials.shoe)\n shoeBox(0.27, 0.025, 0.104, 0.065, -0.095, materials.sole)\n shoeBox(0.1, 0.05, 0.088, 0.17, -0.005, materials.shoe)\n leg.add(shoe)\n\n const shoulderOf = (sign: 1 | -1, out: THREE_NS.Vector3): THREE_NS.Vector3 => (sign === -1 && rig.shoulderLeft ? out.set(...rig.shoulderLeft) : out.set(rig.shoulder[0] * sign, rig.shoulder[1], rig.shoulder[2]))\n const poleOf = (sign: 1 | -1): THREE_NS.Vector3 => (sign === -1 && rig.elbowPoleLeft ? new THREE.Vector3(...rig.elbowPoleLeft) : new THREE.Vector3(rig.elbowPole[0] * sign, rig.elbowPole[1], rig.elbowPole[2]))\n const kneePole = new THREE.Vector3(...rig.kneePole)\n /** The shoulder-to-wrist distance past which the shoulder comes forward: the arm with its elbow at `reachBend` (law of cosines), else nearly straight. */\n const reachOf = (sign: 1 | -1): number => {\n const bend = rig.reachBend?.[sign === 1 ? 0 : 1]\n if (bend === undefined) return (rig.upper + rig.fore) * REACH_SLACK\n return Math.sqrt(rig.upper * rig.upper + rig.fore * rig.fore + 2 * rig.upper * rig.fore * Math.cos(bend))\n }\n const hip = new THREE.Vector3(...rig.hip)\n\n const euler = new THREE.Euler(0, 0, 0, 'YZX')\n const quaternionOf = (r: readonly [number, number, number]): THREE_NS.Quaternion => new THREE.Quaternion().setFromEuler(euler.set(r[0], r[1], r[2], 'YZX'))\n const restPose = (rest: RestPose, mirror: boolean, out: Pose): Pose => {\n out.p.set(...rest.p)\n out.q.copy(quaternionOf(rest.r))\n if (mirror) {\n out.p.x = -out.p.x\n out.q.copy(mirrorQuaternion(THREE, out.q))\n }\n out.grip = rest.grip ?? 0\n out.scale = 1\n return out\n }\n const DEFAULT_REST: RestPose = { p: [0.17, -0.3, -0.3], r: [0, 1.5, 0], grip: 0.3 }\n const stanceRest = (id: string, side: 'R' | 'L', out: Pose): Pose => {\n const stance = stances[id] ?? stances.relaxed\n const right = stance?.R ?? DEFAULT_REST\n const left = stance?.L\n if (side === 'R') return restPose(right, false, out)\n return left && left !== 'mirror' ? restPose(left, false, out) : restPose(right, true, out)\n }\n\n const camPosition = new THREE.Vector3()\n const camQuaternion = new THREE.Quaternion()\n const camInverse = new THREE.Quaternion()\n const clamped = newPose(THREE)\n const probeAt = new THREE.Vector3()\n const probeForward = new THREE.Vector3()\n const probeFingers = new THREE.Vector3()\n /** Set each update when the host can answer where the world is in front of the camera (`contact` of the state). */\n let contact: ((origin: [number, number, number], direction: [number, number, number], maxDistance: number) => number | null) | undefined\n /**\n * Keeps a hand (or the foot) in front of the surface it would go into: the surface along the camera's forward through the hand's place, minus how far the hand reaches forward (its fingers when they point\n * ahead) and a few millimetres. The IK then bends the elbow instead of the hand entering the mesh. Never closer to the eye than `CONTACT_MIN`.\n */\n const keepOutside = (pose: Pose, reach: number): Pose => {\n if (!contact) return pose\n probeAt.set(pose.p.x, pose.p.y, 0).applyQuaternion(camQuaternion).add(camPosition)\n probeForward.set(0, 0, -1).applyQuaternion(camQuaternion)\n const distance = contact([probeAt.x, probeAt.y, probeAt.z], [probeForward.x, probeForward.y, probeForward.z], CONTACT_PROBE)\n if (distance === null) return pose\n const limit = Math.max(CONTACT_MIN, distance - reach - CONTACT_MARGIN)\n if (-pose.p.z <= limit) return pose\n copyPose(clamped, pose)\n clamped.p.z = -limit\n return clamped\n }\n /** How far a hand reaches forward of its middle: the fingers when they point ahead, else the thickness of the palm. */\n const forward = (pose: Pose, length: number): number => Math.max(CONTACT_PALM, -probeFingers.set(1, 0, 0).applyQuaternion(pose.q).z * length * pose.scale)\n const handReach = (pose: Pose): number => forward(pose, 0.085)\n const camScale = new THREE.Vector3()\n const toCamera = (target: HandPose, grip: number, scale: number, out: Pose): Pose => {\n out.p.set(...target.position).sub(camPosition).applyQuaternion(camInverse)\n out.q.set(...target.quaternion).premultiply(camInverse)\n out.grip = grip\n out.scale = scale\n return out\n }\n\n const listeners = new Set<(event: FirstPersonEvent) => void>()\n /** `left`: the foot is the left one; `swap`: the hands swap sides in a mirror. */\n let run: { clip: FirstPersonClip; time: number; left: boolean; swap: boolean } | null = null\n const emit = (event: FirstPersonEvent): void => {\n for (const listener of listeners) listener(event)\n }\n const fire = (clip: FirstPersonClip, from: number, to: number): void => {\n for (const event of clipEventsBetween(clip, from, to)) emit({ ...event, clip: clip.id })\n }\n\n let stanceId = 'relaxed'\n let phase = 0\n let swing = 0\n let sink = 0\n let first = true\n const bobOffset = new THREE.Vector3()\n const desired = newPose(THREE)\n const channelPose = newPose(THREE)\n const mixed = newPose(THREE)\n const dropped = newPose(THREE)\n // the index finger of each hand that holds a trigger (`HandTargets.fingers` for the right, `fingersL` for the left)\n const indexCurl: { R: number | undefined; L: number | undefined } = { R: undefined, L: undefined }\n const bone = createTwoBone(THREE)\n const shoulder = new THREE.Vector3()\n const wristAt = new THREE.Vector3()\n const palmAt = new THREE.Vector3()\n const fingers = new THREE.Vector3()\n const towards = new THREE.Vector3()\n\n /** The hand of the clip's channel, in the camera's space, as a pose. */\n /** `from`: the side the channel was written for (the other one when the hands swap); numbers written for the right hand, or the right's in a mirror, are mirrored onto the left and the other way round. */\n const fromChannel = (channel: FirstPersonSampleChannel, side: 'R' | 'L', base: Pose, out: Pose, from: 'R' | 'L' = side): Pose => {\n out.p.set(...channel.p)\n out.q.copy(quaternionOf(channel.r))\n const rightNumbers = from === 'R' || channel.mirror\n if (rightNumbers !== (side === 'R')) {\n out.p.x = -out.p.x\n out.q.copy(mirrorQuaternion(THREE, out.q))\n }\n out.grip = channel.grip ?? base.grip\n out.scale = base.scale\n return out\n }\n\n /** Where the elbow goes when it is put in the view (`elbowView`); the shoulder follows it, out of the view. */\n const elbowAt = new THREE.Vector3()\n const viewOf = (camera: THREE_NS.Object3D): View | null => {\n const lens = camera as THREE_NS.PerspectiveCamera\n if (!lens.isPerspectiveCamera) return null\n const tanV = Math.tan((lens.fov * Math.PI) / 360)\n return { tanV, tanH: tanV * lens.aspect }\n }\n /** Sets `elbowAt` a forearm from the wrist along `elbowView`, pulled inside the view, and `shoulder` an upper arm behind it toward the body's shoulder; false when the rig has no `elbowView`. */\n const placeElbowInView = (sign: 1 | -1, view: View): boolean => {\n const way = rig.elbowView?.[sign === 1 ? 0 : 1]\n if (!way) return false\n elbowAt.set(way[0], way[1], way[2]).setLength(rig.fore).add(wristAt)\n for (let pass = 0; pass < ELBOW_VIEW_PASSES; pass++) {\n const depth = Math.max(0.05, -elbowAt.z)\n const high = view.tanV * ELBOW_VIEW_MARGIN * depth\n const wide = view.tanH * ELBOW_VIEW_MARGIN * depth\n elbowAt.y = Math.max(elbowAt.y, -high)\n elbowAt.x = Math.min(wide, Math.max(-wide, elbowAt.x))\n elbowAt.sub(wristAt).setLength(rig.fore).add(wristAt)\n }\n shoulder.sub(elbowAt).setLength(rig.upper).add(elbowAt)\n return true\n }\n const drawArm = (arm: Arm, pose: Pose, view: View | null): void => {\n copyPose(arm.drawn, pose)\n const scale = pose.scale\n // the wrist is where the forearm ends: behind the palm along the fingers\n fingers.set(1, 0, 0).applyQuaternion(pose.q)\n wristAt.copy(pose.p).addScaledVector(fingers, -rig.wrist * scale)\n shoulderOf(arm.sign, shoulder).add(bobOffset)\n if (view && placeElbowInView(arm.sign, view)) {\n solveTwoBone(shoulder, wristAt, rig.upper, rig.fore, towards.copy(elbowAt).sub(shoulder).add(elbowAt).sub(wristAt), bone)\n finishArm(arm, pose, scale)\n return\n }\n // an arm that cannot reach brings its shoulder forward, toward the hand, up to `reachShift`: the shoulders are never on screen, so a weapon held out at the length of a rifle stays in the\n // hands, with the elbow still bent by `reachBend`\n const excess = shoulder.distanceTo(wristAt) - reachOf(arm.sign)\n if (excess > 0 && rig.reachShift > 0) shoulder.addScaledVector(towards.subVectors(wristAt, shoulder).normalize(), Math.min(excess, rig.reachShift))\n solveTwoBone(shoulder, wristAt, rig.upper, rig.fore, poleOf(arm.sign), bone)\n finishArm(arm, pose, scale)\n }\n\n /** Puts the hand on the end of the forearm (out of reach, short of the target) and the sleeve on the bones `bone` holds. */\n const finishArm = (arm: Arm, pose: Pose, scale: number): void => {\n palmAt.copy(bone.end).addScaledVector(fingers, rig.wrist * scale)\n arm.drawn.p.copy(palmAt)\n arm.anchor.position.copy(palmAt)\n arm.anchor.quaternion.copy(pose.q)\n arm.anchor.scale.setScalar(scale)\n arm.hand.setGrip(pose.grip)\n arm.hand.setIndex(indexCurl[arm.side])\n arm.joints.shoulder.copy(shoulder)\n arm.joints.elbow.copy(bone.joint)\n arm.joints.wrist.copy(bone.end)\n place(arm.upper, shoulder, bone.joint)\n place(arm.fore, bone.joint, bone.end)\n arm.elbow.position.copy(bone.joint)\n // the cuff sits at the end of the forearm, a little onto the wrist\n const toWrist = new THREE.Vector3().subVectors(bone.end, bone.joint).normalize()\n place(arm.cuff, new THREE.Vector3().copy(bone.end).addScaledVector(toWrist, -0.02), new THREE.Vector3().copy(bone.end).addScaledVector(toWrist, 0.012))\n }\n\n const footPose = newPose(THREE)\n const footRest = newPose(THREE)\n const ankle = new THREE.Vector3()\n const hipMirrored = new THREE.Vector3(-hip.x, hip.y, hip.z)\n const kneePoleMirrored = new THREE.Vector3(-kneePole.x, kneePole.y, kneePole.z)\n const drawLeg = (pose: Pose, left: boolean): void => {\n const origin = left ? hipMirrored : hip\n solveTwoBone(origin, pose.p, rig.thigh, rig.shin, left ? kneePoleMirrored : kneePole, bone)\n ankle.copy(bone.end)\n place(thigh, origin, bone.joint)\n place(shin, bone.joint, ankle)\n knee.position.copy(bone.joint)\n shoe.position.copy(ankle)\n shoe.quaternion.copy(pose.q)\n }\n\n const modeOf = (key: string, arm: Arm): void => {\n if (arm.mode === key) return\n copyPose(arm.from, arm.shown)\n arm.mode = key\n arm.blend = first ? 1 : 0\n }\n\n return {\n root,\n get playing() {\n return run ? run.clip.id : null\n },\n get stance() {\n return stanceId\n },\n play(id, options) {\n const clip = clips.get(id)\n if (!clip) return false\n run = { clip, time: 0, left: options?.leg === 'left', swap: options?.hand === 'left' }\n fire(clip, -1e-9, 0) // the events at t = 0 fire as the clip starts\n return true\n },\n stop() {\n run = null\n },\n update(dt, state) {\n const { camera } = state\n contact = state.contact\n camera.updateWorldMatrix(true, false)\n camera.matrixWorld.decompose(camPosition, camQuaternion, camScale)\n camInverse.copy(camQuaternion).invert()\n root.position.copy(camPosition)\n root.quaternion.copy(camQuaternion)\n root.updateMatrixWorld(true)\n\n // walk bob: the shoulders (and the hands at rest) sway and rise with the stride, more when running, less when still; crouching sinks them\n const speed = state.speed ?? 0\n const target = Math.min(1, speed / bob.fullSpeed) * (state.running ? bob.run : 1)\n swing += (target - swing) * Math.min(1, dt * 8)\n phase += dt * speed * bob.frequency\n sink += ((state.crouch ? 1 : 0) - sink) * Math.min(1, dt * 8)\n bobOffset.set(Math.sin(phase) * bob.x * swing, Math.sin(phase * 2) * bob.y * swing - bob.crouch * sink, 0)\n\n stanceId = state.stance ?? 'relaxed'\n const stance = stances[stanceId] ?? stances.relaxed\n const targets = state.targets ?? null\n\n // where the clip is now\n if (run) {\n const from = run.time\n run.time += dt\n fire(run.clip, from, Math.min(run.time, run.clip.duration))\n }\n const sample = run ? sampleFirstPersonClip(run.clip, Math.min(run.time, run.clip.duration)) : null\n\n for (const side of ['R', 'L'] as const) {\n const arm = arms[side]\n const target = targets?.[side]\n let mode: string\n if (stance?.follow && target) {\n mode = 'target'\n toCamera(target, (side === 'L' ? targets?.gripL : undefined) ?? targets?.grip ?? 1, targets?.scale ?? 1, desired)\n } else {\n mode = `rest:${stance?.follow ? (stance.fallback ?? 'relaxed') : stanceId}`\n stanceRest(stance?.follow ? (stance.fallback ?? 'relaxed') : stanceId, side, desired)\n desired.p.add(bobOffset)\n }\n modeOf(mode, arm)\n indexCurl[side] = mode === 'target' ? (side === 'R' ? targets?.fingers?.index : targets?.fingersL?.index) : undefined\n arm.blend = blendSeconds <= 0 ? 1 : Math.min(1, arm.blend + dt / blendSeconds)\n if (arm.blend >= 1) copyPose(arm.shown, desired)\n else mixPose(THREE, arm.shown, arm.from, desired, ease(arm.blend))\n const from = run?.swap ? (side === 'R' ? 'L' : 'R') : side\n const channel = sample?.[from]\n let pose: Pose\n if (channel && channel.w > 0) {\n fromChannel(channel, side, arm.shown, channelPose, from)\n mixPose(THREE, mixed, arm.shown, channelPose, channel.w)\n pose = mode === 'target' ? mixed : keepOutside(mixed, handReach(mixed))\n } else pose = mode === 'target' ? arm.shown : keepOutside(arm.shown, handReach(arm.shown))\n // nothing to do with the hands (walking, standing): they drop out of the view and are not drawn, as a person's hands do not hang in front of their eyes\n const idle = options.hideWhenIdle === true && mode === 'rest:relaxed' && !(channel && channel.w > 0)\n arm.away = options.hideWhenIdle ? Math.min(1, Math.max(0, arm.away + ((idle ? 1 : 0) - arm.away) * Math.min(1, dt * (idle ? AWAY_OUT : AWAY_IN)))) : 0\n if (arm.away > 0) {\n copyPose(dropped, pose)\n dropped.p.y -= AWAY_DROP * ease(arm.away)\n pose = dropped\n }\n drawArm(arm, pose, mode === 'target' && targets?.elbows !== 'body' ? viewOf(state.camera) : null)\n const shown = arm.away < AWAY_HIDDEN\n for (const part of [arm.anchor, arm.upper, arm.fore, arm.cuff, arm.elbow]) part.visible = shown\n }\n\n // the leg of a kick\n const foot = sample?.F\n leg.visible = !!foot && foot.w > FOOT_SHOWN\n if (foot && leg.visible) {\n restPose(rig.foot, false, footRest)\n fromChannel(foot, 'R', footRest, footPose)\n mixPose(THREE, mixed, footRest, footPose, foot.w)\n copyPose(footPose, mixed)\n // the left leg is the right one in a mirror\n if (run?.left) {\n footPose.p.x = -footPose.p.x\n footPose.q.copy(mirrorRotation(THREE, footPose.q))\n }\n drawLeg(contact ? keepOutside(footPose, forward(footPose, FOOT_LENGTH)) : footPose, run?.left ?? false)\n }\n if (run && run.time >= run.clip.duration) run = null\n first = false\n },\n on(_type, listener) {\n listeners.add(listener)\n return () => void listeners.delete(listener)\n },\n joints(side) {\n const { shoulder, elbow, wrist } = arms[side].joints\n return { shoulder: shoulder.clone(), elbow: elbow.clone(), wrist: wrist.clone() }\n },\n handPose(side) {\n const pose = arms[side].drawn\n return { position: pose.p.clone(), quaternion: pose.q.clone(), grip: pose.grip }\n },\n dispose() {\n run = null\n listeners.clear()\n for (const arm of Object.values(arms)) arm.hand.dispose()\n for (const geometry of geometries) geometry.dispose()\n for (const material of Object.values(materials)) material.dispose()\n root.removeFromParent()\n },\n }\n}\n","{\n \"source\": {\n \"note\": \"Authored in the kit: no team delivered first-person arms. The rig is in metres in the camera's space (x right, y up, the view looks down -z); rest poses use the hand frame of HandPose in game-contracts, Euler [roll, yaw, pitch] in the order YZX (yaw pi/2 points the fingers forward).\"\n },\n \"rig\": {\n \"shoulder\": [0.16, -0.36, 0.18],\n \"upper\": 0.32,\n \"fore\": 0.3,\n \"reachShift\": 0.42,\n \"reachBend\": [1.35, 0.95],\n \"elbowView\": [[0.96, -0.26, -0.06], null],\n \"wrist\": 0.07,\n \"elbowPole\": [0.45, -1, 0.2],\n \"shoulderLeft\": [-0.07, -0.46, 0.18],\n \"elbowPoleLeft\": [-0.1, -1, 0.2],\n \"radius\": { \"shoulder\": 0.04, \"elbow\": 0.034, \"wrist\": 0.028, \"cuff\": 0.031 },\n \"hip\": [0.12, -0.82, 0.04],\n \"thigh\": 0.46,\n \"shin\": 0.46,\n \"kneePole\": [0.1, 0.5, -1],\n \"foot\": { \"p\": [0.13, -0.85, -0.05], \"r\": [0, 1.5708, 0] }\n },\n \"stances\": {\n \"relaxed\": {\n \"R\": { \"p\": [0.2, -0.22, -0.36], \"r\": [0.05, 1.57, -0.05], \"grip\": 0.2 },\n \"L\": \"mirror\"\n },\n \"fists\": {\n \"R\": { \"p\": [0.15, -0.12, -0.4], \"r\": [0, 1.5, 0.15], \"grip\": 1 },\n \"L\": \"mirror\"\n },\n \"hold\": { \"follow\": true, \"fallback\": \"relaxed\" }\n },\n \"bob\": { \"frequency\": 2.3, \"x\": 0.006, \"y\": 0.008, \"run\": 1.5, \"fullSpeed\": 4, \"crouch\": 0.02 }\n}\n","import { buildHand } from '../rich/accessories/hands'\nimport type { THREE_NS } from '../three'\n\ntype Three = typeof THREE_NS\n\n/** The palm of the Retratos do Vale hand (the same one the player's body wears in third person): a flattened ball this far down the hand from the wrist. */\nconst PALM = { radius: 0.048, scale: [0.6, 1.05, 1] as const, down: 0.035 }\n/** How far the fingers curl at a full grip (radians), the near and the far joint, as the body's hand (`avatar.ts`) closes them. */\nconst CURL = { closed: 1.25, near: 0.9, far: 1.1 }\nconst THUMB = { open: 0.32, closed: 0.25 }\n\nexport type HandMesh = {\n /** The hand with its origin at the middle of the palm: x to the knuckles, y the back of the hand, z the little-finger side (the thumb at -z). */\n root: THREE_NS.Group\n /** 0 open, 1 closed on a grip. */\n setGrip(grip: number): void\n /** Curls the index finger on its own (0 extended, 1 curled); `undefined` gives it back to the grip. */\n setIndex(curl: number | undefined): void\n dispose(): void\n}\n\n/**\n * The first-person hand: the Retratos do Vale hand (a rounded palm, four fingers of two joints and a thumb, `buildHand`), the one the player's body wears in third person, turned\n * to the hand frame of `HandPose`. A left hand is made by mirroring the group (`scale.z = -1`).\n */\nexport const createHandMesh = (THREE: Three, skin: THREE_NS.Material, wristSkin: THREE_NS.Material = skin): HandMesh => {\n const root = new THREE.Group()\n root.name = 'first-person-hand'\n const geometries: THREE_NS.BufferGeometry[] = []\n const add = (parent: THREE_NS.Object3D, geometry: THREE_NS.BufferGeometry, material: THREE_NS.Material, x = 0, y = 0, z = 0): THREE_NS.Mesh => {\n geometries.push(geometry)\n const mesh = new THREE.Mesh(geometry, material)\n mesh.position.set(x, y, z)\n mesh.frustumCulled = false\n parent.add(mesh)\n return mesh\n }\n // the team's hand hangs its fingers down -y with the palm toward +x (a right hand) and the thumb in front (+z): as the hand frame, its -y is x, its -x is y and its -z is z\n const group = new THREE.Group()\n group.quaternion.setFromRotationMatrix(new THREE.Matrix4().makeBasis(new THREE.Vector3(0, -1, 0), new THREE.Vector3(-1, 0, 0), new THREE.Vector3(0, 0, -1)))\n group.position.set(-PALM.down, 0, 0)\n root.add(group)\n add(group, new THREE.SphereGeometry(PALM.radius, 14, 10), skin, 0, -PALM.down, 0).scale.set(...PALM.scale)\n const built = buildHand({ THREE, add, hg: group, handM: skin, s: -1, detailed: true }) as { fingers: THREE_NS.Object3D[]; th: THREE_NS.Object3D | null }\n // the wrist the hand grows from, where the sleeve ends\n const wristGeometry = new THREE.CylinderGeometry(0.03, 0.033, 0.05, 10)\n wristGeometry.rotateZ(Math.PI / 2)\n add(root, wristGeometry, wristSkin, -PALM.down - 0.03, 0, 0)\n\n let lastGrip = 0\n let indexCurl: number | undefined\n const curlFinger = (finger: number, k: number): void => {\n built.fingers[finger * 2]!.rotation.z = k * CURL.closed * CURL.near\n built.fingers[finger * 2 + 1]!.rotation.z = k * CURL.closed * CURL.far\n }\n const applyIndex = (): void => curlFinger(0, indexCurl === undefined ? lastGrip : Math.min(1, Math.max(0, indexCurl)))\n const setGrip = (grip: number): void => {\n lastGrip = Math.min(1, Math.max(0, grip))\n for (let finger = 1; finger < 4; finger++) curlFinger(finger, lastGrip)\n if (built.th) built.th.rotation.z = THUMB.open + lastGrip * THUMB.closed\n applyIndex()\n }\n const setIndex = (value: number | undefined): void => {\n indexCurl = value\n applyIndex()\n }\n setGrip(0)\n return {\n root,\n setGrip,\n setIndex,\n dispose() {\n for (const geometry of geometries) geometry.dispose()\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;A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,UAAU,OAAO,QAAQ;AAAA,IAC7C;AAAA,IACA,OAAO,MAAM;AACX,YAAM,EAAE,UAAAC,WAAU,OAAO,MAAM,IAAI,KAAK,IAAI,EAAE;AAC9C,aAAO,EAAE,UAAUA,UAAS,MAAM,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM,MAAM,EAAE;AAAA,IAClF;AAAA,IACA,SAAS,MAAM;AACb,YAAM,OAAO,KAAK,IAAI,EAAE;AACxB,aAAO,EAAE,UAAU,KAAK,EAAE,MAAM,GAAG,YAAY,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,KAAK;AAAA,IACjF;AAAA,IACA,UAAU;AACR,YAAM;AACN,gBAAU,MAAM;AAChB,iBAAW,OAAO,OAAO,OAAO,IAAI,EAAG,KAAI,KAAK,QAAQ;AACxD,iBAAW,YAAY,WAAY,UAAS,QAAQ;AACpD,iBAAW,YAAY,OAAO,OAAO,SAAS,EAAG,UAAS,QAAQ;AAClE,WAAK,iBAAiB;AAAA,IACxB;AAAA,EACF;AACF;","names":["tag","shapeGeometries","createRng","distance","distance","TWO_PI","createRng","bob","raise","tilt","options","clipEventsBetween","hexOf","distance","clipEventsBetween","options","target","shoulder"]}