diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..dff6e4de --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,25 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**How to submit a good bug report** + +- Are you sure this is a bug? If not, consider using the "Ask for help" or "Feature request" templates. + +- Use a clear and descriptive title. + +- Make it easy to reproduce the problem. + +- Include a ***minimal*** model that demonstrates the problem. If the model is small, include it as inline XML. If it requires binary assets, attach it as a zip file. + +- Include a screenshot or video, if relevant. + +- Include the following context: + - Operating system. + - MuJoCo version (and if the bug is new, the version where it used to work). + - For Python issues, what bindings are you using (i.e `mujoco`, `dm_control`, `mujoco-py`)? \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..8ca6213c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for MuJoCo +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/help.md b/.github/ISSUE_TEMPLATE/help.md new file mode 100644 index 00000000..8b34900a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/help.md @@ -0,0 +1,16 @@ +--- +name: Help +about: Ask for help with MuJoCo +title: '' +labels: question +assignees: '' + +--- + +**How to ask for help** + +- Take a step back and tell us what you're trying to accomplish, and in what context. The more information you give, the better the answers you will get. + +- If relevant, include a ***minimal*** model that demonstrates the problem. If the model is small, include it as inline XML. If it requires binary assets, attach it as a zip file. + +- Include a screenshot or video, if relevant. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..87a54605 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,228 @@ +# Copyright 2021 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. + +cmake_minimum_required(VERSION 3.18) + +# Make CMAKE_C_VISIBILITY_PRESET work properly. +set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) +# INTERPROCEDURAL_OPTIMIZATION is enforced when enabled. +set(CMAKE_POLICY_DEFAULT_CMP0069 NEW) +# Default to GLVND if available. +set(CMAKE_POLICY_DEFAULT_CMP0072 NEW) +# Avoid BUILD_SHARED_LIBS getting overridden by an option() in ccd. +set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) + +# This line has to appear before 'PROJECT' in order to be able to disable incremental linking +set(MSVC_INCREMENTAL_DEFAULT ON) + +project( + mujoco + VERSION 2.2.0 + DESCRIPTION "MuJoCo Physics Simulator" + HOMEPAGE_URL "https://mujoco.org" +) + +enable_language(C) +enable_language(CXX) + +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +option(MUJOCO_BUILD_EXAMPLES "Build samples for MuJoCo" ON) +option(MUJOCO_BUILD_TESTS "Build tests for MuJoCo" ON) +option(MUJOCO_TEST_PYTHON_UTIL "Build and test utility libraries for Python bindings" ON) + +if(APPLE AND MUJOCO_BUILD_EXAMPLES) + enable_language(OBJC) + enable_language(OBJCXX) +endif() + +include(MujocoOptions) +include(MujocoMacOS) +include(MujocoDependencies) + +set(MUJOCO_HEADERS + include/mujoco/mjdata.h + include/mujoco/mjexport.h + include/mujoco/mjmodel.h + include/mujoco/mjrender.h + include/mujoco/mjtnum.h + include/mujoco/mjui.h + include/mujoco/mjvisualize.h + include/mujoco/mjxmacro.h + include/mujoco/mujoco.h +) + +add_library(mujoco SHARED) +target_include_directories( + mujoco + PUBLIC $ + $ + PRIVATE src +) + +add_subdirectory(src/engine) +add_subdirectory(src/user) +add_subdirectory(src/xml) +add_subdirectory(src/render) +add_subdirectory(src/ui) + +target_compile_definitions(mujoco PRIVATE _GNU_SOURCE CCD_STATIC_DEFINE MUJOCO_DLL_EXPORTS) +if(MUJOCO_ENABLE_AVX_INTRINSICS) + target_compile_definitions(mujoco PUBLIC mjUSEPLATFORMSIMD) +endif() + +target_compile_options( + mujoco + PRIVATE ${AVX_COMPILE_OPTIONS} + ${MUJOCO_MACOS_COMPILE_OPTIONS} + ${EXTRA_COMPILE_OPTIONS} + ${MUJOCO_CXX_FLAGS} +) +target_link_options( + mujoco + PRIVATE + ${MUJOCO_MACOS_LINK_OPTIONS} + ${EXTRA_LINK_OPTIONS} +) + +target_link_libraries( + mujoco + PRIVATE ccd + lodepng + qhullstatic_r + tinyobjloader + tinyxml2 +) + +set_target_properties( + mujoco PROPERTIES VERSION "${mujoco_VERSION}" PUBLIC_HEADER "${MUJOCO_HEADERS}" +) + +# CMake's built-in FRAMEWORK option doesn't give us control over the dylib name inside the +# Framework. We instead make our own Framework here. +if(APPLE AND MUJOCO_BUILD_MACOS_FRAMEWORKS) + include(DuplicateTarget) + duplicate_target( + TARGET + mujoco + NEW_TARGET_NAME + mujoco_framework + ) + + # Do not add mujoco::mujoco to the ALL target. We do this to speed up the + # build assuming the user is interested in the Frameworks. + set_target_properties(mujoco PROPERTIES EXCLUDE_FROM_ALL TRUE) + + set(TAPI + "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/tapi" + ) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/dist/Info.plist.framework.in + ${CMAKE_CURRENT_SOURCE_DIR}/dist/Info.framework.plist + ) + set_target_properties( + mujoco_framework + PROPERTIES LIBRARY_OUTPUT_DIRECTORY + "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/mujoco.framework/Versions/A" + BUILD_WITH_INSTALL_NAME_DIR TRUE + INSTALL_NAME_DIR "@rpath/mujoco.framework/Versions/A" + OUTPUT_NAME "mujoco" + ) + add_custom_command( + TARGET mujoco_framework + POST_BUILD + COMMAND mkdir -p $/Headers + COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && cp ${MUJOCO_HEADERS} + $/Headers + COMMAND mkdir -p $/Modules + COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/dist/module.modulemap + $/Modules + COMMAND mkdir -p $/Resources + COMMAND mv ${CMAKE_CURRENT_SOURCE_DIR}/dist/Info.framework.plist + $/Resources/Info.plist + COMMAND ln -fhs A $/../Current + COMMAND ${TAPI} stubify $ -o + $/../../mujoco.tbd + COMMAND ln -fhs Versions/Current/Headers $/../../Headers + COMMAND ln -fhs Versions/Current/Modules $/../../Modules + COMMAND ln -fhs Versions/Current/Resources $/../../Resources + COMMAND_EXPAND_LISTS + ) +endif() + +# Add a namespace alias to mujoco to be used by the examples. +# This simulates the install interface when building with sources. +add_library(mujoco::mujoco ALIAS mujoco) + +add_subdirectory(model) + +if(MUJOCO_BUILD_EXAMPLES) + add_subdirectory(sample) +endif() + +if(BUILD_TESTING AND MUJOCO_BUILD_TESTS) + enable_testing() + add_subdirectory(test) +endif() + +if(BUILD_TESTING AND MUJOCO_TEST_PYTHON_UTIL) + enable_testing() + add_subdirectory(python/mujoco/util) +endif() + +# Install the libraries. +install( + TARGETS mujoco + EXPORT ${PROJECT_NAME} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT runtime + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT runtime + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT dev + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT dev +) + +set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +# Generate and install the mujocoTargets.cmake file. This defines the targets as +# IMPORTED libraries for downstream users. +install( + EXPORT ${PROJECT_NAME} + DESTINATION ${CONFIG_PACKAGE_LOCATION} + NAMESPACE mujoco:: + FILE "${PROJECT_NAME}Targets.cmake" +) + +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${mujoco_VERSION} + COMPATIBILITY AnyNewerVersion +) + +configure_package_config_file( + cmake/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION} +) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CONFIG_PACKAGE_LOCATION} +) + +# Install also models into share folder. +install( + DIRECTORY model + DESTINATION "${CMAKE_INSTALL_DATADIR}/mujoco" + PATTERN "CMakeLists.txt" EXCLUDE +) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 61657090..6960eb16 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,25 +1,116 @@ -# How to Contribute +# Contributing to MuJoCo -We are still in the process of preparing the MuJoCo codebase for open-sourcing, -however the full source code for the Python bindings and the Unity plugin are -already released. You are welcome to send us pull requests to improve any part -of this repository. +We intend for MuJoCo to be a true community-driven project and look forward to +accepting your contributions! -## Contributor License Agreement +## Before you contribute + +### Documentation, forums + +Please read MuJoCo's [documentation](https://mujoco.readthedocs.io) and look +through current topics on our GitHub +[issues](https://github.com/deepmind/mujoco/issues) and +[discussions](https://github.com/deepmind/mujoco/discussions) pages. + +### Contributor License Agreement Contributions to this project must be accompanied by a Contributor License -Agreement. You (or your employer) retain the copyright to your contribution, -this simply gives us permission to use and redistribute your contributions as -part of the project. Head over to to see -your current agreements on file or to sign a new one. +Agreement (CLA). You (or your employer) retain the copyright to your +contribution; this simply gives us permission to use and redistribute your +contributions as part of the project. Head over to + to see your current agreements on file or +to sign a new one. You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again. -## Code reviews +## Contributing -All submissions require review. Please use GitHub pull requests for this -purpose. Consult +### Reporting bugs + +How to submit a good bug report: + +- Use a clear and descriptive title. + +- Make it easy to reproduce the problem. If this requires a model, attach it as +a zip file to the bug report. The model and steps required to reproduce the +proplem should be *minimal*, in the sense that irrelevant parts are +removed. + +- Clearly state what is the expected behavior. + +- Include an illustrative screenshot, if relevant. + +Try to provide context: + +- If the problem is new, see if you can reproduce it in an older version. +What's the most recent version in which the problem doesn't happen? + +- Can you reproduce the problem on multiple platforms? + +### Suggesting enhancements + +Before submitting an enhancement suggestion: + +- Check if you're using the [latest +version](https://github.com/deepmind/mujoco/releases/latest) of MuJoCo. + +- Perform a quick [search](https://github.com/deepmind/mujoco/issues) to see if +the enhancement has already been suggested. If it has, add a comment to the +existing issue instead of opening a new one. + +How to submit a good enhacement suggestion: + +- Use a clear and descriptive title. + +- Describe the current behaviour and the behavior which you hope to see instead. + +- Explain why this enhancement would be useful. + +- Specify the version of MuJoCo and platform/OS you are using. + +### Contributing code + +- Except for small and straightforward bugfixes, please get in touch with us +before you start working on a contribution so that we can help and possibly +guide you. Coordinating up front makes it much easier to avoid frustration later +on. + +- All submissions require review. Please use GitHub pull requests for this +purpose. Please consult [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more information on pull requests. + +- Write tests. MuJoCo uses [googletest](https://github.com/google/googletest) +for C++ tests, [absltest](https://abseil.io/docs/python/guides/testing) for +Python binding code and [nunit](https://nunit.org/) for C# code in the Unity +plugin. In most cases, a pull request will only be accepted if it includes +tests. MuJoCo's internal codebase is currently lacking in test coverage. If you +want to modify a function that isn't covered by tests, you'll be expected to +contribute tests for the existing functionality, not just your modification. In +fact, writing a test for existing code is a great way to get started with +contributions. + +- Resolve compiler warnings. + +- All existing tests must pass. + +- Follow the [Style Guide](./STYLEGUIDE.md). In particular, adequately comment +your code. + +- Make small pull requests. We will likely ask you to split up a large pull +request into self-contained, smaller ones, especially if the PR is trying to +achieve multiple things. + +- Respond to reviewers. Please be responsive to any questions and comments. + +Once you have met all the requirements, your code will be merged. +Thanks for improving MuJoCo! + + + +### Community guidelines + +This project follows Google's +[Open Source Community Guidelines](https://opensource.google/conduct/). diff --git a/README.md b/README.md index 26980f57..3fbac852 100644 --- a/README.md +++ b/README.md @@ -6,77 +6,50 @@ in robotics, biomechanics, graphics and animation, machine learning, and other areas which demand fast and accurate simulation of articulated structures interacting with their environment. -DeepMind has acquired MuJoCo, and we are currently making preparations to open -source the codebase. In the meantime, MuJoCo is available for download as a free -and unrestricted precompiled binary under the Apache 2.0 license from -the [GitHub Releases page](https://github.com/deepmind/mujoco/releases). - -MuJoCo's source code will be released through this GitHub repository once it is -ready. In the meantime, the repository hosts MuJoCo's documentation, C header -files for its public API, sample program code, along with the full source code -for the Python bindings and Unity plugin. If you wish to report bugs or make -feature requests, please file them as [GitHub Issues]. You are also welcome to -send us pull requests to improve anything that has been released into this -repository. - - -## Overview - -MuJoCo is a compiled library with a C API, intended for researchers and -developers. The runtime simulation module is tuned to maximize performance and -operates on low-level data structures which are preallocated by the built-in XML -parser and compiler. The user defines models in the native MJCF scene -description language -- an XML file format designed to be as human readable and -editable as possible. URDF model files can also be loaded. The library includes -interactive visualization with a native GUI, rendered in OpenGL. MuJoCo further -exposes a large number of utility functions for computing physics-related -quantities, not necessarily in a simulation loop. Features include - -- Simulation in generalized coordinates, avoiding joint violations. - -- Inverse dynamics that are well-defined even in the presence of contacts. - -- Unified continuous-time formulation of constraints via convex optimization. - -- Constraints include soft contacts, limits, dry friction, equality - constraints. - -- Simulation of particle systems, cloth, rope and soft objects. - -- Actuators including motors, cylinders, muscles, tendons, slider-cranks. - -- Choice of Newton, Conjugate Gradient, or Projected Gauss-Seidel solvers. - -- Choice of pyramidal or elliptic friction cones, dense or sparse Jacobians. - -- Choice of Euler or Runge-Kutta numerical integrators. - -- Multi-threaded sampling and finite-difference approximations. - -- Intuitive XML model format (called MJCF) and built-in model compiler. - -- Cross-platform GUI with interactive 3D visualization in OpenGL. - -- Run-time module written in ANSI C and hand-tuned for performance. - -[Python bindings](https://github.com/deepmind/mujoco/tree/main/python) and a -[plugin for the Unity game engine](https://github.com/deepmind/mujoco/tree/main/unity) -are also provided and are actively supported by the MuJoCo development team. - - -## Requirements - -MuJoCo binaries are currently built for Linux (x86-64 and AArch64), -Windows (x86-64 only), and macOS. If you require a build for a different -platform, please let us know via [GitHub Issues] or -[Discussions](https://github.com/deepmind/mujoco/discussions). +This repository is maintained by DeepMind, please see our [acquisition] and +[open sourcing] announcements. +MuJoCo has a C API and is intended for researchers and developers. The runtime +simulation module is tuned to maximize performance and operates on low-level +data structures that are preallocated by the built-in XML compiler. The library +includes interactive visualization with a native GUI, rendered in OpenGL. MuJoCo +further exposes a large number of utility functions for computing physics- +related quantities. We also provide Python bindings and a plug-in for the Unity +game engine. ## Documentation -MuJoco's current documentation is available at [mujoco.org/book], which is -serving Sphinx-based webpages derived from the ReStructuredText -[documentation source files]. +MuJoCo's documentation is available at [mujoco.readthedocs.io], which serves +webpages derived from the [documentation source files]. + +## Releases + +Versioned releases are available as precompiled binaries from the GitHub +[releases page], built for Linux (x86-64 and AArch64), Windows (x86-64 only), +and macOS (universal). This is the recommended way to use the software. + +Users who wish to build MuJoCo from source, please consult the [build from +source] section of the documentation. However, please note that the commit at +the tip of the `main` branch branch may be unstable. + + +## Getting Started + +There are two easy ways to get started with MuJoCo: + +1. **Run `simulate` on your machine.** +[This video](https://www.youtube.com/watch?v=0ORsj_E17B0) shows a screen capture +of `simulate`, MuJoCo's native interactive viewer. Follow the steps described in +the [Getting Started] section of the documentation to get `simulate` running on +your machine. + +2. **Explore our online IPython notebooks.** +If you are a Python user, you might want to start with our tutorial notebooks, +running on Google Colab: + + - The first tutorial focuses on the basic MuJoco Python bindings: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/deepmind/dm_control/blob/main/dm_control/mujoco/tutorial.ipynb). + + - The second tutorial includes more examples of `dm_control`-specific functionality: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/deepmind/dm_control/blob/main/tutorial.ipynb). ## Citation @@ -85,19 +58,23 @@ If you use MuJoCo for published research, please cite: ``` @inproceedings{todorov2012mujoco, - title={Mujoco: A physics engine for model-based control}, + title={MuJoCo: A physics engine for model-based control}, author={Todorov, Emanuel and Erez, Tom and Tassa, Yuval}, booktitle={2012 IEEE/RSJ International Conference on Intelligent Robots and Systems}, pages={5026--5033}, year={2012}, - organization={IEEE} + organization={IEEE}, + doi={10.1109/IROS.2012.6386109} } ``` ## License and Disclaimer -Copyright 2021 DeepMind Technologies Limited +Copyright 2021 DeepMind Technologies Limited. + +Box collision code ([`engine_collision_box.c`](https://github.com/deepmind/mujoco/tree/main/src/engine/engine_collision_box.c)) +is Copyright 2016 Svetoslav Kolev. ReStructuredText documents, images, and videos in the `doc` directory are made available under the terms of the Creative Commons Attribution 4.0 (CC BY 4.0) @@ -109,7 +86,11 @@ copy of the License at https://www.apache.org/licenses/LICENSE-2.0. This is not an officially supported Google product. - +[build from source]: https://mujoco.readthedocs.io/en/latest/programming.html#building-mujoco-from-source +[Getting Started]: https://mujoco.readthedocs.io/en/latest/programming.html#getting-started +[acquisition]: https://www.deepmind.com/blog/opening-up-a-physics-simulator-for-robotics +[open sourcing]: https://www.deepmind.com/blog/open-sourcing-mujoco +[releases page]: https://github.com/deepmind/mujoco/releases [GitHub Issues]: https://github.com/deepmind/mujoco/issues [documentation source files]: https://github.com/deepmind/mujoco/tree/main/doc -[mujoco.org/book]: https://mujoco.org/book +[mujoco.readthedocs.io]: https://mujoco.readthedocs.io diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md new file mode 100644 index 00000000..df16f2c6 --- /dev/null +++ b/STYLEGUIDE.md @@ -0,0 +1,159 @@ +# MuJoCo Style Guide + +The MuJoCo codebase follows an internally consistent style that values +compactness and readability. Please try to follow the style guide as closely as +possible in your code contributions. + +### Scope of this guide + +MuJoCo has three main code categories: + +1. **C code:** MuJoCo's core codebase. It consists of public headers under +`include/` and C source files and internal headers under `src/`. This style +guide primarily concerns itself with this category. + +2. **Legacy C++:** Files under `src/user/` and `src/xml/`. These do not +necessarily follow best C++ practices. We intend to gradually replace these with +new code that follows the [Google C++ +style](https://google.github.io/styleguide/cppguide.html) over time. + +3. **New code:** This includes C++ files under `test/` and `python/` and C# +files under `unity/`. Added by DeepMind engineers, this code adheres to the +[Google style](https://google.github.io/styleguide/). + +### General principles + +Where any aspect of coding style is not explicitly spelled out in this guide, +the following principle is followed: + +| Maximise consistency with the rest of the code. | +| --- | + +If there is a contradiction between this guide and existing code, the guide +takes precedence. Additional principles include: + +- Follow the [naming conventions](https://mujoco.readthedocs.io/en/latest/programming.html#naming-convention). +- Be sparing with horizontal space: Try to keep lines short, avoid line-breaks +where possble. +- Be generous with vertical space: Empty lines between code blocks are good. +- Keep names short. +- Inline comments are part of the code, treat them as such. +- Use American English in comments and documentation. + +### Specific rules for C code + +Over time, this style guide will be expanded to cover most aspects of C +programming in the MuJoCo codebase. In the meantime, it is usually enough to +inspect existing code and try to follow its example. + +If there are any consistent coding patterns that are specific to the MuJoCo +codebase but aren't mentioned in the guide, the guide should be expanded. If you +spot such a pattern, feel free to send a PR to update the guide. + +#### Indentation + +2-space indents, using space characters rather than tabs. + +#### Line length + +Line length is 100 characters. In rare situations, like the collision table at +the top of +[engine_collision_driver.c](https://github.com/deepmind/mujoco/search?q=repo%3Ad +eepmind%2Fmujoco+filename%3Aengine_collision_driver.c), longer lines are alowed +for readability. + +#### Comments + +MuJoCo makes generous use of short, one-line comments describing the code block +just below them. They are considered an essential part of the code. Comments +should be: + +- As succinct as possible, while maintaining clarity. +- Preceded by an empty line, unless at the top of a block. +- Uncapitalized and not terminated by a full-stop. + +A helpful heuristic regarding in-code comments is that the reader should be able +to get a sense of what is happening in a function just by reading the comments. + +An exception to the third bullet point above are function declaration comments +in public header files which are considered to be docstrings rather than code +and are therefore capitalized and terminated by a full stop. These docstrings +are required. + +#### Braces + +- MuJoCo uses +[attached K&R braces](https://en.wikipedia.org/wiki/Indentation_style#Variant:_mandatory_braces), +including for one-line blocks: + + ```C + // transpose matrix + void mju_transpose(mjtNum* res, const mjtNum* mat, int nr, int nc) { + for (int i=0; i with all the possible build types. This is needed for multi-config generators as they can change the type of build without invoking again CMake. + set(CMAKE_ALL_PROPERTY_LIST "") + foreach(PROPERTY ${ALL_PROPERTIES}) + # Skip reading the LOCAION property as they should not be read. + # See https://stackoverflow.com/questions/32197663/how-can-i-remove-the-the-location-property-may-not-be-read-from-target-error-i + if(PROPERTY STREQUAL "LOCATION" + OR PROPERTY MATCHES "^LOCATION_" + OR PROPERTY MATCHES "_LOCATION$" + ) + continue() + endif() + + set(_ignore OFF) + foreach(_pro ${IGNORED_PROPERTIES}) + if(PROPERTY STREQUAL ${_pro}) + set(_ignore ON) + break() + endif() + endforeach() + + if(_ignore) + continue() + endif() + + string(FIND ${PROPERTY} "" FOUND) + if(${FOUND} EQUAL -1) + # Simply append the property. + list(APPEND CMAKE_ALL_PROPERTY_LIST ${PROPERTY}) + else() + # Iterate on the build types to add the correct property. + foreach(BUILD_TYPE ${BUILD_TYPES}) + string( + REPLACE "" + "${BUILD_TYPE}" + CONFIG_PROPERTY + ${PROPERTY} + ) + list(APPEND CMAKE_ALL_PROPERTY_LIST ${CONFIG_PROPERTY}) + endforeach() + endif() + + endforeach() + + endif() + + foreach(PROPERTY ${CMAKE_ALL_PROPERTY_LIST}) + # Search if we should skip this property. + + list( + FIND + PROPERTIES_TO_SKIP + ${PROPERTY} + SHOULD_SKIP + ) + if(${SHOULD_SKIP} GREATER_EQUAL 0) + continue() + endif() + + # First check if the property was set on the target + get_property( + PROPERTY_FOUND + TARGET ${_ARGS_TARGET} + PROPERTY ${PROPERTY} + SET + ) + if(PROPERTY_FOUND) + get_target_property(PROPERTY_VALUE ${_ARGS_TARGET} ${PROPERTY}) + set_target_properties(${_ARGS_NEW_TARGET_NAME} PROPERTIES ${PROPERTY} "${PROPERTY_VALUE}") + endif() + endforeach() +endmacro() diff --git a/cmake/FindOrFetch.cmake b/cmake/FindOrFetch.cmake index 4eeb617e..602601f5 100644 --- a/cmake/FindOrFetch.cmake +++ b/cmake/FindOrFetch.cmake @@ -31,8 +31,9 @@ # # Arguments: # - ``USE_SYSTEM_PACKAGE`` one-value argument on whether to search for the -# package in the system (ON) or whether to fetch the library from a git -# repository (OFF). +# package in the system (ON) or whether to fetch the library using +# FetchContent from the specified Git repository (OFF). Note that +# FetchContent variables will override this behaviour. # - ``PACKAGE_NAME`` name of the system-package. Ignored if # ``USE_SYSTEM_PACKAGE`` is ``OFF``. # - ``LIBRARY_NAME`` name of the library. Ignored if @@ -41,9 +42,19 @@ # ``USE_SYSTEM_PACKAGE`` is ``ON``. # - ``GIT_TAG`` tag reference when fetching the library from the git # repository. Ignored if ``USE_SYSTEM_PACKAGE`` is ``ON``. +# - ``PATCH_COMMAND`` Specifies a custom command to patch the sources after an +# update. See https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add +# for details on the parameter. # - ``TARGETS`` list of targets to be satisfied. If any of these targets are # not currently defined, this macro will attempt to either find or fetch the # package. +# - ``EXCLUDE_FROM_ALL`` if specified, the targets are not added to the ``all`` +# metatarget. +# +# Note: if ``USE_SYSTEM_PACKAGE`` is ``OFF``, FetchContent will be used to +# retrieve the specified targets. It is possible to specify any variable in +# https://cmake.org/cmake/help/latest/module/FetchContent.html#variables to +# override this macro behaviour. if(COMMAND FindOrFetch) return() @@ -76,10 +87,14 @@ macro(FindOrFetch) if(NOT _ARGS_TARGETS) message(FATAL_ERROR "mujoco::FindOrFetch: TARGETS must be specified.") endif() + set(targets_found TRUE) + message(CHECK_START + "mujoco::FindOrFetch: checking for targets in package `${_ARGS_PACKAGE_NAME}`" + ) foreach(target ${_ARGS_TARGETS}) if(NOT TARGET ${target}) - message(STATUS "mujoco::FindOrFetch: target `${target}` not defined.") + message(CHECK_FAIL "target `${target}` not defined.") set(targets_found FALSE) break() endif() @@ -88,16 +103,14 @@ macro(FindOrFetch) # If targets are not found, use `find_package` or `FetchContent...` to get it. if(NOT targets_found) if(${_ARGS_USE_SYSTEM_PACKAGE}) - message( - STATUS - "mujoco::FindOrFetch: Attempting to find `${_ARGS_PACKAGE_NAME}` in system packages..." + message(CHECK_START + "mujoco::FindOrFetch: finding `${_ARGS_PACKAGE_NAME}` in system packages..." ) find_package(${_ARGS_PACKAGE_NAME} REQUIRED) - message(STATUS "mujoco::FindOrFetch: Found `${_ARGS_PACKAGE_NAME}` in system packages.") + message(CHECK_PASS "found") else() - message( - STATUS - "mujoco::FindOrFetch: Attempting to fetch `${_ARGS_LIBRARY_NAME}` from `${_ARGS_GIT_REPO}`..." + message(CHECK_START + "mujoco::FindOrFetch: Using FetchContent to retrieve `${_ARGS_LIBRARY_NAME}`" ) FetchContent_Declare( ${_ARGS_LIBRARY_NAME} @@ -118,11 +131,9 @@ macro(FindOrFetch) else() FetchContent_MakeAvailable(${_ARGS_LIBRARY_NAME}) endif() - message( - STATUS "mujoco::FindOrFetch: Fetched `${_ARGS_LIBRARY_NAME}` from `${_ARGS_GIT_REPO}`." - ) + message(CHECK_PASS "Done") endif() else() - message(STATUS "mujoco::FindOrFetch: `${_ARGS_PACKAGE_NAME}` targets found.") + message(CHECK_PASS "found") endif() endmacro() diff --git a/cmake/MujocoDependencies.cmake b/cmake/MujocoDependencies.cmake new file mode 100644 index 00000000..56a1e645 --- /dev/null +++ b/cmake/MujocoDependencies.cmake @@ -0,0 +1,327 @@ +# Copyright 2021 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. + +# Build configuration for third party libraries used in MuJoCo. + +# Override the BUILD_SHARED_LIBS setting, just for building third party libs (since we always want +# static libraries). The ccd CMakeLists.txt doesn't expose an option to build a static ccd library, +# unless BUILD_SHARED_LIBS is set. + +set(MUJOCO_DEP_VERSION_lodepng + 48e5364ef48ec2408f44c727657ac1b6703185f8 + CACHE STRING "Version of `lodepng` to be fetched." +) +set(MUJOCO_DEP_VERSION_tinyxml2 + 1dee28e51f9175a31955b9791c74c430fe13dc82 # 9.0.0 + CACHE STRING "Version of `tinyxml2` to be fetched." +) +set(MUJOCO_DEP_VERSION_tinyobjloader + 1421a10d6ed9742f5b2c1766d22faa6cfbc56248 + CACHE STRING "Version of `tinyobjloader` to be fetched." +) +set(MUJOCO_DEP_VERSION_ccd + 7931e764a19ef6b21b443376c699bbc9c6d4fba8 # v2.1 + CACHE STRING "Version of `ccd` to be fetched." +) +set(MUJOCO_DEP_VERSION_qhull + 3df027b91202cf179f3fba3c46eebe65bbac3790 + CACHE STRING "Version of `qhull` to be fetched." +) +set(MUJOCO_DEP_VERSION_Eigen3 + b02c384ef4e8eba7b8bdef16f9dc6f8f4d6a6b2b + CACHE STRING "Version of `Eigen3` to be fetched." +) + +set(MUJOCO_DEP_VERSION_abseil + 78f9680225b9792c26dfdd99d0bd26c96de53dd4 # Fixes universal builds for macOS + CACHE STRING "Version of `abseil` to be fetched." +) + +set(MUJOCO_DEP_VERSION_gtest + e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0 + CACHE STRING "Version of `gtest` to be fetched." +) + +set(MUJOCO_DEP_VERSION_benchmark + 0d98dba29d66e93259db7daa53a9327df767a415 # v1.6.1 + CACHE STRING "Version of `benchmark` to be fetched." +) + +mark_as_advanced(MUJOCO_DEP_VERSION_lodepng) +mark_as_advanced(MUJOCO_DEP_VERSION_tinyxml2) +mark_as_advanced(MUJOCO_DEP_VERSION_tinyobjloader) +mark_as_advanced(MUJOCO_DEP_VERSION_ccd) +mark_as_advanced(MUJOCO_DEP_VERSION_qhull) +mark_as_advanced(MUJOCO_DEP_VERSION_Eigen3) +mark_as_advanced(MUJOCO_DEP_VERSION_abseil) +mark_as_advanced(MUJOCO_DEP_VERSION_gtest) +mark_as_advanced(MUJOCO_DEP_VERSION_benchmark) + +include(FetchContent) +include(FindOrFetch) + +# We force all the dependencies to be compiled as static libraries. +# TODO(fraromano) Revisit this choice when adding support for install. +set(BUILD_SHARED_LIBS_OLD ${BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS + OFF + CACHE INTERNAL "Build SHARED libraries" +) + +if(NOT TARGET lodepng) + FetchContent_Declare( + lodepng + GIT_REPOSITORY https://github.com/lvandeve/lodepng.git + GIT_TAG ${MUJOCO_DEP_VERSION_lodepng} + ) + + FetchContent_GetProperties(lodepng) + if(NOT lodepng_POPULATED) + FetchContent_Populate(lodepng) + # This is not a CMake project. + set(LODEPNG_SRCS ${lodepng_SOURCE_DIR}/lodepng.cpp) + set(LODEPNG_HEADERS ${lodepng_SOURCE_DIR}/lodepng.h) + add_library(lodepng STATIC ${LODEPNG_HEADERS} ${LODEPNG_SRCS}) + target_compile_options(lodepng PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS}) + target_link_options(lodepng PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS}) + target_include_directories(lodepng PUBLIC ${lodepng_SOURCE_DIR}) + endif() +endif() + +# TODO(fraromano) We fetch qhull before the other libraries as it needs to go before until https://github.com/qhull/qhull/pull/111 is merged. +set(QHULL_ENABLE_TESTING OFF) +# We need Git to apply the patch using git apply. +find_package(Git REQUIRED) + +findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + qhull + LIBRARY_NAME + qhull + GIT_REPO + https://github.com/qhull/qhull.git + GIT_TAG + ${MUJOCO_DEP_VERSION_qhull} + TARGETS + qhull + # TODO(fraromano) Remove when https://github.com/qhull/qhull/pull/112 is merged. + # Do not fail if patch fails. This will happen the second time we run CMake as the sources will be already patched. + PATCH_COMMAND + "${GIT_EXECUTABLE}" + "apply" + "-q" + "${PROJECT_SOURCE_DIR}/cmake/qhull_fix_testing.patch" + "||" + "${CMAKE_COMMAND}" + "-E" + "true" + EXCLUDE_FROM_ALL +) +# MuJoCo includes a file from libqhull_r which is not exported by the qhull include directories. +# Add it to the target. +target_include_directories( + qhullstatic_r INTERFACE $ +) +target_compile_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS}) +target_link_options(qhullstatic_r PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS}) + +set(tinyxml2_BUILD_TESTING OFF) +findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + tinyxml2 + LIBRARY_NAME + tinyxml2 + GIT_REPO + https://github.com/leethomason/tinyxml2.git + GIT_TAG + ${MUJOCO_DEP_VERSION_tinyxml2} + TARGETS + tinyxml2 + EXCLUDE_FROM_ALL +) +target_compile_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS}) +target_link_options(tinyxml2 PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS}) + +findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + tinyobjloader + LIBRARY_NAME + tinyobjloader + GIT_REPO + https://github.com/tinyobjloader/tinyobjloader.git + GIT_TAG + ${MUJOCO_DEP_VERSION_tinyobjloader} + TARGETS + tinyobjloader + EXCLUDE_FROM_ALL +) + +set(ENABLE_DOUBLE_PRECISION ON) +set(CCD_HIDE_ALL_SYMBOLS ON) +findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + ccd + LIBRARY_NAME + ccd + GIT_REPO + https://github.com/danfis/libccd.git + GIT_TAG + ${MUJOCO_DEP_VERSION_ccd} + TARGETS + ccd + EXCLUDE_FROM_ALL +) +target_compile_options(ccd PRIVATE ${MUJOCO_MACOS_COMPILE_OPTIONS}) +target_link_options(ccd PRIVATE ${MUJOCO_MACOS_LINK_OPTIONS}) + +# libCCD has an unconditional `#define _CRT_SECURE_NO_WARNINGS` on Windows. +# TODO(stunya): Remove this after https://github.com/danfis/libccd/pull/77 is merged. +if(WIN32) + if(MSVC) + # C4005 is the MSVC equivalent of -Wmacro-redefined. + target_compile_options(ccd PRIVATE /wd4005) + else() + target_compile_options(ccd PRIVATE -Wno-macro-redefined) + endif() +endif() + +if(MUJOCO_BUILD_TESTS) + set(ABSL_PROPAGATE_CXX_STD ON) + + # This specific version of Abseil does not have the following variable. We need to work with BUILD_TESTING + set(BUILD_TESTING_OLD ${BUILD_TESTING}) + set(BUILD_TESTING + OFF + CACHE INTERNAL "Build tests." + ) + + set(ABSL_BUILD_TESTING OFF) + findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + absl + LIBRARY_NAME + abseil-cpp + GIT_REPO + https://github.com/abseil/abseil-cpp.git + GIT_TAG + ${MUJOCO_DEP_VERSION_abseil} + TARGETS + absl::core_headers + EXCLUDE_FROM_ALL + ) + + set(BUILD_TESTING + ${BUILD_TESTING_OLD} + CACHE BOOL "Build tests." FORCE + ) + + # Avoid linking errors on Windows by dynamically linking to the C runtime. + set(gtest_force_shared_crt + ON + CACHE BOOL "" FORCE + ) + + findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + GTest + LIBRARY_NAME + googletest + GIT_REPO + https://github.com/google/googletest.git + GIT_TAG + ${MUJOCO_DEP_VERSION_gtest} + TARGETS + gtest + gmock + gtest_main + EXCLUDE_FROM_ALL + ) + + set(BENCHMARK_EXTRA_FETCH_ARGS "") + if(WIN32 AND NOT MSVC) + set(BENCHMARK_EXTRA_FETCH_ARGS + PATCH_COMMAND + "sed" + "-i" + "-e" + "s/-std=c++11/-std=c++14/g" + "-e" + "s/HAVE_CXX_FLAG_STD_CXX11/HAVE_CXX_FLAG_STD_CXX14/g" + "${CMAKE_BINARY_DIR}/_deps/benchmark-src/CMakeLists.txt" + ) + endif() + + set(BENCHMARK_ENABLE_TESTING OFF) + + findorfetch( + USE_SYSTEM_PACKAGE + OFF + PACKAGE_NAME + benchmark + LIBRARY_NAME + benchmark + GIT_REPO + https://github.com/google/benchmark.git + GIT_TAG + ${MUJOCO_DEP_VERSION_benchmark} + TARGETS + benchmark::benchmark + benchmark::benchmark_main + ${BENCHMARK_EXTRA_FETCH_ARGS} + EXCLUDE_FROM_ALL + ) +endif() + +if(MUJOCO_TEST_PYTHON_UTIL) + add_compile_definitions(EIGEN_MPL2_ONLY) + if(NOT TARGET eigen) + # Support new IN_LIST if() operator. + set(CMAKE_POLICY_DEFAULT_CMP0057 NEW) + + FetchContent_Declare( + Eigen3 + GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git + GIT_TAG ${MUJOCO_DEP_VERSION_Eigen3} + ) + + FetchContent_GetProperties(Eigen3) + if(NOT Eigen3_POPULATED) + FetchContent_Populate(Eigen3) + + # Mark the library as IMPORTED as a workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/15415 + add_library(Eigen3::Eigen INTERFACE IMPORTED) + set_target_properties( + Eigen3::Eigen PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${eigen3_SOURCE_DIR}" + ) + endif() + endif() +endif() + +# Reset BUILD_SHARED_LIBS to its previous value +set(BUILD_SHARED_LIBS + ${BUILD_SHARED_LIBS_OLD} + CACHE BOOL "Build MuJoCo as a shared library" FORCE +) diff --git a/cmake/MujocoHarden.cmake b/cmake/MujocoHarden.cmake new file mode 100644 index 00000000..7beb88fe --- /dev/null +++ b/cmake/MujocoHarden.cmake @@ -0,0 +1,35 @@ +# Copyright 2022 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. + +option(MUJOCO_HARDEN "Enable build hardening for MuJoCo." OFF) +if(MUJOCO_HARDEN + AND NOT + CMAKE_CXX_COMPILER_ID + MATCHES + ".*Clang.*" +) + message(FATAL_ERROR "MUJOCO_HARDEN is only supported when building with Clang") +endif() + +if(MUJOCO_HARDEN) + set(MUJOCO_HARDEN_COMPILE_OPTIONS -D_FORTIFY_SOURCE=2 -fstack-protector) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-bind_at_load) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") + set(MUJOCO_HARDEN_LINK_OPTIONS -Wl,-z,relro -Wl,-z,now) + endif() +else() + set(MUJOCO_HARDEN_COMPILE_OPTIONS "") + set(MUJOCO_HARDEN_LINK_OPTIONS "") +endif() diff --git a/cmake/MujocoMacOS.cmake b/cmake/MujocoMacOS.cmake new file mode 100644 index 00000000..d2f378f6 --- /dev/null +++ b/cmake/MujocoMacOS.cmake @@ -0,0 +1,38 @@ +# Copyright 2022 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. + +if(APPLE) + # 10.12 is the oldest version of macOS that supports C++17, launched 2016. + set(MUJOCO_MACOSX_VERSION_MIN 10.12) + + # We are setting the -mmacosx-version-min compiler flag directly rather than using the + # CMAKE_OSX_DEPLOYMENT_TARGET variable since we do not want to affect choice of SDK, + # and also we only want to apply the version restriction locally. + set(MUJOCO_MACOS_COMPILE_OPTIONS -mmacosx-version-min=${MUJOCO_MACOSX_VERSION_MIN} + -Werror=partial-availability -Werror=unguarded-availability + ) + set(MUJOCO_MACOS_LINK_OPTIONS -mmacosx-version-min=${MUJOCO_MACOSX_VERSION_MIN} + -Wl,-no_weak_imports + ) +else() + set(MUJOCO_MACOS_COMPILE_OPTIONS "") + set(MUJOCO_MACOS_LINK_OPTIONS "") +endif() + +function(enforce_mujoco_macosx_min_version) + if(APPLE) + add_compile_options(${MUJOCO_MACOS_COMPILE_OPTIONS}) + add_link_options(${MUJOCO_MACOS_LINK_OPTIONS}) + endif() +endfunction() diff --git a/cmake/MujocoOptions.cmake b/cmake/MujocoOptions.cmake new file mode 100644 index 00000000..2b0ce938 --- /dev/null +++ b/cmake/MujocoOptions.cmake @@ -0,0 +1,106 @@ +# Copyright 2021 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. + +# Global compilation settings +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_EXTENSIONS OFF) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For LLVM tooling + +if(NOT CMAKE_CONFIGURATION_TYPES) + if(NOT CMAKE_BUILD_TYPE) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE + "Release" + CACHE STRING "Choose the type of build, recommanded options are: Debug or Release" FORCE + ) + endif() + set(BUILD_TYPES + "Debug" + "Release" + "MinSizeRel" + "RelWithDebInfo" + ) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${BUILD_TYPES}) +endif() + +include(GNUInstallDirs) + +# Change the default output directory in the build structure. This is not stricly needed, but helps +# running in Windows, such that all built executables have DLLs in the same folder as the .exe +# files. +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") + +set(OpenGL_GL_PREFERENCE GLVND) + +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) + +if(MSVC) + add_compile_options(/Gy /Gw /Oi) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-fdata-sections -ffunction-sections) +endif() + +# We default to shared library. +set(BUILD_SHARED_LIBS + ON + CACHE BOOL "Build Mujoco as shared library." +) + +option(MUJOCO_ENABLE_AVX "Build binaries that require AVX instructions, if possible." ON) +option(MUJOCO_ENABLE_AVX_INTRINSICS "Make use of hand-written AVX intrinsics, if possible." ON) +option(MUJOCO_ENABLE_RPATH "Enable RPath support when installing Mujoco." ON) +mark_as_advanced(MUJOCO_ENABLE_RPATH) + +if(MUJOCO_ENABLE_AVX) + include(CheckAvxSupport) + get_avx_compile_options(AVX_COMPILE_OPTIONS) +else() + set(AVX_COMPILE_OPTIONS) +endif() + +option(MUJOCO_BUILD_MACOS_FRAMEWORKS "Build libraries as macOS Frameworks" OFF) + +# Get some extra link options. +include(MujocoLinkOptions) +get_mujoco_extra_link_options(EXTRA_LINK_OPTIONS) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC)) + set(EXTRA_COMPILE_OPTIONS -Wall -Werror) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(EXTRA_COMPILE_OPTIONS + -Wno-int-in-bool-context + -Wno-maybe-uninitialized + -Wno-sign-compare + -Wno-stringop-overflow + -Wno-stringop-truncation + ) + endif() +endif() + +if(WIN32) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +endif() + +include(MujocoHarden) +set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} ${MUJOCO_HARDEN_COMPILE_OPTIONS}) +set(EXTRA_LINK_OPTIONS ${EXTRA_LINK_OPTIONS} ${MUJOCO_HARDEN_LINK_OPTIONS}) diff --git a/cmake/TargetAddRpath.cmake b/cmake/TargetAddRpath.cmake new file mode 100644 index 00000000..370cb46d --- /dev/null +++ b/cmake/TargetAddRpath.cmake @@ -0,0 +1,188 @@ +# Copyright 2022 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. +# +#[=======================================================================[.rst: +TargetAddRpath +---------------------- + +Add support to RPATH for the specified targets + +.. command:: target_add_rpath + + Add support to RPATH for the specified targets:: + +.. code-block:: cmake + target_add_rpath(target1 target2 ... + INSTALL_DIRECTORY install_directory + LIB_DIRS dir1 dir2 ... + [INSTALL_NAME_DIR [dir]] + [DEPENDS condition [condition]] + [USE_LINK_PATH]) + + This function setups the RPATH paths for the specified targets. The use of + RPATH allows to avoid using the (dangerous) environment variable + ``LD_LIBRARY_PATH`` (or equivalent on macOS) when installing without absolute + paths. + By using RPATH the installation can be relocated as the linker will look for + (some of) the dependencies at run time. + + The function has the following parameters: + + Options: + - ``USE_LINK_PATH``: if defined, the function will set + ``INSTALL_RPATH_USE_LINK_PATH`` on all the specified targets, i.e. CMake + will automatically adds to the RPATH the path to all the dependent + libraries defined outside this project. + + Arguments: + - ``INSTALL_DIRECTORY`` The directory where the specified targets will be + installed. + - ``LIB_DIRS`` list of directories to be added a search path to the RPATH. + Note that the relative path between ``INSTALL_DIRECTORY`` and these + directories will be added to the RPATH. + - ``INSTALL_NAME_DIR`` directory where the libraries will be installed. + This variable will be used only if ``CMAKE_SKIP_RPATH`` or + ``CMAKE_SKIP_INSTALL_RPATH`` is set to ``TRUE`` as it will set the + ``INSTALL_NAME_DIR`` on all targets. + - ``DEPENDS`` list of conditions that should be ``TRUE`` to enable + RPATH, for example ``FOO; NOT BAR``. + + Note: see https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + and https://gitlab.kitware.com/cmake/cmake/issues/16589 for further details. + +#]=======================================================================] + +if(COMMAND target_add_rpath) + return() +endif() + +function(_get_system_dirs _output_var) + set(${_output_var} + ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} + PARENT_SCOPE + ) +endfunction() + +function( + _get_rpath_relative_path + _output_var + _bin_dir + _lib_dir +) + file( + RELATIVE_PATH + _rel_path + ${_bin_dir} + ${_lib_dir} + ) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(${_output_var} + "@loader_path/${_rel_path}" + PARENT_SCOPE + ) + else() + set(${_output_var} + "\$ORIGIN/${_rel_path}" + PARENT_SCOPE + ) + endif() +endfunction() + +function(target_add_rpath) + set(_options USE_LINK_PATH) + set(_oneValueArgs INSTALL_NAME_DIR INSTALL_DIRECTORY) + set(_multiValueArgs TARGETS LIB_DIRS DEPENDS) + + cmake_parse_arguments( + _ARGS + "${_options}" + "${_oneValueArgs}" + "${_multiValueArgs}" + "${ARGN}" + ) + + # Handle Apple-specific installation directory. Note that this disable proper RPATH. + if(CMAKE_SKIP_RPATH OR CMAKE_SKIP_INSTALL_RPATH) + if(DEFINED _ARGS_INSTALL_NAME_DIR) + set_target_properties(${_ARGS_TARGETS} PROPERTIES INSTALL_NAME_DIR ${_ARGS_INSTALL_NAME_DIR}) + endif() + endif() + + # If RPATH is disabled, do nothing and return. + if(CMAKE_SKIP_RPATH OR (CMAKE_SKIP_INSTALL_RPATH AND CMAKE_SKIP_BUILD_RPATH)) + return() + endif() + + # Check if the user requested RPATH for the specified targets. + set(_enable_rpath ON) + if(DEFINED _ARGS_DEPENDS) + foreach(_cond ${_ARGS_DEPENDS}) + string( + REGEX + REPLACE " +" + ";" + _cond + "${_cond}" + ) + if(NOT (${_cond})) + set(_enable_rpath OFF) + endif() + endforeach() + endif() + + if(NOT _enable_rpath) + return() + endif() + + # Now enable RPATH for the specified targets. + _get_system_dirs(_system_dirs) + + # We do this per target to preserve the original rpath setting. + foreach(_target ${_ARGS_TARGETS}) + get_target_property(_install_rpath ${_target} INSTALL_RPATH) + + foreach(_lib_dir ${_ARGS_LIB_DIRS}) + # Check if the specified library path is a system directory. These are always searched so we do + # not need to include them in the RPATH. + list( + FIND + _system_dirs + "${_lib_dir}" + is_system_dir + ) + if("${is_system_dir}" STREQUAL "-1") + + _get_rpath_relative_path(_bin_lib_rel_path ${_ARGS_INSTALL_DIRECTORY} ${_lib_dir}) + list(APPEND _install_rpath ${_bin_lib_rel_path}) + + endif() + endforeach() + + if(NOT + "${_install_rpath}" + STREQUAL + "" + ) + list(REMOVE_DUPLICATES _install_rpath) + endif() + + set_target_properties( + ${_target} + PROPERTIES INSTALL_RPATH ${_install_rpath} + INSTALL_RPATH_USE_LINK_PATH ${_ARGS_USE_LINK_PATH} + MACOSX_RPATH ON # This is ON by default. + ) + endforeach() + +endfunction() diff --git a/cmake/cleanup_test_dir.sh b/cmake/cleanup_test_dir.sh new file mode 100755 index 00000000..ed333b31 --- /dev/null +++ b/cmake/cleanup_test_dir.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# Copyright 2021 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 +# +# http://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. + +if [ -z "$1" ]; then + echo "Expecting an output directory. Got none." 1>&2 + exit 1 +fi + +rm -rf "$1" diff --git a/cmake/mujocoConfig.cmake.in b/cmake/mujocoConfig.cmake.in new file mode 100644 index 00000000..d00d1cc4 --- /dev/null +++ b/cmake/mujocoConfig.cmake.in @@ -0,0 +1,24 @@ +# Copyright 2021 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. + +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_dependency(OpenGL) + +if(NOT TARGET mujoco AND NOT @PROJECT_NAME@_BINARY_DIR) + include("${CMAKE_CURRENT_LIST_DIR}/mujocoTargets.cmake") +endif() + +check_required_components(mujoco) diff --git a/cmake/qhull_fix_testing.patch b/cmake/qhull_fix_testing.patch new file mode 100644 index 00000000..9236cbd3 --- /dev/null +++ b/cmake/qhull_fix_testing.patch @@ -0,0 +1,92 @@ +From 2bf2d1f5151d0d36cd17dea03129bd9a825384c5 Mon Sep 17 00:00:00 2001 +From: Francesco Romano +Date: Fri, 6 May 2022 11:30:44 +0100 +Subject: [PATCH] Add option to disable testing + +--- + CMakeLists.txt | 55 ++++++++++++++++++++++++++------------------------ + 1 file changed, 29 insertions(+), 26 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cd95ad0..6ff1c98 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -113,6 +113,7 @@ cmake_dependent_option(LINK_APPS_SHARED "Use shared library for linking applicat + "BUILD_SHARED_LIBS;BUILD_STATIC_LIBS" + ${BUILD_SHARED_LIBS} + ) ++option(QHULL_ENABLE_TESTING "Build and run tests" ON) + + if(INCLUDE_INSTALL_DIR) + else() +@@ -147,6 +148,7 @@ message(STATUS "Build Type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}") + message(STATUS "Build static libraries: ${BUILD_STATIC_LIBS}") + message(STATUS "Build shared library: ${BUILD_SHARED_LIBS}") + message(STATUS "Use shared library for linking apps: ${LINK_APPS_SHARED}") ++message(STATUS "Build tests: ${QHULL_ENABLE_TESTING}") + message(STATUS "To override these options, add -D{OPTION_NAME}=... to the cmake command") + message(STATUS " Build the debug targets -DCMAKE_BUILD_TYPE=Debug") + message(STATUS) +@@ -636,32 +638,33 @@ set_target_properties(user_egp PROPERTIES + # --------------------------------------- + # Define test + # --------------------------------------- +- +-enable_testing() +-add_test(NAME testqset +- COMMAND ./testqset 10000) +-add_test(NAME testqset_r +- COMMAND ./testqset_r 10000) +-add_test(NAME smoketest +- COMMAND sh -c "./rbox D4 | ./qhull Tv") +-add_test(NAME rbox-10-qhull +- COMMAND sh -c "./rbox 10 | ./qhull Tv") +-add_test(NAME rbox-10-qconvex +- COMMAND sh -c "./rbox 10 | ./qconvex Tv") +-add_test(NAME rbox-10-qdelaunay +- COMMAND sh -c "./rbox 10 | ./qdelaunay Tv") +-add_test(NAME rbox-10-qhalf +- COMMAND sh -c "./rbox 10 | ./qconvex FQ FV n Tv | ./qhalf Tv") +-add_test(NAME rbox-10-qvoronoi +- COMMAND sh -c "./rbox 10 | ./qvoronoi Tv") +-add_test(NAME user_eg +- COMMAND sh -c "./user_eg") +-add_test(NAME user_eg2 +- COMMAND sh -c "./user_eg2") +- +-if(${BUILD_STATIC_LIBS}) +- add_test(NAME user_eg3 +- COMMAND sh -c "./user_eg3 rbox '10 D2' '2 D2' qhull 's p' facets") ++if (QHULL_ENABLE_TESTING) ++ enable_testing() ++ add_test(NAME testqset ++ COMMAND ./testqset 10000) ++ add_test(NAME testqset_r ++ COMMAND ./testqset_r 10000) ++ add_test(NAME smoketest ++ COMMAND sh -c "./rbox D4 | ./qhull Tv") ++ add_test(NAME rbox-10-qhull ++ COMMAND sh -c "./rbox 10 | ./qhull Tv") ++ add_test(NAME rbox-10-qconvex ++ COMMAND sh -c "./rbox 10 | ./qconvex Tv") ++ add_test(NAME rbox-10-qdelaunay ++ COMMAND sh -c "./rbox 10 | ./qdelaunay Tv") ++ add_test(NAME rbox-10-qhalf ++ COMMAND sh -c "./rbox 10 | ./qconvex FQ FV n Tv | ./qhalf Tv") ++ add_test(NAME rbox-10-qvoronoi ++ COMMAND sh -c "./rbox 10 | ./qvoronoi Tv") ++ add_test(NAME user_eg ++ COMMAND sh -c "./user_eg") ++ add_test(NAME user_eg2 ++ COMMAND sh -c "./user_eg2") ++ ++ if(${BUILD_STATIC_LIBS}) ++ add_test(NAME user_eg3 ++ COMMAND sh -c "./user_eg3 rbox '10 D2' '2 D2' qhull 's p' facets") ++ endif() + endif() + + # --------------------------------------- +-- +2.36.0.512.ge40c2bad7a-goog + diff --git a/cmake/setup_test_dir.sh b/cmake/setup_test_dir.sh new file mode 100755 index 00000000..46ec06db --- /dev/null +++ b/cmake/setup_test_dir.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Copyright 2021 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 +# +# http://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. + +if [ -z "$1" ]; then + echo "Expecting an output directory. Got none." 1>&2 + exit 1 +fi + +mkdir -p "$1" +rm -rf "$1/*" diff --git a/dist/Info.plist.framework.in b/dist/Info.plist.framework.in new file mode 100644 index 00000000..e084b7df --- /dev/null +++ b/dist/Info.plist.framework.in @@ -0,0 +1,30 @@ + + + + + CFBundleName + MuJoCo + CFBundleIdentifier + org.mujoco.mujoco + CFBundleVersion + ${PROJECT_VERSION} + CFBundleGetInfoString + ${PROJECT_VERSION} + CFBundleExecutable + libmujoco.dylib + CFBundlePackageType + FMWK + NSHumanReadableCopyright + Copyright 2021 DeepMind Technologies Limited. + MDItemKeywords + MuJoCo, physics engine, physics simulator, physics, MJ + CFBundleInfoDictionaryVersion + 6.0 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + MacOSX + + + diff --git a/dist/Info.plist.simulate.in b/dist/Info.plist.simulate.in new file mode 100644 index 00000000..2397bf8c --- /dev/null +++ b/dist/Info.plist.simulate.in @@ -0,0 +1,36 @@ + + + + + CFBundleName + ${MACOSX_BUNDLE_BUNDLE_NAME} + CFBundleIdentifier + ${MACOSX_BUNDLE_GUI_IDENTIFIER} + CFBundleVersion + ${MACOSX_BUNDLE_BUNDLE_VERSION} + CFBundleGetInfoString + ${MACOSX_BUNDLE_INFO_STRING} + CFBundleLongVersionString + ${MACOSX_BUNDLE_LONG_VERSION_STRING} + CFBundleShortVersionString + ${MACOSX_BUNDLE_SHORT_VERSION_STRING} + CFBundleExecutable + simulate + CFBundleIconFile + ${MACOSX_BUNDLE_ICON_FILE} + CFBundlePackageType + APPL + NSHumanReadableCopyright + ${MACOSX_BUNDLE_COPYRIGHT} + MDItemKeywords + MuJoCo, physics engine, physics simulator, physics, simulate, MJ, mujoco simulate, mj simulate + CFBundleInfoDictionaryVersion + 6.0 + CFBundleDevelopmentRegion + en + CFBundleSupportedPlatforms + + MacOSX + + + diff --git a/dist/appicon.rc b/dist/appicon.rc new file mode 100644 index 00000000..b46fbcea --- /dev/null +++ b/dist/appicon.rc @@ -0,0 +1 @@ +IDI_ICON1 ICON DISCARDABLE "mujoco.ico" diff --git a/dist/module.modulemap b/dist/module.modulemap new file mode 100644 index 00000000..8fac4abc --- /dev/null +++ b/dist/module.modulemap @@ -0,0 +1,6 @@ +framework module mujoco { + umbrella header "mujoco.h" + + export * + module * { export * } +} diff --git a/dist/mujoco.icns b/dist/mujoco.icns new file mode 100644 index 00000000..b979247c Binary files /dev/null and b/dist/mujoco.icns differ diff --git a/dist/mujoco.ico b/dist/mujoco.ico new file mode 100644 index 00000000..145a5810 Binary files /dev/null and b/dist/mujoco.ico differ diff --git a/doc/APIreference.rst b/doc/APIreference.rst index 4e3af9e5..9d171bb0 100644 --- a/doc/APIreference.rst +++ b/doc/APIreference.rst @@ -38,7 +38,7 @@ mjtNum typedef float mjtNum; #endif -| Defined in `mjtnum.h `_ +| Defined in `mjtnum.h `_ | This is the floating-point type used throughout the simulator. If the symbol ``mjUSEDOUBLE`` is defined in ``mjmodel.h``, this type is defined as ``double``, otherwise it is defined as ``float``. Currently only the @@ -61,7 +61,7 @@ mjtByte typedef unsigned char mjtByte; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Byte type used to represent boolean variables. @@ -90,7 +90,7 @@ mjtDisableBit mjNDISABLE = 12 // number of disable flags } mjtDisableBit; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Constants which are powers of 2. They are used as bitmasks for the field ``disableflags`` of :ref:`mjOption`. At runtime this field is ``m->opt.disableflags``. The number of these constants is given by ``mjNDISABLE`` which is @@ -117,7 +117,7 @@ mjtEnableBit mjNENABLE = 5 // number of enable flags } mjtEnableBit; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Constants which are powers of 2. They are used as bitmasks for the field ``enableflags`` of :ref:`mjOption`. At runtime this field is ``m->opt.enableflags``. The number of these constants is given by ``mjNENABLE`` which is also @@ -138,7 +138,7 @@ mjtJoint mjJNT_HINGE // rotation angle (rad) around body-fixed axis (1) } mjtJoint; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Primitive joint types. These values are used in ``m->jnt_type``. The numbers in the comments indicate how many positional coordinates each joint type has. Note that ball joints and rotational components of free joints are @@ -176,7 +176,7 @@ mjtGeom mjGEOM_NONE = 1001 // missing geom type } mjtGeom; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Geometric types supported by MuJoCo. The first group are "official" geom types that can be used in the model. The second group are geom types that cannot be used in the model but are used by the visualizer to add decorative @@ -198,7 +198,7 @@ mjtCamLight mjCAMLIGHT_TARGETBODYCOM // pos fixed in body, rot tracks target subtree com } mjtCamLight; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Dynamic modes for cameras and lights, specifying how the camera/light position and orientation are computed. These values are used in ``m->cam_mode`` and ``m->light_mode``. @@ -217,7 +217,7 @@ mjtTexture mjTEXTURE_SKYBOX // cube texture used as skybox } mjtTexture; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Texture types, specifying how the texture will be mapped. These values are used in ``m->tex_type``. @@ -234,7 +234,7 @@ mjtIntegrator mjINT_RK4 // 4th-order Runge Kutta } mjtIntegrator; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Numerical integrator types. These values are used in ``m->opt.integrator``. @@ -252,7 +252,7 @@ mjtCollision mjCOL_DYNAMIC // test dynamic pairs only } mjtCollision; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Collision modes specifying how candidate geom pairs are generated for near-phase collision checking. These values are used in ``m->opt.collision``. @@ -270,7 +270,7 @@ mjtCone mjCONE_ELLIPTIC // elliptic } mjtCone; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Available friction cone types. These values are used in ``m->opt.cone``. @@ -288,7 +288,7 @@ mjtJacobian mjJAC_AUTO // dense if nv<=60, sparse otherwise } mjtJacobian; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Available Jacobian types. These values are used in ``m->opt.jacobian``. @@ -306,7 +306,7 @@ mjtSolver mjSOL_NEWTON // Newton (primal) } mjtSolver; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Available constraint solver algorithms. These values are used in ``m->opt.solver``. @@ -326,7 +326,7 @@ mjtEq mjEQ_DISTANCE // fix the contact distance betweent two geoms } mjtEq; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Equality constraint types. These values are used in ``m->eq_type``. @@ -347,7 +347,7 @@ mjtWrap mjWRAP_CYLINDER // wrap around (infinite) cylinder } mjtWrap; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Tendon wrapping object types. These values are used in ``m->wrap_type``. @@ -369,7 +369,7 @@ mjtTrn mjTRN_UNDEFINED = 1000 // undefined transmission type } mjtTrn; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Actuator transmission types. These values are used in ``m->actuator_trntype``. @@ -389,7 +389,7 @@ mjtDyn mjDYN_USER // user-defined dynamics type } mjtDyn; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Actuator dynamics types. These values are used in ``m->actuator_dyntype``. @@ -407,7 +407,7 @@ mjtGain mjGAIN_USER // user-defined gain type } mjtGain; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Actuator gain types. These values are used in ``m->actuator_gaintype``. @@ -426,7 +426,7 @@ mjtBias mjBIAS_USER // user-defined bias type } mjtBias; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Actuator bias types. These values are used in ``m->actuator_biastype``. @@ -465,7 +465,7 @@ mjtObj mjOBJ_KEY // keyframe } mjtObj; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | MuJoCo object types. These values are used in the support functions :ref:`mj_name2id` and :ref:`mj_id2name` to convert between object names and integer ids. @@ -489,7 +489,7 @@ mjtConstraint mjCNSTR_CONTACT_ELLIPTIC // frictional contact, elliptic friction cone } mjtConstraint; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Constraint types. These values are not used in mjModel, but are used in the mjData field ``d->efc_type`` when the list of active constraints is constructed at each simulation time step. @@ -510,7 +510,7 @@ mjtConstraintState mjCNSTRSTATE_CONE // squared distance to cone cost (elliptic contact) } mjtConstraintState; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | These values are used by the solver internally to keep track of the constraint states. @@ -574,7 +574,7 @@ mjtSensor mjSENS_USER // sensor data provided by mjcb_sensor callback } mjtSensor; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | Sensor types. These values are used in ``m->sensor_type``. @@ -593,7 +593,7 @@ mjtStage mjSTAGE_ACC // acceleration/force-dependent computations } mjtStage; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | These are the compute stages for the skipstage parameters of :ref:`mj_forwardSkip` and :ref:`mj_inverseSkip`. @@ -613,7 +613,7 @@ mjtDataType mjDATATYPE_QUATERNION // unit quaternion } mjtDataType; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | These are the possible sensor data types, used in ``mjData.sensor_datatype``. @@ -638,7 +638,7 @@ mjtWarning mjNWARNING // number of warnings } mjtWarning; -| Defined in `mjdata.h `_ +| Defined in `mjdata.h `_ | Warning types. The number of warning types is given by ``mjNWARNING`` which is also the length of the array ``mjData.warning``. @@ -674,7 +674,7 @@ mjtTimer mjNTIMER // number of timers } mjtTimer; -| Defined in `mjdata.h `_ +| Defined in `mjdata.h `_ | Timer types. The number of timer types is given by ``mjNTIMER`` which is also the length of the array ``mjData.timer``, as well as the length of the string array :ref:`mjTIMERSTRING` with timer names. @@ -694,7 +694,7 @@ mjtCatBit mjCAT_ALL = 7 // select all categories } mjtCatBit; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are the available categories of geoms in the abstract visualizer. The bitmask can be used in the function :ref:`mjr_render` to specify which categories should be rendered. @@ -717,7 +717,7 @@ mjtMouse mjMOUSE_SELECT // selection } mjtMouse; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are the mouse actions that the abstract visualizer recognizes. It is up to the user to intercept mouse events and translate them into these actions, as illustrated in ``simulate.cc``. @@ -735,7 +735,7 @@ mjtPertBit mjPERT_ROTATE = 2 // rotation } mjtPertBit; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These bitmasks enable the translational and rotational components of the mouse perturbation. For the regular mouse, only one can be enabled at a time. For the 3D mouse (SpaceNavigator) both can be enabled simultaneously. They are used @@ -756,7 +756,7 @@ mjtCamera mjCAMERA_USER // user is responsible for setting OpenGL camera } mjtCamera; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are the possible camera types, used in ``mjvCamera.type``. @@ -787,7 +787,7 @@ mjtLabel mjNLABEL // number of label types } mjtLabel; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are the abstract visualization elements that can have text labels. Used in ``mjvOption.label``. @@ -811,7 +811,7 @@ mjtFrame mjNFRAME // number of visualization frames } mjtFrame; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are the MuJoCo objects whose spatial frames can be rendered. Used in ``mjvOption.frame``. @@ -850,7 +850,7 @@ mjtVisFlag mjNVISFLAG // number of visualization flags } mjtVisFlag; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are indices in the array ``mjvOption.flags``, whose elements enable/disable the visualization of the corresponding model or decoration element. @@ -877,7 +877,7 @@ mjtRndFlag mjNRNDFLAG // number of rendering flags } mjtRndFlag; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are indices in the array ``mjvScene.flags``, whose elements enable/disable OpenGL rendering effects. @@ -895,7 +895,7 @@ mjtStereo mjSTEREO_SIDEBYSIDE // side-by-side } mjtStereo; -| Defined in `mjvisualize.h `_ +| Defined in `mjvisualize.h `_ | These are the possible stereo rendering types. They are used in ``mjvScene.stereo``. @@ -914,7 +914,7 @@ mjtGridPos mjGRID_BOTTOMRIGHT // bottom right } mjtGridPos; -| Defined in `mjrender.h `_ +| Defined in `mjrender.h `_ | These are the possible grid positions for text overlays. They are used as an argument to the function :ref:`mjr_overlay`. @@ -932,7 +932,7 @@ mjtFramebuffer mjFB_OFFSCREEN // offscreen buffer } mjtFramebuffer; -| Defined in `mjrender.h `_ +| Defined in `mjrender.h `_ | These are the possible framebuffers. They are used as an argument to the function :ref:`mjr_setBuffer`. @@ -953,7 +953,7 @@ mjtFontScale mjFONTSCALE_300 = 300 // 300% scale } mjtFontScale; -| Defined in `mjrender.h `_ +| Defined in `mjrender.h `_ | These are the possible font sizes. The fonts are predefined bitmaps stored in the dynamic library at three different sizes. @@ -972,7 +972,7 @@ mjtFont mjFONT_BIG // big font (for user alerts) } mjtFont; -| Defined in `mjrender.h `_ +| Defined in `mjrender.h `_ | These are the possible font types. @@ -991,7 +991,7 @@ mjtButton mjBUTTON_MIDDLE // middle button } mjtButton; -| Defined in `mjui.h `_ +| Defined in `mjui.h `_ | Mouse button IDs used in the UI framework. @@ -1013,7 +1013,7 @@ mjtEvent mjEVENT_RESIZE // resize } mjtEvent; -| Defined in `mjui.h `_ +| Defined in `mjui.h `_ | Event types used in the UI framework. @@ -1046,7 +1046,7 @@ mjtItem mjNITEM // number of item types } mjtItem; -| Defined in `mjui.h `_ +| Defined in `mjui.h `_ | Item types used in the UI framework. @@ -1055,8 +1055,8 @@ mjtItem Function types ^^^^^^^^^^^^^^ -MuJoCo callbacks have corresponding function types. They are defined in `mjdata.h `_ and in -`mjui.h `_. The actual callback functions are documented later. +MuJoCo callbacks have corresponding function types. They are defined in `mjdata.h `_ and in +`mjui.h `_. The actual callback functions are documented later. .. _mjfGeneric: @@ -1163,7 +1163,7 @@ mjVFS }; typedef struct _mjVFS mjVFS; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | This is the data structure with the virtual file system. It can only be constructed programmatically, and does not have an analog in MJCF. @@ -1213,7 +1213,7 @@ mjOption }; typedef struct _mjOption mjOption; -| Defined in `mjmodel.h `_ +| Defined in `mjmodel.h `_ | This is the data structure with simulation options. It corresponds to the MJCF element :ref:`option