Skip to content

Conversation

@petrasvestartas
Copy link
Collaborator

@petrasvestartas petrasvestartas commented Jun 4, 2025

Tessagon API implementation for mesh map:

Options are:

  • "Hex",
  • "Tri",
  • "Octo",
  • "Square",
  • "Rhombus",
  • "HexTri",
  • "DissectedSquare",
  • "DissectedTriangle",
  • "DissectedHexQuad",
  • "DissectedHexTri",
  • "Floret",
  • "Pythagorean",
  • "Brick",
  • "Weave",
  • "ZigZag",
  • "HexBigTri",
  • "Dodeca",
  • "SquareTri"
from pathlib import Path

from compas.colors import Color
from compas.datastructures import Mesh
from compas_viewer import Viewer
from compas_viewer.config import Config

from compas_libigl.mapping import map_pattern_to_mesh



# ==============================================================================
# Input geometry: 3D Mesh
# ==============================================================================

mesh = Mesh.from_obj(Path(__file__).parent.parent.parent / "data" / "minimal_surface.obj")

for vertex in mesh.vertices():
    x, y, z = mesh.vertex_attributes(vertex, "xyz")  # type: ignore
    mesh.vertex_attributes(vertex, "xyz", [x, -z, y])

# ==============================================================================
# Mapping: 3D Mesh, 2D Pattern, UV
# ==============================================================================

mesh_mapped = map_pattern_to_mesh("ZigZag", mesh, clip_boundaries=True, tolerance=1e-6, pattern_u=16, pattern_v=16)

# ==============================================================================
# Viewer
# ==============================================================================

config = Config()
config.camera.target = [0, 0, 0]
config.camera.position = [0.75, 0, 0.75]

viewer = Viewer(config=config)

# viewer.scene.add(mesh, name="mesh", show_faces=False, linecolor=Color.grey(), opacity=0.2)
viewer.scene.add(mesh_mapped, name="mesh_mapped", facecolor=Color.red())

viewer.show()

Method map_mesh in the example example_mapping.py now outputs more detailed information:
mv, mf, mn, mb, mg = map_mesh((v, f), (pv, pf)), where:

mv - mapped vertices
mf - mapped faces
mn - mapped normals (barycentric mapping of normals form the base mesh rather than pattern, must be precise for coarse patterns)
mb - boolean values that says if a polygon is on a boundary or not
mg - grouping values, when polygons have holes after clipping (you need cgal to vizualize such constrained triangulation).

Screenshot from 2025-06-04 14-06-28
Screenshot from 2025-06-04 15-30-17

Copy link
Member

@tomvanmele tomvanmele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool :)

@petrasvestartas petrasvestartas merged commit 62c29fb into main Jun 4, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants