MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / ManipulationController

Class ManipulationController

dm_control/viewer/viewer.py:460–546  ·  view source on GitHub ↗

Binds control over scene objects to user input.

Source from the content-addressed store, hash-verified

458
459
460class ManipulationController:
461 """Binds control over scene objects to user input."""
462
463 def __init__(self, viewport, camera, pointer, **unused):
464 """Instance initializer.
465
466 Args:
467 viewport: Instance of mujoco_viewer.Viewport.
468 camera: Instance of mujoco_viewer.SceneCamera.
469 pointer: A pointer that moves around the screen and is used to point at
470 bodies. Implements a single attribute - 'position' - that returns a
471 2-component vector of pointer's screen space position.
472 **unused: Other arguments, unused by this class.
473 """
474 del unused # Unused.
475 self._viewport = viewport
476 self._camera = camera
477 self._pointer = pointer
478 self._action = util.AtomicAction(self._update_action)
479 self._perturb = None
480
481 def select(self):
482 """Translates mouse double-clicks to object selection action."""
483 body_id, _ = self._camera.raycast(self._viewport, self._pointer.position)
484 if body_id >= 0:
485 self._perturb = self._camera.new_perturbation(body_id)
486 else:
487 self._perturb = None
488
489 def set_move_vertical_mode(self, enable):
490 """Begins/ends an object translation action along the vertical plane.
491
492 Args:
493 enable: A boolean flag, True begins the action, False ends it.
494 """
495 if enable:
496 self._action.begin(mujoco.mjtMouse.mjMOUSE_MOVE_V)
497 else:
498 self._action.end(mujoco.mjtMouse.mjMOUSE_MOVE_V)
499
500 def set_move_horizontal_mode(self, enable):
501 """Begins/ends an object translation action along the horizontal plane.
502
503 Args:
504 enable: A boolean flag, True begins the action, False ends it.
505 """
506 if enable:
507 self._action.begin(mujoco.mjtMouse.mjMOUSE_MOVE_H)
508 else:
509 self._action.end(mujoco.mjtMouse.mjMOUSE_MOVE_H)
510
511 def set_rotate_mode(self, enable):
512 """Begins/ends an object rotation action.
513
514 Args:
515 enable: A boolean flag, True begins the action, False ends it.
516 """
517 if enable:

Callers 1

initializeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…