import bpy, bmesh, json, os, math HERE = os.path.dirname(os.path.abspath(__file__)) out = {} for me in bpy.data.meshes: if not me.users or not me.name.startswith("DoorArm"): continue bm = bmesh.new(); bm.from_mesh(me) lay = bm.faces.layers.int.get('part') sh = bm.edges.layers.bool.get('sharp_edge') ids = list(me.get("parts", [])) per = {} tot_soft_sharp = 0 for e in bm.edges: if len(e.link_faces) != 2 or sh is None or not e[sh]: continue ang = math.degrees(e.calc_face_angle(0.0)) if ang < 12.0: tot_soft_sharp += 1 f = e.link_faces[0] pid = ids[f[lay]] if lay is not None and f[lay] < len(ids) else "?" per[pid] = per.get(pid, 0) + 1 bm.free() if tot_soft_sharp: out[me.name] = dict(sharp_edges_under_12deg=tot_soft_sharp, by_part=dict(sorted(per.items(), key=lambda kv: -kv[1])[:12])) json.dump(out, open(os.path.join(HERE, "crit1_sharp.json"), "w"), indent=1) print("[crit1] sharp done", flush=True)