Skip to content

Commit

Permalink
mesh2visual: check if scipy is present before asking trimesh for normals
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Aug 28, 2024
1 parent b0f9155 commit 4b41bd2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion octarine/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import numpy as np
import trimesh as tm

from importlib.util import find_spec

from . import config, utils

logger = config.get_logger(__name__)
Expand Down Expand Up @@ -579,8 +581,11 @@ def trimesh2gfx(mesh, color=None, alpha=None, use_material=True):
kwargs = dict(
positions=np.ascontiguousarray(mesh.vertices, dtype="f4"),
indices=np.ascontiguousarray(mesh.faces, dtype="i4"),
normals=np.ascontiguousarray(mesh.vertex_normals, dtype="f4"),
)
# trimesh needs scipy to compute normals
if find_spec("scipy"):
kwargs['normals'] = np.ascontiguousarray(mesh.vertex_normals, dtype="f4")

if mesh.visual.kind == "texture" and getattr(mesh.visual, "uv", None) is not None:
# convert the uv coordinates from opengl to wgpu conventions.
# wgpu uses the D3D and Metal coordinate systems.
Expand Down

0 comments on commit 4b41bd2

Please sign in to comment.