From 4f553d7324d93ac630c1ee64478f07b7915a3478 Mon Sep 17 00:00:00 2001 From: Kashu7100 Date: Thu, 26 Dec 2024 03:52:36 -0500 Subject: [PATCH] avoid trimesh import failure when pyrender has issue --- genesis/vis/rasterizer_context.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/genesis/vis/rasterizer_context.py b/genesis/vis/rasterizer_context.py index f5a79392..52b2c503 100644 --- a/genesis/vis/rasterizer_context.py +++ b/genesis/vis/rasterizer_context.py @@ -4,9 +4,10 @@ import genesis.utils.geom as gu import genesis.utils.mesh as mu import genesis.utils.particle as pu +from genesis.ext import trimesh try: - from genesis.ext import pyrender, trimesh + from genesis.ext import pyrender from genesis.ext.pyrender.jit_render import JITRenderer except Exception as e: print(f"[Error]: {e}\n") @@ -199,14 +200,13 @@ def update_link_frame(self, buffer_updates): for link in links: link_T = gu.trans_quat_to_T(links_pos[link.idx], links_quat[link.idx]) - buffer_updates[self._scene.get_buffer_id(self.link_frame_nodes[link.uid], "model")] = ( - link_T.transpose([0, 2, 1]) - ) + buffer_updates[ + self._scene.get_buffer_id(self.link_frame_nodes[link.uid], "model") + ] = link_T.transpose([0, 2, 1]) def on_tool(self): if self.sim.tool_solver.is_active(): for tool_entity in self.sim.tool_solver.entities: - if tool_entity.mesh is not None: mesh = trimesh.Trimesh( tool_entity.mesh.init_vertices_np, @@ -411,9 +411,9 @@ def update_mpm(self, buffer_updates): tfs = np.tile(np.eye(4), (mpm_entity.n_particles, 1, 1)) tfs[:, :3, 3] = particles_all[mpm_entity.particle_start : mpm_entity.particle_end] - buffer_updates[self._scene.get_buffer_id(self.static_nodes[mpm_entity.uid], "model")] = ( - tfs.transpose([0, 2, 1]) - ) + buffer_updates[ + self._scene.get_buffer_id(self.static_nodes[mpm_entity.uid], "model") + ] = tfs.transpose([0, 2, 1]) elif mpm_entity.surface.vis_mode == "visual": mpm_entity._vmesh.verts = vverts_all[mpm_entity.vvert_start : mpm_entity.vvert_end] @@ -476,9 +476,9 @@ def update_sph(self, buffer_updates): tfs = np.tile(np.eye(4), (sph_entity.n_particles, 1, 1)) tfs[:, :3, 3] = particles_all[sph_entity.particle_start : sph_entity.particle_end] - buffer_updates[self._scene.get_buffer_id(self.static_nodes[sph_entity.uid], "model")] = ( - tfs.transpose([0, 2, 1]) - ) + buffer_updates[ + self._scene.get_buffer_id(self.static_nodes[sph_entity.uid], "model") + ] = tfs.transpose([0, 2, 1]) def on_pbd(self): if self.sim.pbd_solver.is_active(): @@ -556,9 +556,9 @@ def update_pbd(self, buffer_updates): tfs = np.tile(np.eye(4), (pbd_entity.n_particles, 1, 1)) tfs[:, :3, 3] = particles_all[pbd_entity.particle_start : pbd_entity.particle_end] - buffer_updates[self._scene.get_buffer_id(self.static_nodes[pbd_entity.uid], "model")] = ( - tfs.transpose([0, 2, 1]) - ) + buffer_updates[ + self._scene.get_buffer_id(self.static_nodes[pbd_entity.uid], "model") + ] = tfs.transpose([0, 2, 1]) elif self.render_particle_as == "tet": new_verts = mu.transform_tets_mesh_verts( @@ -574,7 +574,6 @@ def update_pbd(self, buffer_updates): buffer_updates[self._scene.get_buffer_id(node, "normal")] = normal_data elif pbd_entity.surface.vis_mode == "visual": - vverts = vverts_all[pbd_entity.vvert_start : pbd_entity.vvert_end] node = self.static_nodes[pbd_entity.uid] update_data = self._scene.reorder_vertices(node, vverts)