|
9 | 9 |
|
10 | 10 | from cpacspy.cpacsfunctions import get_value |
11 | 11 |
|
12 | | -from stl import mesh |
13 | 12 | from pathlib import Path |
14 | 13 | from numpy import ndarray |
15 | 14 | from cpacspy.cpacspy import CPACS |
@@ -331,21 +330,25 @@ def get_aircraft_mesh_data( |
331 | 330 | return None |
332 | 331 |
|
333 | 332 | try: |
334 | | - your_mesh = mesh.Mesh.from_file(vtp_file) |
| 333 | + pv_mesh = pv.read(str(vtp_file)) |
335 | 334 | except Exception as e: |
336 | 335 | st.error(f"Cannot load 3D preview mesh file: {e=}.") |
337 | 336 | return None |
338 | 337 |
|
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) |
340 | 343 |
|
341 | | - mesh_vectors = your_mesh.vectors |
342 | 344 | 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] |
344 | 349 |
|
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] |
349 | 352 | return ( |
350 | 353 | x, y, z, |
351 | 354 | i, j, k, |
|
0 commit comments