Skip to content

Commit ad296b7

Browse files
authored
Merge pull request #374 from cfsengineering/ui-updates
stl to vtp
2 parents ec73241 + b1e720f commit ad296b7

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/ceasiompy/utils/plot.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from cpacspy.cpacsfunctions import get_value
1111

12-
from stl import mesh
1312
from pathlib import Path
1413
from numpy import ndarray
1514
from cpacspy.cpacspy import CPACS
@@ -331,21 +330,25 @@ def get_aircraft_mesh_data(
331330
return None
332331

333332
try:
334-
your_mesh = mesh.Mesh.from_file(vtp_file)
333+
pv_mesh = pv.read(str(vtp_file))
335334
except Exception as e:
336335
st.error(f"Cannot load 3D preview mesh file: {e=}.")
337336
return None
338337

339-
log.info(f"Mesh from stl at {vtp_file=}")
338+
log.info(f"Mesh from vtp at {vtp_file=}")
339+
340+
surface = pv_mesh.extract_surface(algorithm="dataset_surface").triangulate().clean()
341+
points = np.asarray(surface.points, dtype=float)
342+
faces = np.asarray(surface.faces.reshape(-1, 4), dtype=np.int64)
340343

341-
mesh_vectors = your_mesh.vectors
342344
if symmetry:
343-
mesh_vectors = mesh_vectors[np.all(mesh_vectors[:, :, 1] >= -1e-3, axis=1)]
345+
# Keep only triangles whose vertices all have y >= -1e-3
346+
tri_points = points[faces[:, 1:]] # shape (n_faces, 3, 3)
347+
mask = np.all(tri_points[:, :, 1] >= -1e-3, axis=1)
348+
faces = faces[mask]
344349

345-
triangles = mesh_vectors.reshape(-1, 3)
346-
vertices, indices = np.unique(triangles, axis=0, return_inverse=True)
347-
i, j, k = indices[0::3], indices[1::3], indices[2::3]
348-
x, y, z = vertices.T
350+
i, j, k = faces[:, 1], faces[:, 2], faces[:, 3]
351+
x, y, z = points[:, 0], points[:, 1], points[:, 2]
349352
return (
350353
x, y, z,
351354
i, j, k,

0 commit comments

Comments
 (0)