"""Tiger: quick look from other sides (headless): side, top, front, rear three-quarter, under, and a hero view, in the studio. blender.exe -b Tender_Tiger.blend -t 0 --python build/tg_views.py -- TAG [samples] -> previews/_.png, _sheet.png """ import bpy import math import os import sys from mathutils import Vector HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] TAG = args[0] if args else "v" SAMPLES = int(args[1]) if len(args) > 1 else 32 sc = bpy.context.scene sc.render.engine = 'CYCLES' sc.cycles.samples = SAMPLES sc.cycles.use_denoising = True try: prefs = bpy.context.preferences.addons['cycles'].preferences for kind in ('OPTIX', 'CUDA', 'HIP', 'ONEAPI'): try: prefs.compute_device_type = kind except Exception: continue prefs.refresh_devices() if any(d.type == kind for d in prefs.devices): for d in prefs.devices: d.use = d.type == kind sc.cycles.device = 'GPU' break except Exception as ex: print("GPU not set", ex) sc.view_settings.view_transform = 'Standard' cd = bpy.data.cameras.new("_views") cam = bpy.data.objects.new("_views", cd) sc.collection.objects.link(cam) sc.camera = cam sc.render.resolution_x, sc.render.resolution_y = 900, 600 C = Vector((0.0, 1.2, -0.1)) SHOTS = {"side": ((14.0, 1.2, 0.2), 'ORTHO', 8.5), "top": ((0.0, 1.2, 14.0), 'ORTHO', 8.5), "front": ((0.0, -14.0, 0.0), 'ORTHO', 5.0), "rear34": ((-7.5, 9.5, 3.0), 'PERSP', 50), "under": ((5.0, -2.0, -8.0), 'PERSP', 50), "hero": ((-8.0, -7.5, 3.5), 'PERSP', 50)} paths = [] for name, (loc, kind, val) in SHOTS.items(): cam.location = loc tgt = C if kind == 'PERSP' else Vector((loc[0] * 0 + (C.x if name != "front" else 0), C.y if name != "front" else 0, C.z)) if name == "top": cam.rotation_euler = (0, 0, math.radians(90)) else: cam.rotation_euler = (Vector(tgt) - Vector(loc)).to_track_quat('-Z', 'Z').to_euler() cd.type = kind if kind == 'ORTHO': cd.ortho_scale = val else: cd.lens = val sc.render.filepath = os.path.join(ROOT, "previews", "%s_%s.png" % (TAG, name)) bpy.ops.render.render(write_still=True) paths.append(sc.render.filepath) print("VIEWS OK", paths)