"""Re-import the os_machines FBX files and print per-object origin / bounds / tris / materials (Blender space: Z up, front -Y), check required children + empties, tri budgets and footprints. Run: blender -b --factory-startup --python verify_os_machines.py -- [names]""" import bpy, os, sys d = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..", "Assets", "Art", "Models")) # name: (required children, footprint half-extents (x, y) or None, tri budget) REQ = { "SM_Hopper": (["Body", "Mouth"], (1.0, 1.0), 10000), "SM_Filler": (["Body", "Lamp", "Out"], (1.0, 1.0), 10000), "SM_Vaporizer": (["Body", "Lamp", "Vent", "Out"], (1.0, 1.0), 10000), "SM_CryoPress": (["Body", "Lamp", "Press", "Out"], (1.0, 1.0), 10000), "SM_Pump": (["Body", "Rotor"], (0.5, 1.0, "front"), 10000), # intake pipe is meant to hang over the front (-Y) edge "SM_WaterTank": (["Body", "Fill"], (1.0, 1.0), 10000), "SM_DroneHub": (["Body", "Land"], (1.0, 1.0), 10000), "SM_RainDrone": (["Body", "Tank", "Rotor_1", "Rotor_2", "Rotor_3", "Rotor_4"], None, 6000), } names = (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []) or list(REQ) bad = 0 for n in names: req, fp, budget = REQ[n] bpy.ops.wm.read_factory_settings(use_empty=True) bpy.ops.import_scene.fbx(filepath=os.path.join(d, n + ".fbx")) bpy.context.view_layer.update() total = 0 gmn = [1e9] * 3 gmx = [-1e9] * 3 rows, found, deck = [], set(), [] for o in sorted(bpy.context.scene.objects, key=lambda o: o.name): found.add(o.name) org = o.matrix_world.translation if o.type == "EMPTY": rows.append(f" {o.name:<9} EMPTY at({org.x:.3f},{org.y:.3f},{org.z:.3f})") continue if o.type != "MESH": continue tris = sum(len(f.vertices) - 2 for f in o.data.polygons) total += tris pts = [o.matrix_world @ v.co for v in o.data.vertices] mn = [min(p[i] for p in pts) for i in range(3)] mx = [max(p[i] for p in pts) for i in range(3)] gmn = [min(a, b) for a, b in zip(gmn, mn)] gmx = [max(a, b) for a, b in zip(gmx, mx)] deck += [p for p in pts if p.z > -0.05] # parts above the deck must stay inside the footprint mats = ",".join(sorted({m.name for m in o.data.materials if m})) uv = "uv" if o.data.uv_layers else "NO-UV" rows.append(f" {o.name:<9} origin({org.x:.3f},{org.y:.3f},{org.z:.3f}) x[{mn[0]:.3f},{mx[0]:.3f}] y[{mn[1]:.3f},{mx[1]:.3f}] " f"z[{mn[2]:.3f},{mx[2]:.3f}] tris={tris} {uv} [{mats}]") missing = [r for r in req if r not in found] issues = [] if missing: issues.append("missing=%s" % missing) if total > budget: issues.append("over budget %d>%d" % (total, budget)) if fp and deck: ex = max(abs(p.x) for p in deck) ey = max((p.y if len(fp) > 2 else abs(p.y)) for p in deck) if ex > fp[0] + 0.01 or ey > fp[1] + 0.01: issues.append("footprint |x|=%.3f |y|=%.3f (limit %.1f x %.1f)" % (ex, ey, fp[0], fp[1])) bad += len(issues) dims = [b - a for a, b in zip(gmn, gmx)] print(f"OSM|{n}|tris={total}/{budget}|size {dims[0]:.2f} x {dims[1]:.2f} x {dims[2]:.2f}|" f"x[{gmn[0]:.2f},{gmx[0]:.2f}] y[{gmn[1]:.2f},{gmx[1]:.2f}] z[{gmn[2]:.2f},{gmx[2]:.2f}]|{'; '.join(issues) or 'OK'}") for r in rows: print(r) print(f"OSM|RESULT|{'OK' if bad == 0 else 'ISSUES %d' % bad}")