# Spearfish: orthographic Workbench renders framed exactly like the blueprint's panels (exec'd in Blender), for # build/compare_views.py, which lays them over the blueprint. 2 render pixels per blueprint pixel. import bpy, math, os from mathutils import Vector, Matrix HERE = r"D:\HADAL - The Descent\models\tender-spearfish\build" exec(open(os.path.join(HERE, "sf_measure.py")).read()) OUTD = os.path.join(os.path.dirname(HERE), "previews", "compare") os.makedirs(OUTD, exist_ok=True) K = 2 FS = 0.01333 # FRONT / REAR panels: metres per blueprint pixel (body width 165 px = 2.20 m) # name: (image box x0, y0, x1, y1), metres per px, camera centre in model, right, up, forward VIEWS = { "top": ((468, 32, 1168, 282), S, lambda bx, by: Vector(((157.5 - by) * S, Yi(bx), 0)), (0, -1, 0), (1, 0, 0), (0, 0, -1)), "side": ((468, 290, 1168, 470), S, lambda bx, by: Vector((0, Yi(bx), Zi(by))), (0, -1, 0), (0, 0, 1), (1, 0, 0)), "under": ((468, 470, 1168, 680), S, lambda bx, by: Vector(((by - 574.5) * S, Yi(bx), 0)), (0, -1, 0), (-1, 0, 0), (0, 0, 1)), "front": ((1175, 95, 1475, 265), FS, lambda bx, by: Vector(((bx - 1322.5) * FS, 0, -0.60 + (246 - by) * FS)), (1, 0, 0), (0, 0, 1), (0, 1, 0)), "rear": ((1175, 370, 1475, 525), FS, lambda bx, by: Vector((-(bx - 1323) * FS, 0, -0.60 + (516 - by) * FS)), (-1, 0, 0), (0, 0, 1), (0, -1, 0)), } sc = bpy.context.scene sc.render.engine = 'BLENDER_WORKBENCH' sh = sc.display.shading sh.light = 'STUDIO'; sh.color_type = 'MATERIAL'; sh.show_object_outline = True; sh.object_outline_color = (0, 0, 0) sh.show_cavity = True sc.render.film_transparent = True sc.render.image_settings.file_format = 'PNG'; sc.render.image_settings.color_mode = 'RGBA' cam = bpy.data.objects.get("_cmp_cam") if cam is None: cam = bpy.data.objects.new("_cmp_cam", bpy.data.cameras.new("_cmp_cam")) sc.collection.objects.link(cam) cam.data.type = 'ORTHO'; cam.data.clip_start = 0.01; cam.data.clip_end = 100 prev_cam = sc.camera sc.camera = cam hide = [o for o in bpy.data.objects if o.name.startswith(("SM_Spearfish_Cabin", "UCX_"))] for o in hide: o.hide_render = True for name, (box, mpp, cfun, right, up, fwd) in VIEWS.items(): x0, y0, x1, y1 = box w, h = (x1 - x0), (y1 - y0) c = cfun((x0 + x1) / 2, (y0 + y1) / 2) R, U, F = Vector(right), Vector(up), Vector(fwd) m = Matrix((R, U, -F)).transposed().to_4x4() m.translation = c - F * 20 cam.matrix_world = m sc.render.resolution_x, sc.render.resolution_y = w * K, h * K sc.render.resolution_percentage = 100 cam.data.ortho_scale = max(w, h) * mpp sc.render.filepath = os.path.join(OUTD, "r_%s.png" % name) bpy.ops.render.render(write_still=True) for o in hide: o.hide_render = False sc.camera = prev_cam result = sorted(os.listdir(OUTD))