A mech game prototype, pushed by Gemini 4 Argon
agent (cont.)
+33:58read_file{"EndLine":383,"Path":"~/work/sortie/kit/figure.py","StartLine":310}
input
{ "EndLine": 383, "Path": "~/work/sortie/kit/figure.py", "StartLine": 310 }result, 75 lines
Showing lines 310-383 of 383 310: out.append(("shin", acc, plate(sh, .02, side([(-.2, .23), (.0, .23), (.0, .43), (-.2, .43)], k=0), 311: front(mx([(.093, .23), (.107, .23), (.107, .43), (.093, .43)], sx), k=0), sx=sx))) 312: # boot shaft and its top band 313: boot = [S(.07, .084, .11, x=x, y=.02), S(.13, .086, .1, x=x, y=.015), S(.22, .092, .106, x=x, y=.014), S(.255, .096, .11, x=x, y=.014)] 314: out.append(("shin", "main", form(boot, sx=sx, sharp=50))) 315: out.append(("shin", "accent", form([S(.235, .1, .114, x=x, y=.014), S(.265, .102, .116, x=x, y=.014)], sx=sx, sharp=50))) 316: return out 317: 318: 319: def foot(sx): 320: x = .1 * sx 321: # the foot lofted heel to toe along -Y: (x, z) outlines 322: secs = [(.08, .068, .07, .045), (.04, .084, .1, .058), (-.04, .088, .08, .05), (-.12, .088, .06, .04), (-.175, .07, .042, .03), 323: (-.195, .045, .026, .022)] 324: bm = subd(loft([(y, ell(w, h, x, zc, 2.6)) for y, w, h, zc in secs], axis="y"), 2, sharp=70) 325: sole = subd(loft([(y, ell(w + .006, .022, x, .011, 4)) for y, w, _, _ in secs], axis="y"), 1, sharp=70) 326: return [("foot", "main", bm), ("foot", "joint", sole)] 327: 328: 329: # ---- the helmet -------------------------------------------------------------------------------------------- 330: SHELL = [S(1.5, .14, .15, y=.02), S(1.53, .2, .23), S(1.58, .245, .272, y=.002), S(1.65, .258, .288, y=.006), 331: S(1.72, .24, .27, y=.012), S(1.77, .18, .21, y=.018), S(1.795, .08, .1, y=.02)] 332: VISOR = [(-.1, 1.6), (.1, 1.6), (.122, 1.645), (.112, 1.69), (.06, 1.705), (-.06, 1.705), (-.112, 1.69), (-.122, 1.645)] 333: 334: 335: def helmet(acc): 336: out = [] 337: shell = cut(form(SHELL, sharp=60), front(VISOR, -1, -.02, k=1), "DIFFERENCE") 338: # the shell in two plates: a white crown and a jaw in the accent, the seam rising toward the back 339: jaw, crown = halves(shell, (0, 0, 1.6), (0, -.4, 1), .008) 340: out += [("head", "main", crown), ("head", "accent", jaw)] 341: out.append(("head", "visor", plate(SHELL, -.012, front(VISOR, -1, -.0, k=1)))) 342: # crest stripe from the brow over the crown, a short fin at its front 343: out.append(("head", acc, plate(SHELL, .007, side([(-.2, 1.69), (.12, 1.69), (.12, 1.9), (-.2, 1.9)], k=0), 344: box(-.015, .015, -1, 1, 1.6, 1.9)))) 345: out.append(("head", acc, form([S(1.703, .018, .03, y=-.133), S(1.74, .014, .07, y=-.124), S(1.765, .008, .05, y=-.11)], lv=1, sharp=40))) 346: # brow plate over the visor 347: out.append(("head", "main", plate(SHELL, .009, front([(-.12, 1.702), (.12, 1.702), (.1, 1.732), (-.1, 1.732)], -1, -.04, k=1)))) 348: # ear pods with an accent ring 349: for sx in (1, -1): 350: pod = loft([(.116, ell(.075, .075, .005, 1.645)), (.14, ell(.072, .072, .005, 1.645)), (.149, ell(.052, .052, .005, 1.645))], axis="x") 351: out.append(("head", "main", mirror(subd(pod, 2, sharp=50), sx))) 352: ringb = loft([(.145, ell(.034, .034, .005, 1.645)), (.154, ell(.03, .03, .005, 1.645))], axis="x") 353: out.append(("head", acc, mirror(subd(ringb, 1, sharp=50), sx))) 354: out.append(("head", "suit", form([S(1.47, .11, .11, y=.015), S(1.56, .1, .1, y=.015)]))) 355: return out 356: 357: 358: # ---- assembly ---------------------------------------------------------------------------------------------- 359: def pilot(parent, at=(0.0, 0.0), n="pilot", role="hazard", pose="stand", z=0.0, turn=0.0, skip=(), parents=None): 360: """Build the pilot under `parent`, the rest pose's feet at `at` and height z, turned `turn` degrees 361: about Z (0 faces -Y), in a pose. `skip` 362: drops parts by joint ("head", "chest", ...), for a cockpit seen from the pilot's own eye. 363: `parents` hangs joints on other objects ({"hand.L": stick}), so hands follow a moving grip. 364: Returns points(pose) at that placement.""" 365: acc = "trim" if role == "hazard" else role 366: P = POSES[pose] 367: parts = torso(acc) + ([] if "head" in skip else helmet(acc)) 368: for sx, s in ((1, "L"), (-1, "R")): 369: side_parts = arm(sx, acc) + hand(sx, P["fingers"], P["thumb"]) + leg(sx, acc) + foot(sx) 370: parts += [(f"{j}.{s}", r, bm) for j, r, bm in side_parts] 371: M = rig(pose) 372: off = place(at, z, turn) 373: groups = {} 374: for joint, r, bm in parts: 375: if joint.split(".")[0] in skip: 376: bm.free() 377: continue 378: transform(bm, off @ M[joint]) 379: groups.setdefault((joint, r), []).append(bm) 380: for (joint, r), bms in groups.items(): 381: solid(f"{n}_{joint.replace('.', '_')}_{r}", merge(*bms), r, (parents or {}).get(joint, parent), smooth=True, panels=False) 382: return points(pose, at, z, turn) 383:
agent
+34:07reasoning
I'm thinking through how to approach this.
The modifications aim to prevent clipping issues with the knight model. Removing the square mount-pad meshes should resolve interference with curved armor pieces like pauldrons and vambraces. Additionally, adding thruster nozzles to the lower leg bells in the "heavy" configuration will enhance the model.
read_file{"EndLine":170,"Path":"~/work/sortie/src/render/mech.ts","StartLine":1}
input
{ "EndLine": 170, "Path": "~/work/sortie/src/render/mech.ts", "StartLine": 1 }result, 171 lines
Showing lines 1-170 of 209 1: import * as THREE from 'three'; 2: import { find, nodes } from './assets'; 3: import { Exhaust, KINDS, type NozzleKind, type ThrustReading } from './exhaust'; 4: import { PALETTES, type PaletteName } from './palette'; 5: import { PLUME_HULL, plumeMaterial, plumeVisible, setPlume } from './plume'; 6: 7: /** Joint rotations in degrees, glTF axes: X pitches a limb (negative swings it forward), Z swings it 8: * sideways (positive moves a left limb outward), Y twists. */ 9: export type Pose = Partial<Record<Joint, [number, number, number]>>; 10: 11: export const JOINTS = [ 12: 'pelvis', 'waist', 'torso', 'neck', 'head', 'backpack', 13: 'shoulder.L', 'upperarm.L', 'forearm.L', 'hand.L', 'shoulder.R', 'upperarm.R', 'forearm.R', 'hand.R', 14: 'thigh.L', 'shin.L', 'foot.L', 'thigh.R', 'shin.R', 'foot.R', 'binder.L', 'binder.R', 15: ] as const; 16: export type Joint = (typeof JOINTS)[number]; 17: 18: export const POSES = { 19: stand: { 20: 'upperarm.L': [0, 0, 6], 'upperarm.R': [0, 0, -6], 'forearm.L': [-12, 0, 0], 'forearm.R': [-12, 0, 0], 21: }, 22: /** Standing on the catapult: knees bent, leaning into the launch. */ 23: launch: { 24: pelvis: [8, 0, 0], torso: [10, 0, 0], head: [-14, 0, 0], 25: 'thigh.L': [-38, 0, 2], 'thigh.R': [-38, 0, -2], 'shin.L': [58, 0, 0], 'shin.R': [58, 0, 0], 26: 'foot.L': [-20, 0, 0], 'foot.R': [-20, 0, 0], 27: 'upperarm.L': [-18, 0, 14], 'forearm.L': [-40, 0, 0], 'upperarm.R': [-30, 0, -8], 'forearm.R': [-50, 0, 0], 28: 'binder.L': [18, 0, 0], 'binder.R': [18, 0, 0], 29: }, 30: /** The launch crouch for a heavy: 24 m in a 26 m tube, so knees deep, head down and binders folded, 31: * which brings it under the tube's signal box. */ 32: launch_heavy: { 33: pelvis: [12, 0, 0], torso: [12, 0, 0], head: [-20, 0, 0], 34: 'thigh.L': [-58, 0, 3], 'thigh.R': [-58, 0, -3], 'shin.L': [106, 0, 0], 'shin.R': [106, 0, 0], 35: 'foot.L': [-48, 0, 0], 'foot.R': [-48, 0, 0], 36: 'upperarm.L': [-18, 0, 14], 'forearm.L': [-40, 0, 0], 'upperarm.R': [-30, 0, -8], 'forearm.R': [-50, 0, 0], 37: 'binder.L': [40, 0, 0], 'binder.R': [40, 0, 0], 38: }, 39: /** Free flight, rifle up. */ 40: flight: { 41: pelvis: [6, 0, 0], torso: [-4, 0, 0], head: [-2, 0, 0], 42: 'thigh.L': [-22, 0, 4], 'thigh.R': [6, 0, -3], 'shin.L': [42, 0, 0], 'shin.R': [30, 0, 0], 43: 'foot.L': [8, 0, 0], 'foot.R': [18, 0, 0], 44: 'upperarm.L': [-22, 0, 16], 'forearm.L': [-46, 0, 0], 45: 'upperarm.R': [-62, -8, -6], 'forearm.R': [-26, 0, 0], 'hand.R': [0, 0, 0], 46: 'binder.L': [-6, 0, 0], 'binder.R': [-6, 0, 0], 47: }, 48: } satisfies Record<string, Pose>; 49: export type PoseName = keyof typeof POSES; 50: 51: /** The catapult pose for a size class: the striker's, with a deeper crouch for heavies. */ 52: export const launchPose = (cls: string): Pose => (cls === 'heavy' ? POSES.launch_heavy : POSES.launch); 53: 54: export interface Nozzle { 55: node: THREE.Object3D; 56: dir: THREE.Vector3; // exhaust direction in the node's parent space 57: radius: number; 58: kind: NozzleKind; 59: plume: THREE.Mesh; 60: } 61: 62: const tmpQ = new THREE.Quaternion(); 63: const _sum = new THREE.Vector3(); 64: const _at = new THREE.Vector3(); 65: const _white = new THREE.Color(1, 1, 1); 66: const tmpE = new THREE.Euler(); 67: const D = THREE.MathUtils.DEG2RAD; 68: 69: /** A frame model's joints, posed by rotation, with weapons held at grip.R and thruster plumes. */ 70: export class MechRig { 71: readonly joints = new Map<Joint, THREE.Object3D>(); 72: readonly nozzles: Nozzle[] = []; 73: readonly cockpit: THREE.Object3D; 74: readonly grip: THREE.Object3D; 75: held: THREE.Object3D | null = null; 76: /** Plume state, stepped by thrust(). */ 77: readonly exhaust = new Exhaust(); 78: /** One plume material per nozzle kind: a kind fires together. */ 79: private plumeMats: Record<NozzleKind, THREE.ShaderMaterial>; 80: private exhaustColor: THREE.Color; 81: private targets = new Map<Joint, THREE.Quaternion>(); 82: 83: constructor(readonly root: THREE.Object3D) { 84: const map = nodes(root); 85: for (const j of JOINTS) { 86: const n = find(map, j); 87: if (n) this.joints.set(j, n); 88: } 89: this.cockpit = find(map, 'cockpit') ?? root; 90: this.grip = find(map, 'grip.R') ?? root; 91: const paint = PALETTES[(root.userData.palette as PaletteName | undefined) ?? 'merc'].glow_exhaust; 92: this.exhaustColor = new THREE.Color(paint.color); 93: this.plumeMats = { 94: main: plumeMaterial(this.exhaustColor, paint.glow ?? 1, 0), 95: binder: plumeMaterial(this.exhaustColor, paint.glow ?? 1, 17.3), 96: calf: plumeMaterial(this.exhaustColor, paint.glow ?? 1, 41.7), 97: }; 98: root.traverse((o) => { 99: const dir = o.userData.dir as number[] | undefined; 100: if (!dir || !/^nozzle/.test(o.name)) return; 101: const kind: NozzleKind = /main/.test(o.name) ? 'main' : /binder/.test(o.name) ? 'binder' : 'calf'; 102: const radius = (o.userData.radius as number) ?? 0.5; 103: // the plume's own space is in nozzle radii (render/plume.ts) 104: const plume = new THREE.Mesh(PLUME_HULL, this.plumeMats[kind]); 105: const d = new THREE.Vector3(...(dir as [number, number, number])); 106: plume.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), d); 107: plume.scale.setScalar(radius); 108: plume.visible = false; 109: plume.renderOrder = 2; 110: o.add(plume); 111: this.nozzles.push({ node: o, dir: d, radius, kind, plume }); 112: }); 113: } 114: 115: /** Any named node of the model (extras like harken.L), or null. */ 116: node(name: string): THREE.Object3D | null { 117: return find(nodes(this.root), name) ?? null; 118: } 119: 120: /** Snap to a pose. */ 121: apply(pose: Pose) { 122: for (const [j, node] of this.joints) { 123: const r = pose[j] ?? [0, 0, 0]; 124: node.quaternion.setFromEuler(tmpE.set(r[0] * D, r[1] * D, r[2] * D)); 125: } 126: } 127: 128: /** Snap to a pose and measure how high its soles sit above the root, in world metres (root 129: * upright). A crouch lifts the feet, so the frame drops by this much to stand on its clamps. */ 130: soles(pose: Pose): number { 131: this.apply(pose); 132: this.root.updateMatrixWorld(true); 133: const v = new THREE.Vector3(); 134: let min = Infinity; 135: for (const j of ['foot.L', 'foot.R'] as const) { 136: this.joints.get(j)?.traverse((o) => { 137: const p = (o as THREE.Mesh).isMesh ? (o as THREE.Mesh).geometry.attributes.position : null; 138: if (!p) return; 139: for (let i = 0; i < p.count; i++) min = Math.min(min, v.fromBufferAttribute(p, i).applyMatrix4(o.matrixWorld).y); 140: }); 141: } 142: return Number.isFinite(min) ? min - this.root.getWorldPosition(v).y : 0; 143: } 144: 145: /** Ease toward a blend of poses; weights need not sum to 1 (the rest is the rest pose). */ 146: blend(poses: [Pose, number][], rate: number, dt: number) { 147: const k = 1 - Math.exp(-rate * dt); 148: for (const [j, node] of this.joints) { 149: let x = 0, y = 0, z = 0; 150: for (const [p, w] of poses) { 151: const r = p[j]; 152: if (r) { 153: x += r[0] * w; 154: y += r[1] * w; 155: z += r[2] * w; 156: } 157: } 158: let t = this.targets.get(j); 159: if (!t) this.targets.set(j, (t = new THREE.Quaternion())); 160: t.setFromEuler(tmpE.set(x * D, y * D, z * D)); 161: node.quaternion.slerp(t, k); 162: } 163: } 164: 165: /** Turn one joint by an extra rotation on top of its current pose (aim, lean). */ 166: add(j: Joint, x: number, y: number, z: number) { 167: const n = this.joints.get(j); 168: if (n) n.quaternion.multiply(tmpQ.setFromEuler(tmpE.set(x * D, y * D, z * D))); 169: } 170:
agent
+34:23reasoning
The file src/render/mech.ts appears relevant to understanding the glTF axes within the rendering process. Examining how X, Z, and Y axes control limb movement and rotation will be key to understanding the rendering behavior. Specifically, X seems to pitch limbs forward/backward, Z swings limbs sideways, and Y twists around the vertical axis.
Torso/head Y-axis rotation confirmed: positive Y rotates the mech left (viewer's right), negative Y rotates right (viewer's left). Blender coordinate system check initiated using a shield on the left forearm and lance on the right hand. Located the left forearm joint position and planned to define a shield based on a band and radius centered there. The band parameters were determined.
The shield's parameters define a curved surface wrapping the forearm, with a keel ridge and blazon panel. The specified rotation angles of the upper and forearm joints result in the shield presenting at a 3/4 angle relative to the camera. The right hand's grip position and forward-pointing direction are confirmed in the Blender rest pose.
The lance's position in the rest pose aligns with the hand's rotation, confirming the natural rotation with J["hand", "R"]. Analyzing the joint rotations reveals that combined adjustments to upperarm.R, forearm.R, and hand.R achieve specific lance orientations in both flight and guard poses. The initial assumption that the arm hangs straight down from rest pose needs further consideration.
read_file{"EndLine":95,"Path":"~/work/sortie/kit/mech.py","StartLine":45}
input
{ "EndLine": 95, "Path": "~/work/sortie/kit/mech.py", "StartLine": 45 }result, 52 lines
Showing lines 45-95 of 400 45: d = Vector((direction[0] * sx, direction[1], direction[2])) 46: bell, glow = nozzle(r, length) 47: solid(f"{name}.{side}", place(bell, p, d), shell, j, smooth=True) 48: solid(f"{name}.{side}.glow", place(glow, p, d), "glow_thruster", j, outline=False) 49: # an armoured housing around the throat, so the nozzle reads as mounted, not floating 50: if housing: 51: house = loft([(length * .5, octo(r * 2.5, r * 2.5, r * .6)), (-length * .3, octo(r * 2.3, r * 2.3, r * .55))]) 52: solid(f"{name}_housing.{side}", place(house, p, d), "main", j, bevel=.02, panels=False) 53: empty(f"nozzle.{name}.{side}", p + d.normalized() * length, j, dir=gltf_dir(d), radius=r) 54: 55: 56: def seam(bm, a, b, gap=.05): 57: """Split a solid along the line a->b of the front view (x, z): two plates with a real seam.""" 58: a, b = Vector((a[0], 0, a[1])), Vector((b[0], 0, b[1])) 59: d = (b - a).normalized() 60: n = Vector((-d.z, 0, d.x)) 61: return halves(bm, a, n, gap) 62: 63: 64: def pair_pieces(name, pieces, role, jl, jr, **kw): 65: for i, bm in enumerate(pieces): 66: pair(f"{name}{i}", bm, role, jl, jr, **kw) 67: 68: 69: def joints(): 70: J = {"frame": empty("frame", (0, 0, 0), frame="striker", height=17.6)} 71: J["pelvis"] = empty("pelvis", (0, 0, 10.6), J["frame"]) 72: J["waist"] = empty("waist", (0, 0, 11.1), J["pelvis"]) 73: J["torso"] = empty("torso", (0, 0, 11.9), J["waist"]) 74: J["neck"] = empty("neck", (0, 0, 15.3), J["torso"]) 75: J["head"] = empty("head", (0, 0, 15.85), J["neck"]) 76: J["backpack"] = empty("backpack", (0, 1.5, 13.8), J["torso"]) 77: J["cockpit"] = empty("cockpit", (0, -0.75, 13.7), J["torso"]) 78: for s, sx in (("L", 1), ("R", -1)): 79: J["shoulder", s] = empty(f"shoulder.{s}", (2.0 * sx, 0, 14.6), J["torso"]) 80: J["upperarm", s] = empty(f"upperarm.{s}", (2.45 * sx, 0, 14.4), J["shoulder", s]) 81: J["forearm", s] = empty(f"forearm.{s}", (2.5 * sx, 0, 11.95), J["upperarm", s]) 82: J["hand", s] = empty(f"hand.{s}", (2.5 * sx, 0, 9.6), J["forearm", s]) 83: J["grip", s] = empty(f"grip.{s}", (2.36 * sx, -0.02, 9.12), J["hand", s]) 84: J["thigh", s] = empty(f"thigh.{s}", (1.15 * sx, 0, 10.55), J["pelvis"]) 85: J["shin", s] = empty(f"shin.{s}", (1.2 * sx, 0, 6.1), J["thigh", s]) 86: J["foot", s] = empty(f"foot.{s}", (1.2 * sx, 0.1, 1.55), J["shin", s]) 87: J["binder", s] = empty(f"binder.{s}", (0.9 * sx, 2.25, 14.7), J["backpack"]) 88: return J 89: 90: 91: def lr(J, part): 92: return J[part, "L"], J[part, "R"] 93: 94: 95: def build_pelvis(J):read_file{"EndLine":209,"Path":"~/work/sortie/src/render/mech.ts","StartLine":165}
input
{ "EndLine": 209, "Path": "~/work/sortie/src/render/mech.ts", "StartLine": 165 }result, 46 lines
Showing lines 165-209 of 209 165: /** Turn one joint by an extra rotation on top of its current pose (aim, lean). */ 166: add(j: Joint, x: number, y: number, z: number) { 167: const n = this.joints.get(j); 168: if (n) n.quaternion.multiply(tmpQ.setFromEuler(tmpE.set(x * D, y * D, z * D))); 169: } 170: 171: /** Put a weapon in the right hand: barrel along the forearm, handle in the fist. */ 172: hold(weapon: THREE.Object3D | null) { 173: if (this.held && this.held !== weapon) this.held.removeFromParent(); 174: this.held = weapon; 175: if (!weapon) return; 176: this.grip.add(weapon); 177: weapon.position.set(0, 0, 0); 178: weapon.quaternion.setFromEuler(tmpE.set(Math.PI / 2, 0, 0)); 179: } 180: 181: /** Step the plumes from this frame's flight reading and draw them. `time` drives the turbulence. */ 182: thrust(r: ThrustReading, time: number, dt: number) { 183: this.exhaust.step(r, dt); 184: for (const k of KINDS) setPlume(this.plumeMats[k], this.exhaust.plumes[k], time); 185: for (const n of this.nozzles) n.plume.visible = plumeVisible(this.exhaust.plumes[n.kind]); 186: } 187: 188: /** Put `light` at the burning plumes' weighted centre, as bright as they burn: the glow the 189: * exhaust throws on the frame. A light costs every lit pixel, so a scene gives one to the player 190: * and the nearest few frames at most, and keeps the count fixed (a change recompiles shaders). */ 191: lightExhaust(light: THREE.PointLight, strength = 1) { 192: let w = 0; 193: _sum.set(0, 0, 0); 194: const s = this.root.scale.x; 195: for (const n of this.nozzles) { 196: const p = this.exhaust.plumes[n.kind]; 197: const k = (Math.min(1, p.level) * (1 + 0.5 * p.heavy) + 0.4 * p.flash) * (n.radius * s) ** 2; 198: if (k <= 0 || !n.plume.visible) continue; 199: // a little way downstream, where the plume is brightest 200: n.plume.localToWorld(_at.set(0, 0, 2.5)); 201: _sum.addScaledVector(_at, k); 202: w += k; 203: } 204: light.visible = true; 205: light.color.copy(this.exhaustColor).lerp(_white, 0.4); 206: light.intensity = w > 0 ? w * 35 * strength : 0; 207: if (w > 0) light.position.copy(_sum).divideScalar(w); 208: } 209: }
agent
+34:49reasoning
The code comment describes weapon placement: barrel along the forearm, handle in the fist. The forearm's rest pose is along the negative Z-axis, implying the weapon's barrel should align with this axis.
The forearm's negative Z in Blender corresponds to negative Y in glTF. A weapon aligned with this axis will point forward when the arm pitches as described. Calculation confirms that a weapon parented to the hand with a slight forward tilt will point horizontally in a "guard" pose and diagonally downwards in a "stand" pose, consistent with expectations. These checks suggest the weapon's initial orientation and parent attachment are correct.
edit_file{"Path":"~/work/sortie/kit/frame_std.py","Replacement":"PADS = {\n \"forearm\": (\"forearm\", (3.08, 0, 10.42), (1, 0, 0), (0, 0, 1)),\n \"shoulder\": (\"shoulder\", (2.42, .12, ROOF), (0, 0, 1), (0, -1, 0)),\n \"hip\": (\"pelvis\", (1.52, 0, 10.92), (1, 0, 0), (0, 0, 1)),\n}\nBACK_PAD = ((0, 1.56, 13.8), (0, 1, 0), (0, 0, 1))\n\n\ndef build_pelvis(J):\n P = J[\"pelvis\"]\n solid(\"pelvis_block\", loft([(9.85, octo(1.1, .95, .25)), (10.35, octo(1.6, 1.25, .3)), (10.98, octo(1.5, 1.2, .3))]),\n \"frame\", P, BEVEL)\n # hip arms reach out over the thighs and carry the holster pads\n pair(\"hip_arm\", box(.6, 1.48, -.32, .32, 10.62, 11.04), \"frame\", P, P, bevel=BEVEL)","Target":"PADS = {\n \"forearm\": (\"forearm\", (3.08, 0, 10.42), (1, 0, 0), (0, 0, 1)),\n \"shoulder\": (\"shoulder\", (2.42, .12, ROOF), (0, 0, 1), (0, -1, 0)),\n \"hip\": (\"pelvis\", (2.04, 0, 10.92), (1, 0, 0), (0, 0, 1)),\n}\nBACK_PAD = ((0, 1.56, 13.8), (0, 1, 0), (0, 0, 1))\n\n\ndef build_pelvis(J):\n P = J[\"pelvis\"]\n solid(\"pelvis_block\", loft([(9.85, octo(1.1, .95, .25)), (10.35, octo(1.6, 1.25, .3)), (10.98, octo(1.5, 1.2, .3))]),\n \"frame\", P, BEVEL)\n # hip arms reach out over the thighs and carry the holster pads\n pair(\"hip_arm\", box(.6, 1.98, -.32, .32, 10.62, 11.04), \"frame\", P, P, bevel=BEVEL)"}
input
{ "Path": "~/work/sortie/kit/frame_std.py", "Replacement": "PADS = {\n \"forearm\": (\"forearm\", (3.08, 0, 10.42), (1, 0, 0), (0, 0, 1)),\n \"shoulder\": (\"shoulder\", (2.42, .12, ROOF), (0, 0, 1), (0, -1, 0)),\n \"hip\": (\"pelvis\", (1.52, 0, 10.92), (1, 0, 0), (0, 0, 1)),\n}\nBACK_PAD = ((0, 1.56, 13.8), (0, 1, 0), (0, 0, 1))\n\n\ndef build_pelvis(J):\n P = J[\"pelvis\"]\n solid(\"pelvis_block\", loft([(9.85, octo(1.1, .95, .25)), (10.35, octo(1.6, 1.25, .3)), (10.98, octo(1.5, 1.2, .3))]),\n \"frame\", P, BEVEL)\n # hip arms reach out over the thighs and carry the holster pads\n pair(\"hip_arm\", box(.6, 1.48, -.32, .32, 10.62, 11.04), \"frame\", P, P, bevel=BEVEL)", "Target": "PADS = {\n \"forearm\": (\"forearm\", (3.08, 0, 10.42), (1, 0, 0), (0, 0, 1)),\n \"shoulder\": (\"shoulder\", (2.42, .12, ROOF), (0, 0, 1), (0, -1, 0)),\n \"hip\": (\"pelvis\", (2.04, 0, 10.92), (1, 0, 0), (0, 0, 1)),\n}\nBACK_PAD = ((0, 1.56, 13.8), (0, 1, 0), (0, 0, 1))\n\n\ndef build_pelvis(J):\n P = J[\"pelvis\"]\n solid(\"pelvis_block\", loft([(9.85, octo(1.1, .95, .25)), (10.35, octo(1.6, 1.25, .3)), (10.98, octo(1.5, 1.2, .3))]),\n \"frame\", P, BEVEL)\n # hip arms reach out over the thighs and carry the holster pads\n pair(\"hip_arm\", box(.6, 1.98, -.32, .32, 10.62, 11.04), \"frame\", P, P, bevel=BEVEL)" }result, 1 line
Made 1 replacement in ~/work/sortie/kit/frame_std.py starting at line 123 (+2/-2 lines).
edit_file{"Path":"~/work/sortie/kit/frame_std.py","Replacement":" solid(\"neck_base\", loft([(15.0, octo(1.2, 1.1, .3)), (15.28, octo(.9, .85, .25))]), \"frame\", T, .02)\n cable(\"chest_cable\", [(1.18, -.58, 12.6), (1.28, -.62, 13.6), (1.32, -.58, 14.4)], T, T)","Target":" solid(\"neck_base\", loft([(15.0, octo(1.2, 1.1, .3)), (15.28, octo(.9, .85, .25))]), \"frame\", T, .02)\n cable(\"chest_cable\", [(1.22, -.95, 12.6), (1.38, -.98, 13.6), (1.42, -.8, 14.4)], T, T)"}
input
{ "Path": "~/work/sortie/kit/frame_std.py", "Replacement": " solid(\"neck_base\", loft([(15.0, octo(1.2, 1.1, .3)), (15.28, octo(.9, .85, .25))]), \"frame\", T, .02)\n cable(\"chest_cable\", [(1.18, -.58, 12.6), (1.28, -.62, 13.6), (1.32, -.58, 14.4)], T, T)", "Target": " solid(\"neck_base\", loft([(15.0, octo(1.2, 1.1, .3)), (15.28, octo(.9, .85, .25))]), \"frame\", T, .02)\n cable(\"chest_cable\", [(1.22, -.95, 12.6), (1.38, -.98, 13.6), (1.42, -.8, 14.4)], T, T)" }result, 1 line
Made 1 replacement in ~/work/sortie/kit/frame_std.py starting at line 182 (+1/-1 lines).
agent
+35:14reasoning
The goal is to modify the shoulder_root function to remove specified meshes associated with the mount-pad components. This involves filtering out mesh names starting with "pad_shoulder*", "shoulder_pedestal*", "pad_hip*", "pad_forearm*", and "pad_post*" while preserving meshes beginning with "mount.*". The focus is on the frame's joints named "shoulder", "pelvis", and "forearm."
edit_file{"Path":"~/work/sortie/kit/lab/knightkit.py","Replacement":"def shoulder_root(P, J, role=\"main\"):\n \"\"\"A curved inner spaulder cowl bridging the step from the breastplate to the pauldron.\"\"\"\n import bpy\n S = (J[\"shoulder\", \"L\"], J[\"shoulder\", \"R\"])\n sh = band((1.82, -.04), 13.55, 15.08, [.68, .78, .72], lin(-155, 155, 22), nv=6, kx=1.08, ky=.96, t=.14,\n disp=lambda u, v: .07 * tent(u, -90, 36))\n put(P, \"shoulder_root\", sh, role, *S)\n rim(P, \"shoulder_root_rim\", sh.edge(\"v0\", out=.01), .04, *S, role=\"trim\")\n # remove the utilitarian square mount-pad boxes so they don't clip through curved knight plates\n for j in (*S, J[\"pelvis\"], J[\"forearm\", \"L\"], J[\"forearm\", \"R\"]):\n for o in list(j.children):\n if o.type == \"MESH\" and any(o.name.startswith(p) for p in (\"pad_shoulder\", \"shoulder_pedestal\", \"pad_hip\", \"pad_forearm\", \"pad_post\")):\n bpy.data.objects.remove(o, do_unlink=True)","Target":"def shoulder_root(P, J, role=\"main\"):\n \"\"\"A curved inner spaulder cowl bridging the step from the breastplate to the pauldron.\"\"\"\n S = (J[\"shoulder\", \"L\"], J[\"shoulder\", \"R\"])\n sh = band((1.82, -.04), 13.55, 15.08, [.68, .78, .72], lin(-155, 155, 22), nv=6, kx=1.08, ky=.96, t=.14,\n disp=lambda u, v: .07 * tent(u, -90, 36))\n put(P, \"shoulder_root\", sh, role, *S)\n rim(P, \"shoulder_root_rim\", sh.edge(\"v0\", out=.01), .04, *S, role=\"trim\")"}
input
{ "Path": "~/work/sortie/kit/lab/knightkit.py", "Replacement": "def shoulder_root(P, J, role=\"main\"):\n \"\"\"A curved inner spaulder cowl bridging the step from the breastplate to the pauldron.\"\"\"\n import bpy\n S = (J[\"shoulder\", \"L\"], J[\"shoulder\", \"R\"])\n sh = band((1.82, -.04), 13.55, 15.08, [.68, .78, .72], lin(-155, 155, 22), nv=6, kx=1.08, ky=.96, t=.14,\n disp=lambda u, v: .07 * tent(u, -90, 36))\n put(P, \"shoulder_root\", sh, role, *S)\n rim(P, \"shoulder_root_rim\", sh.edge(\"v0\", out=.01), .04, *S, role=\"trim\")\n # remove the utilitarian square mount-pad boxes so they don't clip through curved knight plates\n for j in (*S, J[\"pelvis\"], J[\"forearm\", \"L\"], J[\"forearm\", \"R\"]):\n for o in list(j.children):\n if o.type == \"MESH\" and any(o.name.startswith(p) for p in (\"pad_shoulder\", \"shoulder_pedestal\", \"pad_hip\", \"pad_forearm\", \"pad_post\")):\n bpy.data.objects.remove(o, do_unlink=True)", "Target": "def shoulder_root(P, J, role=\"main\"):\n \"\"\"A curved inner spaulder cowl bridging the step from the breastplate to the pauldron.\"\"\"\n S = (J[\"shoulder\", \"L\"], J[\"shoulder\", \"R\"])\n sh = band((1.82, -.04), 13.55, 15.08, [.68, .78, .72], lin(-155, 155, 22), nv=6, kx=1.08, ky=.96, t=.14,\n disp=lambda u, v: .07 * tent(u, -90, 36))\n put(P, \"shoulder_root\", sh, role, *S)\n rim(P, \"shoulder_root_rim\", sh.edge(\"v0\", out=.01), .04, *S, role=\"trim\")" }result, 1 line
Made 1 replacement in ~/work/sortie/kit/lab/knightkit.py starting at line 323 (+6/-0 lines).
agent
+35:28reasoning
Adding thruster nozzles to the flared lower leg section, specifically within the shin function, aims to incorporate flight plume effects. Also integrating gear for the arms function is now required.
A knight shield will be added to the left forearm, with carefully defined bottom and top curves and an upper accent panel. A tapered Estoc rapier-lance will be assigned to the right hand, with details like the blade, guard, collar, hilt, and pommel incorporated. The geometry of the arms' gear is being thoroughly checked.
Shield design incorporates a gold rim using edge selections for the top, bottom, front, and back. A bearing decal is added to the shield face, positioned and oriented based on calculated angles and coordinates. The right hand's Estoc rapier-lance is defined by the hand grip's center and direction vector.
Defining the Estoc rapier-lance involves detailed geometric construction: the grip, shaft, bell-guard with swept quillons, and a four-ridged diamond blade are being designed. Parameters such as horn shapes, number of facets, and power values are carefully adjusted to achieve the desired aesthetic and structural characteristics. Details include a fuller spine and precise vector calculations for the quillons' orientation and placement.
edit_file{"Path":"~/work/sortie/kit/lab/board_sleek.py","Replacement":"from knightkit import Sheet, addon, band, by, curve, horn, joint_covers, lames, lin, put, put2, rim, smooth, tent\nfrom lib import copy\nfrom makers import atelier\nfrom makers.atelier import bearing_at, lr\nfrom makers.shell import subtract\nfrom mech import nozzle_pair","Target":"from knightkit import Sheet, addon, band, by, curve, horn, joint_covers, lames, lin, put, put2, rim, smooth, tent\nfrom lib import copy\nfrom makers import atelier\nfrom makers.atelier import bearing_at, lr\nfrom makers.shell import subtract"}
input
{ "Path": "~/work/sortie/kit/lab/board_sleek.py", "Replacement": "from knightkit import Sheet, addon, band, by, curve, horn, joint_covers, lames, lin, put, put2, rim, smooth, tent\nfrom lib import copy\nfrom makers import atelier\nfrom makers.atelier import bearing_at, lr\nfrom makers.shell import subtract\nfrom mech import nozzle_pair", "Target": "from knightkit import Sheet, addon, band, by, curve, horn, joint_covers, lames, lin, put, put2, rim, smooth, tent\nfrom lib import copy\nfrom makers import atelier\nfrom makers.atelier import bearing_at, lr\nfrom makers.shell import subtract" }result, 1 line
Made 1 replacement in ~/work/sortie/kit/lab/board_sleek.py starting at line 17 (+1/-0 lines).
edit_file{"Path":"~/work/sortie/kit/lab/board_sleek.py","Replacement":" calf = band(GC, 1.92, 5.3, [1.0, .84, .7, .76, .82, .66], lin(10, 170, 22), nv=12, ky=1.12, t=.14)\n put(P, \"calf\", calf, \"main\", *SH)\n nozzle_pair(\"calf\", (1.2, .72, 2.05), (0, .45, -.89), .22, .38, *SH, housing=False)\n for side, j, sx in ((\"L\", SH[0], 1), (\"R\", SH[1], -1)):\n bearing_at(f\"shin.{side}\", (1.2 * sx, GC[1] - .85, 4.0), (0, -1, 0), j, .4)","Target":" calf = band(GC, 1.92, 5.3, [1.0, .84, .7, .76, .82, .66], lin(10, 170, 22), nv=12, ky=1.12, t=.14)\n put(P, \"calf\", calf, \"main\", *SH)\n for side, j, sx in ((\"L\", SH[0], 1), (\"R\", SH[1], -1)):\n bearing_at(f\"shin.{side}\", (1.2 * sx, GC[1] - .85, 4.0), (0, -1, 0), j, .4)"}
input
{ "Path": "~/work/sortie/kit/lab/board_sleek.py", "Replacement": " calf = band(GC, 1.92, 5.3, [1.0, .84, .7, .76, .82, .66], lin(10, 170, 22), nv=12, ky=1.12, t=.14)\n put(P, \"calf\", calf, \"main\", *SH)\n nozzle_pair(\"calf\", (1.2, .72, 2.05), (0, .45, -.89), .22, .38, *SH, housing=False)\n for side, j, sx in ((\"L\", SH[0], 1), (\"R\", SH[1], -1)):\n bearing_at(f\"shin.{side}\", (1.2 * sx, GC[1] - .85, 4.0), (0, -1, 0), j, .4)", "Target": " calf = band(GC, 1.92, 5.3, [1.0, .84, .7, .76, .82, .66], lin(10, 170, 22), nv=12, ky=1.12, t=.14)\n put(P, \"calf\", calf, \"main\", *SH)\n for side, j, sx in ((\"L\", SH[0], 1), (\"R\", SH[1], -1)):\n bearing_at(f\"shin.{side}\", (1.2 * sx, GC[1] - .85, 4.0), (0, -1, 0), j, .4)" }result, 1 line
Made 1 replacement in ~/work/sortie/kit/lab/board_sleek.py starting at line 265 (+1/-0 lines).
edit_file{"Path":"~/work/sortie/kit/lab/board_sleek.py","Replacement":"def arms_gear(P, J, g):\n \"\"\"For the heavy Estoc knight: a compound-curved heraldic kite shield on the left forearm and a\n four-ridge diamond Estoc rapier-lance in the right hand.\"\"\"\n from mathutils import Vector\n if g != \"heavy\":\n return\n FA_L, HA_R = J[\"forearm\", \"L\"], J[\"hand\", \"R\"]\n sh_bot = lambda u: 8.85 + 1.15 * (1 - tent(u, -22, 46)) ** 1.3\n sh_top = lambda u: 12.55 - .28 * (1 - tent(u, -22, 46))\n sh = band((2.48, -.06), sh_bot, sh_top, [.82, .88, .9, .86], lin(-64, 20, 26), nv=12, t=.14,\n disp=lambda u, v: .14 * tent(u, -22, 24))\n P.solid(\"shield\", sh.bm(), \"main\", FA_L, bevel=0)\n sh_hi = band((2.48, -.06), lambda u: 11.15 + .45 * (1 - tent(u, -22, 46)), lambda u: sh_top(u) - .12,\n [.9, .92, .88], lin(-56, 12, 20), nv=6, t=.08, disp=lambda u, v: .14 * tent(u, -22, 24))\n P.solid(\"shield_field\", sh_hi.bm(), \"accent\", FA_L, bevel=0)\n rim(P, \"shield_pipe_lo\", sh.edge(\"v0\", out=.01), .045, FA_L)\n rim(P, \"shield_pipe_hi\", sh.edge(\"v1\", out=.01), .045, FA_L)\n rim(P, \"shield_pipe_f\", sh.edge(\"u0\", out=.01), .04, FA_L)\n rim(P, \"shield_pipe_b\", sh.edge(\"u1\", out=.01), .04, FA_L)\n a_sh = math.radians(-22)\n bearing_at(\"shield\", (2.48 + .98 * math.cos(a_sh), -.06 + .98 * math.sin(a_sh), 11.2),\n (math.cos(a_sh), math.sin(a_sh), 0), FA_L, .85)\n\n p0 = Vector((-2.38, -.08, 9.12))\n d = Vector((0, -.42, -.9075)).normalized()\n pg = p0 + d * .48\n P.solid(\"estoc_pommel\", horn([p0 - d * .15, p0 - d * .75, p0 - d * 1.25], .22, n=8, power=1.1), \"trim\", HA_R, bevel=0)\n P.solid(\"estoc_grip\", horn([p0 + d * .45, p0 - d * .65], .14, n=8, power=.2), \"joint\", HA_R, bevel=0)\n P.solid(\"estoc_guard\", horn([p0 + d * 1.35, p0 + d * .85, p0 + d * .42], .56, n=12, power=.75, squash=.82, up=(1, 0, 0)),\n \"main\", HA_R, bevel=0)\n P.solid(\"estoc_collar\", horn([p0 + d * 1.5, p0 + d * .38], .36, n=8, power=.45, squash=.85, up=(1, 0, 0)),\n \"trim\", HA_R, bevel=0)\n for k, sx in ((\"i\", 1), (\"o\", -1)):\n P.solid(f\"estoc_quillon_{k}\", horn([pg, pg + Vector((.55 * sx, -.15, .18)) + d * .25,\n pg + Vector((1.05 * sx, -.25, .42)) + d * .55], .16, n=8, power=1.1, squash=.45, up=(0, 1, 0)),\n \"trim\", HA_R, bevel=0)\n P.solid(\"estoc_ricasso\", horn([p0 + d * .5, p0 + d * 2.2, p0 + d * 4.2], .24, n=4, power=1.05, squash=.85, up=(1, 0, 0)),\n \"accent\", HA_R, bevel=0)\n P.solid(\"estoc_blade\", horn([p0 + d * .48, p0 + d * 2.5, p0 + d * 5.2, p0 + d * 8.4], .34, n=4, power=.88, squash=.68, up=(1, 0, 0)),\n \"metal\", HA_R, bevel=0)\n\n\ndef plates(J, P, g=\"medium\"):\n from knightkit import helm, sabaton, shoulder_root\n helm(P, J, g, helm_blades(g))\n chest(P, J, g)\n waist(P, J, g)\n pelvis(P, J, g)\n shoulder(P, J, g)\n shoulder_root(P, J)\n upperarm(P, J, g)\n forearm(P, J, g)\n arms_gear(P, J, g)\n thigh(P, J, g)\n shin(P, J, g)","Target":"def plates(J, P, g=\"medium\"):\n from knightkit import helm, sabaton, shoulder_root\n helm(P, J, g, helm_blades(g))\n chest(P, J, g)\n waist(P, J, g)\n pelvis(P, J, g)\n shoulder(P, J, g)\n shoulder_root(P, J)\n upperarm(P, J, g)\n forearm(P, J, g)\n thigh(P, J, g)\n shin(P, J, g)"}
input
{ "Path": "~/work/sortie/kit/lab/board_sleek.py", "Replacement": "def arms_gear(P, J, g):\n \"\"\"For the heavy Estoc knight: a compound-curved heraldic kite shield on the left forearm and a\n four-ridge diamond Estoc rapier-lance in the right hand.\"\"\"\n from mathutils import Vector\n if g != \"heavy\":\n return\n FA_L, HA_R = J[\"forearm\", \"L\"], J[\"hand\", \"R\"]\n sh_bot = lambda u: 8.85 + 1.15 * (1 - tent(u, -22, 46)) ** 1.3\n sh_top = lambda u: 12.55 - .28 * (1 - tent(u, -22, 46))\n sh = band((2.48, -.06), sh_bot, sh_top, [.82, .88, .9, .86], lin(-64, 20, 26), nv=12, t=.14,\n disp=lambda u, v: .14 * tent(u, -22, 24))\n P.solid(\"shield\", sh.bm(), \"main\", FA_L, bevel=0)\n sh_hi = band((2.48, -.06), lambda u: 11.15 + .45 * (1 - tent(u, -22, 46)), lambda u: sh_top(u) - .12,\n [.9, .92, .88], lin(-56, 12, 20), nv=6, t=.08, disp=lambda u, v: .14 * tent(u, -22, 24))\n P.solid(\"shield_field\", sh_hi.bm(), \"accent\", FA_L, bevel=0)\n rim(P, \"shield_pipe_lo\", sh.edge(\"v0\", out=.01), .045, FA_L)\n rim(P, \"shield_pipe_hi\", sh.edge(\"v1\", out=.01), .045, FA_L)\n rim(P, \"shield_pipe_f\", sh.edge(\"u0\", out=.01), .04, FA_L)\n rim(P, \"shield_pipe_b\", sh.edge(\"u1\", out=.01), .04, FA_L)\n a_sh = math.radians(-22)\n bearing_at(\"shield\", (2.48 + .98 * math.cos(a_sh), -.06 + .98 * math.sin(a_sh), 11.2),\n (math.cos(a_sh), math.sin(a_sh), 0), FA_L, .85)\n\n p0 = Vector((-2.38, -.08, 9.12))\n d = Vector((0, -.42, -.9075)).normalized()\n pg = p0 + d * .48\n P.solid(\"estoc_pommel\", horn([p0 - d * .15, p0 - d * .75, p0 - d * 1.25], .22, n=8, power=1.1), \"trim\", HA_R, bevel=0)\n P.solid(\"estoc_grip\", horn([p0 + d * .45, p0 - d * .65], .14, n=8, power=.2), \"joint\", HA_R, bevel=0)\n P.solid(\"estoc_guard\", horn([p0 + d * 1.35, p0 + d * .85, p0 + d * .42], .56, n=12, power=.75, squash=.82, up=(1, 0, 0)),\n \"main\", HA_R, bevel=0)\n P.solid(\"estoc_collar\", horn([p0 + d * 1.5, p0 + d * .38], .36, n=8, power=.45, squash=.85, up=(1, 0, 0)),\n \"trim\", HA_R, bevel=0)\n for k, sx in ((\"i\", 1), (\"o\", -1)):\n P.solid(f\"estoc_quillon_{k}\", horn([pg, pg + Vector((.55 * sx, -.15, .18)) + d * .25,\n pg + Vector((1.05 * sx, -.25, .42)) + d * .55], .16, n=8, power=1.1, squash=.45, up=(0, 1, 0)),\n \"trim\", HA_R, bevel=0)\n P.solid(\"estoc_ricasso\", horn([p0 + d * .5, p0 + d * 2.2, p0 + d * 4.2], .24, n=4, power=1.05, squash=.85, up=(1, 0, 0)),\n \"accent\", HA_R, bevel=0)\n P.solid(\"estoc_blade\", horn([p0 + d * .48, p0 + d * 2.5, p0 + d * 5.2, p0 + d * 8.4], .34, n=4, power=.88, squash=.68, up=(1, 0, 0)),\n \"metal\", HA_R, bevel=0)\n\n\ndef plates(J, P, g=\"medium\"):\n from knightkit import helm, sabaton, shoulder_root\n helm(P, J, g, helm_blades(g))\n chest(P, J, g)\n waist(P, J, g)\n pelvis(P, J, g)\n shoulder(P, J, g)\n shoulder_root(P, J)\n upperarm(P, J, g)\n forearm(P, J, g)\n arms_gear(P, J, g)\n thigh(P, J, g)\n shin(P, J, g)", "Target": "def plates(J, P, g=\"medium\"):\n from knightkit import helm, sabaton, shoulder_root\n helm(P, J, g, helm_blades(g))\n chest(P, J, g)\n waist(P, J, g)\n pelvis(P, J, g)\n shoulder(P, J, g)\n shoulder_root(P, J)\n upperarm(P, J, g)\n forearm(P, J, g)\n thigh(P, J, g)\n shin(P, J, g)" }result, 1 line
Made 1 replacement in ~/work/sortie/kit/lab/board_sleek.py starting at line 302 (+43/-0 lines).
agent
+36:15reasoning
The task requires modifying build scripts to integrate new construction calls. First, focusing on kit/build.py, integration of the build commands. Then, the integration point for the pilot construction within the source rendering assets. The goal is to ensure the new build processes are correctly linked within the build infrastructure and rendering pipeline.
read_file{"EndLine":90,"Path":"~/work/sortie/src/render/assets.ts","StartLine":1}
input
{ "EndLine": 90, "Path": "~/work/sortie/src/render/assets.ts", "StartLine": 1 }result, 91 lines
Showing lines 1-90 of 228 1: import * as THREE from 'three'; 2: import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'; 3: import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js'; 4: import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js'; 5: import { PALETTES, type PaletteName } from './palette'; 6: import { DETAIL_LAYER } from './pipeline'; 7: import { BARE, isRole, material } from './materials'; 8: 9: const loader = new GLTFLoader(); 10: loader.setMeshoptDecoder(MeshoptDecoder); 11: const sources = new Map<string, Promise<THREE.Object3D>>(); 12: 13: /** Every model the kit builds (kit/build.py). */ 14: export type ModelName = 'alien_acicular' | 'alien_druse' | 'alien_druse_mimic' | 'alien_geode' 15: | 'striker' | 'striker_a' | 'striker_b' | 'light' | 'light_line' | 'light_lancer' | 'heavy' | 'heavy_B' | 'heavy_C' 16: | 'auto_tally' | 'auto_tick' | 'auto_ledger' | 'rifle' | 'cannon' | 'drone' | 'cockpit' | 'cockpit_light' | 'ship' | 'station' 17: | 'wreck_field' | 'salvage_pod' | 'escape_pod' | 'raider_grunt' | 'raider_brawler' | 'raider_boss'; 18: 19: /** 20: * Models ship as .glb. Artifact pages serve neither .glb nor fetches of data: URLs, so the artifact 21: * build wraps each model as base64 in JSON (VITE_MODEL_EXT=glb.json) and the page decodes it here. 22: * Those are squeezed (tools/squeeze.mjs): meshopt compressed, plus a quantized-only copy 23: * (.q.glb.json) for a page that can't run the WebAssembly decoder. 24: */ 25: const EXT: string = import.meta.env.VITE_MODEL_EXT ?? 'glb'; 26: const meshopt: Promise<boolean> = EXT === 'glb' ? Promise.resolve(true) : MeshoptDecoder.ready.then(() => true, () => false); 27: 28: async function fetchGlb(url: string): Promise<ArrayBuffer> { 29: const res = await fetch(url); 30: if (!res.ok) throw new Error(`${url}: ${res.status}`); 31: if (!url.endsWith('.json')) return res.arrayBuffer(); 32: const b64 = (await res.json()).glb as string; 33: const bin = atob(b64); 34: const out = new Uint8Array(bin.length); 35: for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i); 36: return out.buffer; 37: } 38: 39: /** Models loading now and loaded so far, for a loading indicator. */ 40: export const loading = { pending: 0, done: 0, listeners: new Set<() => void>() }; 41: function track<T>(p: Promise<T>): Promise<T> { 42: loading.pending++; 43: const tell = () => { 44: for (const f of loading.listeners) f(); 45: }; 46: tell(); 47: const end = () => { 48: loading.pending--; 49: loading.done++; 50: tell(); 51: }; 52: p.then(end, end); 53: return p; 54: } 55: 56: function source(name: ModelName, merge = true): Promise<THREE.Object3D> { 57: const key = merge ? name : `${name}:parts`; 58: let p = sources.get(key); 59: if (!p) { 60: const url = (ok: boolean) => `${import.meta.env.BASE_URL}assets/${name}.${ok ? EXT : `q.${EXT}`}`; 61: p = track(meshopt.then((ok) => fetchGlb(url(ok))).then((glb) => parseModel(glb, merge))); 62: sources.set(key, p); 63: } 64: return p; 65: } 66: 67: /** A model's scene from GLB bytes, plain or squeezed. `merge` false keeps every part its own mesh. */ 68: export async function parseModel(glb: ArrayBuffer, merge = true): Promise<THREE.Object3D> { 69: const root = unquantize((await loader.parseAsync(glb, '')).scene); 70: return merge ? mergeParts(root) : root; 71: } 72: 73: /** Start loading models now, side by side, so later awaits find them ready. */ 74: export function preload(names: Iterable<ModelName>) { 75: for (const n of names) source(n).catch((e) => console.error(e)); 76: } 77: 78: /** A fresh copy of a model, painted with a palette and tagged for ink lines. `merge` false keeps every 79: * part its own mesh, for models whose parts move apart (the aliens). */ 80: export async function model(name: ModelName, palette: PaletteName = 'merc', merge = true): Promise<THREE.Object3D> { 81: const root = (await source(name, merge)).clone(true); 82: paint(root, palette); 83: return root; 84: } 85: 86: export function paint(root: THREE.Object3D, palette: PaletteName) { 87: const pal = PALETTES[palette]; 88: // the plumes (render/mech.ts) take their colour from the same palette 89: root.userData.palette = palette; 90: root.traverse((o) => {