Skip to content

Commit

Permalink
Update Magnum to latest (#2243)
Browse files Browse the repository at this point in the history
* Fix build with external Magnum.

* Add a zstd submodule.

Replaces zstd bundled with Basis, as that one is severely outdated.
Using version 1.5.0 instead of the latest, as the latest doesn't build
on the ancient Emscripten version used on the CI.

* Updated Magnum submodules.

The renamed function does the same as the old one (which is now
deprecated), it's just named appropriately because it always returned a
half angle.
  • Loading branch information
mosra authored Oct 26, 2023
1 parent 294c3fe commit 5808983
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@
[submodule "src/deps/rlr-audio-propagation"]
path = src/deps/rlr-audio-propagation
url = https://github.com/facebookresearch/rlr-audio-propagation
[submodule "src/deps/zstd"]
path = src/deps/zstd
url = https://github.com/facebook/zstd
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ option(USE_SYSTEM_MAGNUM "Use system Magnum instead of a bundled submodule" OFF)
option(USE_SYSTEM_PYBIND11 "Use system Pybind11 instead of a bundled submodule" OFF)
option(USE_SYSTEM_RAPIDJSON "Use system RapidJSON instead of a bundled submodule" OFF)
option(USE_SYSTEM_BULLET "Use system Bullet instead of a bundled submodule" OFF)
# Zstd is used only by the BasisImporter plugin, if external Magnum is used it
# doesn't need to be built at all.
include(CMakeDependentOption)
cmake_dependent_option(
USE_SYSTEM_ZSTD "Use system zstd instead of a bundled submodule" OFF
"NOT USE_SYSTEM_MAGNUM" ON
)
option(
BUILD_BASIS_COMPRESSOR
"Wether or not to build the basis compressor. Loading basis compressed meshes does NOT require this."
Expand Down
17 changes: 15 additions & 2 deletions src/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ else()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${DEPS_DIR}/eigen/cmake")
endif()

# Zstd, needed by BasisImporter. Let it find a system package on its own, if
# preferred.
if(NOT USE_SYSTEM_ZSTD)
set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "" FORCE)
# Create a static library so the plugin is self-contained
set(ZSTD_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(ZSTD_BUILD_STATIC ON CACHE BOOL "" FORCE)
# Basis doesn't use any multithreading in zstd, this prevents a need to link
# to pthread on Linux
set(ZSTD_MULTITHREAD_SUPPORT OFF CACHE BOOL "" FORCE)
# Don't build Zstd tests if enable_testing() was called in parent project
set(ZSTD_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory("${DEPS_DIR}/zstd/build/cmake" EXCLUDE_FROM_ALL)
endif()

# tinyxml2
include_directories("${DEPS_DIR}/tinyxml2")
add_subdirectory("${DEPS_DIR}/tinyxml2")
Expand Down Expand Up @@ -238,8 +253,6 @@ if(NOT USE_SYSTEM_MAGNUM)
# formats (BC7 mode 6 has > 1 MB tables, ATC/FXT1/PVRTC2 are quite rare and
# not supported by Magnum).
set(BASIS_UNIVERSAL_DIR "${DEPS_DIR}/basis-universal")
# Disabling Zstd for now, when it's actually needed we bundle a submodule
set(CMAKE_DISABLE_FIND_PACKAGE_Zstd ON)
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DBASISD_SUPPORT_BC7_MODE6_OPAQUE_ONLY=0 -DBASISD_SUPPORT_ATC=0 -DBASISD_SUPPORT_FXT1=0 -DBASISD_SUPPORT_PVRTC2=0"
Expand Down
2 changes: 1 addition & 1 deletion src/deps/corrade
Submodule corrade updated 202 files
2 changes: 1 addition & 1 deletion src/deps/magnum
Submodule magnum updated 1446 files
2 changes: 1 addition & 1 deletion src/deps/magnum-bindings
Submodule magnum-bindings updated 133 files
2 changes: 1 addition & 1 deletion src/deps/magnum-integration
2 changes: 1 addition & 1 deletion src/deps/magnum-plugins
Submodule magnum-plugins updated 517 files
1 change: 1 addition & 0 deletions src/deps/zstd
Submodule zstd added at a488ba
7 changes: 6 additions & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ find_package(
AnyImageImporter
)
find_package(
MagnumPlugins REQUIRED GltfImporter StbImageImporter KtxImporter
MagnumPlugins
REQUIRED
GltfImporter
StbImageImporter
KtxImporter
StbImageConverter
OPTIONAL_COMPONENTS GltfSceneConverter KtxImageConverter StanfordImporter
OpenExrImporter OpenExrImageConverter
)
Expand Down
8 changes: 4 additions & 4 deletions src/tests/PhysicsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ void PhysicsTest::testVelocityControl() {
(objectWrapper->getTranslation() - posGroundTruth).length(), errorEps,
Cr::TestSuite::Compare::LessOrEqual);
Magnum::Rad angleError =
Magnum::Math::angle(objectWrapper->getRotation(), qGroundTruth);
Magnum::Math::halfAngle(objectWrapper->getRotation(), qGroundTruth);

CORRADE_COMPARE_AS(float(angleError), errorEps,
Cr::TestSuite::Compare::LessOrEqual);
Expand All @@ -936,8 +936,8 @@ void PhysicsTest::testVelocityControl() {
(objectWrapper->getTranslation() - kinematicResult.translation)
.length(),
errorEps, Cr::TestSuite::Compare::LessOrEqual);
angleError = Magnum::Math::angle(objectWrapper->getRotation(),
kinematicResult.rotation);
angleError = Magnum::Math::halfAngle(objectWrapper->getRotation(),
kinematicResult.rotation);
CORRADE_COMPARE_AS(float(angleError), errorEps,
Cr::TestSuite::Compare::LessOrEqual);

Expand Down Expand Up @@ -979,7 +979,7 @@ void PhysicsTest::testVelocityControl() {
(objectWrapper->getTranslation() - posLocalGroundTruth).length(),
errorEps, Cr::TestSuite::Compare::LessOrEqual);
Magnum::Rad angleErrorLocal =
Magnum::Math::angle(objectWrapper->getRotation(), qLocalGroundTruth);
Magnum::Math::halfAngle(objectWrapper->getRotation(), qLocalGroundTruth);

CORRADE_COMPARE_AS(float(angleErrorLocal), errorEps,
Cr::TestSuite::Compare::LessOrEqual);
Expand Down
36 changes: 18 additions & 18 deletions tests/test_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def test_velocity_control():
ground_truth_pos = sim.get_world_time() * vel_control.linear_velocity
assert np.allclose(box_object.translation, ground_truth_pos, atol=0.01)
ground_truth_q = mn.Quaternion([[0, 0.480551, 0], 0.876967])
angle_error = mn.math.angle(ground_truth_q, box_object.rotation)
angle_error = mn.math.half_angle(ground_truth_q, box_object.rotation)
assert angle_error < mn.Rad(0.005)

sim.reset()
Expand All @@ -490,7 +490,7 @@ def test_velocity_control():
assert np.allclose(
box_object.translation, np.array([0, 1.0, 0.0]), atol=0.07
)
angle_error = mn.math.angle(ground_truth_q, box_object.rotation)
angle_error = mn.math.half_angle(ground_truth_q, box_object.rotation)
assert angle_error < mn.Rad(0.05)

rigid_obj_mgr.remove_object_by_id(box_object.object_id)
Expand Down Expand Up @@ -748,7 +748,7 @@ def check_articulated_object_root_state(
assert np.allclose(
articulated_object.translation, target_rigid_state.translation, atol=epsilon
)
assert mn.math.angle(
assert mn.math.half_angle(
articulated_object.rotation, target_rigid_state.rotation
) < mn.Rad(epsilon)
# check against object's rigid_state
Expand All @@ -757,7 +757,7 @@ def check_articulated_object_root_state(
target_rigid_state.translation,
atol=epsilon,
)
assert mn.math.angle(
assert mn.math.half_angle(
articulated_object.rigid_state.rotation, target_rigid_state.rotation
) < mn.Rad(epsilon)

Expand Down Expand Up @@ -1118,7 +1118,7 @@ def test_articulated_object_dynamics(test_asset):
mn.Rad(np.linalg.norm(target_ang_vel * timestep)),
target_ang_vel / np.linalg.norm(target_ang_vel),
)
angle_error = mn.math.angle(robot.rotation, expected_rotation)
angle_error = mn.math.half_angle(robot.rotation, expected_rotation)
assert angle_error < mn.Rad(0.0005)

assert not np.allclose(robot.root_linear_velocity, mn.Vector3(0), atol=0.1)
Expand Down Expand Up @@ -1279,8 +1279,8 @@ def check_joint_positions(robot, target, single_dof_eps=5.0e-3, quat_eps=0.2):
actual_q = mn.Quaternion(
positions[start_pos : start_pos + 3], positions[start_pos + 3]
)
angle_error = mn.math.angle(target_q, actual_q)
angle_error2 = mn.math.angle(target_q, -1 * actual_q)
angle_error = mn.math.half_angle(target_q, actual_q)
angle_error2 = mn.math.half_angle(target_q, -1 * actual_q)
# negative quaternion represents the same rotation, but gets a different angle error so check both
assert angle_error < mn.Rad(quat_eps) or angle_error2 < mn.Rad(quat_eps)
elif joint_type in [
Expand Down Expand Up @@ -1656,8 +1656,8 @@ def test_rigid_constraints():
)
assert np.allclose(global_pivot_pos, constraint_settings.pivot_b, atol=1.0e-3)
# default frames lock identity orientation
assert mn.math.angle(cube_obj.rotation, mn.Quaternion()) < mn.Rad(0.01)
assert mn.math.angle(cube_obj_2.rotation, mn.Quaternion()) < mn.Rad(0.01)
assert mn.math.half_angle(cube_obj.rotation, mn.Quaternion()) < mn.Rad(0.01)
assert mn.math.half_angle(cube_obj_2.rotation, mn.Quaternion()) < mn.Rad(0.01)

# change the global frame rotation
global_target_frame = mn.Quaternion.rotation(
Expand All @@ -1679,11 +1679,11 @@ def test_rigid_constraints():

observations += simulate(sim, 2.0, produce_debug_video)
# check global frame change of object 1
assert mn.math.angle(cube_obj.rotation, global_target_frame) < mn.Rad(0.01)
assert mn.math.half_angle(cube_obj.rotation, global_target_frame) < mn.Rad(0.01)
# check that relative frames of objects total pi/2
angle_error = mn.math.angle(cube_obj.rotation, cube_obj_2.rotation) - mn.Rad(
mn.math.pi / 4.0
)
angle_error = mn.math.half_angle(
cube_obj.rotation, cube_obj_2.rotation
) - mn.Rad(mn.math.pi / 4.0)
assert abs(float(angle_error)) < 0.01

# removing objects will clear constraints
Expand Down Expand Up @@ -1749,7 +1749,7 @@ def test_rigid_constraints():
assert np.allclose(global_connect_a, global_connect_b, atol=0.08)

# check that relative frames of objects near 0
assert mn.math.angle(
assert mn.math.half_angle(
cube_obj.rotation,
robot.get_link_scene_node(constraint_settings_2.link_id_a).rotation,
) < mn.Rad(0.1)
Expand All @@ -1767,7 +1767,7 @@ def test_rigid_constraints():

observations += simulate(sim, 4.0, produce_debug_video)
# check frames align
angle_error = mn.math.angle(
angle_error = mn.math.half_angle(
cube_obj.rotation,
robot.get_link_scene_node(constraint_settings_2.link_id_a).rotation,
) - mn.Rad(mn.math.pi / 4.0)
Expand Down Expand Up @@ -1817,7 +1817,7 @@ def test_rigid_constraints():
assert np.allclose(global_connect_a, constraint_settings_2.pivot_b, atol=0.08)

# check frames align
angle_error = mn.math.angle(
angle_error = mn.math.half_angle(
local_target_frame_2,
robot.get_link_scene_node(constraint_settings_2.link_id_a).rotation,
) - mn.Rad(mn.math.pi / 4.0)
Expand All @@ -1828,7 +1828,7 @@ def test_rigid_constraints():
sim.remove_rigid_constraint(constraint_id_2)
constraint_id_2 = sim.create_rigid_constraint(constraint_settings_2)
observations += simulate(sim, 5.0, produce_debug_video)
angle_error = mn.math.angle(local_target_frame_2, robot.rotation) - mn.Rad(
angle_error = mn.math.half_angle(local_target_frame_2, robot.rotation) - mn.Rad(
mn.math.pi / 4.0
)
# NOTE: This error is a bit high, but constraint is doing its best
Expand Down Expand Up @@ -1895,7 +1895,7 @@ def test_rigid_constraints():
assert np.allclose(global_connect_a, global_connect_b, atol=0.08)

# check frames align
angle_error = mn.math.angle(
angle_error = mn.math.half_angle(
robot.get_link_scene_node(constraint_settings_2.link_id_a).rotation,
robot2.get_link_scene_node(constraint_settings_2.link_id_b).rotation,
)
Expand Down

0 comments on commit 5808983

Please sign in to comment.