"""Prints the extents of an opened demo-map .blend and which kit meshes it uses most (for studying the pack). blender -b --factory-startup --python build/study_bounds.py """ import collections import json import bpy from mathutils import Vector lo = Vector((1e9, 1e9, 1e9)) hi = Vector((-1e9, -1e9, -1e9)) use = collections.Counter() zs = collections.Counter() for ob in bpy.data.objects: if ob.type != "MESH" or not ob.get("ue_mesh"): continue use[ob.data.name] += 1 zs[round(ob.matrix_world.translation.z, 1)] += 1 for c in ob.bound_box: p = ob.matrix_world @ Vector(c) lo = Vector((min(lo.x, p.x), min(lo.y, p.y), min(lo.z, p.z))) hi = Vector((max(hi.x, p.x), max(hi.y, p.y), max(hi.z, p.z))) print("STUDY " + json.dumps({ "file": bpy.path.basename(bpy.data.filepath), "lo": [round(v, 2) for v in lo], "hi": [round(v, 2) for v in hi], "origin_z_levels": sorted(zs.items(), key=lambda kv: -kv[1])[:14], "most_used": use.most_common(45), "lights": sum(1 for o in bpy.data.objects if o.type == "LIGHT"), }))