Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug calling callback #38

Open
nashmit opened this issue Aug 25, 2022 · 1 comment
Open

bug calling callback #38

nashmit opened this issue Aug 25, 2022 · 1 comment

Comments

@nashmit
Copy link

nashmit commented Aug 25, 2022

When you define your "callback" function the desired behavior is to get it triggered once every "callback_period" times.
What happens instead is that it also gets triggered by any control applied in the window ( e.g. mouse pressed, key pressed, etc ) hence, the "callback" function gets activated more times than it should be.

urdf_path = "robot-assets/urdfs/robots/franka_panda/panda.urdf"


class Viewer(viewer.windowed.SceneViewer):
    def __init__(self, scene, callback, callback_period, start_loop, profile):
        super().__init__(scene,
                         callback=callback,
                         callback_period=callback_period,
                         start_loop=start_loop,
                         profile=profile)

Scene=yourdfpy.URDF.load(
    urdf_path,
    load_meshes=True,
    #load_collision_meshes=True,
    #build_collision_scene_graph=True,
    build_scene_graph=True
)

def updateScene(scene):
    cfg = Scene.cfg
    cfg[1]=cfg[1]+3.14/32
    Scene.update_cfg(cfg)
    scene = Scene.scene
    pass

view = Viewer(Scene.scene,
              callback=updateScene,
              callback_period=5,
              start_loop=True,
              profile=False)

@nashmit
Copy link
Author

nashmit commented Aug 25, 2022

Possible quick fix ( I would recommend redesign for this functionality by decoupling the "callback" function from "on_draw" )

in: pyglet\app\base.py:

        dt = self.clock.update_time()
        redraw_all = self.clock.call_scheduled_functions(dt)

        # Redraw all windows
        for window in app.windows:
            if redraw_all or (window._legacy_invalid and window.invalid):
                window.switch_to()
                if redraw_all:                                                    ## this line was added
                    window.redraw_all = True                           ## this line was added
                else:                                                                 ## this line was added
                    window.redraw_all = False                          ## this line was added
                window.dispatch_event('on_draw')
                window.flip()
                window._legacy_invalid = False

        # Update timout
        return self.clock.get_sleep_time(True)

in trimesh\viewer\windowed.py:

    def _update_meshes(self):
        # call the callback if specified
        if self.callback is not None:
            if hasattr(self,"redraw_all") and self.redraw_all:              ## this line was added
                self.callback(self.scene)                                              ## this line was added
            self._update_vertex_list()
            self._update_perspective(self.width, self.height)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant