""" blender/create_station_blend.py Builds the complete photorealistic, interactive, and animated station.blend: 1. Physical realism for Camera and Lighting: - High-bay industrial LED luminaire fixture overhead with aluminum heatsink housing, glowing emissive diffuser panel, and ceiling suspension cables. - Machine vision ring illuminator with bright glowing cool-white emissive LED ring. - High-precision Basler/Keyence-style C-mount lens barrel with knurled focus ring and glowing status LED. - Multi-tier Andon tower with animated Green/Red signal alarm states. 2. Animated Conveyor Simulation (Frames 1-120): - Continuous conveyor belt translation with multiple tracking seams. - Defective bracket traveling from in-feed to inspection center. - High-contrast AI Machine Vision HUD triggering at Frame 36-50: * Optical alignment reticle * Glowing red 3D defect bounding box * Industrial inspection readout badge: [DEFECT: DENT 98.4% -> REJECT] - Pneumatic reject actuator extending piston to knock defective bracket down the slide chute (Frames 74-92). - In-feed production stream bracket following upstream. 3. Clean Viewport Configuration: - Disables wireframe extras (frustums, area light boxes) and relationship lines. - Deselects all objects so no orange outlines appear. 4. Renders: - 3D Overview still & Station Camera HUD still. - Dual MP4 videos: Top-Down Station Camera View & 3D Perspective Overview. """ import bpy import mathutils import sys import os import math def configure_cycles(scene): scene.render.engine = 'CYCLES' try: cpref = bpy.context.preferences.addons['cycles'].preferences cpref.compute_device_type = 'OPTIX' cpref.get_devices() for d in cpref.devices: if d.type == 'OPTIX': d.use = True else: d.use = False scene.cycles.device = 'GPU' print("Cycles OptiX GPU configured successfully.") except Exception as e: print(f"Cycles GPU fallback to CPU: {e}") scene.cycles.device = 'CPU' scene.cycles.samples = 64 scene.cycles.use_denoising = True def create_emissive_material(name, color=(1.0, 1.0, 1.0, 1.0), strength=5.0): """Creates a Principled BSDF material with high emission.""" mat = bpy.data.materials.get(name) if not mat: mat = bpy.data.materials.new(name) mat.use_nodes = True bsdf = mat.node_tree.nodes.get("Principled BSDF") if bsdf: bsdf.inputs["Base Color"].default_value = color # In Blender 4.0+ / 5.0+, Emission Color and Emission Strength are standard inputs if "Emission Color" in bsdf.inputs: bsdf.inputs["Emission Color"].default_value = color if "Emission Strength" in bsdf.inputs: bsdf.inputs["Emission Strength"].default_value = strength bsdf.inputs["Roughness"].default_value = 0.2 return mat def build_overhead_luminaire_fixture(scene): """ Builds a realistic industrial high-bay overhead light fixture: - Extruded aluminum housing with cooling fins - Glowing emissive diffuser panel (no black floating boxes!) - Suspension cables anchoring to ceiling """ lum_coll = bpy.data.collections.new("OverheadLuminaire") scene.collection.children.link(lum_coll) # Aluminum housing material housing_mat = bpy.data.materials.get("AnodizedAluminum") if not housing_mat: housing_mat = bpy.data.materials.new("LuminaireHousingMat") housing_mat.use_nodes = True bsdf = housing_mat.node_tree.nodes.get("Principled BSDF") if bsdf: bsdf.inputs["Base Color"].default_value = (0.35, 0.36, 0.38, 1.0) bsdf.inputs["Metallic"].default_value = 0.8 bsdf.inputs["Roughness"].default_value = 0.3 diffuser_mat = create_emissive_material( "LuminaireDiffuserMat", color=(1.0, 0.98, 0.95, 1.0), strength=6.5 ) cable_mat = bpy.data.materials.get("PistonChrome") if not cable_mat: cable_mat = housing_mat # 1. Main Housing Hood (Aluminum reflector body) bpy.ops.mesh.primitive_cube_add(size=1.0) hood = bpy.context.active_object hood.name = "Luminaire_Housing" hood.scale = (0.70, 0.30, 0.04) hood.location = (0.0, -0.05, 0.72) hood.data.materials.append(housing_mat) lum_coll.objects.link(hood) scene.collection.objects.unlink(hood) # 2. Glowing Diffuser Face Panel bpy.ops.mesh.primitive_cube_add(size=1.0) diffuser = bpy.context.active_object diffuser.name = "Luminaire_Diffuser_Face" diffuser.scale = (0.66, 0.26, 0.008) diffuser.location = (0.0, -0.05, 0.698) diffuser.data.materials.append(diffuser_mat) lum_coll.objects.link(diffuser) scene.collection.objects.unlink(diffuser) # 3. 4 Steel Suspension Cables cable_r = 0.002 for ci, (cx, cy) in enumerate([(-0.32, -0.18), (0.32, -0.18), (-0.32, 0.08), (0.32, 0.08)]): bpy.ops.mesh.primitive_cylinder_add(radius=cable_r, depth=0.35) cable = bpy.context.active_object cable.name = f"Luminaire_Cable_{ci}" cable.location = (cx, cy, 0.72 + 0.175) cable.data.materials.append(cable_mat) lum_coll.objects.link(cable) scene.collection.objects.unlink(cable) # 4. Supplemental Area Light (Directional soft emitter) ceiling_light_data = bpy.data.lights.new("FactoryCeilingBay", type='AREA') ceiling_light_data.energy = 45.0 ceiling_light_data.shape = 'RECTANGLE' ceiling_light_data.size = 0.65 ceiling_light_data.size_y = 0.25 ceiling_light_data.color = (1.0, 0.98, 0.95) ceiling_light_obj = bpy.data.objects.new("FactoryCeilingBay", ceiling_light_data) lum_coll.objects.link(ceiling_light_obj) ceiling_light_obj.location = (0.0, -0.05, 0.695) ceiling_light_obj.rotation_euler = (0.0, 0.0, 0.0) return hood, diffuser def build_camera_ring_illuminator(scene): """ Adds a bright emissive LED ring and precision C-mount hardware to the vision rig. """ rig_coll = scene.collection # 1. Glowing Ring Illuminator Face (Bright cool white) ring_mat = create_emissive_material("RingLightEmitterMat", color=(0.95, 0.98, 1.0, 1.0), strength=7.0) bpy.ops.mesh.primitive_cylinder_add(radius=0.028, depth=0.004) ring_face = bpy.context.active_object ring_face.name = "VisionRig_RingLED_Face" ring_face.location = (0.0, 0.0, 0.213) ring_face.data.materials.append(ring_mat) # 2. Knurled Silver Lens Focus Lock Ring lens_chrome = bpy.data.materials.get("AnodizedAluminum") bpy.ops.mesh.primitive_cylinder_add(radius=0.0175, depth=0.005) focus_ring = bpy.context.active_object focus_ring.name = "VisionRig_Focus_Knurl" focus_ring.location = (0.0, 0.0, 0.226) if lens_chrome: focus_ring.data.materials.append(lens_chrome) # 3. Camera Active Status LED (Green Trigger Indicator) status_mat = create_emissive_material("CameraStatusLEDMat", color=(0.1, 0.95, 0.2, 1.0), strength=5.0) bpy.ops.mesh.primitive_cylinder_add(radius=0.0035, depth=0.003) status_led = bpy.context.active_object status_led.name = "VisionRig_Status_LED_Face" status_led.location = (0.015, 0.015, 0.281) status_led.data.materials.append(status_mat) return ring_face, status_led def build_belt_tracking_markers(scene): """Creates multiple moving belt tracking seams across the conveyor.""" seam_mat = bpy.data.materials.get("BlackPolymer") if not seam_mat: seam_mat = bpy.data.materials.new("SeamMat") seam_mat.use_nodes = True bsdf = seam_mat.node_tree.nodes.get("Principled BSDF") if bsdf: bsdf.inputs["Base Color"].default_value = (0.02, 0.02, 0.025, 1.0) bsdf.inputs["Roughness"].default_value = 0.9 seams = [] # 5 seams spaced across belt belt_width = 0.12 for i in range(5): bpy.ops.mesh.primitive_cube_add(size=1.0) s = bpy.context.active_object s.name = f"Conveyor_Belt_Seam_{i}" s.scale = (0.0018, belt_width, 0.0006) s.location = (-0.36 + i * 0.18, 0.0, 0.0003) s.data.materials.append(seam_mat) seams.append(s) return seams def build_hmi_operator_panel(scene): """ Builds a physical 3D industrial touchscreen HMI monitor mounted on the conveyor stanchion, displaying real-time line KPIs, pass/fail counts, and defect telemetry. """ hmi_coll = bpy.data.collections.new("OperatorHMI") scene.collection.children.link(hmi_coll) # Monitor position & orientation (mounted near mast, angled toward camera/operator) hmi_loc = mathutils.Vector((-0.07, 0.16, 0.18)) hmi_rot = (math.radians(15.0), math.radians(0.0), math.radians(-30.0)) # 1. Bezel / Monitor Casing bezel_mat = bpy.data.materials.get("BlackPolymer") bpy.ops.mesh.primitive_cube_add(size=1.0) bezel = bpy.context.active_object bezel.name = "HMI_Monitor_Bezel" bezel.scale = (0.13, 0.008, 0.085) bezel.location = hmi_loc bezel.rotation_euler = hmi_rot if bezel_mat: bezel.data.materials.append(bezel_mat) hmi_coll.objects.link(bezel) scene.collection.objects.unlink(bezel) # 2. Touchscreen Display Face (Emissive HMI texture) hmi_mat = bpy.data.materials.new("HMIDisplayMat") hmi_mat.use_nodes = True nodes = hmi_mat.node_tree.nodes links = hmi_mat.node_tree.links bsdf = nodes.get("Principled BSDF") tex_path = os.path.abspath("assets/textures/hmi_kpi_dashboard.png") if os.path.exists(tex_path): tex_node = nodes.new("ShaderNodeTexImage") tex_node.image = bpy.data.images.load(tex_path) links.new(tex_node.outputs["Color"], bsdf.inputs["Base Color"]) if "Emission Color" in bsdf.inputs: links.new(tex_node.outputs["Color"], bsdf.inputs["Emission Color"]) if "Emission Strength" in bsdf.inputs: bsdf.inputs["Emission Strength"].default_value = 2.5 bsdf.inputs["Roughness"].default_value = 0.1 bpy.ops.mesh.primitive_plane_add(size=1.0) screen = bpy.context.active_object screen.name = "HMI_Display_Screen" screen.scale = (0.062, 0.039, 1.0) rot_mat = mathutils.Euler(hmi_rot).to_matrix() fwd = rot_mat @ mathutils.Vector((0.0, -0.0045, 0.0)) screen.location = hmi_loc + fwd screen.rotation_euler = (hmi_rot[0] + math.radians(90.0), hmi_rot[1], hmi_rot[2]) screen.data.materials.append(hmi_mat) hmi_coll.objects.link(screen) scene.collection.objects.unlink(screen) # 3. Articulated Swivel Arm connecting to Mast arm_mat = bpy.data.materials.get("AnodizedAluminum") bpy.ops.mesh.primitive_cylinder_add(radius=0.006, depth=0.10) arm = bpy.context.active_object arm.name = "HMI_Mount_Arm" arm.location = (-0.095, 0.18, 0.17) arm.rotation_euler = (math.radians(90.0), math.radians(35.0), 0.0) if arm_mat: arm.data.materials.append(arm_mat) hmi_coll.objects.link(arm) scene.collection.objects.unlink(arm) return bezel, screen def build_secondary_oblique_camera(scene): """ Builds a secondary 45-degree oblique profile camera (Camera 2) inspecting fastener height and tilt. """ cam_coll = bpy.data.collections.new("ObliqueCameraRig") scene.collection.children.link(cam_coll) cam_loc = mathutils.Vector((0.09, -0.14, 0.13)) target = mathutils.Vector((0.0, 0.0, 0.006)) direction = target - cam_loc # 1. Physical Camera Housing cam_mat = bpy.data.materials.get("CameraBodyPaint") bpy.ops.mesh.primitive_cube_add(size=1.0) cbody = bpy.context.active_object cbody.name = "VisionRig_Cam2_Body" cbody.scale = (0.024, 0.024, 0.035) cbody.location = cam_loc cbody.rotation_euler = direction.to_track_quat('-Z', 'Y').to_euler() if cam_mat: cbody.data.materials.append(cam_mat) cam_coll.objects.link(cbody) scene.collection.objects.unlink(cbody) # 2. Physical Lens Barrel lens_mat = bpy.data.materials.get("LensMetal") bpy.ops.mesh.primitive_cylinder_add(radius=0.012, depth=0.022) clens = bpy.context.active_object clens.name = "VisionRig_Cam2_Lens" fwd_offset = direction.normalized() * 0.026 clens.location = cam_loc + fwd_offset clens.rotation_euler = direction.to_track_quat('Z', 'Y').to_euler() if lens_mat: clens.data.materials.append(lens_mat) cam_coll.objects.link(clens) scene.collection.objects.unlink(clens) # 3. Mounting Stalk bpy.ops.mesh.primitive_cylinder_add(radius=0.005, depth=0.14) stalk = bpy.context.active_object stalk.name = "VisionRig_Cam2_Stalk" stalk.location = (cam_loc.x, cam_loc.y, 0.06) stalk_mat = bpy.data.materials.get("AnodizedAluminum") if stalk_mat: stalk.data.materials.append(stalk_mat) cam_coll.objects.link(stalk) scene.collection.objects.unlink(stalk) # 4. Blender Camera Object (Camera_Oblique_Side, 35mm lens) oblique_cam_data = bpy.data.cameras.new("Camera_Oblique_Side") oblique_cam_data.lens = 35.0 oblique_cam_obj = bpy.data.objects.new("Camera_Oblique_Side", oblique_cam_data) scene.collection.objects.link(oblique_cam_obj) oblique_cam_obj.location = cam_loc oblique_cam_obj.rotation_euler = direction.to_track_quat('-Z', 'Y').to_euler() return oblique_cam_obj def build_inspection_hud_overlay(scene): """ Creates high-tech AI defect detection graphics visible through station camera and in 3D: - Optical Crosshair Reticle at center - High-contrast glowing red 3D bounding box - Dark semi-transparent backing plate - Bright glowing red defect badge: [● DEFECT: DENT [98.4%] -> REJECT] - Station header readout badge: [STATION-04 | CAM 01 | 60 FPS] """ hud_red_mat = create_emissive_material("DefectRedGlow", color=(1.0, 0.05, 0.05, 1.0), strength=4.5) hud_cyan_mat = create_emissive_material("VisionCyanGlow", color=(0.1, 0.9, 1.0, 1.0), strength=3.5) dark_plate_mat = bpy.data.materials.new("HUDDarkPlate") dark_plate_mat.use_nodes = True bsdf = dark_plate_mat.node_tree.nodes.get("Principled BSDF") if bsdf: bsdf.inputs["Base Color"].default_value = (0.02, 0.03, 0.04, 1.0) bsdf.inputs["Roughness"].default_value = 0.3 hud_objects = [] # 1. 3D Bounding Box around defect bpy.ops.mesh.primitive_cube_add(size=1.0) bbox = bpy.context.active_object bbox.name = "Defect_BBox_Overlay" bbox.scale = (0.018, 0.018, 0.002) bbox.location = (0.0, 0.0, 0.0072) bbox.display_type = 'WIRE' bbox.data.materials.append(hud_red_mat) hud_objects.append(bbox) # 2. Dark Backing Plate for High-Contrast Readout bpy.ops.mesh.primitive_cube_add(size=1.0) plate = bpy.context.active_object plate.name = "Defect_HUD_Plate" plate.scale = (0.078, 0.010, 0.0004) plate.location = (0.0, 0.016, 0.0085) plate.data.materials.append(dark_plate_mat) hud_objects.append(plate) # 3. 3D Text Badge: DEFECT DETECTED font_curve = bpy.data.curves.new(type="FONT", name="DefectBadgeCurve") font_curve.body = "DEFECT: DENT [98.4%] -> REJECT" font_curve.size = 0.0052 font_curve.extrude = 0.0004 badge_obj = bpy.data.objects.new("Defect_HUD_Badge", font_curve) scene.collection.objects.link(badge_obj) badge_obj.location = (-0.036, 0.014, 0.0090) badge_obj.data.materials.append(hud_red_mat) hud_objects.append(badge_obj) # 4. Camera Crosshairs Reticle (Thin lines at center) bpy.ops.mesh.primitive_cube_add(size=1.0) reticle_x = bpy.context.active_object reticle_x.name = "Defect_Reticle_X" reticle_x.scale = (0.030, 0.0004, 0.0002) reticle_x.location = (0.0, 0.0, 0.0078) reticle_x.data.materials.append(hud_cyan_mat) hud_objects.append(reticle_x) bpy.ops.mesh.primitive_cube_add(size=1.0) reticle_y = bpy.context.active_object reticle_y.name = "Defect_Reticle_Y" reticle_y.scale = (0.0004, 0.030, 0.0002) reticle_y.location = (0.0, 0.0, 0.0078) reticle_y.data.materials.append(hud_cyan_mat) hud_objects.append(reticle_y) return hud_objects def animate_conveyor_simulation(scene, hud_objects, seams): """ Sets up a 120-frame (5-second @ 24fps) industrial visual inspection simulation: - Belt seams continuous translation along +X - Defective bracket traveling to center (Frame 36-50) - AI HUD triggers on frame 36, stays active through 50 - Pneumatic pusher knocks part into reject chute (Frame 74-92) - Andon tower changes from Green to Red during defect detection! """ scene.frame_start = 1 scene.frame_end = 120 scene.frame_current = 1 # 1. Conveyor Belt Seams Translation for i, seam in enumerate(seams): init_x = seam.location.x seam.location.x = init_x seam.keyframe_insert(data_path="location", index=0, frame=1) seam.location.x = init_x + 0.36 seam.keyframe_insert(data_path="location", index=0, frame=120) # 2. Primary Inspected Product (Defective Bracket) product = bpy.data.objects.get("Product") if product: # Frame 1: Upstream in-feed product.location = (-0.32, 0.0, 0.0) product.rotation_euler = (0.0, 0.0, math.radians(2.5)) product.keyframe_insert(data_path="location", frame=1) product.keyframe_insert(data_path="rotation_euler", frame=1) # Frame 36: Aligns dead-center under inspection camera product.location = (0.0, 0.0, 0.0) product.rotation_euler = (0.0, 0.0, 0.0) product.keyframe_insert(data_path="location", frame=36) product.keyframe_insert(data_path="rotation_euler", frame=36) # Frame 50: Held under camera during inspection product.location = (0.0, 0.0, 0.0) product.rotation_euler = (0.0, 0.0, 0.0) product.keyframe_insert(data_path="location", frame=50) product.keyframe_insert(data_path="rotation_euler", frame=50) # Frame 74: Moves to reject diverter station product.location = (0.18, 0.0, 0.0) product.rotation_euler = (0.0, 0.0, 0.0) product.keyframe_insert(data_path="location", frame=74) product.keyframe_insert(data_path="rotation_euler", frame=74) # Frame 84: Pushed sideways off belt toward chute by pneumatic ram product.location = (0.19, -0.09, -0.04) product.rotation_euler = (math.radians(-15.0), 0.0, math.radians(10.0)) product.keyframe_insert(data_path="location", frame=84) product.keyframe_insert(data_path="rotation_euler", frame=84) # Frame 98: Slides smoothly down the reject chute product.location = (0.20, -0.16, -0.12) product.rotation_euler = (math.radians(-35.0), 0.0, math.radians(15.0)) product.keyframe_insert(data_path="location", frame=98) product.keyframe_insert(data_path="rotation_euler", frame=98) # Frame 120: Resting in reject bin product.location = (0.20, -0.16, -0.12) product.rotation_euler = (math.radians(-35.0), 0.0, math.radians(15.0)) product.keyframe_insert(data_path="location", frame=120) product.keyframe_insert(data_path="rotation_euler", frame=120) # 3. AI HUD Bounding Box & Defect Badge Triggering for obj in hud_objects: if obj: # Hidden before inspection obj.hide_viewport = True obj.hide_render = True obj.keyframe_insert(data_path="hide_viewport", frame=1) obj.keyframe_insert(data_path="hide_render", frame=1) obj.keyframe_insert(data_path="hide_viewport", frame=35) obj.keyframe_insert(data_path="hide_render", frame=35) # Pops visible during inspection (Frames 36 - 50) obj.hide_viewport = False obj.hide_render = False obj.keyframe_insert(data_path="hide_viewport", frame=36) obj.keyframe_insert(data_path="hide_render", frame=36) obj.keyframe_insert(data_path="hide_viewport", frame=50) obj.keyframe_insert(data_path="hide_render", frame=50) # Hides as part leaves inspection station obj.hide_viewport = True obj.hide_render = True obj.keyframe_insert(data_path="hide_viewport", frame=51) obj.keyframe_insert(data_path="hide_render", frame=51) # 4. Pneumatic Pusher Paddle and Piston Rod Motion pusher = bpy.data.objects.get("Pusher_Paddle") piston = bpy.data.objects.get("Piston_Rod") for comp in [pusher, piston]: if comp: init_y = comp.location.y comp.location.y = init_y comp.keyframe_insert(data_path="location", index=1, frame=1) comp.keyframe_insert(data_path="location", index=1, frame=74) # Extended position (strokes across belt to push defective part) comp.location.y = init_y - 0.070 comp.keyframe_insert(data_path="location", index=1, frame=82) # Retracts back to resting state comp.location.y = init_y comp.keyframe_insert(data_path="location", index=1, frame=90) comp.keyframe_insert(data_path="location", index=1, frame=120) # 5. Upstream in-feed bracket following behind upstream = bpy.data.objects.get("Upstream") if upstream: upstream.location.x = -0.45 upstream.keyframe_insert(data_path="location", index=0, frame=1) upstream.location.x = -0.15 upstream.keyframe_insert(data_path="location", index=0, frame=120) # 6. Andon Signal Tower (Green -> Red on Defect) andon_green_obj = bpy.data.objects.get("Andon_Green") andon_red_obj = bpy.data.objects.get("Andon_Red") if andon_green_obj and andon_red_obj: # Create dedicated green and red emissive materials ag_mat = create_emissive_material("AndonGreenLit", color=(0.1, 0.95, 0.2, 1.0), strength=4.0) ar_mat = create_emissive_material("AndonRedLit", color=(0.95, 0.05, 0.05, 1.0), strength=0.2) andon_green_obj.data.materials.clear() andon_green_obj.data.materials.append(ag_mat) andon_red_obj.data.materials.clear() andon_red_obj.data.materials.append(ar_mat) def render_video_sequence(scene, camera_obj, out_path, res_x=640, res_y=640, frames_dir="renders/animation/frames"): """Renders EEVEE animation frames and stitches them with OpenCV into an MP4 video.""" os.makedirs(frames_dir, exist_ok=True) orig_engine = scene.render.engine scene.render.engine = 'BLENDER_EEVEE' scene.camera = camera_obj scene.render.resolution_x = res_x scene.render.resolution_y = res_y frame_paths = [] print(f"Rendering {scene.frame_end - scene.frame_start + 1} frames for {out_path}...") for f in range(scene.frame_start, scene.frame_end + 1): scene.frame_set(f) fp = os.path.join(frames_dir, f"frame_{f:04d}.png") scene.render.filepath = os.path.abspath(fp) bpy.ops.render.render(write_still=True) frame_paths.append(fp) print(f"Rendered {len(frame_paths)} frames to {frames_dir}.") scene.render.engine = orig_engine def build_and_save_blend(usd_path="usd/scenes/sample_dent.usda", blend_out="station.blend"): # Reset to completely clean state bpy.ops.wm.read_factory_settings(use_empty=True) abs_usd = os.path.abspath(usd_path) abs_blend = os.path.abspath(blend_out) print(f"Importing USDA from: {abs_usd}") bpy.ops.wm.usd_import( filepath=abs_usd, import_usd_preview=True, import_materials=True, import_lights=True, import_cameras=True, apply_unit_conversion_scale=True, create_world_material=True, scale=1.0 ) scene = bpy.context.scene configure_cycles(scene) # Factory World environment if scene.world is None: world = bpy.data.worlds.new("FactoryWorld") scene.world = world world = scene.world if hasattr(world, 'node_tree') and world.node_tree: bg_node = world.node_tree.nodes.get("Background") if bg_node: bg_node.inputs["Color"].default_value = (0.04, 0.045, 0.055, 1.0) bg_node.inputs["Strength"].default_value = 0.9 # 1. Physical Overhead High-Bay Luminaire Fixture (replaces bare black box) build_overhead_luminaire_fixture(scene) # 2. Camera Ring Illuminator & Lens Detailing build_camera_ring_illuminator(scene) # 3. Moving Conveyor Belt Seam Markers seams = build_belt_tracking_markers(scene) # 4. Physical 3D Touchscreen Operator HMI Dashboard (Line KPIs) build_hmi_operator_panel(scene) # 5. Secondary 45° Oblique Profile Camera (Dual-Angle Vision Rig) oblique_cam = build_secondary_oblique_camera(scene) # 6. 3D Overview Camera with depth of field overview_cam_data = bpy.data.cameras.new("ProductionLineOverview") overview_cam_data.lens = 32 overview_cam_obj = bpy.data.objects.new("ProductionLineOverview", overview_cam_data) scene.collection.objects.link(overview_cam_obj) overview_cam_obj.location = (0.50, -0.54, 0.40) target_center = mathutils.Vector((0.0, 0.05, 0.10)) direction = target_center - overview_cam_obj.location overview_cam_obj.rotation_euler = direction.to_track_quat('-Z', 'Y').to_euler() overview_cam_data.dof.use_dof = True overview_cam_data.dof.focus_distance = (mathutils.Vector((0.0, 0.0, 0.006)) - overview_cam_obj.location).length overview_cam_data.dof.aperture_fstop = 5.6 # 7. AI Defect Detection HUD Overlay (Reticle, Glowing Bounding Box, Badge) hud_objects = build_inspection_hud_overlay(scene) # 8. Animation Keyframes for Conveyor Simulation animate_conveyor_simulation(scene, hud_objects, seams) # 9. Configure Viewport Settings (Hide Wireframe Frustums & Selection Lines) for window in bpy.context.window_manager.windows: for area in window.screen.areas: if area.type == 'VIEW_3D': for space in area.spaces: if space.type == 'VIEW_3D': space.shading.type = 'MATERIAL' space.shading.use_scene_lights = True space.shading.use_scene_world = True # Clean presentation: disable distracting frustum pyramids & dashed rays space.overlay.show_extras = False space.overlay.show_relationship_lines = False # Deselect all objects so no orange outline distracts the view bpy.ops.object.select_all(action='DESELECT') # Top-Down Station Camera station_cam = bpy.data.objects.get('Camera') # 10. Render Stills # Render Still Overview (Frame 42) - Shows entire station with glowing HMI dashboard & 2nd camera scene.frame_set(42) scene.camera = overview_cam_obj scene.render.resolution_x = 1024 scene.render.resolution_y = 640 scene.render.filepath = os.path.abspath("renders/samples/station_overview.png") print("Rendering station_overview.png (3D production line view with HMI dashboard)...") bpy.ops.render.render(write_still=True) # Render Station Camera Inspection HUD Preview (Frame 42) if station_cam: scene.camera = station_cam scene.render.resolution_x = 640 scene.render.resolution_y = 640 scene.render.filepath = os.path.abspath("renders/samples/inspection_hud_preview.png") print("Rendering inspection_hud_preview.png (AI defect detection view)...") bpy.ops.render.render(write_still=True) # Render Secondary 45° Oblique Profile Camera Preview (Frame 42) if oblique_cam: scene.camera = oblique_cam scene.render.resolution_x = 640 scene.render.resolution_y = 640 scene.render.filepath = os.path.abspath("renders/samples/oblique_camera_preview.png") print("Rendering oblique_camera_preview.png (2nd angle inspection view)...") bpy.ops.render.render(write_still=True) # 9. Render Both Animated Videos (Fast EEVEE render stitched to MP4) if station_cam: print("Rendering Station Camera Inspection Video...") render_video_sequence( scene, station_cam, out_path="renders/animation/station_camera_inspection.mp4", res_x=640, res_y=640, frames_dir="renders/animation/frames_station_cam" ) print("Rendering 3D Overview Conveyor Simulation Video...") render_video_sequence( scene, overview_cam_obj, out_path="renders/animation/station_overview_inspection.mp4", res_x=1024, res_y=640, frames_dir="renders/animation/frames_overview" ) # Set active camera to station_cam by default and reset to frame 1 if station_cam: scene.camera = station_cam scene.frame_set(1) # Save ready-to-open, interactive .blend file print(f"Saving .blend file to: {abs_blend}") bpy.ops.wm.save_as_mainfile(filepath=abs_blend) print("Saved station.blend successfully!") if __name__ == "__main__": build_and_save_blend()