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

Class CameraSelector

dm_control/viewer/viewer.py:281–337  ·  view source on GitHub ↗

Binds camera behavior to user input.

Source from the content-addressed store, hash-verified

279
280
281class CameraSelector:
282 """Binds camera behavior to user input."""
283
284 def __init__(self, model, camera, free_camera, **unused):
285 """Instance initializer.
286
287 Args:
288 model: Instance of MjModel.
289 camera: Instance of SceneCamera.
290 free_camera: Instance of FreeCameraController.
291 **unused: Other arguments, not used by this class.
292 """
293 del unused # Unused.
294 self._model = model
295 self._camera = camera
296 self._free_ctrl = free_camera
297
298 self._camera_idx = -1
299 self._active_ctrl = self._free_ctrl
300
301 def select_previous(self):
302 """Cycles to the previous scene camera."""
303 self._camera_idx -= 1
304 if not self._model.ncam or self._camera_idx < -1:
305 self._camera_idx = self._model.ncam - 1
306 self._commit_selection()
307
308 def select_next(self):
309 """Cycles to the next scene camera."""
310 self._camera_idx += 1
311 if not self._model.ncam or self._camera_idx >= self._model.ncam:
312 self._camera_idx = -1
313 self._commit_selection()
314
315 def escape(self) -> None:
316 """Unconditionally switches to the free camera."""
317 self._camera_idx = -1
318 self._commit_selection()
319
320 def _commit_selection(self):
321 """Selects a controller that should go with the selected camera."""
322 if self._camera_idx < 0:
323 self._activate(self._free_ctrl)
324 else:
325 self._camera.set_fixed_mode(self._camera_idx)
326 self._activate(None)
327
328 def _activate(self, controller):
329 """Activates a sub-controller."""
330 if controller == self._active_ctrl:
331 return
332
333 if self._active_ctrl is not None:
334 self._active_ctrl.deactivate()
335 self._active_ctrl = controller
336 if self._active_ctrl is not None:
337 self._active_ctrl.activate()
338

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…