diff --git a/surfaces/blender/brokkr_kitbash/core.py b/surfaces/blender/brokkr_kitbash/core.py index 71f3717..e68c566 100644 --- a/surfaces/blender/brokkr_kitbash/core.py +++ b/surfaces/blender/brokkr_kitbash/core.py @@ -1044,7 +1044,8 @@ class Sheet(NamedTuple): poles (P,) are the cage's vertices of irregular valence, as built; triangles is how many faces have 3 sides. boundary is the Subdivision's Boundary Smooth, by Blender's name: PRESERVE_CORNERS on a loft (a boundary vertex of two edges stays a corner), ALL on a free cage (the boundary is smoothed through it unless a corner pins it), - which is how a cage modelled by hand is set.""" + which is how a cage modelled by hand is set. mirror_of (V,) is, per vertex, the authored vertex it reflects + across x = 0, or itself: an authored vertex, one on the mirror plane, every vertex of a sheet not mirrored.""" V: np.ndarray faces: np.ndarray counts: np.ndarray @@ -1059,6 +1060,7 @@ class Sheet(NamedTuple): poles: np.ndarray triangles: int boundary: str + mirror_of: np.ndarray def _index(value: Any, where: str, least: int, most: int) -> int: @@ -1130,6 +1132,9 @@ def sheet(document: Any) -> Sheet: vertex = lambda i, j: i * N + j % N # noqa: E731 quads = np.array([[vertex(i, j), vertex(i, j + 1), vertex(i + 1, j + 1), vertex(i + 1, j)] for i in range(R - 1) for j in range(wrap)], dtype=np.int32) V = P.reshape(-1, 3) + mirror_of = np.arange(R * N).reshape(R, N) + if mirror: + mirror_of[:, :C - 1] = mirror_of[:, :C - 1:-1] corners = V[quads] areas = 0.5 * (np.linalg.norm(np.cross(corners[:, 1] - corners[:, 0], corners[:, 3] - corners[:, 0]), axis=1) + np.linalg.norm(np.cross(corners[:, 3] - corners[:, 2], corners[:, 1] - corners[:, 2]), axis=1)) @@ -1196,7 +1201,7 @@ def sheet(document: Any) -> Sheet: return Sheet(V=V.copy(), faces=quads.ravel().astype(np.int32), counts=np.full(len(quads), 4, dtype=np.int32), smooth=np.ones(len(quads), dtype=bool), sharp=NO_SHARP, creases=np.array([key for key, _ in kept], dtype=np.int64).reshape(-1, 2), weights=np.array([w for _, w in kept], dtype=np.float64), corners=np.array([key for key, _ in pinned], dtype=np.int64), corner_weights=np.array([w for _, w in pinned], dtype=np.float64), rings=R, points=N, - poles=np.zeros(0, dtype=np.int64), triangles=0, boundary="PRESERVE_CORNERS") + poles=np.zeros(0, dtype=np.int64), triangles=0, boundary="PRESERVE_CORNERS", mirror_of=mirror_of.ravel()) def _cage_facts(vertices: int, faces, counts): @@ -1321,6 +1326,7 @@ def _cage(document: Any, gate: bool = True) -> Sheet: if mirror and seam[a] and seam[b] and len(both) == 2: raise KitError(f"sheet.faces[{both[0]}] and sheet.faces[{both[1]}] share the edge between vertices {min(a, b)} and {max(a, b)}, which lies on the mirror plane: " "with their reflections that edge is in four faces (a fin on the plane)") + mirror_of = np.concatenate([np.arange(A), np.flatnonzero(~seam)]) if mirror else np.arange(A) twin = np.arange(A) if mirror: twin[~seam] = A + np.arange(int((~seam).sum())) @@ -1398,7 +1404,7 @@ def _cage(document: Any, gate: bool = True) -> Sheet: return Sheet(V=V, faces=flat, counts=counts, smooth=np.ones(len(counts), dtype=bool), sharp=NO_SHARP, creases=np.array([key for key, _ in kept], dtype=np.int64).reshape(-1, 2), weights=np.array([w for _, w in kept], dtype=np.float64), corners=np.array([key for key, _ in held], dtype=np.int64), corner_weights=np.array([w for _, w in held], dtype=np.float64), - rings=None, points=None, poles=poles, triangles=int((counts == 3).sum()), boundary="ALL") + rings=None, points=None, poles=poles, triangles=int((counts == 3).sum()), boundary="ALL", mirror_of=mirror_of) # --- reports -------------------------------------------------------------------------------------------------