"""Quick Workbench renders of the vat from the cameras fitted to the picture's views (build/cams.json), headless: blender.exe -b ../NutritionVat.blend --python nv_preview.py -- [tag] [views...] [--hoses] [--wire] Writes previews/fit/_.png at twice the picture's size (2000 x 1158), transparent; nv_compare.py lays them beside the picture. The file is not saved. """ import bpy, math, os, sys, json from mathutils import Euler, Vector HERE = os.path.dirname(os.path.abspath(__file__)) FOLDER = os.path.dirname(HERE) argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] flags = {a for a in argv if a.startswith("--")} args = [a for a in argv if not a.startswith("--")] TAG = args[0] if args else "v01" VIEWS = args[1:] or ["left", "mid", "right"] OUT = os.path.join(FOLDER, "previews", "fit") os.makedirs(OUT, exist_ok=True) cams = json.load(open(os.path.join(HERE, "cams.json"))) COL = {"M_NV_Shell": (0.62, 0.72, 0.68, 1), "M_NV_ShellDark": (0.30, 0.34, 0.33, 1), "M_NV_Gap": (0.03, 0.03, 0.03, 1), "M_NV_Glass": (0.10, 0.45, 0.55, 1), "M_NV_Glow": (0.2, 0.95, 1.0, 1), "M_NV_Rubber": (0.06, 0.06, 0.07, 1), "M_NV_Chrome": (0.85, 0.86, 0.88, 1), "M_NV_Brass": (0.7, 0.55, 0.2, 1), "M_NV_Keypad": (0.08, 0.08, 0.09, 1), "M_NV_Grille": (0.12, 0.13, 0.13, 1), "M_NV_Decal": (0.9, 0.7, 0.1, 1), "M_NV_CanGlass": (0.5, 0.55, 0.5, 1)} def main(): sc = bpy.context.scene for m in bpy.data.materials: if m.name in COL: m.diffuse_color = COL[m.name] hoses = bpy.data.objects.get("SM_NutritionVat_Hoses") if hoses: hoses.hide_render = "--hoses" not in flags and "--hoses-mid" not in flags for o in bpy.data.objects: if o.name.startswith("UCX_"): o.hide_render = True sc.render.engine = 'BLENDER_WORKBENCH' sh = sc.display.shading sh.light = 'STUDIO' sh.color_type = 'MATERIAL' sh.show_cavity = "--nocav" not in flags sh.cavity_type = 'BOTH' sh.show_object_outline = False if "--wire" in flags: sh.show_object_outline = True sc.render.engine = 'BLENDER_WORKBENCH' sc.render.film_transparent = True sc.render.resolution_x, sc.render.resolution_y = 2000, 1158 sc.render.resolution_percentage = 100 sc.view_settings.view_transform = 'Standard' cam_d = bpy.data.cameras.new("FitCam") cam = bpy.data.objects.new("FitCam", cam_d) sc.collection.objects.link(cam) sc.camera = cam cam_d.sensor_fit = 'HORIZONTAL' cam_d.sensor_width = 36.0 cam_d.clip_start, cam_d.clip_end = 0.05, 2000.0 for v in VIEWS: c = cams[v] p = c["params"] cam.location = p[:3] cam.rotation_euler = Euler(p[3:6], 'XYZ') cam_d.lens = c["lens_mm"] cam_d.shift_x, cam_d.shift_y = c["shift"] dist = (cam.location - Vector((0, 0, 1.0))).length # depth range round the pod (precision at 300 m) cam_d.clip_start, cam_d.clip_end = max(0.05, dist - 3.0), dist + 3.0 if hoses: hoses.hide_render = not ("--hoses" in flags or ("--hoses-mid" in flags and v == "mid")) sc.render.filepath = os.path.join(OUT, "%s_%s.png" % (TAG, v)) bpy.ops.render.render(write_still=True) print("PREVIEW OK", TAG, VIEWS) main()