"""Door robot arm: the LODs side by side (LOD0, LOD1, LOD2 of each version, imported back from fbx/), Workbench, a side view, to check that the silhouette holds -> previews/lods_.png. blender -b --factory-startup --python build/dra_lod_preview.py """ import os import math import bpy from mathutils import Vector HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) FBX = os.path.join(ROOT, "fbx") for ver in ("A", "B"): bpy.ops.wm.read_factory_settings(use_empty=True) sc = bpy.context.scene tris = [] groups = [] for i, suf in enumerate(("", "_LOD1", "_LOD2")): before = set(bpy.data.objects) bpy.ops.import_scene.fbx(filepath=os.path.join(FBX, "SK_DoorRobotArm_%s%s.fbx" % (ver, suf))) new = [o for o in bpy.data.objects if o not in before] groups.append(new) for o in new: if o.type == 'MESH': o.data.calc_loop_triangles() tris.append(len(o.data.loop_triangles)) bpy.context.view_layer.update() # the arm's forward axis lies along the longer horizontal side of its bounds: spread the copies along it and look # across it (a side view, as ref1) me0 = next(o for o in groups[0] if o.type == 'MESH') pts = [me0.matrix_world @ v.co for v in me0.data.vertices] ex = max(p.x for p in pts) - min(p.x for p in pts) ey = max(p.y for p in pts) - min(p.y for p in pts) along = Vector((1, 0, 0)) if ex >= ey else Vector((0, 1, 0)) print("[dra] extents", round(ex, 3), round(ey, 3), tuple(along), flush=True) across = Vector((0, 1, 0)) if ex >= ey else Vector((1, 0, 0)) for i, grp in enumerate(groups): for o in grp: if o.parent is None: o.location += along * (i * 3.6) sc.render.engine = 'BLENDER_WORKBENCH' sh = sc.display.shading sh.light = 'STUDIO' sh.color_type = 'MATERIAL' sh.show_cavity = True sh.show_object_outline = True sc.render.resolution_x, sc.render.resolution_y = 2400, 900 cd = bpy.data.cameras.new("cam") cd.type = 'ORTHO' cd.ortho_scale = 13.0 cam = bpy.data.objects.new("cam", cd) sc.collection.objects.link(cam) tgt = along * 3.6 + Vector((0, 0, 1.2)) cam.location = tgt + across * 14.0 d = (tgt - cam.location).normalized() cam.rotation_euler = d.to_track_quat('-Z', 'Y').to_euler() sc.camera = cam print("[dra] camera", tuple(round(c, 2) for c in cam.location), tuple(round(c, 3) for c in d), flush=True) w = bpy.data.worlds.new("w") w.color = (0.6, 0.6, 0.6) sc.world = w sc.render.filepath = os.path.join(ROOT, "previews", "lods_%s.png" % ver) bpy.ops.render.render(write_still=True) print("[dra] lods", ver, tris, sc.render.filepath, flush=True)