From ebb27a3b3022a0b9260a215fa7ef5b3e08c17a04 Mon Sep 17 00:00:00 2001 From: Alexis Duburcq <alexis.duburcq@gmail.com> Date: Mon, 15 Jul 2024 16:13:12 +0200 Subject: [PATCH] WIP: Further speedup. --- .../viewer/panda3d/panda3d_visualizer.py | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/python/jiminy_py/src/jiminy_py/viewer/panda3d/panda3d_visualizer.py b/python/jiminy_py/src/jiminy_py/viewer/panda3d/panda3d_visualizer.py index ae9c63645..a58ed32cc 100644 --- a/python/jiminy_py/src/jiminy_py/viewer/panda3d/panda3d_visualizer.py +++ b/python/jiminy_py/src/jiminy_py/viewer/panda3d/panda3d_visualizer.py @@ -1019,9 +1019,9 @@ def move_orbital_camera_task(self, def _make_light_ambient(self, color: Tuple3FType) -> NodePath: """Patched to fix wrong color alpha. """ - node = super()._make_light_ambient(color) - node.get_node(0).set_color((*color, 1.0)) - return node + light = super()._make_light_ambient(color) + light.node().set_color((*color, 1.0)) + return light def _make_light_direct(self, index: int, @@ -1031,9 +1031,9 @@ def _make_light_direct(self, ) -> NodePath: """Patched to fix wrong color alpha. """ - light_path = super()._make_light_direct(index, color, pos, target) - light_path.get_node(0).set_color((*color, 1.0)) - return light_path + light = super()._make_light_direct(index, color, pos, target) + light.node().set_color((*color, 1.0)) + return light def _make_axes(self) -> NodePath: model = GeomNode('axes') @@ -1094,7 +1094,7 @@ def _make_floor(self, # Adjust frustum of the lights to project shadow over the whole scene for light_path in self._lights[1:]: bmin, bmax = node.get_tight_bounds(light_path) - lens = light_path.get_node(0).get_lens() + lens = light_path.node().get_lens() lens.set_film_offset((bmin.xz + bmax.xz) * 0.5) lens.set_film_size(bmax.xz - bmin.xz) lens.set_near_far(bmin.y, bmax.y) @@ -1856,16 +1856,30 @@ def get_screenshot(self, else: buffer = self._user_buffers[camera_name] + # Get frame as raw texture + texture = buffer.get_texture() + is_depth_map = texture.format == Texture.F_depth_component32 + + # Disable shadow casting for depth map computation since it is useless + shadow_buffers = [] + if is_depth_map: + for light in self._lights: + if not light.node().is_ambient_light(): + shadow_buffer = light.node().getShadowBuffer(self.win.gsg) + if shadow_buffer is not None: + shadow_buffer.active = False + shadow_buffers.append(shadow_buffer) + # Refresh the scene buffer.trigger_copy() buffer.set_one_shot(True) self.graphics_engine.render_frame() - # Get frame as raw texture - texture = buffer.get_texture() + # Restore shadow casting + for shadow_buffer in shadow_buffers: + shadow_buffer.active = True # Extract raw array buffer from texture - is_depth_map = texture.format == Texture.F_depth_component32 if is_depth_map: image = texture.get_ram_image() else: