From e141782a608f807fca5b2925d409adebda98476d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 1 Dec 2026 06:46:50 +0100 Subject: [PATCH] mesh polish: boundary_root, the cut-root formula cut_parts shared with the rig Co-Authored-By: Claude Sonnet 5.5 --- surfaces/blender/brokkr_mesh_polish/__init__.py | 2 +- surfaces/blender/brokkr_mesh_polish/core.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/surfaces/blender/brokkr_mesh_polish/__init__.py b/surfaces/blender/brokkr_mesh_polish/__init__.py index 473550d..915ab5d 100644 --- a/surfaces/blender/brokkr_mesh_polish/__init__.py +++ b/surfaces/blender/brokkr_mesh_polish/__init__.py @@ -667,7 +667,7 @@ class BROKKR_MESH_POLISH_OT_cut_parts(PolishOperator): raise Refused(f"Part {name!r} came out empty: move its seed onto the surface.") lengths = np.array([e.calc_length() for e in cut]) mids = np.array([((e.verts[0].co + e.verts[1].co) / 2)[:] for e in cut]).reshape(-1, 3) - root_local = (mids * lengths[:, None]).sum(axis=0) / lengths.sum() if len(cut) else np.zeros(3) + root_local = core.boundary_root(mids, lengths) spread = mids - root_local normal_local = np.linalg.eigh((spread * lengths[:, None]).T @ spread)[1][:, 0] if len(cut) >= 3 else np.array([0.0, 0.0, 1.0]) mean_radius = float((np.linalg.norm(spread, axis=1) * lengths).sum() / lengths.sum()) if len(cut) else 0.0 diff --git a/surfaces/blender/brokkr_mesh_polish/core.py b/surfaces/blender/brokkr_mesh_polish/core.py index 9031425..179efb0 100644 --- a/surfaces/blender/brokkr_mesh_polish/core.py +++ b/surfaces/blender/brokkr_mesh_polish/core.py @@ -259,6 +259,12 @@ def grow_parts(count: int, pairs: np.ndarray, costs: np.ndarray, seeds: list[tup return np.asarray(part, dtype=np.int64), np.asarray(best) +def boundary_root(mids: np.ndarray, lengths: np.ndarray) -> np.ndarray: + """Where a part is rooted: the length-weighted mean of the midpoints of the edges along its cut (zeros when + it has no cut).""" + return (mids * lengths[:, None]).sum(axis=0) / lengths.sum() if len(lengths) else np.zeros(3) + + def parse_seeds(text: str) -> list[tuple[str, tuple[float, float, float]]]: """'hull=0,0,0; pod1=1,0,0.5; pod1=1.2,0,0.4' as [(name, (x, y, z))]; ValueError names the bad entry.""" seeds = []