From e166d0cb166a7fc01955d53932722b850acaedb3 Mon Sep 17 00:00:00 2001 From: LeonDeligny Date: Wed, 11 Mar 2026 16:08:35 +0100 Subject: [PATCH 1/2] stl to vtp --- src/ceasiompy/utils/plot.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ceasiompy/utils/plot.py b/src/ceasiompy/utils/plot.py index 1b5c1aace..98e819cbd 100644 --- a/src/ceasiompy/utils/plot.py +++ b/src/ceasiompy/utils/plot.py @@ -9,7 +9,6 @@ from cpacspy.cpacsfunctions import get_value -from stl import mesh from pathlib import Path from numpy import ndarray from cpacspy.cpacspy import CPACS @@ -331,21 +330,25 @@ def get_aircraft_mesh_data( return None try: - your_mesh = mesh.Mesh.from_file(vtp_file) + pv_mesh = pv.read(str(vtp_file)) except Exception as e: st.error(f"Cannot load 3D preview mesh file: {e=}.") return None - log.info(f"Mesh from stl at {vtp_file=}") + log.info(f"Mesh from vtp at {vtp_file=}") + + surface = pv_mesh.extract_surface().triangulate().clean() + points = np.asarray(surface.points, dtype=float) + faces = np.asarray(surface.faces.reshape(-1, 4), dtype=np.int64) - mesh_vectors = your_mesh.vectors if symmetry: - mesh_vectors = mesh_vectors[np.all(mesh_vectors[:, :, 1] >= -1e-3, axis=1)] + # Keep only triangles whose vertices all have y >= -1e-3 + tri_points = points[faces[:, 1:]] # shape (n_faces, 3, 3) + mask = np.all(tri_points[:, :, 1] >= -1e-3, axis=1) + faces = faces[mask] - triangles = mesh_vectors.reshape(-1, 3) - vertices, indices = np.unique(triangles, axis=0, return_inverse=True) - i, j, k = indices[0::3], indices[1::3], indices[2::3] - x, y, z = vertices.T + i, j, k = faces[:, 1], faces[:, 2], faces[:, 3] + x, y, z = points[:, 0], points[:, 1], points[:, 2] return ( x, y, z, i, j, k, From b1e720f9e4b416561ad2aef4e598f648a72591cc Mon Sep 17 00:00:00 2001 From: LeonDeligny Date: Wed, 11 Mar 2026 16:09:19 +0100 Subject: [PATCH 2/2] use algorithm="dataset_surface" for pyvista --- src/ceasiompy/utils/plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ceasiompy/utils/plot.py b/src/ceasiompy/utils/plot.py index 98e819cbd..7f772b176 100644 --- a/src/ceasiompy/utils/plot.py +++ b/src/ceasiompy/utils/plot.py @@ -337,7 +337,7 @@ def get_aircraft_mesh_data( log.info(f"Mesh from vtp at {vtp_file=}") - surface = pv_mesh.extract_surface().triangulate().clean() + surface = pv_mesh.extract_surface(algorithm="dataset_surface").triangulate().clean() points = np.asarray(surface.points, dtype=float) faces = np.asarray(surface.faces.reshape(-1, 4), dtype=np.int64)