diff --git a/assets/gear/autocannon.glb b/assets/gear/autocannon.glb new file mode 100644 index 0000000..fa2c413 Binary files /dev/null and b/assets/gear/autocannon.glb differ diff --git a/assets/gear/copper_rad.glb b/assets/gear/copper_rad.glb new file mode 100644 index 0000000..e1c2692 Binary files /dev/null and b/assets/gear/copper_rad.glb differ diff --git a/assets/gear/gilded_lance.glb b/assets/gear/gilded_lance.glb new file mode 100644 index 0000000..1e0878b Binary files /dev/null and b/assets/gear/gilded_lance.glb differ diff --git a/assets/gear/gold_radiator.glb b/assets/gear/gold_radiator.glb new file mode 100644 index 0000000..b0952c8 Binary files /dev/null and b/assets/gear/gold_radiator.glb differ diff --git a/assets/gear/mg_762.glb b/assets/gear/mg_762.glb new file mode 100644 index 0000000..8c6658a Binary files /dev/null and b/assets/gear/mg_762.glb differ diff --git a/assets/gear/recoilless.glb b/assets/gear/recoilless.glb new file mode 100644 index 0000000..815f0cc Binary files /dev/null and b/assets/gear/recoilless.glb differ diff --git a/assets/vehicles/anvil/anvil.glb b/assets/vehicles/anvil/anvil.glb new file mode 100644 index 0000000..1468d2e Binary files /dev/null and b/assets/vehicles/anvil/anvil.glb differ diff --git a/assets/vehicles/anvil/manifest.json b/assets/vehicles/anvil/manifest.json new file mode 100644 index 0000000..ca8cff5 --- /dev/null +++ b/assets/vehicles/anvil/manifest.json @@ -0,0 +1,154 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "anvil", + "name": "Anvil", + "class": "Heavy Quad-Track Siege Tank", + "plane": "Dorsal", + "gridWidth": 5, + "gridHeight": 6, + "mask": [ + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "hardpoints": [ + { + "id": "hp.armor.front", + "kind": "armor", + "x": 0, + "y": 0, + "w": 5, + "h": 1, + "modelNodeId": "hp.armor.front" + }, + { + "id": "hp.weapon.sponson_l", + "kind": "weapon", + "x": 0, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.sponson_l" + }, + { + "id": "hp.weapon.siege_l", + "kind": "weapon", + "x": 1, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.siege_l" + }, + { + "id": "hp.armor.sides", + "kind": "armor", + "x": 2, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.armor.sides" + }, + { + "id": "hp.weapon.siege_r", + "kind": "weapon", + "x": 3, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.siege_r" + }, + { + "id": "hp.weapon.sponson_r", + "kind": "weapon", + "x": 4, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.sponson_r" + }, + { + "id": "hp.engine.rear", + "kind": "engine", + "x": 1, + "y": 3, + "w": 3, + "h": 2, + "modelNodeId": "hp.engine.rear" + }, + { + "id": "hp.radiator.l", + "kind": "radiator", + "x": 0, + "y": 4, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.l" + }, + { + "id": "hp.radiator.r", + "kind": "radiator", + "x": 4, + "y": 4, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.r" + } + ], + "joints": [ + { + "id": "joint.turret_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -180.0, + "max": 180.0 + } + ], + "bounds": { + "min": [ + -1.93, + 0.0, + -2.8252 + ], + "max": [ + 1.93, + 3.0266, + 2.8252 + ], + "size": [ + 3.86, + 3.0266, + 5.6504 + ] + }, + "triCount": 18044 +} diff --git a/assets/vehicles/bastion/bastion.glb b/assets/vehicles/bastion/bastion.glb new file mode 100644 index 0000000..aada0cf Binary files /dev/null and b/assets/vehicles/bastion/bastion.glb differ diff --git a/assets/vehicles/bastion/manifest.json b/assets/vehicles/bastion/manifest.json new file mode 100644 index 0000000..43f8d8a --- /dev/null +++ b/assets/vehicles/bastion/manifest.json @@ -0,0 +1,151 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "bastion", + "name": "Bastion", + "class": "Heavy Siege Quadruped", + "plane": "Dorsal", + "gridWidth": 6, + "gridHeight": 6, + "mask": [ + false, + false, + true, + true, + false, + false, + false, + true, + true, + true, + true, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + true, + true, + true, + true, + false, + false, + true, + false, + false, + true, + false + ], + "hardpoints": [ + { + "id": "hp.armor.prow", + "kind": "armor", + "x": 2, + "y": 0, + "w": 2, + "h": 1, + "modelNodeId": "hp.armor.prow" + }, + { + "id": "hp.weapon.turret_pd", + "kind": "weapon", + "x": 1, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.turret_pd" + }, + { + "id": "hp.weapon.turret_main", + "kind": "weapon", + "x": 2, + "y": 1, + "w": 2, + "h": 2, + "modelNodeId": "hp.weapon.turret_main" + }, + { + "id": "hp.weapon.flank_l", + "kind": "weapon", + "x": 0, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.flank_l" + }, + { + "id": "hp.weapon.flank_r", + "kind": "weapon", + "x": 5, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.flank_r" + }, + { + "id": "hp.engine.core", + "kind": "engine", + "x": 2, + "y": 3, + "w": 2, + "h": 2, + "modelNodeId": "hp.engine.core" + }, + { + "id": "hp.radiator.rear_l", + "kind": "radiator", + "x": 1, + "y": 4, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.rear_l" + }, + { + "id": "hp.radiator.rear_r", + "kind": "radiator", + "x": 4, + "y": 4, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.rear_r" + } + ], + "joints": [ + { + "id": "joint.turret_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -180.0, + "max": 180.0 + } + ], + "bounds": { + "min": [ + -6.6043, + 0.0, + -8.043 + ], + "max": [ + 6.6094, + 9.625, + 6.7519 + ], + "size": [ + 13.2137, + 9.625, + 14.7949 + ] + }, + "triCount": 36656 +} diff --git a/assets/vehicles/breaker/breaker.glb b/assets/vehicles/breaker/breaker.glb new file mode 100644 index 0000000..164b627 Binary files /dev/null and b/assets/vehicles/breaker/breaker.glb differ diff --git a/assets/vehicles/breaker/manifest.json b/assets/vehicles/breaker/manifest.json new file mode 100644 index 0000000..a3bd05c --- /dev/null +++ b/assets/vehicles/breaker/manifest.json @@ -0,0 +1,943 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "breaker", + "name": "Breaker", + "class": "Heavy Assault Biped", + "plane": "Coronal", + "gridWidth": 5, + "gridHeight": 6, + "mask": [ + false, + true, + true, + true, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + true, + false, + true, + false, + false, + true, + false, + true, + false + ], + "hardpoints": [ + { + "id": "hp.weapon.arm_l", + "kind": "weapon", + "x": 0, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_l" + }, + { + "id": "hp.weapon.arm_r", + "kind": "weapon", + "x": 4, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_r" + }, + { + "id": "hp.weapon.shoulder_l", + "kind": "weapon", + "x": 1, + "y": 0, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.shoulder_l" + }, + { + "id": "hp.armor.torso", + "kind": "armor", + "x": 2, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.armor.torso" + }, + { + "id": "hp.engine.chest", + "kind": "engine", + "x": 2, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.chest" + }, + { + "id": "hp.radiator.back_l", + "kind": "radiator", + "x": 1, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back_l" + }, + { + "id": "hp.radiator.back_r", + "kind": "radiator", + "x": 3, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back_r" + } + ], + "joints": [ + { + "id": "joint.torso_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -90.0, + "max": 90.0 + }, + { + "id": "joint.arm_l_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 60.0 + }, + { + "id": "joint.arm_r_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 60.0 + } + ], + "bounds": { + "min": [ + -2.3356, + -0.0, + -1.274 + ], + "max": [ + 2.3808, + 6.2567, + 1.8859 + ], + "size": [ + 4.7164, + 6.2567, + 3.1599 + ] + }, + "triCount": 39196, + "mechanisms": { + "frame": "gltf (+Y up, +Z forward, +X left, meters)", + "rootOrigin": [ + -0.0, + 3.362557, + 0.0 + ], + "dofs": [ + { + "name": "LegL.Hip", + "parent": -1, + "kind": "slew", + "mechanism": "hip", + "side": "L", + "origin": [ + 0.6209, + 3.362557, + 0.0 + ], + "axis": [ + 1.0, + -0.0, + 0.0 + ], + "lo": -1.0471975511965976, + "hi": 1.0471975511965976, + "depth": 0 + }, + { + "name": "LegL.Thigh", + "parent": 0, + "kind": "slew", + "mechanism": "hip yaw", + "side": "L", + "origin": [ + 1.0809, + 2.71148, + 0.173509 + ], + "axis": [ + -0.0, + -0.966276, + 0.257508 + ], + "lo": -0.6108652381980153, + "hi": 0.6108652381980153, + "depth": 1 + }, + { + "name": "LegL.Shin", + "parent": 1, + "kind": "hinge", + "mechanism": "knee", + "side": "L", + "origin": [ + 1.0809, + 2.086744, + 0.339999 + ], + "axis": [ + -0.0, + -0.970991, + -0.239116 + ], + "lo": -1.7453292519943295, + "hi": 1.7453292519943295, + "depth": 2 + }, + { + "name": "LegL.Oleo", + "parent": 2, + "kind": "slide", + "mechanism": "oleo", + "side": "L", + "origin": [ + 1.0809, + 1.021033, + 0.077557 + ], + "axis": [ + -0.0, + -0.970991, + -0.239116 + ], + "lo": -0.2, + "hi": 0.0, + "depth": 3, + "compliance": { + "damping_ratio": 0.45, + "hertz": 1.6 + } + }, + { + "name": "LegL.Foot", + "parent": 3, + "kind": "hinge", + "mechanism": "ankle", + "side": "L", + "origin": [ + 1.0809, + 0.624869, + -0.020002 + ], + "axis": [ + -0.0, + -1.0, + 0.0 + ], + "lo": -0.6981317007977318, + "hi": 0.6981317007977318, + "depth": 4, + "stopped_by": "ram" + }, + { + "name": "LegL.Foot.Toe0.Seg0", + "parent": 4, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 0.753334, + 0.252079, + 0.237904 + ], + "axis": [ + -0.08495, + -0.223571, + 0.970979 + ], + "lo": -0.1745329183221527, + "hi": 0.5235987824755791, + "depth": 5 + }, + { + "name": "LegL.Foot.Toe0.Seg1", + "parent": 5, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 0.719354, + 0.162651, + 0.626296 + ], + "axis": [ + -0.087156, + 0.0, + 0.996195 + ], + "lo": -0.2094395171165998, + "hi": 0.8377580340799979, + "depth": 6 + }, + { + "name": "LegL.Foot.Toe1.Seg0", + "parent": 4, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 1.408466, + 0.252079, + 0.237904 + ], + "axis": [ + 0.08495, + -0.223571, + 0.970979 + ], + "lo": -0.1745329183221527, + "hi": 0.5235987824755791, + "depth": 5 + }, + { + "name": "LegL.Foot.Toe1.Seg1", + "parent": 7, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 1.442446, + 0.162651, + 0.626296 + ], + "axis": [ + 0.087156, + 0.0, + 0.996195 + ], + "lo": -0.2094395171165998, + "hi": 0.8377580340799979, + "depth": 6 + }, + { + "name": "LegL.Foot.Toe2.Seg0", + "parent": 4, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 0.353393, + 0.252079, + 0.057444 + ], + "axis": [ + -0.58406, + -0.316267, + 0.747562 + ], + "lo": -0.17453293312755827, + "hi": 0.5235987676701735, + "depth": 5 + }, + { + "name": "LegL.Foot.Toe3.Seg0", + "parent": 4, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 1.808407, + 0.252079, + 0.057444 + ], + "axis": [ + 0.58406, + -0.316267, + 0.747562 + ], + "lo": -0.17453293312755827, + "hi": 0.5235987676701735, + "depth": 5 + }, + { + "name": "LegL.Foot.Toe4.Seg0", + "parent": 4, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 0.694624, + 0.252079, + -0.387362 + ], + "axis": [ + -0.225859, + -0.358307, + -0.905872 + ], + "lo": -0.20943950039479836, + "hi": 0.4188790303231602, + "depth": 5 + }, + { + "name": "LegL.Foot.Toe5.Seg0", + "parent": 4, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "L", + "origin": [ + 1.467176, + 0.252079, + -0.387362 + ], + "axis": [ + 0.225859, + -0.358307, + -0.905872 + ], + "lo": -0.20943950039479836, + "hi": 0.4188790303231602, + "depth": 5 + }, + { + "name": "LegR.Hip", + "parent": -1, + "kind": "slew", + "mechanism": "hip", + "side": "R", + "origin": [ + -0.6209, + 3.362557, + 0.0 + ], + "axis": [ + -1.0, + -0.0, + -0.0 + ], + "lo": -1.0471975511965976, + "hi": 1.0471975511965976, + "depth": 0 + }, + { + "name": "LegR.Thigh", + "parent": 13, + "kind": "slew", + "mechanism": "hip yaw", + "side": "R", + "origin": [ + -1.0809, + 2.690817, + 0.052652 + ], + "axis": [ + 0.0, + -0.996942, + 0.078142 + ], + "lo": -0.6108652381980153, + "hi": 0.6108652381980153, + "depth": 1 + }, + { + "name": "LegR.Shin", + "parent": 14, + "kind": "hinge", + "mechanism": "knee", + "side": "R", + "origin": [ + -1.0809, + 2.046254, + 0.103173 + ], + "axis": [ + 0.0, + -0.944097, + -0.329667 + ], + "lo": -1.7453292519943295, + "hi": 1.7453292519943295, + "depth": 2 + }, + { + "name": "LegR.Oleo", + "parent": 15, + "kind": "slide", + "mechanism": "oleo", + "side": "R", + "origin": [ + -1.0809, + 1.01006, + -0.258652 + ], + "axis": [ + 0.0, + -0.944097, + -0.329667 + ], + "lo": -0.2, + "hi": 0.0, + "depth": 3, + "compliance": { + "damping_ratio": 0.45, + "hertz": 1.6 + } + }, + { + "name": "LegR.Foot", + "parent": 16, + "kind": "hinge", + "mechanism": "ankle", + "side": "R", + "origin": [ + -1.0809, + 0.624868, + -0.393156 + ], + "axis": [ + 0.0, + -1.0, + 0.0 + ], + "lo": -0.6981317007977318, + "hi": 0.6981317007977318, + "depth": 4, + "stopped_by": "ram" + }, + { + "name": "LegR.Foot.Toe0.Seg0", + "parent": 17, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -1.408466, + 0.252079, + -0.13525 + ], + "axis": [ + -0.08495, + -0.223571, + 0.970979 + ], + "lo": -0.1745329183221527, + "hi": 0.5235987824755791, + "depth": 5 + }, + { + "name": "LegR.Foot.Toe0.Seg1", + "parent": 18, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -1.442446, + 0.16265, + 0.253141 + ], + "axis": [ + -0.087156, + 0.0, + 0.996195 + ], + "lo": -0.2094395171165998, + "hi": 0.8377580340799979, + "depth": 6 + }, + { + "name": "LegR.Foot.Toe1.Seg0", + "parent": 17, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -0.753334, + 0.252079, + -0.135251 + ], + "axis": [ + 0.08495, + -0.223571, + 0.970979 + ], + "lo": -0.1745329183221527, + "hi": 0.5235987824755791, + "depth": 5 + }, + { + "name": "LegR.Foot.Toe1.Seg1", + "parent": 20, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -0.719354, + 0.16265, + 0.253141 + ], + "axis": [ + 0.087156, + 0.0, + 0.996195 + ], + "lo": -0.2094395171165998, + "hi": 0.8377580340799979, + "depth": 6 + }, + { + "name": "LegR.Foot.Toe2.Seg0", + "parent": 17, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -1.808407, + 0.252079, + -0.315711 + ], + "axis": [ + -0.58406, + -0.316267, + 0.747562 + ], + "lo": -0.17453293312755827, + "hi": 0.5235987676701735, + "depth": 5 + }, + { + "name": "LegR.Foot.Toe3.Seg0", + "parent": 17, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -0.353393, + 0.252079, + -0.315711 + ], + "axis": [ + 0.58406, + -0.316267, + 0.747562 + ], + "lo": -0.17453293312755827, + "hi": 0.5235987676701735, + "depth": 5 + }, + { + "name": "LegR.Foot.Toe4.Seg0", + "parent": 17, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -1.467176, + 0.252079, + -0.760517 + ], + "axis": [ + -0.225859, + -0.358307, + -0.905872 + ], + "lo": -0.20943950039479836, + "hi": 0.4188790303231602, + "depth": 5 + }, + { + "name": "LegR.Foot.Toe5.Seg0", + "parent": 17, + "kind": "hinge", + "mechanism": "toe pitch", + "side": "R", + "origin": [ + -0.694624, + 0.252079, + -0.760517 + ], + "axis": [ + 0.225859, + -0.358307, + -0.905872 + ], + "lo": -0.20943950039479836, + "hi": 0.4188790303231602, + "depth": 5 + }, + { + "name": "Core", + "parent": -1, + "kind": "slew", + "mechanism": "waist", + "side": "", + "origin": [ + -0.0, + 3.721381, + 0.0 + ], + "axis": [ + -0.0, + 1.0, + 0.0 + ], + "lo": -1.9198621771937625, + "hi": 1.9198621771937625, + "depth": 0 + }, + { + "name": "ShoulderYokeL", + "parent": 26, + "kind": "slew", + "mechanism": "shoulder slew", + "side": "L", + "origin": [ + 0.819255, + 4.983909, + 0.0 + ], + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "lo": -1.7453292519943295, + "hi": 1.7453292519943295, + "depth": 1 + }, + { + "name": "UpperArmL", + "parent": 27, + "kind": "hinge", + "mechanism": "shoulder hinge", + "side": "L", + "origin": [ + 1.488455, + 4.983909, + 0.0 + ], + "axis": [ + 0.087165, + -0.991212, + 0.0995 + ], + "lo": -0.7853981633974483, + "hi": 0.7853981633974483, + "depth": 2 + }, + { + "name": "ElbowYokeL", + "parent": 28, + "kind": "slew", + "mechanism": "arm twist", + "side": "L", + "origin": [ + 1.556551, + 4.209545, + 0.077732 + ], + "axis": [ + 0.087165, + -0.991212, + 0.0995 + ], + "lo": -1.5707963267948966, + "hi": 1.5707963267948966, + "depth": 3 + }, + { + "name": "ForearmL", + "parent": 29, + "kind": "hinge", + "mechanism": "elbow", + "side": "L", + "origin": [ + 1.601947, + 3.693322, + 0.129552 + ], + "axis": [ + 0.1199, + -0.441691, + 0.889119 + ], + "lo": -1.7453292519943295, + "hi": 1.7453292519943295, + "depth": 4 + }, + { + "name": "ShoulderYokeR", + "parent": 26, + "kind": "slew", + "mechanism": "shoulder slew", + "side": "R", + "origin": [ + -0.819255, + 4.983909, + 0.0 + ], + "axis": [ + -1.0, + -0.0, + -0.0 + ], + "lo": -1.7453292519943295, + "hi": 1.7453292519943295, + "depth": 1 + }, + { + "name": "UpperArmR", + "parent": 31, + "kind": "hinge", + "mechanism": "shoulder hinge", + "side": "R", + "origin": [ + -1.488455, + 4.983909, + -0.0 + ], + "axis": [ + -0.061315, + -0.978592, + 0.196466 + ], + "lo": -0.7853981633974483, + "hi": 0.7853981633974483, + "depth": 2 + }, + { + "name": "ElbowYokeR", + "parent": 32, + "kind": "slew", + "mechanism": "arm twist", + "side": "R", + "origin": [ + -1.536356, + 4.219404, + 0.153485 + ], + "axis": [ + -0.061315, + -0.978592, + 0.196466 + ], + "lo": -1.5707963267948966, + "hi": 1.5707963267948966, + "depth": 3 + }, + { + "name": "ForearmR", + "parent": 33, + "kind": "hinge", + "mechanism": "elbow", + "side": "R", + "origin": [ + -1.56829, + 3.709754, + 0.255804 + ], + "axis": [ + 0.03822, + -0.374104, + 0.926599 + ], + "lo": -1.7453292519943295, + "hi": 1.7453292519943295, + "depth": 4 + } + ], + "rams": [], + "scissors": [ + { + "name": "LegL.Torque", + "upper_bone": "LegL.Torque.upper", + "lower_bone": "LegL.Torque.lower", + "arm": 0.3087611656677239, + "a_parent_dof": 2, + "a_pos": [ + 1.0809, + 1.240598, + 0.44059 + ], + "b_parent_dof": 3, + "b_pos": [ + 1.0809, + 0.757042, + 0.32151 + ], + "out_dir": [ + 0.0, + -0.239116, + 0.970991 + ] + }, + { + "name": "LegR.Torque", + "upper_bone": "LegR.Torque.upper", + "lower_bone": "LegR.Torque.lower", + "arm": 0.30876125639651403, + "a_parent_dof": 15, + "a_pos": [ + -1.0809, + 1.194391, + 0.123477 + ], + "b_parent_dof": 16, + "b_pos": [ + -1.0809, + 0.724229, + -0.040697 + ], + "out_dir": [ + 0.0, + -0.329667, + 0.944097 + ] + } + ], + "struts": [ + { + "name": "LegL.Oleo", + "side": "L", + "dof": "LegL.Oleo", + "travel": 0.2, + "hertz": 1.6, + "damping_ratio": 0.45 + }, + { + "name": "LegR.Oleo", + "side": "R", + "dof": "LegR.Oleo", + "travel": 0.2, + "hertz": 1.6, + "damping_ratio": 0.45 + } + ] + } +} diff --git a/assets/vehicles/condor/condor.glb b/assets/vehicles/condor/condor.glb new file mode 100644 index 0000000..692968b Binary files /dev/null and b/assets/vehicles/condor/condor.glb differ diff --git a/assets/vehicles/condor/manifest.json b/assets/vehicles/condor/manifest.json new file mode 100644 index 0000000..8b056e5 --- /dev/null +++ b/assets/vehicles/condor/manifest.json @@ -0,0 +1,225 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "condor", + "name": "Condor", + "class": "Heavy Quad-Thruster Assault VTOL", + "plane": "Dorsal", + "gridWidth": 5, + "gridHeight": 6, + "mask": [ + false, + true, + true, + true, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + false, + true, + false, + false + ], + "hardpoints": [ + { + "id": "hp.weapon.nose", + "kind": "weapon", + "x": 1, + "y": 0, + "w": 2, + "h": 1, + "modelNodeId": "hp.weapon.nose" + }, + { + "id": "hp.armor.hull", + "kind": "armor", + "x": 3, + "y": 0, + "w": 1, + "h": 1, + "modelNodeId": "hp.armor.hull" + }, + { + "id": "hp.weapon.sponson_l", + "kind": "weapon", + "x": 0, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.sponson_l" + }, + { + "id": "hp.weapon.dorsal", + "kind": "weapon", + "x": 2, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.dorsal" + }, + { + "id": "hp.weapon.sponson_r", + "kind": "weapon", + "x": 4, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.sponson_r" + }, + { + "id": "hp.engine.core", + "kind": "engine", + "x": 1, + "y": 2, + "w": 3, + "h": 2, + "modelNodeId": "hp.engine.core" + }, + { + "id": "hp.radiator.spine_l", + "kind": "radiator", + "x": 0, + "y": 3, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.spine_l" + }, + { + "id": "hp.radiator.spine_r", + "kind": "radiator", + "x": 4, + "y": 3, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.spine_r" + } + ], + "joints": [ + { + "id": "joint.nacelle_fl", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 75.0 + }, + { + "id": "joint.rotor_fl", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.nacelle_fr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 75.0 + }, + { + "id": "joint.rotor_fr", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.nacelle_rl", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 75.0 + }, + { + "id": "joint.rotor_rl", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.nacelle_rr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 75.0 + }, + { + "id": "joint.rotor_rr", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.turret_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -180.0, + "max": 180.0 + } + ], + "bounds": { + "min": [ + -2.3586, + 0.0, + -3.1 + ], + "max": [ + 2.3586, + 2.2046, + 2.7758 + ], + "size": [ + 4.7172, + 2.2046, + 5.8758 + ] + }, + "triCount": 12960 +} diff --git a/assets/vehicles/ferret/ferret.glb b/assets/vehicles/ferret/ferret.glb new file mode 100644 index 0000000..e2bd6ea Binary files /dev/null and b/assets/vehicles/ferret/ferret.glb differ diff --git a/assets/vehicles/ferret/manifest.json b/assets/vehicles/ferret/manifest.json new file mode 100644 index 0000000..77052ab --- /dev/null +++ b/assets/vehicles/ferret/manifest.json @@ -0,0 +1,100 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "ferret", + "name": "Ferret", + "class": "Light Tracked Scout Tankette", + "plane": "Dorsal", + "gridWidth": 3, + "gridHeight": 4, + "mask": [ + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "hardpoints": [ + { + "id": "hp.armor.glacis", + "kind": "armor", + "x": 0, + "y": 0, + "w": 3, + "h": 1, + "modelNodeId": "hp.armor.glacis" + }, + { + "id": "hp.weapon.pod", + "kind": "weapon", + "x": 0, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.pod" + }, + { + "id": "hp.weapon.turret", + "kind": "weapon", + "x": 1, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.turret" + }, + { + "id": "hp.engine.rear", + "kind": "engine", + "x": 2, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.rear" + }, + { + "id": "hp.radiator.deck", + "kind": "radiator", + "x": 1, + "y": 3, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.deck" + } + ], + "joints": [ + { + "id": "joint.turret_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -180.0, + "max": 180.0 + } + ], + "bounds": { + "min": [ + -1.1075, + 0.0, + -1.8009 + ], + "max": [ + 1.1075, + 1.5523, + 1.869 + ], + "size": [ + 2.215, + 1.5523, + 3.6699 + ] + }, + "triCount": 7612 +} diff --git a/assets/vehicles/hornet/hornet.glb b/assets/vehicles/hornet/hornet.glb new file mode 100644 index 0000000..abc6a71 Binary files /dev/null and b/assets/vehicles/hornet/hornet.glb differ diff --git a/assets/vehicles/hornet/manifest.json b/assets/vehicles/hornet/manifest.json new file mode 100644 index 0000000..bfe246a --- /dev/null +++ b/assets/vehicles/hornet/manifest.json @@ -0,0 +1,143 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "hornet", + "name": "Hornet", + "class": "Light Ducted-Fan VTOL Gunship", + "plane": "Dorsal", + "gridWidth": 4, + "gridHeight": 4, + "mask": [ + false, + true, + true, + false, + true, + true, + true, + true, + true, + true, + true, + true, + false, + true, + true, + false + ], + "hardpoints": [ + { + "id": "hp.weapon.chin", + "kind": "weapon", + "x": 1, + "y": 0, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.chin" + }, + { + "id": "hp.radiator.nacelle_l", + "kind": "radiator", + "x": 0, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.nacelle_l" + }, + { + "id": "hp.radiator.nacelle_r", + "kind": "radiator", + "x": 3, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.nacelle_r" + }, + { + "id": "hp.weapon.wing_l", + "kind": "weapon", + "x": 0, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.wing_l" + }, + { + "id": "hp.engine.core", + "kind": "engine", + "x": 1, + "y": 2, + "w": 2, + "h": 2, + "modelNodeId": "hp.engine.core" + }, + { + "id": "hp.weapon.wing_r", + "kind": "weapon", + "x": 3, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.wing_r" + } + ], + "joints": [ + { + "id": "joint.nacelle_l", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 75.0 + }, + { + "id": "joint.rotor_l", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.nacelle_r", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 75.0 + }, + { + "id": "joint.rotor_r", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + } + ], + "bounds": { + "min": [ + -1.65, + -0.0, + -2.6715 + ], + "max": [ + 1.65, + 1.8235, + 2.0 + ], + "size": [ + 3.3, + 1.8235, + 4.6715 + ] + }, + "triCount": 7252 +} diff --git a/assets/vehicles/ironclad/ironclad.glb b/assets/vehicles/ironclad/ironclad.glb new file mode 100644 index 0000000..e7a9470 Binary files /dev/null and b/assets/vehicles/ironclad/ironclad.glb differ diff --git a/assets/vehicles/ironclad/manifest.json b/assets/vehicles/ironclad/manifest.json new file mode 100644 index 0000000..f3b5bfa --- /dev/null +++ b/assets/vehicles/ironclad/manifest.json @@ -0,0 +1,126 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "ironclad", + "name": "Ironclad", + "class": "Medium Tracked Battle Tank", + "plane": "Dorsal", + "gridWidth": 4, + "gridHeight": 5, + "mask": [ + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "hardpoints": [ + { + "id": "hp.armor.front", + "kind": "armor", + "x": 0, + "y": 0, + "w": 4, + "h": 1, + "modelNodeId": "hp.armor.front" + }, + { + "id": "hp.weapon.coax", + "kind": "weapon", + "x": 0, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.coax" + }, + { + "id": "hp.weapon.main", + "kind": "weapon", + "x": 1, + "y": 1, + "w": 2, + "h": 2, + "modelNodeId": "hp.weapon.main" + }, + { + "id": "hp.armor.skirts", + "kind": "armor", + "x": 3, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.armor.skirts" + }, + { + "id": "hp.radiator.l", + "kind": "radiator", + "x": 0, + "y": 3, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.l" + }, + { + "id": "hp.engine.rear", + "kind": "engine", + "x": 1, + "y": 3, + "w": 2, + "h": 2, + "modelNodeId": "hp.engine.rear" + }, + { + "id": "hp.radiator.r", + "kind": "radiator", + "x": 3, + "y": 3, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.r" + } + ], + "joints": [ + { + "id": "joint.turret_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -180.0, + "max": 180.0 + } + ], + "bounds": { + "min": [ + -1.5272, + 0.0, + -2.4115 + ], + "max": [ + 1.4934, + 1.792, + 2.3554 + ], + "size": [ + 3.0206, + 1.792, + 4.7669 + ] + }, + "triCount": 16840 +} diff --git a/assets/vehicles/jackal/jackal.glb b/assets/vehicles/jackal/jackal.glb new file mode 100644 index 0000000..ce79f09 Binary files /dev/null and b/assets/vehicles/jackal/jackal.glb differ diff --git a/assets/vehicles/jackal/manifest.json b/assets/vehicles/jackal/manifest.json new file mode 100644 index 0000000..fc9934c --- /dev/null +++ b/assets/vehicles/jackal/manifest.json @@ -0,0 +1,132 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "jackal", + "name": "Jackal", + "class": "Light Wheeled Dune Buggy", + "plane": "Dorsal", + "gridWidth": 3, + "gridHeight": 4, + "mask": [ + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "hardpoints": [ + { + "id": "hp.weapon.roof", + "kind": "weapon", + "x": 1, + "y": 0, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.roof" + }, + { + "id": "hp.engine.rear", + "kind": "engine", + "x": 1, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.rear" + }, + { + "id": "hp.radiator.rear", + "kind": "radiator", + "x": 2, + "y": 3, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.rear" + } + ], + "joints": [ + { + "id": "joint.steer_fl", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -32.0, + "max": 32.0 + }, + { + "id": "joint.wheel_fl", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.steer_fr", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -32.0, + "max": 32.0 + }, + { + "id": "joint.wheel_fr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rl", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + } + ], + "bounds": { + "min": [ + -0.9778, + 0.0, + -1.5461 + ], + "max": [ + 0.9778, + 1.5457, + 1.705 + ], + "size": [ + 1.9556, + 1.5457, + 3.2511 + ] + }, + "triCount": 16068 +} diff --git a/assets/vehicles/kestrel/kestrel.glb b/assets/vehicles/kestrel/kestrel.glb new file mode 100644 index 0000000..284a261 Binary files /dev/null and b/assets/vehicles/kestrel/kestrel.glb differ diff --git a/assets/vehicles/kestrel/manifest.json b/assets/vehicles/kestrel/manifest.json new file mode 100644 index 0000000..41c8428 --- /dev/null +++ b/assets/vehicles/kestrel/manifest.json @@ -0,0 +1,133 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "kestrel", + "name": "Kestrel", + "class": "Light Scout Biped", + "plane": "Coronal", + "gridWidth": 5, + "gridHeight": 5, + "mask": [ + false, + false, + true, + false, + false, + false, + true, + true, + true, + false, + false, + true, + true, + true, + true, + false, + true, + true, + true, + true, + false, + true, + false, + true, + false + ], + "hardpoints": [ + { + "id": "hp.weapon.dorsal", + "kind": "weapon", + "x": 2, + "y": 0, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.dorsal" + }, + { + "id": "hp.armor.chest", + "kind": "armor", + "x": 2, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.armor.chest" + }, + { + "id": "hp.radiator.back", + "kind": "radiator", + "x": 1, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back" + }, + { + "id": "hp.engine.core", + "kind": "engine", + "x": 2, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.core" + }, + { + "id": "hp.weapon.arm_r", + "kind": "weapon", + "x": 4, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_r" + } + ], + "joints": [ + { + "id": "joint.torso_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -90.0, + "max": 90.0 + }, + { + "id": "joint.arm_l_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 60.0 + }, + { + "id": "joint.arm_r_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 60.0 + } + ], + "bounds": { + "min": [ + -2.6628, + 0.0, + -2.0753 + ], + "max": [ + 2.6048, + 9.7815, + 2.378 + ], + "size": [ + 5.2676, + 9.7815, + 4.4533 + ] + }, + "triCount": 41374 +} diff --git a/assets/vehicles/mammoth/mammoth.glb b/assets/vehicles/mammoth/mammoth.glb new file mode 100644 index 0000000..32427a5 Binary files /dev/null and b/assets/vehicles/mammoth/mammoth.glb differ diff --git a/assets/vehicles/mammoth/manifest.json b/assets/vehicles/mammoth/manifest.json new file mode 100644 index 0000000..c57615a --- /dev/null +++ b/assets/vehicles/mammoth/manifest.json @@ -0,0 +1,259 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "mammoth", + "name": "Mammoth", + "class": "Heavy 8x8 Armored Fire Support Rig", + "plane": "Dorsal", + "gridWidth": 4, + "gridHeight": 6, + "mask": [ + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "hardpoints": [ + { + "id": "hp.armor.glacis", + "kind": "armor", + "x": 0, + "y": 0, + "w": 4, + "h": 1, + "modelNodeId": "hp.armor.glacis" + }, + { + "id": "hp.weapon.bow", + "kind": "weapon", + "x": 0, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.bow" + }, + { + "id": "hp.weapon.turret_l", + "kind": "weapon", + "x": 1, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.turret_l" + }, + { + "id": "hp.weapon.turret_r", + "kind": "weapon", + "x": 2, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.turret_r" + }, + { + "id": "hp.armor.flanks", + "kind": "armor", + "x": 3, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.armor.flanks" + }, + { + "id": "hp.engine.rear", + "kind": "engine", + "x": 1, + "y": 3, + "w": 2, + "h": 2, + "modelNodeId": "hp.engine.rear" + }, + { + "id": "hp.radiator.l", + "kind": "radiator", + "x": 0, + "y": 4, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.l" + }, + { + "id": "hp.radiator.r", + "kind": "radiator", + "x": 3, + "y": 4, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.r" + } + ], + "joints": [ + { + "id": "joint.steer_fl1", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -28.0, + "max": 28.0 + }, + { + "id": "joint.wheel_fl1", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.steer_fr1", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -28.0, + "max": 28.0 + }, + { + "id": "joint.wheel_fr1", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.steer_fl2", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -28.0, + "max": 28.0 + }, + { + "id": "joint.wheel_fl2", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.steer_fr2", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -28.0, + "max": 28.0 + }, + { + "id": "joint.wheel_fr2", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rl1", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rr1", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rl2", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rr2", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.turret_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -180.0, + "max": 180.0 + } + ], + "bounds": { + "min": [ + -1.46, + 0.0, + -2.64 + ], + "max": [ + 1.46, + 2.3467, + 3.2249 + ], + "size": [ + 2.92, + 2.3467, + 5.8649 + ] + }, + "triCount": 20512 +} diff --git a/assets/vehicles/manticore/manifest.json b/assets/vehicles/manticore/manifest.json new file mode 100644 index 0000000..d47831b --- /dev/null +++ b/assets/vehicles/manticore/manifest.json @@ -0,0 +1,171 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "manticore", + "name": "Manticore", + "class": "Heavy Quadruped Scorpion", + "plane": "Dorsal", + "gridWidth": 5, + "gridHeight": 5, + "mask": [ + true, + true, + true, + true, + true, + false, + true, + true, + true, + false, + true, + true, + true, + true, + true, + false, + true, + true, + true, + false, + true, + false, + true, + false, + true + ], + "hardpoints": [ + { + "id": "hp.weapon.chin", + "kind": "weapon", + "x": 2, + "y": 0, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.chin" + }, + { + "id": "hp.radiator.flank_l", + "kind": "radiator", + "x": 1, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.flank_l" + }, + { + "id": "hp.engine.core", + "kind": "engine", + "x": 2, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.core" + }, + { + "id": "hp.radiator.flank_r", + "kind": "radiator", + "x": 3, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.flank_r" + }, + { + "id": "hp.weapon.l", + "kind": "weapon", + "x": 0, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.l" + }, + { + "id": "hp.weapon.r", + "kind": "weapon", + "x": 4, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.r" + }, + { + "id": "hp.armor.prow", + "kind": "armor", + "x": 2, + "y": 3, + "w": 1, + "h": 1, + "modelNodeId": "hp.armor.prow" + } + ], + "joints": [ + { + "id": "joint.tail_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -75.0, + "max": 75.0 + }, + { + "id": "joint.tail_s1", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -60.0, + "max": 60.0 + }, + { + "id": "joint.tail_s2", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -75.0, + "max": 15.0 + }, + { + "id": "joint.tail_s3", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -80.0, + "max": 10.0 + }, + { + "id": "joint.tail_elev", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -40.0, + "max": 30.0 + } + ], + "bounds": { + "min": [ + -3.4374, + 0.0, + -4.5621 + ], + "max": [ + 3.4358, + 6.5001, + 4.547 + ], + "size": [ + 6.8732, + 6.5001, + 9.1091 + ] + }, + "triCount": 33517 +} diff --git a/assets/vehicles/manticore/manticore.glb b/assets/vehicles/manticore/manticore.glb new file mode 100644 index 0000000..57c7313 Binary files /dev/null and b/assets/vehicles/manticore/manticore.glb differ diff --git a/assets/vehicles/mule/manifest.json b/assets/vehicles/mule/manifest.json new file mode 100644 index 0000000..a646428 --- /dev/null +++ b/assets/vehicles/mule/manifest.json @@ -0,0 +1,182 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "mule", + "name": "Mule", + "class": "Medium 6x6 Armored Gun Truck", + "plane": "Dorsal", + "gridWidth": 3, + "gridHeight": 5, + "mask": [ + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true + ], + "hardpoints": [ + { + "id": "hp.armor.front", + "kind": "armor", + "x": 0, + "y": 0, + "w": 3, + "h": 1, + "modelNodeId": "hp.armor.front" + }, + { + "id": "hp.radiator.left", + "kind": "radiator", + "x": 0, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.left" + }, + { + "id": "hp.engine.front", + "kind": "engine", + "x": 1, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.front" + }, + { + "id": "hp.radiator.right", + "kind": "radiator", + "x": 2, + "y": 1, + "w": 1, + "h": 2, + "modelNodeId": "hp.radiator.right" + }, + { + "id": "hp.weapon.cab", + "kind": "weapon", + "x": 0, + "y": 3, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.cab" + }, + { + "id": "hp.weapon.bed_main", + "kind": "weapon", + "x": 1, + "y": 3, + "w": 2, + "h": 2, + "modelNodeId": "hp.weapon.bed_main" + } + ], + "joints": [ + { + "id": "joint.steer_fl", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -30.0, + "max": 30.0 + }, + { + "id": "joint.wheel_fl", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.steer_fr", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -30.0, + "max": 30.0 + }, + { + "id": "joint.wheel_fr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_ml", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_mr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rl", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + }, + { + "id": "joint.wheel_rr", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -360.0, + "max": 360.0 + } + ], + "bounds": { + "min": [ + -1.1938, + 0.0, + -2.4067 + ], + "max": [ + 1.1938, + 2.0889, + 2.46 + ], + "size": [ + 2.3876, + 2.0889, + 4.8667 + ] + }, + "triCount": 13772 +} diff --git a/assets/vehicles/mule/mule.glb b/assets/vehicles/mule/mule.glb new file mode 100644 index 0000000..8f82821 Binary files /dev/null and b/assets/vehicles/mule/mule.glb differ diff --git a/assets/vehicles/paladin/manifest.json b/assets/vehicles/paladin/manifest.json new file mode 100644 index 0000000..dd6df5f --- /dev/null +++ b/assets/vehicles/paladin/manifest.json @@ -0,0 +1,186 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "paladin", + "name": "Paladin", + "class": "Heavy Assault Biped", + "plane": "Coronal", + "gridWidth": 6, + "gridHeight": 7, + "mask": [ + false, + false, + true, + true, + false, + false, + false, + true, + true, + true, + true, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + true, + true, + true, + true, + false, + false, + true, + false, + false, + true, + false, + false, + true, + false, + false, + true, + false + ], + "hardpoints": [ + { + "id": "hp.weapon.sh_l", + "kind": "weapon", + "x": 1, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.sh_l" + }, + { + "id": "hp.armor.torso", + "kind": "armor", + "x": 2, + "y": 1, + "w": 2, + "h": 1, + "modelNodeId": "hp.armor.torso" + }, + { + "id": "hp.weapon.sh_r", + "kind": "weapon", + "x": 4, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.sh_r" + }, + { + "id": "hp.weapon.arm_l", + "kind": "weapon", + "x": 0, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_l" + }, + { + "id": "hp.engine.chest", + "kind": "engine", + "x": 2, + "y": 2, + "w": 2, + "h": 2, + "modelNodeId": "hp.engine.chest" + }, + { + "id": "hp.weapon.arm_r", + "kind": "weapon", + "x": 5, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_r" + }, + { + "id": "hp.radiator.back_l", + "kind": "radiator", + "x": 1, + "y": 4, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back_l" + }, + { + "id": "hp.armor.legs", + "kind": "armor", + "x": 2, + "y": 4, + "w": 2, + "h": 1, + "modelNodeId": "hp.armor.legs" + }, + { + "id": "hp.radiator.back_r", + "kind": "radiator", + "x": 4, + "y": 4, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back_r" + } + ], + "joints": [ + { + "id": "joint.torso_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -90.0, + "max": 90.0 + }, + { + "id": "joint.arm_l_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -40.0, + "max": 70.0 + }, + { + "id": "joint.arm_r_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -40.0, + "max": 70.0 + } + ], + "bounds": { + "min": [ + -4.4388, + -0.0, + -1.5109 + ], + "max": [ + 4.4387, + 11.3161, + 2.4514 + ], + "size": [ + 8.8775, + 11.3161, + 3.9623 + ] + }, + "triCount": 36463 +} diff --git a/assets/vehicles/paladin/paladin.glb b/assets/vehicles/paladin/paladin.glb new file mode 100644 index 0000000..20482ce Binary files /dev/null and b/assets/vehicles/paladin/paladin.glb differ diff --git a/assets/vehicles/raptor/manifest.json b/assets/vehicles/raptor/manifest.json new file mode 100644 index 0000000..29f6590 --- /dev/null +++ b/assets/vehicles/raptor/manifest.json @@ -0,0 +1,128 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "raptor", + "name": "Raptor", + "class": "Medium Theropod Biped", + "plane": "Coronal", + "gridWidth": 5, + "gridHeight": 6, + "mask": [ + false, + false, + true, + false, + false, + false, + true, + true, + true, + false, + true, + true, + true, + true, + true, + true, + false, + true, + false, + true, + false, + true, + false, + true, + false, + false, + true, + false, + true, + false + ], + "hardpoints": [ + { + "id": "hp.radiator.sh_l", + "kind": "radiator", + "x": 1, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.sh_l" + }, + { + "id": "hp.radiator.sh_r", + "kind": "radiator", + "x": 3, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.sh_r" + }, + { + "id": "hp.weapon.arm_l", + "kind": "weapon", + "x": 0, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_l" + }, + { + "id": "hp.engine.chest", + "kind": "engine", + "x": 2, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.chest" + }, + { + "id": "hp.weapon.arm_r", + "kind": "weapon", + "x": 4, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_r" + } + ], + "joints": [ + { + "id": "joint.arm_l_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 45.0 + }, + { + "id": "joint.arm_r_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 45.0 + } + ], + "bounds": { + "min": [ + -2.3822, + 0.0, + -4.422 + ], + "max": [ + 2.3822, + 6.9873, + 4.5553 + ], + "size": [ + 4.7644, + 6.9873, + 8.9773 + ] + }, + "triCount": 36156 +} diff --git a/assets/vehicles/raptor/raptor.glb b/assets/vehicles/raptor/raptor.glb new file mode 100644 index 0000000..36a4b9e Binary files /dev/null and b/assets/vehicles/raptor/raptor.glb differ diff --git a/assets/vehicles/spectre/manifest.json b/assets/vehicles/spectre/manifest.json new file mode 100644 index 0000000..83922ea --- /dev/null +++ b/assets/vehicles/spectre/manifest.json @@ -0,0 +1,156 @@ +{ + "schema": "rtd.vehicle.manifest.v1", + "id": "spectre", + "name": "Spectre", + "class": "Medium Recon/Skirmisher Biped", + "plane": "Coronal", + "gridWidth": 5, + "gridHeight": 6, + "mask": [ + false, + true, + false, + false, + false, + false, + true, + true, + true, + false, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + false, + true, + false, + true, + false, + false, + true, + false, + true, + false + ], + "hardpoints": [ + { + "id": "hp.weapon.shoulder_l", + "kind": "weapon", + "x": 1, + "y": 0, + "w": 1, + "h": 1, + "modelNodeId": "hp.weapon.shoulder_l" + }, + { + "id": "hp.armor.torso", + "kind": "armor", + "x": 2, + "y": 1, + "w": 1, + "h": 1, + "modelNodeId": "hp.armor.torso" + }, + { + "id": "hp.weapon.arm_l", + "kind": "weapon", + "x": 0, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_l" + }, + { + "id": "hp.radiator.back_l", + "kind": "radiator", + "x": 1, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back_l" + }, + { + "id": "hp.engine.core", + "kind": "engine", + "x": 2, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.engine.core" + }, + { + "id": "hp.radiator.back_r", + "kind": "radiator", + "x": 3, + "y": 2, + "w": 1, + "h": 1, + "modelNodeId": "hp.radiator.back_r" + }, + { + "id": "hp.weapon.arm_r", + "kind": "weapon", + "x": 4, + "y": 2, + "w": 1, + "h": 2, + "modelNodeId": "hp.weapon.arm_r" + } + ], + "joints": [ + { + "id": "joint.torso_yaw", + "axis": [ + 0.0, + 1.0, + 0.0 + ], + "min": -90.0, + "max": 90.0 + }, + { + "id": "joint.arm_l_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 60.0 + }, + { + "id": "joint.arm_r_pitch", + "axis": [ + 1.0, + 0.0, + 0.0 + ], + "min": -45.0, + "max": 60.0 + } + ], + "bounds": { + "min": [ + -3.4467, + -0.0, + -2.442 + ], + "max": [ + 3.8332, + 8.9891, + 3.6426 + ], + "size": [ + 7.2799, + 8.9891, + 6.0846 + ] + }, + "triCount": 40696 +} diff --git a/assets/vehicles/spectre/spectre.glb b/assets/vehicles/spectre/spectre.glb new file mode 100644 index 0000000..112cd17 Binary files /dev/null and b/assets/vehicles/spectre/spectre.glb differ diff --git a/tools/vehicles/build_anvil.py b/tools/vehicles/build_anvil.py new file mode 100644 index 0000000..871f408 --- /dev/null +++ b/tools/vehicles/build_anvil.py @@ -0,0 +1,468 @@ +"""Build the Anvil (Heavy Quad-Track Siege Tank) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def _build_quad_track_pod(name: str, side: float, y_center: float, is_front: bool, parent) -> None: + """Build one heavy articulated armored quad-track pod grounded at Z = 0.""" + pod_x = side * 1.56 + pod = vc.make_empty(name, parent=parent, location=(pod_x, y_center, 0.0)) + + rw_r = 0.27 + rw_z = rw_r + 0.045 + rw_ys = (-0.54, 0.0, 0.54) + front_y, front_z, front_r = -0.98, 0.54, 0.24 + rear_y, rear_z, rear_r = 0.98, 0.54, 0.24 + track_w = 0.62 + + # 3 roadwheels + front/rear sprockets + for i, ry in enumerate(rw_ys): + vc.make_tube_part( + f"{name}_rw_tire_{i}", rw_r, rw_r, track_w * 0.84, segments=14, + mat_name="rubber_dark", parent=pod, location=(-track_w * 0.42, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_rw_hub_{i}", rw_r * 0.64, rw_r * 0.64, track_w * 0.90, segments=10, + mat_name="olive_armor", parent=pod, location=(-track_w * 0.45, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_sproc_f", front_r, front_r, track_w * 0.80, segments=12, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.40, front_y, front_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_sproc_r", rear_r, rear_r, track_w * 0.80, segments=12, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.40, rear_y, rear_z), rotation_deg=(0.0, 90.0, 0.0), + ) + + # Track loop polyline in (y, z) + loop_yz: list[tuple[float, float]] = [] + for k in range(6): + ang = math.radians(100.0 + 135.0 * (k / 5.0)) + loop_yz.append((front_y + math.cos(ang) * (front_r + 0.03), front_z + math.sin(ang) * (front_r + 0.03))) + loop_yz.append((-0.54, 0.025)) + loop_yz.append((0.54, 0.025)) + for k in range(6): + ang = math.radians(-55.0 + 135.0 * (k / 5.0)) + loop_yz.append((rear_y + math.cos(ang) * (rear_r + 0.03), rear_z + math.sin(ang) * (rear_r + 0.03))) + loop_yz.append((0.46, 0.83)) + loop_yz.append((-0.46, 0.83)) + + path_3d = [[0.0, y, z] for (y, z) in loop_yz] + vc.make_swept_profile( + f"{name}_track_band", + "box", + 0.034, + track_w * 0.92, + 0.034, + path_3d, + up=[1.0, 0.0, 0.0], + mat_name="rubber_dark", + parent=pod, + closed=True, + ) + + pts = loop_yz + [loop_yz[0]] + segs = [math.hypot(pts[i + 1][0] - pts[i][0], pts[i + 1][1] - pts[i][1]) for i in range(len(loop_yz))] + total_len = sum(segs) + n_shoes = 28 + + def build_shoes(bm: bmesh.types.BMesh) -> None: + for s_idx in range(n_shoes): + target_d = (s_idx / n_shoes) * total_len + acc = 0.0 + for i, sl in enumerate(segs): + if acc + sl >= target_d or i == len(segs) - 1: + t = (target_d - acc) / max(sl, 1e-6) + y0, z0 = pts[i] + y1, z1 = pts[i + 1] + py = y0 + (y1 - y0) * t + pz = z0 + (z1 - z0) * t + ang = math.atan2(z1 - z0, y1 - y0) + m = ( + Matrix.Translation((0.0, py, pz)) + @ Matrix.Rotation(ang, 4, "X") + @ Matrix.Diagonal((track_w, 0.11, 0.034, 1.0)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + break + acc += sl + + vc.make_bmesh_object(f"{name}_shoes", build_shoes, "gunmetal", parent=pod) + + # Heavy sloped armored pod housing (top deck + chamfered nose/tail + outer bolted side skirts) + vc.make_box(f"{name}_cover_top", (track_w + 0.12, 1.98, 0.14), "olive_armor", parent=pod, location=(0.0, 0.0, 0.92), bevel=0.012) + vc.make_box(f"{name}_cover_f", (track_w + 0.12, 0.42, 0.14), "olive_armor", parent=pod, location=(0.0, -1.14, 0.80), rotation_deg=(36.0, 0.0, 0.0), bevel=0.01) + vc.make_box(f"{name}_cover_r", (track_w + 0.12, 0.42, 0.14), "olive_armor", parent=pod, location=(0.0, 1.14, 0.80), rotation_deg=(-36.0, 0.0, 0.0), bevel=0.01) + # Outer bolted track pod side skirt + skirt_pts = [ + [side * (track_w * 0.5 + 0.04), -1.12, 0.72], + [side * (track_w * 0.5 + 0.04), 1.12, 0.72], + [side * (track_w * 0.5 + 0.04), 0.98, 0.94], + [side * (track_w * 0.5 + 0.04), -0.98, 0.94], + [side * (track_w * 0.5 + 0.04), -0.74, 0.34], + [side * (track_w * 0.5 + 0.04), 0.74, 0.34], + [side * (track_w * 0.5 + 0.04), 1.12, 0.56], + [side * (track_w * 0.5 + 0.04), -1.12, 0.56], + ] + # Use clean trapezoidal slab for outer pod skirt with bolts + vc.make_plates( + { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": f"{name}_outer_skirt", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "one", + "mirror": False, + "slab": { + "at": [side * (track_w * 0.5 + 0.04), 0.0, 0.64], + "normal": [side, 0.0, 0.0], + "up": [0.0, 0.0, 1.0], + "right": [0.0, -side, 0.0], + "outline": [[-1.08, -0.08], [-0.74, -0.32], [0.74, -0.32], [1.08, -0.08], [0.96, 0.28], [-0.96, 0.28]], + "thick": 0.055, + "taper": 0.012, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.025, "spacing": 0.34, "mat": "gunmetal", "params": "r=0.014"}, + ], + } + ], + }, + parent=pod, + ) + # Inner pod cheek & front headlight block + vc.make_box(f"{name}_inner_cheek", (0.06, 1.84, 0.48), "gunmetal", parent=pod, location=(-side * (track_w * 0.5 + 0.02), 0.0, 0.64), bevel=0.008) + if is_front: + vc.make_box(f"{name}_headlight_pod", (0.28, 0.20, 0.14), "gunmetal", parent=pod, location=(0.0, -1.04, 1.00), bevel=0.008) + vc.make_box(f"{name}_headlight_lens", (0.20, 0.05, 0.08), "smoked_glass", parent=pod, location=(0.0, -1.14, 1.00), bevel=0.004) + + +def build_anvil() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("AnvilRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # --- 1. Central Lower Belly Tub, Ribbed Prow & Pod Outrigger Beams --- + vc.make_box("lower_tub", (2.14, 4.78, 0.64), "gunmetal", parent=chassis, location=(0.0, 0.04, 0.74), bevel=0.016) + # Corrugated lower prow armor ribs + vc.make_box("lower_prow_plate", (2.06, 0.44, 0.52), "olive_armor", parent=chassis, location=(0.0, -2.32, 0.74), rotation_deg=(24.0, 0.0, 0.0), bevel=0.012) + for rx in (-0.84, -0.56, -0.28, 0.0, 0.28, 0.56, 0.84): + vc.make_box(f"prow_rib_{rx:.2f}", (0.08, 0.14, 0.48), "gunmetal", parent=chassis, location=(rx, -2.50, 0.72), rotation_deg=(24.0, 0.0, 0.0), bevel=0.006) + # Outrigger pod axle beams + suspension rams + for p_tag, py in (("f", -1.48), ("r", 1.48)): + vc.make_box(f"pod_crossbeam_{p_tag}", (3.08, 0.58, 0.32), "gunmetal", parent=chassis, location=(0.0, py, 0.62), bevel=0.012) + for side in (-1.0, 1.0): + s_tag = "L" if side > 0 else "R" + vc.make_ram_span( + f"pod_strut_{p_tag}_{s_tag}", + [side * 1.04, py, 1.02], + [side * 1.38, py, 0.74], + body_r=0.048, + rod_r=0.026, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + + # --- 2. Wide Sloped Composite Hull & Tall Casemate Superstructure (Brokkr plate.v0) --- + hull_pts = [ + # Lower hull belt above track pods + [-1.18, -2.38, 0.96], [1.18, -2.38, 0.96], + [-1.22, -0.50, 1.02], [1.22, -0.50, 1.02], + [-1.22, 2.58, 1.02], [1.22, 2.58, 1.02], + # Tall casemate roof (y = -0.48 .. +1.28, z = 1.98) + [-1.16, -0.48, 1.98], [1.16, -0.48, 1.98], + [-1.18, 1.28, 1.98], [1.18, 1.28, 1.98], + # Stepped rear engine deck (y = +1.30 .. +2.64, z = 1.70) + [-1.18, 1.32, 1.70], [1.18, 1.32, 1.70], + [-1.14, 2.64, 1.68], [1.14, 2.64, 1.68], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "anvil_hull", + "mat": "olive_armor", + "bevel": 0.016, + "sides": "one", + "mirror": False, + "points": hull_pts, + "clad": { + "mat": "olive_armor", + "facets": [{"n": [0.0, -0.45, 0.89], "cos": 0.86}], + "min_area": 0.22, + "lifts": [0.008, 0.015], + "inset": 0.07, + "gap": 0.020, + "split": 0.88, + "seed": 901, + "bolt_r": 0.014, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + }, + # Heavy bolted forward superstructure cheek plates + { + "name": "anvil_casemate_cheek", + "mat": "olive_armor", + "bevel": 0.010, + "sides": "both", + "mirror": False, + "slab": { + "at": [1.20, 0.42, 1.54], + "normal": [1.0, 0.0, 0.0], + "up": [0.0, 0.0, 1.0], + "right": [0.0, -1.0, 0.0], + "outline": [[-0.86, -0.34], [0.86, -0.34], [0.78, 0.36], [-0.52, 0.36]], + "thick": 0.055, + "taper": 0.014, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.03, "spacing": 0.34, "mat": "gunmetal", "params": "r=0.014"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Sponson weapon shelves (left/right forward flanks) + rear radiator housing + driver periscope + vc.make_box("driver_periscope", (0.58, 0.18, 0.11), "smoked_glass", parent=chassis, location=(0.0, -0.78, 1.84), rotation_deg=(-24.0, 0.0, 0.0), bevel=0.006) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"sponson_shelf_{tag}", (0.48, 0.72, 0.24), "gunmetal", parent=chassis, location=(side * 1.24, -0.76, 1.42), bevel=0.01) + vc.make_box(f"rad_housing_{tag}", (0.16, 1.18, 0.62), "olive_armor", parent=chassis, location=(side * 1.20, 1.50, 1.42), bevel=0.01) + vc.make_box(f"tow_shackle_{tag}", (0.09, 0.16, 0.16), "signal_orange", parent=chassis, location=(side * 0.68, -2.54, 0.64), bevel=0.006) + + # --- 3. 4 Articulated Quad-Track Pods --- + _build_quad_track_pod("pod_fl", 1.0, -1.48, True, chassis) + _build_quad_track_pod("pod_fr", -1.0, -1.48, True, chassis) + _build_quad_track_pod("pod_rl", 1.0, 1.48, False, chassis) + _build_quad_track_pod("pod_rr", -1.0, 1.48, False, chassis) + + # --- 4. Towering Rear Exhaust Stacks --- + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + for s_idx, sy in enumerate((2.40, 2.62)): + vc.make_swept_tube( + f"exhaust_stack_{tag}_{s_idx}", + [ + [side * 0.96, sy - 0.14, 1.48], + [side * 1.04, sy, 1.66], + [side * 1.04, sy, 2.86], + [side * 1.04, sy + 0.14, 2.98], + ], + 0.072, + segments=12, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.06, + ) + vc.make_tube_part( + f"exhaust_shroud_{tag}_{s_idx}", + 0.105, + 0.105, + 0.68, + segments=10, + inner0=0.09, + inner1=0.09, + mat_name="olive_armor", + parent=chassis, + location=(side * 1.04, sy, 1.76), + ) + + # --- 5. Broad Reinforced Siege Turret (joint.turret_yaw) --- + turret_pivot = vc.make_empty("joint.turret_yaw", parent=chassis, location=(0.0, 0.04, 1.98)) + vc.tag_joint(turret_pivot, "joint.turret_yaw", [0.0, 1.0, 0.0], -180.0, 180.0) + joints_manifest = [{"id": "joint.turret_yaw", "axis": [0.0, 1.0, 0.0], "min": -180.0, "max": 180.0}] + + vc.make_tube_part("turret_race", 0.88, 0.94, 0.10, segments=24, mat_name="gunmetal", parent=turret_pivot) + + turret_pts = [ + [-0.76, -0.92, 0.10], [0.76, -0.92, 0.10], + [0.98, -0.22, 0.10], [0.88, 1.04, 0.10], + [-0.88, 1.04, 0.10], [-0.98, -0.22, 0.10], + [-0.58, -0.70, 0.62], [0.58, -0.70, 0.62], + [0.76, -0.14, 0.62], [0.68, 0.86, 0.62], + [-0.68, 0.86, 0.62], [-0.76, -0.14, 0.62], + ] + turret_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "anvil_turret_shell", + "mat": "olive_armor", + "bevel": 0.016, + "sides": "one", + "mirror": False, + "points": turret_pts, + }, + { + "name": "anvil_turret_cheek", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.86, 0.16, 0.34], + "normal": [0.94, 0.0, 0.34], + "up": [-0.34, 0.0, 0.94], + "right": [0.0, -1.0, 0.0], + "outline": [[-0.58, -0.18], [0.58, -0.18], [0.46, 0.18], [-0.46, 0.18]], + "thick": 0.055, + "taper": 0.014, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.025, "spacing": 0.26, "mat": "gunmetal", "params": "r=0.013"}, + ], + }, + ], + } + vc.make_plates(turret_doc, parent=turret_pivot) + + vc.make_box("turret_mantlet_bar", (1.12, 0.22, 0.24), "gunmetal", parent=turret_pivot, location=(0.0, -0.84, 0.34), bevel=0.012) + vc.make_box("turret_bustle", (1.28, 0.46, 0.38), "olive_armor", parent=turret_pivot, location=(0.0, 1.10, 0.38), bevel=0.012) + vc.make_tube_part("commander_cupola", 0.22, 0.24, 0.11, segments=14, mat_name="olive_armor", parent=turret_pivot, location=(0.0, 0.48, 0.62)) + vc.make_box("turret_optic", (0.20, 0.22, 0.16), "smoked_glass", parent=turret_pivot, location=(0.0, -0.46, 0.68), bevel=0.008) + + # --- 6. Visible Exterior Hardpoints (5x6 Dorsal Grid) --- + # 1) hp.armor.front (0,0, 5x1) on steep front glacis + vc.add_hardpoint_slot( + "hp.armor.front", + "armor", + parent=chassis, + location=(0.0, -1.48, 1.46), + 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( + "hp.weapon.sponson_l", + "weapon", + parent=chassis, + location=(1.26, -0.76, 1.54), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.50, 0.50, 0.09), + ) + vc.add_hardpoint_slot( + "hp.weapon.sponson_r", + "weapon", + parent=chassis, + location=(-1.26, -0.76, 1.54), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.50, 0.50, 0.09), + ) + # 4 & 5) hp.weapon.siege_l (1,1, 1x2) & hp.weapon.siege_r (3,1, 1x2) on turret roof + vc.add_hardpoint_slot( + "hp.weapon.siege_l", + "weapon", + parent=turret_pivot, + location=(0.42, -0.04, 0.63), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.62, 0.62, 0.11), + ) + vc.add_hardpoint_slot( + "hp.weapon.siege_r", + "weapon", + parent=turret_pivot, + location=(-0.42, -0.04, 0.63), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.62, 0.62, 0.11), + ) + # 6) hp.armor.sides (2,1, 1x2) on right (-X) casemate cheek + vc.add_hardpoint_slot( + "hp.armor.sides", + "armor", + parent=chassis, + 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) 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.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( + "hp.radiator.l", + "radiator", + parent=chassis, + location=(1.28, 1.50, 1.42), + rotation_deg=(90.0, 0.0, 90.0), + size=(1.04, 0.52, 0.13), + ) + vc.add_hardpoint_slot( + "hp.radiator.r", + "radiator", + parent=chassis, + location=(-1.28, 1.50, 1.42), + rotation_deg=(90.0, 0.0, -90.0), + size=(1.04, 0.52, 0.13), + ) + + # --- 7. Export GLB, Manifest & Preview --- + glb_path = vc.ASSETS_VEHICLES_DIR / "anvil" / "anvil.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "anvil" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "anvil_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="anvil", + name="Anvil", + vehicle_class="Heavy Quad-Track Siege Tank", + grid_width=5, + grid_height=6, + mask=[ + "#####", + "#####", + "#####", + "#####", + "#####", + "#####", + ], + hardpoints=[ + {"id": "hp.armor.front", "kind": "armor", "x": 0, "y": 0, "w": 5, "h": 1, "modelNodeId": "hp.armor.front"}, + {"id": "hp.weapon.sponson_l", "kind": "weapon", "x": 0, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.sponson_l"}, + {"id": "hp.weapon.siege_l", "kind": "weapon", "x": 1, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.siege_l"}, + {"id": "hp.armor.sides", "kind": "armor", "x": 2, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.armor.sides"}, + {"id": "hp.weapon.siege_r", "kind": "weapon", "x": 3, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.siege_r"}, + {"id": "hp.weapon.sponson_r", "kind": "weapon", "x": 4, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.sponson_r"}, + {"id": "hp.engine.rear", "kind": "engine", "x": 1, "y": 3, "w": 3, "h": 2, "modelNodeId": "hp.engine.rear"}, + {"id": "hp.radiator.l", "kind": "radiator", "x": 0, "y": 4, "w": 1, "h": 2, "modelNodeId": "hp.radiator.l"}, + {"id": "hp.radiator.r", "kind": "radiator", "x": 4, "y": 4, "w": 1, "h": 2, "modelNodeId": "hp.radiator.r"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[anvil] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "anvil", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_anvil() diff --git a/tools/vehicles/build_condor.py b/tools/vehicles/build_condor.py new file mode 100644 index 0000000..b6d3e67 --- /dev/null +++ b/tools/vehicles/build_condor.py @@ -0,0 +1,508 @@ +"""Build the Condor (Heavy Quad-Thruster Assault VTOL) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def _build_jet_nacelle( + name: str, + joint_id: str, + rotor_id: str, + side: float, + location: tuple[float, float, float], + scale: float, + tilt_deg: float, + parent, + joints_manifest: list[dict], +) -> None: + """Build a pivoting vectored-thrust armored jet nacelle with copper exhaust skirt and spinning turbine.""" + nacelle_pivot = vc.make_empty( + joint_id, + parent=parent, + location=location, + rotation_deg=(tilt_deg, 0.0, 0.0), + ) + vc.tag_joint(nacelle_pivot, joint_id, [1.0, 0.0, 0.0], -45.0, 75.0) + joints_manifest.append({"id": joint_id, "axis": [1.0, 0.0, 0.0], "min": -45.0, "max": 75.0}) + + r_in = 0.31 * scale + r_out = 0.43 * scale + # Armored olive intake shroud + jet housing + shroud_prof = [ + [r_in, -0.18 * scale], + [r_out * 0.96, -0.18 * scale], + [r_out * 1.05, 0.02 * scale], + [r_out * 1.05, 0.34 * scale], + [r_out * 0.92, 0.44 * scale], + [r_in * 1.02, 0.44 * scale], + [r_in * 0.96, 0.26 * scale], + [r_in, -0.18 * scale], + ] + vc.make_lathe_part( + f"{name}_shroud", + shroud_prof[:-1], + segments=20, + loop=True, + smooth=True, + mat_name="olive_armor", + parent=nacelle_pivot, + ) + # Vectored copper thermal exhaust nozzle petals + nozzle_prof = [ + [r_in * 0.92, -0.44 * scale], + [r_out * 0.86, -0.44 * scale], + [r_out * 0.96, -0.18 * scale], + [r_in, -0.18 * scale], + ] + vc.make_lathe_part( + f"{name}_nozzle", + nozzle_prof, + segments=20, + loop=True, + smooth=True, + mat_name="copper_rad", + parent=nacelle_pivot, + ) + # Inner gunmetal stator vanes + outer hinge trunnion lug + for ang_deg in (0.0, 90.0): + vc.make_box( + f"{name}_stator_{int(ang_deg)}", + (r_in * 1.92, 0.04 * scale, 0.06 * scale), + "gunmetal", + parent=nacelle_pivot, + location=(0.0, 0.0, -0.16 * scale), + rotation_deg=(0.0, 0.0, ang_deg), + bevel=0.004, + ) + vc.make_box( + f"{name}_trunnion_lug", + (0.18 * scale, 0.28 * scale, 0.20 * scale), + "gunmetal", + parent=nacelle_pivot, + location=(-side * (r_out * 0.98), 0.0, 0.12 * scale), + bevel=0.008, + ) + + # Spinning axial turbine rotor + rotor_pivot = vc.make_empty(rotor_id, parent=nacelle_pivot, location=(0.0, 0.0, 0.14 * scale)) + vc.tag_joint(rotor_pivot, rotor_id, [0.0, 1.0, 0.0], -360.0, 360.0) + joints_manifest.append({"id": rotor_id, "axis": [0.0, 1.0, 0.0], "min": -360.0, "max": 360.0}) + + spinner_prof = [ + [0.0, -0.06 * scale], + [0.11 * scale, -0.06 * scale], + [0.11 * scale, 0.08 * scale], + [0.06 * scale, 0.22 * scale], + [0.0, 0.30 * scale], + ] + vc.make_lathe_part(f"{name}_spinner", spinner_prof, segments=12, loop=False, smooth=True, mat_name="gunmetal", parent=rotor_pivot) + + def build_blades(bm: bmesh.types.BMesh) -> None: + for i in range(6): + a = i * math.pi / 3.0 + m = ( + Matrix.Rotation(a, 4, "Z") + @ Matrix.Translation((0.19 * scale, 0.0, 0.02 * scale)) + @ Matrix.Rotation(math.radians(26.0), 4, "X") + @ Matrix.Diagonal((0.20 * scale, 0.072 * scale, 0.014 * scale, 1.0)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + + vc.make_bmesh_object(f"{name}_blades", build_blades, "gunmetal", parent=rotor_pivot) + + +def build_condor() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("CondorRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # --- 1. 4 Stubby Hydraulic Landing Legs (grounded at Z = 0) --- + # Front twin nose/cheek wheel-legs at y = -1.56, x = +/- 0.42 + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_ram_span( + f"gear_front_strut_{tag}", + [side * 0.34, -1.52, 0.64], + [side * 0.44, -1.60, 0.16], + body_r=0.052, + rod_r=0.030, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + vc.make_ram_span( + f"gear_front_drag_{tag}", + [side * 0.30, -1.16, 0.58], + [side * 0.44, -1.58, 0.18], + body_r=0.030, + rod_r=0.018, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="gunmetal", + ) + vc.make_knobby_wheel( + f"gear_front_wheel_{tag}", + radius=0.16, + width=0.14, + parent=chassis, + location=(side * 0.46, -1.60, 0.16), + tread_lugs=10, + rim_segments=12, + side_sign=int(side), + ) + # Rear splayed outrigger hydraulic legs with armored ski-pads at y = +1.08 + vc.make_box(f"gear_rear_sponson_{tag}", (0.26, 0.46, 0.24), "olive_armor", parent=chassis, location=(side * 0.78, 1.06, 0.68), bevel=0.01) + vc.make_ram_span( + f"gear_rear_strut_{tag}", + [side * 0.78, 1.06, 0.64], + [side * 1.04, 1.08, 0.08], + body_r=0.058, + rod_r=0.032, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + vc.make_ram_span( + f"gear_rear_brace_{tag}", + [side * 0.62, 0.68, 0.56], + [side * 1.02, 1.06, 0.10], + body_r=0.032, + rod_r=0.020, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="gunmetal", + ) + # Articulated ski-pad foot + small bogie wheel grounded at Z = 0 + vc.make_box(f"gear_rear_ski_{tag}", (0.26, 0.66, 0.055), "gunmetal", parent=chassis, location=(side * 1.04, 1.08, 0.028), bevel=0.008) + vc.make_box(f"gear_rear_ski_tip_{tag}", (0.26, 0.16, 0.055), "gunmetal", parent=chassis, location=(side * 1.04, 0.72, 0.065), rotation_deg=(28.0, 0.0, 0.0), bevel=0.006) + + # --- 2. Brutalist Angular Bolted Fuselage & Canopy (Brokkr plate.v0) --- + hull_pts = [ + # Nose prow (y = -2.78) + [-0.38, -2.78, 0.84], [0.38, -2.78, 0.84], + [-0.44, -2.72, 1.06], [0.44, -2.72, 1.06], + # Forward cabin shoulder (y = -1.54) + [-0.78, -1.54, 0.56], [0.78, -1.54, 0.56], + [-0.86, -1.42, 1.24], [0.86, -1.42, 1.24], + [-0.58, -1.24, 1.62], [0.58, -1.24, 1.62], + # Mid troop bay (y = +1.12) + [-0.78, 1.12, 0.56], [0.78, 1.12, 0.56], + [-0.88, 1.12, 1.28], [0.88, 1.12, 1.28], + [-0.64, 1.12, 1.66], [0.64, 1.12, 1.66], + # Tapered rear tail boom (y = +2.78) + [-0.36, 2.78, 1.08], [0.36, 2.78, 1.08], + [-0.38, 2.78, 1.48], [0.38, 2.78, 1.48], + ] + canopy_pts = [ + [-0.42, -2.42, 1.06], [0.42, -2.42, 1.06], + [-0.56, -1.36, 1.26], [0.56, -1.36, 1.26], + [-0.48, -1.20, 1.66], [0.48, -1.20, 1.66], + [-0.40, -1.86, 1.62], [0.40, -1.86, 1.62], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "condor_fuselage", + "mat": "olive_armor", + "bevel": 0.016, + "sides": "one", + "mirror": False, + "points": hull_pts, + }, + { + "name": "condor_canopy", + "mat": "smoked_glass", + "bevel": 0.008, + "sides": "one", + "mirror": False, + "points": canopy_pts, + }, + # Bolted side troop-bay armor plates + crew doors + { + "name": "condor_flank_armor", + "mat": "olive_armor", + "bevel": 0.010, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.86, -0.14, 0.94], + "normal": [0.98, 0.0, -0.18], + "up": [0.18, 0.0, 0.98], + "right": [0.0, -1.0, 0.0], + "outline": [[-1.18, -0.32], [1.18, -0.32], [1.08, 0.34], [-1.08, 0.34]], + "thick": 0.05, + "taper": 0.014, + "back": 0.92, + }, + "clad": { + "mat": "olive_armor", + "facets": "outer", + "min_area": 0.14, + "lifts": [0.008, 0.014], + "inset": 0.05, + "gap": 0.016, + "split": 0.72, + "seed": 1001, + "bolt_r": 0.013, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + "fits": [ + {"kind": "bolts", "inset": 0.025, "spacing": 0.34, "mat": "gunmetal", "params": "r=0.013"}, + {"kind": "part", "part": "handle", "at": [0.32, 0.02], "roll": 0.0, "mat": "gunmetal", "params": "length=0.22;lift=0.045;r=0.012"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Canopy structural armor ribs + dorsal radiator spine housing + rear APU jet nozzle + V-tail stabilizers + vc.make_swept_tube( + "canopy_spine", + [[0.0, -2.44, 1.06], [0.0, -1.86, 1.64], [0.0, -1.18, 1.68]], + 0.028, segments=6, mat_name="olive_armor", parent=chassis, fillet_r=0.04, + ) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_swept_tube( + f"canopy_rib_{tag}", + [[side * 0.40, -2.40, 1.06], [side * 0.42, -1.84, 1.62], [side * 0.48, -1.20, 1.66]], + 0.022, segments=6, mat_name="olive_armor", parent=chassis, fillet_r=0.04, + ) + # Side weapon sponson boxes on forward cheek flanks + vc.make_box(f"weapon_sponson_box_{tag}", (0.24, 0.76, 0.36), "olive_armor", parent=chassis, location=(side * 0.92, -1.16, 0.96), bevel=0.01) + # Fore nacelle shoulder sponsons (y = -0.86) + vc.make_box(f"fore_wing_{tag}", (0.64, 0.44, 0.22), "olive_armor", parent=chassis, location=(side * 0.86, -0.86, 1.48), rotation_deg=(0.0, side * -6.0, 0.0), bevel=0.012) + # Aft main high-mounted swept wings (y = +0.74) + vc.make_box(f"aft_wing_{tag}", (1.06, 0.72, 0.22), "olive_armor", parent=chassis, location=(side * 1.18, 0.74, 1.60), rotation_deg=(0.0, side * -5.0, side * -8.0), bevel=0.014) + # Tilt actuator rams for fore & aft nacelles + vc.make_ram_span( + f"tilt_ram_f_{tag}", + [side * 0.68, -1.04, 1.54], + [side * 1.06, -0.86, 1.50], + body_r=0.032, + rod_r=0.018, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + vc.make_ram_span( + f"tilt_ram_r_{tag}", + [side * 1.18, 0.50, 1.68], + [side * 1.56, 0.74, 1.66], + body_r=0.038, + rod_r=0.020, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + # Canted twin tail stabilizers + ventral strakes + vc.make_box( + f"tail_fin_{tag}", + (0.06, 0.66, 0.94), + "olive_armor", + parent=chassis, + location=(side * 0.56, 2.58, 1.72), + rotation_deg=(24.0, side * -32.0, 0.0), + bevel=0.01, + ) + vc.make_box( + f"tail_horiz_{tag}", + (0.46, 0.54, 0.07), + "olive_armor", + parent=chassis, + location=(side * 0.44, 2.54, 1.34), + rotation_deg=(0.0, side * 10.0, side * -12.0), + bevel=0.008, + ) + + # Dorsal radiator spine ridge (runs behind canopy to tail root) + vc.make_box("dorsal_spine_core", (0.78, 2.48, 0.26), "olive_armor", parent=chassis, location=(0.0, 0.28, 1.70), bevel=0.014) + vc.make_box("dorsal_spine_cap", (0.48, 2.38, 0.14), "gunmetal", parent=chassis, location=(0.0, 0.28, 1.84), bevel=0.01) + + # Rear tail APU / main jet exhaust cone + rear_nozzle_prof = [ + [0.18, 0.0], + [0.27, 0.0], + [0.29, 0.18], + [0.24, 0.36], + [0.16, 0.36], + [0.18, 0.0], + ] + vc.make_lathe_part( + "rear_jet_nozzle", + rear_nozzle_prof[:-1], + segments=18, + loop=True, + smooth=True, + mat_name="copper_rad", + parent=chassis, + location=(0.0, 2.74, 1.28), + rotation_deg=(-90.0, 0.0, 0.0), + ) + + # --- 3. 4 Pivoting Vectored-Thrust Jet Nacelles (joint.nacelle_fl/fr/rl/rr) --- + joints_manifest: list[dict] = [] + # Fore nacelles + for side, j_tag in ((1.0, "fl"), (-1.0, "fr")): + _build_jet_nacelle( + f"nacelle_{j_tag}", + f"joint.nacelle_{j_tag}", + f"joint.rotor_{j_tag}", + side, + location=(side * 1.42, -0.86, 1.48), + scale=0.82, + tilt_deg=-16.0, + parent=chassis, + joints_manifest=joints_manifest, + ) + # Aft main nacelles (larger vectored jet pods) + for side, j_tag in ((1.0, "rl"), (-1.0, "rr")): + _build_jet_nacelle( + f"nacelle_{j_tag}", + f"joint.nacelle_{j_tag}", + f"joint.rotor_{j_tag}", + side, + location=(side * 1.88, 0.74, 1.62), + scale=1.06, + tilt_deg=-14.0, + parent=chassis, + joints_manifest=joints_manifest, + ) + + # --- 4. Heavy Nose Chin Turret (joint.turret_yaw) --- + turret_pivot = vc.make_empty("joint.turret_yaw", parent=chassis, location=(0.0, -2.26, 0.74)) + vc.tag_joint(turret_pivot, "joint.turret_yaw", [0.0, 1.0, 0.0], -180.0, 180.0) + joints_manifest.append({"id": "joint.turret_yaw", "axis": [0.0, 1.0, 0.0], "min": -180.0, "max": 180.0}) + + vc.make_tube_part("chin_turret_ring", 0.28, 0.30, 0.10, segments=16, mat_name="gunmetal", parent=turret_pivot, location=(0.0, 0.0, -0.04)) + vc.make_box("chin_turret_housing", (0.44, 0.48, 0.22), "olive_armor", parent=turret_pivot, location=(0.0, 0.0, -0.14), bevel=0.012) + vc.make_box("chin_optics", (0.20, 0.10, 0.10), "smoked_glass", parent=turret_pivot, location=(0.0, -0.24, -0.10), bevel=0.005) + + # --- 5. Visible Exterior Hardpoints (5x6 Masked Dorsal Grid) --- + # 1) hp.weapon.nose (1,0, 2x1) under chin turret + vc.add_hardpoint_slot( + "hp.weapon.nose", + "weapon", + parent=turret_pivot, + location=(0.0, 0.0, -0.25), + rotation_deg=(0.0, 180.0, 0.0), + size=(0.46, 0.46, 0.08), + ) + # 2) hp.armor.hull (3,0, 1x1) on sloped upper nose glacis in front of canopy + vc.add_hardpoint_slot( + "hp.armor.hull", + "armor", + parent=chassis, + location=(0.0, -2.56, 1.13), + 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( + "hp.weapon.sponson_l", + "weapon", + parent=chassis, + location=(1.04, -1.16, 0.96), + rotation_deg=(0.0, 90.0, 0.0), + size=(0.44, 0.44, 0.08), + ) + vc.add_hardpoint_slot( + "hp.weapon.sponson_r", + "weapon", + parent=chassis, + location=(-1.04, -1.16, 0.96), + rotation_deg=(0.0, -90.0, 0.0), + size=(0.44, 0.44, 0.08), + ) + # 5) hp.weapon.dorsal (2,1, 1x1) on forward dorsal spine behind cockpit + vc.add_hardpoint_slot( + "hp.weapon.dorsal", + "weapon", + parent=chassis, + location=(0.0, -0.78, 1.91), + 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 (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.89), + rotation_deg=(0.0, 0.0, 0.0), + 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( + "hp.radiator.spine_l", + "radiator", + parent=chassis, + location=(0.56, 1.02, 1.68), + rotation_deg=(0.0, 56.0, 0.0), + size=(0.40, 1.04, 0.11), + ) + vc.add_hardpoint_slot( + "hp.radiator.spine_r", + "radiator", + parent=chassis, + location=(-0.56, 1.02, 1.68), + rotation_deg=(0.0, -56.0, 0.0), + size=(0.40, 1.04, 0.11), + ) + + # --- 6. Export GLB, Manifest & Preview --- + glb_path = vc.ASSETS_VEHICLES_DIR / "condor" / "condor.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "condor" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "condor_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="condor", + name="Condor", + vehicle_class="Heavy Quad-Thruster Assault VTOL", + grid_width=5, + grid_height=6, + mask=[ + ".###.", + "#####", + "#####", + "#####", + "#####", + "..#..", + ], + hardpoints=[ + {"id": "hp.weapon.nose", "kind": "weapon", "x": 1, "y": 0, "w": 2, "h": 1, "modelNodeId": "hp.weapon.nose"}, + {"id": "hp.armor.hull", "kind": "armor", "x": 3, "y": 0, "w": 1, "h": 1, "modelNodeId": "hp.armor.hull"}, + {"id": "hp.weapon.sponson_l", "kind": "weapon", "x": 0, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.sponson_l"}, + {"id": "hp.weapon.dorsal", "kind": "weapon", "x": 2, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.weapon.dorsal"}, + {"id": "hp.weapon.sponson_r", "kind": "weapon", "x": 4, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.sponson_r"}, + {"id": "hp.engine.core", "kind": "engine", "x": 1, "y": 2, "w": 3, "h": 2, "modelNodeId": "hp.engine.core"}, + {"id": "hp.radiator.spine_l", "kind": "radiator", "x": 0, "y": 3, "w": 1, "h": 2, "modelNodeId": "hp.radiator.spine_l"}, + {"id": "hp.radiator.spine_r", "kind": "radiator", "x": 4, "y": 3, "w": 1, "h": 2, "modelNodeId": "hp.radiator.spine_r"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[condor] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "condor", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_condor() diff --git a/tools/vehicles/build_ferret.py b/tools/vehicles/build_ferret.py new file mode 100644 index 0000000..1c17c8f --- /dev/null +++ b/tools/vehicles/build_ferret.py @@ -0,0 +1,344 @@ +"""Build the Ferret (Light Tracked Scout Tankette) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def _build_track_pod(name: str, side: float, parent) -> None: + """Build one wide articulated steel track pod with roadwheels, drive sprockets, and track shoes.""" + pod_x = side * 0.86 + pod = vc.make_empty(name, parent=parent, location=(pod_x, 0.0, 0.0)) + + # Track loop keypoints in (y, z): front idler -> bottom roadwheels -> rear sprocket -> top return + # Ground at z = 0.0 (track shoe thickness ~0.04 -> wheel bottom at z = 0.04) + rw_r = 0.25 + rw_z = rw_r + 0.04 + rw_ys = (-0.90, -0.30, 0.30, 0.90) + idler_y, idler_z, idler_r = -1.48, 0.46, 0.22 + sproc_y, sproc_z, sproc_r = 1.46, 0.48, 0.23 + track_w = 0.40 + + # Roadwheels (4) + Front Idler + Rear Drive Sprocket + for i, ry in enumerate(rw_ys): + vc.make_tube_part( + f"{name}_rw_tire_{i}", rw_r, rw_r, track_w * 0.82, segments=16, + mat_name="rubber_dark", parent=pod, location=(-track_w * 0.41, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_rw_hub_{i}", rw_r * 0.66, rw_r * 0.66, track_w * 0.88, segments=12, + mat_name="olive_armor", parent=pod, location=(-track_w * 0.44, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_idler", idler_r, idler_r, track_w * 0.78, segments=14, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.39, idler_y, idler_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_sprocket", sproc_r, sproc_r, track_w * 0.82, segments=14, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.41, sproc_y, sproc_z), rotation_deg=(0.0, 90.0, 0.0), + ) + + # Track belt loop + articulated grouser shoes sampled evenly around closed perimeter + # Build loop path points in (y, z) + loop_yz: list[tuple[float, float]] = [] + # Front idler arc (from top-front down to bottom-front) + for k in range(7): + ang = math.radians(95.0 + 145.0 * (k / 6.0)) + loop_yz.append((idler_y + math.cos(ang) * (idler_r + 0.025), idler_z + math.sin(ang) * (idler_r + 0.025))) + # Bottom run across roadwheels + loop_yz.append((-0.90, 0.02)) + loop_yz.append((0.90, 0.02)) + # Rear sprocket arc (from bottom-rear up to top-rear) + for k in range(7): + ang = math.radians(-65.0 + 145.0 * (k / 6.0)) + loop_yz.append((sproc_y + math.cos(ang) * (sproc_r + 0.025), sproc_z + math.sin(ang) * (sproc_r + 0.025))) + # Top return run + loop_yz.append((0.40, 0.73)) + loop_yz.append((-0.40, 0.73)) + + # Continuous inner track band via core.sweep (with up=+X, outline's h spans X and w spans thickness) + path_3d = [[0.0, y, z] for (y, z) in loop_yz] + vc.make_swept_profile( + f"{name}_track_band", + "box", + 0.030, + track_w * 0.92, + 0.030, + path_3d, + up=[1.0, 0.0, 0.0], + mat_name="rubber_dark", + parent=pod, + closed=True, + ) + + # Articulated steel grouser shoes along loop + # Compute cumulative arc length + pts = loop_yz + [loop_yz[0]] + segs = [math.hypot(pts[i + 1][0] - pts[i][0], pts[i + 1][1] - pts[i][1]) for i in range(len(loop_yz))] + total_len = sum(segs) + n_shoes = 38 + + def build_shoes(bm: bmesh.types.BMesh) -> None: + for s_idx in range(n_shoes): + target_d = total_d = (s_idx / n_shoes) * total_len + acc = 0.0 + for i, sl in enumerate(segs): + if acc + sl >= target_d or i == len(segs) - 1: + t = (target_d - acc) / max(sl, 1e-6) + y0, z0 = pts[i] + y1, z1 = pts[i + 1] + py = y0 + (y1 - y0) * t + pz = z0 + (z1 - z0) * t + ang = math.atan2(z1 - z0, y1 - y0) + # Normal pointing outward from loop (y, z) + m = ( + Matrix.Translation((0.0, py, pz)) + @ Matrix.Rotation(ang, 4, "X") + @ Matrix.Diagonal((track_w, 0.085, 0.026, 1.0)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + break + acc += sl + + vc.make_bmesh_object(f"{name}_shoes", build_shoes, "gunmetal", parent=pod) + + # Armored track fender & upper side skirt (Brokkr plate.v0 slab) + vc.make_box(f"{name}_fender_top", (track_w + 0.06, 3.24, 0.055), "olive_armor", parent=pod, location=(0.0, -0.02, 0.79), bevel=0.008) + vc.make_box(f"{name}_fender_front", (track_w + 0.06, 0.34, 0.055), "olive_armor", parent=pod, location=(0.0, -1.72, 0.68), rotation_deg=(36.0, 0.0, 0.0), bevel=0.008) + vc.make_box(f"{name}_fender_rear", (track_w + 0.06, 0.32, 0.055), "olive_armor", parent=pod, location=(0.0, 1.66, 0.68), rotation_deg=(-36.0, 0.0, 0.0), bevel=0.008) + + # Outer bolted track skirt covering upper roadwheels + skirt_pts = [ + [side * 0.22, -1.36, 0.78], + [side * 0.22, 1.36, 0.78], + [side * 0.22, 1.18, 0.36], + [side * 0.22, -1.16, 0.36], + ] + vc.make_box( + f"{name}_skirt", + (0.045, 2.52, 0.40), + "olive_armor", + parent=pod, + location=(side * (track_w * 0.5 + 0.025), 0.0, 0.58), + bevel=0.008, + ) + + +def build_ferret() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("FerretRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # --- 1. Lower Tub & Wedge Glacis Hull (Brokkr plate.v0 convex hull) --- + vc.make_box("lower_tub", (1.28, 3.06, 0.44), "gunmetal", parent=chassis, location=(0.0, -0.04, 0.46), bevel=0.012) + + hull_pts = [ + [-0.64, -1.68, 0.46], [0.64, -1.68, 0.46], + [0.68, -1.68, 0.64], [-0.68, -1.68, 0.64], + [-0.68, -0.78, 1.04], [0.68, -0.78, 1.04], + [-0.68, 0.66, 1.04], [0.68, 0.66, 1.04], + [-0.64, 1.66, 0.80], [0.64, 1.66, 0.80], + [-0.64, 1.66, 0.50], [0.64, 1.66, 0.50], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "ferret_hull", + "mat": "olive_armor", + "bevel": 0.014, + "sides": "one", + "mirror": False, + "points": hull_pts, + "clad": { + "mat": "olive_armor", + "facets": [{"n": [0.0, -0.45, 0.89], "cos": 0.90}], + "min_area": 0.12, + "lifts": [0.008, 0.014], + "inset": 0.05, + "gap": 0.016, + "split": 0.90, + "seed": 601, + "bolt_r": 0.012, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + }, + # Sloped upper hull sponson cheek plates + { + "name": "ferret_sponson", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.76, 0.14, 0.90], + "normal": [0.85, 0.0, 0.52], + "up": [0.0, 0.0, 1.0], + "right": [0.0, -1.0, 0.0], + "outline": [[-0.94, -0.14], [0.94, -0.14], [0.76, 0.14], [-0.78, 0.14]], + "thick": 0.05, + "taper": 0.014, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.30, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Headlights, tow shackles, and flank cylindrical mufflers + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"headlight_{tag}", (0.12, 0.12, 0.10), "gunmetal", parent=chassis, location=(side * 0.82, -1.52, 0.88), bevel=0.008) + vc.make_box(f"tow_shackle_{tag}", (0.06, 0.10, 0.10), "signal_orange", parent=chassis, location=(side * 0.42, -1.72, 0.56), bevel=0.005) + # Side exhaust muffler + copper pipes + vc.make_tube_part( + f"muffler_{tag}", 0.085, 0.085, 0.62, segments=12, + mat_name="gunmetal", parent=chassis, location=(side * 0.80, 0.72, 0.92), rotation_deg=(-90.0, 0.0, 0.0), + ) + vc.make_swept_tube( + f"muffler_pipe_{tag}", + [[side * 0.62, 0.64, 0.92], [side * 0.80, 0.72, 0.92], [side * 0.80, 1.44, 0.90]], + 0.032, segments=8, mat_name="copper_rad", parent=chassis, fillet_r=0.03, + ) + + # --- 2. Wide Articulated Track Pods --- + _build_track_pod("track_pod_L", 1.0, chassis) + _build_track_pod("track_pod_R", -1.0, chassis) + + # --- 3. Low Octagonal Turret (joint.turret_yaw) --- + turret_pivot = vc.make_empty("joint.turret_yaw", parent=chassis, location=(0.0, -0.18, 1.04)) + vc.tag_joint(turret_pivot, "joint.turret_yaw", [0.0, 1.0, 0.0], -180.0, 180.0) + joints_manifest = [{"id": "joint.turret_yaw", "axis": [0.0, 1.0, 0.0], "min": -180.0, "max": 180.0}] + + # Turret ring race + vc.make_tube_part("turret_race", 0.54, 0.58, 0.07, segments=20, mat_name="gunmetal", parent=turret_pivot, location=(0.0, 0.0, 0.0)) + + turret_pts = [ + [-0.46, -0.52, 0.06], [0.46, -0.52, 0.06], + [0.54, -0.10, 0.06], [0.48, 0.56, 0.06], + [-0.48, 0.56, 0.06], [-0.54, -0.10, 0.06], + [-0.36, -0.40, 0.42], [0.36, -0.40, 0.42], + [0.42, -0.06, 0.42], [0.38, 0.46, 0.42], + [-0.38, 0.46, 0.42], [-0.42, -0.06, 0.42], + ] + turret_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "ferret_turret_shell", + "mat": "olive_armor", + "bevel": 0.012, + "sides": "one", + "mirror": False, + "points": turret_pts, + }, + ], + } + vc.make_plates(turret_doc, parent=turret_pivot) + + # Commander hatch & front optic prism + cheek pylon shelf + vc.make_tube_part("commander_cupola", 0.17, 0.18, 0.08, segments=12, mat_name="olive_armor", parent=turret_pivot, location=(-0.16, 0.14, 0.42)) + vc.make_box("turret_optic", (0.14, 0.16, 0.10), "smoked_glass", parent=turret_pivot, location=(0.18, -0.26, 0.45), bevel=0.006) + vc.make_box("turret_mantlet_collar", (0.28, 0.16, 0.22), "gunmetal", parent=turret_pivot, location=(0.0, -0.50, 0.24), bevel=0.008) + vc.make_box("cheek_pylon_shelf", (0.24, 0.34, 0.08), "gunmetal", parent=turret_pivot, location=(0.56, 0.02, 0.22), bevel=0.006) + + # --- 4. Visible Exterior Hardpoints (3x4 Dorsal Grid) --- + # 1) Front wedge glacis armor stud rail + vc.add_hardpoint_slot( + "hp.armor.glacis", + "armor", + parent=chassis, + location=(0.0, -1.24, 0.85), + 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( + "hp.weapon.turret", + "weapon", + parent=turret_pivot, + location=(0.0, -0.02, 0.43), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.62, 0.62, 0.10), + ) + # 3) Turret cheek pod weapon collar (on left +X cheek pylon shelf) + vc.add_hardpoint_slot( + "hp.weapon.pod", + "weapon", + parent=turret_pivot, + location=(0.58, 0.02, 0.27), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.34, 0.34, 0.07), + ) + # 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.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 (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.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 --- + glb_path = vc.ASSETS_VEHICLES_DIR / "ferret" / "ferret.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "ferret" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "ferret_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="ferret", + name="Ferret", + vehicle_class="Light Tracked Scout Tankette", + grid_width=3, + grid_height=4, + mask=[ + "###", + "###", + "###", + "###", + ], + hardpoints=[ + {"id": "hp.armor.glacis", "kind": "armor", "x": 0, "y": 0, "w": 3, "h": 1, "modelNodeId": "hp.armor.glacis"}, + {"id": "hp.weapon.pod", "kind": "weapon", "x": 0, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.weapon.pod"}, + {"id": "hp.weapon.turret", "kind": "weapon", "x": 1, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.turret"}, + {"id": "hp.engine.rear", "kind": "engine", "x": 2, "y": 2, "w": 1, "h": 2, "modelNodeId": "hp.engine.rear"}, + {"id": "hp.radiator.deck", "kind": "radiator", "x": 1, "y": 3, "w": 1, "h": 1, "modelNodeId": "hp.radiator.deck"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[ferret] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "ferret", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_ferret() diff --git a/tools/vehicles/build_gear.py b/tools/vehicles/build_gear.py new file mode 100644 index 0000000..60b095d --- /dev/null +++ b/tools/vehicles/build_gear.py @@ -0,0 +1,144 @@ +"""Build the 6 modular starter gear GLBs into assets/gear/.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def _export_gear(name: str, root) -> tuple[int, dict]: + glb_path = vc.ASSETS_GEAR_DIR / f"{name}.glb" + tris, bounds = vc.export_vehicle_glb(glb_path, root=root) + print(f"[gear:{name}] tris={tris} bounds={bounds} glb={glb_path}") + return tris, bounds + + +def build_mg_762() -> None: + vc.reset_scene() + vc.ensure_materials() + root = vc.make_empty("GearRoot") + # Pintle base + yoke + receiver + perforated barrel shroud + side ammo box + spade grips + vc.make_tube_part("pintle_base", 0.14, 0.12, 0.06, segments=12, mat_name="gunmetal", parent=root) + vc.make_box("cradle_yoke", (0.14, 0.18, 0.18), "gunmetal", parent=root, location=(0.0, 0.0, 0.15), bevel=0.006) + vc.make_box("receiver", (0.12, 0.44, 0.14), "olive_armor", parent=root, location=(0.0, -0.04, 0.28), bevel=0.006) + vc.make_tube_part("barrel_shroud", 0.032, 0.028, 0.48, segments=10, mat_name="gunmetal", parent=root, location=(0.0, -0.24, 0.29), rotation_deg=(90.0, 0.0, 0.0)) + vc.make_tube_part("barrel_inner", 0.014, 0.014, 0.68, segments=8, mat_name="gunmetal", parent=root, location=(0.0, -0.24, 0.29), rotation_deg=(90.0, 0.0, 0.0)) + vc.make_box("ammo_box", (0.14, 0.22, 0.16), "olive_armor", parent=root, location=(0.14, -0.02, 0.25), bevel=0.006) + vc.make_box("ammo_latch", (0.04, 0.10, 0.04), "signal_orange", parent=root, location=(0.14, -0.02, 0.34), bevel=0.003) + for side in (-1.0, 1.0): + vc.make_tube_part(f"grip_{'L' if side > 0 else 'R'}", 0.012, 0.012, 0.10, segments=6, mat_name="rubber_dark", parent=root, location=(side * 0.06, 0.22, 0.23)) + _export_gear("mg_762", root) + + +def build_autocannon() -> None: + vc.reset_scene() + vc.ensure_materials() + root = vc.make_empty("GearRoot") + # Turret base ring + twin armored trunnion cheeks + dual 20mm barrels + twin ammo drums + vc.make_tube_part("turret_collar", 0.26, 0.24, 0.08, segments=16, mat_name="gunmetal", parent=root) + vc.make_box("gun_housing", (0.30, 0.46, 0.24), "olive_armor", parent=root, location=(0.0, 0.04, 0.20), bevel=0.010) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_tube_part(f"barrel_jacket_{tag}", 0.036, 0.030, 0.42, segments=10, mat_name="gunmetal", parent=root, location=(side * 0.085, -0.18, 0.22), rotation_deg=(90.0, 0.0, 0.0)) + vc.make_tube_part(f"barrel_tube_{tag}", 0.018, 0.018, 0.88, segments=8, mat_name="gunmetal", parent=root, location=(side * 0.085, -0.18, 0.22), rotation_deg=(90.0, 0.0, 0.0)) + vc.make_tube_part(f"muzzle_brake_{tag}", 0.028, 0.028, 0.09, segments=8, mat_name="copper_rad", parent=root, location=(side * 0.085, -1.00, 0.22), rotation_deg=(90.0, 0.0, 0.0)) + vc.make_tube_part(f"ammo_drum_{tag}", 0.13, 0.13, 0.16, segments=14, mat_name="olive_armor", parent=root, location=(side * 0.22, 0.14, 0.24), rotation_deg=(0.0, 90.0 * side, 0.0)) + vc.make_box("optic_pod", (0.10, 0.14, 0.09), "smoked_glass", parent=root, location=(0.0, -0.08, 0.36), bevel=0.005) + _export_gear("autocannon", root) + + +def build_recoilless() -> None: + vc.reset_scene() + vc.ensure_materials() + root = vc.make_empty("GearRoot") + # Pedestal + heavy long recoilless tube + flared rear venturi + top optic rail + vc.make_tube_part("base_flange", 0.20, 0.18, 0.07, segments=14, mat_name="gunmetal", parent=root) + vc.make_box("trunnion_post", (0.14, 0.20, 0.20), "gunmetal", parent=root, location=(0.0, 0.02, 0.16), bevel=0.008) + tube_prof = [ + [0.055, -0.58], + [0.085, -0.58], + [0.095, -0.35], + [0.095, 0.42], + [0.072, 0.46], + [0.072, 0.78], + [0.088, 0.82], + [0.062, 0.82], + [0.055, 0.44], + ] + vc.make_lathe_part("launcher_tube", tube_prof, segments=16, loop=True, smooth=True, mat_name="olive_armor", parent=root, location=(0.0, 0.0, 0.32), rotation_deg=(-90.0, 0.0, 0.0)) + vc.make_box("breech_band", (0.20, 0.12, 0.20), "signal_orange", parent=root, location=(0.0, 0.26, 0.32), bevel=0.006) + vc.make_tube_part("sight_tube", 0.028, 0.032, 0.22, segments=10, mat_name="gunmetal", parent=root, location=(0.11, -0.02, 0.36), rotation_deg=(90.0, 0.0, 0.0)) + _export_gear("recoilless", root) + + +def build_copper_rad() -> None: + vc.reset_scene() + vc.ensure_materials() + root = vc.make_empty("GearRoot") + # Industrial copper finned radiator bank + armored end tanks + coolant pipes + base flange + vc.make_box("base_flange", (0.48, 0.42, 0.045), "gunmetal", parent=root, location=(0.0, 0.0, 0.0225), bevel=0.006) + vc.make_kit_part( + "copper_fins", + "mechanical", + "radiator_stack", + {"fins": 10, "fin_w": 0.36, "fin_h": 0.24, "fin_t": 0.008, "pitch": 0.032, "segments": 10}, + mat_name="copper_rad", + parent=root, + location=(0.0, -0.145, 0.18), + rotation_deg=(-90.0, 0.0, 0.0), + ) + for side in (-1.0, 1.0): + vc.make_box(f"end_tank_{'L' if side > 0 else 'R'}", (0.06, 0.38, 0.26), "gunmetal", parent=root, location=(side * 0.21, 0.0, 0.18), bevel=0.008) + vc.make_swept_tube(f"coolant_pipe_{'L' if side > 0 else 'R'}", [[side * 0.21, 0.14, 0.26], [side * 0.21, 0.24, 0.18], [side * 0.16, 0.24, 0.06]], 0.018, segments=8, mat_name="copper_rad", parent=root, fillet_r=0.02) + vc.make_box("top_cap_bar", (0.44, 0.06, 0.04), "signal_orange", parent=root, location=(0.0, -0.15, 0.31), bevel=0.004) + _export_gear("copper_rad", root) + + +def build_gilded_lance() -> None: + vc.reset_scene() + vc.ensure_materials() + root = vc.make_empty("GearRoot") + # Imperial Tourist ornate gilded thermal lance with ivory cowl, gold flutes, and cyan condenser rings + vc.make_tube_part("imperial_base", 0.24, 0.21, 0.08, segments=18, mat_name="imperial_gold", parent=root) + vc.make_box("ivory_cowl", (0.28, 0.52, 0.22), "imperial_ivory", parent=root, location=(0.0, 0.02, 0.20), bevel=0.014) + vc.make_box("gold_crest", (0.10, 0.44, 0.08), "imperial_gold", parent=root, location=(0.0, 0.02, 0.32), bevel=0.008) + vc.make_tube_part("lance_core", 0.042, 0.026, 0.96, segments=14, mat_name="imperial_gold", parent=root, location=(0.0, -0.20, 0.22), rotation_deg=(90.0, 0.0, 0.0)) + for i, dy in enumerate((-0.42, -0.64, -0.86)): + vc.make_tube_part(f"condenser_ring_{i}", 0.062 - i * 0.006, 0.062 - i * 0.006, 0.04, segments=14, mat_name="cyan_coil", parent=root, location=(0.0, dy, 0.22), rotation_deg=(90.0, 0.0, 0.0)) + _export_gear("gilded_lance", root) + + +def build_gold_radiator() -> None: + vc.reset_scene() + vc.ensure_materials() + root = vc.make_empty("GearRoot") + # Imperial Tourist ornate gilded louver array with ivory housing & cyan thermal core + vc.make_box("imperial_flange", (0.48, 0.42, 0.045), "imperial_gold", parent=root, location=(0.0, 0.0, 0.0225), bevel=0.006) + vc.make_box("ivory_shroud", (0.44, 0.38, 0.22), "imperial_ivory", parent=root, location=(0.0, 0.0, 0.155), bevel=0.012) + vc.make_box("cyan_core", (0.34, 0.28, 0.16), "cyan_coil", parent=root, location=(0.0, 0.0, 0.16), bevel=0.004) + def build_gold_vanes(bm: bmesh.types.BMesh) -> None: + for i in range(7): + y = -0.14 + 0.28 * (i / 6.0) + m = Matrix.Translation((0.0, y, 0.265)) @ Matrix.Rotation(math.radians(20.0), 4, "X") @ Matrix.Diagonal((0.38, 0.022, 0.055, 1.0)) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + vc.make_bmesh_object("gold_vanes", build_gold_vanes, "imperial_gold", parent=root) + _export_gear("gold_radiator", root) + + +def build_all_gear() -> None: + build_mg_762() + build_autocannon() + build_recoilless() + build_copper_rad() + build_gilded_lance() + build_gold_radiator() + + +if __name__ == "__main__": + build_all_gear() diff --git a/tools/vehicles/build_hornet.py b/tools/vehicles/build_hornet.py new file mode 100644 index 0000000..bb073e1 --- /dev/null +++ b/tools/vehicles/build_hornet.py @@ -0,0 +1,400 @@ +"""Build the Hornet (Light Ducted-Fan VTOL Gunship) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def _build_ducted_nacelle(name: str, side: float, parent, joints_manifest: list[dict]) -> None: + """Build a pivoting armored ducted-fan nacelle with inner copper thrust collar and spinning rotor.""" + nacelle_id = f"joint.nacelle_{'l' if side > 0 else 'r'}" + nacelle_pivot = vc.make_empty( + nacelle_id, + parent=parent, + location=(side * 1.18, 0.10, 1.32), + rotation_deg=(-18.0, 0.0, 0.0), + ) + vc.tag_joint(nacelle_pivot, nacelle_id, [1.0, 0.0, 0.0], -45.0, 75.0) + joints_manifest.append({"id": nacelle_id, "axis": [1.0, 0.0, 0.0], "min": -45.0, "max": 75.0}) + + # Upper olive-drab armored duct shroud (CCW in (r, z) for core.lathe) + shroud_prof = [ + [0.34, -0.06], + [0.44, -0.06], + [0.47, 0.02], + [0.47, 0.22], + [0.43, 0.28], + [0.35, 0.28], + [0.33, 0.20], + [0.34, -0.06], + ] + vc.make_lathe_part( + f"{name}_shroud", + shroud_prof[:-1], + segments=22, + loop=True, + smooth=True, + mat_name="olive_armor", + parent=nacelle_pivot, + ) + # Lower copper thermal exhaust skirt + skirt_prof = [ + [0.33, -0.20], + [0.41, -0.20], + [0.44, -0.06], + [0.34, -0.06], + ] + vc.make_lathe_part( + f"{name}_skirt", + skirt_prof, + segments=22, + loop=True, + smooth=True, + mat_name="copper_rad", + parent=nacelle_pivot, + ) + # Stator cross vanes + hinge yoke collar + for ang_deg in (0.0, 90.0): + vc.make_box( + f"{name}_stator_{int(ang_deg)}", + (0.68, 0.04, 0.06), + "gunmetal", + parent=nacelle_pivot, + location=(0.0, 0.0, -0.08), + rotation_deg=(0.0, 0.0, ang_deg), + bevel=0.004, + ) + vc.make_box( + f"{name}_hinge_lug", + (0.16, 0.22, 0.16), + "gunmetal", + parent=nacelle_pivot, + location=(-side * 0.44, 0.0, 0.08), + bevel=0.008, + ) + + # Spinning rotor hub + 4 pitched fan blades (about glTF +Y = Blender +Z) + rotor_id = f"joint.rotor_{'l' if side > 0 else 'r'}" + rotor_pivot = vc.make_empty(rotor_id, parent=nacelle_pivot, location=(0.0, 0.0, 0.04)) + vc.tag_joint(rotor_pivot, rotor_id, [0.0, 1.0, 0.0], -360.0, 360.0) + joints_manifest.append({"id": rotor_id, "axis": [0.0, 1.0, 0.0], "min": -360.0, "max": 360.0}) + + spinner_prof = [ + [0.0, -0.04], + [0.10, -0.04], + [0.10, 0.06], + [0.06, 0.16], + [0.0, 0.22], + ] + vc.make_lathe_part(f"{name}_spinner", spinner_prof, segments=14, loop=False, smooth=True, mat_name="gunmetal", parent=rotor_pivot) + + def build_blades(bm: bmesh.types.BMesh) -> None: + for i in range(4): + a = i * math.pi * 0.5 + m = ( + Matrix.Rotation(a, 4, "Z") + @ Matrix.Translation((0.20, 0.0, 0.02)) + @ Matrix.Rotation(math.radians(22.0), 4, "X") + @ Matrix.Diagonal((0.24, 0.085, 0.014, 1.0)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + + vc.make_bmesh_object(f"{name}_blades", build_blades, "gunmetal", parent=rotor_pivot) + + +def build_hornet() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("HornetRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # --- 1. Rugged Steel Landing Skids (grounded at Z = 0) --- + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_swept_tube( + f"skid_runner_{tag}", + [ + [side * 0.72, -1.56, 0.16], + [side * 0.72, -1.24, 0.032], + [side * 0.72, 1.06, 0.032], + ], + 0.032, + segments=8, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.08, + ) + # Front & rear diagonal skid struts up to fuselage belly + for s_tag, sy_lo, sy_hi in (("f", -0.82, -0.68), ("r", 0.52, 0.44)): + vc.make_swept_tube( + f"skid_strut_{tag}_{s_tag}", + [[side * 0.72, sy_lo, 0.04], [side * 0.40, sy_hi, 0.54]], + 0.026, + segments=8, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.0, + ) + + # --- 2. Faceted Armored Cockpit & Fuselage Hull (Brokkr plate.v0) --- + hull_pts = [ + [-0.28, -1.86, 0.56], [0.28, -1.86, 0.56], + [-0.36, -1.78, 0.78], [0.36, -1.78, 0.78], + [-0.58, -0.86, 0.46], [0.58, -0.86, 0.46], + [-0.64, -0.64, 1.02], [0.64, -0.64, 1.02], + [-0.64, 0.76, 1.02], [0.64, 0.76, 1.02], + [-0.56, 0.88, 0.54], [0.56, 0.88, 0.54], + [-0.44, 0.64, 1.44], [0.44, 0.64, 1.44], + [-0.44, -0.26, 1.44], [0.44, -0.26, 1.44], + ] + canopy_pts = [ + [-0.34, -1.66, 0.78], [0.34, -1.66, 0.78], + [-0.52, -0.88, 1.02], [0.52, -0.88, 1.02], + [-0.42, -0.28, 1.40], [0.42, -0.28, 1.40], + [-0.36, -0.88, 1.38], [0.36, -0.88, 1.38], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "hornet_fuselage", + "mat": "olive_armor", + "bevel": 0.014, + "sides": "one", + "mirror": False, + "points": hull_pts, + }, + { + "name": "hornet_canopy", + "mat": "smoked_glass", + "bevel": 0.008, + "sides": "one", + "mirror": False, + "points": canopy_pts, + }, + # Cheek armor skirts with bolts + { + "name": "hornet_cheek", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.58, -0.62, 0.76], + "normal": [0.92, -0.28, 0.26], + "up": [0.0, 0.0, 1.0], + "right": [-0.28, -0.96, 0.0], + "outline": [[-0.56, -0.14], [0.52, -0.18], [0.48, 0.16], [-0.46, 0.14]], + "thick": 0.04, + "taper": 0.012, + "back": 0.90, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.24, "mat": "gunmetal", "params": "r=0.011"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Canopy structural armor ribs + nose EO/IR optics pod + vc.make_swept_tube( + "canopy_spine", + [[0.0, -1.68, 0.78], [0.0, -0.90, 1.40], [0.0, -0.26, 1.44]], + 0.024, segments=6, mat_name="olive_armor", parent=chassis, fillet_r=0.04, + ) + for side in (-1.0, 1.0): + vc.make_swept_tube( + f"canopy_rib_{'L' if side > 0 else 'R'}", + [[side * 0.33, -1.65, 0.78], [side * 0.37, -0.89, 1.38], [side * 0.43, -0.28, 1.42]], + 0.020, segments=6, mat_name="olive_armor", parent=chassis, fillet_r=0.04, + ) + vc.make_box("nose_optics_housing", (0.24, 0.20, 0.18), "gunmetal", parent=chassis, location=(0.0, -1.86, 0.66), bevel=0.01) + vc.make_tube_part("nose_optics_lens", 0.065, 0.065, 0.06, segments=12, mat_name="smoked_glass", parent=chassis, location=(0.0, -1.94, 0.66), rotation_deg=(90.0, 0.0, 0.0)) + + # Stub wings + nacelle outrigger arms + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box( + f"stub_wing_{tag}", + (0.68, 0.56, 0.09), + "olive_armor", + parent=chassis, + location=(side * 0.74, 0.14, 0.74), + rotation_deg=(0.0, side * 8.0, side * -10.0), + bevel=0.01, + ) + vc.make_box( + f"nacelle_arm_{tag}", + (0.46, 0.30, 0.18), + "gunmetal", + parent=chassis, + location=(side * 0.62, 0.10, 1.32), + bevel=0.01, + ) + + # --- 3. Pivoting Ducted-Fan Nacelles + Hydraulic Tilt Actuators --- + joints_manifest: list[dict] = [] + for side in (1.0, -1.0): + tag = "L" if side > 0 else "R" + _build_ducted_nacelle(f"nacelle_{tag}", side, chassis, joints_manifest) + # Dual hydraulic tilt actuator from dorsal shoulder clevis out to nacelle hinge lug + vc.make_box(f"tilt_clevis_{tag}", (0.10, 0.14, 0.10), "gunmetal", parent=chassis, location=(side * 0.44, -0.10, 1.38), bevel=0.005) + vc.make_ram_span( + f"tilt_actuator_{tag}", + [side * 0.44, -0.10, 1.38], + [side * 0.78, 0.08, 1.38], + body_r=0.028, + rod_r=0.015, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + + # --- 4. Skeletal Truss Tail Boom & V/T Tailfins --- + # Rear boom mounting bulkhead + 3-chord space-frame tail boom anchored inside fuselage + vc.make_box("tail_boom_collar", (0.44, 0.28, 0.42), "gunmetal", parent=chassis, location=(0.0, 0.74, 1.10), bevel=0.01) + boom_top_l = [0.16, 0.62, 1.24] + boom_top_r = [-0.16, 0.62, 1.24] + boom_bot = [0.0, 0.62, 0.94] + tail_top_l = [0.07, 2.38, 1.34] + tail_top_r = [-0.07, 2.38, 1.34] + tail_bot = [0.0, 2.38, 1.16] + for cname, p0, p1 in [ + ("boom_tl", boom_top_l, tail_top_l), + ("boom_tr", boom_top_r, tail_top_r), + ("boom_bt", boom_bot, tail_bot), + ]: + vc.make_swept_tube(cname, [p0, p1], 0.020, segments=6, mat_name="gunmetal", parent=chassis, fillet_r=0.0) + + # Truss bay diagonals along the tail boom + n_bays = 5 + def lerp3(a, b, t): + return [a[k] + (b[k] - a[k]) * t for k in range(3)] + + for i in range(n_bays): + t0 = i / n_bays + t1 = (i + 1) / n_bays + p_tl0, p_tr0, p_b0 = lerp3(boom_top_l, tail_top_l, t0), lerp3(boom_top_r, tail_top_r, t0), lerp3(boom_bot, tail_bot, t0) + p_tl1, p_tr1, p_b1 = lerp3(boom_top_l, tail_top_l, t1), lerp3(boom_top_r, tail_top_r, t1), lerp3(boom_bot, tail_bot, t1) + vc.make_swept_tube(f"boom_cross_{i}", [p_tl1, p_tr1, p_b1, p_tl1], 0.012, segments=6, mat_name="gunmetal", parent=chassis, fillet_r=0.0) + vc.make_swept_tube(f"boom_diag_l_{i}", [p_tl0, p_b1], 0.011, segments=6, mat_name="gunmetal", parent=chassis, fillet_r=0.0) + vc.make_swept_tube(f"boom_diag_r_{i}", [p_tr0, p_b1], 0.011, segments=6, mat_name="gunmetal", parent=chassis, fillet_r=0.0) + + # Swept-back V-tail stabilizers + ventral fin + tail hub + vc.make_box("tail_fin_hub", (0.16, 0.24, 0.20), "gunmetal", parent=chassis, location=(0.0, 2.36, 1.26), bevel=0.008) + for side in (-1.0, 1.0): + vc.make_box( + f"vtail_{'L' if side > 0 else 'R'}", + (0.04, 0.34, 0.62), + "olive_armor", + parent=chassis, + location=(side * 0.24, 2.40, 1.54), + rotation_deg=(22.0, side * -38.0, 0.0), + bevel=0.006, + ) + vc.make_box("ventral_fin", (0.035, 0.26, 0.24), "olive_armor", parent=chassis, location=(0.0, 2.36, 1.04), rotation_deg=(22.0, 0.0, 0.0), bevel=0.006) + + # --- 5. Visible Exterior Hardpoints (4x4 Dorsal Grid) --- + # 1) Chin gimbal collar (under nose, pointing +Z forward and -Y downward) + vc.add_hardpoint_slot( + "hp.weapon.chin", + "weapon", + parent=chassis, + 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( + "hp.weapon.wing_l", + "weapon", + parent=chassis, + location=(0.88, 0.14, 0.69), + rotation_deg=(0.0, 180.0, 0.0), + size=(0.34, 0.34, 0.07), + ) + vc.add_hardpoint_slot( + "hp.weapon.wing_r", + "weapon", + parent=chassis, + location=(-0.88, 0.14, 0.69), + rotation_deg=(0.0, 180.0, 0.0), + size=(0.34, 0.34, 0.07), + ) + # 4) Dorsal turbine core engine bay + vc.add_hardpoint_slot( + "hp.engine.core", + "engine", + parent=chassis, + location=(0.0, 0.26, 1.44), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.74, 0.80, 0.13), + ) + # 5 & 6) Twin copper-louvered nacelle root exhaust radiator bays + vc.add_hardpoint_slot( + "hp.radiator.nacelle_l", + "radiator", + parent=chassis, + 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.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 --- + glb_path = vc.ASSETS_VEHICLES_DIR / "hornet" / "hornet.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "hornet" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "hornet_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="hornet", + name="Hornet", + vehicle_class="Light Ducted-Fan VTOL Gunship", + grid_width=4, + grid_height=4, + mask=[ + ".##.", + "####", + "####", + ".##.", + ], + hardpoints=[ + {"id": "hp.weapon.chin", "kind": "weapon", "x": 1, "y": 0, "w": 1, "h": 2, "modelNodeId": "hp.weapon.chin"}, + {"id": "hp.radiator.nacelle_l", "kind": "radiator", "x": 0, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.radiator.nacelle_l"}, + {"id": "hp.radiator.nacelle_r", "kind": "radiator", "x": 3, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.radiator.nacelle_r"}, + {"id": "hp.weapon.wing_l", "kind": "weapon", "x": 0, "y": 2, "w": 1, "h": 1, "modelNodeId": "hp.weapon.wing_l"}, + {"id": "hp.engine.core", "kind": "engine", "x": 1, "y": 2, "w": 2, "h": 2, "modelNodeId": "hp.engine.core"}, + {"id": "hp.weapon.wing_r", "kind": "weapon", "x": 3, "y": 2, "w": 1, "h": 1, "modelNodeId": "hp.weapon.wing_r"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[hornet] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "hornet", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_hornet() diff --git a/tools/vehicles/build_ironclad.py b/tools/vehicles/build_ironclad.py new file mode 100644 index 0000000..a20dfeb --- /dev/null +++ b/tools/vehicles/build_ironclad.py @@ -0,0 +1,423 @@ +"""Build the Ironclad (Medium Tracked Battle Tank) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def _build_mbt_track_pod(name: str, side: float, parent) -> None: + """Build one wide MBT track assembly with 5 double roadwheels, idler, sprocket, shoes, and bolted side skirt.""" + pod_x = side * 1.12 + pod = vc.make_empty(name, parent=parent, location=(pod_x, 0.0, 0.0)) + + rw_r = 0.28 + rw_z = rw_r + 0.045 + rw_ys = (-1.28, -0.64, 0.0, 0.64, 1.28) + idler_y, idler_z, idler_r = -1.94, 0.56, 0.25 + sproc_y, sproc_z, sproc_r = 1.92, 0.58, 0.26 + track_w = 0.48 + + # Roadwheels (5) + 3 return rollers + Front Idler + Rear Drive Sprocket + for i, ry in enumerate(rw_ys): + vc.make_tube_part( + f"{name}_rw_tire_{i}", rw_r, rw_r, track_w * 0.84, segments=16, + mat_name="rubber_dark", parent=pod, location=(-track_w * 0.42, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_rw_dish_{i}", rw_r * 0.68, rw_r * 0.68, track_w * 0.90, segments=12, + mat_name="olive_armor", parent=pod, location=(-track_w * 0.45, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_rw_cap_{i}", rw_r * 0.28, rw_r * 0.28, track_w * 0.94, segments=10, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.47, ry, rw_z), rotation_deg=(0.0, 90.0, 0.0), + ) + for j, rry in enumerate((-0.96, 0.0, 0.96)): + vc.make_tube_part( + f"{name}_ret_{j}", 0.09, 0.09, track_w * 0.68, segments=10, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.34, rry, 0.78), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_idler", idler_r, idler_r, track_w * 0.80, segments=14, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.40, idler_y, idler_z), rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_tube_part( + f"{name}_sprocket", sproc_r, sproc_r, track_w * 0.84, segments=14, + mat_name="gunmetal", parent=pod, location=(-track_w * 0.42, sproc_y, sproc_z), rotation_deg=(0.0, 90.0, 0.0), + ) + + # Track loop polyline in (y, z) + loop_yz: list[tuple[float, float]] = [] + for k in range(7): + ang = math.radians(95.0 + 145.0 * (k / 6.0)) + loop_yz.append((idler_y + math.cos(ang) * (idler_r + 0.03), idler_z + math.sin(ang) * (idler_r + 0.03))) + loop_yz.append((-1.28, 0.025)) + loop_yz.append((1.28, 0.025)) + for k in range(7): + ang = math.radians(-65.0 + 145.0 * (k / 6.0)) + loop_yz.append((sproc_y + math.cos(ang) * (sproc_r + 0.03), sproc_z + math.sin(ang) * (sproc_r + 0.03))) + loop_yz.append((0.60, 0.89)) + loop_yz.append((-0.60, 0.89)) + + path_3d = [[0.0, y, z] for (y, z) in loop_yz] + vc.make_swept_profile( + f"{name}_track_band", + "box", + 0.034, + track_w * 0.92, + 0.034, + path_3d, + up=[1.0, 0.0, 0.0], + mat_name="rubber_dark", + parent=pod, + closed=True, + ) + + # Articulated steel grouser shoes + pts = loop_yz + [loop_yz[0]] + segs = [math.hypot(pts[i + 1][0] - pts[i][0], pts[i + 1][1] - pts[i][1]) for i in range(len(loop_yz))] + total_len = sum(segs) + n_shoes = 46 + + def build_shoes(bm: bmesh.types.BMesh) -> None: + for s_idx in range(n_shoes): + target_d = (s_idx / n_shoes) * total_len + acc = 0.0 + for i, sl in enumerate(segs): + if acc + sl >= target_d or i == len(segs) - 1: + t = (target_d - acc) / max(sl, 1e-6) + y0, z0 = pts[i] + y1, z1 = pts[i + 1] + py = y0 + (y1 - y0) * t + pz = z0 + (z1 - z0) * t + ang = math.atan2(z1 - z0, y1 - y0) + m = ( + Matrix.Translation((0.0, py, pz)) + @ Matrix.Rotation(ang, 4, "X") + @ Matrix.Diagonal((track_w, 0.095, 0.030, 1.0)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + break + acc += sl + + vc.make_bmesh_object(f"{name}_shoes", build_shoes, "gunmetal", parent=pod) + + # Full-length top track fender + front/rear mudflaps + vc.make_box(f"{name}_fender_top", (track_w + 0.08, 4.18, 0.065), "olive_armor", parent=pod, location=(0.0, -0.02, 0.96), bevel=0.01) + vc.make_box(f"{name}_fender_front", (track_w + 0.08, 0.36, 0.06), "olive_armor", parent=pod, location=(0.0, -2.20, 0.84), rotation_deg=(38.0, 0.0, 0.0), bevel=0.008) + vc.make_box(f"{name}_fender_rear", (track_w + 0.08, 0.34, 0.06), "olive_armor", parent=pod, location=(0.0, 2.16, 0.84), rotation_deg=(-38.0, 0.0, 0.0), bevel=0.008) + + +def build_ironclad() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("IroncladRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # --- 1. Lower Armored Tub & Welded Angular MBT Hull (Brokkr plate.v0) --- + vc.make_box("lower_tub", (1.74, 4.10, 0.52), "gunmetal", parent=chassis, location=(0.0, -0.02, 0.56), bevel=0.014) + + hull_pts = [ + [-0.87, -2.26, 0.52], [0.87, -2.26, 0.52], + [-0.90, -2.24, 0.74], [0.90, -2.24, 0.74], + [-0.92, -1.16, 1.16], [0.92, -1.16, 1.16], + [-0.92, 0.96, 1.16], [0.92, 0.96, 1.16], + [-0.88, 2.18, 0.96], [0.88, 2.18, 0.96], + [-0.86, 2.16, 0.54], [0.86, 2.16, 0.54], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "ironclad_hull", + "mat": "olive_armor", + "bevel": 0.015, + "sides": "one", + "mirror": False, + "points": hull_pts, + "clad": { + "mat": "olive_armor", + "facets": [{"n": [0.0, -0.36, 0.93], "cos": 0.88}], + "min_area": 0.16, + "lifts": [0.008, 0.014], + "inset": 0.06, + "gap": 0.018, + "split": 0.88, + "seed": 701, + "bolt_r": 0.013, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + }, + # Heavy bolted forward/mid track skirts (leaves rear flank clear for radiator bays) + { + "name": "ironclad_track_skirt", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [1.39, -0.44, 0.68], + "normal": [1.0, 0.0, 0.0], + "up": [0.0, 0.0, 1.0], + "right": [0.0, -1.0, 0.0], + "outline": [[-1.34, -0.26], [1.44, -0.26], [1.26, 0.28], [-1.34, 0.28]], + "thick": 0.048, + "taper": 0.010, + "back": 0.92, + }, + "clad": { + "mat": "olive_armor", + "facets": "outer", + "min_area": 0.10, + "lifts": [0.008, 0.014], + "inset": 0.04, + "gap": 0.016, + "split": 0.72, + "seed": 702, + "bolt_r": 0.013, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + "fits": [ + {"kind": "bolts", "inset": 0.025, "spacing": 0.34, "mat": "gunmetal", "params": "r=0.013"}, + ], + }, + # Sloped upper hull sponson shoulders + { + "name": "ironclad_sponson", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [1.08, 0.16, 1.04], + "normal": [0.76, 0.0, 0.65], + "up": [-0.65, 0.0, 0.76], + "right": [0.0, -1.0, 0.0], + "outline": [[-1.72, -0.18], [1.72, -0.18], [1.56, 0.18], [-1.56, 0.18]], + "thick": 0.05, + "taper": 0.014, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.36, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Rear flank armored housings for radiator bays + driver periscope + headlights + tow shackles + vc.make_box("driver_periscope", (0.42, 0.14, 0.09), "smoked_glass", parent=chassis, location=(-0.30, -1.32, 1.18), bevel=0.005) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"headlight_box_{tag}", (0.18, 0.14, 0.12), "gunmetal", parent=chassis, location=(side * 1.08, -2.06, 1.04), bevel=0.008) + vc.make_box(f"headlight_lens_{tag}", (0.12, 0.04, 0.07), "smoked_glass", parent=chassis, location=(side * 1.08, -2.13, 1.04), bevel=0.003) + vc.make_box(f"tow_shackle_{tag}", (0.07, 0.12, 0.12), "signal_orange", parent=chassis, location=(side * 0.56, -2.28, 0.62), bevel=0.006) + # Rear flank radiator mounting box + exhaust armor box + vc.make_box(f"rear_rad_housing_{tag}", (0.18, 1.04, 0.50), "olive_armor", parent=chassis, location=(side * 1.28, 1.36, 0.78), bevel=0.01) + vc.make_box(f"rear_exhaust_box_{tag}", (0.42, 0.34, 0.24), "gunmetal", parent=chassis, location=(side * 0.62, 2.08, 0.86), bevel=0.01) + vc.make_swept_tube( + f"exhaust_pipe_{tag}", + [[side * 0.62, 2.12, 0.86], [side * 0.72, 2.26, 0.88], [side * 0.72, 2.34, 0.78]], + 0.042, + segments=10, + mat_name="copper_rad", + parent=chassis, + fillet_r=0.03, + ) + # External cylindrical stern fuel drums (signature Ironclad silhouette; tank extends along local +Z) + vc.make_kit_part( + f"stern_fuel_drum_{tag}", + "mechanical", + "tank", + {"radius": 0.17, "length": 0.76, "segments": 14}, + mat_name="olive_armor", + parent=chassis, + location=(side * 0.06, 2.24, 1.04), + rotation_deg=(0.0, side * 90.0, 0.0), + ) + + # --- 2. Wide Articulated MBT Track Pods --- + _build_mbt_track_pod("track_pod_L", 1.0, chassis) + _build_mbt_track_pod("track_pod_R", -1.0, chassis) + + # --- 3. Faceted Central MBT Turret (joint.turret_yaw) --- + turret_pivot = vc.make_empty("joint.turret_yaw", parent=chassis, location=(0.0, -0.18, 1.16)) + vc.tag_joint(turret_pivot, "joint.turret_yaw", [0.0, 1.0, 0.0], -180.0, 180.0) + joints_manifest = [{"id": "joint.turret_yaw", "axis": [0.0, 1.0, 0.0], "min": -180.0, "max": 180.0}] + + vc.make_tube_part("turret_race", 0.76, 0.82, 0.08, segments=24, mat_name="gunmetal", parent=turret_pivot) + + turret_pts = [ + [-0.58, -0.84, 0.08], [0.58, -0.84, 0.08], + [0.86, -0.20, 0.08], [0.76, 0.88, 0.08], + [-0.76, 0.88, 0.08], [-0.86, -0.20, 0.08], + [-0.46, -0.60, 0.50], [0.46, -0.60, 0.50], + [0.64, -0.10, 0.50], [0.58, 0.76, 0.50], + [-0.58, 0.76, 0.50], [-0.64, -0.10, 0.50], + ] + turret_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "ironclad_turret_shell", + "mat": "olive_armor", + "bevel": 0.014, + "sides": "one", + "mirror": False, + "points": turret_pts, + }, + { + "name": "ironclad_turret_cheek", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.62, -0.52, 0.28], + "normal": [0.64, -0.68, 0.35], + "up": [-0.24, 0.25, 0.94], + "right": [-0.73, -0.68, 0.0], + "outline": [[-0.28, -0.16], [0.28, -0.16], [0.22, 0.16], [-0.22, 0.16]], + "thick": 0.05, + "taper": 0.012, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.20, "mat": "gunmetal", "params": "r=0.011"}, + ], + }, + ], + } + vc.make_plates(turret_doc, parent=turret_pivot) + + # Turret mantlet, bustle rack, commander cupola, CITV optic, smoke dischargers & coax bracket + vc.make_box("turret_mantlet", (0.52, 0.24, 0.26), "gunmetal", parent=turret_pivot, location=(0.0, -0.82, 0.28), bevel=0.01) + vc.make_box("turret_bustle", (1.10, 0.44, 0.32), "olive_armor", parent=turret_pivot, location=(0.0, 0.98, 0.32), bevel=0.01) + vc.make_tube_part("commander_cupola", 0.17, 0.19, 0.09, segments=14, mat_name="olive_armor", parent=turret_pivot, location=(-0.36, 0.46, 0.50)) + vc.make_box("turret_citv_pod", (0.18, 0.20, 0.16), "gunmetal", parent=turret_pivot, location=(0.34, -0.32, 0.56), bevel=0.008) + vc.make_box("turret_citv_lens", (0.12, 0.05, 0.09), "smoked_glass", parent=turret_pivot, location=(0.34, -0.42, 0.57), bevel=0.004) + vc.make_box("coax_bracket", (0.36, 0.42, 0.10), "gunmetal", parent=turret_pivot, location=(0.64, -0.22, 0.34), bevel=0.008) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + for k in range(3): + vc.make_tube_part( + f"smoke_tube_{tag}_{k}", 0.030, 0.030, 0.17, segments=8, + mat_name="gunmetal", parent=turret_pivot, + location=(side * 0.80, 0.36 + k * 0.10, 0.30), rotation_deg=(-58.0, 0.0, side * 22.0), + ) + + # --- 4. Visible Exterior Hardpoints (4x5 Dorsal Grid) --- + # 1) hp.armor.front (0,0, 4x1) + vc.add_hardpoint_slot( + "hp.armor.front", + "armor", + parent=chassis, + location=(0.0, -1.72, 0.94), + 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( + "hp.weapon.main", + "weapon", + parent=turret_pivot, + location=(0.0, -0.02, 0.51), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.82, 0.82, 0.11), + ) + # 3) hp.weapon.coax (0,1, 1x1) on left turret cheek bracket + vc.add_hardpoint_slot( + "hp.weapon.coax", + "weapon", + parent=turret_pivot, + location=(0.66, -0.22, 0.39), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.38, 0.38, 0.08), + ) + # 4) hp.armor.skirts (3,1, 1x2) on right (-X) track skirt + vc.add_hardpoint_slot( + "hp.armor.skirts", + "armor", + parent=chassis, + location=(-1.42, -0.38, 0.68), + rotation_deg=(90.0, 0.0, -90.0), + size=(1.28, 0.32, 0.09), + ) + # 5) hp.engine.rear (1,3, 2x2) + vc.add_hardpoint_slot( + "hp.engine.rear", + "engine", + parent=chassis, + location=(0.0, 1.48, 1.08), + rotation_deg=(-9.0, 0.0, 0.0), + size=(1.08, 0.92, 0.13), + ) + # 6 & 7) hp.radiator.l (0,3, 1x2) & hp.radiator.r (3,3, 1x2) + vc.add_hardpoint_slot( + "hp.radiator.l", + "radiator", + parent=chassis, + location=(1.36, 1.36, 0.78), + rotation_deg=(90.0, 0.0, 90.0), + size=(0.94, 0.44, 0.12), + ) + vc.add_hardpoint_slot( + "hp.radiator.r", + "radiator", + parent=chassis, + location=(-1.36, 1.36, 0.78), + rotation_deg=(90.0, 0.0, -90.0), + size=(0.94, 0.44, 0.12), + ) + + # --- 5. Export GLB, Manifest & Preview --- + glb_path = vc.ASSETS_VEHICLES_DIR / "ironclad" / "ironclad.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "ironclad" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "ironclad_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="ironclad", + name="Ironclad", + vehicle_class="Medium Tracked Battle Tank", + grid_width=4, + grid_height=5, + mask=[ + "####", + "####", + "####", + "####", + "####", + ], + hardpoints=[ + {"id": "hp.armor.front", "kind": "armor", "x": 0, "y": 0, "w": 4, "h": 1, "modelNodeId": "hp.armor.front"}, + {"id": "hp.weapon.coax", "kind": "weapon", "x": 0, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.weapon.coax"}, + {"id": "hp.weapon.main", "kind": "weapon", "x": 1, "y": 1, "w": 2, "h": 2, "modelNodeId": "hp.weapon.main"}, + {"id": "hp.armor.skirts", "kind": "armor", "x": 3, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.armor.skirts"}, + {"id": "hp.radiator.l", "kind": "radiator", "x": 0, "y": 3, "w": 1, "h": 2, "modelNodeId": "hp.radiator.l"}, + {"id": "hp.engine.rear", "kind": "engine", "x": 1, "y": 3, "w": 2, "h": 2, "modelNodeId": "hp.engine.rear"}, + {"id": "hp.radiator.r", "kind": "radiator", "x": 3, "y": 3, "w": 1, "h": 2, "modelNodeId": "hp.radiator.r"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[ironclad] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "ironclad", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_ironclad() diff --git a/tools/vehicles/build_jackal.py b/tools/vehicles/build_jackal.py new file mode 100644 index 0000000..97bd932 --- /dev/null +++ b/tools/vehicles/build_jackal.py @@ -0,0 +1,405 @@ +"""Build the Jackal (Light Wheeled Dune Buggy) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def build_jackal() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("JackalRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # Dimensions & key coordinates (Blender: -Y forward, +Z up, +X left) + front_y = -1.12 + rear_y = 1.08 + track_x = 0.84 + wheel_r = 0.41 + wheel_w = 0.29 + axle_z = wheel_r + + # --- 1. Belly pan & central backbone --- + vc.make_box("belly_pan", (0.76, 2.24, 0.08), "gunmetal", parent=chassis, location=(0.0, 0.0, 0.34), bevel=0.01) + vc.make_box("front_diff", (0.28, 0.28, 0.20), "gunmetal", parent=chassis, location=(0.0, front_y, 0.42), bevel=0.01) + vc.make_box("rear_transaxle", (0.34, 0.36, 0.24), "gunmetal", parent=chassis, location=(0.0, rear_y, 0.44), bevel=0.01) + + # --- 2. Tubular Chromoly Rollcage & Bullbar (Brokkr core.sweep) --- + r_main = 0.025 + r_brace = 0.020 + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + # Lower sill rail + vc.make_swept_tube( + f"cage_sill_{tag}", + [ + [side * 0.30, -1.42, 0.48], + [side * 0.48, -0.78, 0.36], + [side * 0.48, 0.56, 0.36], + [side * 0.42, 1.38, 0.56], + ], + r_main, + segments=8, + mat_name="gunmetal", + parent=chassis, + ) + # Main A-pillar -> roof rail -> fastback B/C-pillar + vc.make_swept_tube( + f"cage_arch_{tag}", + [ + [side * 0.34, -1.24, 0.62], + [side * 0.44, -0.70, 0.82], + [side * 0.39, -0.14, 1.44], + [side * 0.39, 0.44, 1.44], + [side * 0.42, 1.38, 0.82], + [side * 0.42, 1.38, 0.56], + ], + r_main, + segments=8, + mat_name="gunmetal", + parent=chassis, + ) + # Mid beltline side bar + diagonal door brace + vc.make_swept_tube( + f"cage_belt_{tag}", + [ + [side * 0.45, -0.70, 0.78], + [side * 0.48, 0.52, 0.78], + [side * 0.42, 1.36, 0.80], + ], + r_brace, + segments=8, + mat_name="gunmetal", + parent=chassis, + ) + vc.make_swept_tube( + f"cage_diag_{tag}", + [[side * 0.46, -0.45, 0.42], [side * 0.41, 0.42, 1.42]], + r_brace, + segments=8, + mat_name="gunmetal", + parent=chassis, + ) + # Shock tower hoop + vc.make_swept_tube( + f"shock_hoop_{tag}", + [ + [side * 0.32, -1.28, 0.54], + [side * 0.38, -1.04, 0.80], + [side * 0.38, -0.78, 0.74], + ], + r_brace, + segments=8, + mat_name="gunmetal", + parent=chassis, + ) + + # Transverse rollcage crossbars & front tubular bullbar + for idx, (y_pos, z_pos, half_w) in enumerate([ + (-0.70, 0.82, 0.44), + (-0.14, 1.44, 0.39), + (0.44, 1.44, 0.39), + (0.54, 0.78, 0.46), + (1.38, 0.82, 0.42), + (1.38, 0.56, 0.42), + ]): + vc.make_swept_tube( + f"cage_cross_{idx}", + [[-half_w, y_pos, z_pos], [half_w, y_pos, z_pos]], + r_brace, + segments=8, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.0, + ) + + # Front stinger bullbar + twin headlights + vc.make_swept_tube( + "front_bullbar", + [ + [-0.32, -1.40, 0.48], + [-0.24, -1.64, 0.56], + [-0.16, -1.68, 0.68], + [0.16, -1.68, 0.68], + [0.24, -1.64, 0.56], + [0.32, -1.40, 0.48], + ], + r_main, + segments=8, + mat_name="gunmetal", + parent=chassis, + ) + for side in (-1.0, 1.0): + vc.make_tube_part( + f"headlight_{'L' if side > 0 else 'R'}", + r0=0.045, + r1=0.055, + length=0.08, + segments=12, + mat_name="gunmetal", + parent=chassis, + location=(side * 0.28, -1.46, 0.66), + rotation_deg=(90.0, 0.0, 0.0), + ) + + # --- 3. Hard Armour Plates (Brokkr plate.v0) --- + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "jackal_side", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.47, -0.05, 0.58], + "normal": [1.0, 0.0, 0.14], + "up": [0.0, 0.0, 1.0], + "right": [0.0, -1.0, 0.0], + "outline": [[-0.58, -0.16], [0.58, -0.14], [0.68, 0.16], [-0.42, 0.22]], + "thick": 0.04, + "taper": 0.015, + "back": 0.92, + }, + "clad": { + "mat": "olive_armor", + "facets": "outer", + "min_area": 0.04, + "lifts": [0.008, 0.012], + "inset": 0.04, + "gap": 0.015, + "split": 0.55, + "seed": 401, + "bolt_r": 0.012, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.26, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + { + "name": "jackal_hood", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "one", + "mirror": False, + "slab": { + "at": [0.0, -0.98, 0.73], + "normal": [0.0, -0.32, 0.95], + "up": [0.0, -0.95, -0.32], + "right": [1.0, 0.0, 0.0], + "outline": [[-0.28, 0.30], [0.28, 0.30], [0.38, -0.28], [-0.38, -0.28]], + "thick": 0.045, + "taper": 0.018, + "back": 0.90, + }, + "clad": { + "mat": "olive_armor", + "facets": "outer", + "min_area": 0.05, + "lifts": [0.008, 0.014], + "inset": 0.04, + "gap": 0.014, + "split": 0.60, + "seed": 402, + "bolt_r": 0.012, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.24, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + { + "name": "jackal_roof", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "one", + "mirror": False, + "slab": { + "at": [0.0, 0.14, 1.455], + "normal": [0.0, 0.0, 1.0], + "up": [0.0, -1.0, 0.0], + "right": [1.0, 0.0, 0.0], + "outline": {"w": 0.74, "h": 0.62, "clip": 0.08}, + "thick": 0.036, + "taper": 0.012, + "back": 0.94, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.22, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # --- 4. Cockpit Seats & Firewall --- + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"seat_base_{tag}", (0.32, 0.34, 0.08), "rubber_dark", parent=chassis, location=(side * 0.20, 0.08, 0.42), bevel=0.01) + vc.make_box(f"seat_back_{tag}", (0.30, 0.08, 0.48), "rubber_dark", parent=chassis, location=(side * 0.20, 0.24, 0.68), rotation_deg=(14.0, 0.0, 0.0), bevel=0.01) + vc.make_box("rear_firewall", (0.76, 0.04, 0.42), "gunmetal", parent=chassis, location=(0.0, 0.46, 0.60), bevel=0.005) + vc.make_swept_tube("steer_col", [[0.18, -0.58, 0.80], [0.18, -0.34, 0.92]], 0.018, segments=8, mat_name="gunmetal", parent=chassis, fillet_r=0.0) + + # --- 5. Double-Wishbone Suspension, Coilovers & 4 Knobby Wheels --- + joints_manifest: list[dict] = [] + + for is_front, y_ax, prefix in [(True, front_y, "f"), (False, rear_y, "r")]: + for side, s_tag in [(1.0, "l"), (-1.0, "r")]: + j_suffix = f"{prefix}{s_tag}" + in_x = side * 0.24 + out_x = side * 0.68 + # Upper & lower A-arms (two separate wishbone legs meeting at the ball joint) + for leg_tag, dy in (("a", -0.16), ("b", 0.16)): + vc.make_swept_tube( + f"wishbone_lo_{j_suffix}_{leg_tag}", + [[in_x, y_ax + dy, 0.36], [out_x, y_ax, axle_z - 0.06]], + 0.018, + segments=6, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.0, + ) + for leg_tag, dy in (("a", -0.14), ("b", 0.14)): + vc.make_swept_tube( + f"wishbone_hi_{j_suffix}_{leg_tag}", + [[in_x, y_ax + dy, 0.52], [out_x, y_ax, axle_z + 0.08]], + 0.016, + segments=6, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.0, + ) + # Coilover shock strut from knuckle up to shock tower + tower_z = 0.80 if is_front else 0.86 + tower_y = y_ax + (0.04 if is_front else -0.06) + vc.make_ram_span( + f"coilover_{j_suffix}", + [side * 0.40, tower_y, tower_z], + [side * 0.62, y_ax, axle_z - 0.02], + body_r=0.028, + rod_r=0.016, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="gunmetal", + coil_rings=6, + ) + + # Steering knuckle (front only) + wheel hub spin joint + knuckle_loc = (side * track_x, y_ax, axle_z) + if is_front: + steer_id = f"joint.steer_{j_suffix}" + steer_node = vc.make_empty(steer_id, parent=chassis, location=(side * 0.68, y_ax, axle_z)) + vc.tag_joint(steer_node, steer_id, [0.0, 1.0, 0.0], -32.0, 32.0) + joints_manifest.append({"id": steer_id, "axis": [0.0, 1.0, 0.0], "min": -32.0, "max": 32.0}) + vc.make_box(f"knuckle_{j_suffix}", (0.08, 0.11, 0.18), "gunmetal", parent=steer_node, bevel=0.005) + wheel_parent = steer_node + wheel_loc = (side * (track_x - 0.68), 0.0, 0.0) + else: + vc.make_box(f"hub_carrier_{j_suffix}", (0.10, 0.12, 0.18), "gunmetal", parent=chassis, location=(side * 0.68, y_ax, axle_z), bevel=0.005) + wheel_parent = chassis + wheel_loc = knuckle_loc + + wheel_id = f"joint.wheel_{j_suffix}" + wheel_pivot = vc.make_knobby_wheel( + wheel_id, + radius=wheel_r, + width=wheel_w, + parent=wheel_parent, + location=wheel_loc, + tread_lugs=16, + rim_segments=18, + side_sign=int(side), + ) + wheel_pivot.name = wheel_id + vc.tag_joint(wheel_pivot, wheel_id, [1.0, 0.0, 0.0], -360.0, 360.0) + joints_manifest.append({"id": wheel_id, "axis": [1.0, 0.0, 0.0], "min": -360.0, "max": 360.0}) + + # --- 6. Visible Exterior Hardpoint Slots --- + # 1) Roof weapon collar ring + vc.add_hardpoint_slot( + "hp.weapon.roof", + "weapon", + parent=chassis, + location=(0.0, 0.14, 1.47), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.62, 0.62, 0.10), + ) + # 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.53), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.62, 0.72, 0.16), + ) + for side in (-1.0, 1.0): + vc.make_swept_tube( + f"exhaust_{'L' if side > 0 else 'R'}", + [ + [side * 0.24, 0.78, 0.68], + [side * 0.36, 1.12, 0.66], + [side * 0.38, 1.48, 0.74], + ], + 0.028, + segments=8, + mat_name="copper_rad", + parent=chassis, + ) + # 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.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.44, 0.95), bevel=0.008) + + # --- 7. Export GLB, Manifest & 4-Panel Preview --- + glb_path = vc.ASSETS_VEHICLES_DIR / "jackal" / "jackal.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "jackal" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "jackal_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="jackal", + name="Jackal", + vehicle_class="Light Wheeled Dune Buggy", + grid_width=3, + grid_height=4, + mask=[ + "###", + "###", + "###", + "###", + ], + hardpoints=[ + {"id": "hp.weapon.roof", "kind": "weapon", "x": 1, "y": 0, "w": 1, "h": 2, "modelNodeId": "hp.weapon.roof"}, + {"id": "hp.engine.rear", "kind": "engine", "x": 1, "y": 2, "w": 1, "h": 2, "modelNodeId": "hp.engine.rear"}, + {"id": "hp.radiator.rear", "kind": "radiator", "x": 2, "y": 3, "w": 1, "h": 1, "modelNodeId": "hp.radiator.rear"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[jackal] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "jackal", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_jackal() diff --git a/tools/vehicles/build_mammoth.py b/tools/vehicles/build_mammoth.py new file mode 100644 index 0000000..e4292ff --- /dev/null +++ b/tools/vehicles/build_mammoth.py @@ -0,0 +1,460 @@ +"""Build the Mammoth (Heavy 8x8 Armored Fire Support Rig) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import math +import sys +from pathlib import Path + +import bmesh +from mathutils import Matrix + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def build_mammoth() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("MammothRoot") + chassis = vc.make_empty("Chassis", parent=root) + + # Dimensions (Blender: -Y forward, +Z up, +X left) + axle_ys = [ + ("f1", -1.90, True), + ("f2", -0.74, True), + ("r1", 0.74, False), + ("r2", 1.90, False), + ] + track_x = 1.24 + wheel_r = 0.52 + wheel_w = 0.38 + axle_z = wheel_r + + # --- 1. Heavy Armored Lower Tub, Frame Rails, Axles & Suspension --- + vc.make_box("lower_tub", (1.64, 4.94, 0.62), "gunmetal", parent=chassis, location=(0.0, -0.02, 0.82), bevel=0.015) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"frame_rail_{tag}", (0.14, 5.10, 0.20), "gunmetal", parent=chassis, location=(side * 0.68, -0.04, 0.62), bevel=0.01) + # Side fuel tank / battery box tucked between front and rear tandem wheel pairs + vc.make_box(f"side_stowage_{tag}", (0.42, 0.72, 0.44), "olive_armor", parent=chassis, location=(side * 1.08, 0.0, 0.86), bevel=0.01) + # Crew entry door + boarding ladder step on mid-hull flank + vc.make_box(f"crew_step_{tag}", (0.16, 0.44, 0.06), "gunmetal", parent=chassis, location=(side * 1.32, 0.0, 0.62), bevel=0.006) + vc.make_box(f"crew_door_{tag}", (0.06, 0.56, 0.78), "olive_armor", parent=chassis, location=(side * 1.28, 0.0, 1.24), bevel=0.008) + + for idx, (a_tag, y_ax, _) in enumerate(axle_ys): + vc.make_tube_part( + f"axle_tube_{a_tag}", + 0.075, + 0.075, + track_x * 1.68, + segments=10, + mat_name="gunmetal", + parent=chassis, + location=(-track_x * 0.84, y_ax, axle_z), + rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_box(f"diff_{a_tag}", (0.34, 0.34, 0.28), "gunmetal", parent=chassis, location=(0.0, y_ax, axle_z), bevel=0.012) + for side in (-1.0, 1.0): + s_tag = "L" if side > 0 else "R" + vc.make_ram_span( + f"strut_{a_tag}_{s_tag}", + [side * 0.74, y_ax, 1.02], + [side * 0.98, y_ax, axle_z + 0.02], + body_r=0.040, + rod_r=0.022, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + coil_rings=0, + ) + + # --- 2. Faceted 8x8 Armored Hull & Bolted Sponson Plates (Brokkr plate.v0) --- + hull_pts = [ + # Lower hull belt above wheel arches (z = 1.14) + [-1.34, -2.26, 1.14], [1.34, -2.26, 1.14], + [-1.36, 2.26, 1.14], [1.36, 2.26, 1.14], + # Lower nose & lower tail bevel + [-1.08, -2.62, 1.02], [1.08, -2.62, 1.02], + [-1.12, 2.64, 1.12], [1.12, 2.64, 1.12], + # Roof deck (z = 1.66) + [-1.14, -1.78, 1.66], [1.14, -1.78, 1.66], + [-1.16, 1.88, 1.66], [1.16, 1.88, 1.66], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "mammoth_hull", + "mat": "olive_armor", + "bevel": 0.016, + "sides": "one", + "mirror": False, + "points": hull_pts, + "clad": { + "mat": "olive_armor", + "facets": [{"n": [0.0, -0.55, 0.83], "cos": 0.85}, {"n": [0.0, 0.0, 1.0], "cos": 0.95}], + "min_area": 0.18, + "lifts": [0.008, 0.014], + "inset": 0.06, + "gap": 0.018, + "split": 0.88, + "seed": 801, + "bolt_r": 0.014, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + }, + # Sloped upper side cheek armor with bolted applique panels + { + "name": "mammoth_side_cheek", + "mat": "olive_armor", + "bevel": 0.010, + "sides": "both", + "mirror": False, + "slab": { + "at": [1.26, -0.04, 1.40], + "normal": [0.92, 0.0, 0.38], + "up": [-0.38, 0.0, 0.92], + "right": [0.0, -1.0, 0.0], + "outline": [[-1.92, -0.24], [1.92, -0.24], [1.72, 0.24], [-1.72, 0.24]], + "thick": 0.055, + "taper": 0.015, + "back": 0.92, + }, + "clad": { + "mat": "olive_armor", + "facets": "outer", + "min_area": 0.14, + "lifts": [0.008, 0.014], + "inset": 0.05, + "gap": 0.016, + "split": 0.72, + "seed": 802, + "bolt_r": 0.013, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + "fits": [ + {"kind": "bolts", "inset": 0.025, "spacing": 0.36, "mat": "gunmetal", "params": "r=0.013"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Heavy flared wheel arches over all 4 wheel stations on each side + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + for a_tag, y_ax, _ in axle_ys: + # Top arch cap + angled front/rear lip flaps + vc.make_box(f"arch_top_{tag}_{a_tag}", (0.44, 0.68, 0.07), "olive_armor", parent=chassis, location=(side * 1.24, y_ax, 1.14), bevel=0.008) + vc.make_box(f"arch_f_{tag}_{a_tag}", (0.44, 0.32, 0.07), "olive_armor", parent=chassis, location=(side * 1.24, y_ax - 0.44, 1.02), rotation_deg=(36.0, 0.0, 0.0), bevel=0.008) + vc.make_box(f"arch_r_{tag}_{a_tag}", (0.44, 0.32, 0.07), "olive_armor", parent=chassis, location=(side * 1.24, y_ax + 0.44, 1.02), rotation_deg=(-36.0, 0.0, 0.0), bevel=0.008) + + # Front nose recessed grille, armored headlights, driver slit & rearview mirrors + vc.make_box("front_grille", (1.22, 0.14, 0.34), "socket_bay", parent=chassis, location=(0.0, -2.58, 0.96), bevel=0.008) + for k in range(4): + vc.make_box(f"grille_slat_{k}", (1.16, 0.06, 0.03), "gunmetal", parent=chassis, location=(0.0, -2.64, 0.86 + k * 0.07), bevel=0.003) + vc.make_box("driver_periscope", (0.56, 0.16, 0.10), "smoked_glass", parent=chassis, location=(-0.38, -1.96, 1.60), rotation_deg=(-22.0, 0.0, 0.0), bevel=0.005) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"headlight_box_{tag}", (0.24, 0.16, 0.16), "gunmetal", parent=chassis, location=(side * 0.88, -2.54, 1.06), bevel=0.008) + vc.make_box(f"headlight_lens_{tag}", (0.16, 0.04, 0.09), "smoked_glass", parent=chassis, location=(side * 0.88, -2.62, 1.06), bevel=0.003) + vc.make_box(f"tow_shackle_{tag}", (0.08, 0.14, 0.14), "signal_orange", parent=chassis, location=(side * 0.48, -2.66, 0.72), bevel=0.006) + # Rear corner tail light housing + vc.make_box(f"taillight_{tag}", (0.18, 0.12, 0.14), "gunmetal", parent=chassis, location=(side * 1.04, 2.58, 1.12), bevel=0.006) + + # --- 3. Reinforced Front Dozer Ram Plow --- + plow_root = vc.make_empty("dozer_plow", parent=chassis, location=(0.0, -2.86, 0.56)) + def build_plow_blade(bm: bmesh.types.BMesh) -> None: + # Curved multi-segment scoop profile extruded across width X = [-1.34, +1.34] + prof = [ + (-0.34, -0.34), # bottom cutting lip + (-0.22, -0.14), + (-0.04, 0.06), + (0.02, 0.26), + (-0.14, 0.42), # upper curved spill lip + (0.04, 0.42), + (0.14, 0.22), + (0.08, -0.12), + (-0.18, -0.34), + ] + hw = 1.34 + verts_l = [bm.verts.new((hw, y, z)) for (y, z) in prof] + verts_r = [bm.verts.new((-hw, y, z)) for (y, z) in prof] + n = len(prof) + for i in range(n): + j = (i + 1) % n + bm.faces.new([verts_l[i], verts_l[j], verts_r[j], verts_r[i]]) + bm.faces.new(verts_l) + bm.faces.new(list(reversed(verts_r))) + + vc.make_bmesh_object("plow_moldboard", build_plow_blade, "olive_armor", parent=plow_root, bevel=0.012) + vc.make_box("plow_cutting_edge", (2.72, 0.16, 0.07), "gunmetal", parent=plow_root, location=(0.0, -0.28, -0.32), rotation_deg=(16.0, 0.0, 0.0), bevel=0.006) + for gx in (-0.98, -0.48, 0.0, 0.48, 0.98): + vc.make_box(f"plow_rib_{gx:.2f}", (0.07, 0.18, 0.62), "gunmetal", parent=plow_root, location=(gx, 0.12, 0.06), bevel=0.006) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"plow_wing_{tag}", (0.12, 0.48, 0.68), "olive_armor", parent=plow_root, location=(side * 1.36, -0.10, 0.04), bevel=0.008) + # Hydraulic push arms + tilt rams + vc.make_box(f"plow_pusharm_{tag}", (0.12, 0.72, 0.14), "gunmetal", parent=chassis, location=(side * 0.66, -2.56, 0.56), bevel=0.008) + vc.make_ram_span( + f"plow_ram_{tag}", + [side * 0.66, -2.42, 0.90], + [side * 0.66, -2.80, 0.76], + body_r=0.042, + rod_r=0.024, + parent=chassis, + mat_barrel="gunmetal", + mat_rod="copper_rad", + ) + + # --- 4. Rear Diesel Exhaust Stacks --- + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_swept_tube( + f"exhaust_stack_{tag}", + [ + [side * 1.02, 2.24, 1.36], + [side * 1.06, 2.46, 1.56], + [side * 1.06, 2.46, 2.18], + [side * 1.06, 2.60, 2.30], + ], + 0.062, + segments=12, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.06, + ) + vc.make_tube_part( + f"exhaust_shield_{tag}", + 0.09, + 0.09, + 0.52, + segments=10, + inner0=0.078, + inner1=0.078, + mat_name="copper_rad", + parent=chassis, + location=(side * 1.06, 2.46, 1.62), + ) + + # --- 5. 8x8 Wheels & Front 4 Steering Knuckles --- + joints_manifest: list[dict] = [] + for a_tag, y_ax, steerable in axle_ys: + for side, s_tag in ((1.0, "l"), (-1.0, "r")): + j_suffix = f"{a_tag[0]}{s_tag}{a_tag[1]}" # fl1, fr1, fl2, fr2, rl1, rr1, rl2, rr2 + if steerable: + steer_id = f"joint.steer_{j_suffix}" + steer_node = vc.make_empty(steer_id, parent=chassis, location=(side * 0.98, y_ax, axle_z)) + vc.tag_joint(steer_node, steer_id, [0.0, 1.0, 0.0], -28.0, 28.0) + joints_manifest.append({"id": steer_id, "axis": [0.0, 1.0, 0.0], "min": -28.0, "max": 28.0}) + vc.make_box(f"knuckle_{j_suffix}", (0.10, 0.14, 0.22), "gunmetal", parent=steer_node, bevel=0.006) + wheel_parent = steer_node + wheel_loc = (side * (track_x - 0.98), 0.0, 0.0) + else: + vc.make_box(f"hub_carrier_{j_suffix}", (0.12, 0.16, 0.22), "gunmetal", parent=chassis, location=(side * 0.98, y_ax, axle_z), bevel=0.006) + wheel_parent = chassis + wheel_loc = (side * track_x, y_ax, axle_z) + + wheel_id = f"joint.wheel_{j_suffix}" + wheel_pivot = vc.make_knobby_wheel( + wheel_id, + radius=wheel_r, + width=wheel_w, + parent=wheel_parent, + location=wheel_loc, + tread_lugs=14, + rim_segments=16, + side_sign=int(side), + ) + wheel_pivot.name = wheel_id + vc.tag_joint(wheel_pivot, wheel_id, [1.0, 0.0, 0.0], -360.0, 360.0) + joints_manifest.append({"id": wheel_id, "axis": [1.0, 0.0, 0.0], "min": -360.0, "max": 360.0}) + + # --- 6. Broad Angular Central Turret (joint.turret_yaw) --- + turret_pivot = vc.make_empty("joint.turret_yaw", parent=chassis, location=(0.0, -0.18, 1.66)) + vc.tag_joint(turret_pivot, "joint.turret_yaw", [0.0, 1.0, 0.0], -180.0, 180.0) + joints_manifest.append({"id": "joint.turret_yaw", "axis": [0.0, 1.0, 0.0], "min": -180.0, "max": 180.0}) + + vc.make_tube_part("turret_race", 0.74, 0.80, 0.08, segments=24, mat_name="gunmetal", parent=turret_pivot) + turret_pts = [ + [-0.64, -0.78, 0.08], [0.64, -0.78, 0.08], + [0.84, -0.22, 0.08], [0.76, 0.94, 0.08], + [-0.76, 0.94, 0.08], [-0.84, -0.22, 0.08], + [-0.50, -0.60, 0.56], [0.50, -0.60, 0.56], + [0.64, -0.14, 0.56], [0.58, 0.78, 0.56], + [-0.58, 0.78, 0.56], [-0.64, -0.14, 0.56], + ] + turret_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "mammoth_turret_shell", + "mat": "olive_armor", + "bevel": 0.015, + "sides": "one", + "mirror": False, + "points": turret_pts, + }, + { + "name": "mammoth_turret_cheek", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.74, 0.14, 0.30], + "normal": [0.94, 0.0, 0.34], + "up": [-0.34, 0.0, 0.94], + "right": [0.0, -1.0, 0.0], + "outline": [[-0.52, -0.16], [0.52, -0.16], [0.42, 0.16], [-0.42, 0.16]], + "thick": 0.045, + "taper": 0.012, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.24, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + ], + } + vc.make_plates(turret_doc, parent=turret_pivot) + + # Turret bustle stowage rack, commander hatch, optics & smoke launchers + vc.make_box("turret_bustle", (1.08, 0.42, 0.34), "gunmetal", parent=turret_pivot, location=(0.0, 0.98, 0.34), bevel=0.01) + vc.make_tube_part("commander_cupola", 0.22, 0.24, 0.10, segments=14, mat_name="olive_armor", parent=turret_pivot, location=(-0.28, 0.34, 0.56)) + vc.make_box("turret_sight", (0.20, 0.22, 0.14), "smoked_glass", parent=turret_pivot, location=(0.24, -0.38, 0.62), bevel=0.008) + vc.make_box("turret_mantlet_bar", (0.94, 0.18, 0.18), "gunmetal", parent=turret_pivot, location=(0.0, -0.70, 0.30), bevel=0.01) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + for k in range(3): + vc.make_tube_part( + f"smoke_tube_{tag}_{k}", + 0.032, + 0.032, + 0.18, + segments=8, + mat_name="gunmetal", + parent=turret_pivot, + location=(side * 0.78, 0.42 + k * 0.10, 0.34), + rotation_deg=(-58.0, 0.0, side * 22.0), + ) + + # --- 7. Visible Exterior Hardpoints (4x6 Dorsal Grid) --- + # 1) hp.armor.glacis (0,0, 4x1) + vc.add_hardpoint_slot( + "hp.armor.glacis", + "armor", + parent=chassis, + location=(0.0, -2.20, 1.36), + 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) + vc.add_hardpoint_slot( + "hp.weapon.bow", + "weapon", + parent=chassis, + location=(0.88, -1.48, 1.68), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.46, 0.46, 0.09), + ) + # 3) hp.weapon.turret_l (1,1, 1x2) & 4) hp.weapon.turret_r (2,1, 1x2) on turret roof + vc.add_hardpoint_slot( + "hp.weapon.turret_l", + "weapon", + parent=turret_pivot, + location=(0.36, -0.10, 0.57), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.56, 0.56, 0.10), + ) + vc.add_hardpoint_slot( + "hp.weapon.turret_r", + "weapon", + parent=turret_pivot, + location=(-0.36, -0.10, 0.57), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.56, 0.56, 0.10), + ) + # 5) hp.armor.flanks (3,1, 1x2) on right (-X) upper cheek + vc.add_hardpoint_slot( + "hp.armor.flanks", + "armor", + parent=chassis, + location=(-1.32, -0.16, 1.38), + rotation_deg=(90.0, 0.0, -90.0), + size=(1.12, 0.32, 0.10), + ) + # 6) hp.engine.rear (1,3, 2x2) + vc.add_hardpoint_slot( + "hp.engine.rear", + "engine", + parent=chassis, + location=(0.0, 1.34, 1.66), + rotation_deg=(0.0, 0.0, 0.0), + size=(1.14, 1.04, 0.14), + ) + # 7 & 8) hp.radiator.l (0,4, 1x2) & hp.radiator.r (3,4, 1x2) + vc.add_hardpoint_slot( + "hp.radiator.l", + "radiator", + parent=chassis, + location=(1.28, 1.40, 1.38), + rotation_deg=(90.0, 0.0, 90.0), + size=(0.98, 0.44, 0.12), + ) + vc.add_hardpoint_slot( + "hp.radiator.r", + "radiator", + parent=chassis, + location=(-1.28, 1.40, 1.38), + rotation_deg=(90.0, 0.0, -90.0), + size=(0.98, 0.44, 0.12), + ) + + # --- 8. Export GLB, Manifest & Preview --- + glb_path = vc.ASSETS_VEHICLES_DIR / "mammoth" / "mammoth.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "mammoth" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "mammoth_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="mammoth", + name="Mammoth", + vehicle_class="Heavy 8x8 Armored Fire Support Rig", + grid_width=4, + grid_height=6, + mask=[ + "####", + "####", + "####", + "####", + "####", + "####", + ], + hardpoints=[ + {"id": "hp.armor.glacis", "kind": "armor", "x": 0, "y": 0, "w": 4, "h": 1, "modelNodeId": "hp.armor.glacis"}, + {"id": "hp.weapon.bow", "kind": "weapon", "x": 0, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.weapon.bow"}, + {"id": "hp.weapon.turret_l", "kind": "weapon", "x": 1, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.turret_l"}, + {"id": "hp.weapon.turret_r", "kind": "weapon", "x": 2, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.turret_r"}, + {"id": "hp.armor.flanks", "kind": "armor", "x": 3, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.armor.flanks"}, + {"id": "hp.engine.rear", "kind": "engine", "x": 1, "y": 3, "w": 2, "h": 2, "modelNodeId": "hp.engine.rear"}, + {"id": "hp.radiator.l", "kind": "radiator", "x": 0, "y": 4, "w": 1, "h": 2, "modelNodeId": "hp.radiator.l"}, + {"id": "hp.radiator.r", "kind": "radiator", "x": 3, "y": 4, "w": 1, "h": 2, "modelNodeId": "hp.radiator.r"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[mammoth] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "mammoth", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_mammoth() diff --git a/tools/vehicles/build_mule.py b/tools/vehicles/build_mule.py new file mode 100644 index 0000000..b5223dd --- /dev/null +++ b/tools/vehicles/build_mule.py @@ -0,0 +1,299 @@ +"""Build the Mule (Medium 6x6 Armored Gun Truck) chassis GLB, manifest.json, and preview.""" +from __future__ import annotations + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import vehicle_common as vc # noqa: E402 + + +def build_mule() -> dict: + vc.reset_scene() + vc.ensure_materials() + + root = vc.make_empty("MuleRoot") + chassis = vc.make_empty("Chassis", parent=root) + + front_y = -1.52 + mid_y = 0.88 + rear_y = 1.92 + track_x = 0.98 + wheel_r = 0.49 + wheel_w = 0.34 + axle_z = wheel_r + + # --- 1. Ladder Frame Rails, Axles, Bumper & Fuel Tanks --- + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"frame_rail_{tag}", (0.12, 4.54, 0.18), "gunmetal", parent=chassis, location=(side * 0.46, 0.0, 0.62), bevel=0.008) + # Side cylindrical fuel tanks (Brokkr mechanical kit tank) + vc.make_kit_part( + f"fuel_tank_{tag}", + "mechanical", + "tank", + {"radius": 0.19, "length": 0.86, "segments": 14}, + mat_name="gunmetal", + parent=chassis, + location=(side * 0.78, -0.35, 0.56), + rotation_deg=(90.0, 0.0, 0.0), + ) + + for idx, y_ax in enumerate((front_y, mid_y, rear_y)): + vc.make_tube_part( + f"axle_tube_{idx}", + 0.065, + 0.065, + track_x * 1.66, + segments=10, + mat_name="gunmetal", + parent=chassis, + location=(-track_x * 0.83, y_ax, axle_z), + rotation_deg=(0.0, 90.0, 0.0), + ) + vc.make_box(f"diff_{idx}", (0.28, 0.28, 0.24), "gunmetal", parent=chassis, location=(0.0, y_ax, axle_z), bevel=0.01) + + # Heavy front steel bumper + tow shackles + vc.make_box("front_bumper", (2.16, 0.24, 0.24), "gunmetal", parent=chassis, location=(0.0, -2.26, 0.66), bevel=0.014) + for side in (-1.0, 1.0): + vc.make_box(f"bumper_shackle_{'L' if side > 0 else 'R'}", (0.07, 0.12, 0.14), "signal_orange", parent=chassis, location=(side * 0.52, -2.40, 0.62), bevel=0.006) + vc.make_box(f"headlight_box_{'L' if side > 0 else 'R'}", (0.16, 0.12, 0.14), "gunmetal", parent=chassis, location=(side * 0.78, -2.18, 0.92), bevel=0.008) + + # --- 2. Armored Hood & Sloped Armored Cab (Brokkr plate.v0 + faceted cab) --- + # Hood core + front grille frame + vc.make_box("hood_core", (1.36, 1.06, 0.60), "olive_armor", parent=chassis, location=(0.0, -1.66, 1.04), bevel=0.015) + vc.make_box("cab_lower", (1.84, 1.18, 0.68), "olive_armor", parent=chassis, location=(0.0, -0.54, 1.06), bevel=0.015) + + # Sloped upper armored cab via plate.v0 convex hull ("faces" / "points") + cab_pts = [ + [-0.90, -1.12, 1.34], [0.90, -1.12, 1.34], + [0.90, 0.04, 1.34], [-0.90, 0.04, 1.34], + [-0.78, -0.82, 2.02], [0.78, -0.82, 2.02], + [0.80, 0.02, 2.02], [-0.80, 0.02, 2.02], + ] + plates_doc = { + "schema": "brokkr.plates.v0", + "plates": [ + { + "name": "mule_cab_upper", + "mat": "olive_armor", + "bevel": 0.016, + "sides": "one", + "mirror": False, + "points": cab_pts, + }, + # Flared front wheel fenders + { + "name": "mule_fender_front", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.92, -1.52, 1.08], + "normal": [0.18, 0.0, 0.98], + "up": [0.0, -1.0, 0.0], + "right": [0.98, 0.0, -0.18], + "outline": [[-0.24, 0.54], [0.24, 0.54], [0.24, -0.54], [-0.24, -0.54]], + "thick": 0.06, + "taper": 0.015, + "back": 0.92, + }, + "fits": [ + {"kind": "bolts", "inset": 0.02, "spacing": 0.28, "mat": "gunmetal", "params": "r=0.012"}, + ], + }, + # Armored cab doors with stepped clad panels + { + "name": "mule_door", + "mat": "olive_armor", + "bevel": 0.008, + "sides": "both", + "mirror": False, + "slab": { + "at": [0.93, -0.54, 1.18], + "normal": [1.0, 0.0, 0.0], + "up": [0.0, 0.0, 1.0], + "right": [0.0, -1.0, 0.0], + "outline": [[-0.44, -0.34], [0.44, -0.34], [0.40, 0.36], [-0.44, 0.36]], + "thick": 0.04, + "taper": 0.012, + "back": 0.94, + }, + "clad": { + "mat": "olive_armor", + "facets": "outer", + "min_area": 0.06, + "lifts": [0.008, 0.012], + "inset": 0.04, + "gap": 0.014, + "split": 0.65, + "seed": 501, + "bolt_r": 0.012, + "bolt_mat": "gunmetal", + "bevel": 0.004, + }, + "fits": [ + {"kind": "part", "part": "handle", "at": [0.24, -0.04], "roll": 0.0, "mat": "gunmetal", "params": "length=0.20;lift=0.045;r=0.012"}, + ], + }, + ], + } + vc.make_plates(plates_doc, parent=chassis) + + # Armored smoked glass windshield slit & side viewports + vc.make_box("windshield_slit", (1.28, 0.08, 0.16), "smoked_glass", parent=chassis, location=(0.0, -0.98, 1.68), rotation_deg=(-22.0, 0.0, 0.0), bevel=0.004) + for side in (-1.0, 1.0): + vc.make_box(f"side_glass_{'L' if side > 0 else 'R'}", (0.06, 0.46, 0.22), "smoked_glass", parent=chassis, location=(side * 0.86, -0.46, 1.66), rotation_deg=(0.0, side * -12.0, 0.0), bevel=0.004) + + # --- 3. Open Armored Cargo Bed + Rear Mudguards --- + vc.make_box("bed_floor", (2.06, 2.26, 0.12), "gunmetal", parent=chassis, location=(0.0, 1.24, 0.92), bevel=0.01) + # Bed side walls (stepped armor with ribs & tubular top grab rail) + for side in (-1.0, 1.0): + tag = "L" if side > 0 else "R" + vc.make_box(f"bed_wall_{tag}", (0.10, 2.22, 0.68), "olive_armor", parent=chassis, location=(side * 0.98, 1.24, 1.32), bevel=0.01) + for ry in (0.35, 0.95, 1.55, 2.15): + vc.make_box(f"bed_rib_{tag}_{ry:.2f}", (0.05, 0.08, 0.64), "olive_armor", parent=chassis, location=(side * 1.04, ry, 1.32), bevel=0.004) + vc.make_swept_tube( + f"bed_rail_{tag}", + [[side * 0.98, 0.16, 1.68], [side * 0.98, 0.16, 1.82], [side * 0.98, 2.32, 1.82], [side * 0.98, 2.32, 1.68]], + 0.022, + segments=8, + mat_name="gunmetal", + parent=chassis, + fillet_r=0.03, + ) + # Rear tandem fender flare + vc.make_box(f"rear_fender_{tag}", (0.38, 1.98, 0.08), "olive_armor", parent=chassis, location=(side * 0.94, 1.40, 1.06), bevel=0.008) + + # Tailgate + vc.make_box("bed_tailgate", (1.92, 0.10, 0.62), "olive_armor", parent=chassis, location=(0.0, 2.32, 1.29), bevel=0.01) + # Central turret pedestal drum in cargo bed + vc.make_tube_part("bed_pedestal", 0.44, 0.48, 0.58, segments=16, mat_name="gunmetal", parent=chassis, location=(0.0, 1.36, 0.98)) + + # --- 4. 6x6 Off-Road Wheels & Front Steering Knuckles --- + joints_manifest: list[dict] = [] + for axle_tag, y_ax, steerable in (("f", front_y, True), ("m", mid_y, False), ("r", rear_y, False)): + for side, s_tag in ((1.0, "l"), (-1.0, "r")): + j_suffix = f"{axle_tag}{s_tag}" + if steerable: + steer_id = f"joint.steer_{j_suffix}" + steer_node = vc.make_empty(steer_id, parent=chassis, location=(side * 0.80, y_ax, axle_z)) + vc.tag_joint(steer_node, steer_id, [0.0, 1.0, 0.0], -30.0, 30.0) + joints_manifest.append({"id": steer_id, "axis": [0.0, 1.0, 0.0], "min": -30.0, "max": 30.0}) + wheel_parent = steer_node + wheel_loc = (side * (track_x - 0.80), 0.0, 0.0) + else: + wheel_parent = chassis + wheel_loc = (side * track_x, y_ax, axle_z) + + wheel_id = f"joint.wheel_{j_suffix}" + wheel_pivot = vc.make_knobby_wheel( + wheel_id, + radius=wheel_r, + width=wheel_w, + parent=wheel_parent, + location=wheel_loc, + tread_lugs=16, + rim_segments=18, + side_sign=int(side), + ) + wheel_pivot.name = wheel_id + vc.tag_joint(wheel_pivot, wheel_id, [1.0, 0.0, 0.0], -360.0, 360.0) + joints_manifest.append({"id": wheel_id, "axis": [1.0, 0.0, 0.0], "min": -360.0, "max": 360.0}) + + # --- 5. Visible Exterior Hardpoints (3x5 Dorsal Grid) --- + # Front bumper/grille armor rail + vc.add_hardpoint_slot( + "hp.armor.front", + "armor", + parent=chassis, + 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( + "hp.engine.front", + "engine", + parent=chassis, + location=(0.0, -1.66, 1.32), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.88, 0.86, 0.14), + ) + # Cab roof weapon pintle ring + vc.add_hardpoint_slot( + "hp.weapon.cab", + "weapon", + parent=chassis, + location=(0.0, -0.44, 2.02), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.56, 0.56, 0.09), + ) + # Main cargo-bed turret ring + vc.add_hardpoint_slot( + "hp.weapon.bed_main", + "weapon", + parent=chassis, + location=(0.0, 1.36, 1.56), + rotation_deg=(0.0, 0.0, 0.0), + size=(0.98, 0.98, 0.12), + ) + # Twin flank radiator louver pods behind cab (horizontal louvers: local +Y = +Z up) + vc.add_hardpoint_slot( + "hp.radiator.left", + "radiator", + parent=chassis, + location=(1.04, 0.56, 1.40), + rotation_deg=(90.0, 0.0, 90.0), + size=(0.78, 0.72, 0.14), + ) + vc.add_hardpoint_slot( + "hp.radiator.right", + "radiator", + parent=chassis, + location=(-1.04, 0.56, 1.40), + rotation_deg=(90.0, 0.0, -90.0), + size=(0.78, 0.72, 0.14), + ) + + # --- 6. Export GLB, Manifest & Preview --- + glb_path = vc.ASSETS_VEHICLES_DIR / "mule" / "mule.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / "mule" / "manifest.json" + preview_path = vc.PREVIEWS_DIR / "mule_preview.png" + + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root) + vc.write_manifest( + manifest_path, + vehicle_id="mule", + name="Mule", + vehicle_class="Medium 6x6 Armored Gun Truck", + grid_width=3, + grid_height=5, + mask=[ + "###", + "###", + "###", + "###", + "###", + ], + hardpoints=[ + {"id": "hp.armor.front", "kind": "armor", "x": 0, "y": 0, "w": 3, "h": 1, "modelNodeId": "hp.armor.front"}, + {"id": "hp.radiator.left", "kind": "radiator", "x": 0, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.radiator.left"}, + {"id": "hp.engine.front", "kind": "engine", "x": 1, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.engine.front"}, + {"id": "hp.radiator.right", "kind": "radiator", "x": 2, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.radiator.right"}, + {"id": "hp.weapon.cab", "kind": "weapon", "x": 0, "y": 3, "w": 1, "h": 1, "modelNodeId": "hp.weapon.cab"}, + {"id": "hp.weapon.bed_main", "kind": "weapon", "x": 1, "y": 3, "w": 2, "h": 2, "modelNodeId": "hp.weapon.bed_main"}, + ], + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + ) + vc.render_four_panel_preview(preview_path) + print(f"[mule] tris={tri_count} bounds={bounds} glb={glb_path}") + return {"id": "mule", "tris": tri_count, "bounds": bounds} + + +if __name__ == "__main__": + build_mule() diff --git a/tools/vehicles/previews/anvil_preview.png b/tools/vehicles/previews/anvil_preview.png new file mode 100644 index 0000000..4e5fc09 Binary files /dev/null and b/tools/vehicles/previews/anvil_preview.png differ diff --git a/tools/vehicles/previews/bastion_preview.png b/tools/vehicles/previews/bastion_preview.png new file mode 100644 index 0000000..96022c9 Binary files /dev/null and b/tools/vehicles/previews/bastion_preview.png differ diff --git a/tools/vehicles/previews/breaker_preview.png b/tools/vehicles/previews/breaker_preview.png new file mode 100644 index 0000000..9dbe35e Binary files /dev/null and b/tools/vehicles/previews/breaker_preview.png differ diff --git a/tools/vehicles/previews/condor_preview.png b/tools/vehicles/previews/condor_preview.png new file mode 100644 index 0000000..c8ef101 Binary files /dev/null and b/tools/vehicles/previews/condor_preview.png differ diff --git a/tools/vehicles/previews/ferret_preview.png b/tools/vehicles/previews/ferret_preview.png new file mode 100644 index 0000000..a6fe46e Binary files /dev/null and b/tools/vehicles/previews/ferret_preview.png differ diff --git a/tools/vehicles/previews/hornet_preview.png b/tools/vehicles/previews/hornet_preview.png new file mode 100644 index 0000000..dbdf035 Binary files /dev/null and b/tools/vehicles/previews/hornet_preview.png differ diff --git a/tools/vehicles/previews/ironclad_preview.png b/tools/vehicles/previews/ironclad_preview.png new file mode 100644 index 0000000..2c217db Binary files /dev/null and b/tools/vehicles/previews/ironclad_preview.png differ diff --git a/tools/vehicles/previews/jackal_preview.png b/tools/vehicles/previews/jackal_preview.png new file mode 100644 index 0000000..7cf2b1a Binary files /dev/null and b/tools/vehicles/previews/jackal_preview.png differ diff --git a/tools/vehicles/previews/kestrel_preview.png b/tools/vehicles/previews/kestrel_preview.png new file mode 100644 index 0000000..3e03632 Binary files /dev/null and b/tools/vehicles/previews/kestrel_preview.png differ diff --git a/tools/vehicles/previews/mammoth_preview.png b/tools/vehicles/previews/mammoth_preview.png new file mode 100644 index 0000000..ce921ce Binary files /dev/null and b/tools/vehicles/previews/mammoth_preview.png differ diff --git a/tools/vehicles/previews/manticore_preview.png b/tools/vehicles/previews/manticore_preview.png new file mode 100644 index 0000000..e90a2bb Binary files /dev/null and b/tools/vehicles/previews/manticore_preview.png differ diff --git a/tools/vehicles/previews/mule_preview.png b/tools/vehicles/previews/mule_preview.png new file mode 100644 index 0000000..5180720 Binary files /dev/null and b/tools/vehicles/previews/mule_preview.png differ diff --git a/tools/vehicles/previews/paladin_preview.png b/tools/vehicles/previews/paladin_preview.png new file mode 100644 index 0000000..8cebb84 Binary files /dev/null and b/tools/vehicles/previews/paladin_preview.png differ diff --git a/tools/vehicles/previews/raptor_preview.png b/tools/vehicles/previews/raptor_preview.png new file mode 100644 index 0000000..6e662e4 Binary files /dev/null and b/tools/vehicles/previews/raptor_preview.png differ diff --git a/tools/vehicles/previews/spectre_preview.png b/tools/vehicles/previews/spectre_preview.png new file mode 100644 index 0000000..9506ebb Binary files /dev/null and b/tools/vehicles/previews/spectre_preview.png differ diff --git a/tools/vehicles/retrofit_mechs.py b/tools/vehicles/retrofit_mechs.py new file mode 100644 index 0000000..9e0b8ae --- /dev/null +++ b/tools/vehicles/retrofit_mechs.py @@ -0,0 +1,2391 @@ +"""Retrofit Brokkr kit-built mechs for Rust to Dust: +- Strip built-in weapon loadouts and studio backdrop/rig helpers (read-only on source .blend/.json). +- Normalize procedural Brokkr shaders to clean glTF 2.0 Principled BSDF PBR materials. +- Apply skinning-preserving / silhouette-preserving LOD decimation (target ~26k-32k tris). +- Reorient from Brokkr (+Y forward, -X left) to RTD (+Z forward glTF / -Y Blender, +X left), grounded at minY = 0. +- Attach visible exterior hardpoint collars/bays (`add_hardpoint_slot`) and joint tags (`tag_joint`). +- Emit `.glb`, `manifest.json` (including `mechanisms` when model JSON has rams/scissors/struts), and 4-panel preview PNG. + +Adding a future Brokkr mech (e.g. `bastion`, `seraph`): add a `MechRetrofitSpec` entry in `SPECS`. +""" +from __future__ import annotations + +import argparse +import json +import math +import sys +from dataclasses import dataclass, field +from pathlib import Path +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 + + +@dataclass(frozen=True) +class HardpointMount: + hp_id: str + kind: str + x: int + y: int + w: int + h: int + parent_name: str + parent_bone: str | None + world_pos: tuple[float, float, float] + world_normal: tuple[float, float, float] + size: tuple[float, float, float] + + +@dataclass(frozen=True) +class JointTagSpec: + joint_id: str + target_name: str + parent_bone: str | None + axis_gltf: tuple[float, float, float] + min_val: float + max_val: float + + +@dataclass(frozen=True) +class MechRetrofitSpec: + mech_id: str + name: str + vehicle_class: str + plane: str + grid_width: int + grid_height: int + mask: tuple[str, ...] + blend_path: Path + model_json_path: Path | None + target_mech_tris: int + drop_collections: tuple[str, ...] = () + strip_prefixes: tuple[str, ...] = () + strip_vertex_groups: tuple[str, ...] = () + strip_islands: tuple[tuple[str, str, float], ...] = () + armature_name: str | None = None + hardpoints: tuple[HardpointMount, ...] = () + joints: tuple[JointTagSpec, ...] = () + extra_notes: str = "" + + +SPECS: dict[str, MechRetrofitSpec] = { + "breaker": MechRetrofitSpec( + mech_id="breaker", + name="Breaker", + vehicle_class="Heavy Assault Biped", + plane="Coronal", + grid_width=5, + grid_height=6, + mask=( + ".###.", + "#####", + "#####", + "#####", + ".#.#.", + ".#.#.", + ), + 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, "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", "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( + mech_id="paladin", + name="Paladin", + vehicle_class="Heavy Assault Biped", + plane="Coronal", + grid_width=6, + grid_height=7, + mask=( + "..##..", + ".####.", + "######", + "######", + ".####.", + ".#..#.", + ".#..#.", + ), + blend_path=Path(r"F:\aeth-wt\fable-paladin-3\out\paladin\paladin.blend"), + model_json_path=None, + 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.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)), + ), + joints=( + JointTagSpec("joint.torso_yaw", "Trunk", None, (0.0, 1.0, 0.0), -90.0, 90.0), + JointTagSpec("joint.arm_l_pitch", "ArmL.Upper", None, (1.0, 0.0, 0.0), -40.0, 70.0), + JointTagSpec("joint.arm_r_pitch", "ArmR.Upper", None, (1.0, 0.0, 0.0), -40.0, 70.0), + ), + ), + "raptor": MechRetrofitSpec( + mech_id="raptor", + name="Raptor", + vehicle_class="Medium Theropod Biped", + plane="Coronal", + grid_width=5, + grid_height=6, + mask=( + "..#..", + ".###.", + "#####", + "#.#.#", + ".#.#.", + ".#.#.", + ), + blend_path=Path(r"F:\aeth-wt\fable-raptor-4\out\raptor\raptor.blend"), + model_json_path=None, + 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.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), + JointTagSpec("joint.arm_r_pitch", "ArmR.Upper", None, (1.0, 0.0, 0.0), -45.0, 45.0), + ), + ), + "manticore": MechRetrofitSpec( + mech_id="manticore", + name="Manticore", + vehicle_class="Heavy Quadruped Scorpion", + plane="Dorsal", + grid_width=5, + grid_height=5, + mask=( + "#####", + ".###.", + "#####", + ".###.", + "#.#.#", + ), + blend_path=Path(r"F:\aeth-wt\fable-manticore-3\out\manticore\manticore.blend"), + model_json_path=None, + target_mech_tris=28000, + strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "Laser.light", "Launcher.", "ArmGunL.", "ArmGunR."), + hardpoints=( + HardpointMount("hp.weapon.chin", "weapon", 2, 0, 1, 1, "Hull", None, (0.0, 3.34, 1.38), (0.0, 0.94, -0.34), (0.64, 0.64, 0.12)), + HardpointMount("hp.radiator.flank_l", "radiator", 1, 1, 1, 1, "Hull", None, (-1.18, -0.35, 2.76), (-0.22, 0.0, 0.97), (0.56, 0.98, 0.12)), + HardpointMount("hp.engine.core", "engine", 2, 1, 1, 2, "Hull", None, (0.0, -0.25, 2.94), (0.0, 0.14, 0.99), (0.86, 1.20, 0.14)), + HardpointMount("hp.radiator.flank_r", "radiator", 3, 1, 1, 1, "Hull", None, (1.18, -0.35, 2.76), (0.22, 0.0, 0.97), (0.56, 0.98, 0.12)), + HardpointMount("hp.weapon.l", "weapon", 0, 2, 1, 1, "ArmL.Upper", None, (-0.96, 2.75, 0.72), (-0.65, 0.76, 0.0), (0.56, 0.56, 0.11)), + HardpointMount("hp.weapon.r", "weapon", 4, 2, 1, 1, "ArmR.Upper", None, (0.96, 2.75, 0.72), (0.65, 0.76, 0.0), (0.56, 0.56, 0.11)), + HardpointMount("hp.armor.prow", "armor", 2, 3, 1, 1, "Hull", None, (0.0, 3.14, 1.94), (0.0, 0.85, 0.53), (0.88, 0.34, 0.11)), + ), + joints=( + JointTagSpec("joint.tail_yaw", "Tail.Coxa", None, (0.0, 1.0, 0.0), -75.0, 75.0), + JointTagSpec("joint.tail_s1", "Tail.S1", None, (1.0, 0.0, 0.0), -60.0, 60.0), + JointTagSpec("joint.tail_s2", "Tail.S2", None, (1.0, 0.0, 0.0), -75.0, 15.0), + JointTagSpec("joint.tail_s3", "Tail.S3", None, (1.0, 0.0, 0.0), -80.0, 10.0), + JointTagSpec("joint.tail_elev", "Tail.Elev", None, (1.0, 0.0, 0.0), -40.0, 30.0), + ), + ), + "bastion": MechRetrofitSpec( + mech_id="bastion", + name="Bastion", + vehicle_class="Heavy Siege Quadruped", + plane="Dorsal", + grid_width=6, + grid_height=6, + mask=( + "..##..", + ".####.", + "######", + "######", + ".####.", + ".#..#.", + ), + blend_path=Path(r"F:\aeth-wt\fable-bastion-2\out\bastion\bastion.blend"), + model_json_path=None, + target_mech_tris=32000, + strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "Aim.Gun", "Gun.", "Magazine.", "Interceptor."), + hardpoints=( + HardpointMount("hp.armor.prow", "armor", 2, 0, 2, 1, "Trunk", None, (0.0, 5.16, 6.50), (0.0, 0.29, 0.96), (1.35, 0.42, 0.12)), + HardpointMount("hp.weapon.turret_pd", "weapon", 1, 1, 1, 1, "Aim.Turret", None, (0.0, -1.80, 9.11), (0.0, 0.0, 1.0), (0.68, 0.68, 0.12)), + HardpointMount("hp.weapon.turret_main", "weapon", 2, 1, 2, 2, "Aim.Turret", None, (0.0, 0.45, 9.07), (0.0, 0.03, 1.0), (1.30, 1.30, 0.16)), + HardpointMount("hp.weapon.flank_l", "weapon", 0, 2, 1, 2, "Trunk", None, (-3.70, -0.22, 6.18), (-1.0, 0.0, 0.0), (0.85, 0.85, 0.14)), + HardpointMount("hp.weapon.flank_r", "weapon", 5, 2, 1, 2, "Trunk", None, (3.70, -0.22, 6.18), (1.0, 0.0, 0.0), (0.85, 0.85, 0.14)), + HardpointMount("hp.engine.core", "engine", 2, 3, 2, 2, "Trunk", None, (0.0, -5.70, 7.34), (0.0, 0.0, 1.0), (1.50, 1.35, 0.16)), + HardpointMount("hp.radiator.rear_l", "radiator", 1, 4, 1, 2, "Trunk", None, (-2.55, -5.75, 7.38), (0.0, 0.0, 1.0), (0.98, 1.38, 0.14)), + HardpointMount("hp.radiator.rear_r", "radiator", 4, 4, 1, 2, "Trunk", None, (2.55, -5.75, 7.38), (0.0, 0.0, 1.0), (0.98, 1.38, 0.14)), + ), + joints=( + JointTagSpec("joint.turret_yaw", "Aim.Turret", None, (0.0, 1.0, 0.0), -180.0, 180.0), + ), + ), + "spectre": MechRetrofitSpec( + mech_id="spectre", + name="Spectre", + vehicle_class="Medium Recon/Skirmisher Biped", + plane="Coronal", + grid_width=5, + grid_height=6, + mask=( + ".#...", + ".###.", + "#####", + "#####", + ".#.#.", + ".#.#.", + ), + blend_path=Path(r"F:\aeth-wt\fable-spectre-3\out\spectre\spectre.blend"), + model_json_path=None, + target_mech_tris=27000, + strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "Rack.", "RackTail.", "GunL.lamp", "GunR.lamp", "GunR.glass"), + strip_islands=( + ("GunL.gunmetal", "max_y>", 2.0), + ("GunR.gunmetal", "max_y>", 3.15), + ("GunR.khaki", "max_y>", 3.15), + ), + hardpoints=( + HardpointMount("hp.weapon.shoulder_l", "weapon", 1, 0, 1, 1, "Waist", None, (-2.22, 0.15, 7.48), (-0.17, 0.23, 0.96), (0.78, 0.78, 0.13)), + HardpointMount("hp.armor.torso", "armor", 2, 1, 1, 1, "Waist", None, (0.0, 3.10, 5.68), (0.0, 0.11, -0.99), (0.74, 0.28, 0.10)), + HardpointMount("hp.weapon.arm_l", "weapon", 0, 2, 1, 2, "ShoulderL", None, (-2.81, 1.75, 5.15), (-1.0, 0.0, 0.0), (0.52, 0.52, 0.11)), + HardpointMount("hp.radiator.back_l", "radiator", 1, 2, 1, 1, "Waist", None, (-2.20, -0.79, 7.00), (0.0, -1.0, 0.0), (0.76, 0.96, 0.12)), + HardpointMount("hp.engine.core", "engine", 2, 2, 1, 2, "Waist", None, (0.0, -2.30, 7.00), (0.0, -1.0, 0.0), (0.86, 1.18, 0.14)), + HardpointMount("hp.radiator.back_r", "radiator", 3, 2, 1, 1, "Waist", None, (2.20, -0.79, 7.00), (0.0, -1.0, 0.0), (0.76, 0.96, 0.12)), + HardpointMount("hp.weapon.arm_r", "weapon", 4, 2, 1, 2, "ShoulderR", None, (2.66, 1.75, 5.05), (1.0, 0.0, 0.0), (0.52, 0.52, 0.11)), + ), + joints=( + JointTagSpec("joint.torso_yaw", "Waist", None, (0.0, 1.0, 0.0), -90.0, 90.0), + JointTagSpec("joint.arm_l_pitch", "ShoulderL", None, (1.0, 0.0, 0.0), -45.0, 60.0), + JointTagSpec("joint.arm_r_pitch", "ShoulderR", None, (1.0, 0.0, 0.0), -45.0, 60.0), + ), + ), + "kestrel": MechRetrofitSpec( + mech_id="kestrel", + name="Kestrel", + vehicle_class="Light Scout Biped", + plane="Coronal", + grid_width=5, + grid_height=5, + mask=( + "..#..", + ".###.", + ".####", + ".####", + ".#.#.", + ), + blend_path=Path(r"F:\aeth-wt\fable-kestrel-2\out\kestrel\kestrel.blend"), + model_json_path=None, + target_mech_tris=27000, + strip_prefixes=("Rig", "Cam", "Sun", "Back", "Bounce", "Ground", "Horizon", "WeaponArm.accent_yellow"), + strip_islands=( + ("WeaponArm.gunmetal", "max_y>", 2.30), + ), + hardpoints=( + HardpointMount("hp.weapon.dorsal", "weapon", 2, 0, 1, 1, "Torso.pose", None, (0.0, 0.23, 9.25), (0.0, 0.38, 0.92), (0.56, 0.56, 0.11)), + HardpointMount("hp.armor.chest", "armor", 2, 1, 1, 1, "Torso.pose", None, (0.0, 2.28, 6.87), (0.0, 0.88, -0.47), (0.72, 0.32, 0.10)), + HardpointMount("hp.radiator.back", "radiator", 1, 2, 1, 1, "Torso.pose", None, (-1.02, -1.86, 8.35), (0.0, -0.97, 0.26), (0.58, 0.78, 0.11)), + HardpointMount("hp.engine.core", "engine", 2, 2, 1, 2, "Torso.pose", None, (0.0, -1.72, 8.20), (0.0, -0.93, 0.36), (0.76, 1.02, 0.13)), + HardpointMount("hp.weapon.arm_r", "weapon", 4, 2, 1, 2, "ArmR", None, (2.29, 1.15, 5.95), (1.0, 0.0, 0.0), (0.46, 0.46, 0.10)), + ), + joints=( + JointTagSpec("joint.torso_yaw", "Torso.pose", None, (0.0, 1.0, 0.0), -90.0, 90.0), + JointTagSpec("joint.arm_l_pitch", "ArmL", None, (1.0, 0.0, 0.0), -45.0, 60.0), + JointTagSpec("joint.arm_r_pitch", "ArmR", None, (1.0, 0.0, 0.0), -45.0, 60.0), + ), + ), +} + + +def _should_strip(name: str, prefixes: tuple[str, ...]) -> bool: + return any(name == p or name.startswith(p) or name.startswith(p.rstrip(".")) and name == p.rstrip(".") for p in prefixes) + + +def _remove_object_recursive(obj: bpy.types.Object) -> None: + for ch in list(obj.children): + _remove_object_recursive(ch) + if obj.name in bpy.data.objects: + bpy.data.objects.remove(obj, do_unlink=True) + + +def _strip_scene_objects(spec: MechRetrofitSpec) -> list[str]: + stripped: list[str] = [] + + # 1. Drop excluded build collections (e.g. breaker.build) + for col_name in spec.drop_collections: + col = bpy.data.collections.get(col_name) + if col is not None: + for obj_name in [o.name for o in col.objects]: + stripped.append(obj_name) + obj = bpy.data.objects.get(obj_name) + if obj is not None: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.collections.remove(col) + + # 2. Strip matching prefixes, studio lights/cameras/fonts, and hidden boolean cutters + for obj_name in [o.name for o in bpy.data.objects]: + obj = bpy.data.objects.get(obj_name) + if obj is None: + continue + if obj.type in ("LIGHT", "CAMERA", "FONT"): + stripped.append(obj_name) + bpy.data.objects.remove(obj, do_unlink=True) + continue + is_skeleton_pivot = obj.get("kit_part") in ("bone", "trunk") + if not is_skeleton_pivot and (obj.hide_viewport or obj.hide_render or obj.display_type in ("WIRE", "BOUNDS")): + stripped.append(obj_name) + bpy.data.objects.remove(obj, do_unlink=True) + continue + if _should_strip(obj_name, spec.strip_prefixes): + stripped.append(obj_name) + _remove_object_recursive(obj) + continue + if not spec.armature_name and ".bolts" in obj_name: + stripped.append(obj_name) + bpy.data.objects.remove(obj, do_unlink=True) + + return sorted(set(stripped)) + + +def _strip_vertex_groups_from_mesh(obj: bpy.types.Object, vg_names: tuple[str, ...]) -> int: + if not vg_names or obj.type != "MESH": + return 0 + target_indices = { + obj.vertex_groups[name].index + for name in vg_names + if name in obj.vertex_groups + } + if not target_indices: + return 0 + bm = bmesh.new() + bm.from_mesh(obj.data) + dlayer = bm.verts.layers.deform.active + removed_verts = 0 + if dlayer is not None: + to_delete = [] + for v in bm.verts: + dw = v[dlayer] + if any(dw.get(idx, 0.0) > 0.5 for idx in target_indices): + to_delete.append(v) + removed_verts = len(to_delete) + if to_delete: + bmesh.ops.delete(bm, geom=to_delete, context="VERTS") + bm.to_mesh(obj.data) + bm.free() + obj.data.validate(verbose=False) + obj.data.update() + return removed_verts + + +def _strip_mesh_islands(strip_islands: tuple[tuple[str, str, float], ...]) -> dict[str, int]: + """Remove disconnected mesh islands matching world-space predicates (e.g. protruding gun barrels).""" + removed: dict[str, int] = {} + for obj_name, op, thresh in strip_islands: + obj = bpy.data.objects.get(obj_name) + if obj is None or obj.type != "MESH" or obj.data is None: + continue + bm = bmesh.new() + bm.from_mesh(obj.data) + bm.verts.ensure_lookup_table() + mw = obj.matrix_world + visited: set[int] = set() + del_verts: list[bmesh.types.BMVert] = [] + for v in bm.verts: + if v.index in visited: + continue + comp: list[bmesh.types.BMVert] = [] + stack = [v] + visited.add(v.index) + while stack: + cur = stack.pop() + comp.append(cur) + for e in cur.link_edges: + ov = e.other_vert(cur) + if ov.index not in visited: + visited.add(ov.index) + stack.append(ov) + pts = [mw @ c.co for c in comp] + hit = False + if op == "max_y>": + hit = max(p.y for p in pts) > thresh + elif op == "min_y<": + hit = min(p.y for p in pts) < thresh + elif op == "max_z>": + hit = max(p.z for p in pts) > thresh + if hit: + del_verts.extend(comp) + if del_verts: + bmesh.ops.delete(bm, geom=del_verts, context="VERTS") + bm.to_mesh(obj.data) + obj.data.validate(verbose=False) + obj.data.update() + removed[obj_name] = len(del_verts) + bm.free() + return removed + + +def _assemble_kestrel_hierarchy() -> None: + """Group Kestrel's flat root parts under Pelvis, Torso.pose, ArmL, and ArmR pivots.""" + torso_pose = bpy.data.objects.get("Torso.pose") + if torso_pose is None: + return + + def reparent_keep_world(obj: bpy.types.Object, parent: bpy.types.Object) -> None: + mw = obj.matrix_world.copy() + obj.parent = parent + obj.matrix_parent_inverse = Matrix.Identity(4) + obj.matrix_local = parent.matrix_world.inverted() @ mw + + pelvis = vc.make_empty("Pelvis", parent=None, location=(0.0, 0.0, 0.0)) + arm_l = vc.make_empty("ArmL", parent=torso_pose, location=(-1.62, 0.65, 1.50)) + arm_r = vc.make_empty("ArmR", parent=torso_pose, location=(1.62, 0.65, 1.50)) + bpy.context.view_layer.update() + + for obj in list(bpy.data.objects): + if obj in (pelvis, torso_pose, arm_l, arm_r): + continue + name = obj.name + if obj.parent is None and ( + name.startswith("Pelvis.") + or name.startswith("LegJoints") + or name.startswith("Thigh") + or name.startswith("Shin") + or name.startswith("Ankle") + or name.startswith("Foot") + ): + reparent_keep_world(obj, pelvis) + elif obj.parent is None and (name.startswith("Neck.") or name.startswith("Shoulder")): + reparent_keep_world(obj, torso_pose) + elif name.startswith("UpperArmL.") or name.startswith("ElbowL.") or name.startswith("ForearmL.") or name.startswith("HandL."): + reparent_keep_world(obj, arm_l) + elif name.startswith("UpperArmR.") or name.startswith("ElbowR.") or name.startswith("WeaponArm."): + reparent_keep_world(obj, arm_r) + bpy.context.view_layer.update() + + +def _apply_existing_modifiers() -> None: + """Drop BEVEL (which causes decimate spikes) and bake SOLIDIFY/BOOLEAN before stripping cutters.""" + for obj_name in [o.name for o in bpy.data.objects]: + obj = bpy.data.objects.get(obj_name) + if obj is None or obj.type != "MESH" or not obj.modifiers: + continue + for mod in list(obj.modifiers): + if mod.type == "BEVEL": + obj.modifiers.remove(mod) + depsgraph = bpy.context.evaluated_depsgraph_get() + for obj_name in [o.name for o in bpy.data.objects]: + obj = bpy.data.objects.get(obj_name) + if obj is None or obj.type != "MESH" or not obj.modifiers: + continue + if any(m.type == "ARMATURE" for m in obj.modifiers): + continue + ev = obj.evaluated_get(depsgraph) + new_mesh = bpy.data.meshes.new_from_object(ev, preserve_all_data_layers=True, depsgraph=depsgraph) + new_mesh.name = f"{obj.name}_baked" + obj.modifiers.clear() + obj.data = new_mesh + + +def _convert_surviving_curves() -> None: + """Convert surviving CURVE hydraulic hoses to MESH.""" + view_layer = bpy.context.view_layer + curves = [o for o in bpy.data.objects if o.type == "CURVE"] + if curves: + bpy.ops.object.select_all(action="DESELECT") + for c in curves: + c.select_set(True) + view_layer.objects.active = curves[0] + bpy.ops.object.convert(target="MESH") + + +def _normalize_materials_for_gltf() -> None: + """Replace linked procedural shader trees with clean flat Principled BSDF PBR values.""" + vc.ensure_materials() + pal_map = { + "armour": "olive_armor", + "armor": "olive_armor", + "olive": "olive_armor", + "khaki": "olive_armor", + "metal": "gunmetal", + "gunmetal": "gunmetal", + "machine": "gunmetal", + "rubber": "rubber_dark", + "hazard": "signal_orange", + "brass": "copper_rad", + "copper": "copper_rad", + "glass": "smoked_glass", + "optic": "smoked_glass", + "pit": "socket_bay", + } + for mat in list(bpy.data.materials): + if mat.name in vc.PALETTE or not mat.use_nodes or not mat.node_tree: + continue + nt = mat.node_tree + bsdf = next((n for n in nt.nodes if n.type == "BSDF_PRINCIPLED"), None) + if bsdf is None: + continue + lname = mat.name.lower() + + # 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"): + roughness = float(grp.inputs["Roughness"].default_value) + + # Fallback to matching shared RTD palette entry for linked/procedural mats + matched_pal = None + for key, pal_name in pal_map.items(): + if key in lname: + matched_pal = vc.PALETTE[pal_name] + break + + # Clear links on Principled BSDF and reset overrides (e.g. Emission/Transmission) + for inp in bsdf.inputs: + for lk in list(inp.links): + nt.links.remove(lk) + if "Emission Strength" in bsdf.inputs: + bsdf.inputs["Emission Strength"].default_value = 0.0 + if "Emission Color" in bsdf.inputs: + bsdf.inputs["Emission Color"].default_value = (0.0, 0.0, 0.0, 1.0) + if "Transmission Weight" in bsdf.inputs: + bsdf.inputs["Transmission Weight"].default_value = 0.0 + if "Coat Weight" in bsdf.inputs: + bsdf.inputs["Coat Weight"].default_value = 0.0 + + if "glow_blue" in lname: + bsdf.inputs["Base Color"].default_value = vc.srgb_hex_to_linear("#38c9d8") + bsdf.inputs["Roughness"].default_value = 0.20 + bsdf.inputs["Emission Color"].default_value = vc.srgb_hex_to_linear("#38c9d8") + bsdf.inputs["Emission Strength"].default_value = 2.4 + elif any(k in lname for k in ("lamp", "glow", "amber")): + col = vc.srgb_hex_to_linear("#ff9f2e") + bsdf.inputs["Base Color"].default_value = col + bsdf.inputs["Roughness"].default_value = 0.20 + bsdf.inputs["Emission Color"].default_value = col + bsdf.inputs["Emission Strength"].default_value = 2.2 + elif "steel" in lname: + bsdf.inputs["Base Color"].default_value = (0.58, 0.60, 0.62, 1.0) + bsdf.inputs["Metallic"].default_value = 0.94 + bsdf.inputs["Roughness"].default_value = 0.22 + elif "optic_red" in lname: + bsdf.inputs["Base Color"].default_value = (0.14, 0.02, 0.015, 1.0) + bsdf.inputs["Metallic"].default_value = 0.0 + bsdf.inputs["Roughness"].default_value = 0.15 + if "Emission Color" in bsdf.inputs: + bsdf.inputs["Emission Color"].default_value = (1.0, 0.08, 0.03, 1.0) + if "Emission Strength" in bsdf.inputs: + bsdf.inputs["Emission Strength"].default_value = 1.6 + elif "warhead" in lname: + 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: + bsdf.inputs["Base Color"].default_value = cover_col if (cover_col is not None and cover_amt >= 0.5) else (0.48, 0.46, 0.42, 1.0) + bsdf.inputs["Metallic"].default_value = 0.0 + bsdf.inputs["Roughness"].default_value = roughness if roughness is not None else 0.72 + 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"]) + bsdf.inputs["Roughness"].default_value = float(matched_pal["roughness"]) + if "alpha" in matched_pal: + bsdf.inputs["Alpha"].default_value = float(matched_pal["alpha"]) + if hasattr(mat, "blend_method"): + mat.blend_method = "BLEND" + elif base_col is not None: + bsdf.inputs["Base Color"].default_value = base_col + if metallic is not None: + bsdf.inputs["Metallic"].default_value = metallic + if roughness is not None: + bsdf.inputs["Roughness"].default_value = roughness + + +def _mesh_tri_count(obj: bpy.types.Object) -> int: + obj.data.calc_loop_triangles() + return len(obj.data.loop_triangles) + + +def _apply_crisp_normals_and_decimate(obj: bpy.types.Object, ratio: float) -> int: + view_layer = bpy.context.view_layer + if obj.data.users > 1: + obj.data = obj.data.copy() + bpy.ops.object.select_all(action="DESELECT") + obj.select_set(True) + view_layer.objects.active = obj + + if ratio < 0.99: + mod = obj.modifiers.new("LOD_Decimate", "DECIMATE") + mod.decimate_type = "COLLAPSE" + mod.ratio = ratio + mod.use_collapse_triangulate = True + if len(obj.modifiers) > 1: + bpy.ops.object.modifier_move_to_index(modifier=mod.name, index=0) + bpy.ops.object.modifier_apply(modifier=mod.name) + + # Split sharp armor edges (>36 deg) so decimated bevel corners never look pillowed + es = obj.modifiers.new("LOD_EdgeSplit", "EDGE_SPLIT") + es.use_edge_angle = True + es.split_angle = math.radians(36.0) + es.use_edge_sharp = True + if len(obj.modifiers) > 1: + bpy.ops.object.modifier_move_to_index(modifier=es.name, index=0) + bpy.ops.object.modifier_apply(modifier=es.name) + obj.data.validate(verbose=False) + obj.data.update() + return _mesh_tri_count(obj) + + +def _decimate_mech_meshes(meshes: list[bpy.types.Object], target_tris: int, min_keep_tris: int = 48) -> tuple[int, int]: + """Decimate mech meshes adaptively to target_tris while keeping armor plates crisp and spike-free.""" + tri_counts = [_mesh_tri_count(o) for o in meshes] + raw_total = sum(tri_counts) + if raw_total == 0: + return 0, 0 + + # Single-mesh rigged path (e.g. breaker.mesh) -> modifier_apply preserves armature + skinning + if len(meshes) == 1: + obj = meshes[0] + ratio = max(0.02, min(1.0, target_tris / raw_total)) + after = _apply_crisp_normals_and_decimate(obj, ratio) + return raw_total, after + + min_main_ratio = 0.125 if raw_total > 150000 else 0.20 + + def _target_for(obj: bpy.types.Object, t: int, k_val: float) -> int: + if t <= min_keep_tris: + return t + is_detail = ( + obj.name.startswith("Foot") + or ".Foot" in obj.name + or ".fit." in obj.name + or ".ferrules" in obj.name + or ".panels" in obj.name + ) + if is_detail: + return max(24, int(round(t * max(k_val * 0.50, 0.06)))) + if t <= 220: + return max(min(t, 44), int(round(t * max(k_val, 0.28)))) + return max(84, int(round(t * max(k_val, min_main_ratio)))) + + if raw_total <= target_tris: + k = 1.0 + else: + lo, hi = 0.10, 1.0 + for _ in range(28): + mid = 0.5 * (lo + hi) + est = sum(_target_for(obj, t, mid) for obj, t in zip(meshes, tri_counts)) + if est > target_tris: + hi = mid + else: + lo = mid + k = 0.5 * (lo + hi) + + # Queue DECIMATE + EDGE_SPLIT on all objects, then evaluate in one depsgraph pass + for obj, t in zip(meshes, tri_counts): + tgt = _target_for(obj, t, k) + if tgt < t: + ratio = max(0.08, min(1.0, tgt / t)) + if ratio < 0.99: + mod = obj.modifiers.new("LOD_Decimate", "DECIMATE") + mod.decimate_type = "COLLAPSE" + mod.ratio = ratio + mod.use_collapse_triangulate = True + es = obj.modifiers.new("LOD_EdgeSplit", "EDGE_SPLIT") + es.use_edge_angle = True + es.split_angle = math.radians(36.0) + es.use_edge_sharp = True + + depsgraph = bpy.context.evaluated_depsgraph_get() + after_total = 0 + for obj in meshes: + ev = obj.evaluated_get(depsgraph) + new_mesh = bpy.data.meshes.new_from_object(ev, preserve_all_data_layers=True, depsgraph=depsgraph) + new_mesh.name = f"{obj.name}_lod" + new_mesh.validate(verbose=False) + obj.modifiers.clear() + obj.data = new_mesh + after_total += _mesh_tri_count(obj) + + 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: + tight_hits: list[float] = [] + for tx, ty in ((-0.07, 0.0), (0.07, 0.0), (0.0, -0.07), (0.0, 0.07)): + t_loc, _, _, _ = bvh.ray_cast(p0 + tu * tx + tv * ty + n * 0.65, -n, 1.35) + if t_loc is not None: + tight_hits.append((t_loc - p0).dot(n)) + t_med = sorted(tight_hits)[len(tight_hits) // 2] if tight_hits else h_center + if h_center - t_med > 0.06: + h_center = c_med + + # Keep corner hits near the local surface patch; replace misses/cliffs with nearest or conservative drop + valid_corners: list[float] = [h_center] + 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=adj_size, + plinth_depth=plinth_depth, + ) + bay_root = anchor.parent + if hp.parent_bone is not None: + bay_root.parent_type = "BONE" + bay_root.parent_bone = hp.parent_bone + + 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(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] + # Blender bone parenting attaches at the pose bone tail with bone axes + bone_tail_mat = parent_obj.matrix_world @ pb.matrix @ Matrix.Translation((0.0, pb.length, 0.0)) + m_local = bone_tail_mat.inverted() @ m_world + else: + m_local = parent_obj.matrix_world.inverted() @ m_world + + loc, rot, _ = m_local.decompose() + bay_root.location = loc + bay_root.rotation_mode = "XYZ" + bay_root.rotation_euler = rot.to_euler("XYZ") + + +def _apply_joint_tags(spec: MechRetrofitSpec) -> list[dict[str, Any]]: + joints_manifest: list[dict[str, Any]] = [] + for j in spec.joints: + target = bpy.data.objects[j.target_name] + if j.parent_bone is not None and target.type == "ARMATURE": + node = vc.make_empty(j.joint_id, parent=target, display_size=0.16) + node.parent_type = "BONE" + node.parent_bone = j.parent_bone + bpy.context.view_layer.update() + pb = target.pose.bones[j.parent_bone] + bone_head_w = target.matrix_world @ pb.head + bone_tail_mat = target.matrix_world @ pb.matrix @ Matrix.Translation((0.0, pb.length, 0.0)) + m_local = bone_tail_mat.inverted() @ Matrix.Translation(bone_head_w) + node.location = m_local.to_translation() + else: + node = target + vc.tag_joint(node, j.joint_id, j.axis_gltf, j.min_val, j.max_val) + joints_manifest.append({ + "id": j.joint_id, + "axis": [float(v) for v in j.axis_gltf], + "min": float(j.min_val), + "max": float(j.max_val), + }) + return joints_manifest + + +def _brokkr_vec_to_gltf(v: list[float], ground_z_shift: float = 0.0) -> list[float]: + """Convert raw Brokkr Blender (+Y fwd, -X left, +Z up) after 180 deg Z rot to glTF (+Z fwd, +X left, +Y up).""" + return [round(-float(v[0]), 6), round(float(v[2]) + ground_z_shift, 6), round(float(v[1]), 6)] + + +def _brokkr_dir_to_gltf(v: list[float]) -> list[float]: + return [round(-float(v[0]), 6), round(float(v[2]), 6), round(float(v[1]), 6)] + + +def _extract_mechanisms(model_json_path: Path, ground_z_shift: float = 0.0) -> dict[str, Any]: + raw = json.loads(model_json_path.read_text(encoding="utf-8")) + dofs_out = [] + for d in raw.get("dofs", []): + entry = { + "name": d["name"], + "parent": d["parent"], + "kind": d["kind"], + "mechanism": d.get("mechanism"), + "side": d.get("side"), + "origin": _brokkr_vec_to_gltf(d["origin"], ground_z_shift), + "axis": _brokkr_dir_to_gltf(d["axis"]), + "lo": d["lo"], + "hi": d["hi"], + "depth": d["depth"], + } + if "compliance" in d: + entry["compliance"] = d["compliance"] + if "stopped_by" in d: + entry["stopped_by"] = d["stopped_by"] + dofs_out.append(entry) + + points_raw = raw.get("points", {}) + dirs_raw = raw.get("dirs", {}) + rams_out = [] + for r in raw.get("rams", []): + pt_a = points_raw.get(r["a"]) + pt_b = points_raw.get(r["b"]) + dir_pin = dirs_raw.get(r["pin"]) + rams_out.append({ + "name": r["name"], + "barrel_bone": r["barrel_bone"], + "rod_bone": r["rod_bone"], + "spans": r.get("spans", []), + "bore": r.get("bore"), + "body": r.get("body"), + "inner": r.get("inner"), + "extension": r.get("extension"), + "rest": r.get("rest"), + "stroke": r.get("stroke"), + "a_parent_dof": pt_a[0] if pt_a else None, + "a_pos": _brokkr_vec_to_gltf(pt_a[1], ground_z_shift) if pt_a else None, + "b_parent_dof": pt_b[0] if pt_b else None, + "b_pos": _brokkr_vec_to_gltf(pt_b[1], ground_z_shift) if pt_b else None, + "pin_dir": _brokkr_dir_to_gltf(dir_pin[1]) if dir_pin else None, + }) + + scissors_out = [] + for s in raw.get("scissors", []): + pt_a = points_raw.get(s["a"]) + pt_b = points_raw.get(s["b"]) + dir_out = dirs_raw.get(s["out"]) + scissors_out.append({ + "name": s["name"], + "upper_bone": s["upper_bone"], + "lower_bone": s["lower_bone"], + "arm": s.get("arm"), + "a_parent_dof": pt_a[0] if pt_a else None, + "a_pos": _brokkr_vec_to_gltf(pt_a[1], ground_z_shift) if pt_a else None, + "b_parent_dof": pt_b[0] if pt_b else None, + "b_pos": _brokkr_vec_to_gltf(pt_b[1], ground_z_shift) if pt_b else None, + "out_dir": _brokkr_dir_to_gltf(dir_out[1]) if dir_out else None, + }) + + struts_out = [ + { + "name": st["name"], + "side": st.get("side"), + "dof": st["dof"], + "travel": st["travel"], + "hertz": st["hertz"], + "damping_ratio": st["damping_ratio"], + } + for st in raw.get("struts", []) + ] + + return { + "frame": "gltf (+Y up, +Z forward, +X left, meters)", + "rootOrigin": _brokkr_vec_to_gltf(raw.get("root", [0.0, 0.0, 0.0]), ground_z_shift), + "dofs": dofs_out, + "rams": rams_out, + "scissors": scissors_out, + "struts": struts_out, + } + + +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 _finalize_shroud_obj(obj: bpy.types.Object, bevel: float = 0.010) -> bpy.types.Object: + """Apply crisp hard-surface bevel + 36-deg edge split and bake to clean mesh.""" + if bevel > 0.0: + bv = obj.modifiers.new("Shroud_Bevel", "BEVEL") + bv.width = float(bevel) + bv.segments = 1 + bv.limit_method = "ANGLE" + bv.angle_limit = math.radians(30.0) + bv.harden_normals = False + es = obj.modifiers.new("Shroud_EdgeSplit", "EDGE_SPLIT") + es.use_edge_angle = True + es.split_angle = math.radians(36.0) + es.use_edge_sharp = True + depsgraph = bpy.context.evaluated_depsgraph_get() + ev = obj.evaluated_get(depsgraph) + new_mesh = bpy.data.meshes.new_from_object(ev, preserve_all_data_layers=True, depsgraph=depsgraph) + new_mesh.name = f"{obj.name}_mesh" + new_mesh.validate(verbose=False) + obj.modifiers.clear() + obj.data = new_mesh + return obj + + +def _make_loft_shroud( + name: str, + rings: list[list[Vector]], + parent: bpy.types.Object, + mat_name: str = "olive_armor", + bevel: float = 0.010, +) -> bpy.types.Object: + """Loft a closed manifold hard-surface armor shell across multi-station 3D rings in parent local space.""" + assert len(rings) >= 2 and all(len(r) == len(rings[0]) for r in rings) + m = len(rings[0]) + bm = bmesh.new() + bm_rings: list[list[bmesh.types.BMVert]] = [ + [bm.verts.new(tuple(float(c) for c in pt)) for pt in ring] + for ring in rings + ] + bm.verts.ensure_lookup_table() + for i in range(len(bm_rings) - 1): + r0, r1 = bm_rings[i], bm_rings[i + 1] + for j in range(m): + jn = (j + 1) % m + bm.faces.new((r0[j], r0[jn], r1[jn], r1[j])) + bm.faces.new(list(reversed(bm_rings[0]))) + bm.faces.new(bm_rings[-1]) + bmesh.ops.recalc_face_normals(bm, faces=bm.faces) + mesh = bpy.data.meshes.new(name) + bm.to_mesh(mesh) + bm.free() + obj = bpy.data.objects.new(name, mesh) + vc._assign_material(obj, mat_name) + vc._link_object(obj, parent=parent, location=(0.0, 0.0, 0.0), rotation_deg=(0.0, 0.0, 0.0)) + return _finalize_shroud_obj(obj, bevel=bevel) + + +def _make_chamfer_box_shroud( + name: str, + x0: float, + x1: float, + y0: float, + y1: float, + z0: float, + z1: float, + parent: bpy.types.Object, + mat_name: str = "olive_armor", + chamfer: float = 0.035, + top_taper_xy: tuple[float, float] = (1.0, 1.0), + bevel: float = 0.010, +) -> bpy.types.Object: + """Create a tapered octagonal-section armor plate spanning [x0..x1] x [y0..y1] x [z0..z1].""" + cx, cy = 0.5 * (x0 + x1), 0.5 * (y0 + y1) + hx, hy = 0.5 * abs(x1 - x0), 0.5 * abs(y1 - y0) + c = min(chamfer, hx * 0.42, hy * 0.42) + + def _ring(z_val: float, sx: float, sy: float) -> list[Vector]: + rx, ry = hx * sx, hy * sy + cc = min(c, rx * 0.45, ry * 0.45) + pts = [ + (cx - rx + cc, cy - ry), + (cx + rx - cc, cy - ry), + (cx + rx, cy - ry + cc), + (cx + rx, cy + ry - cc), + (cx + rx - cc, cy + ry), + (cx - rx + cc, cy + ry), + (cx - rx, cy + ry - cc), + (cx - rx, cy - ry + cc), + ] + return [Vector((px, py, z_val)) for px, py in pts] + + tx, ty = top_taper_xy + rings = [_ring(z0, 1.0, 1.0), _ring(z1, tx, ty)] + return _make_loft_shroud(name, rings, parent=parent, mat_name=mat_name, bevel=bevel) + + +def _make_arc_fender( + name: str, + center: Vector, + axis: Vector, + fwd_dir: Vector, + up_dir: Vector, + r_in: float, + r_out: float, + half_w: float, + ang_start_deg: float, + ang_end_deg: float, + steps: int, + parent: bpy.types.Object, + mat_name: str = "olive_armor", + end_taper_w: float = 0.84, + bevel: float = 0.010, +) -> bpy.types.Object: + """Sweep a beveled armored fender arch around a cylindrical drum (0 deg = fwd_dir, 90 deg = up_dir).""" + ax = axis.normalized() + fd = fwd_dir.normalized() + ud = up_dir.normalized() + rings: list[list[Vector]] = [] + for k in range(steps + 1): + u = k / steps + ang = math.radians(ang_start_deg + (ang_end_deg - ang_start_deg) * u) + radial = fd * math.cos(ang) + ud * math.sin(ang) + # Slightly pinch width and thickness at the very ends for Brokkr fender silhouette + edge_fac = 1.0 - (1.0 - end_taper_w) * (abs(2.0 * u - 1.0) ** 2) + hw = half_w * edge_fac + hw_outer = hw * 0.86 + r_mid = r_in + (r_out - r_in) * 0.65 + pts = [ + center + radial * r_in - ax * hw, + center + radial * r_in + ax * hw, + center + radial * r_mid + ax * hw, + center + radial * r_out + ax * hw_outer, + center + radial * r_out - ax * hw_outer, + center + radial * r_mid - ax * hw, + ] + rings.append(pts) + return _make_loft_shroud(name, rings, parent=parent, mat_name=mat_name, bevel=bevel) + + +def _obj_bounds_in_ref(obj_names: list[str], ref_obj: bpy.types.Object, z_filter: tuple[float, float] | None = None) -> tuple[Vector, Vector] | None: + """Measure combined world vertices of named objects transformed into ref_obj local space.""" + inv_ref = ref_obj.matrix_world.inverted() + pts: list[Vector] = [] + for nm in obj_names: + o = bpy.data.objects.get(nm) + if o is None or o.type != "MESH" or o.data is None: + continue + mw = o.matrix_world + for v in o.data.vertices: + pw = mw @ v.co + if z_filter is not None and not (z_filter[0] <= pw.z <= z_filter[1]): + continue + pts.append(inv_ref @ pw) + if not pts: + return None + bmin = Vector((min(p.x for p in pts), min(p.y for p in pts), min(p.z for p in pts))) + bmax = Vector((max(p.x for p in pts), max(p.y for p in pts), max(p.z for p in pts))) + return bmin, bmax + + +def _add_kestrel_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + torso = bpy.data.objects.get("Torso.pose") + pelvis = bpy.data.objects.get("Pelvis") + if torso is None or pelvis is None: + return created + + # 1. Sloped hooded shoulder pauldrons over exposed ribbed shoulder drums (parented to Torso.pose) + # Linearly tapered stations keep top/flank quads planar for crisp panel shading. + for side, sx in (("L", -1.0), ("R", 1.0)): + stations_spec = [ + # (|x|, y_rear, y_front, z_low_rear, z_low_front, z_top_rear, z_top_front) + (1.20, 0.00, 1.24, 1.54, 1.54, 2.26, 2.18), + (1.52, 0.02, 1.22, 1.36, 1.42, 2.18, 2.10), + (1.86, 0.04, 1.19, 1.22, 1.30, 2.07, 2.00), + (2.16, 0.06, 1.16, 1.16, 1.24, 1.92, 1.86), + (2.30, 0.10, 1.10, 1.24, 1.30, 1.74, 1.69), + ] + rings: list[list[Vector]] = [] + for ax, yr, yf, zlr, zlf, ztr, ztf in stations_spec: + px = sx * ax + yc = 0.5 * (yr + yf) + pts = [ + Vector((px, yr, zlr)), + Vector((px, yr + 0.14, zlr)), + Vector((px, yr + 0.16, ztr - 0.18)), + Vector((px, yc, min(ztr, ztf) - 0.12)), + Vector((px, yf - 0.16, ztf - 0.18)), + Vector((px, yf - 0.14, zlf)), + Vector((px, yf, zlf)), + Vector((px, yf - 0.08, ztf)), + Vector((px, yc, max(ztr, ztf) + 0.04)), + Vector((px, yr + 0.08, ztr)), + ] + if sx < 0: + pts = list(reversed(pts)) + rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.Pauldron{side}", rings, torso, "olive_armor", bevel=0.012)) + + # Gunmetal mounting flange bracket bridging inner shoulder cowl to drum core + created.append( + _make_arc_fender( + f"Shroud.Kestrel.PauldronFlange{side}", + center=Vector((sx * 1.38, 0.65, 1.50)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.49, + r_out=0.56, + half_w=0.10, + ang_start_deg=15.0, + ang_end_deg=165.0, + steps=6, + parent=torso, + mat_name="gunmetal", + end_taper_w=0.92, + bevel=0.008, + ) + ) + + # 2. Compact sloped hip-fender guards + outer drum caps over bare hip cylinders (parented to Pelvis) + created.append( + _make_arc_fender( + f"Shroud.Kestrel.HipFender{side}", + center=Vector((sx * 1.28, 0.0, 6.20)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.515, + r_out=0.60, + half_w=0.38, + ang_start_deg=-10.0, + ang_end_deg=158.0, + steps=8, + parent=pelvis, + mat_name="olive_armor", + end_taper_w=0.80, + bevel=0.010, + ) + ) + # Outer hip drum shield cap + hip_cap_rings: list[list[Vector]] = [] + for x_off, r in ((1.46, 0.36), (1.58, 0.36), (1.64, 0.25)): + px = sx * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), 6.20 + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if sx < 0: + pts = list(reversed(pts)) + hip_cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.HipCap{side}", hip_cap_rings, pelvis, "olive_armor", bevel=0.008)) + created.append( + _make_arc_fender( + f"Shroud.Kestrel.HipFlange{side}", + center=Vector((sx * 1.02, 0.0, 6.20)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.49, + r_out=0.54, + half_w=0.07, + ang_start_deg=-5.0, + ang_end_deg=162.0, + steps=7, + parent=pelvis, + mat_name="gunmetal", + end_taper_w=0.95, + bevel=0.006, + ) + ) + + # 4. Faceted knee caps + outer cheek shields over bare black knee drums (parented to Pelvis) + knee_bounds = _obj_bounds_in_ref([f"LegJoints{side}.gunmetal"], pelvis, z_filter=(3.0, 4.4)) + if knee_bounds is not None: + kmin, kmax = knee_bounds + kcx = 0.5 * (kmin.x + kmax.x) + kcy = 0.5 * (kmin.y + kmax.y) + kcz = 0.5 * (kmin.z + kmax.z) + created.append( + _make_arc_fender( + f"Shroud.Kestrel.KneeCap{side}", + center=Vector((kcx, kcy, kcz)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.37, + r_out=0.465, + half_w=0.37, + ang_start_deg=-42.0, + ang_end_deg=72.0, + steps=6, + parent=pelvis, + mat_name="olive_armor", + end_taper_w=0.78, + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Kestrel.KneeCapFront{side}", + kcx - 0.25, + kcx + 0.25, + kcy + 0.36, + kcy + 0.49, + kcz - 0.24, + kcz + 0.28, + parent=pelvis, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.86, 0.85), + bevel=0.009, + ) + ) + knee_side_rings: list[list[Vector]] = [] + for x_off, r in ((0.28, 0.28), (0.37, 0.28), (0.42, 0.19)): + px = kcx + sx * x_off + pts = [ + Vector((px, kcy + r * math.cos(math.radians(a)), kcz + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if sx < 0: + pts = list(reversed(pts)) + knee_side_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.KneeCheek{side}", knee_side_rings, pelvis, "olive_armor", bevel=0.008)) + + # 5. Armored calf/shin shrouds wrapping rear twin ankle hydraulic pistons (parented to Pelvis) + ram_objs = [f"Ankle{side}.root.machine.ram", f"Ankle{side}.root.steel.ram", f"Ankle{side}.root.steel.eye"] + top_b = _obj_bounds_in_ref(ram_objs, pelvis, z_filter=(2.05, 2.75)) + bot_b = _obj_bounds_in_ref(ram_objs, pelvis, z_filter=(0.95, 1.65)) + if top_b is not None and bot_b is not None: + t_cx = 0.5 * (top_b[0].x + top_b[1].x) + t_cy = 0.5 * (top_b[0].y + top_b[1].y) + b_cx = 0.5 * (bot_b[0].x + bot_b[1].x) + b_cy = 0.5 * (bot_b[0].y + bot_b[1].y) + z_bot, z_top = 1.16, 2.74 + # Interpolate exact piston spine centerline from z_bot..z_top and wrap a U-channel rear/flank greave + greave_rings: list[list[Vector]] = [] + for frac, hw, y_back, y_front in ( + (0.00, 0.145, -0.145, 0.13), + (0.22, 0.165, -0.165, 0.17), + (0.75, 0.180, -0.175, 0.22), + (1.00, 0.160, -0.145, 0.19), + ): + zz = z_bot + (z_top - z_bot) * frac + # top_b centroid is ~z=2.40, bot_b centroid is ~z=1.30 + t_u = (zz - 1.30) / 1.10 + px = b_cx + (t_cx - b_cx) * t_u + py = b_cy + (t_cy - b_cy) * t_u + c_in = hw * 0.58 + pts = [ + Vector((px - hw, py + y_front, zz)), + Vector((px - c_in, py + y_front, zz)), + Vector((px - c_in, py + y_back + 0.08, zz)), + Vector((px + c_in, py + y_back + 0.08, zz)), + Vector((px + c_in, py + y_front, zz)), + Vector((px + hw, py + y_front, zz)), + Vector((px + hw, py + y_back + 0.05, zz)), + Vector((px + hw * 0.62, py + y_back, zz)), + Vector((px - hw * 0.62, py + y_back, zz)), + Vector((px - hw, py + y_back + 0.05, zz)), + ] + greave_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Kestrel.AnkleGreave{side}", greave_rings, pelvis, "olive_armor", bevel=0.010)) + for idx_band, zb in enumerate((1.38, 2.38)): + t_u = (zb - 1.30) / 1.10 + px = b_cx + (t_cx - b_cx) * t_u + py = b_cy + (t_cy - b_cy) * t_u + created.append( + _make_chamfer_box_shroud( + f"Shroud.Kestrel.AnkleBand{side}{idx_band}", + px - 0.18, + px + 0.18, + py - 0.175, + py + 0.16, + zb - 0.045, + zb + 0.045, + parent=pelvis, + mat_name="gunmetal", + chamfer=0.03, + bevel=0.006, + ) + ) + + # 3. Segmented armored spine shroud over exposed rear waist hydraulic rods (parented to Torso.pose) + # In Torso.pose local space (offset 0, -0.15, 6.75), neck rings step forward in Y as Z rises from -0.05 to +0.88 + for idx_seg, (z0, z1, y_back, hx) in enumerate(( + (-0.04, 0.27, -0.66, 0.58), + (0.24, 0.56, -0.58, 0.54), + (0.53, 0.86, -0.49, 0.49), + )): + created.append( + _make_chamfer_box_shroud( + f"Shroud.Kestrel.WaistSpine{idx_seg}", + -hx, + hx, + y_back, + y_back + 0.34, + z0, + z1, + parent=torso, + mat_name="olive_armor", + chamfer=0.07, + top_taper_xy=(0.92, 0.90), + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Kestrel.WaistSpineRib", + -0.16, + 0.16, + -0.69, + -0.42, + 0.00, + 0.82, + parent=torso, + mat_name="gunmetal", + chamfer=0.03, + top_taper_xy=(0.88, 0.85), + bevel=0.008, + ) + ) + return created + + +def _add_spectre_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + + # 1. Angled shin/hock hydraulic ram deflector greaves (parented to LegL.Cannon / LegR.Cannon) + for leg in ("LegL", "LegR"): + cannon = bpy.data.objects.get(f"{leg}.Cannon") + if cannon is None: + continue + inv_can = cannon.matrix_world.inverted() + ram_objs = [bpy.data.objects.get(f"{leg}.Hock.ram.barrel"), bpy.data.objects.get(f"{leg}.Hock.ram.rod")] + for side_tag, x_sign in (("Out", -1.0 if leg == "LegL" else 1.0), ("In", 1.0 if leg == "LegL" else -1.0)): + pts: list[Vector] = [] + for ro in ram_objs: + if ro is None or ro.type != "MESH" or ro.data is None: + continue + mw = ro.matrix_world + for v in ro.data.vertices: + pl = inv_can @ (mw @ v.co) + if pl.x * x_sign > 0.10: + pts.append(pl) + if not pts: + continue + xmin = min(p.x for p in pts) + xmax = max(p.x for p in pts) + ymax = max(p.y for p in pts) + ymin = min(p.y for p in pts) + # Deflector greave wrapping the front (+Y) and outer/side face of each exposed silver ram + x_in = (xmin - 0.02) if x_sign > 0 else (xmin - 0.055) + x_out = (xmax + 0.055) if x_sign > 0 else (xmax + 0.02) + y_f = ymax + 0.055 + y_b = max(ymin - 0.02, ymax - 0.24) + z_top = 0.28 + z_bot = 1.46 + # Loft from top bevel cap -> mid shield -> lower tapered deflector lip + rings: list[list[Vector]] = [] + for zz, x_pad, y_pad in ( + (z_top, -0.02, -0.03), + (z_top + 0.14, 0.0, 0.0), + (z_bot - 0.18, 0.0, 0.0), + (z_bot, -0.025, -0.04), + ): + xa, xb = x_in - x_pad * x_sign, x_out + x_pad * x_sign + if xa > xb: + xa, xb = xb, xa + yf = y_f + y_pad + yb = y_b + xm = 0.5 * (xa + xb) + ym = 0.5 * (yb + yf) + rings.append([ + Vector((xa, yb, zz)), + Vector((xb, yb, zz)), + Vector((xb, ym + 0.03, zz)), + Vector((xm + 0.04 * (xb - xa), yf, zz)), + Vector((xm - 0.04 * (xb - xa), yf, zz)), + Vector((xa, ym + 0.03, zz)), + ]) + created.append(_make_loft_shroud(f"Shroud.Spectre.{leg}RamGuard{side_tag}", rings, cannon, "olive_armor", bevel=0.009)) + # Gunmetal mounting bracket tying greave into Leg*.Shank + bx0 = min(x_in, x_out) - (0.06 if x_sign > 0 else 0.0) + bx1 = max(x_in, x_out) + (0.06 if x_sign < 0 else 0.0) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Spectre.{leg}RamBracket{side_tag}", + bx0, + bx1, + y_b - 0.08, + y_b + 0.04, + 0.55, + 0.78, + parent=cannon, + mat_name="gunmetal", + chamfer=0.025, + bevel=0.006, + ) + ) + + # 2. Compact armored waist collar / hip skirt around vertical waist spindle (parented to Waist) + waist = bpy.data.objects.get("Waist") + if waist is not None: + # Waist wloc=(0,0,5.30), WaistLug extends z_local=-0.35..0.14, WaistColumn z_local=0..0.81 + skirt_rings: list[list[Vector]] = [] + for zz, sx, sy in ( + (-0.28, 0.72, 0.62), + (-0.04, 0.74, 0.64), + (0.24, 0.64, 0.56), + (0.42, 0.55, 0.49), + ): + c = 0.16 + skirt_rings.append([ + Vector((-sx + c, -sy, zz)), + Vector((sx - c, -sy, zz)), + Vector((sx, -sy + c, zz)), + Vector((sx, sy - c, zz)), + Vector((sx - c, sy, zz)), + Vector((-sx + c, sy, zz)), + Vector((-sx, sy - c, zz)), + Vector((-sx, -sy + c, zz)), + ]) + created.append(_make_loft_shroud("Shroud.Spectre.WaistSkirt", skirt_rings, waist, "olive_armor", bevel=0.010)) + created.append( + _make_chamfer_box_shroud( + "Shroud.Spectre.WaistCollar", + -0.56, + 0.56, + -0.51, + 0.51, + 0.32, + 0.48, + parent=waist, + mat_name="gunmetal", + chamfer=0.10, + bevel=0.008, + ) + ) + + # 3. Outer shoulder-hinge axle caps (parented to ShoulderL / ShoulderR) + for side, sx in (("L", -1.0), ("R", 1.0)): + sh = bpy.data.objects.get(f"Shoulder{side}") + if sh is None: + continue + cap_rings: list[list[Vector]] = [] + for x_off, r in ((0.24, 0.305), (0.44, 0.305), (0.52, 0.225)): + px = sx * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if sx < 0: + pts = list(reversed(pts)) + cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Spectre.ShoulderCap{side}", cap_rings, sh, "olive_armor", bevel=0.008)) + + return created + + +def _add_raptor_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + pelvis = bpy.data.objects.get("Pelvis") + + for side, sx in (("L", -1.0), ("R", 1.0)): + # 1. Angled olive hip-fender cowl over protruding black hip drum (parented to Pelvis) + if pelvis is not None: + created.append( + _make_arc_fender( + f"Shroud.Raptor.HipFender{side}", + center=Vector((sx * 1.44, 0.0, 0.0)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.535, + r_out=0.615, + half_w=0.45, + ang_start_deg=18.0, + ang_end_deg=165.0, + steps=7, + parent=pelvis, + mat_name="olive_armor", + end_taper_w=0.82, + bevel=0.010, + ) + ) + created.append( + _make_arc_fender( + f"Shroud.Raptor.HipFlange{side}", + center=Vector((sx * 1.02, 0.0, 0.0)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.50, + r_out=0.555, + half_w=0.07, + ang_start_deg=15.0, + ang_end_deg=168.0, + steps=6, + parent=pelvis, + mat_name="gunmetal", + end_taper_w=0.95, + bevel=0.006, + ) + ) + + # 2. Outer hip drum cap + knee-cap shield + rear thigh actuator guard (parented to Leg*.Thigh) + thigh = bpy.data.objects.get(f"Leg{side}.Thigh") + if thigh is not None: + # In LegL.Thigh local space +X is outer left; in LegR.Thigh local space -X is outer right + x_out_sign = -sx + hip_cap_rings: list[list[Vector]] = [] + for x_off, r in ((0.48, 0.35), (0.60, 0.35), (0.66, 0.25)): + px = x_out_sign * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if x_out_sign < 0: + pts = list(reversed(pts)) + hip_cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Raptor.HipCap{side}", hip_cap_rings, thigh, "olive_armor", bevel=0.008)) + + # KneeBearing*.gunmetal sits at z_local=[1.52..2.28], y_local=[-0.38..+0.38] (center 0.0, 1.90) + created.append( + _make_arc_fender( + f"Shroud.Raptor.KneeCap{side}", + center=Vector((x_out_sign * 0.06, 0.0, 1.90)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, -1.0)), + r_in=0.385, + r_out=0.475, + half_w=0.46, + ang_start_deg=-62.0, + ang_end_deg=62.0, + steps=7, + parent=thigh, + mat_name="olive_armor", + end_taper_w=0.78, + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.KneeCapFront{side}", + x_out_sign * 0.06 - 0.30, + x_out_sign * 0.06 + 0.30, + 0.37, + 0.50, + 1.64, + 2.16, + parent=thigh, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.86, 0.85), + bevel=0.009, + ) + ) + # Outer circular knee-drum cap + knee_cap_rings: list[list[Vector]] = [] + for x_off, r in ((0.46, 0.28), (0.58, 0.28), (0.64, 0.19)): + px = x_out_sign * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), 1.90 + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if x_out_sign < 0: + pts = list(reversed(pts)) + knee_cap_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Raptor.KneeOuterCap{side}", knee_cap_rings, thigh, "olive_armor", bevel=0.008)) + + # Rear thigh actuator guard over Actuators*.steel (y_local=[-0.62..-0.42], z_local=[1.14..1.71]) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.ThighRam{side}", + -0.37, + 0.37, + -0.66, + -0.36, + 1.08, + 1.72, + parent=thigh, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.90, 0.88), + bevel=0.009, + ) + ) + + # 3. Shin upper rod shroud (parented to Leg*.Shin) + shin = bpy.data.objects.get(f"Leg{side}.Shin") + if shin is not None: + # HydraulicsShin*.gunmetal/steel: x=[-0.23..0.23], y=[0.46..0.66], z=[0.18..1.48] + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.ShinRod{side}", + -0.27, + 0.27, + 0.36, + 0.71, + 0.20, + 1.32, + parent=shin, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.82, 0.80), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.ShinRodCollar{side}", + -0.29, + 0.29, + 0.34, + 0.72, + 0.82, + 0.98, + parent=shin, + mat_name="gunmetal", + chamfer=0.04, + bevel=0.006, + ) + ) + + # 4. Protruding rear calf hydraulic rod shroud (parented to Leg*.Cannon) + cannon = bpy.data.objects.get(f"Leg{side}.Cannon") + if cannon is not None: + # Hydraulics*.gunmetal/steel: x=[-0.23..0.23], y=[-0.57..-0.37], z=[0.18..1.61] + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.CalfRod{side}", + -0.28, + 0.28, + -0.63, + -0.27, + 0.20, + 1.40, + parent=cannon, + mat_name="olive_armor", + chamfer=0.07, + top_taper_xy=(0.80, 0.78), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Raptor.CalfRodCollar{side}", + -0.30, + 0.30, + -0.64, + -0.26, + 0.88, + 1.04, + parent=cannon, + mat_name="gunmetal", + chamfer=0.04, + bevel=0.006, + ) + ) + + return created + + +def _add_manticore_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + for leg in ("LegBL", "LegBR"): + # In LegBL local space -X is outward-left; in LegBR local space +X is outward-right + x_out_sign = -1.0 if leg == "LegBL" else 1.0 + + # 1. Rear hip armor cap over bare gunmetal coxa drum (parented to LegB*.Coxa) + coxa = bpy.data.objects.get(f"{leg}.Coxa") + if coxa is not None: + # coxa.dress.machine: x=[-0.446..0.446], y=[-0.30..0.30], z=[0.16..0.76]; +Y_local is outer-rear + created.append( + _make_chamfer_box_shroud( + f"Shroud.Manticore.{leg}HipCap", + -0.48, + 0.48, + -0.12, + 0.40, + -0.02, + 0.54, + parent=coxa, + mat_name="olive_armor", + chamfer=0.08, + top_taper_xy=(0.90, 0.86), + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Manticore.{leg}HipFlange", + -0.50, + 0.50, + -0.14, + 0.28, + -0.04, + 0.12, + parent=coxa, + mat_name="gunmetal", + chamfer=0.06, + bevel=0.006, + ) + ) + + # 2. Rear knee armor cap arching over bare gunmetal knee drum + outer drum cap (parented to LegB*.S1) + s1 = bpy.data.objects.get(f"{leg}.S1") + if s1 is not None: + # knee.dress.machine: x=[-0.44..0.44], y=[-0.34..0.34], z=[1.242..1.922]; femur.plate ends at z=1.25, y=[0.30..0.42] + created.append( + _make_arc_fender( + f"Shroud.Manticore.{leg}KneeCap", + center=Vector((0.0, 0.0, 1.58)), + axis=Vector((1.0, 0.0, 0.0)), + fwd_dir=Vector((0.0, 1.0, 0.0)), + up_dir=Vector((0.0, 0.0, 1.0)), + r_in=0.345, + r_out=0.445, + half_w=0.48, + ang_start_deg=-38.0, + ang_end_deg=132.0, + steps=8, + parent=s1, + mat_name="olive_armor", + end_taper_w=0.84, + bevel=0.010, + ) + ) + created.append( + _make_chamfer_box_shroud( + f"Shroud.Manticore.{leg}KneeCapTop", + -0.34, + 0.34, + 0.24, + 0.45, + 1.26, + 1.80, + parent=s1, + mat_name="olive_armor", + chamfer=0.06, + top_taper_xy=(0.88, 0.85), + bevel=0.009, + ) + ) + knee_side_rings: list[list[Vector]] = [] + for x_off, r in ((0.38, 0.28), (0.48, 0.28), (0.53, 0.19)): + px = x_out_sign * x_off + pts = [ + Vector((px, r * math.cos(math.radians(a)), 1.58 + r * math.sin(math.radians(a)))) + for a in range(0, 360, 45) + ] + if x_out_sign < 0: + pts = list(reversed(pts)) + knee_side_rings.append(pts) + created.append(_make_loft_shroud(f"Shroud.Manticore.{leg}KneeSideCap", knee_side_rings, s1, "olive_armor", bevel=0.008)) + + return created + + +def _add_paladin_shrouds() -> list[bpy.types.Object]: + created: list[bpy.types.Object] = [] + arm_r = bpy.data.objects.get("ArmR.Lower") + if arm_r is None: + return created + + # ArmR.Lower local box is [-0.297, -0.25, -0.144]..[0.297, 0.25, 1.55]. + # hp.weapon.arm_r sits on -X_local face at (-0.311, -0.124, 0.697) with 0.72x0.72 footprint -> keep -X_local z=[0.26..1.16] clear! + # Inner (+X), Front (+Y), and Rear (-Y) forearm plates: + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRInner", + 0.28, + 0.42, + -0.27, + 0.27, + 0.14, + 1.44, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.04, + top_taper_xy=(0.90, 0.88), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRFront", + -0.31, + 0.36, + 0.23, + 0.39, + 0.14, + 1.44, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.05, + top_taper_xy=(0.86, 0.86), + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRRear", + -0.31, + 0.36, + -0.39, + -0.23, + 0.14, + 1.44, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.05, + top_taper_xy=(0.86, 0.86), + bevel=0.009, + ) + ) + # Upper elbow cuff & lower wrist cuff collar (staying clear of hp.weapon.arm_r around z=0.26..1.16 on -X) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRElbowCuff", + -0.38, + 0.38, + -0.33, + 0.33, + -0.02, + 0.22, + parent=arm_r, + mat_name="olive_armor", + chamfer=0.06, + bevel=0.009, + ) + ) + created.append( + _make_chamfer_box_shroud( + "Shroud.Paladin.ArmRWristBand", + -0.34, + 0.36, + -0.30, + 0.30, + 1.36, + 1.50, + parent=arm_r, + mat_name="gunmetal", + chamfer=0.04, + bevel=0.006, + ) + ) + return created + + +def _add_actuator_armor_shrouds(mech_id: str) -> list[bpy.types.Object]: + builders = { + "kestrel": _add_kestrel_shrouds, + "spectre": _add_spectre_shrouds, + "raptor": _add_raptor_shrouds, + "manticore": _add_manticore_shrouds, + "paladin": _add_paladin_shrouds, + } + fn = builders.get(mech_id) + if fn is None: + return [] + return fn() + + +def retrofit_mech(spec: MechRetrofitSpec) -> dict[str, Any]: + bpy.ops.wm.open_mainfile(filepath=str(spec.blend_path)) + scene = bpy.context.scene + scene.unit_settings.system = "METRIC" + scene.unit_settings.scale_length = 1.0 + + # 1. Apply SOLIDIFY/BOOLEAN/BEVEL BEFORE stripping hidden boolean cutters + if not spec.armature_name: + _apply_existing_modifiers() + + # 2. Strip studio rig/backdrop & built-in weapons + stripped = _strip_scene_objects(spec) + + 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; strip protruding weapon islands + stripped_vgs: dict[str, int] = {} + if spec.strip_vertex_groups: + for obj in bpy.data.objects: + if obj.type == "MESH": + cnt = _strip_vertex_groups_from_mesh(obj, spec.strip_vertex_groups) + if cnt > 0: + stripped_vgs[obj.name] = cnt + if spec.strip_islands: + _strip_mesh_islands(spec.strip_islands) + if spec.mech_id == "kestrel": + _assemble_kestrel_hierarchy() + + # 4. Normalize procedural materials -> clean glTF PBR + _normalize_materials_for_gltf() + + # 5. Collect surviving mech meshes & decimate to game-ready LOD budget + mech_meshes = [o for o in bpy.data.objects if o.type == "MESH"] + raw_tris, lod_tris = _decimate_mech_meshes(mech_meshes, spec.target_mech_tris) + + # 5b. Add Brokkr-style olive-drab armor shrouds over exposed joints/actuators + shroud_objs = _add_actuator_armor_shrouds(spec.mech_id) + if shroud_objs: + shroud_tris = sum(_mesh_tri_count(o) for o in shroud_objs) + lod_tris += shroud_tris + print(f" [shroud] {spec.mech_id}: +{len(shroud_objs)} shrouds (+{shroud_tris} tris)") + + # 6. Parent everything cleanly under a root Empty (in raw Brokkr orientation first) + chassis_root = vc.make_empty(spec.mech_id, parent=None, location=(0.0, 0.0, 0.0)) + for obj in list(bpy.data.objects): + if obj == chassis_root or obj.parent is not None: + continue + mw = obj.matrix_world.copy() + obj.parent = chassis_root + obj.matrix_parent_inverse = Matrix.Identity(4) + obj.matrix_local = mw + bpy.context.view_layer.update() + + # 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, 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 + chassis_root.rotation_mode = "XYZ" + chassis_root.rotation_euler = Euler((0.0, 0.0, math.pi), "XYZ") + bpy.context.view_layer.update() + + # 9. Export GLB (grounding minZ=0.0), write manifest.json, render 4-panel preview + glb_path = vc.ASSETS_VEHICLES_DIR / spec.mech_id / f"{spec.mech_id}.glb" + manifest_path = vc.ASSETS_VEHICLES_DIR / spec.mech_id / "manifest.json" + preview_path = vc.PREVIEWS_DIR / f"{spec.mech_id}_preview.png" + + z_shift_before = chassis_root.location.z + tri_count, bounds = vc.export_vehicle_glb(glb_path, root=chassis_root) + ground_z_shift = chassis_root.location.z - z_shift_before + + 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 = [ + { + "id": hp.hp_id, + "kind": hp.kind, + "x": hp.x, + "y": hp.y, + "w": hp.w, + "h": hp.h, + "modelNodeId": hp.hp_id, + } + for hp in spec.hardpoints + ] + + vc.write_manifest( + manifest_path, + vehicle_id=spec.mech_id, + name=spec.name, + vehicle_class=spec.vehicle_class, + plane=spec.plane, + grid_width=spec.grid_width, + grid_height=spec.grid_height, + mask=spec.mask, + hardpoints=hp_manifest, + joints=joints_manifest, + bounds=bounds, + tri_count=tri_count, + mechanisms=mechanisms, + ) + + vc.render_four_panel_preview(preview_path) + glb_bytes = glb_path.stat().st_size + summary = { + "id": spec.mech_id, + "raw_tris_after_strip": raw_tris, + "lod_mech_tris": lod_tris, + "exported_total_tris": tri_count, + "glb_bytes": glb_bytes, + "bounds": bounds, + "stripped_count": len(stripped), + "stripped_vgs": stripped_vgs, + } + print(f"[{spec.mech_id}] {json.dumps(summary)}") + return summary + + +def main() -> int: + argv = sys.argv[sys.argv.index("--") + 1 :] if "--" in sys.argv else [] + parser = argparse.ArgumentParser(description="Retrofit Brokkr mechs for Rust to Dust.") + parser.add_argument("--mech", choices=sorted(SPECS.keys()), help="Single mech ID to retrofit.") + parser.add_argument("--all", action="store_true", help="Retrofit all configured mechs sequentially.") + args = parser.parse_args(argv) + + targets = list(SPECS.keys()) if (args.all or not args.mech) else [args.mech] + for mid in targets: + retrofit_mech(SPECS[mid]) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tools/vehicles/vehicle_common.py b/tools/vehicles/vehicle_common.py new file mode 100644 index 0000000..0077681 --- /dev/null +++ b/tools/vehicles/vehicle_common.py @@ -0,0 +1,1160 @@ +"""Shared Brokkr-powered vehicle construction, hardpoint sockets, joint tagging, +GLB export, manifest emission, and 4-panel preview rendering for Rust to Dust. + +All Blender geometry is authored in Blender right-handed Z-up coordinates with: + -Y = vehicle forward (+Z in exported glTF) + +Y = vehicle rear (-Z in exported glTF) + +Z = vehicle up (+Y in exported glTF, grounded at Z = 0) + +X = vehicle left (+X in exported glTF) + -X = vehicle right (-X in exported glTF) + +Export uses bpy.ops.export_scene.gltf(..., export_yup=True, export_extras=True) +so Godot receives +Z forward, +Y up, minY ~ 0.0, and rtd.* custom properties. +""" +from __future__ import annotations + +import json +import math +import sys +from pathlib import Path +from typing import Any, Callable, Sequence + +import bmesh +import bpy +import numpy as np +from mathutils import Euler, Matrix, Vector + +BROKKR_BLENDER_DIR = Path(r"F:\Projects\Brokkr\surfaces\blender") +if str(BROKKR_BLENDER_DIR) not in sys.path: + sys.path.insert(0, str(BROKKR_BLENDER_DIR)) + +import brokkr_mesh_polish # noqa: E402, F401 +import brokkr_kitbash # noqa: E402 +from brokkr_kitbash import core, plate, ram # noqa: E402, F401 + +REPO_ROOT = Path(__file__).resolve().parents[2] +ASSETS_VEHICLES_DIR = REPO_ROOT / "assets" / "vehicles" +ASSETS_GEAR_DIR = REPO_ROOT / "assets" / "gear" +PREVIEWS_DIR = Path(__file__).resolve().parent / "previews" + +# Shared industrial PBR palette (sRGB hex -> linear PBR base color) +PALETTE: dict[str, dict[str, Any]] = { + "olive_armor": {"hex": "#4e5740", "metallic": 0.28, "roughness": 0.58}, + "gunmetal": {"hex": "#2c302e", "metallic": 0.78, "roughness": 0.40}, + "rubber_dark": {"hex": "#191a19", "metallic": 0.04, "roughness": 0.86}, + "copper_rad": {"hex": "#9c5a34", "metallic": 0.86, "roughness": 0.34}, + "socket_bay": {"hex": "#151816", "metallic": 0.55, "roughness": 0.72}, + "signal_orange": {"hex": "#d96c27", "metallic": 0.18, "roughness": 0.44}, + "smoked_glass": {"hex": "#1e2a2d", "metallic": 0.12, "roughness": 0.10, "alpha": 0.82}, + # Imperial Tourist & salvage gear accents + "imperial_gold": {"hex": "#d4a634", "metallic": 0.90, "roughness": 0.26}, + "imperial_ivory": {"hex": "#ebe4d1", "metallic": 0.16, "roughness": 0.38}, + "cyan_coil": {"hex": "#38c9d8", "metallic": 0.20, "roughness": 0.25, "emission": "#38c9d8", "emission_strength": 1.8}, +} + +_KITS_CACHE: dict[str, dict] = {} + + +def srgb_hex_to_linear(hex_str: str) -> tuple[float, float, float, float]: + h = hex_str.lstrip("#") + vals = [int(h[i : i + 2], 16) / 255.0 for i in (0, 2, 4)] + + def to_lin(c: float) -> float: + return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4 + + return (to_lin(vals[0]), to_lin(vals[1]), to_lin(vals[2]), 1.0) + + +def reset_scene() -> bpy.types.Scene: + """Clear all objects, meshes, materials, cameras, lights, and orphan data.""" + bpy.ops.wm.read_factory_settings(use_empty=True) + scene = bpy.context.scene + scene.unit_settings.system = "METRIC" + scene.unit_settings.scale_length = 1.0 + return scene + + +def ensure_materials() -> dict[str, bpy.types.Material]: + """Create shared industrial PBR materials cleanly on Principled BSDF.""" + mats: dict[str, bpy.types.Material] = {} + for name, spec in PALETTE.items(): + mat = bpy.data.materials.get(name) + if mat is None: + mat = bpy.data.materials.new(name=name) + mat.use_nodes = True + nt = mat.node_tree + nt.nodes.clear() + out = nt.nodes.new("ShaderNodeOutputMaterial") + bsdf = nt.nodes.new("ShaderNodeBsdfPrincipled") + nt.links.new(bsdf.outputs["BSDF"], out.inputs["Surface"]) + bsdf.inputs["Base Color"].default_value = srgb_hex_to_linear(spec["hex"]) + bsdf.inputs["Metallic"].default_value = float(spec["metallic"]) + bsdf.inputs["Roughness"].default_value = float(spec["roughness"]) + if "alpha" in spec: + bsdf.inputs["Alpha"].default_value = float(spec["alpha"]) + mat.blend_method = "BLEND" if hasattr(mat, "blend_method") else "HASHED" + if "emission" in spec: + bsdf.inputs["Emission Color"].default_value = srgb_hex_to_linear(spec["emission"]) + bsdf.inputs["Emission Strength"].default_value = float(spec.get("emission_strength", 1.0)) + mats[name] = mat + return mats + + +def load_kit(name: str) -> dict: + if name not in _KITS_CACHE: + _KITS_CACHE[name] = core.load_kit(name) + return _KITS_CACHE[name] + + +def _assign_material(obj: bpy.types.Object, mat_name: str) -> None: + mat = bpy.data.materials.get(mat_name) + if mat is None: + ensure_materials() + mat = bpy.data.materials[mat_name] + if len(obj.data.materials): + obj.data.materials[0] = mat + else: + obj.data.materials.append(mat) + + +def _link_object( + obj: bpy.types.Object, + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), +) -> bpy.types.Object: + scene = bpy.context.scene + if obj.name not in scene.collection.objects: + scene.collection.objects.link(obj) + if parent is not None: + obj.parent = parent + obj.matrix_parent_inverse = Matrix.Identity(4) + obj.location = Vector(location) + obj.rotation_mode = "XYZ" + obj.rotation_euler = Euler([math.radians(a) for a in rotation_deg], "XYZ") + return obj + + +def _add_bevel(obj: bpy.types.Object, width: float, segments: int = 1, angle_deg: float = 30.0) -> None: + if width <= 0.0: + return + mod = obj.modifiers.new("Bevel", "BEVEL") + mod.width = width + mod.segments = segments + mod.limit_method = "ANGLE" + mod.angle_limit = math.radians(angle_deg) + mod.harden_normals = False + + +def make_empty( + name: str, + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + display_type: str = "PLAIN_AXES", + display_size: float = 0.12, +) -> bpy.types.Object: + obj = bpy.data.objects.new(name, None) + obj.empty_display_type = display_type + obj.empty_display_size = display_size + return _link_object(obj, parent=parent, location=location, rotation_deg=rotation_deg) + + +def make_mesh_from_swept( + name: str, + swept: Any, + mat_name: str, + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + bevel: float = 0.0, +) -> bpy.types.Object: + mesh = bpy.data.meshes.new(name) + brokkr_kitbash.write_mesh(mesh, swept) + obj = bpy.data.objects.new(name, mesh) + _assign_material(obj, mat_name) + _link_object(obj, parent=parent, location=location, rotation_deg=rotation_deg) + if bevel > 0.0: + _add_bevel(obj, bevel, segments=1) + return obj + + +def _build_inline_shape(name: str, shape_dict: dict[str, Any]) -> core.Built: + doc = { + "schema": core.SCHEMA, + "kit": "inline", + "doc": "inline part", + "socketTypes": {}, + "parts": [{ + "name": "p", + "doc": name, + "params": [], + "shapes": [shape_dict], + "sockets": [], + }], + } + checked = core.check_kit(doc) + return core.build(checked["parts"]["p"], {}) + + +def make_tube_part( + name: str, + r0: float, + r1: float, + length: float, + segments: int = 12, + inner0: float = 0.0, + inner1: float = 0.0, + smooth: bool = True, + mat_name: str = "gunmetal", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + bevel: float = 0.0, +) -> bpy.types.Object: + shape_dict: dict[str, Any] = { + "shape": "tube", + "r0": float(r0), + "r1": float(r1), + "length": float(length), + "segments": int(segments), + "smooth": bool(smooth), + } + if inner0 > 0.0 or inner1 > 0.0: + shape_dict["inner0"] = float(inner0) + shape_dict["inner1"] = float(inner1) + return make_mesh_from_swept( + name, + _build_inline_shape(name, shape_dict), + mat_name, + parent=parent, + location=location, + rotation_deg=rotation_deg, + bevel=bevel, + ) + + +def make_lathe_part( + name: str, + profile: Sequence[Sequence[float]], + segments: int = 16, + loop: bool = False, + smooth: bool = True, + mat_name: str = "gunmetal", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + bevel: float = 0.0, +) -> bpy.types.Object: + shape_dict = { + "shape": "lathe", + "segments": int(segments), + "loop": bool(loop), + "smooth": bool(smooth), + "profile": [[float(p[0]), float(p[1])] for p in profile], + } + return make_mesh_from_swept( + name, + _build_inline_shape(name, shape_dict), + mat_name, + parent=parent, + location=location, + rotation_deg=rotation_deg, + bevel=bevel, + ) + + +def make_kit_part( + name: str, + kit_name: str, + part_name: str, + params: dict[str, Any] | None = None, + mat_name: str = "gunmetal", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + bevel: float = 0.0, +) -> bpy.types.Object: + kit = load_kit(kit_name) + part_def = core.part(kit, part_name) + built = core.build(part_def, params or {}) + return make_mesh_from_swept( + name=name, + swept=built, + mat_name=mat_name, + parent=parent, + location=location, + rotation_deg=rotation_deg, + bevel=bevel, + ) + + +def _auto_ups(path: np.ndarray, closed: bool = False) -> np.ndarray: + """Compute smooth non-collinear up vectors along any 3D polyline for core.sweep.""" + n = len(path) + steps = (np.roll(path, -1, axis=0) - path)[: n if closed else n - 1] + lengths = np.linalg.norm(steps, axis=1, keepdims=True) + tangents = steps / np.maximum(lengths, 1e-9) + if closed: + vert_tan = tangents + np.roll(tangents, 1, axis=0) + else: + vert_tan = np.vstack([tangents[:1], tangents[:-1] + tangents[1:], tangents[-1:]]) + vert_tan /= np.maximum(np.linalg.norm(vert_tan, axis=1, keepdims=True), 1e-9) + ups = np.zeros_like(vert_tan) + ref = np.array([0.0, 0.0, 1.0]) if abs(vert_tan[0, 2]) < 0.85 else np.array([1.0, 0.0, 0.0]) + u0 = ref - vert_tan[0] * float(ref @ vert_tan[0]) + ups[0] = u0 / np.linalg.norm(u0) + for i in range(1, n): + u = ups[i - 1] - vert_tan[i] * float(ups[i - 1] @ vert_tan[i]) + norm = float(np.linalg.norm(u)) + if norm < 1e-5: + alt = np.array([1.0, 0.0, 0.0]) if abs(vert_tan[i, 0]) < 0.85 else np.array([0.0, 1.0, 0.0]) + u = alt - vert_tan[i] * float(alt @ vert_tan[i]) + norm = float(np.linalg.norm(u)) + ups[i] = u / norm + return ups + + +def fillet_polyline(points: Sequence[Sequence[float]], radius: float = 0.05, subdivs: int = 2, closed: bool = False) -> np.ndarray: + """Round interior corners of a 3D polyline so core.sweep stays well below TURN_LIMIT.""" + pts = np.asarray(points, dtype=np.float64) + if len(pts) < 3 or radius <= 0.0: + return pts + out: list[np.ndarray] = [] + n = len(pts) + indices = range(n) if closed else range(1, n - 1) + if not closed: + out.append(pts[0]) + for i in indices: + p_prev = pts[(i - 1) % n] + p_curr = pts[i] + p_next = pts[(i + 1) % n] + v_in = p_curr - p_prev + v_out = p_next - p_curr + l_in = float(np.linalg.norm(v_in)) + l_out = float(np.linalg.norm(v_out)) + if l_in < 1e-6 or l_out < 1e-6: + out.append(p_curr) + continue + d_in = v_in / l_in + d_out = v_out / l_out + if float(d_in @ d_out) > 0.995: + out.append(p_curr) + continue + trim = min(radius, 0.35 * l_in, 0.35 * l_out) + a = p_curr - d_in * trim + b = p_curr + d_out * trim + for k in range(subdivs + 1): + t = k / subdivs + # Quadratic Bezier corner blend + pt = (1 - t) ** 2 * a + 2 * (1 - t) * t * p_curr + t ** 2 * b + out.append(pt) + if not closed: + out.append(pts[-1]) + return np.array(out, dtype=np.float64) + + +def make_swept_tube( + name: str, + points: Sequence[Sequence[float]], + radius: float, + segments: int = 8, + mat_name: str = "gunmetal", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + closed: bool = False, + fillet_r: float = 0.04, +) -> bpy.types.Object: + path = fillet_polyline(points, radius=fillet_r, subdivs=2, closed=closed) if fillet_r > 0 else np.asarray(points, dtype=np.float64) + ups = _auto_ups(path, closed=closed) + swept = core.sweep(path, core.circle(radius, segments), ups, closed=closed) + return make_mesh_from_swept(name, swept, mat_name, parent=parent, location=location, rotation_deg=rotation_deg) + + +def make_swept_profile( + name: str, + section: str, + w: float, + h: float, + t: float, + points: Sequence[Sequence[float]], + up: Sequence[float] | None = None, + mat_name: str = "gunmetal", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + closed: bool = False, +) -> bpy.types.Object: + path = np.asarray(points, dtype=np.float64) + ups = np.asarray(up, dtype=np.float64) if up is not None else _auto_ups(path, closed=closed) + swept = core.sweep(path, core.profile(section, w, h, t), ups, closed=closed) + return make_mesh_from_swept(name, swept, mat_name, parent=parent, location=location, rotation_deg=rotation_deg) + + +def make_box( + name: str, + size: Sequence[float], + mat_name: str = "olive_armor", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + bevel: float = 0.008, +) -> bpy.types.Object: + sx, sy, sz = (float(v) for v in size) + V = core.BOX_SIGNS * np.array([sx, sy, sz], dtype=np.float64) + swept = core.Swept( + V=V, + faces=core.BOX_FACES.ravel().astype(np.int32), + counts=np.full(6, 4, dtype=np.int32), + smooth=np.zeros(6, dtype=bool), + sharp=core.NO_SHARP.astype(np.int32), + ) + return make_mesh_from_swept(name, swept, mat_name, parent=parent, location=location, rotation_deg=rotation_deg, bevel=bevel) + + +def make_bmesh_object( + name: str, + builder: Callable[[bmesh.types.BMesh], None], + mat_name: str = "olive_armor", + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + rotation_deg: Sequence[float] = (0.0, 0.0, 0.0), + bevel: float = 0.0, + smooth: bool = False, +) -> bpy.types.Object: + bm = bmesh.new() + builder(bm) + bmesh.ops.recalc_face_normals(bm, faces=bm.faces) + mesh = bpy.data.meshes.new(name) + bm.to_mesh(mesh) + bm.free() + if smooth: + for poly in mesh.polygons: + poly.use_smooth = True + obj = bpy.data.objects.new(name, mesh) + _assign_material(obj, mat_name) + _link_object(obj, parent=parent, location=location, rotation_deg=rotation_deg) + if bevel > 0.0: + _add_bevel(obj, bevel, segments=1) + return obj + + +def _write_vf_mesh(name: str, V: np.ndarray, faces: list[list[int]], mat_name: str, parent: bpy.types.Object | None = None, bevel: float = 0.0) -> bpy.types.Object: + mesh = bpy.data.meshes.new(name) + mesh.from_pydata(np.asarray(V, dtype=np.float64).tolist(), [], [[int(k) for k in f] for f in faces]) + sharp = mesh.attributes.get("sharp_face") or mesh.attributes.new("sharp_face", "BOOLEAN", "FACE") + sharp.data.foreach_set("value", np.ones(len(mesh.polygons), dtype=bool)) + mesh.update() + obj = bpy.data.objects.new(name, mesh) + _assign_material(obj, mat_name) + _link_object(obj, parent=parent) + if bevel > 0.0: + _add_bevel(obj, bevel, segments=1, angle_deg=15.0) + return obj + + +def make_plates( + table_doc: dict[str, Any], + parent: bpy.types.Object | None = None, + prefix: str = "", + side: int = 1, +) -> list[bpy.types.Object]: + """Build Brokkr hard armour plates (brokkr.plates.v0) directly into Blender objects.""" + checked = plate.check(table_doc) + entries = plate.build(checked, side=side) + created: list[bpy.types.Object] = [] + for entry in entries: + row = checked["plates"][entry["row"]] + pname = f"{prefix}{entry['name']}" + solid_obj = _write_vf_mesh(pname, entry["solid"][0], entry["solid"][1], row["mat"], parent=parent, bevel=row["bevel"]) + created.append(solid_obj) + clad = row["clad"] + if clad: + if len(entry["panels"][1]): + p_obj = _write_vf_mesh(f"{pname}.panels", entry["panels"][0], entry["panels"][1], clad["mat"], parent=solid_obj, bevel=clad["bevel"]) + created.append(p_obj) + if len(entry["bolts"][1]): + b_obj = _write_vf_mesh(f"{pname}.bolts", entry["bolts"][0], entry["bolts"][1], clad["bolt_mat"], parent=solid_obj, bevel=0.0) + created.append(b_obj) + for fit_mat, fit_mesh in entry["fits"].items(): + if len(fit_mesh[1]): + f_obj = _write_vf_mesh(f"{pname}.fit.{fit_mat}", fit_mesh[0], fit_mesh[1], fit_mat, parent=solid_obj, bevel=0.0) + created.append(f_obj) + return created + + +def make_knobby_wheel( + name: str, + radius: float, + width: float, + parent: bpy.types.Object | None = None, + location: Sequence[float] = (0.0, 0.0, 0.0), + tread_lugs: int = 18, + rim_segments: int = 20, + side_sign: int = 1, +) -> bpy.types.Object: + """Build a crisp game-ready off-road wheel centered at (0,0,0) spinning about local X. + + side_sign = +1 for left (+X) wheel (hub faces +X), -1 for right (-X) wheel (hub faces -X). + """ + hub_pivot = make_empty(f"{name}_hub", parent=parent, location=location) + # Tire carcass via lathe rotated onto X axis (tube/lathe builds along +Z, so rot_y = 90) + r_rim = radius * 0.56 + r_side = radius * 0.92 + hw = width * 0.5 + tire_profile = [ + [r_rim * 0.96, -hw * 0.85], + [r_side, -hw * 0.95], + [radius * 0.96, -hw * 0.72], + [radius * 0.96, hw * 0.72], + [r_side, hw * 0.95], + [r_rim * 0.96, hw * 0.85], + ] + make_lathe_part( + f"{name}_tire", + tire_profile, + segments=rim_segments, + loop=True, + smooth=True, + mat_name="rubber_dark", + parent=hub_pivot, + rotation_deg=(0.0, 90.0, 0.0), + ) + + # Staggered knobby tread lugs around circumference (compact, low poly, high visual read) + def build_tread(bm: bmesh.types.BMesh) -> None: + lug_w = width * 0.38 + lug_h = radius * 0.055 + lug_len = (2.0 * math.pi * radius / tread_lugs) * 0.52 + for i in range(tread_lugs): + ang = 2.0 * math.pi * i / tread_lugs + for row_s in (-1.0, 1.0): + a = ang + (0.5 if row_s > 0 else 0.0) * (2.0 * math.pi / tread_lugs) + cy = math.cos(a) * (radius * 0.965) + cz = math.sin(a) * (radius * 0.965) + cx = row_s * hw * 0.42 + mat = ( + Matrix.Translation((cx, cy, cz)) + @ Matrix.Rotation(a, 4, "X") + @ Matrix.Scale(lug_w, 4, (1, 0, 0)) + @ Matrix.Scale(lug_h, 4, (0, 1, 0)) + @ Matrix.Scale(lug_len, 4, (0, 0, 1)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=mat) + + make_bmesh_object(f"{name}_treads", build_tread, "rubber_dark", parent=hub_pivot) + + # Steel wheel dish rim + hub cap (CCW in (r, z); +Z points outward via rot_y = 90 * side_sign) + rim_profile = [ + [0.0, -hw * 0.45], + [r_rim * 0.98, -hw * 0.45], + [r_rim * 0.98, hw * 0.86], + [r_rim * 0.82, hw * 0.86], + [r_rim * 0.72, hw * 0.48], + [r_rim * 0.30, hw * 0.48], + [r_rim * 0.25, hw * 0.82], + [0.0, hw * 0.82], + ] + make_lathe_part( + f"{name}_rim", + rim_profile, + segments=16, + loop=False, + smooth=True, + mat_name="gunmetal", + parent=hub_pivot, + rotation_deg=(0.0, 90.0 * side_sign, 0.0), + ) + + # Hub lug ring + def build_lugs(bm: bmesh.types.BMesh) -> None: + hx = side_sign * hw * 0.62 + for i in range(6): + a = 2.0 * math.pi * i / 6.0 + r_b = r_rim * 0.50 + m = Matrix.Translation((hx, math.cos(a) * r_b, math.sin(a) * r_b)) @ Matrix.Rotation(math.pi * 0.5, 4, "Y") + bmesh.ops.create_cone(bm, cap_ends=True, cap_tris=False, segments=6, radius1=radius * 0.042, radius2=radius * 0.042, depth=width * 0.14, matrix=m) + + make_bmesh_object(f"{name}_hubbolts", build_lugs, "signal_orange", parent=hub_pivot) + return hub_pivot + + +def make_ram_span( + name: str, + p_base: Sequence[float], + p_tip: Sequence[float], + body_r: float = 0.036, + rod_r: float = 0.020, + parent: bpy.types.Object | None = None, + mat_barrel: str = "gunmetal", + mat_rod: str = "copper_rad", + coil_rings: int = 0, +) -> bpy.types.Object: + """Create a realistic hydraulic actuator or coilover strut spanning p_base -> p_tip.""" + a = np.asarray(p_base, dtype=np.float64) + b = np.asarray(p_tip, dtype=np.float64) + vec = b - a + total = float(np.linalg.norm(vec)) + if total < 1e-4: + raise ValueError(f"Ram {name} has zero span") + z_dir = Vector((vec / total).tolist()) + quat = Vector((0.0, 0.0, 1.0)).rotation_difference(z_dir) + rot_deg = tuple(math.degrees(v) for v in quat.to_euler("XYZ")) + root = make_empty(name, parent=parent, location=a.tolist(), rotation_deg=rot_deg) + + body_len = max(0.05, total * 0.54) + rod_len = max(0.05, total * 0.56) + if 0.05 <= body_r <= 0.12 and 0.2 <= body_len <= 1.0 and 0.2 <= rod_len <= 2.0 and 0.01 <= rod_r <= 0.02: + make_kit_part( + f"{name}_barrel", + "mechanical", + "ram_barrel", + {"body_r": body_r, "body_len": body_len, "rod_r": rod_r, "segments": 10}, + mat_name=mat_barrel, + parent=root, + ) + make_kit_part( + f"{name}_rod", + "mechanical", + "ram_rod", + {"body_r": body_r, "rod_r": rod_r, "length": rod_len, "segments": 10}, + mat_name=mat_rod, + parent=root, + location=(0.0, 0.0, total), + rotation_deg=(180.0, 0.0, 0.0), + ) + else: + make_tube_part(f"{name}_barrel", body_r, body_r, body_len, segments=10, mat_name=mat_barrel, parent=root) + make_tube_part( + f"{name}_rod", + rod_r, + rod_r, + rod_len, + segments=8, + mat_name=mat_rod, + parent=root, + location=(0.0, 0.0, total - rod_len), + ) + if coil_rings > 0: + def build_coils(bm: bmesh.types.BMesh) -> None: + z0 = total * 0.16 + z1 = total * 0.78 + for k in range(coil_rings): + z = z0 + (z1 - z0) * (k / max(1, coil_rings - 1)) + # Octagonal spring ring + pts = [] + rc = body_r * 1.48 + for s in range(10): + ang = 2.0 * math.pi * s / 10.0 + pts.append((rc * math.cos(ang), rc * math.sin(ang), z)) + # Build small torus-like faceted collar ring + for s in range(10): + p0 = Vector(pts[s]) + p1 = Vector(pts[(s + 1) % 10]) + mid = (p0 + p1) * 0.5 + seg_dir = (p1 - p0).normalized() + q_seg = Vector((0, 0, 1)).rotation_difference(seg_dir) + m = Matrix.Translation(mid) @ q_seg.to_matrix().to_4x4() + bmesh.ops.create_cone( + bm, cap_ends=True, cap_tris=False, segments=6, + radius1=body_r * 0.24, radius2=body_r * 0.24, + depth=(p1 - p0).length * 1.08, matrix=m, + ) + + make_bmesh_object(f"{name}_coil", build_coils, "signal_orange", parent=root) + return root + + +def add_hardpoint_slot( + hp_id: str, + kind: str, + parent: bpy.types.Object, + 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) + + if kind == "weapon": + 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], + [r_outer, 0.0], + [r_outer, collar_h * 0.65], + [r_outer * 0.92, collar_h], + [r_inner * 1.04, collar_h], + [r_inner, collar_h * 0.35], + ] + make_lathe_part( + f"{hp_id}.collar", + collar_prof, + segments=12, + loop=True, + smooth=False, + mat_name="gunmetal", + parent=bay_root, + ) + # Recessed dark weapon socket floor + make_box(f"{hp_id}.well", (r_inner * 1.65, r_inner * 1.65, 0.024), "socket_bay", parent=bay_root, location=(0.0, 0.0, 0.012), bevel=0.0) + # Twin mounting rails + 4 signal-orange lock lugs + 8 perimeter bolts + rail_sep = r_inner * 0.52 + for side in (-1.0, 1.0): + make_box( + f"{hp_id}.rail_{'l' if side > 0 else 'r'}", + (0.04, r_inner * 1.45, collar_h * 0.72), + "gunmetal", + parent=bay_root, + location=(side * rail_sep, 0.0, collar_h * 0.38), + bevel=0.004, + ) + def build_lugs_and_bolts(bm: bmesh.types.BMesh) -> None: + for ang_deg in (45.0, 135.0, 225.0, 315.0): + a = math.radians(ang_deg) + rl = r_outer * 0.88 + m = Matrix.Translation((rl * math.cos(a), rl * math.sin(a), collar_h * 0.96)) @ Matrix.Rotation(a, 4, "Z") + bmesh.ops.create_cube(bm, size=1.0, matrix=m @ Matrix.Diagonal((0.065, 0.042, 0.032, 1.0))) + + make_bmesh_object(f"{hp_id}.lugs", build_lugs_and_bolts, "signal_orange", parent=bay_root) + + def build_bolts(bm: bmesh.types.BMesh) -> None: + for k in range(8): + a = 2.0 * math.pi * k / 8.0 + rb = r_outer * 0.84 + m = Matrix.Translation((rb * math.cos(a), rb * math.sin(a), collar_h * 0.85)) + bmesh.ops.create_cone(bm, cap_ends=True, cap_tris=False, segments=6, radius1=0.016, radius2=0.014, depth=0.02, matrix=m) + + make_bmesh_object(f"{hp_id}.bolts", build_bolts, "gunmetal", parent=bay_root) + anchor_z = collar_h * 0.82 + + 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) + make_box(f"{hp_id}.frame_top", (sx, frame_t, depth), "gunmetal", parent=bay_root, location=(0.0, sy * 0.5 - frame_t * 0.5, depth * 0.5), bevel=0.005) + make_box(f"{hp_id}.frame_bot", (sx, frame_t, depth), "gunmetal", parent=bay_root, location=(0.0, -sy * 0.5 + frame_t * 0.5, depth * 0.5), bevel=0.005) + make_box(f"{hp_id}.frame_l", (frame_t, sy - frame_t * 2, depth), "gunmetal", parent=bay_root, location=(sx * 0.5 - frame_t * 0.5, 0.0, depth * 0.5), bevel=0.005) + make_box(f"{hp_id}.frame_r", (frame_t, sy - frame_t * 2, depth), "gunmetal", parent=bay_root, location=(-sx * 0.5 + frame_t * 0.5, 0.0, depth * 0.5), bevel=0.005) + # Copper radiator core louvers inside the bay + n_fins = max(5, min(11, int(sy / 0.065))) + def build_louvers(bm: bmesh.types.BMesh) -> None: + inner_w = sx - frame_t * 2.2 + inner_h = sy - frame_t * 2.2 + for i in range(n_fins): + y = -inner_h * 0.44 + inner_h * 0.88 * (i / max(1, n_fins - 1)) + m = ( + Matrix.Translation((0.0, y, depth * 0.58)) + @ Matrix.Rotation(math.radians(24.0), 4, "X") + @ Matrix.Diagonal((inner_w, 0.018, depth * 0.42, 1.0)) + ) + bmesh.ops.create_cube(bm, size=1.0, matrix=m) + + make_bmesh_object(f"{hp_id}.louvers", build_louvers, "copper_rad", parent=bay_root) + # Corner flange bolts + signal-orange lock tabs + def build_tabs(bm: bmesh.types.BMesh) -> None: + for xs in (-1.0, 1.0): + for ys in (-1.0, 1.0): + m = Matrix.Translation((xs * (sx * 0.42), ys * (sy * 0.42), depth * 1.02)) + bmesh.ops.create_cube(bm, size=1.0, matrix=m @ Matrix.Diagonal((0.045, 0.045, 0.022, 1.0))) + + make_bmesh_object(f"{hp_id}.locktabs", build_tabs, "signal_orange", parent=bay_root) + anchor_z = depth * 0.55 + + 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 + for xs in (-1.0, 1.0): + make_box(f"{hp_id}.coam_{'l' if xs > 0 else 'r'}", (wall_t, sy, depth), "gunmetal", parent=bay_root, location=(xs * (sx * 0.5 - wall_t * 0.5), 0.0, depth * 0.5), bevel=0.006) + for ys in (-1.0, 1.0): + make_box(f"{hp_id}.coam_{'b' if ys > 0 else 'f'}", (sx - wall_t * 2, wall_t, depth * 0.85), "gunmetal", parent=bay_root, location=(0.0, ys * (sy * 0.5 - wall_t * 0.5), depth * 0.42), bevel=0.006) + # Twin internal engine mount cradle rails + exhaust manifold stubs + for xs in (-1.0, 1.0): + make_box(f"{hp_id}.cradle_{'l' if xs > 0 else 'r'}", (0.05, sy * 0.72, depth * 0.45), "gunmetal", parent=bay_root, location=(xs * sx * 0.22, 0.0, depth * 0.45), bevel=0.004) + make_swept_tube( + f"{hp_id}.manifold_{'l' if xs > 0 else 'r'}", + [ + [xs * sx * 0.16, -sy * 0.26, depth * 0.55], + [xs * sx * 0.30, -sy * 0.12, depth * 0.74], + [xs * sx * 0.30, sy * 0.20, depth * 0.74], + ], + 0.022, + segments=8, + mat_name="copper_rad", + parent=bay_root, + fillet_r=0.03, + ) + # Signal-orange lock pins at corners + def build_pins(bm: bmesh.types.BMesh) -> None: + for xs in (-1.0, 1.0): + for ys in (-1.0, 1.0): + m = Matrix.Translation((xs * (sx * 0.40), ys * (sy * 0.40), depth * 1.02)) + bmesh.ops.create_cone(bm, cap_ends=True, cap_tris=False, segments=8, radius1=0.022, radius2=0.018, depth=0.036, matrix=m) + + make_bmesh_object(f"{hp_id}.lockpins", build_pins, "signal_orange", parent=bay_root) + anchor_z = depth * 0.45 + + 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)) + def build_bosses(bm: bmesh.types.BMesh) -> None: + for i in range(n_boss): + x = -sx * 0.38 + sx * 0.76 * (i / max(1, n_boss - 1)) + m = Matrix.Translation((x, 0.0, rail_h * 0.65)) + bmesh.ops.create_cube(bm, size=1.0, matrix=m @ Matrix.Diagonal((0.09, sy * 0.48, rail_h * 0.45, 1.0))) + + make_bmesh_object(f"{hp_id}.bosses", build_bosses, "gunmetal", parent=bay_root) + + def build_studs(bm: bmesh.types.BMesh) -> None: + for i in range(n_boss): + x = -sx * 0.38 + sx * 0.76 * (i / max(1, n_boss - 1)) + m = Matrix.Translation((x, 0.0, rail_h * 0.98)) + bmesh.ops.create_cone(bm, cap_ends=True, cap_tris=False, segments=8, radius1=0.024, radius2=0.018, depth=0.038, matrix=m) + + make_bmesh_object(f"{hp_id}.studs", build_studs, "signal_orange", parent=bay_root) + anchor_z = rail_h * 0.75 + + # Authoritative glTF Empty anchor + anchor = make_empty( + hp_id, + parent=bay_root, + location=(0.0, 0.0, anchor_z), + rotation_deg=(0.0, 0.0, 0.0), + display_type="ARROWS", + display_size=0.18, + ) + anchor["rtd.id"] = hp_id + anchor["rtd.kind"] = kind + anchor["rtd.size"] = [float(sx), float(sy), float(sz)] + return anchor + + +def tag_joint( + node: bpy.types.Object, + joint_id: str, + axis_gltf: Sequence[float], + min_val: float, + max_val: float, +) -> bpy.types.Object: + """Tag a pivot/mechanism node with rtd.joint metadata exported in glTF extras.""" + node["rtd.joint"] = joint_id + node["rtd.axis"] = [float(axis_gltf[0]), float(axis_gltf[1]), float(axis_gltf[2])] + node["rtd.min"] = float(min_val) + node["rtd.max"] = float(max_val) + return node + + +def scene_triangle_count(context: bpy.types.Context | None = None) -> int: + ctx = context or bpy.context + depsgraph = ctx.evaluated_depsgraph_get() + total = 0 + for obj in ctx.scene.objects: + if obj.type != "MESH" or obj.name.startswith("_preview_"): + continue + ev = obj.evaluated_get(depsgraph) + me = ev.to_mesh() + me.calc_loop_triangles() + total += len(me.loop_triangles) + ev.to_mesh_clear() + return total + + +def scene_bounds_blender(context: bpy.types.Context | None = None) -> tuple[Vector, Vector]: + ctx = context or bpy.context + depsgraph = ctx.evaluated_depsgraph_get() + mins = [math.inf, math.inf, math.inf] + maxs = [-math.inf, -math.inf, -math.inf] + for obj in ctx.scene.objects: + if obj.type != "MESH" or obj.name.startswith("_preview_"): + continue + ev = obj.evaluated_get(depsgraph) + me = ev.to_mesh() + mw = obj.matrix_world + for v in me.vertices: + w = mw @ v.co + for i in range(3): + mins[i] = min(mins[i], w[i]) + maxs[i] = max(maxs[i], w[i]) + ev.to_mesh_clear() + return Vector(mins), Vector(maxs) + + +def ground_root_to_z0(root: bpy.types.Object) -> float: + """Shift root along Z so the lowest evaluated mesh vertex sits at Z = 0.""" + bpy.context.view_layer.update() + b_min, _ = scene_bounds_blender() + if math.isfinite(b_min.z) and abs(b_min.z) > 1e-5: + root.location.z -= b_min.z + bpy.context.view_layer.update() + return -b_min.z + return 0.0 + + +def bounds_gltf_from_blender(b_min: Vector, b_max: Vector) -> dict[str, list[float]]: + """Convert Blender Z-up bounds to glTF Y-up bounds: (x, y, z)_gltf = (x, z, -y)_blender.""" + g_min = [round(b_min.x, 4), round(b_min.z, 4), round(-b_max.y, 4)] + g_max = [round(b_max.x, 4), round(b_max.z, 4), round(-b_min.y, 4)] + size = [round(g_max[i] - g_min[i], 4) for i in range(3)] + return {"min": g_min, "max": g_max, "size": size} + + +def export_vehicle_glb(glb_path: Path, root: bpy.types.Object | None = None) -> tuple[int, dict[str, list[float]]]: + """Ground scene (if root given), measure evaluated tris & glTF bounds, and export .glb.""" + if root is not None: + ground_root_to_z0(root) + bpy.context.view_layer.update() + tri_count = scene_triangle_count() + b_min, b_max = scene_bounds_blender() + bounds_gltf = bounds_gltf_from_blender(b_min, b_max) + + glb_path.parent.mkdir(parents=True, exist_ok=True) + # Hide any preview helper objects if present + bpy.ops.export_scene.gltf( + filepath=str(glb_path), + export_format="GLB", + export_yup=True, + export_extras=True, + export_apply=True, + export_materials="EXPORT", + export_normals=True, + export_texcoords=True, + use_visible=True, + ) + return tri_count, bounds_gltf + + +def write_manifest( + manifest_path: Path, + *, + vehicle_id: str, + name: str, + vehicle_class: str, + grid_width: int, + grid_height: int, + mask: Sequence[str] | Sequence[bool], + hardpoints: list[dict[str, Any]], + joints: list[dict[str, Any]], + bounds: dict[str, list[float]], + tri_count: int, + plane: str = "Dorsal", + mechanisms: dict[str, Any] | None = None, +) -> None: + if len(mask) == grid_height and isinstance(mask[0], str): + mask_bools = [ch == "#" for row in mask for ch in row] + else: + mask_bools = [bool(v) for v in mask] + doc = { + "schema": "rtd.vehicle.manifest.v1", + "id": vehicle_id, + "name": name, + "class": vehicle_class, + "plane": plane, + "gridWidth": grid_width, + "gridHeight": grid_height, + "mask": mask_bools, + "hardpoints": hardpoints, + "joints": joints, + "bounds": bounds, + "triCount": int(tri_count), + } + if mechanisms is not None: + doc["mechanisms"] = mechanisms + manifest_path.parent.mkdir(parents=True, exist_ok=True) + manifest_path.write_text(json.dumps(doc, indent=2) + "\n", encoding="utf-8") + + +def _aim_camera_at(cam_obj: bpy.types.Object, eye: Vector, target: Vector) -> None: + cam_obj.location = eye + direction = (target - eye).normalized() + cam_obj.rotation_euler = direction.to_track_quat("-Z", "Y").to_euler() + + +def render_four_panel_preview(preview_path: Path, panel_w: int = 640, panel_h: int = 480) -> Path: + """Render 3/4 Hero, Front (-Y), Side (+X), and Top Dorsal (+Z) views via EEVEE into one 2x2 PNG.""" + scene = bpy.context.scene + bpy.context.view_layer.update() + b_min, b_max = scene_bounds_blender() + center = (b_min + b_max) * 0.5 + extent = max((b_max - b_min).length, 1.5) + + # Setup world + studio lighting + ground plinth + world = bpy.data.worlds.new("_preview_world") + scene.world = world + world.use_nodes = True + bg = world.node_tree.nodes.get("Background") + if bg: + bg.inputs["Color"].default_value = (0.045, 0.050, 0.048, 1.0) + bg.inputs["Strength"].default_value = 1.1 + + # Ground disc (dark slate) + floor_mat = bpy.data.materials.new("_preview_floor_mat") + floor_mat.use_nodes = True + f_bsdf = floor_mat.node_tree.nodes.get("Principled BSDF") + if f_bsdf: + f_bsdf.inputs["Base Color"].default_value = (0.08, 0.085, 0.082, 1.0) + f_bsdf.inputs["Roughness"].default_value = 0.88 + bpy.ops.mesh.primitive_cylinder_add(vertices=48, radius=extent * 1.4, depth=0.04, location=(center.x, center.y, b_min.z - 0.021)) + floor_obj = bpy.context.active_object + floor_obj.name = "_preview_floor" + floor_obj.data.materials.append(floor_mat) + + def add_sun(name: str, rot_deg: Sequence[float], energy: float, color: Sequence[float]) -> bpy.types.Object: + ldata = bpy.data.lights.new(name, type="SUN") + ldata.energy = energy + ldata.color = color + lobj = bpy.data.objects.new(name, ldata) + scene.collection.objects.link(lobj) + lobj.rotation_euler = Euler([math.radians(a) for a in rot_deg], "XYZ") + return lobj + + lights = [ + add_sun("_preview_key", (48.0, 12.0, -35.0), 3.4, (1.0, 0.96, 0.90)), + add_sun("_preview_fill", (55.0, -15.0, 135.0), 1.4, (0.78, 0.86, 0.98)), + add_sun("_preview_rim", (25.0, 0.0, 175.0), 1.6, (1.0, 0.90, 0.78)), + ] + + cam_data = bpy.data.cameras.new("_preview_cam") + cam_data.lens = 42.0 + cam_obj = bpy.data.objects.new("_preview_cam", cam_data) + scene.collection.objects.link(cam_obj) + scene.camera = cam_obj + + scene.render.engine = "BLENDER_EEVEE" + scene.render.resolution_x = panel_w + scene.render.resolution_y = panel_h + scene.render.resolution_percentage = 100 + scene.render.image_settings.file_format = "PNG" + scene.render.image_settings.color_mode = "RGBA" + if hasattr(scene, "eevee"): + scene.eevee.taa_render_samples = 16 + + size_vec = b_max - b_min + d_hero = extent * 1.18 + d_ortho = max(size_vec.x, size_vec.y, size_vec.z) * 1.25 + + views = [ + ("hero", "PERSP", center + Vector((d_hero * 0.72, -d_hero * 0.85, d_hero * 0.46)), center), + ("front", "ORTHO", center + Vector((0.0, -d_ortho * 2.0, size_vec.z * 0.04)), center), + ("side", "ORTHO", center + Vector((d_ortho * 2.0, 0.0, size_vec.z * 0.04)), center), + ("top", "ORTHO", center + Vector((0.0, 0.0, d_ortho * 2.0)), center), + ] + + preview_path.parent.mkdir(parents=True, exist_ok=True) + tmp_files: list[Path] = [] + panels: list[np.ndarray] = [] + + for idx, (tag, proj, eye, tgt) in enumerate(views): + cam_data.type = proj + if proj == "ORTHO": + aspect = panel_w / max(1, panel_h) + if tag == "front": + cam_data.ortho_scale = max(size_vec.x * 1.32, size_vec.z * aspect * 1.38) + elif tag == "side": + cam_data.ortho_scale = max(size_vec.y * 1.24, size_vec.z * aspect * 1.35) + else: + cam_data.ortho_scale = max(size_vec.x * 1.30, size_vec.y * aspect * 1.22) + _aim_camera_at(cam_obj, eye, tgt) + # Keep top view upright with nose (-Y) pointing up in image + if tag == "top": + cam_obj.rotation_euler = Euler((0.0, 0.0, math.radians(180.0)), "XYZ") + + tmp_png = preview_path.with_name(f".tmp_{preview_path.stem}_{tag}.png") + tmp_files.append(tmp_png) + scene.render.filepath = str(tmp_png) + bpy.ops.render.render(write_still=True) + + img = bpy.data.images.load(str(tmp_png), check_existing=False) + arr = np.empty(panel_w * panel_h * 4, dtype=np.float32) + img.pixels.foreach_get(arr) + bpy.data.images.remove(img) + panels.append(arr.reshape((panel_h, panel_w, 4))) + + # Stitch 2x2 grid (note Blender image pixel row 0 is bottom): + # Top row in final PNG = [hero (TL), front (TR)] -> higher Y in Blender image space + # Bottom row in final PNG = [side (BL), top (BR)] -> lower Y in Blender image space + top_row = np.concatenate([panels[0], panels[1]], axis=1) + bot_row = np.concatenate([panels[2], panels[3]], axis=1) + # 4px dark divider lines + grid = np.concatenate([bot_row, top_row], axis=0) + grid[:, panel_w - 2 : panel_w + 2, :3] = 0.25 + grid[panel_h - 2 : panel_h + 2, :, :3] = 0.25 + + out_img = bpy.data.images.new("_preview_composite", width=panel_w * 2, height=panel_h * 2, alpha=True) + out_img.pixels.foreach_set(grid.ravel().tolist()) + out_img.filepath_raw = str(preview_path) + out_img.file_format = "PNG" + out_img.save() + bpy.data.images.remove(out_img) + + # Cleanup temp renders and preview objects + for tmp in tmp_files: + if tmp.exists(): + tmp.unlink() + for obj in [floor_obj, cam_obj, *lights]: + bpy.data.objects.remove(obj, do_unlink=True) + bpy.data.materials.remove(floor_mat) + bpy.data.worlds.remove(world) + + return preview_path diff --git a/tools/vehicles/verify_glbs.py b/tools/vehicles/verify_glbs.py new file mode 100644 index 0000000..bc7694d --- /dev/null +++ b/tools/vehicles/verify_glbs.py @@ -0,0 +1,463 @@ +"""Validate all exported vehicle GLBs, manifests, hardpoint anchors, joints, bounds, and gear GLBs.""" +from __future__ import annotations + +import json +import math +import struct +import sys +from pathlib import Path +from typing import Any + +import numpy as np + +REPO_ROOT = Path(__file__).resolve().parents[2] +VEHICLES_DIR = REPO_ROOT / "assets" / "vehicles" +GEAR_DIR = REPO_ROOT / "assets" / "gear" + +EXPECTED_VEHICLES = ( + "jackal", "mule", "ferret", "hornet", "mammoth", "ironclad", "anvil", "condor", + "breaker", "paladin", "raptor", "manticore", "bastion", "spectre", "kestrel", +) +RETROFIT_MECHS = frozenset({"breaker", "paladin", "raptor", "manticore", "bastion", "spectre", "kestrel"}) +EXPECTED_GEAR = ("mg_762", "autocannon", "recoilless", "copper_rad", "gilded_lance", "gold_radiator") + + +def parse_glb(glb_path: Path) -> tuple[dict[str, Any], bytes]: + data = glb_path.read_bytes() + if len(data) < 20: + raise AssertionError(f"{glb_path}: file too small ({len(data)} bytes)") + magic, version, total_len = struct.unpack_from(" dict[str, Any]: + return parse_glb(glb_path)[0] + + +def _node_local_matrix(node: dict[str, Any]) -> np.ndarray: + if "matrix" in node: + return np.array(node["matrix"], dtype=np.float64).reshape(4, 4).T + m = np.eye(4, dtype=np.float64) + if "scale" in node: + sx, sy, sz = node["scale"] + m = m @ np.diag([sx, sy, sz, 1.0]) + if "rotation" in node: + qx, qy, qz, qw = node["rotation"] + xx, yy, zz = qx * qx, qy * qy, qz * qz + xy, xz, yz = qx * qy, qx * qz, qy * qz + wx, wy, wz = qw * qx, qw * qy, qw * qz + r = np.array([ + [1 - 2 * (yy + zz), 2 * (xy - wz), 2 * (xz + wy), 0.0], + [2 * (xy + wz), 1 - 2 * (xx + zz), 2 * (yz - wx), 0.0], + [2 * (xz - wy), 2 * (yz + wx), 1 - 2 * (xx + yy), 0.0], + [0.0, 0.0, 0.0, 1.0], + ], dtype=np.float64) + m = r @ m + if "translation" in node: + tx, ty, tz = node["translation"] + m[:3, 3] = [tx, ty, tz] + return m + + +def compute_glb_stats(gltf: dict[str, Any], bin_blob: bytes = b"") -> tuple[int, np.ndarray, np.ndarray]: + 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))) + + tri_total = 0 + g_min = np.array([math.inf, math.inf, math.inf], dtype=np.float64) + g_max = np.array([-math.inf, -math.inf, -math.inf], dtype=np.float64) + + def walk(node_idx: int, parent_mat: np.ndarray) -> None: + nonlocal tri_total, g_min, g_max + node = nodes[node_idx] + world = parent_mat @ _node_local_matrix(node) + if "mesh" in node: + mesh = meshes[node["mesh"]] + for prim in mesh.get("primitives", []): + mode = prim.get("mode", 4) + if mode == 4: + if "indices" in prim: + tri_total += accessors[prim["indices"]]["count"] // 3 + elif "POSITION" in prim.get("attributes", {}): + tri_total += accessors[prim["attributes"]["POSITION"]]["count"] // 3 + pos_acc_idx = prim.get("attributes", {}).get("POSITION") + if pos_acc_idx is not None: + acc = accessors[pos_acc_idx] + if bin_blob and "bufferView" in acc and acc.get("componentType") == 5126 and acc.get("type") == "VEC3": + bv = buffer_views[acc["bufferView"]] + off = bv.get("byteOffset", 0) + acc.get("byteOffset", 0) + stride = bv.get("byteStride", 12) + count = acc["count"] + if stride == 12: + pts = np.frombuffer(bin_blob, dtype=" 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=" 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" + manifest_path = vdir / "manifest.json" + if not glb_path.is_file(): + raise AssertionError(f"Missing GLB: {glb_path}") + if not manifest_path.is_file(): + raise AssertionError(f"Missing manifest: {manifest_path}") + + manifest = json.loads(manifest_path.read_text(encoding="utf-8")) + gltf, bin_blob = parse_glb(glb_path) + nodes = gltf.get("nodes", []) + + # 1. Check hardpoint grid bounds, mask activity, and zero overlaps + gw, gh = int(manifest["gridWidth"]), int(manifest["gridHeight"]) + mask = manifest["mask"] + if len(mask) != gw * gh: + raise AssertionError(f"{vid}: mask length {len(mask)} != {gw * gh}") + + occupied: dict[tuple[int, int], str] = {} + for hp in manifest["hardpoints"]: + hx, hy, hw, hh = hp["x"], hp["y"], hp["w"], hp["h"] + if not (0 <= hx and hx + hw <= gw and 0 <= hy and hy + hh <= gh): + raise AssertionError(f"{vid}: hardpoint {hp['id']} out of grid bounds ({hx},{hy} {hw}x{hh} on {gw}x{gh})") + for cy in range(hy, hy + hh): + for cx in range(hx, hx + hw): + if not mask[cy * gw + cx]: + raise AssertionError(f"{vid}: hardpoint {hp['id']} covers inactive cell ({cx},{cy})") + if (cx, cy) in occupied: + raise AssertionError(f"{vid}: cell ({cx},{cy}) overlaps between {occupied[(cx, cy)]} and {hp['id']}") + occupied[(cx, cy)] = hp["id"] + + # 2. Check every manifest hardpoint modelNodeId exists as a unique node with extras["rtd.id"] and extras["rtd.kind"] + by_rtd_id: dict[str, list[dict]] = {} + by_rtd_joint: dict[str, list[dict]] = {} + for node in nodes: + extras = node.get("extras") or {} + if "rtd.id" in extras: + by_rtd_id.setdefault(str(extras["rtd.id"]), []).append(node) + if "rtd.joint" in extras: + by_rtd_joint.setdefault(str(extras["rtd.joint"]), []).append(node) + + for hp in manifest["hardpoints"]: + target_id = hp["modelNodeId"] + matches = by_rtd_id.get(target_id, []) + if len(matches) != 1: + raise AssertionError(f"{vid}: hardpoint {target_id!r} matched {len(matches)} GLB nodes (expected 1)") + node = matches[0] + extras = node.get("extras", {}) + if extras.get("rtd.kind") != hp["kind"]: + raise AssertionError(f"{vid}: node {target_id} rtd.kind={extras.get('rtd.kind')!r} != manifest {hp['kind']!r}") + if node.get("name") != target_id: + raise AssertionError(f"{vid}: node name {node.get('name')!r} != {target_id!r}") + + # 3. Check every manifest joint exists with rtd.joint, rtd.axis, rtd.min, rtd.max + for j in manifest["joints"]: + jid = j["id"] + matches = by_rtd_joint.get(jid, []) + if len(matches) != 1: + raise AssertionError(f"{vid}: joint {jid!r} matched {len(matches)} GLB nodes (expected 1)") + extras = matches[0].get("extras", {}) + for key in ("rtd.axis", "rtd.min", "rtd.max"): + if key not in extras: + raise AssertionError(f"{vid}: joint {jid!r} missing {key} in GLB extras") + + plane = manifest.get("plane") + if plane not in ("Dorsal", "Coronal"): + raise AssertionError(f"{vid}: invalid plane {plane!r}") + + # 4. Check GLB triangle count & grounded +Y-up / +Z-forward bounds + tri_total, g_min, g_max = compute_glb_stats(gltf, bin_blob) + max_tris = 50000 if vid in RETROFIT_MECHS else 35000 + min_tris = 15000 if vid in RETROFIT_MECHS else 1500 + if not (min_tris <= tri_total <= max_tris): + raise AssertionError(f"{vid}: tri count {tri_total} outside [{min_tris}, {max_tris}]") + if abs(tri_total - manifest["triCount"]) > 0: + raise AssertionError(f"{vid}: GLB tri count {tri_total} != manifest triCount {manifest['triCount']}") + if abs(float(g_min[1])) > 0.02: + raise AssertionError(f"{vid}: GLB not grounded at minY=0 (got minY={g_min[1]:.4f})") + size = g_max - g_min + if vid in RETROFIT_MECHS: + if not (2.5 <= size[0] <= 14.0 and 5.0 <= size[1] <= 12.5 and 2.5 <= size[2] <= 16.0): + raise AssertionError(f"{vid}: implausible mech bounds size {size.tolist()}") + 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, + "tris": tri_total, + "bytes": glb_path.stat().st_size, + "hardpoints": len(manifest["hardpoints"]), + "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], + } + + +def validate_gear(gid: str) -> dict[str, Any]: + glb_path = GEAR_DIR / f"{gid}.glb" + if not glb_path.is_file(): + raise AssertionError(f"Missing gear GLB: {glb_path}") + gltf, bin_blob = parse_glb(glb_path) + tri_total, g_min, g_max = compute_glb_stats(gltf, bin_blob) + if tri_total <= 0 or tri_total > 10000: + raise AssertionError(f"gear/{gid}: unexpected tri count {tri_total}") + if abs(float(g_min[1])) > 0.02: + raise AssertionError(f"gear/{gid}: not grounded at minY=0 (got {g_min[1]:.4f})") + return { + "id": gid, + "tris": tri_total, + "bytes": glb_path.stat().st_size, + "size": [round(float(v), 3) for v in (g_max - g_min)], + } + + +def main() -> int: + v_reports = [validate_vehicle(v) for v in EXPECTED_VEHICLES] + g_reports = [validate_gear(g) for g in EXPECTED_GEAR] + 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']} | 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") + return 0 + + +if __name__ == "__main__": + sys.exit(main())