Skip to content

Commit

Permalink
Improve conditional trimesh use
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Dec 21, 2023
1 parent c0d7db1 commit 8726672
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions python/ncollpyde/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
import numpy as np
from numpy.typing import ArrayLike, NDArray

try:
import trimesh
except ImportError:
trimesh = None

from ._ncollpyde import (
TriMeshWrapper,
_index,
Expand Down Expand Up @@ -136,7 +131,9 @@ def __init__(
def _validate(
self, vertices: np.ndarray, triangles: np.ndarray
) -> Tuple[NDArray[np.float64], NDArray[np.uint32]]:
if trimesh:
try:
import trimesh

tm = trimesh.Trimesh(vertices, triangles, validate=True)
if not tm.is_volume:
logger.info("Mesh not valid, attempting to fix")
Expand All @@ -150,8 +147,7 @@ def _validate(
)

return tm.vertices.astype(self.dtype), tm.faces.astype(np.uint32)

else:
except ImportError:
warnings.warn("trimesh not installed; full validation not possible")

if vertices.shape[1:] != (3,):
Expand Down

0 comments on commit 8726672

Please sign in to comment.