"""Critique 1: bounds of chosen parts in the arm frame A (rest), read-only -> crit1_bounds.json""" import bpy, json, os from mathutils import Vector HERE = os.path.dirname(os.path.abspath(__file__)) WANT = {"DoorArm | turret": ["T02", "T03", "T04.L", "T04c.L", "T04a.L", "T11", "T12", "T13", "T09", "T10"], "DoorArm | forearm": ["F02", "F03.L", "F04.L", "F09", "F09c.L", "F09w", "F14.L", "F07", "F05"], "DoorArm | upper arm": ["U02", "U12", "U03.L", "U10.L"], "DoorArm | lower arm": ["L01", "L03.L", "L03c", "L06.L", "L07.L", "L18", "L12.L"], "DoorArm | tool B": ["B01", "B02"], "DoorArm | J3 piston": ["R05"], "DoorArm | J3 cylinder": ["R01"]} out = {} for mn, parts in WANT.items(): me = bpy.data.meshes[mn] ja = Vector(me["joint_A"]) ids = list(me["parts"]); lay = me.attributes["part"] res = {} for p in parts: if p not in ids: res[p] = "missing"; continue k = ids.index(p) vs = set() for poly in me.polygons: if lay.data[poly.index].value == k: vs.update(poly.vertices) pts = [me.vertices[i].co + ja for i in vs] lo = [round(min(q[i] for q in pts), 3) for i in range(3)] hi = [round(max(q[i] for q in pts), 3) for i in range(3)] res[p] = dict(min=lo, max=hi) out[mn] = res json.dump(out, open(os.path.join(HERE, "crit1_bounds.json"), "w"), indent=1) print("[crit1] bounds", flush=True)