Skip to content

Commit

Permalink
Update Magnum to latest (#2521)
Browse files Browse the repository at this point in the history
* datatool: make lowercase again.

Seems like an accident made in 94255f7
(September 2021).

* datatool: port away from assimp.

Using SceneTools to perform a transformation and concatenation of all
meshes in the file instead. The copy back to the ancient habitat
MeshData structure is what makes this longer than it could be but I
don't want to touch that as well now.

With this, the Assimp::Assimp CMake target doesn't need to be found (or
made) anymore, it was additionally errorneously linked to the bindings as
well.

* Update to latest Magnum.

The applications got an overhaul for first-class touch and pen support,
meaning the events are renamed now. Since GLFW doesn't support touch or
pen, nothing else needs to be done really.

Besides that, Magnum itself bundles the Find modules, meaning they don't
need to have copies here anymore, unless used directly such as
FindBullet.

* CMake: include 3rd party dependencies as SYSTEM to reduce warning spam.

* refactor viewer.py applications for new Application Pointer API updates

---------

Co-authored-by: Alexander Clegg <[email protected]>
  • Loading branch information
mosra and aclegg3 authored Jan 8, 2025
1 parent dba25a0 commit 238c90b
Show file tree
Hide file tree
Showing 22 changed files with 977 additions and 1,012 deletions.
49 changes: 25 additions & 24 deletions examples/motion_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ def key_press_event(self, event: Application.KeyEvent) -> None:
"""

key = event.key
pressed = Application.KeyEvent.Key
mod = Application.InputEvent.Modifier
pressed = Application.Key
mod = Application.Modifier

if key == pressed.F:
if event.modifiers == mod.SHIFT:
if event.modifiers & mod.SHIFT:
self.remove_selector_obj()
self.fm_demo.hide_model()
logger.info("Command: hide model")
Expand All @@ -233,7 +233,7 @@ def key_press_event(self, event: Application.KeyEvent) -> None:
path_time=random.uniform(0.0, 10.0)
)
elif not self.sim.pathfinder.is_loaded:
logger.warn("Warning: pathfinder not initialized, recompute navmesh")
logger.warning("Warning: pathfinder not initialized, recompute navmesh")
else:
logger.info("Command: shortest path between two random points")
self.fm_demo.load_model()
Expand All @@ -244,7 +244,7 @@ def key_press_event(self, event: Application.KeyEvent) -> None:
return

elif key == pressed.U:
if event.modifiers == mod.SHIFT:
if event.modifiers & mod.SHIFT:
self.perpetual = not self.perpetual
logger.info(
f"Command: perpetual motion generation set to {self.perpetual}"
Expand Down Expand Up @@ -303,7 +303,7 @@ def key_press_event(self, event: Application.KeyEvent) -> None:

elif key == pressed.SPACE:
if not self.sim.config.sim_cfg.enable_physics:
logger.warn("Warning: physics was not enabled during setup")
logger.warning("Warning: physics was not enabled during setup")
else:
self.simulating = not self.simulating
logger.info(f"Command: physics simulating set to {self.simulating}")
Expand All @@ -314,11 +314,11 @@ def key_press_event(self, event: Application.KeyEvent) -> None:
return

elif key == pressed.P:
if event.modifiers == mod.CTRL:
if event.modifiers & mod.CTRL:
logger.info(f"Last file loaded: {self.fm_demo.last_metadata_file}")
elif event.modifiers == mod.SHIFT:
elif event.modifiers & mod.SHIFT:
if self.fm_demo.last_metadata_file is None:
logger.warn("Warning: No previous file loaded.")
logger.warning("Warning: No previous file loaded.")
else:
self.fm_demo.save_metadata(self.fm_demo.last_metadata_file)
else:
Expand All @@ -334,11 +334,11 @@ def key_press_event(self, event: Application.KeyEvent) -> None:
self.fm_demo.save_metadata(fn)

elif key == pressed.L:
if event.modifiers == mod.CTRL:
if event.modifiers & mod.CTRL:
logger.info(f"Last file loaded: {self.fm_demo.last_metadata_file}")
elif event.modifiers == mod.SHIFT:
elif event.modifiers & mod.SHIFT:
if self.fm_demo.last_metadata_file is None:
logger.warn("Warning: No previous file loaded.")
logger.warning("Warning: No previous file loaded.")
else:
self.fm_demo.fetch_metadata(self.fm_demo.last_metadata_file)
else:
Expand All @@ -352,7 +352,7 @@ def key_press_event(self, event: Application.KeyEvent) -> None:

elif key == pressed.PERIOD:
if self.simulating:
logger.warn("Warning: physic simulation already running")
logger.warning("Warning: physic simulation already running")
else:
self.simulate_single_step = True
logger.info("Command: physics step taken")
Expand All @@ -363,14 +363,13 @@ def key_press_event(self, event: Application.KeyEvent) -> None:

super().key_press_event(event)

def mouse_press_event(self, event: Application.MouseEvent) -> None:
def pointer_press_event(self, event: Application.PointerEvent) -> None:
"""
Handles `Application.MouseEvent`. When in GRAB mode, click on
Handles `Application.PointerEvent`. When in GRAB mode, click on
objects to drag their position. (right-click for fixed constraints).
When in MOTION mode select Fairmotion characters with left-click,
place them in a new location with right-click.
"""
button = Application.MouseEvent.Button
physics_enabled = self.sim.get_physics_simulation_library()

# if interactive mode is True -> MOTION MODE
Expand All @@ -381,8 +380,7 @@ def mouse_press_event(self, event: Application.MouseEvent) -> None:

if raycast_results.has_hits():
hit_info = raycast_results.hits[0]

if event.button == button.LEFT:
if event.pointers & Application.Pointer.MOUSE_LEFT:
if self.fm_demo.belongs_to(hit_info.object_id):
if not self.fm_demo.model:
self.fm_demo.load_model()
Expand All @@ -391,17 +389,20 @@ def mouse_press_event(self, event: Application.MouseEvent) -> None:
else:
self.remove_selector_obj()

elif event.button == button.RIGHT and self.selected_mocap_char:
elif (
event.pointers & Application.Pointer.MOUSE_RIGHT
and self.selected_mocap_char
):
point = hit_info.point
self.fm_demo.set_transform_offsets(translate_offset=point)
self.create_selector_obj(self.fm_demo)
# end has raycast hit

super().mouse_press_event(event)
super().pointer_press_event(event)

def mouse_scroll_event(self, event: Application.MouseScrollEvent) -> None:
def scroll_event(self, event: Application.ScrollEvent) -> None:
"""
Handles `Application.MouseScrollEvent`. When in LOOK mode, enables camera
Handles `Application.ScrollEvent`. When in LOOK mode, enables camera
zooming (fine-grained zoom using shift). When in GRAB mode, adjusts the depth
of the grabber's object. (larger depth change rate using shift). When in MOTION
mode, rotate them about the floor-normal axis with the scroll wheel. (fine-grained
Expand All @@ -420,7 +421,7 @@ def mouse_scroll_event(self, event: Application.MouseScrollEvent) -> None:
return

# use shift to scale action response
shift_pressed = event.modifiers == Application.InputEvent.Modifier.SHIFT
shift_pressed = bool(event.modifiers & Application.Modifier.SHIFT)

if (
self.mouse_interaction == MouseMode.MOTION
Expand All @@ -436,7 +437,7 @@ def mouse_scroll_event(self, event: Application.MouseScrollEvent) -> None:
)
self.create_selector_obj(self.fm_demo)

super().mouse_scroll_event(event)
super().pointer_scroll_event(event)

def cycle_mouse_mode(self):
"""
Expand Down
47 changes: 26 additions & 21 deletions examples/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def __init__(self, sim_settings: Dict[str, Any]) -> None:
self.cached_urdf = ""

# set up our movement map
key = Application.KeyEvent.Key

key = Application.Key
self.pressed = {
key.UP: False,
key.DOWN: False,
Expand All @@ -98,7 +99,6 @@ def __init__(self, sim_settings: Dict[str, Any]) -> None:
}

# set up our movement key bindings map
key = Application.KeyEvent.Key
self.key_to_action = {
key.UP: "look_up",
key.DOWN: "look_down",
Expand All @@ -121,7 +121,9 @@ def __init__(self, sim_settings: Dict[str, Any]) -> None:
)

# Glyphs we need to render everything
self.glyph_cache = text.GlyphCache(mn.Vector2i(256), mn.Vector2i(1))
self.glyph_cache = text.GlyphCacheGL(
mn.PixelFormat.R8_UNORM, mn.Vector2i(256), mn.Vector2i(1)
)
self.display_font.fill_glyph_cache(
self.glyph_cache,
string.ascii_lowercase
Expand Down Expand Up @@ -457,7 +459,7 @@ def move_and_look(self, repetitions: int) -> None:
if repetitions == 0:
return

key = Application.KeyEvent.Key
key = Application.Key
agent = self.sim.agents[self.agent_id]
press: Dict[key.key, bool] = self.pressed
act: Dict[key.key, str] = self.key_to_action
Expand Down Expand Up @@ -487,8 +489,8 @@ def key_press_event(self, event: Application.KeyEvent) -> None:
key will be set to False for the next `self.move_and_look()` to update the current actions.
"""
key = event.key
pressed = Application.KeyEvent.Key
mod = Application.InputEvent.Modifier
pressed = Application.Key
mod = Application.Modifier

shift_pressed = bool(event.modifiers & mod.SHIFT)
alt_pressed = bool(event.modifiers & mod.ALT)
Expand Down Expand Up @@ -674,15 +676,17 @@ def key_release_event(self, event: Application.KeyEvent) -> None:
event.accepted = True
self.redraw()

def mouse_move_event(self, event: Application.MouseMoveEvent) -> None:
def pointer_move_event(self, event: Application.PointerMoveEvent) -> None:
"""
Handles `Application.MouseMoveEvent`. When in LOOK mode, enables the left
Handles `Application.PointerMoveEvent`. When in LOOK mode, enables the left
mouse button to steer the agent's facing direction. When in GRAB mode,
continues to update the grabber's object position with our agents position.
"""
button = Application.MouseMoveEvent.Buttons
# if interactive mode -> LOOK MODE
if event.buttons == button.LEFT and self.mouse_interaction == MouseMode.LOOK:
if (
event.pointers & Application.Pointer.MOUSE_LEFT
and self.mouse_interaction == MouseMode.LOOK
):
agent = self.sim.agents[self.agent_id]
delta = self.get_mouse_position(event.relative_position) / 2
action = habitat_sim.agent.ObjectControls()
Expand All @@ -705,12 +709,11 @@ def mouse_move_event(self, event: Application.MouseMoveEvent) -> None:
self.redraw()
event.accepted = True

def mouse_press_event(self, event: Application.MouseEvent) -> None:
def pointer_press_event(self, event: Application.PointerEvent) -> None:
"""
Handles `Application.MouseEvent`. When in GRAB mode, click on
Handles `Application.PointerEvent`. When in GRAB mode, click on
objects to drag their position. (right-click for fixed constraints)
"""
button = Application.MouseEvent.Button
physics_enabled = self.sim.get_physics_simulation_library()

# if interactive mode is True -> GRAB MODE
Expand Down Expand Up @@ -778,7 +781,7 @@ def mouse_press_event(self, event: Application.MouseEvent) -> None:
constraint_settings.pivot_b = hit_info.point

# by default use a point 2 point constraint
if event.button == button.RIGHT:
if event.pointer == Application.Pointer.MOUSE_RIGHT:
constraint_settings.constraint_type = (
physics.RigidConstraintType.Fixed
)
Expand All @@ -793,7 +796,9 @@ def mouse_press_event(self, event: Application.MouseEvent) -> None:
self.sim,
)
else:
logger.warn("Oops, couldn't find the hit object. That's odd.")
logger.warning(
"Oops, couldn't find the hit object. That's odd."
)
# end if didn't hit the scene
# end has raycast hit
# end has physics enabled
Expand All @@ -802,9 +807,9 @@ def mouse_press_event(self, event: Application.MouseEvent) -> None:
self.redraw()
event.accepted = True

