BASTION (sheet 36), second pass: the carapace rebuilt as hard plates, each authored by its faces
The first pass's one soft cage read as a smooth dome. Every plate of the hull is now called hard (bastion_form.KINDS) and written as the flat faces that bound it: brow, chin, cheek pods with a lamp slot under an overhanging lip, the skirts that carry the 03, flank roofs and sills, rear quarter pods, an eight-flat collar round the turret ring, over a dark core; then detail plating (a raised, split, stepped, bolted panel on each large facet).
massing: plane, through, corners (a convex solid's corners from its faces), hard, panel, clad, Face (a flat facet standing in for surface.Skin).
Legs: front thighs and shins as armoured housings on their bearings, the housing leaning 18 degrees over a 39 degree thigh; rear legs with a stepped bearing stack, an open twin-beam thigh, a shroud, a guard plate and twin rams of bore 0.18 seated by ram core from a mount on the hip housing to the hock.
Cooling: two housings (hood, ribbed wall, floor), radiator faces to the rear and in the flank, a machinery block and manifold between.
Visor: three narrow panes deep under the brow between armoured lids.
Hero camera: 15 marks (hull marks added: nose, lamp slots, the 03, the magazine, the cooling corner, the bearing faces), 20.9 px rms upright from 28.8 on 9; camsolve's free model reaches 16.0 px with its centre 1700 px under the frame and is not kept (bastion_cams.py).
paint.py and surface.py from nibu/fable-paint-2 (d1179a2); the visor's glass at Sky 0.4.
Sheets: bastion_vs_pass1.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
96c881f7db
commit
eeda8bf2de
11 changed files with 1680 additions and 605 deletions
|
|
@ -1,26 +1,27 @@
|
||||||
"""BASTION (sheet 36, images/36.webp): a quadruped, a broad low tortoise hull on four heavy legs, a ballistic turret.
|
"""BASTION (sheet 36, images/36.webp), second pass: a quadruped, a broad low angular carapace on four heavy legs, a
|
||||||
|
ballistic turret.
|
||||||
|
|
||||||
Mass first: the hull is one closed free cage fitted to the sheet's five views (hero, front, side, rear, plan) at their
|
Mass first, and hard: the hull is a set of hard plates, each a faceted solid authored by its faces (bastion_form,
|
||||||
solved cameras (bastion_cameras.json, by quadruped.cameras), then cut by its wells and split into plates. The legs are
|
bastion_body), looked at as mass against the sheet's five views at their solved cameras (bastion_cameras.json, by
|
||||||
|
bastion_cams.py) before any detail; then the detail plating, the legs, the rest (bastion_build). The legs are
|
||||||
quadruped.build's kit skeleton, a joint record an axis; the turret's yaw and the gun's pitch are two more.
|
quadruped.build's kit skeleton, a joint record an axis; the turret's yaw and the gun's pitch are two more.
|
||||||
|
|
||||||
BASTION_STAGE stops early: volume (the hull's mass alone), legs (mass and skeleton with its legs), recess, plates,
|
BASTION_STAGE stops early: volume (the hull's mass alone), legs (mass and legs), full (default). MECH_QUICK renders
|
||||||
full (default). MECH_QUICK renders by Workbench. Writes under MECH_OUT/bastion/: <stage>_<view>.png for hero, front,
|
by Workbench. Writes under MECH_OUT/bastion/: <stage>_<view>.png for hero, front, side, rear, top (the kept cameras,
|
||||||
side, rear, top (the kept cameras, the sheet's own pixels; alpha is the silhouette), <stage>_turn_*.png."""
|
the sheet's own pixels; alpha is the silhouette), <stage>_turn_*.png, close_*.png, bastion.blend."""
|
||||||
import json, math, os, sys, time
|
import json, math, os, sys, time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||||
import mechlib as M
|
import mechlib as M
|
||||||
import massing as MS
|
import massing as MS
|
||||||
import bastion_form as BF
|
import bastion_form as BF
|
||||||
import bastion_body as BB
|
|
||||||
from mathutils import Matrix, Vector
|
from mathutils import Matrix, Vector
|
||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
M.setup()
|
M.setup()
|
||||||
M.cache_kits()
|
M.cache_kits()
|
||||||
STAGES = ("volume", "legs", "recess", "plates", "full")
|
STAGES = ("volume", "legs", "full")
|
||||||
STAGE = os.environ.get("BASTION_STAGE", "full")
|
STAGE = os.environ.get("BASTION_STAGE", "full")
|
||||||
AT = STAGES.index(STAGE)
|
AT = STAGES.index(STAGE)
|
||||||
QUICK = bool(os.environ.get("MECH_QUICK"))
|
QUICK = bool(os.environ.get("MECH_QUICK"))
|
||||||
|
|
@ -30,13 +31,8 @@ OUT.mkdir(parents=True, exist_ok=True)
|
||||||
KEPT = BF.cameras()
|
KEPT = BF.cameras()
|
||||||
CAMS, STAND = KEPT["cameras"], KEPT["stand"]
|
CAMS, STAND = KEPT["cameras"], KEPT["stand"]
|
||||||
|
|
||||||
mass = BB.hull_mass("khaki")
|
import bastion_build
|
||||||
sheet = BB.hull_cage()
|
bastion_build.run(AT, STAND)
|
||||||
print("CAGE Hull", json.dumps(MS.cage_stats(sheet)), flush=True)
|
|
||||||
print("CAGE Hull (brokkr_kitbash.shell)", json.dumps(MS.cage_report(sheet)), flush=True)
|
|
||||||
if AT >= 1:
|
|
||||||
import bastion_build
|
|
||||||
bastion_build.run(mass, AT, STAND)
|
|
||||||
M.update()
|
M.update()
|
||||||
lo, hi = M.bounds()
|
lo, hi = M.bounds()
|
||||||
print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi.x - lo.x, 2), "LENGTH", round(hi.y - lo.y, 2), "stage", STAGE, "build s", round(time.time() - t0, 1), flush=True)
|
print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi.x - lo.x, 2), "LENGTH", round(hi.y - lo.y, 2), "stage", STAGE, "build s", round(time.time() - t0, 1), flush=True)
|
||||||
|
|
@ -44,11 +40,13 @@ print("HEIGHT", round(hi.z - lo.z, 2), "LOW", round(lo.z, 2), "WIDTH", round(hi.
|
||||||
rig, cam, centre, radius = M.stage_field(8 if QUICK else int(os.environ.get("MECH_SAMPLES", 48)))
|
rig, cam, centre, radius = M.stage_field(8 if QUICK else int(os.environ.get("MECH_SAMPLES", 48)))
|
||||||
if not QUICK:
|
if not QUICK:
|
||||||
import paint
|
import paint
|
||||||
paint.apply(os.environ.get("BASTION_PAINT", "paladin"))
|
# a slit of upright panes seen level mirrors the horizon, the brightest band of MechGlass's sky: at the preset's Sky
|
||||||
|
# 2.2 the visor rendered pale grey in the cockpit close-up, so the sky is painted weaker on this glass
|
||||||
|
paint.apply(os.environ.get("BASTION_PAINT", "paladin"), glass={"sky": 0.4})
|
||||||
WIDTH = {"hero": 1536, "front": 711, "side": 855, "rear": 795, "top": 711} # three times the sheet's pixels; the hero one and a half
|
WIDTH = {"hero": 1536, "front": 711, "side": 855, "rear": 795, "top": 711} # three times the sheet's pixels; the hero one and a half
|
||||||
VIEWS = os.environ.get("BASTION_VIEWS", "hero,front,side,rear,top").split(",")
|
VIEWS = [v for v in os.environ.get("BASTION_VIEWS", "hero,front,side,rear,top").split(",") if v and v != "none"]
|
||||||
if AT >= 3 and not os.environ.get("BASTION_NO_EDGES"):
|
if AT >= 2 and VIEWS and not os.environ.get("BASTION_NO_EDGES"):
|
||||||
armour = lambda name: name.startswith(("Hull.", "Cooling.hood", "Thigh.guard", "Shin.guard", "Turret.housing")) and ".fit." not in name and ".mark." not in name # noqa: E731
|
armour = lambda name: name.startswith(("Hull.", "Cooling.hood", "Cooling.frame", "Thigh.guard", "Thigh.shroud", "Shin.guard", "Turret.housing")) and ".fit." not in name and ".mark." not in name # noqa: E731
|
||||||
for tag in ("hero", "side", "top"):
|
for tag in ("hero", "side", "top"):
|
||||||
(OUT / f"{STAGE}_edges_{tag}.json").write_text(json.dumps(M.built_edges(CAMS[tag], keep=armour)), encoding="utf-8")
|
(OUT / f"{STAGE}_edges_{tag}.json").write_text(json.dumps(M.built_edges(CAMS[tag], keep=armour)), encoding="utf-8")
|
||||||
print("edges s", round(time.time() - t0, 1), flush=True)
|
print("edges s", round(time.time() - t0, 1), flush=True)
|
||||||
|
|
@ -70,13 +68,17 @@ for tag in VIEWS:
|
||||||
scene.render.film_transparent, scene.render.image_settings.color_mode = keep
|
scene.render.film_transparent, scene.render.image_settings.color_mode = keep
|
||||||
for o in hidden:
|
for o in hidden:
|
||||||
o.hide_render = False
|
o.hide_render = False
|
||||||
|
ONLY = [c for c in os.environ.get("BASTION_CLOSE", "").split(",") if c]
|
||||||
if not QUICK and not os.environ.get("BASTION_NO_TURNS"):
|
if not QUICK and not os.environ.get("BASTION_NO_TURNS"):
|
||||||
for az in (35, 145, 215):
|
for az in (() if ONLY else (35, 145, 215)):
|
||||||
M.shot(rig, cam, radius, az, 8.0, OUT / f"{STAGE}_turn_{az:03d}.png", (1200, 900), margin=0.8, lens=85.0)
|
M.shot(rig, cam, radius, az, 8.0, OUT / f"{STAGE}_turn_{az:03d}.png", (1200, 900), margin=0.8, lens=85.0)
|
||||||
if STAGE == "full":
|
if STAGE == "full":
|
||||||
CLOSE = {"cockpit": ((0, 6.0, 5.1), 2.4, 18, -2), "magazine": ((-5.0, 0.0, 6.3), 2.3, 72, 4), "turret": ((0, 1.2, 8.6), 3.6, 35, 10), "interceptor": ((-1.5, 4.25, 7.6), 1.1, 28, 12),
|
CLOSE = {"cockpit": ((0, 6.0, 5.1), 2.6, 18, -2), "magazine": ((-5.0, -0.2, 6.2), 2.3, 72, 4), "turret": ((0, 1.2, 8.6), 3.6, 35, 10), "interceptor": ((-3.55, 4.0, 7.0), 1.2, 40, 12),
|
||||||
"rear_leg": ((-4.7, -5.7, 2.7), 3.6, 98, 4), "cooling": ((0, -6.0, 6.2), 3.4, 180, 8), "front_leg": ((-4.4, 5.0, 2.2), 3.0, 55, 4), "foot": ((-4.3, 5.4, 0.5), 1.9, 40, 14)}
|
"rear_leg": ((-4.7, -5.7, 2.9), 3.8, 98, 4), "cooling": ((0, -6.6, 6.2), 3.6, 180, 6), "front_leg": ((-4.4, 5.0, 2.4), 3.2, 55, 4), "foot": ((-4.3, 5.4, 0.5), 1.9, 40, 14),
|
||||||
|
"hull": ((-1.5, 2.5, 6.2), 6.2, 42, 12), "cooling_flank": ((-3.6, -6.2, 6.2), 3.0, 120, 6)}
|
||||||
for name, (target, span, az, el) in CLOSE.items():
|
for name, (target, span, az, el) in CLOSE.items():
|
||||||
|
if ONLY and name not in ONLY:
|
||||||
|
continue
|
||||||
M.closeup(rig, cam, target, span, az, el, OUT / f"close_{name}.png", size=(640, 640))
|
M.closeup(rig, cam, target, span, az, el, OUT / f"close_{name}.png", size=(640, 640))
|
||||||
bpy.ops.wm.save_as_mainfile(filepath=str(OUT / "bastion.blend"))
|
bpy.ops.wm.save_as_mainfile(filepath=str(OUT / "bastion.blend"))
|
||||||
print("total s", round(time.time() - t0, 1))
|
print("total s", round(time.time() - t0, 1))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
"""BASTION's body, mass first (sheet 36): the hull as one closed free cage made a mass, its wells, its plates.
|
"""BASTION's body, second pass (sheet 36): the carapace as hard plates over a dark core, then its detail plating.
|
||||||
Runs inside Blender beside mechlib, massing and bastion_form."""
|
Runs inside Blender beside mechlib, massing and bastion_form.
|
||||||
|
|
||||||
|
hull(host) the mass: the core and every main plate of bastion_form.PLATES, each a faceted solid on the
|
||||||
|
corners of its faces (massing.corners, massing.hard), and the deck's collar. This is what
|
||||||
|
the volume stage shows against the silhouettes, before any detail.
|
||||||
|
plating(plates, host) the detail plating after the main split (massing.clad): a raised panel on each large
|
||||||
|
facet that faces out, split and stepped
|
||||||
|
report(plates) each plate's kind, corners and facets (the hard-plate counterpart of a cage report)"""
|
||||||
import math
|
import math
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
|
@ -9,20 +16,75 @@ import bastion_form as BF
|
||||||
import massing as MS
|
import massing as MS
|
||||||
import mechlib as M
|
import mechlib as M
|
||||||
|
|
||||||
CORE = "gunmetal"
|
|
||||||
I4 = Matrix.Identity(4)
|
I4 = Matrix.Identity(4)
|
||||||
|
T = Matrix.Translation
|
||||||
|
|
||||||
|
|
||||||
_CAGE = {}
|
def _face(f, sx=1):
|
||||||
|
if f[0] == "at":
|
||||||
|
return MS.plane(f[1], f[2])
|
||||||
|
return MS.through(f[1], f[2], f[3], f[4])
|
||||||
|
|
||||||
|
|
||||||
def hull_cage():
|
def _points(plate):
|
||||||
"""The hull's cage, moved so its surface passes through bastion_form's points (massing.cage_through)."""
|
return MS.corners([_face(f) for f in plate["faces"]]) if "faces" in plate else [Vector(p) for p in plate["points"]]
|
||||||
if "hull" not in _CAGE:
|
|
||||||
_CAGE["hull"] = MS.cage_through(BF.hull_sheet())
|
|
||||||
return _CAGE["hull"]
|
|
||||||
|
|
||||||
|
|
||||||
def hull_mass(mat="khaki", levels=3):
|
def hull(host):
|
||||||
"""The hull: carapace and belly, one closed volume from the minimal cage (bastion_form.hull_sheet)."""
|
"""The carapace's mass. Returns ({name: object} of the armour plates, {name: object} of the dark core)."""
|
||||||
return MS.cage("Hull.mass", hull_cage(), I4, mat, levels=levels)
|
plates, dark = {}, {}
|
||||||
|
for group, out in ((BF.DARK, dark), (BF.PLATES, plates)):
|
||||||
|
for name, plate, sided in group:
|
||||||
|
pts = _points(plate)
|
||||||
|
for sx in ((1, -1) if sided else (1,)):
|
||||||
|
key = f"{name}.{'R' if sx > 0 else 'L'}" if sided else name
|
||||||
|
out[key] = MS.hard(key, pts, host, plate["mat"], mirror=plate.get("mirror", False), bevel=plate["bevel"], sx=sx)
|
||||||
|
out[key]["clad"] = bool(plate["clad"])
|
||||||
|
g = M.Geo()
|
||||||
|
g.lathe(T((0, 0, 0)) @ Matrix.Rotation(math.radians(22.5), 4, "Z"), BF.COLLAR, 8)
|
||||||
|
collar = g.to_object("Hull.Collar", BF.P, host, 1.0)
|
||||||
|
mod = collar.modifiers.new("Bevel", "BEVEL")
|
||||||
|
mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.04, 1, "ANGLE", math.radians(12)
|
||||||
|
collar["plate_kind"], collar["clad"] = "hard", True
|
||||||
|
plates["Hull.Collar"] = collar
|
||||||
|
g = M.Geo()
|
||||||
|
g.lathe(I4, [(0, 7.2), (2.6, 7.2), (2.6, 7.56), (0, 7.56)], 48)
|
||||||
|
dark["Core.deck"] = g.to_object("Core.deck", BF.CORE, host)
|
||||||
|
return plates, dark
|
||||||
|
|
||||||
|
|
||||||
|
def outward(n, c):
|
||||||
|
"""A facet the detail plating takes: one that faces out of the hull, not down, not into a neighbour."""
|
||||||
|
if n.z < -0.35:
|
||||||
|
return False
|
||||||
|
radial = Vector((c.x, c.y, 0.0))
|
||||||
|
return n.z > 0.6 or (radial.length > 1.0 and n.dot(radial.normalized()) > 0.25)
|
||||||
|
|
||||||
|
|
||||||
|
def plating(plates, host):
|
||||||
|
"""Detail plating: one object of raised panels a plate (Hull.<plate>.panels), olive_light on olive and the other
|
||||||
|
way round, so a panel reads against its plate; a bolt inside each panel corner (Hull.bolts). Returns
|
||||||
|
{name: panels made}."""
|
||||||
|
made, bolts = {}, M.Geo()
|
||||||
|
for k, (name, obj) in enumerate(sorted(plates.items())):
|
||||||
|
if not obj.get("clad"):
|
||||||
|
continue
|
||||||
|
g = M.Geo()
|
||||||
|
n = MS.clad(obj, g, keep=outward, seed=k, bolts=bolts)
|
||||||
|
if n:
|
||||||
|
mat = BF.P2 if obj.data.materials[0] == M.MATS[BF.P] else BF.P
|
||||||
|
o = g.to_object(f"{name}.panels", mat, host, 1.0)
|
||||||
|
mod = o.modifiers.new("Bevel", "BEVEL")
|
||||||
|
mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.012, 1, "ANGLE", math.radians(20)
|
||||||
|
for p in o.data.polygons:
|
||||||
|
p.use_smooth = False
|
||||||
|
made[name] = n
|
||||||
|
bolts.to_object("Hull.bolts", "gunmetal", host)
|
||||||
|
return made
|
||||||
|
|
||||||
|
|
||||||
|
def report(plates):
|
||||||
|
rows = {}
|
||||||
|
for name, obj in sorted(plates.items()):
|
||||||
|
rows[name] = {"kind": obj.get("plate_kind", "hard"), "corners": len(obj.data.vertices), "facets": len(obj.data.polygons)}
|
||||||
|
return rows
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
"""BASTION beyond its hull's mass: the kit skeleton (quadruped.build), the wells, the plates, the hip housings, the
|
"""BASTION beyond its hull's mass, second pass: the kit skeleton (quadruped.build), the head's visor, the magazines,
|
||||||
legs' dress and rams, the feet (feet.bastion_pads), the turret and gun, the magazines, the interceptors, the cooling.
|
the legs as armoured housings on rotary bearings with their rams (ram core), the feet (feet.bastion_pads), the
|
||||||
|
turret and gun, the interceptors, the cooling assemblies under their housings, the surface detail.
|
||||||
Every part function takes the host it is authored on; every finished part is frozen (brokkr_kitbash.freeze).
|
Every part function takes the host it is authored on; every finished part is frozen (brokkr_kitbash.freeze).
|
||||||
|
|
||||||
|
Rebuilt in this pass: the hull (bastion_body: hard plates), the visor, the hip housings, both leg dresses, the
|
||||||
|
cooling, the detail. Carried over from the first pass unchanged in form: magazine, interceptor, foot, turret, gun.
|
||||||
|
|
||||||
Reconciliations with the design prompt (ruling concept-prompt-is-design-intent), each built as the prompt says:
|
Reconciliations with the design prompt (ruling concept-prompt-is-design-intent), each built as the prompt says:
|
||||||
magazines the sheet draws an open recess in the flank and, in plan, a box outside the rim. The prompt: recessed
|
magazines the sheet draws an open recess in the flank and, in plan, a box outside the rim. The prompt: recessed
|
||||||
side compartments with segmented doors that open upward. Built: a recess in the flank band, a
|
side compartments with segmented doors that open upward. Built: a framed compartment in the flank, a
|
||||||
three-segment door hinged on its upper edge and standing open (the plan's box is the open door).
|
three-segment door hinged on its upper edge and standing open (the plan's box is the open door).
|
||||||
interceptors the sheet's inset shows one launcher; the hero scatters seven boxes on the dome. The prompt: spread
|
interceptors the sheet's inset shows one launcher; the hero scatters seven boxes on the deck. The prompt: spread
|
||||||
round the shell's perimeter. Built: eight, evenly round the shoulder line, the inset's look.
|
round the shell's perimeter. Built: eight, on the pods and the flank roofs, the inset's look.
|
||||||
cooling the rear view shows two bare radiator faces flush in the tail, the side view a block 2 m behind the
|
cooling the rear view shows two framed radiator faces either side of the tail, the hero a ribbed housing with
|
||||||
hull, the plan nothing behind the tail. The prompt: under sculpted protective housings. Built: two
|
a grille in its flank, the side view a block 1.3 m behind the tail. Built: two housings, each a
|
||||||
housings (free cages) over the banks, standing 0.7 m behind the tail, the fins in their mouths.
|
hood over a ribbed wall, radiator faces to the rear and in the flank, a machinery block between.
|
||||||
hips the prompt: rotary housings at the hull's corners. Built: a fixed drum housing under each corner of the
|
|
||||||
overhang, the thigh's drum turning in it.
|
|
||||||
legs front shorter and heavily armoured, rear longer with exposed hydraulics: as the sheet draws them."""
|
legs front shorter and heavily armoured, rear longer with exposed hydraulics: as the sheet draws them."""
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
|
|
@ -20,7 +22,7 @@ import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from mathutils import Matrix, Vector
|
from mathutils import Matrix, Quaternion, Vector
|
||||||
|
|
||||||
import bastion_form as BF
|
import bastion_form as BF
|
||||||
import bastion_body as BB
|
import bastion_body as BB
|
||||||
|
|
@ -29,8 +31,9 @@ import mechlib as M
|
||||||
import quadruped as Q
|
import quadruped as Q
|
||||||
|
|
||||||
F, T = M.frame_at, Matrix.Translation
|
F, T = M.frame_at, Matrix.Translation
|
||||||
P, P2, CORE = "olive", "olive_light", "gunmetal"
|
P, P2, CORE = BF.P, BF.P2, BF.CORE
|
||||||
FOOT_PIN = 0.1
|
FOOT_PIN = 0.1
|
||||||
|
LEAN_FRONT = 18.0 # degrees a front thigh's housing stands off upright (the side view)
|
||||||
RECORDS = {"hip_splay": ((-6.0, 14.0), "hip_splay"), "hip_pitch_front": ((-32.0, 32.0), "hip_pitch"), "hip_pitch_rear": ((-30.0, 34.0), "hip_pitch"),
|
RECORDS = {"hip_splay": ((-6.0, 14.0), "hip_splay"), "hip_pitch_front": ((-32.0, 32.0), "hip_pitch"), "hip_pitch_rear": ((-30.0, 34.0), "hip_pitch"),
|
||||||
"knee_front": ((-35.0, 40.0), "knee"), "knee_rear": ((-40.0, 45.0), "knee"), "turret_yaw": ((-180.0, 180.0), "turret_yaw"), "gun_pitch": ((-8.0, 28.0), "gun_pitch"),
|
"knee_front": ((-35.0, 40.0), "knee"), "knee_rear": ((-40.0, 45.0), "knee"), "turret_yaw": ((-180.0, 180.0), "turret_yaw"), "gun_pitch": ((-8.0, 28.0), "gun_pitch"),
|
||||||
"ankle": ((-30.0, 30.0), "ankle_pitch"), "ankle_roll": ((-22.0, 22.0), "ankle_roll")}
|
"ankle": ((-30.0, 30.0), "ankle_pitch"), "ankle_roll": ((-22.0, 22.0), "ankle_roll")}
|
||||||
|
|
@ -38,6 +41,7 @@ RX = lambda d: Matrix.Rotation(math.radians(d), 4, "X") # noqa: E731
|
||||||
RY = lambda d: Matrix.Rotation(math.radians(d), 4, "Y") # noqa: E731
|
RY = lambda d: Matrix.Rotation(math.radians(d), 4, "Y") # noqa: E731
|
||||||
RZ = lambda d: Matrix.Rotation(math.radians(d), 4, "Z") # noqa: E731
|
RZ = lambda d: Matrix.Rotation(math.radians(d), 4, "Z") # noqa: E731
|
||||||
TIMES = {}
|
TIMES = {}
|
||||||
|
HARD = {} # every hard plate's report: kind, corners, facets
|
||||||
|
|
||||||
|
|
||||||
def frozen(before):
|
def frozen(before):
|
||||||
|
|
@ -74,6 +78,36 @@ def geo(name, mat, host, build, smooth=38.0, bevel=0.0):
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def hard(name, points, host, mat=P, bevel=0.035, clad=None, seed=0, **kw):
|
||||||
|
"""massing.hard, reported; `clad` is a test (normal, centre) of which facets take detail plating."""
|
||||||
|
obj = MS.hard(name, points, host, mat, bevel=bevel, **kw)
|
||||||
|
HARD[name] = {"kind": "hard", "corners": len(obj.data.vertices), "facets": len(obj.data.polygons)}
|
||||||
|
if clad:
|
||||||
|
g, bolts = M.Geo(), M.Geo()
|
||||||
|
if MS.clad(obj, g, keep=clad, min_area=0.5, seed=seed, inset=0.09, bolts=bolts):
|
||||||
|
bolts.to_object(name + ".bolts", "gunmetal", host)
|
||||||
|
o = g.to_object(name + ".panels", P2 if mat == P else P, host, 1.0)
|
||||||
|
mod = o.modifiers.new("Bevel", "BEVEL")
|
||||||
|
mod.width, mod.segments, mod.limit_method, mod.angle_limit = 0.012, 1, "ANGLE", math.radians(20)
|
||||||
|
for p in o.data.polygons:
|
||||||
|
p.use_smooth = False
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def box_pts(x0, x1, y0, y1, z0, z1):
|
||||||
|
return [(x, y, z) for x in (x0, x1) for y in (y0, y1) for z in (z0, z1)]
|
||||||
|
|
||||||
|
|
||||||
|
def ring8(w, y0, y1, c):
|
||||||
|
"""A chamfered rectangle's eight corners: w across x, from y0 to y1."""
|
||||||
|
return [(-w / 2 + c, y0), (w / 2 - c, y0), (w / 2, y0 + c), (w / 2, y1 - c), (w / 2 - c, y1), (-w / 2 + c, y1), (-w / 2, y1 - c), (-w / 2, y0 + c)]
|
||||||
|
|
||||||
|
|
||||||
|
def housing_pts(sections):
|
||||||
|
"""A housing's corners from its sections down a limb: [(z, width, y0, y1, chamfer)]."""
|
||||||
|
return [(x, y, z) for z, w, y0, y1, c in sections for x, y in ring8(w, y0, y1, c)]
|
||||||
|
|
||||||
|
|
||||||
def disc(g, at, r, w, rings=3, bolts=12):
|
def disc(g, at, r, w, rings=3, bolts=12):
|
||||||
"""A rotary housing's face: a drum along at's z from 0 to w, its outer face stepped in `rings` rings to a hub."""
|
"""A rotary housing's face: a drum along at's z from 0 to w, its outer face stepped in `rings` rings to a hub."""
|
||||||
prof = [(0, 0), (r, 0), (r, 0.72 * w)]
|
prof = [(0, 0), (r, 0), (r, 0.72 * w)]
|
||||||
|
|
@ -87,64 +121,56 @@ def disc(g, at, r, w, rings=3, bolts=12):
|
||||||
return g
|
return g
|
||||||
|
|
||||||
|
|
||||||
# --- wells and plates ---------------------------------------------------------------------------------------------------
|
def stack(g, at, bolts=20):
|
||||||
CROWN = 7.6
|
"""A rear hip's bearing as the hero draws it: a drum, a flange, two stepped discs and a hub along at's z, bolted,
|
||||||
MAG = dict(y0=-1.25, y1=1.05, z0=5.55, z1=6.55, depth=1.5)
|
the second step webbed with eight ribs."""
|
||||||
|
g.lathe(at, [(0, 0.55), (1.2, 0.55), (1.2, 0.8), (1.32, 0.8), (1.32, 0.88), (1.0, 0.88), (1.0, 1.06), (0.78, 1.06), (0.78, 1.2), (0.3, 1.2), (0.3, 1.32), (0, 1.32)], 56)
|
||||||
|
g.bolts(at @ T((0, 0, 0.88)), 1.16, bolts, 0.04, 0.05)
|
||||||
def wells():
|
g.bolts(at @ T((0, 0, 1.2)), 0.54, 10, 0.035, 0.04)
|
||||||
"""The cutters: the cockpit's recess under the nose's rim, a magazine's compartment in each flank band."""
|
for k in range(8):
|
||||||
cuts = [MS.slab("Cockpit.cut", (0, 6.0, 5.2), (3.5, 1.9, 0.5), BB.I4)]
|
g.box(at @ RZ(45.0 * k + 22.5) @ T((0.89, 0, 1.13)), (0.2, 0.08, 0.14))
|
||||||
for sx in (-1, 1):
|
return g
|
||||||
cuts.append(MS.slab(f"Magazine.cut.{'L' if sx < 0 else 'R'}", (sx * 4.6, 0.5 * (MAG["y0"] + MAG["y1"]), 0.5 * (MAG["z0"] + MAG["z1"])), (2 * MAG["depth"], MAG["y1"] - MAG["y0"], MAG["z1"] - MAG["z0"]), BB.I4))
|
|
||||||
return cuts
|
|
||||||
|
|
||||||
|
|
||||||
def plates(skin, cuts):
|
|
||||||
"""The carapace split into its plates along the shoulder line and the quarters: fewer, bigger, each at its own
|
|
||||||
depth. A plate is the mass's own surface (massing.plate), so they conform by construction."""
|
|
||||||
g = 0.035
|
|
||||||
up = lambda e: ((0, -0.065, -1), -(6.62 + e)) # noqa: E731 above the shoulder line
|
|
||||||
low = lambda e: ((0, 0.065, 1), 6.62 - e) # noqa: E731 below it
|
|
||||||
rim = ((0, -0.085, -1), -5.27) # above the rim: the overhang's underside stays the mass
|
|
||||||
H = MS.half
|
|
||||||
made = []
|
|
||||||
|
|
||||||
def add(name, keep, proud, wall, mat=P):
|
|
||||||
o = MS.plate(name, skin, keep, proud=proud, wall=wall, mat=mat, cutters=cuts, bevel=0.03)
|
|
||||||
if o is not None:
|
|
||||||
made.append(o)
|
|
||||||
add("Hull.Crown", [H("z", -1, CROWN)], 0.07, 0.1)
|
|
||||||
add("Hull.Glacis", [H("x", 1, 1.85), H("x", -1, -1.85), H("y", -1, 2.3), H("z", 1, CROWN - 2 * g), H("z", -1, 5.52)], 0.15, 0.16)
|
|
||||||
add("Hull.Tail", [H("x", 1, 1.15), H("x", -1, -1.15), H("y", 1, -2.7), H("z", 1, CROWN - 2 * g), rim], 0.12, 0.14)
|
|
||||||
for sx, tag in ((-1, "L"), (1, "R")):
|
|
||||||
side = lambda at: H("x", -sx, sx * at) # noqa: E731 outboard of |x| = at
|
|
||||||
for name, extra, proud, wall, mat in (
|
|
||||||
("CheekUp", [side(1.85 + 2 * g), H("y", -1, 1.5), up(g)], 0.08, 0.12, P),
|
|
||||||
("CheekBand", [side(1.85 + 2 * g), H("y", -1, 1.5), low(g), rim], 0.13, 0.16, P),
|
|
||||||
("FlankUp", [side(1.0), H("y", 1, 1.5 - 2 * g), H("y", -1, -2.0), up(g)], 0.05, 0.1, P2),
|
|
||||||
("FlankBand", [side(1.0), H("y", 1, 1.5 - 2 * g), H("y", -1, -2.0), low(g), rim], 0.17, 0.2, P),
|
|
||||||
("RearUp", [side(1.15 + 2 * g), H("y", 1, -2.0 - 2 * g), up(g)], 0.09, 0.12, P),
|
|
||||||
("RearBand", [side(1.15 + 2 * g), H("y", 1, -2.0 - 2 * g), low(g), rim], 0.12, 0.15, P2)):
|
|
||||||
add(f"Hull.{name}.{tag}", [H("z", 1, CROWN - 2 * g)] + extra, proud, wall, mat)
|
|
||||||
add("Hull.Chin", [H("x", 1, 2.0), H("x", -1, -2.0), H("y", -1, 4.75), H("z", 1, 4.9), H("z", -1, 3.75)], 0.1, 0.14, P2)
|
|
||||||
return made
|
|
||||||
|
|
||||||
|
|
||||||
|
# --- the head ------------------------------------------------------------------------------------------------------------
|
||||||
def cockpit(host):
|
def cockpit(host):
|
||||||
"""RECESSED COCKPIT & SENSOR SUITE inset: a narrow armoured visor deep under the nose's rim, a row of lamps."""
|
"""RECESSED COCKPIT & SENSOR SUITE inset: a narrow armoured visor deep under the brow, three panes round the
|
||||||
def build(g):
|
head's front and its two chamfers, dark glass between an upper and a lower armoured lid, two sensor lamps."""
|
||||||
g.box(T((0, 5.45, 5.2)), (3.3, 0.3, 0.46))
|
V = BF.VISOR
|
||||||
for x in (-1.2, 0.0, 1.2):
|
z0, z1, yf, h, (wx, wy), yb, (g0, g1) = V["z0"], V["z1"], V["front"], V["half"], V["wing"], V["back"], V["glass"]
|
||||||
g.box(T((x, 5.62, 5.2)), (0.12, 0.2, 0.46))
|
MS.hard("Cockpit.tub", [(x, y, z) for z in (z0, z1) for x, y in ((0, yf), (h, yf), (wx, wy), (wx, yb), (0, yb))], host, CORE, mirror=True, bevel=0.0)
|
||||||
geo("Cockpit.frame", CORE, host, build)
|
zc, gh = 0.5 * (g0 + g1), g1 - g0
|
||||||
geo("Cockpit.visor", "glass", host, lambda g: [g.box(T((x, 5.61, 5.22)) @ RX(-12), (1.05, 0.05, 0.3)) for x in (-0.6, 0.6)])
|
n = Vector((yf - wy, wx - h, 0)).normalized()
|
||||||
geo("Cockpit.lamps", "glow_blue", host, lambda g: [g.box(T((x, 5.64, 5.07)), (0.22, 0.04, 0.05)) for x in (-1.0, -0.45, 0.45, 1.0)])
|
length = math.hypot(wx - h, wy - yf)
|
||||||
# the cheeks' lamp slots under the rim, either side (the hero's light bars)
|
wing = lambda sx, lift: F((sx * (0.5 * (h + wx) + n.x * lift), 0.5 * (yf + wy) + n.y * lift, 0), (sx * n.x, n.y, 0)) # noqa: E731
|
||||||
for sx in (-1, 1):
|
|
||||||
at = F((sx * 3.3, 5.02, 4.98), (sx * 0.45, 1, -0.1))
|
def glass(g):
|
||||||
geo(f"Cheek.lamp.{sx}", CORE, host, lambda g: g.box(at, (1.3, 0.34, 0.5)), bevel=0.02)
|
g.box(T((0, yf + 0.02, zc)), (2 * h - 0.14, 0.04, gh))
|
||||||
geo(f"Cheek.glow.{sx}", "lamp", host, lambda g: g.box(at @ T((0.2, 0.0, 0.26)), (0.42, 0.09, 0.02)))
|
for sx in (-1, 1):
|
||||||
|
g.box(wing(sx, 0.02) @ T((0, zc, 0)), (length - 0.16, gh, 0.04))
|
||||||
|
geo("Cockpit.visor", "glass", host, glass)
|
||||||
|
|
||||||
|
def lids(g):
|
||||||
|
for za, zb in ((g1, z1), (z0, g0)):
|
||||||
|
g.box(T((0, yf + 0.05, 0.5 * (za + zb))), (2 * h + 0.06, 0.12, zb - za))
|
||||||
|
for sx in (-1, 1):
|
||||||
|
g.box(wing(sx, 0.05) @ T((0, 0.5 * (za + zb), 0)), (length + 0.04, zb - za, 0.12))
|
||||||
|
for sx in (-1, 1):
|
||||||
|
g.box(T((sx * h, yf + 0.03, zc)), (0.12, 0.14, gh + 0.02))
|
||||||
|
g.box(wing(sx, 0.05) @ T((sx * 0.5 * length - sx * 0.04, zc, 0)), (0.1, gh, 0.12))
|
||||||
|
g.box(T((0, yf + 0.04, zc)), (0.07, 0.1, gh))
|
||||||
|
geo("Cockpit.frame", P2, host, lids, bevel=0.015)
|
||||||
|
geo("Cockpit.lamps", "glow_blue", host, lambda g: [g.box(T((x, yf + 0.045, g0 + 0.07)), (0.14, 0.02, 0.045)) for x in (-0.62, 0.62)])
|
||||||
|
|
||||||
|
|
||||||
|
def cheek_lamp(host, sx):
|
||||||
|
"""The light bar in the slot under a cheek pod's front (the hero and the front view): a dark housing on the
|
||||||
|
tray's face, one lit lens at its inboard end, two dark ones."""
|
||||||
|
L = BF.LAMP
|
||||||
|
at = F((sx * L["at"][0], L["at"][1], L["at"][2]), (sx * L["normal"][0], L["normal"][1], 0))
|
||||||
|
tag = "L" if sx < 0 else "R"
|
||||||
|
geo(f"Cheek.lamp.{tag}", CORE, host, lambda g: [g.box(at @ T((0, 0, 0.03)), (2.0, 0.17, 0.1))] + [g.box(at @ T((x, 0, 0.09)), (0.34, 0.12, 0.04)) for x in (-0.25, 0.3)], bevel=0.01)
|
||||||
|
geo(f"Cheek.glow.{tag}", "lamp", host, lambda g: g.box(at @ T((sx * 0.72, 0, 0.1)), (0.3, 0.07, 0.02)))
|
||||||
|
|
||||||
|
|
||||||
def magazine(host, sx):
|
def magazine(host, sx):
|
||||||
|
|
@ -152,9 +178,10 @@ def magazine(host, sx):
|
||||||
prompt's segmented door, hinged on the upper edge, open upward."""
|
prompt's segmented door, hinged on the upper edge, open upward."""
|
||||||
import hardpoint as HP
|
import hardpoint as HP
|
||||||
tag = "L" if sx < 0 else "R"
|
tag = "L" if sx < 0 else "R"
|
||||||
|
MAG = BF.MAG
|
||||||
y0, y1, z0, z1 = MAG["y0"], MAG["y1"], MAG["z0"], MAG["z1"]
|
y0, y1, z0, z1 = MAG["y0"], MAG["y1"], MAG["z0"], MAG["z1"]
|
||||||
w, h = y1 - y0, z1 - z0
|
w, h = y1 - y0, z1 - z0
|
||||||
face = F((sx * 4.3, 0.5 * (y0 + y1), 0.5 * (z0 + z1)), (sx, 0, 0.0), (0, 0, 1)) # z outboard, y up, x along the hull
|
face = F((sx * (MAG["face"] - 0.1), 0.5 * (y0 + y1), 0.5 * (z0 + z1)), (sx, 0, 0.0), (0, 0, 1)) # z outboard, y up, x along the hull
|
||||||
b = M.Build(f"Magazine.{tag}", host, None)
|
b = M.Build(f"Magazine.{tag}", host, None)
|
||||||
fr = b["gunmetal"]
|
fr = b["gunmetal"]
|
||||||
for u in (-0.5 * w - 0.06, 0.5 * w + 0.06):
|
for u in (-0.5 * w - 0.06, 0.5 * w + 0.06):
|
||||||
|
|
@ -186,7 +213,6 @@ def magazine(host, sx):
|
||||||
b["steel"].rod(face @ Vector((s * 0.46 * w, 0.45 * h, 0.0)), hinge @ RX(-78.0) @ Vector((s * 0.46 * w, -0.8 * seg, 0.0)), 0.03, 8)
|
b["steel"].rod(face @ Vector((s * 0.46 * w, 0.45 * h, 0.0)), hinge @ RX(-78.0) @ Vector((s * 0.46 * w, -0.8 * seg, 0.0)), 0.03, 8)
|
||||||
return b.done()
|
return b.done()
|
||||||
|
|
||||||
|
|
||||||
def interceptor(name, host, at, yaw):
|
def interceptor(name, host, at, yaw):
|
||||||
"""PERIMETER INTERCEPTOR LAUNCHER inset: a small box of four tubes, two over two, with a hooded sight on its
|
"""PERIMETER INTERCEPTOR LAUNCHER inset: a small box of four tubes, two over two, with a hooded sight on its
|
||||||
cheek, trunnioned in a fork on a turning pedestal. `at` is the pedestal's foot, z out of the shell."""
|
cheek, trunnioned in a fork on a turning pedestal. `at` is the pedestal's foot, z out of the shell."""
|
||||||
|
|
@ -206,141 +232,181 @@ def interceptor(name, host, at, yaw):
|
||||||
return b.done()
|
return b.done()
|
||||||
|
|
||||||
|
|
||||||
|
# --- cooling ---------------------------------------------------------------------------------------------------------------
|
||||||
def cooling(host):
|
def cooling(host):
|
||||||
"""REAR COOLING ARRAYS inset under the prompt's sculpted housings: two fin banks on the tail, each under a
|
"""REAR COOLING ARRAYS inset, the rear view's two framed radiator faces and the hero's ribbed housing: each
|
||||||
housing that is a minimal free cage (an arched hood open to the rear), a manifold between them."""
|
assembly is a fin bank behind a framed rear face of two panels and a second bank in its flank, under a housing
|
||||||
|
(a chamfered hood that overhangs the rear face and falls forward into the tail, a ribbed outer wall, an inner
|
||||||
|
wall, a floor); a machinery block with its manifold stands between the two. Hard: the concept draws them boxed."""
|
||||||
|
x0, x1, ya, yb, z0, z1 = 1.5, 3.64, -4.85, -7.15, 5.14, 7.35
|
||||||
|
xc = 0.5 * (x0 + x1)
|
||||||
out = []
|
out = []
|
||||||
for sx in (-1, 1):
|
for sx in (-1, 1):
|
||||||
tag = "L" if sx < 0 else "R"
|
tag = "L" if sx < 0 else "R"
|
||||||
c = Vector((sx * 2.25, -5.6, 6.3))
|
hood = [(x0 - 0.08, yb - 0.1, z1 - 0.2), (x1 + 0.08, yb - 0.1, z1 - 0.2), (x0 + 0.12, yb - 0.02, z1), (x1 - 0.14, yb - 0.02, z1), (x0 + 0.12, ya - 0.7, z1 + 0.04), (x1 - 0.14, ya - 0.7, z1 + 0.04),
|
||||||
w, d, h = 1.6, 1.8, 2.2
|
(x0, ya + 0.55, 6.98), (x1 - 0.1, ya + 0.55, 6.84), (x0 - 0.08, ya - 0.7, z1 - 0.2), (x1 + 0.08, ya - 0.7, z1 - 0.2), (x0 - 0.08, ya + 0.55, 6.78), (x1 + 0.08, ya + 0.55, 6.66),
|
||||||
# the hood: authored on its right half and mirrored; front (toward the hull), crown and flank, open behind and below
|
(x0 - 0.08, yb - 0.1, z1 - 0.36), (x1 + 0.08, yb - 0.1, z1 - 0.36), (x0 - 0.08, ya + 0.55, 6.6), (x1 + 0.08, ya + 0.55, 6.5)]
|
||||||
verts = [[0.0, 0.5 * d, 0.5 * h + 0.05], [0.0, -0.5 * d, 0.5 * h + 0.2],
|
out.append(hard(f"Cooling.hood.{tag}", hood, host, P, bevel=0.06, sx=sx, clad=lambda n, c: n.z > 0.6, seed=3))
|
||||||
[0.5 * w, 0.5 * d, 0.32 * h], [0.5 * w, -0.5 * d, 0.4 * h],
|
out.append(hard(f"Cooling.wall.{tag}", box_pts(x1 - 0.16, x1 + 0.04, ya, yb + 0.78, z0, z1 - 0.3), host, P, bevel=0.03, sx=sx))
|
||||||
[0.56 * w, 0.42 * d, -0.5 * h], [0.56 * w, -0.5 * d, -0.5 * h],
|
out.append(hard(f"Cooling.inner.{tag}", box_pts(x0 - 0.04, x0 + 0.14, ya, yb, z0, z1 - 0.3), host, P, bevel=0.03, sx=sx))
|
||||||
[0.0, 0.62 * d, -0.1 * h], [0.5 * w, 0.6 * d, -0.2 * h]]
|
out.append(hard(f"Cooling.floor.{tag}", box_pts(x0 - 0.08, x1 + 0.08, ya, yb - 0.06, z0 - 0.04, z0 + 0.16), host, P2, bevel=0.04, sx=sx))
|
||||||
faces = [[0, 1, 3, 2], [2, 3, 5, 4], [6, 0, 2, 7]]
|
|
||||||
sheet = {"verts": verts, "faces": faces, "creases": [[2, 3, 0.7], [0, 2, 0.5]], "mirror": True, "rim": 0.6}
|
def frame(g):
|
||||||
out.append(MS.cage_shell(f"Cooling.hood.{tag}", sheet, host, T(c), mat=P, thickness=0.14, levels=2, bevel=0.03, inside=(0, 0, -0.3)))
|
for x, w in ((x0 + 0.1, 0.22), (xc, 0.14), (x1 - 0.07, 0.2)): # posts and the mullion of the rear face
|
||||||
|
g.box(T((sx * x, yb + 0.06, 0.5 * (z0 + z1) - 0.1)), (w, 0.2, z1 - z0 - 0.5))
|
||||||
|
for z, hgt in ((z1 - 0.44, 0.2), (z0 + 0.25, 0.2)):
|
||||||
|
g.box(T((sx * xc, yb + 0.06, z)), (x1 - x0, 0.2, hgt))
|
||||||
|
for y in (yb + 0.74,): # the flank window's forward post
|
||||||
|
g.box(T((sx * (x1 - 0.06), y, 0.5 * (z0 + z1) - 0.1)), (0.2, 0.16, z1 - z0 - 0.5))
|
||||||
|
for k in range(5): # the ribs of the outer wall
|
||||||
|
g.box(T((sx * (x1 + 0.07), ya - 0.2 - 0.27 * k, 0.5 * (z0 + z1) - 0.12)), (0.12, 0.11, z1 - z0 - 0.62))
|
||||||
|
out.append(geo(f"Cooling.frame.{tag}", P2, host, frame, bevel=0.03))
|
||||||
|
|
||||||
def fins(g):
|
def fins(g):
|
||||||
n = 15
|
for x_a, x_b in ((x0 + 0.23, xc - 0.09), (xc + 0.09, x1 - 0.19)):
|
||||||
for k in range(n):
|
n = int((x_b - x_a) / 0.062)
|
||||||
g.box(T(c + Vector(((k - (n - 1) / 2) * 0.085, -0.25, -0.1))), (0.03, 1.2, 1.9))
|
for k in range(n + 1):
|
||||||
|
g.box(T((sx * (x_a + (x_b - x_a) * k / n), yb + 0.24, 0.5 * (z0 + z1) - 0.1)), (0.02, 0.3, z1 - z0 - 0.86))
|
||||||
|
n = 9
|
||||||
|
for k in range(n + 1):
|
||||||
|
g.box(T((sx * (x1 - 0.2), yb + 0.2 + 0.46 * k / n, 0.5 * (z0 + z1) - 0.1)), (0.3, 0.02, z1 - z0 - 0.86))
|
||||||
out.append(geo(f"Cooling.fins.{tag}", "machine", host, fins, smooth=5))
|
out.append(geo(f"Cooling.fins.{tag}", "machine", host, fins, smooth=5))
|
||||||
|
out.append(geo(f"Cooling.core.{tag}", CORE, host, lambda g: g.box(T((sx * xc, 0.5 * (ya + yb) + 0.2, 0.5 * (z0 + z1) - 0.1)), (x1 - x0 - 0.5, ya - yb - 0.4, z1 - z0 - 0.5))))
|
||||||
def core(g):
|
out.append(hard("Cooling.block", box_pts(-1.5, 1.5, -6.5, -4.6, 5.5, 7.18), host, CORE, bevel=0.04))
|
||||||
g.box(T(c + Vector((0, 0.1, -0.15))), (1.36, 1.5, 1.7))
|
out.append(hard("Cooling.block.cap", [(-1.46, -6.62, 7.18), (1.46, -6.62, 7.18), (-1.46, -4.9, 7.18), (1.46, -4.9, 7.18), (-1.3, -6.5, 7.34), (1.3, -6.5, 7.34), (-1.3, -4.9, 7.34), (1.3, -4.9, 7.34)],
|
||||||
g.box(T(c + Vector((0, -0.86, -1.1))), (1.42, 0.12, 0.14))
|
host, P2, bevel=0.03, clad=lambda n, c: n.z > 0.6, seed=5))
|
||||||
g.box(T(c + Vector((0, -0.86, 0.82))), (1.42, 0.12, 0.14))
|
out.append(hard("Cooling.block.low", box_pts(-1.15, 1.15, -6.1, -4.4, 4.1, 5.5), host, CORE, bevel=0.04))
|
||||||
out.append(geo(f"Cooling.core.{tag}", CORE, host, core))
|
|
||||||
|
|
||||||
def manifold(g):
|
def manifold(g):
|
||||||
g.box(T((0, -5.5, 5.75)), (3.0, 1.2, 1.3))
|
for z in (5.95, 6.4, 6.85):
|
||||||
for z in (5.4, 5.9, 6.3):
|
g.rod((-1.5, -6.6, z), (1.5, -6.6, z), 0.12, 12)
|
||||||
g.rod((-1.5, -6.05, z), (1.5, -6.05, z), 0.11, 12)
|
for x in (-1.2, 0.0, 1.2):
|
||||||
g.box(T((0, -5.8, 4.9)), (1.8, 0.9, 0.7))
|
g.cylinder(T((x, -6.6, z)) @ RY(90), 0.16, 0.12, 12)
|
||||||
out.append(geo("Cooling.manifold", CORE, host, manifold))
|
g.box(T((0, -6.62, 5.2)), (1.7, 0.3, 0.75))
|
||||||
|
for x in (-0.55, 0.55):
|
||||||
|
g.cylinder(T((x, -6.8, 5.2)) @ RX(90), 0.24, 0.12, 20)
|
||||||
|
out.append(geo("Cooling.manifold", "machine", host, manifold))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
# --- legs -----------------------------------------------------------------------------------------------------------
|
# --- legs -----------------------------------------------------------------------------------------------------------
|
||||||
def hip_housing(tag, host, hip, rear):
|
def hip_housing(tag, host, hip, rear):
|
||||||
"""The rotary housing at a corner of the hull: a fixed drum under the overhang, on the hull's flank, the thigh's
|
"""The reinforced rotary housing at a corner of the hull (the prompt): a fixed drum under the overhang on a
|
||||||
drum turning in it. Authored in the world (the trunk's frame)."""
|
bracket into the hull, its outer race bolted; over a front hip an armoured shroud."""
|
||||||
sx = -1 if tag[-1] == "l" else 1
|
sx = -1 if tag[-1] == "l" else 1
|
||||||
r = 1.3 if rear else 0.98
|
r = 1.25 if rear else 0.8
|
||||||
hip = Vector(hip)
|
hip = Vector(hip)
|
||||||
inner = 2.3
|
inner = 2.3
|
||||||
|
reach = abs(hip.x) - inner - (0.62 if rear else 1.0)
|
||||||
|
|
||||||
def fixed(g):
|
def fixed(g):
|
||||||
at = F((sx * inner, hip.y, hip.z), (sx, 0, 0), (0, 0, 1))
|
at = F((sx * inner, hip.y, hip.z), (sx, 0, 0), (0, 0, 1))
|
||||||
g.lathe(at, [(0, 0), (1.02 * r, 0), (1.02 * r, abs(hip.x) - inner - 0.5), (0.9 * r, abs(hip.x) - inner - 0.42), (0, abs(hip.x) - inner - 0.42)], 48)
|
g.lathe(at, [(0, 0), (1.02 * r, 0), (1.02 * r, reach), (0.9 * r, reach + 0.08), (0, reach + 0.08)], 48)
|
||||||
# the bracket up into the overhang
|
|
||||||
g.box(T((sx * (inner + 0.6), hip.y, hip.z + 0.75 * r)), (1.3, 1.5 * r, 1.4 * r))
|
g.box(T((sx * (inner + 0.6), hip.y, hip.z + 0.75 * r)), (1.3, 1.5 * r, 1.4 * r))
|
||||||
geo(f"Hip.housing.{tag}", CORE, host, fixed)
|
geo(f"Hip.housing.{tag}", CORE, host, fixed)
|
||||||
geo(f"Hip.collar.{tag}", "machine", host, lambda g: (g.lathe(F((sx * (abs(hip.x) - 0.52), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)),
|
geo(f"Hip.collar.{tag}", "machine", host, lambda g: (g.lathe(F((sx * (inner + reach - 0.02), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), [(1.08 * r, 0), (1.08 * r, 0.14), (0.96 * r, 0.14), (0.96 * r, 0)], 48),
|
||||||
[(1.08 * r, 0), (1.08 * r, 0.14), (0.96 * r, 0.14), (0.96 * r, 0)], 48),
|
g.bolts(F((sx * (inner + reach + 0.12), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), 1.02 * r, 20, 0.035, 0.04)))
|
||||||
g.bolts(F((sx * (abs(hip.x) - 0.38), hip.y, hip.z), (sx, 0, 0), (0, 0, 1)), 1.02 * r, 20, 0.035, 0.04)))
|
if not rear:
|
||||||
|
hard(f"Hip.shroud.{tag}", [(sx * x, hip.y + y, hip.z + z) for x, y, z in ((2.35, -1.2, 0.5), (2.35, 1.0, 0.5), (3.5, -1.2, 0.7), (3.5, 1.0, 0.7), (2.35, -1.3, 1.75), (2.35, 1.1, 1.75), (3.7, -1.3, 1.75), (3.7, 1.1, 1.75))],
|
||||||
|
host, P2, bevel=0.03)
|
||||||
|
|
||||||
|
|
||||||
def shield_sheet(w, top, bottom, lead, crown, back):
|
def leg_front(tag, bones, pose):
|
||||||
"""A leg's guard plate as a minimal free cage, right half (mirrored): a front face from `top` to `bottom` (z,
|
"""A front leg (the hero's near leg, the side and front views; no inset): short and heavily armoured. The thigh is
|
||||||
down the limb is negative) standing `lead` before the limb's axis and `crown` further at its middle, a side
|
an armoured housing on the hip's bearing, its discs standing proud either side; the shin a second, flared
|
||||||
wrapped back to `back`, a hood over the top. Ten authored vertices."""
|
housing; each housing a hard solid of chamfered sections with stepped panels on its face and flanks. A ram
|
||||||
mid = 0.45 * top + 0.55 * bottom
|
behind the thigh drives the hip's pitch (ram core)."""
|
||||||
verts = [[0, lead + 0.1, top + 0.1], [0, lead + crown, mid], [0, lead + 0.05, bottom - 0.1], # the seam
|
sx = -1 if tag[-1] == "l" else 1
|
||||||
[0.5 * w, lead - 0.05, top], [0.52 * w, lead + 0.7 * crown, mid], [0.44 * w, lead - 0.05, bottom], # the front's edge
|
|
||||||
[0.56 * w, back, top - 0.05], [0.58 * w, back + 0.05, mid], [0.5 * w, back + 0.1, bottom + 0.1], # the side's rear edge
|
|
||||||
[0, back + 0.1, top + 0.22]] # the hood's rear, on the seam
|
|
||||||
faces = [[0, 3, 4, 1], [1, 4, 5, 2], [3, 6, 7, 4], [4, 7, 8, 5], [9, 6, 3, 0]]
|
|
||||||
return {"verts": verts, "faces": faces, "creases": [[3, 4, 0.75], [4, 5, 0.75], [0, 3, 0.5]], "mirror": True, "rim": 0.7}
|
|
||||||
|
|
||||||
|
|
||||||
def leg_dress(tag, bones, pose):
|
|
||||||
"""One leg's machinery and armour on its bones (z up the segment, toward its upper joint; x the pin).
|
|
||||||
Front: a short stout girder, a great guard plate before the thigh that hides the hip from the front, a smaller
|
|
||||||
one down the shin. Rear: REAR LEG PROPULSION ASSEMBLY inset - a long open twin-beam thigh, two exposed chromed
|
|
||||||
rams from the hip's housing to the hock, a great layered hip disc, a guard plate behind the lower thigh."""
|
|
||||||
rear, sx = tag[0] == "r", (-1 if tag[-1] == "l" else 1)
|
|
||||||
th, sh, hipb = bones[f"Thigh.{tag}"], bones[f"Shin.{tag}"], bones[f"Bone.hip_splay.{tag}"]
|
th, sh, hipb = bones[f"Thigh.{tag}"], bones[f"Shin.{tag}"], bones[f"Bone.hip_splay.{tag}"]
|
||||||
l1, l2 = (float(json.loads(o["kit_params"])["length"]) for o in (th, sh))
|
l1, l2 = (float(json.loads(o["kit_params"])["length"]) for o in (th, sh))
|
||||||
r_hip, r_knee = (1.22, 0.62) if rear else (0.9, 0.56)
|
r_hip, r_knee = 0.88, 0.56
|
||||||
out = F((0, 0, 0), (sx, 0, 0), (0, 0, 1)) # a frame whose z is outboard
|
out = F((0, 0, 0), (sx, 0, 0), (0, 0, 1))
|
||||||
|
face = lambda n, c: n.y > 0.5 or abs(n.x) > 0.7 # noqa: E731 the front and the flanks take panels
|
||||||
|
|
||||||
def thigh(g):
|
# the housing leans less than the thigh under it: the side view's guard stands about 18 degrees off upright over a
|
||||||
if rear:
|
# thigh the marks put at 39, and the hero's near leg reads as a pillar. G is that frame, in the thigh's own.
|
||||||
for s in (-1, 1):
|
M.update()
|
||||||
g.sweep([(s * 0.52, 0, 0), (s * 0.52, 0, -l1)], [(-0.09, -0.3), (0.09, -0.3), (0.09, 0.3), (-0.09, 0.3)], (0, 1, 0))
|
upright = (th.matrix_world.inverted() @ hipb.matrix_world).to_3x3().to_quaternion()
|
||||||
for z in (0.3, 0.52, 0.74):
|
pitch = math.degrees(upright.angle)
|
||||||
g.box(T((0, 0.12, -z * l1)), (1.0, 0.18, 0.24))
|
G = Quaternion().slerp(upright, max(0.0, 1.0 - LEAN_FRONT / max(pitch, 1e-6))).to_matrix().to_4x4()
|
||||||
g.cylinder(T((0, 0, -l1)) @ RY(90), 0.3, 1.3, 20)
|
knee = G.inverted() @ Vector((0, 0, -l1))
|
||||||
else:
|
geo(f"Thigh.girder.{tag}", CORE, th, lambda g: (g.box(T((0, 0, -0.5 * l1)), (1.5, 0.9, l1)), g.box(T((0, -0.5, -0.5 * l1)), (0.7, 0.4, 0.8 * l1))), bevel=0.015)
|
||||||
g.box(T((0, 0, -0.5 * l1)), (0.9, 0.8, l1))
|
y1 = knee.y + 0.62
|
||||||
g.box(T((0, -0.36, -0.5 * l1)), (0.6, 0.3, 0.7 * l1))
|
pts = housing_pts([(1.0, 1.35, -0.3, 0.6, 0.2), (0.72, 1.9, -0.6, y1, 0.24), (knee.z + 0.1, 1.9, -0.45, y1, 0.24), (knee.z - 0.42, 1.62, -0.2, y1 - 0.14, 0.2)])
|
||||||
geo(f"Thigh.girder.{tag}", CORE, th, thigh, bevel=0.015)
|
made = [hard(f"Thigh.guard.{tag}", [G @ Vector(p) for p in pts], th, P, clad=lambda n, c: (G.inverted().to_3x3() @ n).y > 0.5 or abs(n.x) > 0.7, seed=11)]
|
||||||
|
|
||||||
def drums(g):
|
def drums(g):
|
||||||
disc(g, out @ T((0, 0, 0.1)), r_hip, 0.62 if rear else 0.5, rings=4 if rear else 3, bolts=20 if rear else 14)
|
for s in (-1, 1):
|
||||||
g.cylinder(RY(90), 0.82 * r_hip, 1.0, 40)
|
side = F((0, 0, 0), (s, 0, 0), (0, 0, 1))
|
||||||
kn = T((0, 0, -l1))
|
disc(g, side @ T((0, 0, 0.93)), r_hip, 0.3, rings=3, bolts=14)
|
||||||
disc(g, kn @ out @ T((0, 0, 0.42)), r_knee, 0.22, rings=2, bolts=10)
|
disc(g, T((0, 0, -l1)) @ side @ T((0, 0, 0.93)), r_knee, 0.22, rings=2, bolts=10)
|
||||||
g.cylinder(kn @ RY(90), r_knee, 0.84, 32)
|
g.cylinder(RY(90), 0.8 * r_hip, 1.9, 40)
|
||||||
disc(g, kn @ F((0, 0, 0), (-sx, 0, 0), (0, 0, 1)) @ T((0, 0, 0.42)), 0.8 * r_knee, 0.14, rings=2, bolts=8)
|
g.cylinder(T((0, 0, -l1)) @ RY(90), 0.9 * r_knee, 1.9, 32)
|
||||||
geo(f"Thigh.drums.{tag}", "machine", th, drums)
|
geo(f"Thigh.drums.{tag}", "machine", th, drums)
|
||||||
|
|
||||||
def shin(g):
|
geo(f"Shin.column.{tag}", CORE, sh, lambda g: (g.box(T((0, 0, -0.5 * l2)), (1.2, 0.8, l2)), g.cylinder(T((0, 0, -l2)) @ RY(90), 0.42, 1.5, 24)), bevel=0.015)
|
||||||
g.box(T((0, 0, -0.5 * l2)), (0.74, 0.7, l2))
|
made.append(hard(f"Shin.guard.{tag}", housing_pts([(0.02, 1.5, -0.42, 0.62, 0.18), (-0.3, 1.74, -0.5, 0.76, 0.2), (-l2 + 0.3, 1.9, -0.56, 0.84, 0.22), (-l2 + 0.08, 1.7, -0.46, 0.72, 0.2)]), sh, P2, clad=face, seed=12))
|
||||||
g.cylinder(T((0, 0, -l2)) @ RY(90), 0.4, 1.0, 24)
|
M.update()
|
||||||
if rear:
|
to_hip = hipb.matrix_world.inverted() @ th.matrix_world
|
||||||
g.box(T((0, 0.3, -0.45 * l2)), (0.5, 0.4, 0.7 * l2))
|
a = [to_hip @ Vector((0, y, z)) for y in (-0.6, -0.85, -1.1) for z in (0.9, 0.6, 0.3)]
|
||||||
geo(f"Shin.column.{tag}", CORE, sh, shin, bevel=0.015)
|
fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, -0.66, -k * l1) for k in (0.95, 0.8, 0.65)], 0.11, RECORDS["hip_pitch_front"][0])
|
||||||
made = []
|
return made + objs
|
||||||
if rear:
|
|
||||||
# the guard plate behind the lower thigh (the hero's plate standing up from the hock), its face aft
|
|
||||||
sheet = shield_sheet(1.5, -0.42 * l1, -l1 - 0.25, 0.62, 0.16, 0.05)
|
def leg_rear(tag, bones, pose):
|
||||||
made.append(MS.cage_shell(f"Thigh.guard.{tag}", sheet, th, RZ(180), mat=P, thickness=0.12, levels=2, bevel=0.025, inside=(0, 0, -0.7 * l1)))
|
"""A rear leg, REAR LEG PROPULSION ASSEMBLY inset with orientation and exposure from the side view and the hero:
|
||||||
# the propulsion rams: from the fixed housing under the hip, either side of the beams' middle, to the hock
|
longer, its hydraulics exposed. A great stepped bearing stack outboard of the hip; a long open twin-beam thigh;
|
||||||
M.update()
|
two chromed rams under it from a mount on the hull's hip housing to the hock, seated by ram core (the hip's
|
||||||
to_hip = hipb.matrix_world.inverted() @ th.matrix_world
|
pitch); an armoured shroud over the thigh's head and a tall guard plate standing off the back of its lower
|
||||||
a = [to_hip @ Vector((0, y, z)) for y in (0.7, 0.95, 1.2) for z in (0.3, 0.0, -0.3)]
|
half; a bearing either side of the hock; a short armoured shin."""
|
||||||
fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, 0.34, -k * l1) for k in (0.9, 0.8, 0.7)], 0.15, RECORDS["hip_pitch_rear"][0], twin=0.26)
|
sx = -1 if tag[-1] == "l" else 1
|
||||||
made += objs
|
th, sh, hipb = bones[f"Thigh.{tag}"], bones[f"Shin.{tag}"], bones[f"Bone.hip_splay.{tag}"]
|
||||||
else:
|
l1, l2 = (float(json.loads(o["kit_params"])["length"]) for o in (th, sh))
|
||||||
# the thigh's guard hangs upright at the stance, a boxed shroud before the hip and over the knee: the concept's
|
out = F((0, 0, 0), (sx, 0, 0), (0, 0, 1))
|
||||||
# front leg reads as a pillar, whatever the thigh's lean under it
|
inb = F((0, 0, 0), (-sx, 0, 0), (0, 0, 1))
|
||||||
M.update()
|
kn = T((0, 0, -l1))
|
||||||
upright = (th.matrix_world.inverted() @ hipb.matrix_world).to_3x3().to_4x4()
|
|
||||||
knee = upright.inverted() @ Vector((0, 0, -l1))
|
def thigh(g):
|
||||||
sheet = shield_sheet(2.0, 1.0, knee.z - 0.45, knee.y + 0.55, 0.14, 0.4)
|
for s in (-1, 1):
|
||||||
made.append(MS.cage_shell(f"Thigh.guard.{tag}", sheet, th, upright @ T((sx * 0.25, 0, 0)), mat=P, thickness=0.14, levels=2, bevel=0.03, inside=(0, 0, 0.5 * knee.z)))
|
g.sweep([(s * 0.52, 0, 0), (s * 0.52, 0, -l1)], [(-0.09, -0.32), (0.09, -0.32), (0.09, 0.32), (-0.09, 0.32)], (0, 1, 0))
|
||||||
sheet = shield_sheet(1.45, 0.25, -l2 + 0.1, 0.5, 0.12, -0.2)
|
g.sweep([(s * 0.52, -0.3, -0.1 * l1), (s * 0.52, -0.3, -0.95 * l1)], [(-0.13, -0.05), (0.13, -0.05), (0.13, 0.05), (-0.13, 0.05)], (0, 1, 0))
|
||||||
made.append(MS.cage_shell(f"Shin.guard.{tag}", sheet, sh, T((sx * 0.1, 0, 0)), mat=P2, thickness=0.11, levels=2, bevel=0.025, inside=(0, 0, -0.5 * l2)))
|
for z in (0.3, 0.46, 0.62, 0.78):
|
||||||
to_hip = hipb.matrix_world.inverted() @ th.matrix_world
|
g.box(T((0, 0.1, -z * l1)), (1.0, 0.2, 0.26))
|
||||||
a = [to_hip @ Vector((0, y, z)) for y in (-0.5, -0.75, -1.0) for z in (0.9, 0.6, 0.3)]
|
g.rod((0, -0.12, -0.2 * l1), (0, -0.12, -0.92 * l1), 0.16, 16)
|
||||||
fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, -0.52, -k * l1) for k in (0.95, 0.8, 0.65)], 0.11, RECORDS["hip_pitch_front"][0])
|
g.cylinder(kn @ RY(90), 0.34, 1.5, 24)
|
||||||
made += objs
|
geo(f"Thigh.girder.{tag}", CORE, th, thigh, bevel=0.015)
|
||||||
return made
|
|
||||||
|
def bearings(g):
|
||||||
|
stack(g, out)
|
||||||
|
g.cylinder(RY(90), 0.98, 1.3, 48)
|
||||||
|
g.lathe(inb, [(0, 0.6), (1.05, 0.6), (1.05, 0.72), (0.6, 0.72), (0.6, 0.8), (0, 0.8)], 40)
|
||||||
|
for at in (kn @ out, kn @ inb):
|
||||||
|
disc(g, at @ T((0, 0, 0.62)), 0.62, 0.24, rings=3, bolts=12)
|
||||||
|
geo(f"Thigh.drums.{tag}", "machine", th, bearings)
|
||||||
|
|
||||||
|
behind = lambda n, c: n.y < -0.5 # noqa: E731
|
||||||
|
made = [hard(f"Thigh.shroud.{tag}", housing_pts([(-0.75, 1.5, -1.08, -0.25, 0.2), (-1.35, 1.62, -1.12, -0.2, 0.22), (-0.42 * l1, 1.5, -0.98, -0.2, 0.2), (-0.42 * l1 - 0.3, 1.2, -0.8, -0.2, 0.16)]), th, P2, clad=behind, seed=21)]
|
||||||
|
zt, zb = -0.4 * l1, -l1 - 0.35
|
||||||
|
outline = [(-0.5, zt), (0.5, zt), (0.8, zt - 0.4), (0.8, zb + 0.35), (0.55, zb), (-0.55, zb), (-0.8, zb + 0.35), (-0.8, zt - 0.4)]
|
||||||
|
made.append(hard(f"Thigh.guard.{tag}", [(x, -0.86, z) for x, z in outline] + [(1.06 * x, -0.56, z + 0.04 * (1 if z > 0.5 * (zt + zb) else -1)) for x, z in outline], th, P, clad=behind, seed=22))
|
||||||
|
geo(f"Thigh.struts.{tag}", CORE, th, lambda g: [g.box(T((s * 0.52, -0.46, z * l1)), (0.2, 0.3, 0.3)) for s in (-1, 1) for z in (-0.5, -0.72, -0.94)])
|
||||||
|
|
||||||
|
geo(f"Shin.column.{tag}", CORE, sh, lambda g: (g.box(T((0, 0, -0.5 * l2)), (0.9, 0.7, l2)), g.cylinder(T((0, 0, -l2)) @ RY(90), 0.4, 1.3, 24), g.box(T((0, 0.3, -0.45 * l2)), (0.6, 0.4, 0.7 * l2))), bevel=0.015)
|
||||||
|
made.append(hard(f"Shin.guard.{tag}", housing_pts([(-0.1, 1.3, -0.62, -0.15, 0.14), (-l2 + 0.05, 1.5, -0.7, -0.15, 0.16)]), sh, P2, clad=behind, seed=23))
|
||||||
|
|
||||||
|
# the propulsion rams: from the hull's mount ahead of and under the hip to the hock, a pair either side of the beams' middle
|
||||||
|
M.update()
|
||||||
|
to_hip = hipb.matrix_world.inverted() @ th.matrix_world
|
||||||
|
a = [to_hip @ Vector((0, y, z)) for y in (0.85, 1.1, 1.35) for z in (0.25, -0.05, -0.35)]
|
||||||
|
fit, objs = Q.drive(f"Leg.ram.{tag}", hipb, th, a, [(0, 0.44, -k * l1) for k in (0.93, 0.85, 0.77)], 0.18, RECORDS["hip_pitch_rear"][0], twin=0.3)
|
||||||
|
if fit is not None:
|
||||||
|
from brokkr_kitbash import ram as R
|
||||||
|
base = Vector(R.pose(fit.m, [0.0]).base[0])
|
||||||
|
axis = (to_hip.to_3x3() @ Vector((1, 0, 0))).normalized()
|
||||||
|
toward = (-base).normalized()
|
||||||
|
pts = [base + axis * s * 0.62 + d for s in (-1, 1) for d in (toward * -0.3, toward.cross(axis) * 0.3, toward.cross(axis) * -0.3)] + [axis * s * 0.6 + toward.cross(axis) * k for s in (-1, 1) for k in (-0.5, 0.5)]
|
||||||
|
objs.append(MS.hard(f"Leg.ram.mount.{tag}", pts, hipb, CORE, bevel=0.03))
|
||||||
|
return made + objs
|
||||||
|
|
||||||
|
|
||||||
def foot(tag, bones, pose):
|
def foot(tag, bones, pose):
|
||||||
|
|
@ -354,7 +420,6 @@ def foot(tag, bones, pose):
|
||||||
f.done()
|
f.done()
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
# --- turret -------------------------------------------------------------------------------------------------------------
|
# --- turret -------------------------------------------------------------------------------------------------------------
|
||||||
def turret_ring(host):
|
def turret_ring(host):
|
||||||
"""The reinforced circular bearing on the crown (the plan view's ring): a bolted outer race on the deck."""
|
"""The reinforced circular bearing on the crown (the plan view's ring): a bolted outer race on the deck."""
|
||||||
|
|
@ -407,117 +472,133 @@ def gun(gb):
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def detail():
|
# --- detail ----------------------------------------------------------------------------------------------------------------
|
||||||
"""The detail pass by surface.py on the plates (its Skin reads a massing plate's own face): the 03 on each cheek
|
def ray_down(xy, keep=lambda name: name.startswith("Hull.")):
|
||||||
band, the wings on the chin, panel lines, bolt rows inside the rims, hatches on the upper plates. A feature that
|
"""Where a ray straight down meets the hull's plates at a plan point: (point, normal, object) in the world."""
|
||||||
misses its plate is reported, not drawn. Returns (made, failed)."""
|
dg = bpy.context.evaluated_depsgraph_get()
|
||||||
|
origin = Vector((xy[0], xy[1], 30.0))
|
||||||
|
for _ in range(8):
|
||||||
|
ok, loc, nor, _, obj, _ = bpy.context.scene.ray_cast(dg, origin, Vector((0, 0, -1)))
|
||||||
|
if not ok:
|
||||||
|
return None
|
||||||
|
if keep(obj.name):
|
||||||
|
return loc, nor, obj
|
||||||
|
origin = loc - Vector((0, 0, 0.002))
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def detail(plates, host):
|
||||||
|
"""The detail pass on the hard plates (massing.Face stands in for surface.py's Skin): the 03 on each skirt and the
|
||||||
|
wings on the chin, each on a raised panel of its own; bolt rows round the collar and along the brow; grab
|
||||||
|
handles and lifting eyes on the pods. Returns (made, failed)."""
|
||||||
import surface as S
|
import surface as S
|
||||||
S.materials()
|
S.materials()
|
||||||
made, failed = [0], []
|
made, failed = 0, []
|
||||||
|
for sx, tag in ((1, "R"), (-1, "L")):
|
||||||
def on(plate, steps):
|
sk = plates[f"Hull.Skirt.{tag}"]
|
||||||
if plate not in bpy.data.objects:
|
n = Vector((sx * BF.NUMERAL["normal"][0], BF.NUMERAL["normal"][1], BF.NUMERAL["normal"][2]))
|
||||||
failed.append(f"{plate}: no such plate")
|
g = M.Geo()
|
||||||
return
|
MS.panel(g, [(sx * x, y, z) for x, y, z in BF.SKIRT["points"][:6]], lift=0.06, inset=0.13, out=n)
|
||||||
try:
|
o = g.to_object(f"Hull.Skirt.{tag}.panels", P, host, 1.0)
|
||||||
skin = S.Skin(plate)
|
face = MS.Face(o, P)
|
||||||
except BaseException as error:
|
at = Vector((sx * BF.NUMERAL["at"][0], BF.NUMERAL["at"][1], BF.NUMERAL["at"][2])) + n * 0.068
|
||||||
failed.append(f"{plate}: {type(error).__name__} {error}")
|
S.numeral(face, F(at, n), BF.NUMERAL["text"], BF.NUMERAL["height"], "marking_fresh")
|
||||||
return
|
face.done()
|
||||||
for label, step in steps:
|
made += 2
|
||||||
try:
|
chin = plates["Hull.Chin"]
|
||||||
step(skin)
|
n = Vector(BF.EMBLEM["normal"]).normalized()
|
||||||
made[0] += 1
|
c = BF.CHIN["points"]
|
||||||
except BaseException as error:
|
g = M.Geo()
|
||||||
failed.append(f"{plate} {label}: {type(error).__name__} {error}")
|
MS.panel(g, [c[1], (-c[1][0], c[1][1], c[1][2]), (-c[5][0], c[5][1], c[5][2]), c[5]], lift=0.06, inset=0.1, out=n)
|
||||||
try:
|
o = g.to_object("Hull.Chin.panels", P2, host, 1.0)
|
||||||
skin.prune()
|
face = MS.Face(o, P2)
|
||||||
skin.commit()
|
S.emblem(face, F(Vector(BF.EMBLEM["at"]) + n * 0.068, n), "wings", BF.EMBLEM["height"], "marking_fresh")
|
||||||
except BaseException as error:
|
face.done()
|
||||||
failed.append(f"{plate} commit: {type(error).__name__} {error}")
|
made += 2
|
||||||
|
M.update()
|
||||||
def rim(k, spacing=0.4):
|
fit = MS.Face(plates["Hull.Collar"], "gunmetal")
|
||||||
return (f"bolts on rim {k}", lambda s: S.bolt_row(s, S.along(s, ("rim", k), spacing=spacing, offset=0.12, margin=0.2), r=0.03))
|
for k in range(8):
|
||||||
for sx, tag in ((-1, "L"), (1, "R")):
|
a = math.radians(45.0 * k)
|
||||||
side = ((sx * 9.0, 3.2, 5.9), (-sx, 0, 0))
|
for off in (-0.8, 0.0, 0.8):
|
||||||
on(f"Hull.CheekBand.{tag}", [("03", lambda s: S.numeral(s, s.at(*side), "03", 0.75, "marking_fresh")), rim(0),
|
hit = ray_down((3.2 * math.sin(a) + off * math.cos(a), 3.2 * math.cos(a) - off * math.sin(a)), keep=lambda name: name == "Hull.Collar")
|
||||||
("hatch", lambda s: S.hatch(s, s.at((sx * 9.0, 2.0, 5.75), (-sx, 0, 0)), size=(0.6, 0.5)))])
|
if hit:
|
||||||
on(f"Hull.CheekUp.{tag}", [rim(0), ("hatch", lambda s: S.hatch(s, s.at((sx * 3.0, 3.2, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.8, 0.6))),
|
S.bolt_row(fit, [F(hit[0], hit[1])], r=0.04, mat="gunmetal")
|
||||||
("port", lambda s: S.access_port(s, s.at((sx * 3.4, 2.2, 12.0), (0, 0, -1), up=(0, 1, 0)), r=0.16))])
|
made += 1
|
||||||
on(f"Hull.RearUp.{tag}", [rim(0), ("louvres", lambda s: S.louvre_bank(s, s.at((sx * 2.6, -3.4, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.9, 0.6), slats=6))])
|
for sx in (-1, 1):
|
||||||
on(f"Hull.RearBand.{tag}", [rim(0), ("port", lambda s: S.access_port(s, s.at((sx * 9.0, -3.2, 6.3), (-sx, 0, 0)), r=0.18))])
|
for xy, length, turn in (((sx * 3.9, -2.9), 0.7, 20.0 * sx), ((sx * 3.3, -3.9), 0.6, 60.0 * sx), ((sx * 3.9, 2.6), 0.7, -10.0 * sx), ((sx * 1.1, 4.6), 0.6, 90.0)):
|
||||||
on(f"Hull.FlankUp.{tag}", [rim(0)])
|
hit = ray_down(xy)
|
||||||
on("Hull.Chin", [("wings", lambda s: S.emblem(s, s.at((0, 9.0, 4.45), (0, -1, 0)), "wings", 0.6, "marking_fresh")), rim(0)])
|
if hit:
|
||||||
on("Hull.Glacis", [rim(0), ("hatch", lambda s: S.hatch(s, s.at((0.9, 4.4, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.7, 0.6))),
|
S.grab_handle(fit, F(hit[0], hit[1], (0, 1, 0)) @ RZ(turn), length=length, lift=0.11, r=0.025)
|
||||||
("panel", lambda s: S.inset(s, s.at((-0.8, 4.6, 12.0), (0, 0, -1), up=(0, 1, 0)), size=(0.8, 0.5)))])
|
made += 1
|
||||||
on("Hull.Crown", [rim(0, 0.5)])
|
else:
|
||||||
print(f"DETAIL {made[0]} features made; {len(failed)} failed", flush=True)
|
failed.append(f"handle at {xy}: no plate under it")
|
||||||
|
for xy in ((sx * 4.2, 1.4), (sx * 2.9, 4.4), (sx * 4.3, -1.9)):
|
||||||
|
hit = ray_down(xy)
|
||||||
|
if hit:
|
||||||
|
S.lifting_eye(fit, F(hit[0], hit[1], (0, 1, 0)), size=0.16)
|
||||||
|
made += 1
|
||||||
|
fit.done()
|
||||||
|
print(f"DETAIL {made} features made; {len(failed)} failed", flush=True)
|
||||||
for f in failed:
|
for f in failed:
|
||||||
print(" DETAIL failed:", f, flush=True)
|
print(" DETAIL failed:", f, flush=True)
|
||||||
return made[0], failed
|
return made, failed
|
||||||
|
|
||||||
|
|
||||||
# --- the build ------------------------------------------------------------------------------------------------------------
|
# --- the build ------------------------------------------------------------------------------------------------------------
|
||||||
def run(mass, at, stand):
|
def body(trunk, at):
|
||||||
|
"""The hull: its mass (bastion_body.hull), the magazines' wells cut from the core, and from the full stage its
|
||||||
|
detail plating."""
|
||||||
|
plates, dark = BB.hull(trunk)
|
||||||
|
M.update()
|
||||||
|
cuts = [MS.slab(f"Magazine.cut.{'L' if sx < 0 else 'R'}", (sx * (BF.MAG["face"] - 0.5 * BF.MAG["depth"] + 0.3), 0.5 * (BF.MAG["y0"] + BF.MAG["y1"]), 0.5 * (BF.MAG["z0"] + BF.MAG["z1"])),
|
||||||
|
(BF.MAG["depth"] + 0.6, BF.MAG["y1"] - BF.MAG["y0"] + 0.2, BF.MAG["z1"] - BF.MAG["z0"] + 0.2), BB.I4) for sx in (-1, 1)]
|
||||||
|
MS.carve(dark["Core.upper"], cuts)
|
||||||
|
HARD.update(BB.report(plates))
|
||||||
|
if at >= 2:
|
||||||
|
made = BB.plating(plates, trunk)
|
||||||
|
print("PLATING", sum(made.values()), "panels on", len(made), "plates", flush=True)
|
||||||
|
return plates, dark
|
||||||
|
|
||||||
|
|
||||||
|
def run(at, stand):
|
||||||
pose = {k: list(v) for k, v in stand.items()}
|
pose = {k: list(v) for k, v in stand.items()}
|
||||||
ring = BF.RING
|
ring = BF.RING
|
||||||
trunnion = (0.0, 1.75, ring[2] + 0.68)
|
trunnion = (0.0, 1.75, ring[2] + 0.68)
|
||||||
bones = part("skeleton", Q.build, pose, RECORDS, pin=2 * FOOT_PIN, turret={"ring": list(ring), "trunnion": list(trunnion), "yaw": 0.0, "pitch": 2.0})
|
bones = part("skeleton", Q.build, pose, RECORDS, pin=2 * FOOT_PIN, turret={"ring": list(ring), "trunnion": list(trunnion), "yaw": 0.0, "pitch": 2.0})
|
||||||
trunk = bones["Trunk"]
|
trunk = bones["Trunk"]
|
||||||
print("SKELETON miss", round(Q.miss(bones, pose), 4), "m", flush=True)
|
print("SKELETON miss", round(Q.miss(bones, pose), 4), "m", flush=True)
|
||||||
mass.parent = trunk
|
plates, dark = part("hull", body, trunk, at)
|
||||||
for t in Q.LEGS:
|
if at >= 1:
|
||||||
part(f"hip {t}", hip_housing, t, trunk, pose[f"hip_{t}"], t[0] == "r")
|
for t in Q.LEGS:
|
||||||
part(f"leg {t}", leg_dress, t, bones, pose)
|
part(f"hip {t}", hip_housing, t, trunk, pose[f"hip_{t}"], t[0] == "r")
|
||||||
part(f"foot {t}", foot, t, bones, pose)
|
part(f"leg {t}", leg_rear if t[0] == "r" else leg_front, t, bones, pose)
|
||||||
part("turret ring", turret_ring, trunk)
|
part(f"foot {t}", foot, t, bones, pose)
|
||||||
part("turret", turret, bones["Aim.Turret"])
|
|
||||||
part("gun", gun, bones["Aim.Gun"])
|
|
||||||
part("cooling", cooling, trunk)
|
|
||||||
if at >= 2:
|
if at >= 2:
|
||||||
skin = mass.copy()
|
|
||||||
skin.data = mass.data.copy()
|
|
||||||
bpy.context.scene.collection.objects.link(skin)
|
|
||||||
skin.hide_render = True
|
|
||||||
M.update()
|
|
||||||
cuts = wells()
|
|
||||||
MS.carve(mass, cuts)
|
|
||||||
part("cockpit", cockpit, trunk)
|
part("cockpit", cockpit, trunk)
|
||||||
for sx in (-1, 1):
|
for sx in (-1, 1):
|
||||||
|
part(f"cheek lamp {sx}", cheek_lamp, trunk, sx)
|
||||||
part(f"magazine {sx}", magazine, trunk, sx)
|
part(f"magazine {sx}", magazine, trunk, sx)
|
||||||
if at >= 3:
|
part("turret ring", turret_ring, trunk)
|
||||||
M.assign(mass, CORE)
|
part("turret", turret, bones["Aim.Turret"])
|
||||||
before = set(bpy.data.objects.keys())
|
part("gun", gun, bones["Aim.Gun"])
|
||||||
t = time.time()
|
part("cooling", cooling, trunk)
|
||||||
made = plates(skin, cuts)
|
k = 0
|
||||||
for o in made:
|
for sx in (-1, 1):
|
||||||
o.parent = trunk
|
for x, y in BF.INTERCEPTORS:
|
||||||
if at >= 4:
|
hit = ray_down((sx * x, y))
|
||||||
detail()
|
if hit:
|
||||||
M.update()
|
part(f"interceptor {k}", interceptor, f"Interceptor.{k}", trunk, T(hit[0] - Vector((0, 0, 0.1))), -math.degrees(math.atan2(sx * x, y)))
|
||||||
TIMES["plates"] = round(time.time() - t, 1)
|
k += 1
|
||||||
print(f"PART plates: {TIMES['plates']} s, {frozen(before)} frozen", flush=True)
|
part("detail", detail, plates, trunk)
|
||||||
n = 8
|
report = Q.report(trunk, more=[bones[f"Ankle.{t}"] for t in Q.LEGS])
|
||||||
for k in range(n):
|
rows = report["joints"]
|
||||||
a = math.radians(22.5 + 360.0 * k / n)
|
print("JOINTS", report["schema"], len(rows), "rows;", json.dumps({m: sum(1 for r in rows if r["mechanism"] == m) for m in sorted({str(r["mechanism"]) for r in rows})}), flush=True)
|
||||||
d = Vector((math.sin(a), math.cos(a), 0))
|
out = os.environ.get("MECH_OUT")
|
||||||
hit = ray_down(skin, d * 1.0 + Vector((d.x * 2.9, d.y * 3.6, 0)))
|
if out:
|
||||||
if hit:
|
with open(os.path.join(out, "bastion", "bastion_joints.json"), "w", encoding="utf-8") as fh:
|
||||||
part(f"interceptor {k}", interceptor, f"Interceptor.{k}", trunk, T(hit[0] - Vector((0, 0, 0.12))), -math.degrees(a))
|
json.dump(report, fh, indent=1)
|
||||||
if at >= 2:
|
with open(os.path.join(out, "bastion", "bastion_plates.json"), "w", encoding="utf-8") as fh:
|
||||||
bpy.data.objects.remove(skin, do_unlink=True)
|
json.dump({"kinds": BF.KINDS, "plates": HARD}, fh, indent=1)
|
||||||
report = Q.report(trunk, more=[bones[f"Ankle.{t}"] for t in Q.LEGS])
|
print("HARD", len(HARD), "hard plates;", json.dumps({k: v["corners"] for k, v in sorted(HARD.items())}), flush=True)
|
||||||
rows = report["joints"]
|
|
||||||
print("JOINTS", report["schema"], len(rows), "rows;", json.dumps({m: sum(1 for r in rows if r["mechanism"] == m) for m in sorted({str(r["mechanism"]) for r in rows})}), flush=True)
|
|
||||||
out = os.environ.get("MECH_OUT")
|
|
||||||
if out:
|
|
||||||
with open(os.path.join(out, "bastion", "bastion_joints.json"), "w", encoding="utf-8") as fh:
|
|
||||||
json.dump(report, fh, indent=1)
|
|
||||||
print("TIMES", json.dumps(TIMES), flush=True)
|
print("TIMES", json.dumps(TIMES), flush=True)
|
||||||
return bones
|
return bones
|
||||||
|
|
||||||
|
|
||||||
def ray_down(obj, xy):
|
|
||||||
"""Where a ray straight down meets the mass at a plan point: (point, normal) in the world."""
|
|
||||||
ok, loc, nor, _ = obj.ray_cast(obj.matrix_world.inverted() @ Vector((xy.x, xy.y, 20.0)), Vector((0, 0, -1)))
|
|
||||||
return (obj.matrix_world @ loc, (obj.matrix_world.to_3x3() @ nor).normalized()) if ok else None
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
41
surfaces/blender/experiments/mechs/bastion_cams.py
Normal file
41
surfaces/blender/experiments/mechs/bastion_cams.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
"""python bastion_cams.py [--write]: BASTION's cameras from concepts.json's marks (quadruped.cameras): the elevations
|
||||||
|
and the plan by quadruped.elevation_camera, the hero by camsolve on every mark the hero and the elevations share
|
||||||
|
(hull marks: nose, emblem, lamp slots, the 03, the magazine, the cooling housing's corner, the muzzle; leg marks: hips,
|
||||||
|
a knee, ankles). --write keeps them, with the standing skeleton and the views' spread, as bastion_cameras.json.
|
||||||
|
HULL names the marks that are rigid with the hull: the hero is also solved on those alone and each leg mark's miss
|
||||||
|
at that camera printed, which is how far the hero poses its legs from the elevations' stance. Plain Python."""
|
||||||
|
import json, sys
|
||||||
|
from pathlib import Path
|
||||||
|
import numpy as np
|
||||||
|
HERE = Path(__file__).resolve().parent
|
||||||
|
sys.path.insert(0, str(HERE))
|
||||||
|
import camsolve, quadruped as Q
|
||||||
|
|
||||||
|
# The solver's own choice here is "free" (16.0 px against upright's 20.9): it puts the lens's centre 1700 px under the frame,
|
||||||
|
# which no camera at a standing man's eye has, and from there the deck's top shows. The hero is kept upright: level, the
|
||||||
|
# centre in the frame, the horizon on the soldiers' heads.
|
||||||
|
MODEL = "upright"
|
||||||
|
HULL = ("nose", "emblem", "lamp_l", "lamp_r", "num_l", "mag_l", "cool_l", "muzzle", "disc_fl", "hip_fr", "disc_rl")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
world, spread = Q.stand("bastion"), Q.spread("bastion")
|
||||||
|
cams = Q.cameras("bastion", world, models={"hero": MODEL})
|
||||||
|
auto = Q.cameras("bastion", world)["hero"]
|
||||||
|
print(f"hero by camsolve's auto: model {auto['model']}, rms {auto['rms']:.1f} px, centre ({auto['c'][0]:.0f}, {auto['c'][1]:.0f}), lens {auto['lens']:.0f} mm, {auto['distance']:.0f} m off: not kept (MODEL)")
|
||||||
|
s = Q.spec("bastion")
|
||||||
|
view = s["views"]["hero"]
|
||||||
|
hero = cams["hero"]
|
||||||
|
print("\n".join(camsolve.report("hero, all marks", hero)))
|
||||||
|
for k, (du, dv) in hero["residuals"].items():
|
||||||
|
print(f" {k:10s} {du:+6.1f} {dv:+6.1f} {np.hypot(du, dv):5.1f}")
|
||||||
|
marks = {m: p for m, p in view["joints"].items() if m in world and m in HULL}
|
||||||
|
hull = camsolve.solve(world, marks, view["box"], model="upright", unit=s["unit"], height_px=view["ground"] - view["top"], horizon=view.get("horizon"))
|
||||||
|
print("\n".join(camsolve.report("hero, hull marks alone", hull)))
|
||||||
|
legs = {m: p for m, p in view["joints"].items() if m in world and m not in HULL}
|
||||||
|
miss = {m: [float(v) for v in camsolve.project(hull, [world[m]])[0] - np.array(p)] for m, p in legs.items()}
|
||||||
|
for k, (du, dv) in {**hull["residuals"], **miss}.items():
|
||||||
|
print(f" {k:10s} {du:+6.1f} {dv:+6.1f} {np.hypot(du, dv):5.1f}" + (" (a leg mark, not solved on)" if k in miss else ""))
|
||||||
|
hero["hull_only"] = {"rms": hull["rms"], "names": hull["names"], "lens": hull["lens"], "C": hull["C"], "leg_miss_px": miss}
|
||||||
|
if "--write" in sys.argv:
|
||||||
|
(HERE / "bastion_cameras.json").write_text(json.dumps({"cameras": cams, "stand": world, "spread": spread}, indent=1), encoding="utf-8")
|
||||||
|
print("written")
|
||||||
|
|
@ -1,63 +1,126 @@
|
||||||
"""BASTION's numbers (sheet 36): the hull's cage, the wells, the plates' cuts, the kept cameras. Plain Python.
|
"""BASTION's numbers (sheet 36), second pass: the hull as hard plates, each authored by its faces. Plain Python.
|
||||||
|
|
||||||
The hull is one closed free cage, authored on the mech's right (x >= 0) and mirrored: five rings of seven points
|
The first pass built the carapace as one soft cage and it read as a smooth dome. The concept draws an angular,
|
||||||
from the nose (on the seam) round the flank to the tail (on the seam), closed over the deck and under the belly by a
|
layered hull: every plate has a faceted silhouette, so every plate here is HARD (KINDS; mech-lessons-2026-12-03) and
|
||||||
centre line each. The points are where the SURFACE passes: massing.cage_through moves the cage until its subdivided
|
is written as the flat faces that bound it (massing.corners finds its corners), not as a cage to be subdivided.
|
||||||
surface goes through them. World metres: x right, y forward, z up, the origin on the ground under the turret ring.
|
Nothing on this hull is soft: the round forms are turned machinery (the turret ring, the hip bearings).
|
||||||
|
|
||||||
A the rim: the carapace's overhanging edge, the plan view's outline
|
World metres: x right, y forward, z up, the origin on the ground under the turret ring. Plates are authored on the
|
||||||
B the shoulder: where the flank band breaks into the dome
|
mech's right (x >= 0) and mirrored. The numbers are read off the elevations and the plan at their cameras
|
||||||
C the deck's rim round the turret ring
|
(bastion_cameras.json: 1.1 to 1.4 px rms, 0.057 to 0.072 m a pixel), by hand, to about 2 px (0.12 m); depth where one
|
||||||
D under the overhang, where the belly's box meets the carapace
|
view alone shows a face is my own choice of plane, not a fit.
|
||||||
E the belly's lower edge
|
|
||||||
"""
|
A face is ("at", point, normal) or ("by", a, b, c, out): three points and the side that is outside. A plate is
|
||||||
|
{"faces": [...]} or {"points": [...]} (corners given outright), "mirror" for one solid across the centre line,
|
||||||
|
"mat", "bevel" and "clad": whether the detail plating pass panels its facets."""
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
HERE = Path(__file__).resolve().parent
|
HERE = Path(__file__).resolve().parent
|
||||||
N = 7
|
|
||||||
RINGS = {
|
|
||||||
"A": [(0.0, 6.25, 5.55), (2.3, 5.95, 5.35), (4.4, 4.9, 5.1), (5.05, 2.6, 5.05), (5.05, -2.6, 5.5), (3.9, -4.9, 5.9), (0.0, -5.85, 5.95)],
|
|
||||||
"B": [(0.0, 5.35, 6.3), (1.9, 5.05, 6.35), (3.6, 4.0, 6.5), (4.1, 2.2, 6.8), (4.1, -2.4, 6.95), (3.1, -4.2, 7.0), (0.0, -5.0, 7.0)],
|
|
||||||
"C": [(0.0, 2.9, 7.55), (1.3, 2.7, 7.6), (2.35, 1.8, 7.7), (2.6, 0.6, 7.75), (2.6, -1.6, 7.75), (1.9, -2.9, 7.7), (0.0, -3.3, 7.65)],
|
|
||||||
"D": [(0.0, 5.70, 4.95), (1.7, 5.50, 4.9), (2.45, 4.6, 4.75), (2.45, 2.4, 4.7), (2.45, -2.6, 5.0), (2.0, -4.8, 5.3), (0.0, -5.6, 5.4)],
|
|
||||||
"E": [(0.0, 5.45, 3.9), (1.5, 5.25, 3.8), (2.15, 4.3, 3.3), (2.2, 2.2, 3.05), (2.2, -2.6, 3.2), (1.8, -4.6, 3.9), (0.0, -5.3, 4.2)],
|
|
||||||
}
|
|
||||||
DECK = [(0.0, 2.0, 7.82), (0.0, 1.2, 7.85), (0.0, 0.0, 7.86), (0.0, -1.3, 7.85), (0.0, -2.4, 7.8)] # the deck's centre line, under the turret ring
|
|
||||||
BELLY = [(0.0, 4.4, 3.5), (0.0, 3.0, 3.05), (0.0, 0.0, 3.0), (0.0, -2.6, 3.1), (0.0, -4.3, 3.8)]
|
|
||||||
# creases: (ring, from point, to point, weight) along a ring; (ring, ring, point, weight) a column between two rings
|
|
||||||
RING_CREASES = [("A", 0, 6, 1.0), ("B", 1, 6, 0.85), ("E", 1, 5, 0.6)]
|
|
||||||
COLUMN_CREASES = [("A", "B", 2, 0.6), ("A", "B", 5, 0.6), ("A", "D", 2, 0.5), ("B", "C", 2, 0.6), ("B", "C", 5, 0.6), ("B", "C", 3, 0.4), ("B", "C", 4, 0.4)]
|
|
||||||
RING = (0.0, 0.0, 7.86) # the turret ring's centre on the deck
|
RING = (0.0, 0.0, 7.86) # the turret ring's centre on the deck
|
||||||
RING_R = 1.95
|
RING_R = 1.95
|
||||||
|
P, P2, CORE = "olive", "olive_light", "gunmetal"
|
||||||
|
|
||||||
|
|
||||||
def hull_sheet(rings=None):
|
def at(point, normal):
|
||||||
"""The hull's cage as a free-cage sheet (brokkr_kitbash.shell's form): verts, faces, creases, mirror. Faces are
|
return ("at", tuple(point), tuple(normal))
|
||||||
wound by massing.cage_sheet, which also declares the poles."""
|
|
||||||
R = rings or RINGS
|
|
||||||
order = ["C", "B", "A", "D", "E"]
|
def by(a, b, c, out):
|
||||||
index = {(r, j): k * N + j for k, r in enumerate(order) for j in range(N)}
|
return ("by", tuple(a), tuple(b), tuple(c), tuple(out))
|
||||||
verts = [list(p) for r in order for p in R[r]]
|
|
||||||
deck0 = len(verts)
|
|
||||||
verts += [list(p) for p in DECK]
|
def _unit(v):
|
||||||
belly0 = len(verts)
|
k = math.sqrt(sum(c * c for c in v))
|
||||||
verts += [list(p) for p in BELLY]
|
return tuple(c / k for c in v)
|
||||||
faces = []
|
|
||||||
for a, b in zip(order, order[1:]):
|
|
||||||
for j in range(N - 1):
|
LEAN = 0.38 # how far a pod's flank leans in a metre of height (the front view: 5.04 m out at the rim, 4.1 at the shoulder)
|
||||||
faces.append([index[a, j], index[a, j + 1], index[b, j + 1], index[b, j]])
|
|
||||||
for ring, c0 in (("C", deck0), ("E", belly0)):
|
|
||||||
faces.append([index[ring, 0], index[ring, 1], c0])
|
def _side_x(y, z, d):
|
||||||
for j in range(1, N - 2):
|
"""x on a face x + 0.07 y + LEAN z = d."""
|
||||||
faces.append([index[ring, j], index[ring, j + 1], c0 + j, c0 + j - 1])
|
return d - 0.07 * y - LEAN * z
|
||||||
faces.append([index[ring, N - 2], index[ring, N - 1], c0 + N - 3])
|
|
||||||
creases = []
|
|
||||||
for ring, a, b, w in RING_CREASES:
|
# --- the cheek pod: the front quarter of the carapace, over a front leg ----------------------------------------------------
|
||||||
creases += [[index[ring, j], index[ring, j + 1], w] for j in range(a, b)]
|
A1, B1, A2 = (2.4, 5.5, 5.25), (4.72, 4.0, 5.25), (2.38, 5.2, 6.2)
|
||||||
for ra, rb, j, w in COLUMN_CREASES:
|
C_FRONT = by(A1, B1, A2, (0.5, 1.0, 0.2))
|
||||||
creases.append([index[ra, j], index[rb, j], w])
|
C_SIDE_N = (1.0, 0.07, LEAN)
|
||||||
return {"verts": verts, "faces": faces, "creases": creases, "mirror": True}
|
C_SIDE_AT = (5.03, 0.9, 4.8)
|
||||||
|
C_SIDE_D = 5.03 + 0.07 * 0.9 + LEAN * 4.8
|
||||||
|
_U = _unit((0.72, 0.69, 0.0))
|
||||||
|
_FN = _unit((1.425, 2.204, 0.0)) # the front face's normal, level
|
||||||
|
_SIDE_IN = lambda by_m: tuple(c - n * by_m for c, n in zip(C_SIDE_AT, _unit(C_SIDE_N))) # noqa: E731
|
||||||
|
_FRONT_IN = lambda by_m, z: (A1[0] - _FN[0] * by_m, A1[1] - _FN[1] * by_m, z) # noqa: E731
|
||||||
|
|
||||||
|
CHEEK = {"faces": [C_FRONT, at(_SIDE_IN(0.1), C_SIDE_N), at((4.2, 0.9, 6.95), (0.3, 0.08, 1.0)), at(A2, (0.12, 0.4, 1.0)), at((0, 0, 5.25), (0, 0, -1)),
|
||||||
|
at((0, 0.9, 0), (0, -1, 0)), at((2.38, 0, 0), (-1, 0, 0)), at(tuple(2.85 * c for c in _U), tuple(-c for c in _U))],
|
||||||
|
"mat": P, "bevel": 0.04, "clad": True}
|
||||||
|
CHEEK_TRAY = {"faces": [at(_FRONT_IN(0.28, 5.0), (_FN[0], _FN[1], 0.0)), at(_FRONT_IN(1.3, 5.0), (-_FN[0], -_FN[1], 0.0)), at((0, 0, 4.9), (0, 0, -1)), at((0, 0, 5.3), (0, 0, 1)),
|
||||||
|
at((2.5, 0, 0), (-1, 0, 0)), at(_SIDE_IN(0.3), C_SIDE_N)], "mat": CORE, "bevel": 0.0, "clad": False}
|
||||||
|
CHEEK_LIP = {"faces": [at(_FRONT_IN(0.0, 5.0), (_FN[0], _FN[1], 0.0)), at(_FRONT_IN(0.16, 5.0), (-_FN[0], -_FN[1], 0.0)), at((0, 0, 4.84), (0, 0, -1)), at((0, 0, 4.99), (0, 0, 1)),
|
||||||
|
at((2.45, 0, 0), (-1, 0, 0)), at(_SIDE_IN(0.1), C_SIDE_N)], "mat": P2, "bevel": 0.02, "clad": False}
|
||||||
|
LAMP = {"at": ((A1[0] + B1[0]) / 2 - 0.3 * _FN[0], (A1[1] + B1[1]) / 2 - 0.3 * _FN[1], 5.12), "normal": (_FN[0], _FN[1], 0.0)}
|
||||||
|
# the skirt under the pod's flank: the plate that carries the 03, hanging below the pod, standing 0.1 proud of its side
|
||||||
|
_SKIRT_YZ = [(4.0, 5.3), (3.62, 4.9), (1.35, 4.35), (0.9, 4.8), (0.9, 6.5), (3.8, 6.2)]
|
||||||
|
_sn = _unit(C_SIDE_N)
|
||||||
|
SKIRT = {"points": [(_side_x(y, z, C_SIDE_D), y, z) for y, z in _SKIRT_YZ] + [(_side_x(y, z, C_SIDE_D) - 0.32 * _sn[0], y - 0.32 * _sn[1], z - 0.32 * _sn[2]) for y, z in _SKIRT_YZ],
|
||||||
|
"mat": P, "bevel": 0.035, "clad": False}
|
||||||
|
NUMERAL = {"at": (_side_x(2.15, 5.6, C_SIDE_D), 2.15, 5.6), "normal": _sn, "text": "03", "height": 0.78}
|
||||||
|
|
||||||
|
# --- the rear quarter pod, over a rear hip -----------------------------------------------------------------------------------
|
||||||
|
_V = _unit((0.75, -0.66, 0.0))
|
||||||
|
QUARTER = {"faces": [at((5.0, -1.4, 5.5), (1.0, -0.1, 0.4)), at((4.45, -3.7, 5.7), (0.904, -0.427, 0.4)), at((3.2, -4.9, 5.85), (0.351, -0.936, 0.35)),
|
||||||
|
at((4.2, -2.6, 6.95), (0.28, -0.1, 1.0)), at((0, -1.35, 5.5), (0, -0.12, -1.0)), at((0, -1.4, 0), (0, 1, 0)), at((1.75, 0, 0), (-1, 0, 0)),
|
||||||
|
at(tuple(2.85 * c for c in _V), tuple(-c for c in _V))], "mat": P, "bevel": 0.04, "clad": True}
|
||||||
|
|
||||||
|
# --- the flank between them: the magazine's compartment, its roof and sill ---------------------------------------------------
|
||||||
|
MAG = dict(y0=-1.2, y1=0.75, z0=5.57, z1=6.74, face=4.95, depth=1.25)
|
||||||
|
FLANK_ROOF = {"faces": [at((4.3, 0, 7.05), (0.3, 0, 1.0)), at((4.7, 0, 0), (1, 0, 0.25)), at((0, 0, 6.88), (0, 0, -1)), at((0, 0.85, 0), (0, 1, 0)), at((0, -1.3, 0), (0, -1, 0)),
|
||||||
|
at((2.8, 0, 0), (-1, 0, 0))], "mat": P2, "bevel": 0.03, "clad": True}
|
||||||
|
FLANK_SILL = {"faces": [at((4.98, 0, 0), (1, 0, 0.12)), at((3.9, 0, 0), (-1, 0, 0)), at((0, 0, 5.12), (0, 0, -1)), at((0, 0, 5.45), (0, 0, 1)), at((0, 0.85, 0), (0, 1, 0)),
|
||||||
|
at((0, -1.3, 0), (0, -1, 0))], "mat": P, "bevel": 0.03, "clad": False}
|
||||||
|
|
||||||
|
# --- the head: brow over the visor's recess, chin under it ---------------------------------------------------------------------
|
||||||
|
BROW = {"points": [(0, 6.3, 5.58), (1.05, 6.25, 5.72), (2.0, 5.72, 5.76), (2.28, 4.95, 5.8), (0, 6.14, 6.12), (1.0, 6.1, 6.14), (1.92, 5.6, 6.16), (2.2, 4.95, 6.2),
|
||||||
|
(0, 3.25, 7.0), (2.05, 3.25, 7.0), (0, 3.25, 6.2), (2.28, 3.25, 6.2)], "mirror": True, "mat": P, "bevel": 0.04, "clad": True}
|
||||||
|
VISOR = dict(z0=5.2, z1=5.78, front=5.45, half=1.0, wing=(2.05, 4.85), back=4.2, glass=(5.3, 5.64))
|
||||||
|
SILL = {"faces": [at((4.98, 0, 0), (1, 0, 0.12)), at((3.9, 0, 0), (-1, 0, 0)), at((0, 0, 5.12), (0, 0, -1)), at((0, 0, 5.45), (0, 0, 1)), at((0, 0.85, 0), (0, 1, 0)),
|
||||||
|
at((0, -1.3, 0), (0, -1, 0))], "mat": P, "bevel": 0.03, "clad": False}
|
||||||
|
|
||||||
|
# --- the head: brow over the visor's recess, chin under it ---------------------------------------------------------------------
|
||||||
|
BROW = {"points": [(0, 6.3, 5.58), (1.05, 6.25, 5.72), (2.0, 5.72, 5.76), (2.28, 4.95, 5.8), (0, 6.14, 6.12), (1.0, 6.1, 6.14), (1.92, 5.6, 6.16), (2.2, 4.95, 6.2),
|
||||||
|
(0, 3.25, 7.0), (2.05, 3.25, 7.0), (0, 3.25, 6.2), (2.28, 3.25, 6.2)], "mirror": True, "mat": P, "bevel": 0.04, "clad": True}
|
||||||
|
VISOR = dict(z0=5.2, z1=5.78, front=5.45, half=1.0, wing=(2.05, 4.85), back=4.2, glass=(5.3, 5.64))
|
||||||
|
CHIN = {"points": [(0, 5.78, 5.2), (1.0, 5.78, 5.2), (2.1, 5.15, 5.2), (2.3, 4.3, 5.2), (0, 5.45, 3.95), (0.85, 5.45, 3.95), (1.75, 4.95, 3.98), (1.95, 4.3, 4.0),
|
||||||
|
(2.3, 3.5, 5.2), (1.95, 3.5, 3.95)], "mirror": True, "mat": P, "bevel": 0.04, "clad": True}
|
||||||
|
SILL = {"points": [(0, 5.9, 5.2), (1.05, 5.9, 5.2), (2.2, 5.22, 5.2), (0, 5.84, 5.3), (1.02, 5.84, 5.3), (2.14, 5.18, 5.3), (0, 5.3, 5.2), (2.0, 4.9, 5.2), (0, 5.3, 5.3), (2.0, 4.9, 5.3)],
|
||||||
|
"mirror": True, "mat": P2, "bevel": 0.02, "clad": False}
|
||||||
|
JAW = {"points": [(1.2, 5.3, 3.97), (1.2, 3.7, 3.97), (1.0, 5.12, 3.3), (1.0, 3.85, 3.3)], "mirror": True, "mat": P2, "bevel": 0.03, "clad": False}
|
||||||
|
EMBLEM = {"at": (0.0, 5.45 + (4.72 - 3.95) * 0.33 / 1.25, 4.72), "normal": (0.0, 1.25, -0.33), "height": 0.62}
|
||||||
|
|
||||||
|
# --- the deck: a faceted collar round the turret ring, a plate behind it ---------------------------------------------------------
|
||||||
|
COLLAR = [(2.55, 7.05), (3.78, 7.05), (3.25, 7.6), (2.55, 7.6)] # (radius, z) turned in eight flats, one facing forward
|
||||||
|
TAIL = {"points": [(1.72, -2.75, 7.5), (1.72, -5.0, 7.3), (1.72, -2.75, 7.15), (1.72, -5.0, 7.0)], "mirror": True, "mat": P2, "bevel": 0.03, "clad": True}
|
||||||
|
|
||||||
|
# --- under the plates: the dark core they stand on, and the belly ---------------------------------------------------------------
|
||||||
|
CORE_UP = {"points": [(0, 5.3, 5.3), (2.2, 5.0, 5.3), (4.3, 3.6, 5.3), (4.5, 0.9, 5.2), (4.5, -1.4, 5.4), (4.3, -2.8, 5.6), (3.6, -4.4, 5.8), (2.2, -5.0, 5.9), (0, -5.0, 5.9),
|
||||||
|
(0, 3.4, 6.8), (2.2, 3.4, 6.8), (4.0, 3.0, 6.6), (4.2, 0.9, 6.8), (4.2, -1.4, 6.8), (3.9, -2.8, 6.8), (3.2, -4.2, 6.8), (0, -4.6, 6.9),
|
||||||
|
(2.6, 2.6, 7.3), (2.6, -2.6, 7.3), (0, 3.4, 7.0)], "mirror": True, "mat": CORE, "bevel": 0.0, "clad": False}
|
||||||
|
BELLY = {"points": [(2.3, 4.7, 5.3), (2.3, -4.9, 5.9), (1.7, 4.0, 3.6), (1.8, 2.2, 3.3), (1.8, -2.6, 3.35), (1.5, -4.6, 4.0), (1.2, 4.9, 3.7)], "mirror": True, "mat": CORE, "bevel": 0.03, "clad": False}
|
||||||
|
BELLY_SIDE = {"points": [(2.1, 2.2, 3.9), (2.1, -2.4, 3.95), (2.45, 2.0, 4.1), (2.45, -2.2, 4.15), (2.45, 2.0, 4.85), (2.45, -2.2, 4.9), (2.25, 2.2, 5.1), (2.25, -2.4, 5.15), (1.8, 2.2, 3.9), (1.8, -2.4, 5.15)],
|
||||||
|
"mat": P2, "bevel": 0.03, "clad": True}
|
||||||
|
|
||||||
|
# name, plate, one a side? - the order is the build's. Every plate is hard: the concept draws each with a faceted outline.
|
||||||
|
PLATES = [("Hull.Brow", BROW, False), ("Hull.Chin", CHIN, False), ("Hull.Sill", SILL, False), ("Hull.Jaw", JAW, False), ("Hull.Cheek", CHEEK, True), ("Hull.Skirt", SKIRT, True),
|
||||||
|
("Hull.CheekLip", CHEEK_LIP, True), ("Hull.Quarter", QUARTER, True), ("Hull.FlankRoof", FLANK_ROOF, True), ("Hull.FlankSill", FLANK_SILL, True), ("Hull.Tail", TAIL, False),
|
||||||
|
("Hull.BellySide", BELLY_SIDE, True)]
|
||||||
|
DARK = [("Core.upper", CORE_UP, False), ("Core.belly", BELLY, False), ("Core.cheek_tray", CHEEK_TRAY, True)]
|
||||||
|
KINDS = {name: "hard" for name, _, _ in PLATES}
|
||||||
|
KINDS.update({"Hull.Collar": "hard", "Cooling.hood": "hard", "Thigh.guard": "hard", "Shin.guard": "hard", "Turret.housing": "hard"})
|
||||||
|
INTERCEPTORS = [(3.55, 4.0), (3.5, 1.7), (3.9, -0.3), (3.6, -3.3)] # plan places on the right; mirrored: eight round the perimeter (the prompt)
|
||||||
|
|
||||||
|
|
||||||
def cameras():
|
def cameras():
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ the kept cameras (bastion_cameras.json) and the marks and traced lines of concep
|
||||||
bastion_character.png the character line: the carapace's rim under the dome, the mass alone and the plated build
|
bastion_character.png the character line: the carapace's rim under the dome, the mass alone and the plated build
|
||||||
bastion_plan.png our top view against the concept's, and ours drawn over it
|
bastion_plan.png our top view against the concept's, and ours drawn over it
|
||||||
bastion_components.png each inset beside its built part
|
bastion_components.png each inset beside its built part
|
||||||
|
bastion_vs_pass1.png concept | first pass | this pass, hero, side, rear and front (BASTION_PASS1 names the first
|
||||||
|
pass's render directory; each pass stands at its own solved cameras)
|
||||||
bastion_scores.json the cameras' errors, the flow scores, the silhouettes' overlap"""
|
bastion_scores.json the cameras' errors, the flow scores, the silhouettes' overlap"""
|
||||||
import json, math, os, sys
|
import json, math, os, sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -189,12 +191,12 @@ def character_sheet():
|
||||||
crop = lambda im: im.crop([round(v * k) for v in box]) # noqa: E731
|
crop = lambda im: im.crop([round(v * k) for v in box]) # noqa: E731
|
||||||
c = SHEET.crop(box).resize((round((box[2] - box[0]) * k), round((box[3] - box[1]) * k)), Image.LANCZOS)
|
c = SHEET.crop(box).resize((round((box[2] - box[0]) * k), round((box[3] - box[1]) * k)), Image.LANCZOS)
|
||||||
panels = [label(c, "concept: the rim and the dome")]
|
panels = [label(c, "concept: the rim and the dome")]
|
||||||
for stage, text in (("volume", "the mass alone (one closed free cage, 45 authored vertices)"), ("full", "plated, at the solved hero camera")):
|
for stage, text in (("volume", "the mass alone: hard plates, each authored by its faces, before any detail"), ("full", "detail plating and the rest, at the solved hero camera")):
|
||||||
p = OUT / f"{stage}_hero.png"
|
p = OUT / f"{stage}_hero.png"
|
||||||
if p.exists():
|
if p.exists():
|
||||||
panels.append(label(crop(framed(Image.open(p).resize((1536, 840), Image.LANCZOS))), text))
|
panels.append(label(crop(framed(Image.open(p).resize((1536, 840), Image.LANCZOS))), text))
|
||||||
side = [label(fit(concept("side", 3), 420), "concept, side"), label(fit(framed(ours("side")), 420), "ours, side")]
|
side = [label(fit(concept("side", 3), 420), "concept, side"), label(fit(framed(ours("side")), 420), "ours, side")]
|
||||||
label(stack([row(panels), row(side)]), "BASTION character line: the carapace's overhanging rim under a low dome").save(CMP / "bastion_character.png")
|
label(stack([row(panels), row(side)]), "BASTION character: an angular, layered carapace - faceted pods overhanging round the turret's collar").save(CMP / "bastion_character.png")
|
||||||
|
|
||||||
|
|
||||||
def plan_sheet(scores):
|
def plan_sheet(scores):
|
||||||
|
|
@ -224,11 +226,27 @@ def components_sheet():
|
||||||
continue
|
continue
|
||||||
c = SHEET.crop(box)
|
c = SHEET.crop(box)
|
||||||
cells.append(label(row([fit(c, 400), fit(Image.open(p).convert("RGB"), 400)]), names[key]))
|
cells.append(label(row([fit(c, 400), fit(Image.open(p).convert("RGB"), 400)]), names[key]))
|
||||||
extra = [label(fit(Image.open(OUT / f"close_{k}.png").convert("RGB"), 400), t) for k, t in (("front_leg", "front leg (no inset): guard plates, hip housing"), ("foot", "foot (no inset): feet.bastion_pads")) if (OUT / f"close_{k}.png").exists()]
|
extra = [label(fit(Image.open(OUT / f"close_{k}.png").convert("RGB"), 400), t) for k, t in (("front_leg", "front leg (no inset): armoured housings on the hip's and knee's bearings"), ("foot", "foot (no inset): feet.bastion_pads"),
|
||||||
rows = [row(cells[i:i + 2]) for i in range(0, len(cells), 2)] + ([row(extra)] if extra else [])
|
("hull", "the carapace: hard plates, stepped panels"), ("cooling_flank", "a cooling housing's flank (the hero)")) if (OUT / f"close_{k}.png").exists()]
|
||||||
|
rows = [row(cells[i:i + 2]) for i in range(0, len(cells), 2)] + [row(extra[i:i + 2]) for i in range(0, len(extra), 2)]
|
||||||
label(stack(rows), "BASTION components: the sheet's inset | the built part").save(CMP / "bastion_components.png")
|
label(stack(rows), "BASTION components: the sheet's inset | the built part").save(CMP / "bastion_components.png")
|
||||||
|
|
||||||
|
|
||||||
|
def pass1_sheet():
|
||||||
|
"""Concept | first pass | this pass. The first pass's renders are read where BASTION_PASS1 says they are."""
|
||||||
|
old = Path(os.environ.get("BASTION_PASS1", ""))
|
||||||
|
if not old.is_dir():
|
||||||
|
return
|
||||||
|
rows = []
|
||||||
|
for tag, h in (("hero", 620), ("side", 460), ("rear", 460), ("front", 460)):
|
||||||
|
p = old / f"full_{tag}.png"
|
||||||
|
if not p.exists():
|
||||||
|
continue
|
||||||
|
cells = [label(fit(concept(tag, 2), h), f"{tag}: concept"), label(fit(framed(Image.open(p)), h), "first pass (one soft cage)"), label(fit(framed(ours(tag)), h), "this pass (hard plates)")]
|
||||||
|
rows.append(row(cells))
|
||||||
|
label(stack(rows), "BASTION: concept | first pass | second pass, each pass at its own solved camera").save(CMP / "bastion_vs_pass1.png")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
scores = {"cameras": {}, "flow": {}}
|
scores = {"cameras": {}, "flow": {}}
|
||||||
camera_sheet(scores)
|
camera_sheet(scores)
|
||||||
|
|
@ -237,6 +255,7 @@ if __name__ == "__main__":
|
||||||
character_sheet()
|
character_sheet()
|
||||||
plan_sheet(scores)
|
plan_sheet(scores)
|
||||||
components_sheet()
|
components_sheet()
|
||||||
|
pass1_sheet()
|
||||||
(CMP / "bastion_scores.json").write_text(json.dumps(scores, indent=1), encoding="utf-8")
|
(CMP / "bastion_scores.json").write_text(json.dumps(scores, indent=1), encoding="utf-8")
|
||||||
for p in sorted(CMP.glob("bastion_*.png")):
|
for p in sorted(CMP.glob("bastion_*.png")):
|
||||||
im = Image.open(p)
|
im = Image.open(p)
|
||||||
|
|
|
||||||
|
|
@ -3286,6 +3286,30 @@
|
||||||
"emblem": [
|
"emblem": [
|
||||||
265,
|
265,
|
||||||
660
|
660
|
||||||
|
],
|
||||||
|
"lamp_l": [
|
||||||
|
288,
|
||||||
|
656
|
||||||
|
],
|
||||||
|
"num_l": [
|
||||||
|
327,
|
||||||
|
645.5
|
||||||
|
],
|
||||||
|
"mag_l": [
|
||||||
|
368.5,
|
||||||
|
636
|
||||||
|
],
|
||||||
|
"cool_l": [
|
||||||
|
491,
|
||||||
|
617
|
||||||
|
],
|
||||||
|
"disc_fl": [
|
||||||
|
290,
|
||||||
|
682
|
||||||
|
],
|
||||||
|
"disc_rl": [
|
||||||
|
440,
|
||||||
|
663
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -3343,6 +3367,38 @@
|
||||||
"emblem": [
|
"emblem": [
|
||||||
118,
|
118,
|
||||||
662
|
662
|
||||||
|
],
|
||||||
|
"lamp_l": [
|
||||||
|
179.5,
|
||||||
|
656
|
||||||
|
],
|
||||||
|
"lamp_r": [
|
||||||
|
56,
|
||||||
|
655.5
|
||||||
|
],
|
||||||
|
"num_l": [
|
||||||
|
199,
|
||||||
|
646
|
||||||
|
],
|
||||||
|
"num_r": [
|
||||||
|
37,
|
||||||
|
646
|
||||||
|
],
|
||||||
|
"mag_l": [
|
||||||
|
203,
|
||||||
|
638
|
||||||
|
],
|
||||||
|
"mag_r": [
|
||||||
|
33,
|
||||||
|
638
|
||||||
|
],
|
||||||
|
"disc_fl": [
|
||||||
|
203,
|
||||||
|
682
|
||||||
|
],
|
||||||
|
"disc_fr": [
|
||||||
|
33,
|
||||||
|
682
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -3384,6 +3440,22 @@
|
||||||
"ring": [
|
"ring": [
|
||||||
651,
|
651,
|
||||||
606
|
606
|
||||||
|
],
|
||||||
|
"cool_l": [
|
||||||
|
590,
|
||||||
|
616.5
|
||||||
|
],
|
||||||
|
"cool_r": [
|
||||||
|
717,
|
||||||
|
616.5
|
||||||
|
],
|
||||||
|
"disc_rl": [
|
||||||
|
566,
|
||||||
|
662
|
||||||
|
],
|
||||||
|
"disc_rr": [
|
||||||
|
737,
|
||||||
|
662
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -3438,18 +3510,10 @@
|
||||||
"ground": 525,
|
"ground": 525,
|
||||||
"top": 18,
|
"top": 18,
|
||||||
"joints": {
|
"joints": {
|
||||||
"hip_fl": [
|
|
||||||
533,
|
|
||||||
332
|
|
||||||
],
|
|
||||||
"hip_fr": [
|
"hip_fr": [
|
||||||
222,
|
222,
|
||||||
345
|
345
|
||||||
],
|
],
|
||||||
"hip_rl": [
|
|
||||||
855,
|
|
||||||
283
|
|
||||||
],
|
|
||||||
"knee_rl": [
|
"knee_rl": [
|
||||||
925,
|
925,
|
||||||
455
|
455
|
||||||
|
|
@ -3473,6 +3537,38 @@
|
||||||
"emblem": [
|
"emblem": [
|
||||||
277,
|
277,
|
||||||
270
|
270
|
||||||
|
],
|
||||||
|
"nose": [
|
||||||
|
297,
|
||||||
|
200
|
||||||
|
],
|
||||||
|
"lamp_l": [
|
||||||
|
470,
|
||||||
|
225
|
||||||
|
],
|
||||||
|
"lamp_r": [
|
||||||
|
210,
|
||||||
|
246
|
||||||
|
],
|
||||||
|
"num_l": [
|
||||||
|
588,
|
||||||
|
208
|
||||||
|
],
|
||||||
|
"mag_l": [
|
||||||
|
695,
|
||||||
|
190
|
||||||
|
],
|
||||||
|
"cool_l": [
|
||||||
|
905,
|
||||||
|
137
|
||||||
|
],
|
||||||
|
"disc_fl": [
|
||||||
|
533,
|
||||||
|
332
|
||||||
|
],
|
||||||
|
"disc_rl": [
|
||||||
|
860,
|
||||||
|
288
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"horizon": 437,
|
"horizon": 437,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,20 @@ Tools here (seraph_body uses each more than once):
|
||||||
Curtain(cam, line, frame) a line traced on the concept as a cut: the solved camera's sight lines
|
Curtain(cam, line, frame) a line traced on the concept as a cut: the solved camera's sight lines
|
||||||
along it, so the plate's edge is drawn exactly on the line
|
along it, so the plate's edge is drawn exactly on the line
|
||||||
half(axis, sign, at) a half-space by axis: half("x", -1, 0.3) keeps x >= 0.3
|
half(axis, sign, at) a half-space by axis: half("x", -1, 0.3) keeps x >= 0.3
|
||||||
|
|
||||||
|
Hard plates (a plate whose silhouette the concept draws faceted: mech-lessons-2026-12-03; bastion_body uses each):
|
||||||
|
|
||||||
|
plane(point, normal) / through(a, b, c, out) a face as a half-space (n, d): kept where n.p <= d
|
||||||
|
corners(planes) the corners of the convex solid a set of faces bounds: every three
|
||||||
|
faces' meeting point that lies inside all the others. Authoring a
|
||||||
|
plate by its faces is what keeps every facet flat.
|
||||||
|
hard(name, points, host, ...) a faceted solid on those corners (or any points): flat faces, every
|
||||||
|
edge chamfered by a bevel; obj["plate_kind"] = "hard"
|
||||||
|
panel(geo, polygon, ...) a raised inner panel on a flat polygon: inset, lifted, chamfered
|
||||||
|
clad(obj, geo, ...) detail plating after the main split: every large facet of a hard solid
|
||||||
|
gets its own raised panel, split in two at varied depths
|
||||||
|
Face(obj) a flat facet standing in for a surface.Skin, so surface.py's numerals,
|
||||||
|
emblems, bolt rows and handles land on a hard plate
|
||||||
"""
|
"""
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
|
@ -352,3 +366,159 @@ def plate(name, mass, keep, proud=0.06, wall=0.08, mat="khaki", cutters=(), beve
|
||||||
lo, hi = (min(v.co[k] for v in obj.data.vertices) for k in range(3)), (max(v.co[k] for v in obj.data.vertices) for k in range(3))
|
lo, hi = (min(v.co[k] for v in obj.data.vertices) for k in range(3)), (max(v.co[k] for v in obj.data.vertices) for k in range(3))
|
||||||
print(f"PLATE {name}: {len(obj.data.polygons)} faces, " + " ".join(f"{a:.2f}..{b:.2f}" for a, b in zip(lo, hi)), flush=True)
|
print(f"PLATE {name}: {len(obj.data.polygons)} faces, " + " ".join(f"{a:.2f}..{b:.2f}" for a, b in zip(lo, hi)), flush=True)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
# --- hard plates ---------------------------------------------------------------------------------------------------------
|
||||||
|
def plane(point, normal):
|
||||||
|
"""A face through `point` whose outward normal is `normal`: (n, d), kept where n.p <= d."""
|
||||||
|
n = Vector(normal).normalized()
|
||||||
|
return (n, n.dot(Vector(point)))
|
||||||
|
|
||||||
|
|
||||||
|
def through(a, b, c, out):
|
||||||
|
"""The face through three points, its outward side the one `out` points to."""
|
||||||
|
a, b, c = Vector(a), Vector(b), Vector(c)
|
||||||
|
n = (b - a).cross(c - a).normalized()
|
||||||
|
if n.dot(Vector(out)) < 0:
|
||||||
|
n = -n
|
||||||
|
return (n, n.dot(a))
|
||||||
|
|
||||||
|
|
||||||
|
def moved(face, by):
|
||||||
|
"""A face moved `by` metres along its outward normal (negative: inward)."""
|
||||||
|
return (face[0], face[1] + by)
|
||||||
|
|
||||||
|
|
||||||
|
def corners(planes, tol=1e-6):
|
||||||
|
"""The corners of the convex solid bounded by `planes` [(n, d)]: each three faces' meeting point that is inside
|
||||||
|
every other face. An unbounded or empty set of faces is an error, not a guess."""
|
||||||
|
out = []
|
||||||
|
P = [(Vector(n), float(d)) for n, d in planes]
|
||||||
|
for i in range(len(P)):
|
||||||
|
for j in range(i + 1, len(P)):
|
||||||
|
for k in range(j + 1, len(P)):
|
||||||
|
m = Matrix((P[i][0], P[j][0], P[k][0]))
|
||||||
|
if abs(m.determinant()) < 1e-7:
|
||||||
|
continue
|
||||||
|
p = m.inverted() @ Vector((P[i][1], P[j][1], P[k][1]))
|
||||||
|
if p.length < 1e3 and all(n.dot(p) <= d + tol for n, d in P) and not any((p - q).length < 1e-5 for q in out):
|
||||||
|
out.append(p)
|
||||||
|
if len(out) < 4:
|
||||||
|
raise ValueError(f"massing.corners: {len(planes)} faces bound no solid ({len(out)} corners)")
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def hard(name, points, host=None, mat="olive", mirror=False, bevel=0.03, sx=1):
|
||||||
|
"""A hard plate or block: the faceted convex solid on `points` (massing.corners of its faces, or corners given
|
||||||
|
outright), every facet flat, every edge chamfered `bevel` wide. `sx` -1 builds its mirror across x; `mirror`
|
||||||
|
one solid across the centre line from its right half."""
|
||||||
|
g = M.Geo()
|
||||||
|
g.hull([(sx * Vector(p).x, Vector(p).y, Vector(p).z) for p in points], mirror=mirror)
|
||||||
|
bmesh.ops.dissolve_limit(g.bm, angle_limit=math.radians(0.5), verts=g.bm.verts[:], edges=g.bm.edges[:])
|
||||||
|
obj = g.to_object(name, mat, host, 1.0)
|
||||||
|
if bevel:
|
||||||
|
mod = obj.modifiers.new("Bevel", "BEVEL")
|
||||||
|
mod.width, mod.segments, mod.limit_method, mod.angle_limit = bevel, 1, "ANGLE", math.radians(12)
|
||||||
|
for p in obj.data.polygons:
|
||||||
|
p.use_smooth = False
|
||||||
|
obj["plate_kind"] = "hard"
|
||||||
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
def _clip(poly, point, normal):
|
||||||
|
"""A convex polygon (3D points in one plane) kept on the side of a line the normal points away from."""
|
||||||
|
out = []
|
||||||
|
for i, a in enumerate(poly):
|
||||||
|
b = poly[(i + 1) % len(poly)]
|
||||||
|
da, db = (a - point).dot(normal), (b - point).dot(normal)
|
||||||
|
if da <= 0:
|
||||||
|
out.append(a)
|
||||||
|
if (da < 0) != (db < 0) and abs(da - db) > 1e-9:
|
||||||
|
out.append(a + (b - a) * (da / (da - db)))
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def panel(geo, polygon, lift=0.05, inset=0.1, chamfer=0.02, out=None, sink=0.02, bolts=None, bolt_r=0.028):
|
||||||
|
"""A raised inner panel on a flat convex polygon (3D points, either winding): the polygon moved in `inset` on
|
||||||
|
every edge, standing `lift` proud, its outer rim chamfered. `bolts` is a Geo that takes a hex head inside each
|
||||||
|
of the panel's corners. Returns its frame (z the outward normal), or None for a polygon too small to take one."""
|
||||||
|
P = [Vector(p) for p in polygon]
|
||||||
|
c = sum(P, Vector()) / len(P)
|
||||||
|
n = sum(((P[i] - c).cross(P[(i + 1) % len(P)] - c) for i in range(len(P))), Vector())
|
||||||
|
if n.length < 1e-9:
|
||||||
|
return None
|
||||||
|
n.normalize()
|
||||||
|
if out is not None and n.dot(Vector(out)) < 0:
|
||||||
|
P.reverse()
|
||||||
|
n = -n
|
||||||
|
frame = M.frame_at(c, n)
|
||||||
|
inv = frame.inverted()
|
||||||
|
flat = [(inv @ p).to_2d() for p in P]
|
||||||
|
inner = M._inset(flat, inset)
|
||||||
|
area = lambda q: 0.5 * sum(q[i].x * q[(i + 1) % len(q)].y - q[(i + 1) % len(q)].x * q[i].y for i in range(len(q))) # noqa: E731
|
||||||
|
if area(inner) < 0.25 * area(flat) or area(inner) < 0.02:
|
||||||
|
return None
|
||||||
|
geo.prism(frame @ Matrix.Translation((0, 0, -sink)), inner, lift + sink, chamfer)
|
||||||
|
if bolts is not None:
|
||||||
|
for q in M._inset(inner, 3.2 * bolt_r):
|
||||||
|
bolts.cylinder(frame @ Matrix.Translation((q.x, q.y, lift + 0.3 * bolt_r)), bolt_r, 0.6 * bolt_r, 6)
|
||||||
|
return frame
|
||||||
|
|
||||||
|
|
||||||
|
def facets(obj, min_area=0.6):
|
||||||
|
"""The flat facets of a hard solid's own mesh, in its frame: [(points, normal, area)], largest first."""
|
||||||
|
out = []
|
||||||
|
for p in obj.data.polygons:
|
||||||
|
if p.area >= min_area:
|
||||||
|
out.append(([obj.data.vertices[i].co.copy() for i in p.vertices], p.normal.copy(), p.area))
|
||||||
|
return sorted(out, key=lambda f: -f[2])
|
||||||
|
|
||||||
|
|
||||||
|
def clad(obj, geo, keep=None, min_area=0.9, lifts=(0.045, 0.075), inset=0.11, gap=0.05, split=2.2, seed=0, bolts=None):
|
||||||
|
"""Detail plating on a hard solid, after the main split: each facet of at least `min_area` (and passing
|
||||||
|
`keep(normal, centre)`) takes a raised panel; a facet over `split` square metres is cut in two across its
|
||||||
|
longest side at an uneven share, the two panels at different lifts. Geometry goes into `geo`, in the solid's
|
||||||
|
frame; `bolts` is a Geo for the panels' corner bolts. Returns the number of panels made."""
|
||||||
|
import random
|
||||||
|
rnd = random.Random(seed)
|
||||||
|
made = 0
|
||||||
|
for pts, n, area in facets(obj, min_area):
|
||||||
|
c = sum(pts, Vector()) / len(pts)
|
||||||
|
if keep and not keep(n, c):
|
||||||
|
continue
|
||||||
|
if area > split:
|
||||||
|
k = max(range(len(pts)), key=lambda i: (pts[(i + 1) % len(pts)] - pts[i]).length)
|
||||||
|
a, b = pts[k], pts[(k + 1) % len(pts)]
|
||||||
|
way = (b - a).normalized()
|
||||||
|
at = a + (b - a) * rnd.uniform(0.36, 0.64)
|
||||||
|
parts = [_clip(pts, at - way * gap / 2, way), _clip(pts, at + way * gap / 2, -way)]
|
||||||
|
else:
|
||||||
|
parts = [pts]
|
||||||
|
order = list(lifts) if rnd.random() < 0.5 else list(reversed(lifts))
|
||||||
|
for i, part in enumerate(parts):
|
||||||
|
if len(part) >= 3 and panel(geo, part, lift=order[i % len(order)], inset=inset, out=n, bolts=bolts) is not None:
|
||||||
|
made += 1
|
||||||
|
return made
|
||||||
|
|
||||||
|
|
||||||
|
class Face:
|
||||||
|
"""A hard plate's flat facet standing in for a surface.Skin: surface.py's numeral, emblem, bolt_row, rivet_row,
|
||||||
|
grab_handle and lifting_eye take it. Frames are in the plate object's own frame; done() makes the geometry."""
|
||||||
|
|
||||||
|
def __init__(self, obj, mat="olive"):
|
||||||
|
self.obj, self.name, self.mat = obj, obj.name, mat
|
||||||
|
self.geos, self.decals, self.count = {}, [], 0
|
||||||
|
|
||||||
|
def frame(self, point, normal, up=(0, 0, 1)):
|
||||||
|
return M.frame_at(point, normal, up)
|
||||||
|
|
||||||
|
def sub(self, frame, x, y, roll=0.0, z=0.0):
|
||||||
|
return frame @ Matrix.Translation((x, y, z)) @ Matrix.Rotation(math.radians(roll), 4, "Z")
|
||||||
|
|
||||||
|
def geo(self, mat=None):
|
||||||
|
return self.geos.setdefault(mat or self.mat, M.Geo())
|
||||||
|
|
||||||
|
def done(self, smooth=32.0):
|
||||||
|
made = [g.to_object(f"{self.name}.fit.{mat}", mat, self.obj, smooth) for mat, g in self.geos.items() if len(g.bm.verts)]
|
||||||
|
self.geos = {}
|
||||||
|
return made + self.decals
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,10 @@ The hook, after a mech is built and before it is rendered:
|
||||||
|
|
||||||
import paint; paint.apply("seraph")
|
import paint; paint.apply("seraph")
|
||||||
|
|
||||||
apply(preset, ground=0.0, objects=None, scale=1.0, **overrides) swaps, by material name, every armour paint for
|
apply(preset, ground=0.0, objects=None, scale=1.0, roles=None, glass="smoked", lens="lens", **overrides) swaps, by material name, every armour paint for
|
||||||
the preset's paint, every bare-metal material for its metal, every marking for its worn stencil; it leaves glass,
|
the preset's paint, every bare-metal material for its metal, every marking for its worn stencil, every glass for
|
||||||
rubber, glows and pits alone; called again with another preset it repaints. Returns {old material name: new material}. `ground` is the world height of the
|
a MechGlass (glass="smoked" on panes, lens="lens" on optics under `lens_below` metres across); it leaves rubber,
|
||||||
|
glows and pits alone; called again with another preset it repaints. Returns {old material name: new material}. `ground` is the world height of the
|
||||||
soles (mud and wet are measured from it); `scale` multiplies every noise frequency (a mech half as tall wants 2).
|
soles (mud and wet are measured from it); `scale` multiplies every noise frequency (a mech half as tall wants 2).
|
||||||
An override is any MechPaint input by its lower-case name with underscores, e.g. apply("mcr3", wear=1.4); it
|
An override is any MechPaint input by its lower-case name with underscores, e.g. apply("mcr3", wear=1.4); it
|
||||||
reaches the armour and the markings, not the bare metal (material() tunes one role alone).
|
reaches the armour and the markings, not the bare metal (material() tunes one role alone).
|
||||||
|
|
@ -18,11 +19,35 @@ PRESETS seraph (cleaner, warm drab: 30.webp), mcr3 (grey drab, middli
|
||||||
breaker (dark, heavy wear, mud to the knee: 24.webp), paladin (27.webp), kestrel (29.webp).
|
breaker (dark, heavy wear, mud to the knee: 24.webp), paladin (27.webp), kestrel (29.webp).
|
||||||
material(name, role="armour", preset="seraph", **overrides)
|
material(name, role="armour", preset="seraph", **overrides)
|
||||||
one material of a preset: role is armour, metal, mark or hazard.
|
one material of a preset: role is armour, metal, mark or hazard.
|
||||||
|
glass(name, preset="smoked", **overrides)
|
||||||
|
one MechGlass material. GLASS: smoked (a near-black canopy pane: RAPTOR, 38.webp), amber (a
|
||||||
|
dark amber dome: WYVERN, 35.webp), faceted (smoked, broken into panes by a dark lattice),
|
||||||
|
lens (a coated blue optic), lens_amber (a laser's or lamp's warm optic).
|
||||||
|
shield(objects=None, lights=None)
|
||||||
|
light-links the glass out of the stage's area lights; only a glass with Reflect over 0 needs it.
|
||||||
|
mirrored(*matrices)
|
||||||
|
True where a chain of frames (4x4 or 3x3) reverses handedness: what a marking placed in it
|
||||||
|
must be flipped by to read left to right. surface.decal asks it of the plate and the frame.
|
||||||
|
|
||||||
|
Why glass is its own group, and why it does not mirror the scene. mechlib.stage_field lights a mech with three
|
||||||
|
square area lights, the key 5 scene radii across at 4 radii: half the sky over a canopy. A smooth dielectric
|
||||||
|
mirrors that key at Fresnel strength, and the key's radiance is many times the sky's, so any glossy pane turned
|
||||||
|
up or forward renders pale whatever its colour. Measured on WYVERN pass 2's canopy (wyvern.blend, 16 samples, mean
|
||||||
|
scene-linear radiance of the pane): 0.236 as built (roughness 0.3, coat 0.15); 0.061 with the key hidden from
|
||||||
|
glossy rays; 0.037 under the world alone; 0.406 with mechlib's own "glass" (roughness 0.04, coat 1). Transmission,
|
||||||
|
the light path and the missing interior play no part: the pane is opaque, and with its specular off it renders
|
||||||
|
(0.012, 0.005, 0.002) brown. So MechGlass keeps Cycles' specular off (Reflect 0) and paints its reflection as
|
||||||
|
emission, from the reflected ray alone: a horizon-bright overcast sky in banks, a dark ground, a small sun's glint, all at
|
||||||
|
Fresnel strength. It reads the same on any stage. Reflect over 0 brings Cycles' own reflections back
|
||||||
|
(the mech's frames in the pane); then call shield() once the stage's lights exist, or the pane goes pale again.
|
||||||
group() the MechPaint node group (built once per file). Its layers, bottom up:
|
group() the MechPaint node group (built once per file). Its layers, bottom up:
|
||||||
base paint Base Color, toned per plate by Object Info's Random and Geometry's Random Per Island (value,
|
base paint Base Color, toned per plate by Object Info's Random and Geometry's Random Per Island (value,
|
||||||
and a little hue and saturation: Tone Variation), mottled by two world-space noises (Mottle).
|
and a little hue and saturation: Tone Variation), mottled by two world-space noises (Mottle).
|
||||||
cover a marking's own colour over the paint (Cover Color, Cover); Cover Wear opens it, by Alpha, to
|
cover a marking's own colour over the paint (Cover Color, Cover); Cover Wear opens it, by Alpha, to
|
||||||
the plate under the decal, in specks and in patches.
|
the plate under the decal, in specks and in patches. Legibility (0 to 2) lifts the marking back
|
||||||
|
out of the film, streaks and dust laid over it, brightens it past 1 and closes part of the
|
||||||
|
wear; chips and mud still take it. 0 is the paint of the first pass, where a number under
|
||||||
|
breaker's grime could not be read at figure scale.
|
||||||
cavity grime Ambient Occlusion (4 samples, 0.45 m) darkens recesses, seams and the undersides of overhangs,
|
cavity grime Ambient Occlusion (4 samples, 0.45 m) darkens recesses, seams and the undersides of overhangs,
|
||||||
and a thin film lies in patches on open faces (Grime, Grime Color).
|
and a thin film lies in patches on open faces (Grime, Grime Color).
|
||||||
streaks noise stretched along world Z, on faces that stand upright, stronger where AO says something
|
streaks noise stretched along world Z, on faces that stand upright, stronger where AO says something
|
||||||
|
|
@ -50,6 +75,7 @@ INPUTS = {
|
||||||
"Cover Color": ("NodeSocketColor", (0.2, 0.19, 0.165, 1.0)),
|
"Cover Color": ("NodeSocketColor", (0.2, 0.19, 0.165, 1.0)),
|
||||||
"Cover": ("NodeSocketFloat", 0.0),
|
"Cover": ("NodeSocketFloat", 0.0),
|
||||||
"Cover Wear": ("NodeSocketFloat", 0.5),
|
"Cover Wear": ("NodeSocketFloat", 0.5),
|
||||||
|
"Legibility": ("NodeSocketFloat", 0.0),
|
||||||
"Grime": ("NodeSocketFloat", 1.0),
|
"Grime": ("NodeSocketFloat", 1.0),
|
||||||
"Grime Color": ("NodeSocketColor", (0.02, 0.017, 0.013, 1.0)),
|
"Grime Color": ("NodeSocketColor", (0.02, 0.017, 0.013, 1.0)),
|
||||||
"Streaks": ("NodeSocketFloat", 1.0),
|
"Streaks": ("NodeSocketFloat", 1.0),
|
||||||
|
|
@ -75,32 +101,33 @@ PRESETS = {
|
||||||
# SERAPH, 30.webp: a warm grey drab, the cleanest of the sheets; small chips, light streaks, mud on the feet only.
|
# SERAPH, 30.webp: a warm grey drab, the cleanest of the sheets; small chips, light streaks, mud on the feet only.
|
||||||
"seraph": {"armour": {"base_color": (0.066, 0.056, 0.038), "wear": 0.85, "grime": 0.8, "streaks": 0.8, "dust": 0.6, "mud": 0.8, "mud_top": 1.2, "wet_top": 2.0},
|
"seraph": {"armour": {"base_color": (0.066, 0.056, 0.038), "wear": 0.85, "grime": 0.8, "streaks": 0.8, "dust": 0.6, "mud": 0.8, "mud_top": 1.2, "wet_top": 2.0},
|
||||||
"metal": {**_METAL, "wear": 0.6, "mud": 0.8, "mud_top": 1.2},
|
"metal": {**_METAL, "wear": 0.6, "mud": 0.8, "mud_top": 1.2},
|
||||||
"mark": {"cover_color": (0.22, 0.21, 0.18), "cover_wear": 0.55}},
|
"mark": {"cover_color": (0.3, 0.29, 0.25), "cover_wear": 0.5, "legibility": 0.8}},
|
||||||
# MCR-3, 25.webp: greyer and darker, every plate chipped along its edges, streaked, dirty to the shin.
|
# MCR-3, 25.webp: greyer and darker, every plate chipped along its edges, streaked, dirty to the shin.
|
||||||
"mcr3": {"armour": {"base_color": (0.048, 0.044, 0.034), "wear": 1.0, "grime": 1.0, "streaks": 1.0, "dust": 0.45, "mud": 1.0, "mud_top": 1.4, "wet_top": 2.4, "tone_variation": 0.32},
|
"mcr3": {"armour": {"base_color": (0.048, 0.044, 0.034), "wear": 1.0, "grime": 1.0, "streaks": 1.0, "dust": 0.45, "mud": 1.0, "mud_top": 1.4, "wet_top": 2.4, "tone_variation": 0.32},
|
||||||
"metal": {**_METAL, "wear": 0.9},
|
"metal": {**_METAL, "wear": 0.9},
|
||||||
"mark": {"cover_color": (0.2, 0.195, 0.175), "cover_wear": 0.5}},
|
"mark": {"cover_color": (0.3, 0.29, 0.26), "cover_wear": 0.45, "legibility": 0.9}},
|
||||||
# BREAKER, 24.webp: the same drab two stops down, the heaviest wear on any sheet, mud to the knee.
|
# BREAKER, 24.webp: the same drab two stops down, the heaviest wear on any sheet, mud to the knee.
|
||||||
"breaker": {"armour": {"base_color": (0.03, 0.028, 0.021), "wear": 1.5, "grime": 1.3, "streaks": 1.3, "dust": 0.35, "mud": 1.3, "mud_top": 2.2, "wet_top": 4.0, "tone_variation": 0.35,
|
"breaker": {"armour": {"base_color": (0.03, 0.028, 0.021), "wear": 1.5, "grime": 1.3, "streaks": 1.3, "dust": 0.35, "mud": 1.3, "mud_top": 2.2, "wet_top": 4.0, "tone_variation": 0.35,
|
||||||
"primer_color": (0.12, 0.11, 0.09)},
|
"primer_color": (0.12, 0.11, 0.09)},
|
||||||
"metal": {**_METAL, "wear": 1.3, "grime": 1.5, "mud": 1.3, "mud_top": 2.2},
|
"metal": {**_METAL, "wear": 1.3, "grime": 1.5, "mud": 1.3, "mud_top": 2.2},
|
||||||
"mark": {"cover_color": (0.19, 0.18, 0.15), "cover_wear": 0.75}},
|
"mark": {"cover_color": (0.3, 0.285, 0.24), "cover_wear": 0.6, "legibility": 0.75}},
|
||||||
# PALADIN, 27.webp: an olive greener than SERAPH's, middling wear.
|
# PALADIN, 27.webp: an olive greener than SERAPH's, middling wear.
|
||||||
"paladin": {"armour": {"base_color": (0.05, 0.052, 0.033), "wear": 0.9, "grime": 0.9, "streaks": 0.9},
|
"paladin": {"armour": {"base_color": (0.05, 0.052, 0.033), "wear": 0.9, "grime": 0.9, "streaks": 0.9},
|
||||||
"metal": {**_METAL, "wear": 0.8},
|
"metal": {**_METAL, "wear": 0.8},
|
||||||
"mark": {"cover_wear": 0.5}},
|
"mark": {"cover_color": (0.3, 0.29, 0.25), "cover_wear": 0.5, "legibility": 0.8}},
|
||||||
# KESTREL, 29.webp: a light grey-green scout paint, thin wear, long streaks.
|
# KESTREL, 29.webp: a light grey-green scout paint, thin wear, long streaks.
|
||||||
"kestrel": {"armour": {"base_color": (0.06, 0.062, 0.048), "wear": 0.8, "grime": 0.9, "streaks": 1.2, "mud_top": 1.0},
|
"kestrel": {"armour": {"base_color": (0.06, 0.062, 0.048), "wear": 0.8, "grime": 0.9, "streaks": 1.2, "mud_top": 1.0},
|
||||||
"metal": {**_METAL, "wear": 0.7},
|
"metal": {**_METAL, "wear": 0.7},
|
||||||
"mark": {"cover_wear": 0.5}},
|
"mark": {"cover_color": (0.3, 0.29, 0.25), "cover_wear": 0.5, "legibility": 0.8}},
|
||||||
}
|
}
|
||||||
ROLES = {
|
ROLES = {
|
||||||
"armour": {"khaki", "olive", "olive_light", "plate_olive", "plate_white", "plate_grey", "plate_sand", "drab", "drab_fit", "drab_dark", "drab_dark_fit"},
|
"armour": {"khaki", "olive", "olive_light", "plate_olive", "plate_white", "plate_grey", "plate_sand", "drab", "drab_fit", "drab_dark", "drab_dark_fit"},
|
||||||
"metal": {"gunmetal", "frame", "machine", "structure", "plate_dark"},
|
"metal": {"gunmetal", "frame", "machine", "structure", "plate_dark"},
|
||||||
"mark": {"stencil", "marking", "marking_fresh"},
|
"mark": {"stencil", "marking", "marking_fresh"},
|
||||||
"hazard": {"hazard", "accent_yellow"},
|
"hazard": {"hazard", "accent_yellow"},
|
||||||
|
"glass": {"glass", "canopy", "wyvern_canopy", "optic"},
|
||||||
}
|
}
|
||||||
HAZARD = {"cover_color": (0.32, 0.2, 0.025), "cover_wear": 0.7}
|
HAZARD = {"cover_color": (0.32, 0.2, 0.025), "cover_wear": 0.7, "legibility": 0.5}
|
||||||
|
|
||||||
|
|
||||||
class _Net:
|
class _Net:
|
||||||
|
|
@ -163,11 +190,22 @@ class _Net:
|
||||||
return node.outputs[0]
|
return node.outputs[0]
|
||||||
|
|
||||||
|
|
||||||
|
def _current(name, inputs):
|
||||||
|
"""The file's node group of this name if its inputs are this module's, else a new, empty one: a .blend painted
|
||||||
|
by an older paint.py keeps its group under <name>.old, for whatever still uses it."""
|
||||||
|
old = bpy.data.node_groups.get(name)
|
||||||
|
if old and [i.name for i in old.interface.items_tree if i.item_type == "SOCKET" and i.in_out == "INPUT"] == list(inputs):
|
||||||
|
return old
|
||||||
|
if old:
|
||||||
|
old.name = name + ".old"
|
||||||
|
return bpy.data.node_groups.new(name, "ShaderNodeTree")
|
||||||
|
|
||||||
|
|
||||||
def group():
|
def group():
|
||||||
"""The MechPaint node group; built on first call, then the one in the file."""
|
"""The MechPaint node group; built on first call, then the one in the file."""
|
||||||
if GROUP in bpy.data.node_groups:
|
tree = _current(GROUP, INPUTS)
|
||||||
return bpy.data.node_groups[GROUP]
|
if tree.nodes:
|
||||||
tree = bpy.data.node_groups.new(GROUP, "ShaderNodeTree")
|
return tree
|
||||||
for name, (kind, default) in INPUTS.items():
|
for name, (kind, default) in INPUTS.items():
|
||||||
s = tree.interface.new_socket(name, in_out="INPUT", socket_type=kind)
|
s = tree.interface.new_socket(name, in_out="INPUT", socket_type=kind)
|
||||||
s.default_value = default
|
s.default_value = default
|
||||||
|
|
@ -197,10 +235,11 @@ def group():
|
||||||
shade = n.math("ADD", n.math("ADD", n.ramp(blotch, 0.3, 0.7, (-0.3, 0.3)), n.ramp(speck, 0.3, 0.7, (-0.2, 0.2))), n.ramp(n.noise(pos, 6.0, 5.0, 0.7), 0.3, 0.7, (-0.22, 0.22)))
|
shade = n.math("ADD", n.math("ADD", n.ramp(blotch, 0.3, 0.7, (-0.3, 0.3)), n.ramp(speck, 0.3, 0.7, (-0.2, 0.2))), n.ramp(n.noise(pos, 6.0, 5.0, 0.7), 0.3, 0.7, (-0.22, 0.22)))
|
||||||
col = n.vec("SCALE", hsv.outputs["Color"], scale=n.math("MULTIPLY_ADD", shade, G["Mottle"], 1.0))
|
col = n.vec("SCALE", hsv.outputs["Color"], scale=n.math("MULTIPLY_ADD", shade, G["Mottle"], 1.0))
|
||||||
# a marking's own colour over it, worn through by Alpha
|
# a marking's own colour over it, worn through by Alpha
|
||||||
col = n.mix(col, n.vec("SCALE", G["Cover Color"], scale=n.ramp(n.noise(pos, 7.0, 4.0), 0.3, 0.7, (0.6, 1.05))), G["Cover"])
|
cover = n.vec("SCALE", G["Cover Color"], scale=n.ramp(n.noise(pos, 7.0, 4.0), 0.3, 0.7, (0.6, 1.05)))
|
||||||
|
col = n.mix(col, cover, G["Cover"])
|
||||||
fine_lo, patch_lo = n.ramp(G["Cover Wear"], 0.0, 1.0, (0.7, 0.46)), n.ramp(G["Cover Wear"], 0.0, 1.0, (0.82, 0.46))
|
fine_lo, patch_lo = n.ramp(G["Cover Wear"], 0.0, 1.0, (0.7, 0.46)), n.ramp(G["Cover Wear"], 0.0, 1.0, (0.82, 0.46))
|
||||||
gone = n.math("MAXIMUM", n.ramp(n.noise(pos, 38.0, 3.0, 0.6, 1.2), fine_lo, n.math("ADD", fine_lo, 0.03)), n.ramp(n.noise(pos, 4.5, 5.0), patch_lo, n.math("ADD", patch_lo, 0.05)))
|
gone = n.math("MAXIMUM", n.ramp(n.noise(pos, 38.0, 3.0, 0.6, 1.2), fine_lo, n.math("ADD", fine_lo, 0.03)), n.ramp(n.noise(pos, 4.5, 5.0), patch_lo, n.math("ADD", patch_lo, 0.05)))
|
||||||
alpha = n.math("SUBTRACT", 1.0, n.mul(gone, n.math("MINIMUM", G["Cover"], 1.0)), clamp=True)
|
alpha = n.math("SUBTRACT", 1.0, n.mul(gone, n.math("MINIMUM", G["Cover"], 1.0), n.ramp(G["Legibility"], 0.0, 2.0, (1.0, 0.3))), clamp=True)
|
||||||
|
|
||||||
# cavity grime
|
# cavity grime
|
||||||
ao = tree.nodes.new("ShaderNodeAmbientOcclusion")
|
ao = tree.nodes.new("ShaderNodeAmbientOcclusion")
|
||||||
|
|
@ -224,6 +263,8 @@ def group():
|
||||||
# dust on what looks up
|
# dust on what looks up
|
||||||
dust = n.mul(n.ramp(up, 0.45, 0.95), n.ramp(n.noise(pos, 3.0, 6.0, 0.7), 0.25, 0.7, (0.25, 1.0)), G["Dust"], 0.6, clamp=True)
|
dust = n.mul(n.ramp(up, 0.45, 0.95), n.ramp(n.noise(pos, 3.0, 6.0, 0.7), 0.25, 0.7, (0.25, 1.0)), G["Dust"], 0.6, clamp=True)
|
||||||
col = n.mix(col, G["Dust Color"], dust)
|
col = n.mix(col, G["Dust Color"], dust)
|
||||||
|
# legibility: the marking's paint lifted back out of the film, streaks and dust; chips and mud below still take it
|
||||||
|
col = n.mix(col, n.vec("SCALE", cover, scale=n.ramp(G["Legibility"], 1.0, 2.0, (1.0, 1.7))), n.mul(G["Cover"], G["Legibility"], clamp=True))
|
||||||
|
|
||||||
# edge wear: chips to metal with a primer ring, scuffs on open faces
|
# edge wear: chips to metal with a primer ring, scuffs on open faces
|
||||||
bevel = tree.nodes.new("ShaderNodeBevel")
|
bevel = tree.nodes.new("ShaderNodeBevel")
|
||||||
|
|
@ -262,11 +303,195 @@ def group():
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
||||||
def _input_name(key):
|
GLASS_GROUP = "MechGlass"
|
||||||
for name in INPUTS:
|
GLASS_INPUTS = {
|
||||||
|
"Tint": ("NodeSocketColor", (0.006, 0.007, 0.008, 1.0)), # the pane's own colour, seen where nothing shows through
|
||||||
|
"Interior": ("NodeSocketFloat", 0.5), # how much of Interior Color shows where the eye looks straight in
|
||||||
|
"Interior Color": ("NodeSocketColor", (0.01, 0.011, 0.012, 1.0)),
|
||||||
|
"Roughness": ("NodeSocketFloat", 0.04),
|
||||||
|
"Reflect": ("NodeSocketFloat", 0.0), # Cycles' own specular, 1 a plain dielectric: see shield()
|
||||||
|
"Sky": ("NodeSocketFloat", 2.2), # 1 is the physical reflection of the sky; the sheets paint it stronger
|
||||||
|
"Sky Color": ("NodeSocketColor", (0.58, 0.61, 0.67, 1.0)), # stage_field's world: (0.5, 0.53, 0.58) at 1.15
|
||||||
|
"Clouds": ("NodeSocketFloat", 1.0), # the reflected sky broken into banks, so a reflection has a shape
|
||||||
|
"Ground Color": ("NodeSocketColor", (0.06, 0.055, 0.05, 1.0)),
|
||||||
|
"Glint": ("NodeSocketFloat", 1.0),
|
||||||
|
"Glint Direction": ("NodeSocketVector", (0.35, 0.5, 0.8)), # toward the sun, in the world: high over the mech's front left, where the hero views stand
|
||||||
|
"Glint Size": ("NodeSocketFloat", 0.006), # 1 - cos of the sun's half angle: 0.006 is 6 degrees
|
||||||
|
"Facets": ("NodeSocketFloat", 0.0), # panes a metre; 0 is one pane
|
||||||
|
"Facet Tilt": ("NodeSocketFloat", 0.1),
|
||||||
|
"Mullion": ("NodeSocketFloat", 0.02), # the lattice bar's width, metres
|
||||||
|
"Mullion Color": ("NodeSocketColor", (0.003, 0.003, 0.003, 1.0)),
|
||||||
|
"Dirt": ("NodeSocketFloat", 1.0),
|
||||||
|
"Dirt Color": ("NodeSocketColor", (0.03, 0.028, 0.023, 1.0)),
|
||||||
|
"Scale": ("NodeSocketFloat", 1.0),
|
||||||
|
}
|
||||||
|
GLASS_OUTPUTS = {"Color": "NodeSocketColor", "Roughness": "NodeSocketFloat", "Specular": "NodeSocketFloat", "Normal": "NodeSocketVector", "Emission": "NodeSocketColor"}
|
||||||
|
_LENS = {"roughness": 0.02, "interior": 1.0, "dirt": 0.5}
|
||||||
|
GLASS = {
|
||||||
|
# RAPTOR, 38.webp, RECESSED COCKPIT: near-black panes in an armour lattice, a pale sky low on each, no interior.
|
||||||
|
"smoked": {},
|
||||||
|
# WYVERN, 35.webp, COCKPIT & SENSOR CANOPY: a dark amber dome, the amber showing where the eye looks in.
|
||||||
|
"amber": {"tint": (0.006, 0.0025, 0.001), "interior": 1.0, "interior_color": (0.02, 0.0062, 0.0012)},
|
||||||
|
# one blown pane read as a lattice of flat ones: for a canopy built as a single dome with no frames of its own.
|
||||||
|
"faceted": {"facets": 3.5, "facet_tilt": 0.12, "mullion": 0.022},
|
||||||
|
# a coated optic: a blue-violet depth, a cold reflection (WYVERN's projector and helmet sensor; RAPTOR's emitters).
|
||||||
|
"lens": {**_LENS, "tint": (0.004, 0.005, 0.012), "interior_color": (0.0015, 0.005, 0.022), "sky_color": (0.3, 0.45, 0.95), "sky": 1.2},
|
||||||
|
"lens_amber": {**_LENS, "tint": (0.012, 0.005, 0.002), "interior_color": (0.02, 0.0055, 0.0008), "sky_color": (0.95, 0.6, 0.3), "sky": 1.2},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def glass_group():
|
||||||
|
"""The MechGlass node group; built on first call, then the one in the file. See the module header for why its
|
||||||
|
reflection is painted. Its layers: the pane (Tint, Interior Color where the view is square to it, broken by a
|
||||||
|
slow noise); facets (a Voronoi lattice in the object's frame: each cell's normal tilted its own way, a bar of
|
||||||
|
Mullion Color on the cell borders); dirt (Ambient Occlusion puts it in the corners a frame makes, a noise on
|
||||||
|
what looks up); the painted reflection (sky above the reflected horizon, brightest at it and broken into banks by Clouds; ground below; a
|
||||||
|
sun's disc and halo about Glint Direction), at Fresnel strength for IOR 1.5, dimmed by the dirt."""
|
||||||
|
tree = _current(GLASS_GROUP, GLASS_INPUTS)
|
||||||
|
if tree.nodes:
|
||||||
|
return tree
|
||||||
|
for name, (kind, default) in GLASS_INPUTS.items():
|
||||||
|
tree.interface.new_socket(name, in_out="INPUT", socket_type=kind).default_value = default
|
||||||
|
for name, kind in GLASS_OUTPUTS.items():
|
||||||
|
tree.interface.new_socket(name, in_out="OUTPUT", socket_type=kind)
|
||||||
|
n = _Net(tree)
|
||||||
|
gin, gout = tree.nodes.new("NodeGroupInput"), tree.nodes.new("NodeGroupOutput")
|
||||||
|
G = gin.outputs
|
||||||
|
geo, coords = tree.nodes.new("ShaderNodeNewGeometry"), tree.nodes.new("ShaderNodeTexCoord")
|
||||||
|
own = n.vec("SCALE", coords.outputs["Object"], scale=G["Scale"])
|
||||||
|
|
||||||
|
def z_of(vector):
|
||||||
|
node = tree.nodes.new("ShaderNodeSeparateXYZ")
|
||||||
|
tree.links.new(vector, node.inputs[0])
|
||||||
|
return node.outputs["Z"]
|
||||||
|
|
||||||
|
# facets: a tilt a cell, a bar on the borders
|
||||||
|
on = n.ramp(G["Facets"], 0.0, 0.01)
|
||||||
|
cells = n.vec("SCALE", own, scale=G["Facets"])
|
||||||
|
lattice = {}
|
||||||
|
for feature in ("F1", "DISTANCE_TO_EDGE"):
|
||||||
|
node = tree.nodes.new("ShaderNodeTexVoronoi")
|
||||||
|
node.voronoi_dimensions, node.feature = "3D", feature
|
||||||
|
node.inputs["Scale"].default_value, node.inputs["Randomness"].default_value = 1.0, 0.75
|
||||||
|
tree.links.new(cells, node.inputs["Vector"])
|
||||||
|
lattice[feature] = node
|
||||||
|
tilt = n.vec("SCALE", n.vec("SUBTRACT", lattice["F1"].outputs["Color"], (0.5, 0.5, 0.5)), scale=n.mul(G["Facet Tilt"], on, 2.0))
|
||||||
|
normal = n.vec("NORMALIZE", n.vec("ADD", geo.outputs["Normal"], tilt))
|
||||||
|
half = n.mul(G["Mullion"], G["Facets"], 0.5)
|
||||||
|
bar = n.mul(n.ramp(lattice["DISTANCE_TO_EDGE"].outputs["Distance"], n.math("MULTIPLY_ADD", half, 1.25, 0.002), half), on)
|
||||||
|
|
||||||
|
# dirt: in the corners a frame makes, and on what looks up
|
||||||
|
ao = tree.nodes.new("ShaderNodeAmbientOcclusion")
|
||||||
|
ao.samples, ao.inputs["Distance"].default_value = 4, 0.22
|
||||||
|
patchy = n.ramp(n.noise(own, 6.0, 5.0, 0.7), 0.3, 0.65, (0.35, 1.0))
|
||||||
|
corner = n.mul(n.ramp(ao.outputs["AO"], 0.9, 0.45), patchy)
|
||||||
|
settled = n.mul(n.ramp(z_of(geo.outputs["Normal"]), 0.35, 0.95), n.ramp(n.noise(own, 2.2, 6.0, 0.7), 0.35, 0.7, (0.05, 0.45)))
|
||||||
|
dirt = n.mul(n.math("MAXIMUM", corner, settled), G["Dirt"], clamp=True)
|
||||||
|
|
||||||
|
# the pane: its tint, the interior's colour where the eye looks straight in
|
||||||
|
facing = tree.nodes.new("ShaderNodeLayerWeight")
|
||||||
|
facing.inputs["Blend"].default_value = 0.5
|
||||||
|
tree.links.new(normal, facing.inputs["Normal"])
|
||||||
|
square = n.math("POWER", n.math("SUBTRACT", 1.0, facing.outputs["Facing"], clamp=True), 3.0)
|
||||||
|
inside = n.mul(square, G["Interior"], n.ramp(n.noise(own, 2.6, 3.0, 0.5), 0.3, 0.7, (0.35, 1.0)), clamp=True)
|
||||||
|
col = n.mix(G["Tint"], G["Interior Color"], inside)
|
||||||
|
col = n.mix(col, G["Mullion Color"], bar)
|
||||||
|
col = n.mix(col, G["Dirt Color"], n.math("MULTIPLY", dirt, 0.8))
|
||||||
|
|
||||||
|
# the painted reflection, from the reflected ray
|
||||||
|
ray = n.vec("REFLECT", n.vec("SCALE", geo.outputs["Incoming"], scale=-1.0), normal)
|
||||||
|
rz = z_of(ray)
|
||||||
|
banks = n.noise(n.vec("MULTIPLY", ray, (1.6, 1.6, 4.0)), 1.0, 3.0, 0.55, 0.6)
|
||||||
|
banks = n.math("MULTIPLY_ADD", n.math("SUBTRACT", n.ramp(banks, 0.4, 0.62, (0.3, 1.45)), 1.0), G["Clouds"], 1.0)
|
||||||
|
sky = n.vec("SCALE", G["Sky Color"], scale=n.mul(n.ramp(rz, -0.06, 0.04), n.ramp(rz, 0.0, 0.75, (1.25, 0.4)), banks, G["Sky"]))
|
||||||
|
env = n.mix(n.vec("SCALE", G["Ground Color"], scale=G["Sky"]), sky, n.ramp(rz, -0.06, 0.04))
|
||||||
|
toward = n.vec("DOT_PRODUCT", ray, n.vec("NORMALIZE", G["Glint Direction"]))
|
||||||
|
edge = n.math("SUBTRACT", 1.0, G["Glint Size"])
|
||||||
|
disc = n.math("POWER", n.ramp(toward, n.math("MULTIPLY_ADD", G["Glint Size"], -3.0, edge), 1.0), 3.0)
|
||||||
|
halo = n.math("POWER", n.ramp(toward, 0.6, 1.0), 10.0)
|
||||||
|
sun = n.mul(n.math("ADD", n.math("MULTIPLY", disc, 7.0), n.math("MULTIPLY", halo, 0.4)), G["Glint"])
|
||||||
|
env = n.vec("ADD", env, n.vec("SCALE", (1.0, 0.96, 0.9), scale=sun))
|
||||||
|
fresnel = tree.nodes.new("ShaderNodeFresnel")
|
||||||
|
fresnel.inputs["IOR"].default_value = 1.5
|
||||||
|
tree.links.new(normal, fresnel.inputs["Normal"])
|
||||||
|
clear = n.mul(n.math("SUBTRACT", 1.0, n.math("MULTIPLY", dirt, 0.6)), n.math("SUBTRACT", 1.0, bar))
|
||||||
|
painted = n.vec("SCALE", env, scale=n.mul(fresnel.outputs[0], clear, n.math("SUBTRACT", 1.0, G["Reflect"], clamp=True)))
|
||||||
|
|
||||||
|
tree.links.new(col, gout.inputs["Color"])
|
||||||
|
tree.links.new(n.math("ADD", G["Roughness"], n.math("MAXIMUM", n.math("MULTIPLY", dirt, 0.55), n.math("MULTIPLY", bar, 0.5)), clamp=True), gout.inputs["Roughness"])
|
||||||
|
tree.links.new(n.mul(G["Reflect"], 0.5, n.math("SUBTRACT", 1.0, n.math("MULTIPLY", dirt, 0.6))), gout.inputs["Specular"])
|
||||||
|
tree.links.new(normal, gout.inputs["Normal"])
|
||||||
|
tree.links.new(painted, gout.inputs["Emission"])
|
||||||
|
return tree
|
||||||
|
|
||||||
|
|
||||||
|
def glass(name, preset="smoked", **overrides):
|
||||||
|
"""One MechGlass material: GLASS[preset], then `overrides` (MechGlass inputs, lower case with underscores)."""
|
||||||
|
values = {**GLASS[preset], **overrides}
|
||||||
|
mat = bpy.data.materials.get(name) or bpy.data.materials.new(name)
|
||||||
|
mat.use_nodes = True
|
||||||
|
nodes, links = mat.node_tree.nodes, mat.node_tree.links
|
||||||
|
nodes.clear()
|
||||||
|
out, bsdf, grp = nodes.new("ShaderNodeOutputMaterial"), nodes.new("ShaderNodeBsdfPrincipled"), nodes.new("ShaderNodeGroup")
|
||||||
|
grp.node_tree = glass_group()
|
||||||
|
for key, value in values.items():
|
||||||
|
socket = grp.inputs[_input_name(key, GLASS_INPUTS)]
|
||||||
|
socket.default_value = value if isinstance(value, (int, float)) or len(value) == len(socket.default_value) else (*value, 1.0)
|
||||||
|
for a, b in (("Color", "Base Color"), ("Roughness", "Roughness"), ("Specular", "Specular IOR Level"), ("Normal", "Normal"), ("Emission", "Emission Color")):
|
||||||
|
links.new(grp.outputs[a], bsdf.inputs[b])
|
||||||
|
bsdf.inputs["Emission Strength"].default_value = 1.0
|
||||||
|
links.new(bsdf.outputs[0], out.inputs[0])
|
||||||
|
tint = values.get("tint", GLASS_INPUTS["Tint"][1])
|
||||||
|
mat.diffuse_color = (*tint[:3], 1.0)
|
||||||
|
mat["paint_role"], mat["paint_glass"] = "glass", preset
|
||||||
|
return mat
|
||||||
|
|
||||||
|
|
||||||
|
_make_glass = glass # apply() has a parameter of that name
|
||||||
|
|
||||||
|
|
||||||
|
def shield(objects=None, lights=None):
|
||||||
|
"""Light-link glass out of the stage's softboxes, so a pane with Reflect over 0 mirrors the world and the mech
|
||||||
|
and not a key light half the sky across (the module header has the measurement). objects: default every
|
||||||
|
object whose only material is a MechGlass; lights: default every area light in the scene. Call it after the
|
||||||
|
stage's lights exist; call it again after adding glass. Returns the objects shielded. An object that also
|
||||||
|
carries another material is left alone and named: linking is per object, and its paint needs the lights."""
|
||||||
|
scene = bpy.context.scene
|
||||||
|
lights = lights or [o for o in scene.objects if o.type == "LIGHT" and o.data.type == "AREA"]
|
||||||
|
if objects is None:
|
||||||
|
objects = [o for o in scene.objects if o.type == "MESH" and any(s.material and s.material.get("paint_role") == "glass" for s in o.material_slots)]
|
||||||
|
mixed = [o.name for o in objects if any(not s.material or s.material.get("paint_role") != "glass" for s in o.material_slots)]
|
||||||
|
if mixed:
|
||||||
|
print("SHIELD left alone, glass beside another material:", ", ".join(mixed), flush=True)
|
||||||
|
objects = [o for o in objects if o.name not in mixed]
|
||||||
|
group_ = bpy.data.collections.get("paint.shielded") or bpy.data.collections.new("paint.shielded")
|
||||||
|
for obj in list(group_.objects):
|
||||||
|
group_.objects.unlink(obj)
|
||||||
|
for obj in objects:
|
||||||
|
group_.objects.link(obj)
|
||||||
|
for entry in group_.collection_objects:
|
||||||
|
entry.light_linking.link_state = "EXCLUDE"
|
||||||
|
for light in lights:
|
||||||
|
light.light_linking.receiver_collection = group_ if objects else None
|
||||||
|
return objects
|
||||||
|
|
||||||
|
|
||||||
|
def mirrored(*matrices):
|
||||||
|
"""True where the product of these frames (4x4 or 3x3, outermost first) reverses handedness: a reflection in
|
||||||
|
the object's world matrix, in a Build's to_host, or in a frame written for the other side. A marking laid in
|
||||||
|
such a chain reads right to left until its own x is reversed; surface.decal does that."""
|
||||||
|
sign = 1.0
|
||||||
|
for m in matrices:
|
||||||
|
sign *= (m.to_3x3() if len(m) == 4 else m).determinant()
|
||||||
|
return sign < 0.0
|
||||||
|
|
||||||
|
|
||||||
|
def _input_name(key, table=None):
|
||||||
|
table = INPUTS if table is None else table
|
||||||
|
for name in table:
|
||||||
if name.lower().replace(" ", "_") == key:
|
if name.lower().replace(" ", "_") == key:
|
||||||
return name
|
return name
|
||||||
raise KeyError(f"MechPaint has no input {key!r}; it has " + ", ".join(k.lower().replace(" ", "_") for k in INPUTS))
|
raise KeyError(f"no input {key!r}; there are " + ", ".join(k.lower().replace(" ", "_") for k in table))
|
||||||
|
|
||||||
|
|
||||||
def material(name, role="armour", preset="seraph", **overrides):
|
def material(name, role="armour", preset="seraph", **overrides):
|
||||||
|
|
@ -298,8 +523,11 @@ def material(name, role="armour", preset="seraph", **overrides):
|
||||||
return mat
|
return mat
|
||||||
|
|
||||||
|
|
||||||
def apply(preset="seraph", ground=0.0, objects=None, scale=1.0, roles=None, **overrides):
|
def apply(preset="seraph", ground=0.0, objects=None, scale=1.0, roles=None, glass="smoked", lens="lens", lens_below=0.3, **overrides):
|
||||||
"""Repaint a built mech: see the module header. `roles` adds or moves material names, {name: role}."""
|
"""Repaint a built mech: see the module header. `roles` adds or moves material names, {name: role}; a role of
|
||||||
|
None leaves that material alone. glass, lens: the GLASS preset (or a dict of MechGlass inputs, over "smoked"
|
||||||
|
unless it names a "preset") for panes and for optics, an optic being a glass object under `lens_below` metres
|
||||||
|
across at scale 1."""
|
||||||
role_of = {name: role for role, names in ROLES.items() for name in names}
|
role_of = {name: role for role, names in ROLES.items() for name in names}
|
||||||
role_of.update(roles or {})
|
role_of.update(roles or {})
|
||||||
made, swapped = {}, {}
|
made, swapped = {}, {}
|
||||||
|
|
@ -307,11 +535,20 @@ def apply(preset="seraph", ground=0.0, objects=None, scale=1.0, roles=None, **ov
|
||||||
if obj.type not in {"MESH", "CURVE", "FONT"} or obj.get("stage"):
|
if obj.type not in {"MESH", "CURVE", "FONT"} or obj.get("stage"):
|
||||||
continue
|
continue
|
||||||
for slot in obj.material_slots:
|
for slot in obj.material_slots:
|
||||||
role = slot.material and (slot.material.get("paint_role") or role_of.get(slot.material.name)) # a painted mech can be repainted
|
role = slot.material and role_of.get(slot.material.name, slot.material.get("paint_role")) # a painted mech can be repainted
|
||||||
if not role:
|
if not role:
|
||||||
continue
|
continue
|
||||||
if role not in made:
|
key = role
|
||||||
made[role] = material(f"paint_{preset}_{role}", role, preset, ground_z=ground, scale=scale, **({} if role == "metal" else overrides))
|
if role == "glass":
|
||||||
swapped[slot.material.name] = made[role]
|
key = "lens" if max(obj.dimensions) * scale < lens_below else "pane"
|
||||||
slot.material = made[role]
|
if key not in made:
|
||||||
|
if role == "glass":
|
||||||
|
which = lens if key == "lens" else glass
|
||||||
|
made[key] = _make_glass(f"paint_glass_{key}", **({"preset": which} if isinstance(which, str) else which), scale=scale)
|
||||||
|
else:
|
||||||
|
made[key] = material(f"paint_{preset}_{role}", role, preset, ground_z=ground, scale=scale, **({} if role == "metal" else overrides))
|
||||||
|
swapped[slot.material.name] = made[key]
|
||||||
|
slot.material = made[key]
|
||||||
|
if any(m.get("paint_role") == "glass" and m.node_tree.nodes["Group"].inputs["Reflect"].default_value > 0 for m in made.values()):
|
||||||
|
shield()
|
||||||
return swapped
|
return swapped
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ from mathutils import Matrix, Vector
|
||||||
from mathutils.bvhtree import BVHTree
|
from mathutils.bvhtree import BVHTree
|
||||||
|
|
||||||
import mechlib as M
|
import mechlib as M
|
||||||
|
from paint import mirrored
|
||||||
|
|
||||||
T = Matrix.Translation
|
T = Matrix.Translation
|
||||||
RX = lambda deg: Matrix.Rotation(math.radians(deg), 4, "X") # noqa: E731
|
RX = lambda deg: Matrix.Rotation(math.radians(deg), 4, "X") # noqa: E731
|
||||||
|
|
@ -784,7 +785,12 @@ FONT = r"C:\Windows\Fonts\bahnschrift.ttf"
|
||||||
|
|
||||||
def decal(skin, frame, curve, mat="marking", lift=0.0012, grid=0.03):
|
def decal(skin, frame, curve, mat="marking", lift=0.0012, grid=0.03):
|
||||||
"""A flat 2D curve (in its own xy, metres, centred) laid on the surface along the frame's -z: filled, cut to a
|
"""A flat 2D curve (in its own xy, metres, centred) laid on the surface along the frame's -z: filled, cut to a
|
||||||
`grid` so it bends over a curve or a crease, each vertex set `lift` off the face. Becomes <shell>.mark.<n>."""
|
`grid` so it bends over a curve or a crease, each vertex set `lift` off the face. Becomes <shell>.mark.<n>.
|
||||||
|
It reads left to right from outside the plate on either side of a mech: where the plate's world matrix and the
|
||||||
|
frame together reverse handedness (paint.mirrored(): a plate instanced at a negative scale, a frame carried
|
||||||
|
through a mirroring to_host or written for the other side), the curve's own x is reversed before it is laid.
|
||||||
|
paint_test.py pins that on a mirrored plate."""
|
||||||
|
reading = -1.0 if mirrored(skin.obj.matrix_world, frame) else 1.0
|
||||||
holder = bpy.data.objects.new("decal.tmp", curve)
|
holder = bpy.data.objects.new("decal.tmp", curve)
|
||||||
bpy.context.scene.collection.objects.link(holder)
|
bpy.context.scene.collection.objects.link(holder)
|
||||||
M.update()
|
M.update()
|
||||||
|
|
@ -803,7 +809,7 @@ def decal(skin, frame, curve, mat="marking", lift=0.0012, grid=0.03):
|
||||||
bmesh.ops.bisect_plane(bm, geom=bm.verts[:] + bm.edges[:] + bm.faces[:], plane_co=normal * (k * grid), plane_no=normal)
|
bmesh.ops.bisect_plane(bm, geom=bm.verts[:] + bm.edges[:] + bm.faces[:], plane_co=normal * (k * grid), plane_no=normal)
|
||||||
k += 1
|
k += 1
|
||||||
for v in bm.verts:
|
for v in bm.verts:
|
||||||
seat = skin.sub(frame, v.co.x - centre.x, v.co.y - centre.y)
|
seat = skin.sub(frame, reading * (v.co.x - centre.x), v.co.y - centre.y)
|
||||||
v.co = seat.translation + seat.col[2].xyz * lift
|
v.co = seat.translation + seat.col[2].xyz * lift
|
||||||
bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:])
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces[:])
|
||||||
probe = next(iter(bm.faces))
|
probe = next(iter(bm.faces))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue