Upgrade Breaker to fable-breaker-3 and snap all hardpoints flush to hull
|
|
@ -347,8 +347,9 @@ def build_anvil() -> dict:
|
|||
"armor",
|
||||
parent=chassis,
|
||||
location=(0.0, -1.48, 1.46),
|
||||
rotation_deg=(-62.0, 0.0, 0.0),
|
||||
rotation_deg=(62.0, 0.0, 0.0),
|
||||
size=(1.88, 0.42, 0.10),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
# 2 & 3) hp.weapon.sponson_l (0,1, 1x2) & hp.weapon.sponson_r (4,1, 1x2)
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
@ -389,18 +390,20 @@ def build_anvil() -> dict:
|
|||
"hp.armor.sides",
|
||||
"armor",
|
||||
parent=chassis,
|
||||
location=(-1.26, 0.42, 1.54),
|
||||
location=(-1.20, 0.42, 1.54),
|
||||
rotation_deg=(90.0, 0.0, -90.0),
|
||||
size=(1.12, 0.34, 0.10),
|
||||
plinth_depth=0.03,
|
||||
)
|
||||
# 7) hp.engine.rear (1,3, 3x2)
|
||||
# 7) hp.engine.rear (1,3, 3x2) on sloped rear engine deck (y=1.98 -> hull surface z=1.825)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.engine.rear",
|
||||
"engine",
|
||||
parent=chassis,
|
||||
location=(0.0, 1.98, 1.70),
|
||||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
location=(0.0, 1.98, 1.815),
|
||||
rotation_deg=(-12.5, 0.0, 0.0),
|
||||
size=(1.42, 0.96, 0.15),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
# 8 & 9) hp.radiator.l (0,4, 1x2) & hp.radiator.r (4,4, 1x2)
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
|
|||
|
|
@ -406,8 +406,9 @@ def build_condor() -> dict:
|
|||
"armor",
|
||||
parent=chassis,
|
||||
location=(0.0, -2.56, 1.13),
|
||||
rotation_deg=(-69.0, 0.0, 0.0),
|
||||
rotation_deg=(69.0, 0.0, 0.0),
|
||||
size=(0.64, 0.26, 0.09),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
# 3 & 4) hp.weapon.sponson_l (0,1, 1x2) & hp.weapon.sponson_r (4,1, 1x2) on cheek weapon sponsons
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
@ -435,14 +436,15 @@ def build_condor() -> dict:
|
|||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
size=(0.54, 0.54, 0.09),
|
||||
)
|
||||
# 6) hp.engine.core (1,2, 3x2) central dorsal turbine bay
|
||||
# 6) hp.engine.core (1,2, 3x2) central dorsal turbine bay (dorsal_spine_core width 0.78, cap top at z=1.91)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.engine.core",
|
||||
"engine",
|
||||
parent=chassis,
|
||||
location=(0.0, 0.36, 1.88),
|
||||
location=(0.0, 0.36, 1.89),
|
||||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
size=(0.98, 1.18, 0.14),
|
||||
size=(0.74, 1.14, 0.14),
|
||||
plinth_depth=0.05,
|
||||
)
|
||||
# 7 & 8) hp.radiator.spine_l (0,3, 1x2) & hp.radiator.spine_r (4,3, 1x2) along canted dorsal spine flanks
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
|
|||
|
|
@ -262,8 +262,9 @@ def build_ferret() -> dict:
|
|||
"armor",
|
||||
parent=chassis,
|
||||
location=(0.0, -1.24, 0.85),
|
||||
rotation_deg=(-66.0, 0.0, 0.0),
|
||||
rotation_deg=(66.0, 0.0, 0.0),
|
||||
size=(1.12, 0.34, 0.08),
|
||||
plinth_depth=0.03,
|
||||
)
|
||||
# 2) Main turret weapon collar
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
@ -283,23 +284,25 @@ def build_ferret() -> dict:
|
|||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
size=(0.34, 0.34, 0.07),
|
||||
)
|
||||
# 4) Rear engine bay frame
|
||||
# 4) Rear engine bay frame (sloped deck surface at y=0.82 is z=1.00)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.engine.rear",
|
||||
"engine",
|
||||
parent=chassis,
|
||||
location=(0.0, 0.82, 0.94),
|
||||
rotation_deg=(-12.0, 0.0, 0.0),
|
||||
location=(0.0, 0.82, 0.99),
|
||||
rotation_deg=(-13.5, 0.0, 0.0),
|
||||
size=(0.86, 0.66, 0.13),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
# 5) Rear deck copper radiator louver bay
|
||||
# 5) Rear deck copper radiator louver bay (sloped deck surface at y=1.42 is z=0.858)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.radiator.deck",
|
||||
"radiator",
|
||||
parent=chassis,
|
||||
location=(0.0, 1.42, 0.81),
|
||||
rotation_deg=(-14.0, 0.0, 0.0),
|
||||
location=(0.0, 1.42, 0.845),
|
||||
rotation_deg=(-13.5, 0.0, 0.0),
|
||||
size=(0.88, 0.44, 0.09),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
|
||||
# --- 5. Export GLB, Manifest & Preview ---
|
||||
|
|
|
|||
|
|
@ -309,9 +309,10 @@ def build_hornet() -> dict:
|
|||
"hp.weapon.chin",
|
||||
"weapon",
|
||||
parent=chassis,
|
||||
location=(0.0, -1.46, 0.48),
|
||||
rotation_deg=(0.0, 180.0, 0.0),
|
||||
location=(0.0, -1.46, 0.525),
|
||||
rotation_deg=(5.7, 180.0, 0.0),
|
||||
size=(0.42, 0.42, 0.08),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
# 2 & 3) Stub-wing weapon pylons (under left/right wings)
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
@ -344,17 +345,19 @@ def build_hornet() -> dict:
|
|||
"hp.radiator.nacelle_l",
|
||||
"radiator",
|
||||
parent=chassis,
|
||||
location=(0.58, -0.32, 1.24),
|
||||
location=(0.54, -0.32, 1.23),
|
||||
rotation_deg=(72.0, 0.0, 34.0),
|
||||
size=(0.36, 0.32, 0.09),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.radiator.nacelle_r",
|
||||
"radiator",
|
||||
parent=chassis,
|
||||
location=(-0.58, -0.32, 1.24),
|
||||
location=(-0.54, -0.32, 1.23),
|
||||
rotation_deg=(72.0, 0.0, -34.0),
|
||||
size=(0.36, 0.32, 0.09),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
|
||||
# --- 6. Export GLB, Manifest & Preview ---
|
||||
|
|
|
|||
|
|
@ -323,8 +323,9 @@ def build_ironclad() -> dict:
|
|||
"armor",
|
||||
parent=chassis,
|
||||
location=(0.0, -1.72, 0.94),
|
||||
rotation_deg=(-68.0, 0.0, 0.0),
|
||||
rotation_deg=(68.0, 0.0, 0.0),
|
||||
size=(1.46, 0.36, 0.09),
|
||||
plinth_depth=0.04,
|
||||
)
|
||||
# 2) hp.weapon.main (1,1, 2x2)
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
|
|||
|
|
@ -333,12 +333,13 @@ def build_jackal() -> dict:
|
|||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
size=(0.62, 0.62, 0.10),
|
||||
)
|
||||
# 2) Open rear engine bay frame + twin exhaust sweeps
|
||||
# 2) Open rear engine bay frame + mounting tray + twin exhaust sweeps
|
||||
vc.make_box("rear_engine_tray", (0.64, 0.74, 0.06), "gunmetal", parent=chassis, location=(0.0, 0.90, 0.51), bevel=0.006)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.engine.rear",
|
||||
"engine",
|
||||
parent=chassis,
|
||||
location=(0.0, 0.90, 0.62),
|
||||
location=(0.0, 0.90, 0.53),
|
||||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
size=(0.62, 0.72, 0.16),
|
||||
)
|
||||
|
|
@ -355,16 +356,17 @@ def build_jackal() -> dict:
|
|||
mat_name="copper_rad",
|
||||
parent=chassis,
|
||||
)
|
||||
# 3) Upright rear copper radiator louver bay (tilted -58 deg so fins & copper header read in hero + dorsal)
|
||||
# 3) Upright rear copper radiator louver bay seated on rear cage shroud
|
||||
vc.make_box("rear_rad_shroud", (0.60, 0.06, 0.36), "gunmetal", parent=chassis, location=(0.0, 1.36, 0.74), rotation_deg=(28.0, 0.0, 0.0), bevel=0.006)
|
||||
vc.add_hardpoint_slot(
|
||||
"hp.radiator.rear",
|
||||
"radiator",
|
||||
parent=chassis,
|
||||
location=(0.0, 1.38, 0.96),
|
||||
rotation_deg=(-58.0, 0.0, 0.0),
|
||||
location=(0.0, 1.34, 0.75),
|
||||
rotation_deg=(-62.0, 0.0, 0.0),
|
||||
size=(0.58, 0.44, 0.11),
|
||||
)
|
||||
vc.make_box("rad_header_tank", (0.58, 0.09, 0.08), "copper_rad", parent=chassis, location=(0.0, 1.46, 1.15), bevel=0.008)
|
||||
vc.make_box("rad_header_tank", (0.58, 0.09, 0.08), "copper_rad", parent=chassis, location=(0.0, 1.44, 0.95), bevel=0.008)
|
||||
|
||||
# --- 7. Export GLB, Manifest & 4-Panel Preview ---
|
||||
glb_path = vc.ASSETS_VEHICLES_DIR / "jackal" / "jackal.glb"
|
||||
|
|
|
|||
|
|
@ -349,8 +349,9 @@ def build_mammoth() -> dict:
|
|||
"armor",
|
||||
parent=chassis,
|
||||
location=(0.0, -2.20, 1.36),
|
||||
rotation_deg=(-53.0, 0.0, 0.0),
|
||||
rotation_deg=(53.0, 0.0, 0.0),
|
||||
size=(1.54, 0.38, 0.10),
|
||||
plinth_depth=0.03,
|
||||
)
|
||||
# 2) hp.weapon.bow (0,1, 1x1) on front-left bow deck
|
||||
vc.make_box("bow_weapon_plinth", (0.48, 0.50, 0.12), "gunmetal", parent=chassis, location=(0.88, -1.48, 1.62), bevel=0.008)
|
||||
|
|
|
|||
|
|
@ -208,9 +208,10 @@ def build_mule() -> dict:
|
|||
"hp.armor.front",
|
||||
"armor",
|
||||
parent=chassis,
|
||||
location=(0.0, -2.28, 1.00),
|
||||
rotation_deg=(-90.0, 0.0, 0.0),
|
||||
location=(0.0, -2.18, 1.00),
|
||||
rotation_deg=(90.0, 0.0, 0.0),
|
||||
size=(1.32, 0.36, 0.09),
|
||||
plinth_depth=0.03,
|
||||
)
|
||||
# Hood engine bay frame
|
||||
vc.add_hardpoint_slot(
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 1.4 MiB |
|
|
@ -21,6 +21,7 @@ from typing import Any
|
|||
import bmesh
|
||||
import bpy
|
||||
from mathutils import Euler, Matrix, Vector
|
||||
from mathutils.bvhtree import BVHTree
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
import vehicle_common as vc # noqa: E402
|
||||
|
|
@ -88,26 +89,26 @@ SPECS: dict[str, MechRetrofitSpec] = {
|
|||
".#.#.",
|
||||
".#.#.",
|
||||
),
|
||||
blend_path=Path(r"F:\aeth-wt\fable-walk4\out\breaker_rigged.blend"),
|
||||
model_json_path=Path(r"F:\aeth-wt\fable-walk4\out\breaker_model.json"),
|
||||
target_mech_tris=28000,
|
||||
drop_collections=("breaker.build",),
|
||||
strip_prefixes=("Mark.",),
|
||||
strip_vertex_groups=("CannonL", "CannonR"),
|
||||
armature_name="breaker.rig",
|
||||
blend_path=Path(r"F:\aeth-wt\fable-breaker-3\out\breaker\breaker_walk.blend"),
|
||||
model_json_path=None,
|
||||
target_mech_tris=32000,
|
||||
drop_collections=(),
|
||||
strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "CannonL", "CannonR"),
|
||||
strip_vertex_groups=(),
|
||||
armature_name=None,
|
||||
hardpoints=(
|
||||
HardpointMount("hp.weapon.arm_l", "weapon", 0, 1, 1, 2, "breaker.rig", "ForearmL", (-2.22, 0.56, 3.58), (-1.0, 0.0, 0.0), (0.58, 0.58, 0.11)),
|
||||
HardpointMount("hp.weapon.arm_r", "weapon", 4, 1, 1, 2, "breaker.rig", "ForearmR", (2.22, 0.36, 3.58), (1.0, 0.0, 0.0), (0.58, 0.58, 0.11)),
|
||||
HardpointMount("hp.weapon.shoulder_l", "weapon", 1, 0, 1, 1, "breaker.rig", "ShoulderYokeL", (-1.68, 0.15, 6.02), (0.0, 0.0, 1.0), (0.72, 0.72, 0.12)),
|
||||
HardpointMount("hp.armor.torso", "armor", 2, 1, 1, 1, "breaker.rig", "Core", (0.0, 1.24, 5.42), (0.0, 0.82, 0.57), (1.05, 0.42, 0.11)),
|
||||
HardpointMount("hp.engine.chest", "engine", 2, 2, 1, 2, "breaker.rig", "Core", (0.0, 1.46, 4.35), (0.0, 1.0, 0.0), (0.86, 0.78, 0.13)),
|
||||
HardpointMount("hp.radiator.back_l", "radiator", 1, 1, 1, 1, "breaker.rig", "Core", (-1.30, -1.34, 5.30), (0.0, -1.0, 0.0), (0.68, 0.92, 0.12)),
|
||||
HardpointMount("hp.radiator.back_r", "radiator", 3, 1, 1, 1, "breaker.rig", "Core", (1.08, -1.50, 5.30), (0.0, -1.0, 0.0), (0.68, 0.92, 0.12)),
|
||||
HardpointMount("hp.weapon.arm_l", "weapon", 0, 1, 1, 2, "ForearmL", None, (-2.18, 0.45, 3.52), (-1.0, 0.0, 0.0), (0.54, 0.54, 0.11)),
|
||||
HardpointMount("hp.weapon.arm_r", "weapon", 4, 1, 1, 2, "ForearmR", None, (2.14, 0.65, 3.55), (1.0, 0.0, 0.0), (0.54, 0.54, 0.11)),
|
||||
HardpointMount("hp.weapon.shoulder_l", "weapon", 1, 0, 1, 1, "Core", None, (-1.48, 0.12, 5.99), (0.0, 0.0, 1.0), (0.72, 0.72, 0.12)),
|
||||
HardpointMount("hp.armor.torso", "armor", 2, 1, 1, 1, "Core", None, (0.0, 1.32, 5.05), (0.0, 0.82, 0.57), (1.02, 0.40, 0.11)),
|
||||
HardpointMount("hp.engine.chest", "engine", 2, 2, 1, 2, "Core", None, (0.0, 1.76, 4.48), (0.0, 1.0, 0.0), (0.78, 0.56, 0.13)),
|
||||
HardpointMount("hp.radiator.back_l", "radiator", 1, 1, 1, 1, "Core", None, (-1.50, -1.14, 5.22), (0.0, -1.0, 0.0), (0.68, 0.92, 0.12)),
|
||||
HardpointMount("hp.radiator.back_r", "radiator", 3, 1, 1, 1, "Core", None, (1.50, -1.14, 5.22), (0.0, -1.0, 0.0), (0.68, 0.92, 0.12)),
|
||||
),
|
||||
joints=(
|
||||
JointTagSpec("joint.torso_yaw", "breaker.rig", "Core", (0.0, 1.0, 0.0), -90.0, 90.0),
|
||||
JointTagSpec("joint.arm_l_pitch", "breaker.rig", "ShoulderYokeL", (1.0, 0.0, 0.0), -45.0, 60.0),
|
||||
JointTagSpec("joint.arm_r_pitch", "breaker.rig", "ShoulderYokeR", (1.0, 0.0, 0.0), -45.0, 60.0),
|
||||
JointTagSpec("joint.torso_yaw", "Core", None, (0.0, 1.0, 0.0), -90.0, 90.0),
|
||||
JointTagSpec("joint.arm_l_pitch", "ShoulderYokeL", None, (1.0, 0.0, 0.0), -45.0, 60.0),
|
||||
JointTagSpec("joint.arm_r_pitch", "ShoulderYokeR", None, (1.0, 0.0, 0.0), -45.0, 60.0),
|
||||
),
|
||||
),
|
||||
"paladin": MechRetrofitSpec(
|
||||
|
|
@ -131,12 +132,12 @@ SPECS: dict[str, MechRetrofitSpec] = {
|
|||
target_mech_tris=29000,
|
||||
strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "Battery.", "EW.", "EWLow.", "Gatling.", "Emitter."),
|
||||
hardpoints=(
|
||||
HardpointMount("hp.weapon.sh_l", "weapon", 1, 1, 1, 1, "Trunk", None, (-2.88, 0.35, 9.94), (0.0, 0.0, 1.0), (0.98, 0.98, 0.15)),
|
||||
HardpointMount("hp.armor.torso", "armor", 2, 1, 2, 1, "Trunk", None, (0.0, 2.02, 8.85), (0.0, 0.88, 0.47), (1.35, 0.44, 0.12)),
|
||||
HardpointMount("hp.weapon.sh_r", "weapon", 4, 1, 1, 1, "Trunk", None, (2.88, 0.35, 9.94), (0.0, 0.0, 1.0), (0.98, 0.98, 0.15)),
|
||||
HardpointMount("hp.weapon.arm_l", "weapon", 0, 2, 1, 2, "ArmL.Lower", None, (-3.44, 0.85, 5.75), (-1.0, 0.0, 0.0), (0.78, 0.78, 0.13)),
|
||||
HardpointMount("hp.engine.chest", "engine", 2, 2, 2, 2, "Trunk", None, (0.0, 2.18, 7.82), (0.0, 1.0, 0.0), (1.12, 0.94, 0.14)),
|
||||
HardpointMount("hp.weapon.arm_r", "weapon", 5, 2, 1, 2, "ArmR.Lower", None, (3.56, 1.15, 6.20), (1.0, 0.0, 0.0), (0.78, 0.78, 0.13)),
|
||||
HardpointMount("hp.weapon.sh_l", "weapon", 1, 1, 1, 1, "Trunk", None, (-2.88, 0.35, 9.82), (0.0, 0.0, 1.0), (0.94, 0.94, 0.15)),
|
||||
HardpointMount("hp.armor.torso", "armor", 2, 1, 2, 1, "Trunk", None, (0.0, 1.80, 8.75), (0.0, 0.60, 0.80), (1.22, 0.40, 0.12)),
|
||||
HardpointMount("hp.weapon.sh_r", "weapon", 4, 1, 1, 1, "Trunk", None, (2.88, 0.35, 9.82), (0.0, 0.0, 1.0), (0.94, 0.94, 0.15)),
|
||||
HardpointMount("hp.weapon.arm_l", "weapon", 0, 2, 1, 2, "ArmL.Lower", None, (-3.44, 0.85, 5.75), (-1.0, 0.0, 0.0), (0.74, 0.74, 0.13)),
|
||||
HardpointMount("hp.engine.chest", "engine", 2, 2, 2, 2, "Trunk", None, (0.0, 2.22, 8.05), (0.0, 0.94, 0.34), (0.82, 0.54, 0.14)),
|
||||
HardpointMount("hp.weapon.arm_r", "weapon", 5, 2, 1, 2, "ArmR.Lower", None, (3.52, 1.05, 6.22), (1.0, 0.0, 0.0), (0.72, 0.72, 0.13)),
|
||||
HardpointMount("hp.radiator.back_l", "radiator", 1, 4, 1, 1, "Trunk", None, (-0.92, -1.44, 8.65), (0.0, -1.0, 0.0), (0.82, 1.35, 0.14)),
|
||||
HardpointMount("hp.armor.legs", "armor", 2, 4, 2, 1, "Pelvis", None, (0.0, 1.18, 5.55), (0.0, 1.0, 0.0), (0.95, 0.38, 0.11)),
|
||||
HardpointMount("hp.radiator.back_r", "radiator", 4, 4, 1, 1, "Trunk", None, (0.92, -1.44, 8.65), (0.0, -1.0, 0.0), (0.82, 1.35, 0.14)),
|
||||
|
|
@ -167,11 +168,11 @@ SPECS: dict[str, MechRetrofitSpec] = {
|
|||
target_mech_tris=28000,
|
||||
strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "Bank0.", "Bank1.", "LaserL.", "LaserR."),
|
||||
hardpoints=(
|
||||
HardpointMount("hp.radiator.sh_l", "radiator", 1, 1, 1, 1, "_ROOT_", None, (-0.56, 0.05, 6.26), (-0.25, 0.0, 0.97), (0.66, 1.05, 0.12)),
|
||||
HardpointMount("hp.radiator.sh_r", "radiator", 3, 1, 1, 1, "_ROOT_", None, (0.56, 0.05, 6.26), (0.25, 0.0, 0.97), (0.66, 1.05, 0.12)),
|
||||
HardpointMount("hp.weapon.arm_l", "weapon", 0, 2, 1, 2, "ArmL.Fore", None, (-1.40, 2.22, 3.90), (-1.0, 0.0, 0.0), (0.56, 0.56, 0.11)),
|
||||
HardpointMount("hp.engine.chest", "engine", 2, 2, 1, 2, "_ROOT_", None, (0.0, -2.02, 6.78), (0.0, 0.0, 1.0), (0.86, 1.12, 0.14)),
|
||||
HardpointMount("hp.weapon.arm_r", "weapon", 4, 2, 1, 2, "ArmR.Fore", None, (1.40, 2.22, 3.90), (1.0, 0.0, 0.0), (0.56, 0.56, 0.11)),
|
||||
HardpointMount("hp.radiator.sh_l", "radiator", 1, 1, 1, 1, "_ROOT_", None, (-0.56, 0.05, 6.26), (-0.25, 0.0, 0.97), (0.64, 1.00, 0.12)),
|
||||
HardpointMount("hp.radiator.sh_r", "radiator", 3, 1, 1, 1, "_ROOT_", None, (0.56, 0.05, 6.26), (0.25, 0.0, 0.97), (0.64, 1.00, 0.12)),
|
||||
HardpointMount("hp.weapon.arm_l", "weapon", 0, 2, 1, 2, "ArmL.Fore", None, (-1.32, 2.14, 3.86), (-1.0, 0.0, 0.0), (0.48, 0.48, 0.11)),
|
||||
HardpointMount("hp.engine.chest", "engine", 2, 2, 1, 2, "_ROOT_", None, (0.0, -2.02, 6.78), (0.0, 0.0, 1.0), (0.82, 1.06, 0.14)),
|
||||
HardpointMount("hp.weapon.arm_r", "weapon", 4, 2, 1, 2, "ArmR.Fore", None, (1.32, 2.14, 3.86), (1.0, 0.0, 0.0), (0.48, 0.48, 0.11)),
|
||||
),
|
||||
joints=(
|
||||
JointTagSpec("joint.arm_l_pitch", "ArmL.Upper", None, (1.0, 0.0, 0.0), -45.0, 45.0),
|
||||
|
|
@ -361,11 +362,17 @@ def _normalize_materials_for_gltf() -> None:
|
|||
# Extract Group node overrides if authored by Brokkr paint_pinned
|
||||
grp = next((n for n in nt.nodes if n.type == "GROUP"), None)
|
||||
base_col = None
|
||||
cover_col = None
|
||||
cover_amt = 0.0
|
||||
metallic = None
|
||||
roughness = None
|
||||
if grp is not None:
|
||||
if "Base Color" in grp.inputs and hasattr(grp.inputs["Base Color"], "default_value"):
|
||||
base_col = tuple(grp.inputs["Base Color"].default_value)
|
||||
if "Cover Color" in grp.inputs and hasattr(grp.inputs["Cover Color"], "default_value"):
|
||||
cover_col = tuple(grp.inputs["Cover Color"].default_value)
|
||||
if "Cover" in grp.inputs and hasattr(grp.inputs["Cover"], "default_value"):
|
||||
cover_amt = float(grp.inputs["Cover"].default_value)
|
||||
if "Metallic" in grp.inputs and hasattr(grp.inputs["Metallic"], "default_value"):
|
||||
metallic = float(grp.inputs["Metallic"].default_value)
|
||||
if "Roughness" in grp.inputs and hasattr(grp.inputs["Roughness"], "default_value"):
|
||||
|
|
@ -410,6 +417,10 @@ def _normalize_materials_for_gltf() -> None:
|
|||
bsdf.inputs["Base Color"].default_value = (0.28, 0.10, 0.06, 1.0)
|
||||
bsdf.inputs["Metallic"].default_value = 0.35
|
||||
bsdf.inputs["Roughness"].default_value = 0.45
|
||||
elif "mark" in lname and cover_col is not None and cover_amt >= 0.5:
|
||||
bsdf.inputs["Base Color"].default_value = cover_col
|
||||
bsdf.inputs["Metallic"].default_value = 0.0
|
||||
bsdf.inputs["Roughness"].default_value = roughness if roughness is not None else 0.62
|
||||
elif matched_pal is not None:
|
||||
bsdf.inputs["Base Color"].default_value = vc.srgb_hex_to_linear(matched_pal["hex"])
|
||||
bsdf.inputs["Metallic"].default_value = float(matched_pal["metallic"])
|
||||
|
|
@ -533,18 +544,146 @@ def _decimate_mech_meshes(meshes: list[bpy.types.Object], target_tris: int, min_
|
|||
return raw_total, after_total
|
||||
|
||||
|
||||
def _collect_subtree_meshes(root_obj: bpy.types.Object) -> list[bpy.types.Object]:
|
||||
out: list[bpy.types.Object] = []
|
||||
def walk(obj: bpy.types.Object) -> None:
|
||||
if obj.name.startswith("slot_frame."):
|
||||
return
|
||||
if obj.type == "MESH" and obj.data is not None and len(obj.data.polygons) > 0:
|
||||
out.append(obj)
|
||||
for ch in obj.children:
|
||||
walk(ch)
|
||||
walk(root_obj)
|
||||
return out
|
||||
|
||||
|
||||
def _build_hull_bvh(mesh_objs: list[bpy.types.Object]) -> BVHTree | None:
|
||||
if not mesh_objs:
|
||||
return None
|
||||
depsgraph = bpy.context.evaluated_depsgraph_get()
|
||||
bm = bmesh.new()
|
||||
for obj in mesh_objs:
|
||||
ev = obj.evaluated_get(depsgraph)
|
||||
me = ev.to_mesh()
|
||||
if me is not None and len(me.polygons) > 0:
|
||||
me.transform(obj.matrix_world)
|
||||
bm.from_mesh(me)
|
||||
ev.to_mesh_clear()
|
||||
if len(bm.verts) == 0 or len(bm.faces) == 0:
|
||||
bm.free()
|
||||
return None
|
||||
bvh = BVHTree.FromBMesh(bm)
|
||||
bm.free()
|
||||
return bvh
|
||||
|
||||
|
||||
def _snap_hardpoint_bvh(
|
||||
hp: HardpointMount,
|
||||
parent_obj: bpy.types.Object,
|
||||
root_obj: bpy.types.Object,
|
||||
full_bvh: BVHTree,
|
||||
bvh_cache: dict[str, BVHTree],
|
||||
) -> tuple[Vector, float, tuple[float, float, float]]:
|
||||
"""Snap hardpoint anchor onto actual hull surface via 5-point BVH raycast + recessed plinth."""
|
||||
bvh = full_bvh
|
||||
if parent_obj != root_obj and hp.parent_bone is None:
|
||||
if parent_obj.name not in bvh_cache:
|
||||
sub_meshes = _collect_subtree_meshes(parent_obj)
|
||||
sub_bvh = _build_hull_bvh(sub_meshes)
|
||||
if sub_bvh is not None:
|
||||
bvh_cache[parent_obj.name] = sub_bvh
|
||||
bvh = bvh_cache.get(parent_obj.name, full_bvh)
|
||||
|
||||
p0 = Vector(hp.world_pos)
|
||||
n = Vector(hp.world_normal).normalized()
|
||||
q = Vector((0.0, 0.0, 1.0)).rotation_difference(n)
|
||||
tu = q @ Vector((1.0, 0.0, 0.0))
|
||||
tv = q @ Vector((0.0, 1.0, 0.0))
|
||||
|
||||
sx, sy, sz = hp.size
|
||||
if hp.kind == "weapon":
|
||||
r = min(sx, sy) * 0.48 * 0.78
|
||||
rx, ry = r, r
|
||||
elif hp.kind == "armor":
|
||||
rx, ry = sx * 0.38, sy * 0.14
|
||||
else:
|
||||
rx, ry = sx * 0.38, sy * 0.38
|
||||
|
||||
offsets = [(0.0, 0.0), (-rx, -ry), (rx, -ry), (rx, ry), (-rx, ry)]
|
||||
raw_hits: list[float | None] = []
|
||||
for ox, oy in offsets:
|
||||
pt = p0 + tu * ox + tv * oy
|
||||
# Cast from +1.5m along +normal toward -normal; guard against far overhang hits by also trying +0.55m
|
||||
loc, _, _, _ = bvh.ray_cast(pt + n * 0.65, -n, 1.35)
|
||||
if loc is None:
|
||||
loc, _, _, _ = bvh.ray_cast(pt + n * 1.5, -n, 3.0)
|
||||
raw_hits.append((loc - p0).dot(n) if loc is not None else None)
|
||||
|
||||
h_center = raw_hits[0]
|
||||
if h_center is None:
|
||||
near_loc, _, _, _ = bvh.find_nearest(p0)
|
||||
if near_loc is not None:
|
||||
h_center = (near_loc - p0).dot(n)
|
||||
else:
|
||||
h_center = 0.0
|
||||
# Guard against thin lifting-eye/antenna spikes lifting the entire base off the armor roof
|
||||
corner_vals = sorted(h for h in raw_hits[1:] if h is not None)
|
||||
if len(corner_vals) >= 3:
|
||||
c_med = corner_vals[len(corner_vals) // 2]
|
||||
if h_center - c_med > 0.08:
|
||||
h_center = c_med
|
||||
|
||||
# Keep corner hits near the local surface patch; replace misses/cliffs with nearest or conservative drop
|
||||
valid_corners: list[float] = [h_center]
|
||||
misses = 0
|
||||
for idx, h in enumerate(raw_hits[1:], start=1):
|
||||
if h is None or abs(h - h_center) > 0.18:
|
||||
misses += 1
|
||||
ox, oy = offsets[idx]
|
||||
near_loc, _, _, _ = bvh.find_nearest(p0 + tu * ox + tv * oy + n * h_center)
|
||||
if near_loc is not None:
|
||||
hn = (near_loc - p0).dot(n)
|
||||
if abs(hn - h_center) <= 0.18:
|
||||
valid_corners.append(hn)
|
||||
continue
|
||||
valid_corners.append(h_center - 0.035)
|
||||
else:
|
||||
valid_corners.append(h)
|
||||
|
||||
h_min = min(valid_corners)
|
||||
h_max = max(valid_corners)
|
||||
# Seat bay origin recessed into surface at center (<= 0.022m from surface so verify_glbs passes)
|
||||
# while extending plinth down past h_min and keeping rim proud above h_max
|
||||
h_seat = h_center - 0.020
|
||||
if h_max - h_seat > sz * 0.55:
|
||||
sz_out = max(sz, (h_max - h_seat) + 0.055)
|
||||
else:
|
||||
sz_out = sz
|
||||
plinth_depth = max(0.050, min(0.18, (h_seat - h_min) + 0.045))
|
||||
snapped_pos = p0 + n * h_seat
|
||||
print(
|
||||
f" [snap] {hp.hp_id:22s} | dh_c={h_center:+.3f} span=[{h_min:+.3f},{h_max:+.3f}] "
|
||||
f"seat={h_seat:+.3f} plinth={plinth_depth:.3f} miss={misses}"
|
||||
)
|
||||
return snapped_pos, plinth_depth, (sx, sy, sz_out)
|
||||
|
||||
|
||||
def _attach_hardpoint_world(
|
||||
hp: HardpointMount,
|
||||
root_obj: bpy.types.Object,
|
||||
full_bvh: BVHTree,
|
||||
bvh_cache: dict[str, BVHTree],
|
||||
) -> None:
|
||||
parent_obj = root_obj if hp.parent_name == "_ROOT_" else bpy.data.objects[hp.parent_name]
|
||||
snapped_pos, plinth_depth, adj_size = _snap_hardpoint_bvh(hp, parent_obj, root_obj, full_bvh, bvh_cache)
|
||||
anchor = vc.add_hardpoint_slot(
|
||||
hp.hp_id,
|
||||
hp.kind,
|
||||
parent=parent_obj,
|
||||
location=(0.0, 0.0, 0.0),
|
||||
rotation_deg=(0.0, 0.0, 0.0),
|
||||
size=hp.size,
|
||||
size=adj_size,
|
||||
plinth_depth=plinth_depth,
|
||||
)
|
||||
bay_root = anchor.parent
|
||||
if hp.parent_bone is not None:
|
||||
|
|
@ -554,7 +693,7 @@ def _attach_hardpoint_world(
|
|||
bpy.context.view_layer.update()
|
||||
n = Vector(hp.world_normal).normalized()
|
||||
q = Vector((0.0, 0.0, 1.0)).rotation_difference(n)
|
||||
m_world = Matrix.Translation(Vector(hp.world_pos)) @ q.to_matrix().to_4x4()
|
||||
m_world = Matrix.Translation(snapped_pos) @ q.to_matrix().to_4x4()
|
||||
|
||||
if hp.parent_bone is not None and parent_obj.type == "ARMATURE":
|
||||
pb = parent_obj.pose.bones[hp.parent_bone]
|
||||
|
|
@ -691,6 +830,234 @@ def _extract_mechanisms(model_json_path: Path, ground_z_shift: float = 0.0) -> d
|
|||
}
|
||||
|
||||
|
||||
def _extract_mechanisms_from_blend_raw(root_name: str = "Pelvis") -> dict[str, Any] | None:
|
||||
"""Extract raw Brokkr-frame DOFs, hydraulic rams, torque scissors, and oleo struts from kit_* props."""
|
||||
root_obj = bpy.data.objects.get(root_name)
|
||||
if root_obj is None or "kit_part" not in root_obj:
|
||||
return None
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
def _side_of(name: str) -> str:
|
||||
for tag, s in (("LegL", "L"), ("LegR", "R")):
|
||||
if name.startswith(tag):
|
||||
return s
|
||||
base = name.split(".")[0]
|
||||
if base.endswith("L"):
|
||||
return "L"
|
||||
if base.endswith("R"):
|
||||
return "R"
|
||||
return ""
|
||||
|
||||
limits_deg = {
|
||||
"hip": (-60.0, 60.0), "hip yaw": (-35.0, 35.0), "knee": (-100.0, 100.0),
|
||||
"ankle": (-40.0, 40.0), "waist": (-110.0, 110.0), "shoulder slew": (-100.0, 100.0),
|
||||
"shoulder hinge": (-45.0, 45.0), "arm twist": (-90.0, 90.0), "elbow": (-100.0, 100.0),
|
||||
"hinge": (-60.0, 60.0), "slew": (-90.0, 90.0),
|
||||
}
|
||||
|
||||
dofs_raw: list[dict[str, Any]] = []
|
||||
obj_to_dof: dict[str, int] = {}
|
||||
|
||||
def walk(obj: bpy.types.Object, parent_dof: int, depth: int) -> None:
|
||||
here = parent_dof
|
||||
here_depth = depth
|
||||
if obj != root_obj and "kit_socket" in obj and obj.get("kit_part") != "ram" and obj.parent is not None and "kit_part" in obj.parent:
|
||||
part = str(obj["kit_part"])
|
||||
ppart = str(obj.parent["kit_part"])
|
||||
psock = str(obj.get("kit_parent_socket", ""))
|
||||
kind: str | None = None
|
||||
if ppart == "slew_ring" and psock == "top":
|
||||
kind = "slew"
|
||||
elif str(obj.get("kit_mechanism", "")) == "oleo":
|
||||
kind = "slide"
|
||||
elif psock == "clevis":
|
||||
kind = "hinge"
|
||||
if kind is not None:
|
||||
if kind == "slew":
|
||||
# Slew axis is the parent slew_ring's Z axis at the top socket
|
||||
origin_v = obj.parent.matrix_world.translation.copy()
|
||||
axis_v = obj.parent.matrix_world.to_3x3().col[2].normalized()
|
||||
else:
|
||||
origin_v = obj.matrix_world.translation.copy()
|
||||
axis_v = obj.matrix_world.to_3x3().col[2].normalized()
|
||||
|
||||
grand = obj.parent.parent.get("kit_part", "") if obj.parent.parent else ""
|
||||
if kind == "slide":
|
||||
mech = str(obj.get("kit_mechanism", "oleo"))
|
||||
val = float(obj.get("kit_slide", 0.0))
|
||||
lo = float(obj.get("kit_min", 0.0)) - val
|
||||
hi = float(obj.get("kit_max", 0.2)) - val
|
||||
elif kind == "slew":
|
||||
mech = (
|
||||
"hip" if part in ("thigh", "hip_stub")
|
||||
else "hip yaw" if part == "shank"
|
||||
else "waist" if part == "chassis"
|
||||
else ("shoulder slew" if grand == "chassis" else "arm twist") if part == "yoke"
|
||||
else "slew"
|
||||
)
|
||||
lo, hi = (math.radians(v) for v in limits_deg[mech])
|
||||
else:
|
||||
if "kit_min" in obj and obj.get("kit_mechanism"):
|
||||
mech = str(obj["kit_mechanism"]).replace("_", " ")
|
||||
roll = float(obj.get("kit_roll", 0.0))
|
||||
lo = math.radians(float(obj["kit_min"]) - roll)
|
||||
hi = math.radians(float(obj["kit_max"]) - roll)
|
||||
else:
|
||||
if part in ("foot", "foot_core"):
|
||||
mech = "ankle"
|
||||
elif part in ("link", "strut_shin"):
|
||||
mech = "knee"
|
||||
elif part == "wrist":
|
||||
up_m = dofs_raw[parent_dof]["mechanism"] if parent_dof >= 0 else ""
|
||||
mech = "shoulder hinge" if up_m == "shoulder slew" else "elbow" if up_m == "arm twist" else "hinge"
|
||||
else:
|
||||
mech = "hinge"
|
||||
lo, hi = (math.radians(v) for v in limits_deg[mech])
|
||||
|
||||
entry: dict[str, Any] = {
|
||||
"name": obj.name,
|
||||
"parent": parent_dof,
|
||||
"kind": kind,
|
||||
"mechanism": mech,
|
||||
"side": _side_of(obj.name),
|
||||
"origin": [float(origin_v.x), float(origin_v.y), float(origin_v.z)],
|
||||
"axis": [float(axis_v.x), float(axis_v.y), float(axis_v.z)],
|
||||
"lo": float(lo),
|
||||
"hi": float(hi),
|
||||
"depth": depth,
|
||||
}
|
||||
if obj.get("kit_compliance"):
|
||||
entry["compliance"] = json.loads(str(obj["kit_compliance"]))
|
||||
if mech == "ankle":
|
||||
entry["stopped_by"] = "ram"
|
||||
here = len(dofs_raw)
|
||||
here_depth = depth + 1
|
||||
dofs_raw.append(entry)
|
||||
obj_to_dof[obj.name] = here
|
||||
for ch in obj.children:
|
||||
walk(ch, here, here_depth)
|
||||
|
||||
walk(root_obj, -1, 0)
|
||||
|
||||
rams_raw: list[dict[str, Any]] = []
|
||||
for obj in sorted(bpy.data.objects, key=lambda o: o.name):
|
||||
if obj.get("kit_part") != "ram" or obj.parent is None:
|
||||
continue
|
||||
close_to = bpy.data.objects.get(str(obj.get("kit_close_to", "")))
|
||||
if close_to is None:
|
||||
continue
|
||||
params = json.loads(str(obj.get("kit_params", "{}")))
|
||||
lug_b_params = json.loads(str(close_to.get("kit_params", "{}")))
|
||||
a_pos = obj.matrix_world.translation.copy()
|
||||
# Lug pivot sits at local (0, 0, height)
|
||||
b_h = float(lug_b_params.get("height", 0.234))
|
||||
b_pos = close_to.matrix_world @ Vector((0.0, 0.0, b_h))
|
||||
rest = float((b_pos - a_pos).length)
|
||||
pin_dir = obj.parent.matrix_world.to_3x3().col[0].normalized()
|
||||
body = float(params.get("body_len", 0.68))
|
||||
ext = float(params.get("extension", 0.40))
|
||||
a_dof = obj_to_dof.get(obj.parent.name, -1)
|
||||
b_dof = obj_to_dof.get(close_to.name, -1)
|
||||
rams_raw.append({
|
||||
"name": obj.name,
|
||||
"barrel_bone": f"{obj.name}.barrel",
|
||||
"rod_bone": f"{obj.name}.rod",
|
||||
"spans": [dofs_raw[i]["name"] for i in (a_dof + 1, b_dof) if 0 <= i < len(dofs_raw)],
|
||||
"bore": float(params.get("bore_r", 0.09)),
|
||||
"body": body,
|
||||
"inner": rest - body * 0.85,
|
||||
"extension": ext,
|
||||
"rest": rest,
|
||||
"stroke": [-ext, max(0.2, body - 0.15)],
|
||||
"a_parent_dof": a_dof,
|
||||
"a_pos": [float(a_pos.x), float(a_pos.y), float(a_pos.z)],
|
||||
"b_parent_dof": b_dof,
|
||||
"b_pos": [float(b_pos.x), float(b_pos.y), float(b_pos.z)],
|
||||
"pin_dir": [float(pin_dir.x), float(pin_dir.y), float(pin_dir.z)],
|
||||
})
|
||||
|
||||
scissors_raw: list[dict[str, Any]] = []
|
||||
for sc in json.loads(str(bpy.context.scene.get("mech_scissors", "[]"))):
|
||||
oa = bpy.data.objects.get(sc["a"][0])
|
||||
ob = bpy.data.objects.get(sc["b"][0])
|
||||
oo = bpy.data.objects.get(sc["out"][0])
|
||||
if oa is None or ob is None or oo is None:
|
||||
continue
|
||||
pa = oa.matrix_world @ Vector(sc["a"][1])
|
||||
pb = ob.matrix_world @ Vector(sc["b"][1])
|
||||
dout = (oo.matrix_world.to_3x3() @ Vector(sc["out"][1])).normalized()
|
||||
scissors_raw.append({
|
||||
"name": sc["name"],
|
||||
"upper_bone": f"{sc['name']}.upper",
|
||||
"lower_bone": f"{sc['name']}.lower",
|
||||
"arm": float(sc["arm"]),
|
||||
"a_parent_dof": obj_to_dof.get(oa.name, -1),
|
||||
"a_pos": [float(pa.x), float(pa.y), float(pa.z)],
|
||||
"b_parent_dof": obj_to_dof.get(ob.name, -1),
|
||||
"b_pos": [float(pb.x), float(pb.y), float(pb.z)],
|
||||
"out_dir": [float(dout.x), float(dout.y), float(dout.z)],
|
||||
})
|
||||
|
||||
struts_raw = [
|
||||
{
|
||||
"name": d["name"],
|
||||
"side": d["side"],
|
||||
"dof": d["name"],
|
||||
"travel": round(abs(d["hi"] - d["lo"]), 6),
|
||||
"hertz": float(d["compliance"]["hertz"]),
|
||||
"damping_ratio": float(d["compliance"]["damping_ratio"]),
|
||||
}
|
||||
for d in dofs_raw
|
||||
if d.get("mechanism") == "oleo" and "compliance" in d
|
||||
]
|
||||
|
||||
r_pos = root_obj.matrix_world.translation
|
||||
return {
|
||||
"root": [float(r_pos.x), float(r_pos.y), float(r_pos.z)],
|
||||
"dofs": dofs_raw,
|
||||
"rams": rams_raw,
|
||||
"scissors": scissors_raw,
|
||||
"struts": struts_raw,
|
||||
}
|
||||
|
||||
|
||||
def _finalize_mechanisms_gltf(raw: dict[str, Any], ground_z_shift: float) -> dict[str, Any]:
|
||||
dofs_out = []
|
||||
for d in raw["dofs"]:
|
||||
entry = {
|
||||
**d,
|
||||
"origin": _brokkr_vec_to_gltf(d["origin"], ground_z_shift),
|
||||
"axis": _brokkr_dir_to_gltf(d["axis"]),
|
||||
}
|
||||
dofs_out.append(entry)
|
||||
rams_out = [
|
||||
{
|
||||
**r,
|
||||
"a_pos": _brokkr_vec_to_gltf(r["a_pos"], ground_z_shift),
|
||||
"b_pos": _brokkr_vec_to_gltf(r["b_pos"], ground_z_shift),
|
||||
"pin_dir": _brokkr_dir_to_gltf(r["pin_dir"]),
|
||||
}
|
||||
for r in raw["rams"]
|
||||
]
|
||||
scissors_out = [
|
||||
{
|
||||
**s,
|
||||
"a_pos": _brokkr_vec_to_gltf(s["a_pos"], ground_z_shift),
|
||||
"b_pos": _brokkr_vec_to_gltf(s["b_pos"], ground_z_shift),
|
||||
"out_dir": _brokkr_dir_to_gltf(s["out_dir"]),
|
||||
}
|
||||
for s in raw["scissors"]
|
||||
]
|
||||
return {
|
||||
"frame": "gltf (+Y up, +Z forward, +X left, meters)",
|
||||
"rootOrigin": _brokkr_vec_to_gltf(raw["root"], ground_z_shift),
|
||||
"dofs": dofs_out,
|
||||
"rams": rams_out,
|
||||
"scissors": scissors_out,
|
||||
"struts": raw["struts"],
|
||||
}
|
||||
|
||||
|
||||
def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]:
|
||||
bpy.ops.wm.open_mainfile(filepath=str(spec.blend_path))
|
||||
scene = bpy.context.scene
|
||||
|
|
@ -707,6 +1074,17 @@ def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]:
|
|||
if not spec.armature_name:
|
||||
_convert_surviving_curves()
|
||||
|
||||
# Square Breaker-3 torso yaw (-5 deg walk offset -> 0 deg neutral symmetric forward)
|
||||
if spec.mech_id == "breaker" and "Core" in bpy.data.objects:
|
||||
bpy.data.objects["Core"].rotation_euler.z = 0.0
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
raw_blend_mechs = (
|
||||
_extract_mechanisms_from_blend_raw("Pelvis")
|
||||
if spec.model_json_path is None and spec.mech_id == "breaker"
|
||||
else None
|
||||
)
|
||||
|
||||
# 3. For rigged meshes, strip weapon vertex groups cleanly
|
||||
stripped_vgs: dict[str, int] = {}
|
||||
if spec.strip_vertex_groups:
|
||||
|
|
@ -732,10 +1110,14 @@ def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]:
|
|||
obj.parent = chassis_root
|
||||
obj.matrix_parent_inverse = Matrix.Identity(4)
|
||||
obj.matrix_local = mw
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
# 7. Attach standardized visible exterior hardpoint bays & tag joints
|
||||
# 7. Build hull BVH over final LOD meshes, snap & recess every hardpoint bay, tag joints
|
||||
full_bvh = _build_hull_bvh([o for o in bpy.data.objects if o.type == "MESH"])
|
||||
assert full_bvh is not None, f"{spec.mech_id}: empty hull BVH"
|
||||
bvh_cache: dict[str, BVHTree] = {}
|
||||
for hp in spec.hardpoints:
|
||||
_attach_hardpoint_world(hp, chassis_root)
|
||||
_attach_hardpoint_world(hp, chassis_root, full_bvh, bvh_cache)
|
||||
joints_manifest = _apply_joint_tags(spec)
|
||||
|
||||
# 8. Rotate chassis_root 180 deg around Z so Brokkr +Y forward -> RTD -Y forward (+Z glTF), -X left -> +X left
|
||||
|
|
@ -752,11 +1134,12 @@ def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]:
|
|||
tri_count, bounds = vc.export_vehicle_glb(glb_path, root=chassis_root)
|
||||
ground_z_shift = chassis_root.location.z - z_shift_before
|
||||
|
||||
mechanisms = (
|
||||
_extract_mechanisms(spec.model_json_path, ground_z_shift=ground_z_shift)
|
||||
if spec.model_json_path is not None
|
||||
else None
|
||||
)
|
||||
if spec.model_json_path is not None:
|
||||
mechanisms = _extract_mechanisms(spec.model_json_path, ground_z_shift=ground_z_shift)
|
||||
elif raw_blend_mechs is not None:
|
||||
mechanisms = _finalize_mechanisms_gltf(raw_blend_mechs, ground_z_shift=ground_z_shift)
|
||||
else:
|
||||
mechanisms = None
|
||||
|
||||
hp_manifest = [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -673,16 +673,20 @@ def add_hardpoint_slot(
|
|||
location: Sequence[float],
|
||||
rotation_deg: Sequence[float] = (0.0, 0.0, 0.0),
|
||||
size: Sequence[float] = (0.55, 0.55, 0.12),
|
||||
plinth_depth: float = 0.0,
|
||||
) -> bpy.types.Object:
|
||||
"""Create standardized VISIBLE exterior hardpoint socket geometry + tagged rtd.id anchor Empty.
|
||||
|
||||
The anchor Empty is named `hp_id`, carries custom properties `rtd.id` and `rtd.kind`,
|
||||
and sits at the mounting plane origin with local +Z normal (+Y in glTF) pointing outward.
|
||||
When `plinth_depth > 0`, a solid recessed base flange extends down to `z = -plinth_depth`
|
||||
so sloped/curved armor corners physically intersect the hull with zero air gap.
|
||||
"""
|
||||
if kind not in ("weapon", "radiator", "engine", "armor"):
|
||||
raise ValueError(f"Unsupported hardpoint kind {kind!r}")
|
||||
|
||||
sx, sy, sz = (float(v) for v in size)
|
||||
p_depth = max(0.0, float(plinth_depth))
|
||||
# Visual frame parented alongside the anchor
|
||||
bay_root = make_empty(f"slot_frame.{hp_id}", parent=parent, location=location, rotation_deg=rotation_deg)
|
||||
|
||||
|
|
@ -690,6 +694,18 @@ def add_hardpoint_slot(
|
|||
r_outer = min(sx, sy) * 0.48
|
||||
r_inner = r_outer * 0.72
|
||||
collar_h = max(0.055, sz * 0.65)
|
||||
if p_depth > 0.0:
|
||||
make_tube_part(
|
||||
f"{hp_id}.plinth",
|
||||
r_outer * 0.96,
|
||||
r_outer * 0.96,
|
||||
p_depth + 0.025,
|
||||
segments=12,
|
||||
smooth=False,
|
||||
mat_name="gunmetal",
|
||||
parent=bay_root,
|
||||
location=(0.0, 0.0, -p_depth),
|
||||
)
|
||||
# Octagonal bolted collar ring via Brokkr lathe
|
||||
collar_prof = [
|
||||
[r_inner, 0.0],
|
||||
|
|
@ -743,6 +759,15 @@ def add_hardpoint_slot(
|
|||
elif kind == "radiator":
|
||||
frame_t = max(0.035, min(sx, sy) * 0.09)
|
||||
depth = max(0.07, sz)
|
||||
if p_depth > 0.0:
|
||||
make_box(
|
||||
f"{hp_id}.plinth",
|
||||
(sx * 0.98, sy * 0.98, p_depth + 0.025),
|
||||
"gunmetal",
|
||||
parent=bay_root,
|
||||
location=(0.0, 0.0, (-p_depth + 0.025) * 0.5),
|
||||
bevel=0.0,
|
||||
)
|
||||
# Recessed dark bay floor
|
||||
make_box(f"{hp_id}.well", (sx * 0.92, sy * 0.92, depth * 0.4), "socket_bay", parent=bay_root, location=(0.0, 0.0, depth * 0.2), bevel=0.0)
|
||||
# Outer armored louver frame (4 bars)
|
||||
|
|
@ -778,6 +803,15 @@ def add_hardpoint_slot(
|
|||
elif kind == "engine":
|
||||
wall_t = max(0.045, min(sx, sy) * 0.10)
|
||||
depth = max(0.11, sz)
|
||||
if p_depth > 0.0:
|
||||
make_box(
|
||||
f"{hp_id}.plinth",
|
||||
(sx * 0.98, sy * 0.98, p_depth + 0.025),
|
||||
"gunmetal",
|
||||
parent=bay_root,
|
||||
location=(0.0, 0.0, (-p_depth + 0.025) * 0.5),
|
||||
bevel=0.0,
|
||||
)
|
||||
# Deep dark engine bay recess
|
||||
make_box(f"{hp_id}.well", (sx * 0.90, sy * 0.90, depth * 0.35), "socket_bay", parent=bay_root, location=(0.0, 0.0, depth * 0.18), bevel=0.0)
|
||||
# Armored coaming rails
|
||||
|
|
@ -813,6 +847,15 @@ def add_hardpoint_slot(
|
|||
|
||||
else: # "armor"
|
||||
rail_h = max(0.05, sz)
|
||||
if p_depth > 0.0:
|
||||
make_box(
|
||||
f"{hp_id}.plinth",
|
||||
(sx * 0.90, sy * 0.44, p_depth + 0.025),
|
||||
"gunmetal",
|
||||
parent=bay_root,
|
||||
location=(0.0, 0.0, (-p_depth + 0.025) * 0.5),
|
||||
bevel=0.0,
|
||||
)
|
||||
# Backing plate & stud rails across the glacis / flank
|
||||
make_box(f"{hp_id}.rail", (sx * 0.92, sy * 0.32, rail_h * 0.55), "gunmetal", parent=bay_root, location=(0.0, 0.0, rail_h * 0.28), bevel=0.006)
|
||||
n_boss = max(3, min(5, int(sx / 0.32) + 1))
|
||||
|
|
|
|||
|
|
@ -134,6 +134,186 @@ def compute_glb_stats(gltf: dict[str, Any], bin_blob: bytes = b"") -> tuple[int,
|
|||
return tri_total, g_min, g_max
|
||||
|
||||
|
||||
def _read_accessor(
|
||||
accessors: list[dict[str, Any]],
|
||||
buffer_views: list[dict[str, Any]],
|
||||
bin_blob: bytes,
|
||||
acc_idx: int,
|
||||
) -> np.ndarray:
|
||||
acc = accessors[acc_idx]
|
||||
bv = buffer_views[acc["bufferView"]]
|
||||
off = bv.get("byteOffset", 0) + acc.get("byteOffset", 0)
|
||||
count = acc["count"]
|
||||
ct = acc["componentType"]
|
||||
typ = acc["type"]
|
||||
if typ == "VEC3" and ct == 5126:
|
||||
stride = bv.get("byteStride", 12)
|
||||
if stride == 12:
|
||||
return np.frombuffer(bin_blob, dtype="<f4", count=count * 3, offset=off).reshape(count, 3).astype(np.float64)
|
||||
raw = np.frombuffer(bin_blob, dtype=np.uint8, count=count * stride, offset=off).reshape(count, stride)
|
||||
return raw[:, :12].view("<f4").reshape(count, 3).astype(np.float64)
|
||||
if typ == "SCALAR":
|
||||
dtype = {5121: np.uint8, 5123: "<u2", 5125: "<u4"}[ct]
|
||||
return np.frombuffer(bin_blob, dtype=dtype, count=count, offset=off).astype(np.int64)
|
||||
raise ValueError(f"Unsupported accessor type={typ} componentType={ct}")
|
||||
|
||||
|
||||
def _pt_tri_dist2(p: np.ndarray, a: np.ndarray, b: np.ndarray, c: np.ndarray) -> float:
|
||||
ab = b - a
|
||||
ac = c - a
|
||||
ap = p - a
|
||||
d1 = float(np.dot(ab, ap))
|
||||
d2 = float(np.dot(ac, ap))
|
||||
if d1 <= 0.0 and d2 <= 0.0:
|
||||
return float(np.dot(ap, ap))
|
||||
bp = p - b
|
||||
d3 = float(np.dot(ab, bp))
|
||||
d4 = float(np.dot(ac, bp))
|
||||
if d3 >= 0.0 and d4 <= d3:
|
||||
return float(np.dot(bp, bp))
|
||||
vc = d1 * d4 - d3 * d2
|
||||
if vc <= 0.0 and d1 >= 0.0 and d3 <= 0.0:
|
||||
denom = d1 - d3
|
||||
v = d1 / denom if denom > 1e-18 else 0.0
|
||||
q = a + v * ab
|
||||
return float(np.dot(p - q, p - q))
|
||||
cp = p - c
|
||||
d5 = float(np.dot(ab, cp))
|
||||
d6 = float(np.dot(ac, cp))
|
||||
if d6 >= 0.0 and d5 <= d6:
|
||||
return float(np.dot(cp, cp))
|
||||
vb = d5 * d2 - d1 * d6
|
||||
if vb <= 0.0 and d2 >= 0.0 and d6 <= 0.0:
|
||||
denom = d2 - d6
|
||||
w = d2 / denom if denom > 1e-18 else 0.0
|
||||
q = a + w * ac
|
||||
return float(np.dot(p - q, p - q))
|
||||
va = d3 * d6 - d5 * d4
|
||||
if va <= 0.0 and (d4 - d3) >= 0.0 and (d5 - d6) >= 0.0:
|
||||
denom = (d4 - d3) + (d5 - d6)
|
||||
w = (d4 - d3) / denom if denom > 1e-18 else 0.0
|
||||
q = b + w * (c - b)
|
||||
return float(np.dot(p - q, p - q))
|
||||
s = va + vb + vc
|
||||
if s <= 1e-18:
|
||||
return min(float(np.dot(ap, ap)), float(np.dot(bp, bp)), float(np.dot(cp, cp)))
|
||||
denom = 1.0 / s
|
||||
q = a + ab * (vb * denom) + ac * (vc * denom)
|
||||
return float(np.dot(p - q, p - q))
|
||||
|
||||
|
||||
def _min_dist_to_tris(
|
||||
pt: np.ndarray,
|
||||
tris: np.ndarray,
|
||||
tri_mins: np.ndarray,
|
||||
tri_maxs: np.ndarray,
|
||||
) -> float:
|
||||
d_box = np.maximum(0.0, np.maximum(tri_mins - pt, pt - tri_maxs))
|
||||
d2_box = np.sum(d_box * d_box, axis=1)
|
||||
order = np.argsort(d2_box)
|
||||
min_d2 = math.inf
|
||||
for idx in order:
|
||||
if d2_box[idx] > min_d2:
|
||||
break
|
||||
t = tris[idx]
|
||||
d2 = _pt_tri_dist2(pt, t[0], t[1], t[2])
|
||||
if d2 < min_d2:
|
||||
min_d2 = d2
|
||||
return math.sqrt(min_d2)
|
||||
|
||||
|
||||
def measure_hardpoint_gaps(gltf: dict[str, Any], bin_blob: bytes) -> dict[str, tuple[float, float]]:
|
||||
"""Return {hp_id: (center_to_hull_m, min_slot_vert_to_hull_m)} for all hardpoints in GLB."""
|
||||
nodes = gltf.get("nodes", [])
|
||||
meshes = gltf.get("meshes", [])
|
||||
accessors = gltf.get("accessors", [])
|
||||
buffer_views = gltf.get("bufferViews", [])
|
||||
scenes = gltf.get("scenes", [])
|
||||
root_indices = scenes[gltf.get("scene", 0)]["nodes"] if scenes else list(range(len(nodes)))
|
||||
|
||||
parent_of: dict[int, int] = {}
|
||||
for idx, n in enumerate(nodes):
|
||||
for c in n.get("children", []):
|
||||
parent_of[c] = idx
|
||||
|
||||
hp_roots: dict[int, str] = {}
|
||||
hp_anchors: dict[str, int] = {}
|
||||
for idx, n in enumerate(nodes):
|
||||
extras = n.get("extras") or {}
|
||||
if "rtd.id" in extras:
|
||||
hp_id = str(extras["rtd.id"])
|
||||
hp_anchors[hp_id] = idx
|
||||
p = parent_of.get(idx)
|
||||
if p is not None and str(nodes[p].get("name", "")).startswith("slot_frame."):
|
||||
hp_roots[p] = hp_id
|
||||
|
||||
hp_node_set: dict[int, str] = {}
|
||||
def mark_hp(idx: int, hp_id: str) -> None:
|
||||
hp_node_set[idx] = hp_id
|
||||
for c in nodes[idx].get("children", []):
|
||||
mark_hp(c, hp_id)
|
||||
for r_idx, hp_id in hp_roots.items():
|
||||
mark_hp(r_idx, hp_id)
|
||||
|
||||
hull_tris: list[np.ndarray] = []
|
||||
hp_pts: dict[str, list[np.ndarray]] = {}
|
||||
node_world: dict[int, np.ndarray] = {}
|
||||
|
||||
def walk(idx: int, pmat: np.ndarray) -> None:
|
||||
n = nodes[idx]
|
||||
w = pmat @ _node_local_matrix(n)
|
||||
node_world[idx] = w
|
||||
if "mesh" in n:
|
||||
for prim in meshes[n["mesh"]].get("primitives", []):
|
||||
if prim.get("mode", 4) != 4:
|
||||
continue
|
||||
pos = _read_accessor(accessors, buffer_views, bin_blob, prim["attributes"]["POSITION"])
|
||||
wpos = pos @ w[:3, :3].T + w[:3, 3]
|
||||
if idx in hp_node_set:
|
||||
hp_pts.setdefault(hp_node_set[idx], []).append(wpos)
|
||||
else:
|
||||
if "indices" in prim:
|
||||
ind = _read_accessor(accessors, buffer_views, bin_blob, prim["indices"]).reshape(-1, 3)
|
||||
else:
|
||||
ind = np.arange(len(pos), dtype=np.int64).reshape(-1, 3)
|
||||
hull_tris.append(wpos[ind])
|
||||
for c in n.get("children", []):
|
||||
walk(c, w)
|
||||
|
||||
ident = np.eye(4, dtype=np.float64)
|
||||
for r_idx in root_indices:
|
||||
walk(r_idx, ident)
|
||||
|
||||
if not hull_tris:
|
||||
return {}
|
||||
tris = np.concatenate(hull_tris, axis=0)
|
||||
tri_mins = tris.min(axis=1)
|
||||
tri_maxs = tris.max(axis=1)
|
||||
|
||||
gaps: dict[str, tuple[float, float]] = {}
|
||||
for r_idx, hp_id in hp_roots.items():
|
||||
p_slot = node_world[r_idx][:3, 3]
|
||||
p_anchor = node_world[hp_anchors[hp_id]][:3, 3]
|
||||
out_vec = p_anchor - p_slot
|
||||
out_len = float(np.linalg.norm(out_vec))
|
||||
n_out = out_vec / out_len if out_len > 1e-6 else np.array([0.0, 1.0, 0.0])
|
||||
|
||||
d_center = _min_dist_to_tris(p_slot, tris, tri_mins, tri_maxs)
|
||||
pts = np.concatenate(hp_pts.get(hp_id, []), axis=0) if hp_id in hp_pts else np.empty((0, 3))
|
||||
if len(pts) > 0:
|
||||
proj = (pts - p_slot) @ n_out
|
||||
base_pts = pts[proj <= 0.03]
|
||||
if len(base_pts) == 0:
|
||||
base_pts = pts
|
||||
if len(base_pts) > 256:
|
||||
base_pts = base_pts[np.linspace(0, len(base_pts) - 1, 256, dtype=int)]
|
||||
d_vert = min(_min_dist_to_tris(p, tris, tri_mins, tri_maxs) for p in base_pts)
|
||||
else:
|
||||
d_vert = d_center
|
||||
gaps[hp_id] = (d_center, d_vert)
|
||||
return gaps
|
||||
|
||||
|
||||
def validate_vehicle(vid: str) -> dict[str, Any]:
|
||||
vdir = VEHICLES_DIR / vid
|
||||
glb_path = vdir / f"{vid}.glb"
|
||||
|
|
@ -220,6 +400,20 @@ def validate_vehicle(vid: str) -> dict[str, Any]:
|
|||
elif not (1.2 <= size[0] <= 5.0 and 1.0 <= size[1] <= 3.5 and 2.5 <= size[2] <= 6.5):
|
||||
raise AssertionError(f"{vid}: implausible bounds size {size.tolist()}")
|
||||
|
||||
# 5. Flush-seating check: every hardpoint slot center and base vertices must sit <= 0.025m from hull geometry
|
||||
hp_gaps = measure_hardpoint_gaps(gltf, bin_blob)
|
||||
if len(hp_gaps) != len(manifest["hardpoints"]):
|
||||
raise AssertionError(f"{vid}: measured {len(hp_gaps)} hardpoint slots != manifest {len(manifest['hardpoints'])}")
|
||||
max_gap = 0.0
|
||||
for hp in manifest["hardpoints"]:
|
||||
hid = hp["modelNodeId"]
|
||||
d_center, d_vert = hp_gaps[hid]
|
||||
if d_center > 0.025 or d_vert > 0.025:
|
||||
raise AssertionError(
|
||||
f"{vid}: floating/buried hardpoint {hid!r} (center_to_hull={d_center:.4f}m, base_to_hull={d_vert:.4f}m > 0.025m)"
|
||||
)
|
||||
max_gap = max(max_gap, d_center, d_vert)
|
||||
|
||||
return {
|
||||
"id": vid,
|
||||
"plane": plane,
|
||||
|
|
@ -229,6 +423,7 @@ def validate_vehicle(vid: str) -> dict[str, Any]:
|
|||
"joints": len(manifest["joints"]),
|
||||
"mechanisms": len((manifest.get("mechanisms") or {}).get("dofs", [])),
|
||||
"minY": round(float(g_min[1]), 4),
|
||||
"maxHpGap": round(max_gap, 4),
|
||||
"size": [round(float(v), 3) for v in size],
|
||||
}
|
||||
|
||||
|
|
@ -257,7 +452,7 @@ def main() -> int:
|
|||
print("=== VEHICLE GLB VALIDATION PASSED ===")
|
||||
for r in v_reports:
|
||||
mech_tag = f" | dofs={r['mechanisms']}" if r["mechanisms"] else ""
|
||||
print(f" {r['id']:10s} | {r['plane']:7s} | tris={r['tris']:5d} | size={r['size']} | minY={r['minY']} | hps={r['hardpoints']} | joints={r['joints']}{mech_tag} | {r['bytes']/1024:.1f} KiB")
|
||||
print(f" {r['id']:10s} | {r['plane']:7s} | tris={r['tris']:5d} | size={r['size']} | minY={r['minY']} | hpGap={r['maxHpGap']:.4f}m | hps={r['hardpoints']} | joints={r['joints']}{mech_tag} | {r['bytes']/1024:.1f} KiB")
|
||||
print("=== GEAR GLB VALIDATION PASSED ===")
|
||||
for r in g_reports:
|
||||
print(f" {r['id']:14s} | tris={r['tris']:4d} | size={r['size']} | {r['bytes']/1024:.1f} KiB")
|
||||
|
|
|
|||