From 7d62defb7d5fd65ee4603fda08809c6dfa73d82e Mon Sep 17 00:00:00 2001 From: Alexis DUBURCQ Date: Tue, 8 Jun 2021 14:53:16 +0200 Subject: [PATCH] [python/viewer] Hot fix viewer issues. (#349) Co-authored-by: Alexis Duburcq --- CMakeLists.txt | 2 +- python/jiminy_py/src/jiminy_py/simulator.py | 3 ++- .../viewer/panda3d/panda3d_visualizer.py | 8 +++++++ .../jiminy_py/src/jiminy_py/viewer/viewer.py | 23 +++++++++++-------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ea3da8c0..c26d11f17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) # Set the build version -set(BUILD_VERSION 1.6.19) +set(BUILD_VERSION 1.6.20) # Set compatibility if(CMAKE_VERSION VERSION_GREATER "3.11.0") diff --git a/python/jiminy_py/src/jiminy_py/simulator.py b/python/jiminy_py/src/jiminy_py/simulator.py index d964aba08..c850eaab8 100644 --- a/python/jiminy_py/src/jiminy_py/simulator.py +++ b/python/jiminy_py/src/jiminy_py/simulator.py @@ -532,13 +532,14 @@ def render(self, # Set the camera pose if requested if camera_xyzrpy is not None: self.viewer.set_camera_transform(*camera_xyzrpy) + self.viewer.wait(require_client=False) # Make sure the graphical window is open if required if not return_rgb_array: self.viewer.open_gui() # Try refreshing the viewer - self.viewer.refresh(wait=True) + self.viewer.refresh() # Compute rgb array if needed if return_rgb_array: 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 f3273b116..1257ad865 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 @@ -1129,6 +1129,10 @@ def get_framerate(self) -> Optional[float]: return self.framerate def save_screenshot(self, filename: Optional[str] = None) -> bool: + # Refresh the scene if no graphical window is available + if any(isinstance(win, GraphicsWindow) for win in self.winList): + self.step() + # Generate filename based on current time if not provided if filename is None: template = 'screenshot-%Y-%m-%d-%H-%M-%S.png' @@ -1162,6 +1166,10 @@ def get_screenshot(self, scheduler. The framerate limit must be disable manually to avoid such limitation. """ + # Refresh the scene if no graphical window is available + if any(isinstance(win, GraphicsWindow) for win in self.winList): + self.step() + # Capture frame as raw texture texture = self.buff.get_screenshot() diff --git a/python/jiminy_py/src/jiminy_py/viewer/viewer.py b/python/jiminy_py/src/jiminy_py/viewer/viewer.py index 2020611ba..fba8f5e4c 100644 --- a/python/jiminy_py/src/jiminy_py/viewer/viewer.py +++ b/python/jiminy_py/src/jiminy_py/viewer/viewer.py @@ -1391,7 +1391,7 @@ def get_camera_transform(self) -> Tuple[Tuple3FType, Tuple3FType]: rot = pin.Quaternion(*quat).matrix() rpy = matrixToRpy(rot @ CAMERA_INV_TRANSFORM_PANDA3D.T) else: - xyz, rpy = Viewer._camera_xyzrpy + xyz, rpy = deepcopy(Viewer._camera_xyzrpy) return xyz, rpy @__must_be_open @@ -1421,25 +1421,28 @@ def set_camera_transform(self, How to apply the transform: - **None:** absolute. - - **'camera':** relative to the current camera pose. + - **'camera':** relative to current camera pose. - **other:** relative to a robot frame, not accounting for the rotation of the frame during travalling. It supports both frame name and index in model. :param wait: Whether or not to wait for rendering to finish. """ # Handling of position and rotation arguments - if position is None or rotation is None: - position_current, rotation_current = self.get_camera_transform() - position = np.asarray(position or position_current) - rotation = np.asarray(rotation or rotation_current) + if position is None or rotation is None or relative == 'camera': + position_camera, rotation_camera = self.get_camera_transform() + if position is None: + position = position_camera + if rotation is None: + rotation = rotation_camera + position = np.asarray(position) + rotation = np.asarray(rotation) # Compute associated rotation matrix rotation_mat = rpyToMatrix(rotation) # Compute the relative transformation if necessary if relative == 'camera': - H_orig = SE3(rpyToMatrix( - Viewer._camera_xyzrpy[1]), Viewer._camera_xyzrpy[0]) + H_orig = SE3(rpyToMatrix(rotation_camera), position_camera) elif relative is not None: # Get the body position, not taking into account the rotation if isinstance(relative, str): @@ -1477,7 +1480,7 @@ def set_camera_transform(self, translate=position_meshcat, angles=rotation_meshcat)) # Backup updated camera pose - Viewer._camera_xyzrpy = deepcopy([position, rotation]) + Viewer._camera_xyzrpy = [position, rotation] # Wait for the backend viewer to finish rendering if requested if wait: @@ -2118,7 +2121,7 @@ def refresh(self, self.set_camera_lookat(np.zeros(3), frame) if Viewer._camera_motion is not None: - self.set_camera_transform() + self.set_camera_transform(*Viewer._camera_xyzrpy) # Update pose, color and scale of the markers, if any if Viewer.backend.startswith('panda3d'):