summaryrefslogtreecommitdiff
path: root/stage/blender/probe.py
diff options
context:
space:
mode:
Diffstat (limited to 'stage/blender/probe.py')
-rw-r--r--stage/blender/probe.py152
1 files changed, 144 insertions, 8 deletions
diff --git a/stage/blender/probe.py b/stage/blender/probe.py
index aaffaf4..9b9eb34 100644
--- a/stage/blender/probe.py
+++ b/stage/blender/probe.py
@@ -563,6 +563,129 @@ def apply_material_mode(bpy, materials, mode):
obj.data.materials.append(material)
+def merge_details(bpy, master, extras):
+ """Join detail meshes into the master object so the exported GLB keeps
+ exactly the contract object names while carrying real secondary detail."""
+ if not extras:
+ return master
+ for obj in bpy.context.selected_objects:
+ obj.select_set(False)
+ for extra in extras:
+ extra.select_set(True)
+ master.select_set(True)
+ bpy.context.view_layer.objects.active = master
+ bpy.ops.object.join()
+ return master
+
+
+def detail_torus(bpy, name, location, major_radius, minor_radius, rotation=(0.0, 0.0, 0.0), minor_segments=10):
+ bpy.ops.mesh.primitive_torus_add(
+ major_radius=major_radius,
+ minor_radius=minor_radius,
+ major_segments=48,
+ minor_segments=minor_segments,
+ location=location,
+ rotation=rotation,
+ )
+ obj = bpy.context.object
+ obj.name = name
+ return obj
+
+
+def detail_cube(bpy, name, location, dimensions, rotation=(0.0, 0.0, 0.0)):
+ bpy.ops.mesh.primitive_cube_add(location=location, rotation=rotation)
+ obj = bpy.context.object
+ obj.name = name
+ obj.dimensions = dimensions
+ bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
+ return obj
+
+
+def detail_cylinder(bpy, name, location, radius, depth, rotation=(0.0, 0.0, 0.0), vertices=20):
+ bpy.ops.mesh.primitive_cylinder_add(
+ vertices=vertices,
+ radius=radius,
+ depth=depth,
+ location=location,
+ rotation=rotation,
+ )
+ obj = bpy.context.object
+ obj.name = name
+ return obj
+
+
+def build_details(bpy, object_id, master, materials):
+ """Secondary engineering detail per contract object, joined into the
+ master mesh before export; detail names never reach the GLB."""
+ details = []
+
+ if object_id == "probe.bus.electronics.decagon":
+ # Panel seams around the decagon bus + mounting bosses on both faces.
+ for index in range(10):
+ angle = 2.0 * math.pi * index / 10.0
+ y = 0.455 * math.cos(angle)
+ z = 0.455 * math.sin(angle)
+ details.append(detail_cube(bpy, f"{master.name}.detail.seam.{index:02d}", (0.0, y, z), (0.50, 0.03, 0.03), rotation=(angle, 0.0, 0.0)))
+ for offset in (-0.24, 0.24):
+ details.append(detail_cylinder(bpy, f"{master.name}.detail.boss.{offset:+.2f}", (offset, 0.0, 0.0), 0.30, 0.03, rotation=(0.0, math.pi / 2.0, 0.0)))
+ elif object_id.startswith("probe.bus.bay.panel."):
+ index = int(object_id.rsplit(".", 1)[-1])
+ angle = 2.0 * math.pi * index / 10.0
+ y = 0.46 * math.cos(angle)
+ z = 0.46 * math.sin(angle)
+ # Fastener posts and a hinge rib per bay panel.
+ details.append(detail_cylinder(bpy, master.name + ".detail.hinge", (0.10, y, z), 0.018, 0.30, rotation=(angle, 0.0, 0.0), vertices=8))
+ details.append(detail_cube(bpy, master.name + ".detail.latch", (-0.14, y * 1.02, z * 1.02), (0.05, 0.04, 0.10), rotation=(angle, 0.0, 0.0)))
+ elif object_id.startswith("probe.thruster."):
+ index = int(object_id.rsplit(".", 1)[-1])
+ y, z = ((-0.30, -0.25), (-0.30, 0.25), (0.30, -0.25), (0.30, 0.25))[index - 1]
+ # Thruster mount plate + feed line to the bus core.
+ details.append(detail_cube(bpy, master.name + ".detail.mount", (-0.24, y, z), (0.10, 0.12, 0.12)))
+ details.append(detail_cylinder(bpy, master.name + ".detail.feed", (-0.24, y * 0.55, z * 0.55), 0.014, 0.5, vertices=8))
+ elif object_id.startswith("probe.rtg.") and object_id.endswith(tuple(f".fin.{i:02d}" for i in range(3))):
+ rtg_part, fin_part = object_id.rsplit(".fin.", 1)
+ rtg_index = int(rtg_part.rsplit(".", 1)[-1])
+ fin_index = int(fin_part)
+ y = (-0.80, -1.22, -1.64)[rtg_index - 1] - 0.09 + fin_index * 0.09
+ details.append(detail_torus(bpy, master.name + ".detail.collar", (-0.12, y, -0.16), 0.118, 0.010, rotation=(math.pi / 2.0, 0.0, 0.0), minor_segments=10))
+ elif object_id == "probe.rtg.boom":
+ # Boom truss cross-bracing between the three RTG housings.
+ for index in range(3):
+ y = -0.98 - index * 0.42
+ details.append(detail_torus(bpy, f"{master.name}.detail.brace.{index:02d}", (-0.12, y, -0.16), 0.035, 0.008, minor_segments=10))
+ elif object_id.startswith("probe.rtg."):
+ index = int(object_id.rsplit(".", 1)[-1])
+ y = (-0.80, -1.22, -1.64)[index - 1]
+ # Radiator fins and end caps along each RTG housing.
+ for offset in (-0.09, 0.0, 0.09):
+ details.append(detail_torus(bpy, f"{master.name}.detail.fins.{offset:+.2f}", (-0.12, y + offset, -0.16), 0.115, 0.008, rotation=(math.pi / 2.0, 0.0, 0.0), minor_segments=10))
+ elif object_id == "probe.mag.head":
+ details.append(detail_torus(bpy, master.name + ".detail.collar", (0.0, 6.50, 0.18), 0.105, 0.014, rotation=(math.pi / 2.0, 0.0, 0.0), minor_segments=10))
+ elif object_id == "probe.hga.reflector":
+ # Back-side ribs across the dish so the reflector reads as a rigid
+ # structure, not a floating surface.
+ for index in range(6):
+ angle = 2.0 * math.pi * index / 6.0
+ y = 0.55 * math.cos(angle)
+ z = 0.55 * math.sin(angle)
+ details.append(detail_cube(bpy, f"{master.name}.detail.rib.{index:02d}", (0.22, y * 0.55, z * 0.55), (0.06, 0.04, 0.04)))
+ details.append(detail_cylinder(bpy, master.name + ".detail.hub", (0.30, 0.0, 0.0), 0.10, 0.06, rotation=(0.0, math.pi / 2.0, 0.0)))
+ elif object_id == "probe.scan.platform":
+ for offset in (-0.12, 0.0, 0.12):
+ details.append(detail_cylinder(bpy, f"{master.name}.detail.bolt.{offset:+.2f}", (0.0, offset, 1.67), 0.014, 0.02, vertices=8))
+ details.append(detail_torus(bpy, master.name + ".detail.ring", (0.0, 0.0, 1.665), 0.16, 0.012, minor_segments=10))
+ elif object_id.startswith("probe.pws.tip."):
+ side = object_id.rsplit(".", 1)[-1]
+ sign = -1.0 if side == "left" else 1.0
+ details.append(detail_cylinder(bpy, master.name + ".detail.cap", (-0.12, sign * 2.50, 1.10), 0.020, 0.03, rotation=(math.pi / 2.0, 0.0, 0.0), vertices=8))
+ elif object_id == "probe.science.boom":
+ for index in range(4):
+ z = 0.60 + index * 0.30
+ details.append(detail_torus(bpy, f"{master.name}.detail.guide.{index:02d}", (0.0, 0.0, z), 0.042, 0.008, minor_segments=10))
+ return details
+
+
+
def build_geometry(bpy, materials, step_id):
"""Build every object of the cumulative step, in STEP_OBJECTS order.
@@ -674,6 +797,12 @@ def build_geometry(bpy, materials, step_id):
else:
fail("unknown object id: " + object_id, 4)
+ # Secondary engineering detail is generated per contract object and
+ # merged into the master mesh, keeping the GLB object contract intact.
+ for object_id in list(STEP_OBJECTS[step_id]):
+ master = objects[object_id]
+ merge_details(bpy, master, build_details(bpy, object_id, master, materials))
+
ordered = [objects[object_id] for object_id in STEP_OBJECTS[step_id]]
for obj, object_id in zip(ordered, STEP_OBJECTS[step_id]):
if obj.get("object_id") != object_id:
@@ -702,14 +831,21 @@ def add_render_setup(bpy):
camera.rotation_euler = (Vector((0.0, 2.0, 0.2)) - camera.location).to_track_quat("-Z", "Y").to_euler()
scene.camera = camera
- light_data = bpy.data.lights.new("probe.key", type="AREA")
- light_data.energy = 900
- light_data.shape = "DISK"
- light_data.size = 5.0
- light = bpy.data.objects.new("probe.key", light_data)
- bpy.context.collection.objects.link(light)
- light.location = (4.0, -4.0, 8.0)
- light.rotation_euler = (Vector((0.0, 2.0, 0.2)) - light.location).to_track_quat("-Z", "Y").to_euler()
+ def add_light(name, location, energy, size, color=(1.0, 1.0, 1.0)):
+ light_data = bpy.data.lights.new(name, type="AREA")
+ light_data.energy = energy
+ light_data.shape = "DISK"
+ light_data.size = size
+ light_data.color = color
+ light = bpy.data.objects.new(name, light_data)
+ bpy.context.collection.objects.link(light)
+ light.location = location
+ light.rotation_euler = (Vector((0.0, 2.0, 0.2)) - Vector(location)).to_track_quat("-Z", "Y").to_euler()
+ return light
+
+ add_light("probe.key", (4.0, -4.0, 8.0), 900, 5.0, (1.0, 0.98, 0.94))
+ add_light("probe.fill", (-6.0, -8.0, 3.0), 300, 8.0, (0.72, 0.82, 1.0))
+ add_light("probe.rim", (-5.0, 7.0, -2.5), 650, 3.0, (1.0, 0.86, 0.62))
def export_glb(bpy, objects, output):