We can call libigl in Python through ExternalEvaluate:
$igl = StartExternalSession[ Association["System" -> "Python", "Evaluator" -> <|"Dependencies" -> {"libigl"}, "EnvironmentName" -> "iglenv"|>]]; ExternalEvaluate[$igl, " import igl import numpy as np import os def compute_uv(filename: str) -> np.ndarray: V, F = igl.read_triangle_mesh(filename) bnd = igl.boundary_loop(F) b = np.array([bnd[0], bnd[len(bnd) // 2]]) bc = np.array([[0.0, 0.0], [1.0, 0.0]]) UV = igl.lscm(V, F, b, bc) return UV[0] "]; Right now we have to pass in a file. I tried doing stuff like
def compute_uv(V: np.array, F: np.array) -> np.array:
but I couldn't figure out how to pass in arrays to python as the right type.
ptsvertices = Import["/Users/ghurst/Downloads/theX.csv"]; triangles = Import["/Users/ghurst/Downloads/theT.csv"]; Export["temp.obj", MeshRegion[pts, Polygon[triangles]]]; And now we get the uv data and plot:
uvs = Normal[ExternalEvaluate[$igl, "compute_uv('temp.obj')"]]; texture = ImageResize[Image[Table[Mod[i + j, 2], {i, 8}, {j, 8}]], Scaled[30], Resampling -> "Nearest"]; Graphics3D[{Texture[texture], EdgeForm[], GraphicsComplex[ vertices, Polygon[triangles], VertexTextureCoordinates -> uvs ]}, Lighting -> "Accent", Boxed -> False, ViewVertical -> {0, 1, 0}, ViewPoint -> {0, 0, 4} ]
