"""Critique 1: extra Workbench views of DoorRobotArm.blend into previews/critique1 (the .blend is never saved). usage: blender -b --factory-startup DoorRobotArm.blend --python crit1_render.py -- view1,view2,...""" import bpy, math, os, sys from mathutils import Vector HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(os.path.dirname(HERE)) sys.path.insert(0, os.path.join(ROOT, "build")) import dra_preview as P views = sys.argv[sys.argv.index("--") + 1].split(",") if "--" in sys.argv else [] sc = bpy.data.scenes["DoorArm | Showroom"] bpy.context.window_manager.windows[0].scene = sc if bpy.context.window_manager.windows else None P.setup(sc, 1000) xa, xb = P.arm_x("A"), P.arm_x("B") Z = P.ROOT_Z cd = bpy.data.cameras.new("crit cam") cam = bpy.data.objects.new("crit cam", cd) sc.collection.objects.link(cam) sc.camera = cam cd.clip_start = 0.02 cd.clip_end = 100 def A(x, y, z, v="A"): return Vector(((xa if v == "A" else xb) + x, y, Z + z)) def sph(tgt, dist, az, el): """camera at distance dist from tgt, azimuth az (deg from +X toward +Y), elevation el (deg)""" a, e = math.radians(az), math.radians(el) return tgt + dist * Vector((math.cos(e) * math.cos(a), math.cos(e) * math.sin(a), math.sin(e))) WC = (0.957, 0.0, 2.0614) V = { # name: (version shown, target, dist, az, el, lens, ortho_scale or None) "r6m_A": ("A", A(0.80, 0, 2.06), 3.8, 55, -28, 85, None), "r6m_B": ("B", A(0.80, 0, 2.06, "B"), 3.8, 55, -28, 85, None), "r6m2_A": ("A", A(0.80, 0, 2.06), 3.8, 62, -12, 85, None), "r6m2_B": ("B", A(0.80, 0, 2.06, "B"), 3.8, 62, -12, 85, None), "sideB": ("B", A(0.95, 0, 2.06, "B"), 6.0, 90, 0, None, 1.6), "sideA": ("A", A(0.95, 0, 2.06), 6.0, 90, 0, None, 1.6), "back_drum": ("A", A(-0.34, 0, 0.55), 5.0, 180, 8, None, 1.4), "back_high": ("A", A(-0.34, 0, 0.75), 5.0, 180, 35, None, 1.6), "front": ("A", A(0.0, 0, 1.2), 8.0, 0, 0, None, 3.2), "top": ("A", A(-0.2, 0, 1.5), 8.0, 0, 89.9, None, 3.6), "knee": ("A", A(-0.865, 0.45, 0.85), 2.2, 90, 0, 85, None), "j2": ("A", A(-0.341, 0.45, 0.517), 2.2, 75, 10, 85, None), "knob": ("A", A(-1.676, 0.1, 1.456), 1.2, 100, 15, 85, None), "hub": ("A", A(1.15, 0, 2.06), 1.6, 25, 10, 85, None), "ref2m": ("A", A(-0.1, 0, 1.30), 11.0, 38, 4, 85, None), "ref3m": ("A", A(-0.25, 0, 1.30), 11.0, -125, 4, 85, None), "turret34": ("A", A(0.1, 0, 0.45), 3.2, 35, 12, 85, None), "ref5m": ("A", A(-0.95, 0.2, 1.15), 2.9, 62, -14, 85, None), "ref4m": ("A", A(0.05, 0, 0.42), 3.3, 52, 6, 85, None), "upper34": ("A", A(-0.45, 0, 2.15), 3.4, 40, 10, 85, None), } for name in views: ver, tgt, dist, az, el, lens, osc = V[name] P.show_only(ver) if osc: cd.type = 'ORTHO' cd.ortho_scale = osc else: cd.type = 'PERSP' cd.lens = lens cam.location = sph(tgt, dist, az, el) P.look(cam, tgt) cyc = bpy.data.objects.get("Showroom | cyclorama") if cyc: cyc.hide_render = cam.location.y < -1.0 or el > 60 sc.render.filepath = os.path.join(HERE, "crit1_%s.png" % name) bpy.ops.render.render(write_still=True, scene=sc.name) print("[crit1] rendered", name, flush=True)