"""Studio for the pressure door's pictures: cameras, lights, world. Not exported (collection 'Studio'). render(view, path, engine='CYCLES', samples=96, res=(1600, 1200))""" import bpy, math from mathutils import Vector STUDIO = "Studio" VIEWS = { # name: (location, look-at, lens) "front34": ((-3.6, -6.4, 2.3), (0.55, 0.0, 1.25), 38), "open34": ((-3.9, -6.6, 2.5), (0.8, -1.0, 1.15), 34), "hinge": ((-0.3, -3.1, 2.1), (1.75, -0.45, 1.35), 40), "top": ((0.1, -2.6, 3.6), (0.2, -0.3, 2.2), 40), "back": ((2.6, 4.4, 1.9), (0.0, 0.3, 1.2), 36), "floor": ((-2.6, -3.0, 1.4), (-1.4, -0.9, 0.0), 38), } def studio_coll(): c = bpy.data.collections.get(STUDIO) if c is None: c = bpy.data.collections.new(STUDIO) bpy.context.scene.collection.children.link(c) return c def light(name, kind, loc, rot, energy, size=1.0, color=(1, 1, 1)): ob = bpy.data.objects.get(name) if ob is None: ld = bpy.data.lights.new(name, kind) ob = bpy.data.objects.new(name, ld) studio_coll().objects.link(ob) ob.location = loc ob.rotation_euler = rot ob.data.energy = energy ob.data.color = color if kind == 'AREA': ob.data.size = size return ob def setup(): sc = bpy.context.scene cam = bpy.data.objects.get("PD_Camera") if cam is None: cam = bpy.data.objects.new("PD_Camera", bpy.data.cameras.new("PD_Camera")) studio_coll().objects.link(cam) sc.camera = cam light("PD_Key", 'AREA', (-3.0, -4.5, 4.2), (math.radians(50), 0, math.radians(-35)), 900, 3.0, (1.0, 0.97, 0.93)) light("PD_Fill", 'AREA', (4.5, -4.0, 2.0), (math.radians(70), 0, math.radians(48)), 350, 4.0, (0.9, 0.95, 1.0)) light("PD_Top", 'AREA', (0.5, -1.5, 5.0), (0, 0, 0), 300, 4.0) light("PD_Back", 'AREA', (0.5, 4.0, 3.5), (math.radians(-55), 0, math.radians(180)), 400, 3.0) w = sc.world or bpy.data.worlds.new("World") sc.world = w w.use_nodes = True bg = w.node_tree.nodes.get("Background") bg.inputs[0].default_value = (0.42, 0.45, 0.48, 1) bg.inputs[1].default_value = 0.6 sc.view_settings.view_transform = 'AgX' sc.view_settings.look = 'None' return cam def aim(cam, view): loc, tgt, lens = VIEWS[view] cam.location = loc d = Vector(tgt) - Vector(loc) cam.rotation_euler = d.to_track_quat('-Z', 'Y').to_euler() cam.data.lens = lens cam.data.clip_start = 0.05 def render(view, path, engine='CYCLES', samples=96, res=(1600, 1200)): sc = bpy.context.scene cam = setup() aim(cam, view) sc.render.engine = engine sc.render.resolution_x, sc.render.resolution_y = res sc.render.resolution_percentage = 100 if engine == 'CYCLES': sc.cycles.samples = samples sc.cycles.use_denoising = True try: sc.cycles.device = 'GPU' except Exception: pass sc.render.filepath = path sc.render.image_settings.file_format = 'PNG' bpy.ops.render.render(write_still=True) return path