nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mikedh/trimesh
Pull request #1882 (2023-03-29 19:02:47)

Fix ply uv export
Hey,

while working on the same project as mentioned here https://github.com/mikedh/trimesh/issues/1880 , I noticed that the PLY export ignores the texture coordinates. This PR should fix that.


Patch:
diff --git a/trimesh/exchange/ply.py b/trimesh/exchange/ply.py
index 8b327acd..b1e36660 100644
--- a/trimesh/exchange/ply.py
+++ b/trimesh/exchange/ply.py
@@ -263,6 +263,10 @@ def export_ply(mesh,
     # if we want to include mesh attributes in the export
     if include_attributes:
         if hasattr(mesh, 'vertex_attributes'):
+            # make sure to export texture coordinates as well
+            if hasattr(mesh, "visual") and hasattr(mesh.visual, "uv"):
+                mesh.vertex_attributes["s"] = mesh.visual.uv[:, 0]
+                mesh.vertex_attributes["t"] = mesh.visual.uv[:, 1]
             _assert_attributes_valid(mesh.vertex_attributes)
         if hasattr(mesh, 'face_attributes'):
             _assert_attributes_valid(mesh.face_attributes)


Test patch:
diff --git a/tests/test_ply.py b/tests/test_ply.py
index ce926089..a37e4ce9 100644
--- a/tests/test_ply.py
+++ b/tests/test_ply.py
@@ -199,6 +199,22 @@ class PlyTest(g.unittest.TestCase):
             m = g.get_mesh(mesh_name)
             assert hasattr(m, 'visual') and hasattr(m.visual, 'uv')
             assert m.visual.uv.shape[0] == m.vertices.shape[0]
+    
+    def test_uv_export(self):
+        m = g.get_mesh("fuze.ply")
+        assert hasattr(m, 'visual') and hasattr(m.visual, 'uv')
+        assert m.visual.uv.shape[0] == m.vertices.shape[0]
+
+        # create empty file to export to
+        f = g.tempfile.NamedTemporaryFile(suffix='.ply', delete=False)
+        f.close()
+
+        # export should contain the uv data
+        m.export(f.name)
+        m2 = g.trimesh.load(f.name)
+
+        assert hasattr(m2, 'visual') and hasattr(m2.visual, 'uv')
+        assert g.np.allclose(m.visual.uv, m2.visual.uv)
 
     def test_fix_texture(self):
         # test loading of face indices when uv-coordinates are also contained
Repository: mikedh/trimesh
Pull request #2196 (2024-03-28 15:31:06)

Fix broken solid name in ASCII STL mesh export
Exporting a mesh in ASCII STL format results in the placeholder `{name}` to be printed as solid name instead of the `name` metadata, due to a typo. This PR fixes the typo and introduces a simple unit test.


Patch:
diff --git a/trimesh/exchange/stl.py b/trimesh/exchange/stl.py
index d5e5e47a..a82a6d0d 100644
--- a/trimesh/exchange/stl.py
+++ b/trimesh/exchange/stl.py
@@ -309,7 +309,7 @@ def export_stl_ascii(mesh) -> str:
         name = ""
 
     # concatenate the header, data, and footer, and a new line
-    return "\n".join(["solid {name}", formatter.format(*blob.reshape(-1)), "endsolid\n"])
+    return "\n".join([f"solid {name}", formatter.format(*blob.reshape(-1)), "endsolid\n"])
 
 
 _stl_loaders = {"stl": load_stl, "stl_ascii": load_stl}


Test patch:
diff --git a/tests/test_stl.py b/tests/test_stl.py
index 5b9aa7a2..bf82e41f 100644
--- a/tests/test_stl.py
+++ b/tests/test_stl.py
@@ -72,6 +72,11 @@ class STLTests(g.unittest.TestCase):
         assert len(s.geometry) == 2
         assert set(s.geometry.keys()) == {"bodyA", "bodyB"}
 
+    def test_ascii_solid_name(self):
+        mesh = g.trimesh.creation.icosphere(subdivisions=1, radius=1.0)
+        mesh.metadata = {"name": "solid_A"}
+        assert g.trimesh.exchange.stl.export_stl_ascii(mesh).splitlines()[0] == "solid solid_A"
+
     def test_empty(self):
         # demo files to check
         empty_files = ["stl_empty_ascii.stl", "stl_empty_bin.stl"]