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

Method select

dm_control/mujoco/engine.py:948–1000  ·  view source on GitHub ↗

Returns bodies and geoms visible at given coordinates in the frame. Args: cursor_position: A `tuple` containing x and y coordinates, normalized to between 0 and 1, and where (0, 0) is bottom-left. Returns: A `Selected` namedtuple. Fields are None if nothing is selected

(self, cursor_position)

Source from the content-addressed store, hash-verified

946 return self._physics.contexts.gl.to_pixels(image)
947
948 def select(self, cursor_position):
949 """Returns bodies and geoms visible at given coordinates in the frame.
950
951 Args:
952 cursor_position: A `tuple` containing x and y coordinates, normalized to
953 between 0 and 1, and where (0, 0) is bottom-left.
954
955 Returns:
956 A `Selected` namedtuple. Fields are None if nothing is selected.
957 """
958 self.update()
959 aspect_ratio = self._width / self._height
960 cursor_x, cursor_y = cursor_position
961 pos = np.empty(3, np.double)
962 geom_id_arr = np.intc([-1])
963 flex_id_arr = np.intc([-1])
964 skin_id_arr = np.intc([-1])
965 body_id = mujoco.mjv_select(self._physics.model.ptr, self._physics.data.ptr,
966 self._scene_option.ptr, aspect_ratio, cursor_x,
967 cursor_y, self._scene.ptr, pos, geom_id_arr,
968 flex_id_arr, skin_id_arr)
969 [geom_id] = geom_id_arr
970 [flex_id] = flex_id_arr
971 [skin_id] = skin_id_arr
972
973 # Validate IDs
974 if body_id != -1:
975 assert 0 <= body_id < self._physics.model.nbody
976 else:
977 body_id = None
978 if geom_id != -1:
979 assert 0 <= geom_id < self._physics.model.ngeom
980 else:
981 geom_id = None
982 if flex_id != -1:
983 assert 0 <= flex_id < self._physics.model.nflex
984 else:
985 flex_id = None
986 if skin_id != -1:
987 assert 0 <= skin_id < self._physics.model.nskin
988 else:
989 skin_id = None
990
991 if all(id_ is None for id_ in (body_id, geom_id, skin_id)):
992 pos = None
993
994 return Selected(
995 body=body_id,
996 geom=geom_id,
997 flex=flex_id,
998 skin=skin_id,
999 world_position=pos,
1000 )
1001
1002
1003class MovableCamera(Camera):

Callers 1

testCameraSelectionMethod · 0.95

Calls 1

updateMethod · 0.95

Tested by 1

testCameraSelectionMethod · 0.76