diff --git a/assets/vehicles/kestrel/kestrel.glb b/assets/vehicles/kestrel/kestrel.glb index 7fa9af3..284a261 100644 Binary files a/assets/vehicles/kestrel/kestrel.glb and b/assets/vehicles/kestrel/kestrel.glb differ diff --git a/assets/vehicles/kestrel/manifest.json b/assets/vehicles/kestrel/manifest.json index a8307bd..41c8428 100644 --- a/assets/vehicles/kestrel/manifest.json +++ b/assets/vehicles/kestrel/manifest.json @@ -129,5 +129,5 @@ 4.4533 ] }, - "triCount": 37558 + "triCount": 41374 } diff --git a/assets/vehicles/manticore/manifest.json b/assets/vehicles/manticore/manifest.json index cd74d80..d47831b 100644 --- a/assets/vehicles/manticore/manifest.json +++ b/assets/vehicles/manticore/manifest.json @@ -167,5 +167,5 @@ 9.1091 ] }, - "triCount": 36030 + "triCount": 33517 } diff --git a/assets/vehicles/manticore/manticore.glb b/assets/vehicles/manticore/manticore.glb index 88a627e..57c7313 100644 Binary files a/assets/vehicles/manticore/manticore.glb and b/assets/vehicles/manticore/manticore.glb differ diff --git a/assets/vehicles/paladin/manifest.json b/assets/vehicles/paladin/manifest.json index 7e779b1..dd6df5f 100644 --- a/assets/vehicles/paladin/manifest.json +++ b/assets/vehicles/paladin/manifest.json @@ -182,5 +182,5 @@ 3.9623 ] }, - "triCount": 38752 + "triCount": 36463 } diff --git a/assets/vehicles/paladin/paladin.glb b/assets/vehicles/paladin/paladin.glb index 476c642..20482ce 100644 Binary files a/assets/vehicles/paladin/paladin.glb and b/assets/vehicles/paladin/paladin.glb differ diff --git a/assets/vehicles/raptor/manifest.json b/assets/vehicles/raptor/manifest.json index 322a4bb..29f6590 100644 --- a/assets/vehicles/raptor/manifest.json +++ b/assets/vehicles/raptor/manifest.json @@ -111,7 +111,7 @@ "min": [ -2.3822, 0.0, - -4.4307 + -4.422 ], "max": [ 2.3822, @@ -121,8 +121,8 @@ "size": [ 4.7644, 6.9873, - 8.986 + 8.9773 ] }, - "triCount": 35822 + "triCount": 36156 } diff --git a/assets/vehicles/raptor/raptor.glb b/assets/vehicles/raptor/raptor.glb index 65e86ab..36a4b9e 100644 Binary files a/assets/vehicles/raptor/raptor.glb and b/assets/vehicles/raptor/raptor.glb differ diff --git a/assets/vehicles/spectre/manifest.json b/assets/vehicles/spectre/manifest.json index f7640e7..83922ea 100644 --- a/assets/vehicles/spectre/manifest.json +++ b/assets/vehicles/spectre/manifest.json @@ -152,5 +152,5 @@ 6.0846 ] }, - "triCount": 39288 + "triCount": 40696 } diff --git a/assets/vehicles/spectre/spectre.glb b/assets/vehicles/spectre/spectre.glb index b95b839..112cd17 100644 Binary files a/assets/vehicles/spectre/spectre.glb and b/assets/vehicles/spectre/spectre.glb differ diff --git a/tools/vehicles/previews/kestrel_preview.png b/tools/vehicles/previews/kestrel_preview.png index 3b88f01..3e03632 100644 Binary files a/tools/vehicles/previews/kestrel_preview.png and b/tools/vehicles/previews/kestrel_preview.png differ diff --git a/tools/vehicles/previews/manticore_preview.png b/tools/vehicles/previews/manticore_preview.png index 31868d1..e90a2bb 100644 Binary files a/tools/vehicles/previews/manticore_preview.png and b/tools/vehicles/previews/manticore_preview.png differ diff --git a/tools/vehicles/previews/paladin_preview.png b/tools/vehicles/previews/paladin_preview.png index 2f2c3be..8cebb84 100644 Binary files a/tools/vehicles/previews/paladin_preview.png and b/tools/vehicles/previews/paladin_preview.png differ diff --git a/tools/vehicles/previews/raptor_preview.png b/tools/vehicles/previews/raptor_preview.png index a098583..6e662e4 100644 Binary files a/tools/vehicles/previews/raptor_preview.png and b/tools/vehicles/previews/raptor_preview.png differ diff --git a/tools/vehicles/previews/spectre_preview.png b/tools/vehicles/previews/spectre_preview.png index dc1eb12..9506ebb 100644 Binary files a/tools/vehicles/previews/spectre_preview.png and b/tools/vehicles/previews/spectre_preview.png differ diff --git a/tools/vehicles/retrofit_mechs.py b/tools/vehicles/retrofit_mechs.py index aac0d35..9e0b8ae 100644 --- a/tools/vehicles/retrofit_mechs.py +++ b/tools/vehicles/retrofit_mechs.py @@ -835,7 +835,14 @@ def _snap_hardpoint_bvh( if len(corner_vals) >= 3: c_med = corner_vals[len(corner_vals) // 2] if h_center - c_med > 0.08: - h_center = c_med + tight_hits: list[float] = [] + for tx, ty in ((-0.07, 0.0), (0.07, 0.0), (0.0, -0.07), (0.0, 0.07)): + t_loc, _, _, _ = bvh.ray_cast(p0 + tu * tx + tv * ty + n * 0.65, -n, 1.35) + if t_loc is not None: + tight_hits.append((t_loc - p0).dot(n)) + t_med = sorted(tight_hits)[len(tight_hits) // 2] if tight_hits else h_center + if h_center - t_med > 0.06: + h_center = c_med # Keep corner hits near the local surface patch; replace misses/cliffs with nearest or conservative drop valid_corners: list[float] = [h_center] @@ -1262,6 +1269,972 @@ def _finalize_mechanisms_gltf(raw: dict[str, Any], ground_z_shift: float) -> dic } +def _finalize_shroud_obj(obj: bpy.types.Object, bevel: float = 0.010) -> bpy.types.Object: + """Apply crisp hard-surface bevel + 36-deg edge split and bake to clean mesh.""" + if bevel > 0.0: + bv = obj.modifiers.new("Shroud_Bevel", "BEVEL") + bv.width = float(bevel) + bv.segments = 1 + bv.limit_method = "ANGLE" + bv.angle_limit = math.radians(30.0) + bv.harden_normals = False + es = obj.modifiers.new("Shroud_EdgeSplit", "EDGE_SPLIT") + es.use_edge_angle = True + es.split_angle = math.radians(36.0) + es.use_edge_sharp = True + depsgraph = bpy.context.evaluated_depsgraph_get() + ev = obj.evaluated_get(depsgraph) + new_mesh = bpy.data.meshes.new_from_object(ev, preserve_all_data_layers=True, depsgraph=depsgraph) + new_mesh.name = f"{obj.name}_mesh" + new_mesh.validate(verbose=False) + obj.modifiers.clear() + obj.data = new_mesh + return obj + + +def _make_loft_shroud( + name: str, + rings: list[list[Vector]], + parent: bpy.types.Object, + mat_name: str = "olive_armor", + bevel: float = 0.010, +) -> bpy.types.Object: + """Loft a closed manifold hard-surface armor shell across multi-station 3D rings in parent local space.""" + assert len(rings) >= 2 and all(len(r) == len(rings[0]) for r in rings) + m = len(rings[0]) + bm = bmesh.new() + bm_rings: list[list[bmesh.types.BMVert]] = [ + [bm.verts.new(tuple(float(c) for c in pt)) for pt in ring] + for ring in rings + ] + bm.verts.ensure_lookup_table() + for i in range(len(bm_rings) - 1): + r0, r1 = bm_rings[i], bm_rings[i + 1] + for j in range(m): + jn = (j + 1) % m + bm.faces.new((r0[j], r0[jn], r1[jn], r1[j])) + bm.faces.new(list(reversed(bm_rings[0]))) + bm.faces.new(bm_rings[-1]) + bmesh.ops.recalc_face_normals(bm, faces=bm.faces) + mesh = bpy.data.meshes.new(name) + bm.to_mesh(mesh) + bm.free() + obj = bpy.data.objects.new(name, mesh) + vc._assign_material(obj, mat_name) + vc._link_object(obj, parent=parent, location=(0.0, 0.0, 0.0), rotation_deg=(0.0, 0.0, 0.0)) + return _finalize_shroud_obj(obj, bevel=bevel) + + +def _make_chamfer_box_shroud( + name: str, + x0: float, + x1: float, + y0: float, + y1: float, + z0: float, + z1: float, + parent: bpy.types.Object, + mat_name: str = "olive_armor", + chamfer: float = 0.035, + top_taper_xy: tuple[float, float] = (1.0, 1.0), + bevel: float = 0.010, +) -> bpy.types.Object: + """Create a tapered octagonal-section armor plate spanning [x0..x1] x [y0..y1] x [z0..z1].""" + cx, cy = 0.5 * (x0 + x1), 0.5 * (y0 + y1) + hx, hy = 0.5 * abs(x1 - x0), 0.5 * abs(y1 - y0) + c = min(chamfer, hx * 0.42, hy * 0.42) + + def _ring(z_val: float, sx: float, sy: float) -> list[Vector]: + rx, ry = hx * sx, hy * sy + cc = min(c, rx * 0.45, ry * 0.45) + pts = [ + (cx - rx + cc, cy - ry), + (cx + rx - cc, cy - ry), + (cx + rx, cy - ry + cc), + (cx + rx, cy + ry - cc), + (cx + rx - cc, cy + ry), + (cx - rx + cc, cy + ry), + (cx - rx, cy + ry - cc), + (cx - rx, cy - ry + cc), + ] + return [Vector((px, py, z_val)) for px, py in pts] + + tx, ty = top_taper_xy + rings = [_ring(z0, 1.0, 1.0), _ring(z1, tx, ty)] + return _make_loft_shroud(name, rings, parent=parent, mat_name=mat_name, bevel=bevel) + + +def _make_arc_fender( + name: str, + center: Vector, + axis: Vector, + fwd_dir: Vector, + up_dir: Vector, + r_in: float, + r_out: float, + half_w: float, + ang_start_deg: float, + ang_end_deg: float, + steps: int, + parent: bpy.types.Object, + mat_name: str = "olive_armor", + end_taper_w: float = 0.84, + bevel: float = 0.010, +) -> bpy.types.Object: + """Sweep a beveled armored fender arch around a cylindrical drum (0 deg = fwd_dir, 90 deg = up_dir).""" + ax = axis.normalized() + fd = fwd_dir.normalized() + ud = up_dir.normalized() + rings: list[list[Vector]] = [] + for k in range(steps + 1): + u = k / steps + ang = math.radians(ang_start_deg + (ang_end_deg - ang_start_deg) * u) + radial = fd * math.cos(ang) + ud * math.sin(ang) + # Slightly pinch width and thickness at the very ends for Brokkr fender silhouette + edge_fac = 1.0 - (1.0 - end_taper_w) * (abs(2.0 * u - 1.0) ** 2) + hw = half_w * edge_fac + hw_outer = hw * 0.86 + r_mid = r_in + (r_out - r_in) * 0.65 + pts = [ + center + radial * r_in - ax * hw, + center + radial * r_in + ax * hw, + center + radial * r_mid + ax * hw, + center + radial * r_out + ax * hw_outer, + center + radial * r_out - ax * hw_outer, + center + radial * r_mid - ax * hw, + ] + rings.append(pts) + return _make_loft_shroud(name, rings, parent=parent, mat_name=mat_name, bevel=bevel) + + +def _obj_bounds_in_ref(obj_names: list[str], ref_obj: bpy.types.Object, z_filter: tuple[float, float] | None = None) -> tuple[Vector, Vector] | None: + """Measure combined world vertices of named objects transformed into ref_obj local space.""" + inv_ref = ref_obj.matrix_world.inverted() + pts: list[Vector] = [] + for nm in obj_names: + o = bpy.data.objects.get(nm) + if o is None or o.type != "MESH" or o.data is None: + continue + mw = o.matrix_world + for v in o.data.vertices: + pw = mw @ v.co + if z_filter is not None and not (z_filter[0] <= pw.z <= z_filter[1]): + continue + pts.append(inv_ref @ pw) + if not pts: + return None + bmin = Vector((min(p.x for p in pts), min(p.y for p in pts), min(p.z for p in pts))) + bmax = Vector((max(p.x for p in pts), max(p.y for p in pts), max(p.z for p in pts))) + return bmin, bmax + + +def _add_kestrel_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + torso = bpy.data.objects.get("Torso.pose") + pelvis = bpy.data.objects.get("Pelvis") + if torso is None or pelvis is None: + return created + + # 1. Sloped hooded shoulder pauldrons over exposed ribbed shoulder drums (parented to Torso.pose) + # Linearly tapered stations keep top/flank quads planar for crisp panel shading. + for side, sx in (("L", -1.0), ("R", 1.0)): + stations_spec = [ + # (|x|, y_rear, y_front, z_low_rear, z_low_front, z_top_rear, z_top_front) + (1.20, 0.00, 1.24, 1.54, 1.54, 2.26, 2.18), + (1.52, 0.02, 1.22, 1.36, 1.42, 2.18, 2.10), + (1.86, 0.04, 1.19, 1.22, 1.30, 2.07, 2.00), + (2.16, 0.06, 1.16, 1.16, 1.24, 1.92, 1.86), + (2.30, 0.10, 1.10, 1.24, 1.30, 1.74, 1.69), + ] + rings: list[list[Vector]] = [] + for ax, yr, yf, zlr, zlf, ztr, ztf in stations_spec: + px = sx * ax + yc = 0.5 * (yr + yf) + pts = [ + Vector((px, yr, zlr)), + Vector((px, yr + 0.14, zlr)), + Vector((px, yr + 0.16, ztr - 0.18)), + Vector((px, yc, min(ztr, ztf) - 0.12)), + Vector((px, yf - 0.16, ztf - 0.18)), + Vector((px, yf - 0.14, zlf)), + Vector((px, yf, zlf)), + Vector((px, yf - 0.08, ztf)), + Vector((px, yc, max(ztr, ztf) + 0.04)), + Vector((px, yr + 0.08, ztr)), + ] + if sx < 0: + pts = list(reversed(pts)) + rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.Pauldron{side}", rings, torso, "olive_armor", bevel=0.012)) + + # Gunmetal mounting flange bracket bridging inner shoulder cowl to drum core + created.append( + _make_arc_fender( + f"Shroud.Kestrel.PauldronFlange{side}", + center=Vector((sx * 1.38, 0.65, 1.50)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.49, + r_out=0.56, + half_w=0.10, + ang_start_deg=15.0, + ang_end_deg=165.0, + steps=6, + parent=torso, + mat_name="gunmetal", + end_taper_w=0.92, + bevel=0.008, + ) + ) + + # 2. Compact sloped hip-fender guards + outer drum caps over bare hip cylinders (parented to Pelvis) + created.append( + _make_arc_fender( + f"Shroud.Kestrel.HipFender{side}", + center=Vector((sx * 1.28, 0.0, 6.20)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.515, + r_out=0.60, + half_w=0.38, + ang_start_deg=-10.0, + ang_end_deg=158.0, + steps=8, + parent=pelvis, + mat_name="olive_armor", + end_taper_w=0.80, + bevel=0.010, + ) + ) + # Outer hip drum shield cap + hip_cap_rings: list[list[Vector]] = [] + for x_off, r in ((1.46, 0.36), (1.58, 0.36), (1.64, 0.25)): + px = sx * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), 6.20 + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if sx < 0: + pts = list(reversed(pts)) + hip_cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.HipCap{side}", hip_cap_rings, pelvis, "olive_armor", bevel=0.008)) + created.append( + _make_arc_fender( + f"Shroud.Kestrel.HipFlange{side}", + center=Vector((sx * 1.02, 0.0, 6.20)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.49, + r_out=0.54, + half_w=0.07, + ang_start_deg=-5.0, + ang_end_deg=162.0, + steps=7, + parent=pelvis, + mat_name="gunmetal", + end_taper_w=0.95, + bevel=0.006, + ) + ) + + # 4. Faceted knee caps + outer cheek shields over bare black knee drums (parented to Pelvis) + knee_bounds = _obj_bounds_in_ref([f"LegJoints{side}.gunmetal"], pelvis, z_filter=(3.0, 4.4)) + if knee_bounds is not None: + kmin, kmax = knee_bounds + kcx = 0.5 * (kmin.x + kmax.x) + kcy = 0.5 * (kmin.y + kmax.y) + kcz = 0.5 * (kmin.z + kmax.z) + created.append( + _make_arc_fender( + f"Shroud.Kestrel.KneeCap{side}", + center=Vector((kcx, kcy, kcz)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.37, + r_out=0.465, + half_w=0.37, + ang_start_deg=-42.0, + ang_end_deg=72.0, + steps=6, + parent=pelvis, + mat_name="olive_armor", + end_taper_w=0.78, + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Kestrel.KneeCapFront{side}", + kcx - 0.25, + kcx + 0.25, + kcy + 0.36, + kcy + 0.49, + kcz - 0.24, + kcz + 0.28, + parent=pelvis, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.86, 0.85), + bevel=0.009, + ) + ) + knee_side_rings: list[list[Vector]] = [] + for x_off, r in ((0.28, 0.28), (0.37, 0.28), (0.42, 0.19)): + px = kcx + sx * x_off + pts = [ + Vector((px, kcy + r * math.cos(math.radians(a)), kcz + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if sx < 0: + pts = list(reversed(pts)) + knee_side_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.KneeCheek{side}", knee_side_rings, pelvis, "olive_armor", bevel=0.008)) + + # 5. Armored calf/shin shrouds wrapping rear twin ankle hydraulic pistons (parented to Pelvis) + ram_objs = [f"Ankle{side}.root.machine.ram", f"Ankle{side}.root.steel.ram", f"Ankle{side}.root.steel.eye"] + top_b = _obj_bounds_in_ref(ram_objs, pelvis, z_filter=(2.05, 2.75)) + bot_b = _obj_bounds_in_ref(ram_objs, pelvis, z_filter=(0.95, 1.65)) + if top_b is not None and bot_b is not None: + t_cx = 0.5 * (top_b[0].x + top_b[1].x) + t_cy = 0.5 * (top_b[0].y + top_b[1].y) + b_cx = 0.5 * (bot_b[0].x + bot_b[1].x) + b_cy = 0.5 * (bot_b[0].y + bot_b[1].y) + z_bot, z_top = 1.16, 2.74 + # Interpolate exact piston spine centerline from z_bot..z_top and wrap a U-channel rear/flank greave + greave_rings: list[list[Vector]] = [] + for frac, hw, y_back, y_front in ( + (0.00, 0.145, -0.145, 0.13), + (0.22, 0.165, -0.165, 0.17), + (0.75, 0.180, -0.175, 0.22), + (1.00, 0.160, -0.145, 0.19), + ): + zz = z_bot + (z_top - z_bot) * frac + # top_b centroid is ~z=2.40, bot_b centroid is ~z=1.30 + t_u = (zz - 1.30) / 1.10 + px = b_cx + (t_cx - b_cx) * t_u + py = b_cy + (t_cy - b_cy) * t_u + c_in = hw * 0.58 + pts = [ + Vector((px - hw, py + y_front, zz)), + Vector((px - c_in, py + y_front, zz)), + Vector((px - c_in, py + y_back + 0.08, zz)), + Vector((px + c_in, py + y_back + 0.08, zz)), + Vector((px + c_in, py + y_front, zz)), + Vector((px + hw, py + y_front, zz)), + Vector((px + hw, py + y_back + 0.05, zz)), + Vector((px + hw * 0.62, py + y_back, zz)), + Vector((px - hw * 0.62, py + y_back, zz)), + Vector((px - hw, py + y_back + 0.05, zz)), + ] + greave_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.AnkleGreave{side}", greave_rings, pelvis, "olive_armor", bevel=0.010)) + for idx_band, zb in enumerate((1.38, 2.38)): + t_u = (zb - 1.30) / 1.10 + px = b_cx + (t_cx - b_cx) * t_u + py = b_cy + (t_cy - b_cy) * t_u + created.append( + _make_chamfer_box_shroud( + f"Shroud.Kestrel.AnkleBand{side}{idx_band}", + px - 0.18, + px + 0.18, + py - 0.175, + py + 0.16, + zb - 0.045, + zb + 0.045, + parent=pelvis, + mat_name="gunmetal", + chamfer=0.03, + bevel=0.006, + ) + ) + + # 3. Segmented armored spine shroud over exposed rear waist hydraulic rods (parented to Torso.pose) + # In Torso.pose local space (offset 0, -0.15, 6.75), neck rings step forward in Y as Z rises from -0.05 to +0.88 + for idx_seg, (z0, z1, y_back, hx) in enumerate(( + (-0.04, 0.27, -0.66, 0.58), + (0.24, 0.56, -0.58, 0.54), + (0.53, 0.86, -0.49, 0.49), + )): + created.append( + _make_chamfer_box_shroud( + f"Shroud.Kestrel.WaistSpine{idx_seg}", + -hx, + hx, + y_back, + y_back + 0.34, + z0, + z1, + parent=torso, + mat_name="olive_armor", + chamfer=0.07, + top_taper_xy=(0.92, 0.90), + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Kestrel.WaistSpineRib", + -0.16, + 0.16, + -0.69, + -0.42, + 0.00, + 0.82, + parent=torso, + mat_name="gunmetal", + chamfer=0.03, + top_taper_xy=(0.88, 0.85), + bevel=0.008, + ) + ) + return created + + +def _add_spectre_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + + # 1. Angled shin/hock hydraulic ram deflector greaves (parented to LegL.Cannon / LegR.Cannon) + for leg in ("LegL", "LegR"): + cannon = bpy.data.objects.get(f"{leg}.Cannon") + if cannon is None: + continue + inv_can = cannon.matrix_world.inverted() + ram_objs = [bpy.data.objects.get(f"{leg}.Hock.ram.barrel"), bpy.data.objects.get(f"{leg}.Hock.ram.rod")] + for side_tag, x_sign in (("Out", -1.0 if leg == "LegL" else 1.0), ("In", 1.0 if leg == "LegL" else -1.0)): + pts: list[Vector] = [] + for ro in ram_objs: + if ro is None or ro.type != "MESH" or ro.data is None: + continue + mw = ro.matrix_world + for v in ro.data.vertices: + pl = inv_can @ (mw @ v.co) + if pl.x * x_sign > 0.10: + pts.append(pl) + if not pts: + continue + xmin = min(p.x for p in pts) + xmax = max(p.x for p in pts) + ymax = max(p.y for p in pts) + ymin = min(p.y for p in pts) + # Deflector greave wrapping the front (+Y) and outer/side face of each exposed silver ram + x_in = (xmin - 0.02) if x_sign > 0 else (xmin - 0.055) + x_out = (xmax + 0.055) if x_sign > 0 else (xmax + 0.02) + y_f = ymax + 0.055 + y_b = max(ymin - 0.02, ymax - 0.24) + z_top = 0.28 + z_bot = 1.46 + # Loft from top bevel cap -> mid shield -> lower tapered deflector lip + rings: list[list[Vector]] = [] + for zz, x_pad, y_pad in ( + (z_top, -0.02, -0.03), + (z_top + 0.14, 0.0, 0.0), + (z_bot - 0.18, 0.0, 0.0), + (z_bot, -0.025, -0.04), + ): + xa, xb = x_in - x_pad * x_sign, x_out + x_pad * x_sign + if xa > xb: + xa, xb = xb, xa + yf = y_f + y_pad + yb = y_b + xm = 0.5 * (xa + xb) + ym = 0.5 * (yb + yf) + rings.append([ + Vector((xa, yb, zz)), + Vector((xb, yb, zz)), + Vector((xb, ym + 0.03, zz)), + Vector((xm + 0.04 * (xb - xa), yf, zz)), + Vector((xm - 0.04 * (xb - xa), yf, zz)), + Vector((xa, ym + 0.03, zz)), + ]) + created.append(_make_loft_shroud(f"Shroud.Spectre.{leg}RamGuard{side_tag}", rings, cannon, "olive_armor", bevel=0.009)) + # Gunmetal mounting bracket tying greave into Leg*.Shank + bx0 = min(x_in, x_out) - (0.06 if x_sign > 0 else 0.0) + bx1 = max(x_in, x_out) + (0.06 if x_sign < 0 else 0.0) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Spectre.{leg}RamBracket{side_tag}", + bx0, + bx1, + y_b - 0.08, + y_b + 0.04, + 0.55, + 0.78, + parent=cannon, + mat_name="gunmetal", + chamfer=0.025, + bevel=0.006, + ) + ) + + # 2. Compact armored waist collar / hip skirt around vertical waist spindle (parented to Waist) + waist = bpy.data.objects.get("Waist") + if waist is not None: + # Waist wloc=(0,0,5.30), WaistLug extends z_local=-0.35..0.14, WaistColumn z_local=0..0.81 + skirt_rings: list[list[Vector]] = [] + for zz, sx, sy in ( + (-0.28, 0.72, 0.62), + (-0.04, 0.74, 0.64), + (0.24, 0.64, 0.56), + (0.42, 0.55, 0.49), + ): + c = 0.16 + skirt_rings.append([ + Vector((-sx + c, -sy, zz)), + Vector((sx - c, -sy, zz)), + Vector((sx, -sy + c, zz)), + Vector((sx, sy - c, zz)), + Vector((sx - c, sy, zz)), + Vector((-sx + c, sy, zz)), + Vector((-sx, sy - c, zz)), + Vector((-sx, -sy + c, zz)), + ]) + created.append(_make_loft_shroud("Shroud.Spectre.WaistSkirt", skirt_rings, waist, "olive_armor", bevel=0.010)) + created.append( + _make_chamfer_box_shroud( + "Shroud.Spectre.WaistCollar", + -0.56, + 0.56, + -0.51, + 0.51, + 0.32, + 0.48, + parent=waist, + mat_name="gunmetal", + chamfer=0.10, + bevel=0.008, + ) + ) + + # 3. Outer shoulder-hinge axle caps (parented to ShoulderL / ShoulderR) + for side, sx in (("L", -1.0), ("R", 1.0)): + sh = bpy.data.objects.get(f"Shoulder{side}") + if sh is None: + continue + cap_rings: list[list[Vector]] = [] + for x_off, r in ((0.24, 0.305), (0.44, 0.305), (0.52, 0.225)): + px = sx * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if sx < 0: + pts = list(reversed(pts)) + cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Spectre.ShoulderCap{side}", cap_rings, sh, "olive_armor", bevel=0.008)) + + return created + + +def _add_raptor_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + pelvis = bpy.data.objects.get("Pelvis") + + for side, sx in (("L", -1.0), ("R", 1.0)): + # 1. Angled olive hip-fender cowl over protruding black hip drum (parented to Pelvis) + if pelvis is not None: + created.append( + _make_arc_fender( + f"Shroud.Raptor.HipFender{side}", + center=Vector((sx * 1.44, 0.0, 0.0)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.535, + r_out=0.615, + half_w=0.45, + ang_start_deg=18.0, + ang_end_deg=165.0, + steps=7, + parent=pelvis, + mat_name="olive_armor", + end_taper_w=0.82, + bevel=0.010, + ) + ) + created.append( + _make_arc_fender( + f"Shroud.Raptor.HipFlange{side}", + center=Vector((sx * 1.02, 0.0, 0.0)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.50, + r_out=0.555, + half_w=0.07, + ang_start_deg=15.0, + ang_end_deg=168.0, + steps=6, + parent=pelvis, + mat_name="gunmetal", + end_taper_w=0.95, + bevel=0.006, + ) + ) + + # 2. Outer hip drum cap + knee-cap shield + rear thigh actuator guard (parented to Leg*.Thigh) + thigh = bpy.data.objects.get(f"Leg{side}.Thigh") + if thigh is not None: + # In LegL.Thigh local space +X is outer left; in LegR.Thigh local space -X is outer right + x_out_sign = -sx + hip_cap_rings: list[list[Vector]] = [] + for x_off, r in ((0.48, 0.35), (0.60, 0.35), (0.66, 0.25)): + px = x_out_sign * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if x_out_sign < 0: + pts = list(reversed(pts)) + hip_cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Raptor.HipCap{side}", hip_cap_rings, thigh, "olive_armor", bevel=0.008)) + + # KneeBearing*.gunmetal sits at z_local=[1.52..2.28], y_local=[-0.38..+0.38] (center 0.0, 1.90) + created.append( + _make_arc_fender( + f"Shroud.Raptor.KneeCap{side}", + center=Vector((x_out_sign * 0.06, 0.0, 1.90)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, -1.0)), + r_in=0.385, + r_out=0.475, + half_w=0.46, + ang_start_deg=-62.0, + ang_end_deg=62.0, + steps=7, + parent=thigh, + mat_name="olive_armor", + end_taper_w=0.78, + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.KneeCapFront{side}", + x_out_sign * 0.06 - 0.30, + x_out_sign * 0.06 + 0.30, + 0.37, + 0.50, + 1.64, + 2.16, + parent=thigh, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.86, 0.85), + bevel=0.009, + ) + ) + # Outer circular knee-drum cap + knee_cap_rings: list[list[Vector]] = [] + for x_off, r in ((0.46, 0.28), (0.58, 0.28), (0.64, 0.19)): + px = x_out_sign * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), 1.90 + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if x_out_sign < 0: + pts = list(reversed(pts)) + knee_cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Raptor.KneeOuterCap{side}", knee_cap_rings, thigh, "olive_armor", bevel=0.008)) + + # Rear thigh actuator guard over Actuators*.steel (y_local=[-0.62..-0.42], z_local=[1.14..1.71]) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.ThighRam{side}", + -0.37, + 0.37, + -0.66, + -0.36, + 1.08, + 1.72, + parent=thigh, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.90, 0.88), + bevel=0.009, + ) + ) + + # 3. Shin upper rod shroud (parented to Leg*.Shin) + shin = bpy.data.objects.get(f"Leg{side}.Shin") + if shin is not None: + # HydraulicsShin*.gunmetal/steel: x=[-0.23..0.23], y=[0.46..0.66], z=[0.18..1.48] + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.ShinRod{side}", + -0.27, + 0.27, + 0.36, + 0.71, + 0.20, + 1.32, + parent=shin, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.82, 0.80), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.ShinRodCollar{side}", + -0.29, + 0.29, + 0.34, + 0.72, + 0.82, + 0.98, + parent=shin, + mat_name="gunmetal", + chamfer=0.04, + bevel=0.006, + ) + ) + + # 4. Protruding rear calf hydraulic rod shroud (parented to Leg*.Cannon) + cannon = bpy.data.objects.get(f"Leg{side}.Cannon") + if cannon is not None: + # Hydraulics*.gunmetal/steel: x=[-0.23..0.23], y=[-0.57..-0.37], z=[0.18..1.61] + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.CalfRod{side}", + -0.28, + 0.28, + -0.63, + -0.27, + 0.20, + 1.40, + parent=cannon, + mat_name="olive_armor", + chamfer=0.07, + top_taper_xy=(0.80, 0.78), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.CalfRodCollar{side}", + -0.30, + 0.30, + -0.64, + -0.26, + 0.88, + 1.04, + parent=cannon, + mat_name="gunmetal", + chamfer=0.04, + bevel=0.006, + ) + ) + + return created + + +def _add_manticore_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + for leg in ("LegBL", "LegBR"): + # In LegBL local space -X is outward-left; in LegBR local space +X is outward-right + x_out_sign = -1.0 if leg == "LegBL" else 1.0 + + # 1. Rear hip armor cap over bare gunmetal coxa drum (parented to LegB*.Coxa) + coxa = bpy.data.objects.get(f"{leg}.Coxa") + if coxa is not None: + # coxa.dress.machine: x=[-0.446..0.446], y=[-0.30..0.30], z=[0.16..0.76]; +Y_local is outer-rear + created.append( + _make_chamfer_box_shroud( + f"Shroud.Manticore.{leg}HipCap", + -0.48, + 0.48, + -0.12, + 0.40, + -0.02, + 0.54, + parent=coxa, + mat_name="olive_armor", + chamfer=0.08, + top_taper_xy=(0.90, 0.86), + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Manticore.{leg}HipFlange", + -0.50, + 0.50, + -0.14, + 0.28, + -0.04, + 0.12, + parent=coxa, + mat_name="gunmetal", + chamfer=0.06, + bevel=0.006, + ) + ) + + # 2. Rear knee armor cap arching over bare gunmetal knee drum + outer drum cap (parented to LegB*.S1) + s1 = bpy.data.objects.get(f"{leg}.S1") + if s1 is not None: + # knee.dress.machine: x=[-0.44..0.44], y=[-0.34..0.34], z=[1.242..1.922]; femur.plate ends at z=1.25, y=[0.30..0.42] + created.append( + _make_arc_fender( + f"Shroud.Manticore.{leg}KneeCap", + center=Vector((0.0, 0.0, 1.58)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.345, + r_out=0.445, + half_w=0.48, + ang_start_deg=-38.0, + ang_end_deg=132.0, + steps=8, + parent=s1, + mat_name="olive_armor", + end_taper_w=0.84, + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Manticore.{leg}KneeCapTop", + -0.34, + 0.34, + 0.24, + 0.45, + 1.26, + 1.80, + parent=s1, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.88, 0.85), + bevel=0.009, + ) + ) + knee_side_rings: list[list[Vector]] = [] + for x_off, r in ((0.38, 0.28), (0.48, 0.28), (0.53, 0.19)): + px = x_out_sign * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), 1.58 + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if x_out_sign < 0: + pts = list(reversed(pts)) + knee_side_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Manticore.{leg}KneeSideCap", knee_side_rings, s1, "olive_armor", bevel=0.008)) + + return created + + +def _add_paladin_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + arm_r = bpy.data.objects.get("ArmR.Lower") + if arm_r is None: + return created + + # ArmR.Lower local box is [-0.297, -0.25, -0.144]..[0.297, 0.25, 1.55]. + # hp.weapon.arm_r sits on -X_local face at (-0.311, -0.124, 0.697) with 0.72x0.72 footprint -> keep -X_local z=[0.26..1.16] clear! + # Inner (+X), Front (+Y), and Rear (-Y) forearm plates: + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRInner", + 0.28, + 0.42, + -0.27, + 0.27, + 0.14, + 1.44, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.04, + top_taper_xy=(0.90, 0.88), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRFront", + -0.31, + 0.36, + 0.23, + 0.39, + 0.14, + 1.44, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.05, + top_taper_xy=(0.86, 0.86), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRRear", + -0.31, + 0.36, + -0.39, + -0.23, + 0.14, + 1.44, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.05, + top_taper_xy=(0.86, 0.86), + bevel=0.009, + ) + ) + # Upper elbow cuff & lower wrist cuff collar (staying clear of hp.weapon.arm_r around z=0.26..1.16 on -X) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRElbowCuff", + -0.38, + 0.38, + -0.33, + 0.33, + -0.02, + 0.22, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.06, + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRWristBand", + -0.34, + 0.36, + -0.30, + 0.30, + 1.36, + 1.50, + parent=arm_r, + mat_name="gunmetal", + chamfer=0.04, + bevel=0.006, + ) + ) + return created + + +def _add_actuator_armor_shrouds(mech_id: str) -> list[bpy.types.Object]: + builders = { + "kestrel": _add_kestrel_shrouds, + "spectre": _add_spectre_shrouds, + "raptor": _add_raptor_shrouds, + "manticore": _add_manticore_shrouds, + "paladin": _add_paladin_shrouds, + } + fn = builders.get(mech_id) + if fn is None: + return [] + return fn() + + def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]: bpy.ops.wm.open_mainfile(filepath=str(spec.blend_path)) scene = bpy.context.scene @@ -1309,6 +2282,13 @@ def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]: mech_meshes = [o for o in bpy.data.objects if o.type == "MESH"] raw_tris, lod_tris = _decimate_mech_meshes(mech_meshes, spec.target_mech_tris) + # 5b. Add Brokkr-style olive-drab armor shrouds over exposed joints/actuators + shroud_objs = _add_actuator_armor_shrouds(spec.mech_id) + if shroud_objs: + shroud_tris = sum(_mesh_tri_count(o) for o in shroud_objs) + lod_tris += shroud_tris + print(f" [shroud] {spec.mech_id}: +{len(shroud_objs)} shrouds (+{shroud_tris} tris)") + # 6. Parent everything cleanly under a root Empty (in raw Brokkr orientation first) chassis_root = vc.make_empty(spec.mech_id, parent=None, location=(0.0, 0.0, 0.0)) for obj in list(bpy.data.objects):