"""Quick looks (Workbench) or a wireframe check of NutritionFeeder.blend, nothing saved: blender.exe -b ../NutritionFeeder.blend --python nf_preview.py -- [wire] [inject=0|1] [tag] Shots in previews/wb_* or previews/wire_*.""" import bpy, math, os, sys from mathutils import Vector FOLDER = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) OUTD = os.path.join(FOLDER, "previews") os.makedirs(OUTD, exist_ok=True) argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] wire = "wire" in argv inject = float(next((a.split("=")[1] for a in argv if a.startswith("inject=")), "1")) tag = next((a for a in argv if a not in ("wire",) and not a.startswith("inject=")), "") S, U0, V0 = 0.0005, 513.0, 1345.0 P = lambda u, v, f: Vector(((u - U0) * S, -f * 0.001, (V0 - v) * S)) SHOTS = { "front": (P(675, 972, 1305), P(675, 972, 0), 39.06, (-0.106, 0.133)), "q_left": (P(160, 700, 900), P(560, 760, 30), 40, (0, 0)), "q_right_low": (P(1250, 1250, 700), P(640, 900, 30), 40, (0, 0)), "cavity": (P(560, 820, 420), P(675, 960, 10), 40, (0, 0)), "injector": (P(590, 760, 220), P(676, 820, 30), 45, (0, 0)), "edge": (P(-300, 300, 300), P(150, 300, 40), 50, (0, 0)), } sc = bpy.context.scene root = bpy.data.objects["NutritionFeeder_Root"] if root.animation_data: root.animation_data.action = None root["inject"] = inject temps = [] if wire: wm = bpy.data.materials.new("_wire_ink"); wm.diffuse_color = (0.02, 0.02, 0.03, 1) for o in [o for o in bpy.data.objects if o.type == 'MESH' and not o.name.startswith("UCX_")]: t = o.copy(); t.data = o.data.copy(); t.name = "_w_" + o.name t.data.materials.clear(); t.data.materials.append(wm) sc.collection.objects.link(t) md = t.modifiers.new("w", 'WIREFRAME'); md.thickness = 0.00025; md.use_relative_offset = False; md.use_even_offset = False temps.append(t) sc.render.engine = 'BLENDER_WORKBENCH' sh = sc.display.shading sh.light = 'STUDIO'; sh.color_type = 'MATERIAL'; sh.show_object_outline = False; sh.show_cavity = not wire; sh.cavity_type = 'BOTH' sc.render.image_settings.file_format = 'PNG' cam = bpy.data.objects.new("_pv_cam", bpy.data.cameras.new("_pv_cam")); sc.collection.objects.link(cam); sc.camera = cam for o in bpy.data.objects: if o.name.startswith("UCX_"): o.hide_render = True sc.frame_set(sc.frame_current) done = [] for nm, (loc, tgt, lens, shift) in SHOTS.items(): if nm == "front": sc.render.resolution_x, sc.render.resolution_y = 1024, 1536 cam.data.sensor_fit = 'VERTICAL' else: sc.render.resolution_x, sc.render.resolution_y = (2000, 1400) if wire else (1400, 1000) cam.data.sensor_fit = 'AUTO' cam.location = loc cam.rotation_euler = (tgt - loc).normalized().to_track_quat('-Z', 'Y').to_euler() cam.data.lens = lens cam.data.shift_x, cam.data.shift_y = shift cam.data.clip_start = 0.01 sc.render.filepath = os.path.join(OUTD, "%s%s_%s.png" % ("wire" if wire else "wb", tag, nm)) bpy.ops.render.render(write_still=True) done.append(sc.render.filepath) print("PREVIEW OK", done)