Skip to content

Commit

Permalink
WIP: Further speedup.
Browse files Browse the repository at this point in the history
  • Loading branch information
duburcqa committed Jul 15, 2024
1 parent f2d2875 commit ebb27a3
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions python/jiminy_py/src/jiminy_py/viewer/panda3d/panda3d_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ebb27a3

Please sign in to comment.