def mouse_scroll_event(self, event: Application.MouseScrollEvent) -> None:
def scroll_event(self, event: Application.ScrollEvent) -> None:
"""
Handles `Application.MouseScrollEvent`. When in LOOK mode, enables camera
Handles `Application.ScrollEvent`. When in LOOK mode, enables camera
zooming (fine-grained zoom using shift) When in GRAB mode, adjusts the depth
of the grabber's object. (larger depth change rate using shift)
"""
Expand All @@ -817,9 +822,9 @@ def mouse_scroll_event(self, event: Application.MouseScrollEvent) -> None:
return

# use shift to scale action response
shift_pressed = bool(event.modifiers & Application.InputEvent.Modifier.SHIFT)
alt_pressed = bool(event.modifiers & Application.InputEvent.Modifier.ALT)
ctrl_pressed = bool(event.modifiers & Application.InputEvent.Modifier.CTRL)
shift_pressed = bool(event.modifiers & Application.Modifier.SHIFT)
alt_pressed = bool(event.modifiers & Application.Modifier.ALT)
ctrl_pressed = bool(event.modifiers & Application.Modifier.CTRL)

# if interactive mode is False -> LOOK MODE
if self.mouse_interaction == MouseMode.LOOK:
Expand Down Expand Up @@ -855,7 +860,7 @@ def mouse_scroll_event(self, event: Application.MouseScrollEvent) -> None:
self.redraw()
event.accepted = True

def mouse_release_event(self, event: Application.MouseEvent) -> None:
def pointer_release_event(self, event: Application.PointerEvent) -> None:
"""
Release any existing constraints.
"""
Expand Down
Loading

0 comments on commit 238c90b

Please sign in to comment.