diff --git a/cmake/third_party_deps/font_awesome.cmake b/cmake/third_party_deps/font_awesome.cmake new file mode 100644 index 00000000..9e705984 --- /dev/null +++ b/cmake/third_party_deps/font_awesome.cmake @@ -0,0 +1,31 @@ +# Copyright 2025 DeepMind Technologies Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(MUJOCO_DEP_VERSION_font_awesome + a8386aae19e200ddb0f6845b5feeee5eb7013687 + CACHE STRING "Tag/version of `font_awesome` to be fetched." +) +mark_as_advanced(MUJOCO_DEP_VERSION_font_awesome) + +include(FindOrFetch) + +fetchpackage( + PACKAGE_NAME font_awesome + GIT_REPO https://github.com/FortAwesome/Font-Awesome.git + GIT_TAG ${MUJOCO_DEP_VERSION_font_awesome} + PATCH_COMMAND + "cp" + "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/font_awesome/CMakeLists.txt" + "${FETCHCONTENT_BASE_DIR}/font_awesome-src/CMakeLists.txt" +) diff --git a/cmake/third_party_deps/font_awesome/CMakeLists.txt b/cmake/third_party_deps/font_awesome/CMakeLists.txt new file mode 100644 index 00000000..430de44d --- /dev/null +++ b/cmake/third_party_deps/font_awesome/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2025 DeepMind Technologies Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Data-only package. diff --git a/cmake/third_party_deps/opensans.cmake b/cmake/third_party_deps/opensans.cmake new file mode 100644 index 00000000..08f9b8ce --- /dev/null +++ b/cmake/third_party_deps/opensans.cmake @@ -0,0 +1,31 @@ +# Copyright 2025 DeepMind Technologies Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(MUJOCO_DEP_VERSION_opensans + 3d45774008254746e09bce4f8922b515a7b6a26b + CACHE STRING "Tag/version of `opensans` to be fetched." +) +mark_as_advanced(MUJOCO_DEP_VERSION_opensans) + +include(FindOrFetch) + +fetchpackage( + PACKAGE_NAME opensans + GIT_REPO https://github.com/googlefonts/opensans.git + GIT_TAG ${MUJOCO_DEP_VERSION_opensans} + PATCH_COMMAND + "cp" + "${CMAKE_SOURCE_DIR}/cmake/third_party_deps/opensans/CMakeLists.txt" + "${FETCHCONTENT_BASE_DIR}/opensans-src/CMakeLists.txt" +) diff --git a/cmake/third_party_deps/opensans/CMakeLists.txt b/cmake/third_party_deps/opensans/CMakeLists.txt new file mode 100644 index 00000000..430de44d --- /dev/null +++ b/cmake/third_party_deps/opensans/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2025 DeepMind Technologies Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Data-only package. diff --git a/src/experimental/studio/CMakeLists.txt b/src/experimental/studio/CMakeLists.txt index 3c213d66..15d8f416 100644 --- a/src/experimental/studio/CMakeLists.txt +++ b/src/experimental/studio/CMakeLists.txt @@ -56,6 +56,9 @@ endif() include(third_party_deps/dear_imgui) include(third_party_deps/implot) +include(third_party_deps/opensans) +include(third_party_deps/font_awesome) + target_link_libraries(${MUJOCO_STUDIO_TARGET_NAME} PRIVATE ${MUJOCO_STUDIO_RENDER_DEPS} @@ -68,20 +71,36 @@ target_link_libraries(${MUJOCO_STUDIO_TARGET_NAME} mujoco::toolbox ) +file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets) + +add_custom_command( + TARGET ${MUJOCO_STUDIO_TARGET_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + -E copy + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../_deps/opensans-src/fonts/ttf/OpenSans-Regular.ttf + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets + COMMENT "Copying OpenSans-Regular.ttf assets to build directory" +) +add_custom_command( + TARGET ${MUJOCO_STUDIO_TARGET_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + -E copy + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../_deps/font_awesome-src/fonts/fontawesome-webfont.ttf + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets + COMMENT "Copying fontawesome-webfont.ttf to build directory" +) + # Filament backend requires additional files to be copied into an "assets" folder. if(MUJOCO_USE_FILAMENT) - if(WIN32) - # Copy to work around lack of symlink permissions on Windows. - set(COPY_COMMAND copy_directory) - else() - set(COPY_COMMAND create_symlink) - endif() add_custom_command( TARGET ${MUJOCO_STUDIO_TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E ${COPY_COMMAND} - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../src/experimental/filament/assets - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets + COMMAND ${CMAKE_COMMAND} + -E copy_directory + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../src/experimental/filament/assets + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets COMMENT "Copying Filament assets to build directory" ) endif() diff --git a/src/experimental/toolbox/window.cc b/src/experimental/toolbox/window.cc index 4d6ff907..46229b55 100644 --- a/src/experimental/toolbox/window.cc +++ b/src/experimental/toolbox/window.cc @@ -45,6 +45,27 @@ static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn) { ImGui::StyleColorsDark(); ImGui_ImplSDL2_InitForOther(window); +#ifndef __EMSCRIPTEN__ + // TODO: Get font loading working for wasm. + ImFontConfig main_cfg; + main_cfg.OversampleH = 8; + main_cfg.OversampleV = 4; + main_cfg.GlyphExtraSpacing.x = 0.3f; + + auto main_font = load_asset_fn("OpenSans-Regular.ttf"); + io.Fonts->AddFontFromMemoryTTF(main_font.data(), main_font.size(), 18.f, + &main_cfg); + + ImFontConfig icon_cfg; + icon_cfg.OversampleH = 3; + icon_cfg.OversampleV = 3; + icon_cfg.MergeMode = true; + icon_cfg.GlyphMinAdvanceX = 14.0f; + auto icon_font = load_asset_fn("fontawesome-webfont.ttf"); + constexpr ImWchar icon_ranges[] = {0xf000, 0xf3ff, 0x000}; + io.Fonts->AddFontFromMemoryTTF(icon_font.data(), icon_font.size(), 14.f, + &icon_cfg, icon_ranges); +#endif io.Fonts->Build(); }