Repository: Genesis-Embodied-AI/Genesis
File: genesis/ext/pyrender/viewer.py (Python)

Code before:

        if self._default_persp_cam is None:
            self._default_persp_cam = PerspectiveCamera(yfov=np.pi / 3.0, znear=znear, zfar=zfar)
        if self._default_orth_cam is None:
            xmag = ymag = self.scene.scale
            if self.scene.scale == 0:
                xmag = ymag = 1.0
            self._default_orth_cam = OrthographicCamera(xmag=xmag, ymag=ymag, znear=znear, zfar=zfar)
        if self._default_camera_pose is None:
            self._default_camera_pose = self._compute_initial_camera_pose()

        # Pick camera
        if self.viewer_flags["use_perspective_cam"]:
            camera = self._default_persp_cam
        else:
            camera = self._default_orth_cam

        self._camera_node = Node(matrix=self._default_camera_pose, camera=camera)
        self.scene.add_node(self._camera_node)
        self.scene.main_camera_node = self._camera_node
        self._reset_view()

        # Setup mouse interaction

        # Note: can't import ViewerIntaction at file scope while genesis.engine.scene is still being imported
        from genesis.ext.pyrender.interaction.viewer_interaction import ViewerInteraction
        from genesis.ext.pyrender.interaction.viewer_interaction_base import ViewerInteractionBase

        # Note: context.scene is genesis.engine.scene.Scene
        # Note: context._scene is genesis.ext.pyrender.scene.Scene
        self.viewer_interaction = (
            ViewerInteraction(self._camera_node, context.scene, viewport_size, camera.yfov)
            if use_viewer_interaction
            else ViewerInteractionBase()
        )

        #######################################################################
        # Initialize OpenGL context and renderer
        #######################################################################
        self._renderer = Renderer(
            self._viewport_size[0], self._viewport_size[1], context.jit, self.render_flags["point_size"]
        )
        self._is_active = True

        self.pending_offscreen_camera = None
        self.offscreen_result = None

        self.pending_buffer_updates = {}

        # Starting the viewer would raise an exception if the OpenGL context is invalid for some reason. This exception
        # must be caught in order to implement some fallback mechanism. One may want to start the viewer from the main

Review comment (suggestion):
Just use relative import and move them back on top (after all non-relative imports). It should work:
```python
from .interaction.viewer_interaction import ViewerInteraction
from .interaction.viewer_interaction_base import ViewerInteractionBase
```

Code after:
        if self._default_persp_cam is None:
            self._default_persp_cam = PerspectiveCamera(yfov=np.pi / 3.0, znear=znear, zfar=zfar)
        if self._default_orth_cam is None:
            xmag = ymag = self.scene.scale
            if self.scene.scale == 0:
                xmag = ymag = 1.0
            self._default_orth_cam = OrthographicCamera(xmag=xmag, ymag=ymag, znear=znear, zfar=zfar)
        if self._default_camera_pose is None:
            self._default_camera_pose = self._compute_initial_camera_pose()

        # Pick camera
        if self.viewer_flags["use_perspective_cam"]:
            camera = self._default_persp_cam
        else:
            camera = self._default_orth_cam

        self._camera_node = Node(matrix=self._default_camera_pose, camera=camera)
        self.scene.add_node(self._camera_node)
        self.scene.main_camera_node = self._camera_node
        self._reset_view()

        # Setup mouse interaction

        # Note: context.scene is genesis.engine.scene.Scene
        # Note: context._scene is genesis.ext.pyrender.scene.Scene
        self.viewer_interaction = (
            ViewerInteraction(self._camera_node, context.scene, viewport_size, camera.yfov)
            if enable_interaction
            else ViewerInteractionBase()
        )

        #######################################################################
        # Initialize OpenGL context and renderer
        #######################################################################
        self._renderer = Renderer(
            self._viewport_size[0], self._viewport_size[1], context.jit, self.render_flags["point_size"]
        )
        self._is_active = True

        self.pending_offscreen_camera = None
        self.offscreen_result = None

        self.pending_buffer_updates = {}

        # Starting the viewer would raise an exception if the OpenGL context is invalid for some reason. This exception
        # must be caught in order to implement some fallback mechanism. One may want to start the viewer from the main
        # thread while the running loop would be running on a background thread. However, this approach is not possible
        # because all access to the OpenGL context must be done from the thread that created it in the first place. As
        # a result, the logic for catching an invalid OpenGL context must be implemented at the thread-level.
        self.auto_start = auto_start
        if self._run_in_thread: