### Install Python Bindings via Setup Script Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Build and install the Python wheel package from the project root. ```bash git clone https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git cd PositionBasedDynamics python setup.py bdist_wheel pip install build/dist/*.whl ``` -------------------------------- ### Virtual Environment Setup with UV Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt Configures a virtual environment using 'uv' if PYBIND11_CREATE_WITH_UV is set. It handles existing environments and installs dependencies from requirements.txt. ```cmake if(NOT PYBIND11_CREATE_WITH_UV STREQUAL "") set(Python_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/.venv") if(EXISTS "${Python_ROOT_DIR}") if(EXISTS "${CMAKE_BINARY_DIR}/CMakeCache.txt") message(STATUS "Using existing venv at ${Python_ROOT_DIR}, remove or --fresh to recreate") else() # --fresh used to remove the cache file(REMOVE_RECURSE "${CMAKE_CURRENT_BINARY_DIR}/.venv") endif() endif() if(NOT EXISTS "${Python_ROOT_DIR}") find_program(UV uv REQUIRED) # CMake 3.19+ would be able to use COMMAND_ERROR_IS_FATAL message( STATUS "Creating venv with ${UV} venv -p ${PYBIND11_CREATE_WITH_UV} '${Python_ROOT_DIR}'") execute_process(COMMAND ${UV} venv -p ${PYBIND11_CREATE_WITH_UV} "${Python_ROOT_DIR}" RESULT_VARIABLE _venv_result) if(_venv_result AND NOT _venv_result EQUAL 0) message(FATAL_ERROR "uv venv failed with '${_venv_result}'") endif() message( STATUS "Installing deps with ${UV} pip install -p '${Python_ROOT_DIR}' -r tests/requirements.txt" ) execute_process( COMMAND ${UV} pip install -p "${Python_ROOT_DIR}" -r "${CMAKE_CURRENT_SOURCE_DIR}/tests/requirements.txt" RESULT_VARIABLE _pip_result) if(_pip_result AND NOT _pip_result EQUAL 0) message(FATAL_ERROR "uv pip install failed with '${_pip_result}'") endif() endif() else() if(NOT DEFINED Python3_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE AND NOT DEFINED Python_ROOT_DIR AND NOT DEFINED ENV{VIRTUALENV} AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.venv") message(STATUS "Autodetecting Python in virtual environment") set(Python_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.venv") endif() endif() ``` -------------------------------- ### Handle Wheel Installation Init Files Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt Creates and installs __init__.py files when building wheels for pybind11. ```cmake # When building a wheel, include __init__.py's for modules # (see https://github.com/pybind/pybind11/pull/5552) if(DEFINED SKBUILD_PROJECT_NAME AND SKBUILD_PROJECT_NAME STREQUAL "pybind11") file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/empty") file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/") endif() ``` -------------------------------- ### Install Bindings from Source Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Builds the Python wheel from the repository and installs it locally. Recommended to use within a virtual environment. ```bash git clone https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git cd PositionBasedDynamics python setup.py bdist_wheel pip install build/dist/pyPBD-2.1.0-cp38-cp38-win_amd64.whl ``` -------------------------------- ### Installation Rules Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/CMakeLists.txt Defines installation rules for common header files, GLSL shaders, and demo visualization headers. ```cmake install(DIRECTORY ./Common DESTINATION include FILES_MATCHING PATTERN "*.h") ``` ```cmake install(DIRECTORY ./data DESTINATION include FILES_MATCHING PATTERN "*.glsl") ``` ```cmake install(DIRECTORY ./Demos/Visualization DESTINATION include FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### Install Python Bindings via Pip Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Directly install the bindings from the GitHub repository. ```bash pip install git+https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git ``` -------------------------------- ### Install Utils Headers Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Utils/CMakeLists.txt Installs all header files from the current directory into the 'include/Utils' destination. ```cmake install(DIRECTORY . DESTINATION include/Utils FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### Install Python bindings Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/getting_started.md Clone the repository and install the package using pip. A virtual environment is recommended to manage file storage. ```shell git clone https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git pip install PositionBasedDynamics/ ``` -------------------------------- ### Install Linux Dependencies Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Install essential build tools and libraries required for compiling the project on Ubuntu. ```bash sudo apt install git cmake xorg-dev freeglut3-dev build-essential ``` -------------------------------- ### Install pyPBD Package Source: https://context7.com/interactivecomputergraphics/positionbaseddynamics/llms.txt Install the pyPBD package using pip for quick setup and integration with Python environments. ```bash pip install pypbd ``` -------------------------------- ### Install pybind11 Package and Configuration Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt Handles the installation of headers, CMake config files, and package versioning for pybind11. ```cmake if(PYBIND11_INSTALL) if(DEFINED SKBUILD_PROJECT_NAME AND SKBUILD_PROJECT_NAME STREQUAL "pybind11_global") install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION "${SKBUILD_HEADERS_DIR}") endif() install(DIRECTORY ${pybind11_INCLUDE_DIR}/pybind11 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) set(PYBIND11_CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}" CACHE STRING "install path for pybind11Config.cmake") if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(pybind11_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}") else() set(pybind11_INCLUDEDIR "${PACKAGE_PREFIX_DIR}/${CMAKE_INSTALL_INCLUDEDIR}") endif() configure_package_config_file( tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) # CMake natively supports header-only libraries write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake tools/FindPythonLibsNew.cmake tools/pybind11Common.cmake tools/pybind11Tools.cmake tools/pybind11NewTools.cmake tools/pybind11GuessPythonExtSuffix.cmake DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) if(NOT PYBIND11_EXPORT_NAME) set(PYBIND11_EXPORT_NAME "${PROJECT_NAME}Targets") endif() install(TARGETS pybind11_headers EXPORT "${PYBIND11_EXPORT_NAME}") install( EXPORT "${PYBIND11_EXPORT_NAME}" NAMESPACE "pybind11::" DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR}) ``` -------------------------------- ### Install Utils Library Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Utils/CMakeLists.txt Installs the 'Utils' library targets (runtime, library, archive) to their respective destinations. ```cmake install(TARGETS Utils RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) ``` -------------------------------- ### GenericParameters External Project Setup Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/CMakeLists.txt Configures GenericParameters as an external project if its include directory is not defined. Specifies the Git repository, tag, and installation directory. Sets CMake arguments for build type and installation prefix. ```cmake if (DEFINED GenericParameters_INCLUDE_DIR) message(STATUS "Using ${GenericParameters_INCLUDE_DIR}") else() ExternalProject_Add( Ext_GenericParameters PREFIX "${ExternalInstallDir}/GenericParameters" GIT_REPOSITORY https://github.com/InteractiveComputerGraphics/GenericParameters.git GIT_TAG "a4e2744eea526270cfe38b826440d09f66473316" INSTALL_DIR ${ExternalInstallDir}/GenericParameters CMAKE_ARGS -DCMAKE_BUILD_TYPE=${EXT_CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${ExternalInstallDir}/GenericParameters -DGENERICPARAMETERS_NO_TESTS:BOOL=1 -DCMAKE_POLICY_VERSION_MINIMUM=3.10 ) ExternalProject_Get_Property(Ext_GenericParameters INSTALL_DIR) set(GenericParameters_INCLUDE_DIR ${INSTALL_DIR}/include) unset(INSTALL_DIR) endif() ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/CMakeLists.txt Installs the necessary CMake package configuration files (Eigen3Config.cmake, Eigen3ConfigVersion.cmake, UseEigen3.cmake) to the installation destination. This allows other projects to find and use Eigen. ```cmake install (EXPORT Eigen3Targets NAMESPACE Eigen3:: DESTINATION ${CMAKEPACKAGE_INSTALL_DIR}) install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/UseEigen3.cmake ${CMAKE_CURRENT_BINARY_DIR}/Eigen3Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/Eigen3ConfigVersion.cmake DESTINATION ${CMAKEPACKAGE_INSTALL_DIR} ) ``` -------------------------------- ### Discregrid External Project Setup Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/CMakeLists.txt Configures Discregrid as an external project if not already found. Specifies the Git repository, tag, and installation directory. Sets CMake arguments for build type, installation prefix, and Eigen3 include directory. ```cmake if ((DEFINED Discregrid_INCLUDE_DIR) AND (DEFINED Discregrid_DEBUG_LIB) AND (DEFINED Discregrid_LIB)) message(STATUS "Using ${Discregrid_INCLUDE_DIR}") set(Discregrid_LIBRARIES optimized ${Discregrid_LIB} debug ${Discregrid_DEBUG_LIB}) else() ExternalProject_Add( Ext_Discregrid PREFIX "${CMAKE_BINARY_DIR}/extern/Discregrid" GIT_REPOSITORY https://github.com/InteractiveComputerGraphics/Discregrid.git GIT_TAG "ddf20dc0480874bf02e0bdc6ded76c1f101b17fb" INSTALL_DIR ${ExternalInstallDir}/Discregrid CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=${EXT_CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${ExternalInstallDir}/Discregrid -DBUILD_CMD_EXECUTABLE:BOOL=0 -DEIGEN3_INCLUDE_DIR:PATH=${EIGEN3_INCLUDE_DIR} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_POLICY_VERSION_MINIMUM=3.10 ) ExternalProject_Get_Property(Ext_Discregrid INSTALL_DIR) set(Discregrid_INCLUDE_DIR ${INSTALL_DIR}/include) set(Discregrid_LIBRARIES optimized ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}Discregrid${CMAKE_STATIC_LIBRARY_SUFFIX} debug ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}Discregrid_d${CMAKE_STATIC_LIBRARY_SUFFIX}) unset(INSTALL_DIR) message(STATUS "Building ${Discregrid_INCLUDE_DIR}") endif() ``` -------------------------------- ### Build and Install pyPBD Wheel File Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/py_getting_started.md For development, build a Python wheel file from the source and install it. This method allows for quicker updates. ```shell cd PositionBasedDynamics python setup.py bdist_wheel pip install -I build/dist/*.whl ``` -------------------------------- ### Install Python Bindings Dependencies Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Install Python development headers, pip, and pipx to manage virtual environments for the bindings. ```bash sudo apt install python3-dev python3-pip python3-venv python3 -m pip install pipx python3 -m pipx ensurepath ``` -------------------------------- ### Cocoa Window and NSOpenGL Context Setup (macOS) Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/CMakeLists.txt Configures window creation using Cocoa and context creation using NSOpenGL for macOS. Appends necessary frameworks to the GLFW libraries list. ```cmake if (_GLFW_COCOA) list(APPEND glfw_LIBRARIES "-framework Cocoa" "-framework IOKit" "-framework CoreFoundation") set(glfw_PKG_DEPS "") set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation") endif() ``` -------------------------------- ### Installing GLFW Files Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/CMakeLists.txt Installs GLFW headers, CMake configuration files, export targets, and pkg-config files to their respective system locations when GLFW_INSTALL is enabled. ```cmake if (GLFW_INSTALL) install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION "${GLFW_CONFIG_PATH}") install(EXPORT glfwTargets FILE glfw3Targets.cmake EXPORT_LINK_INTERFACE_LIBRARIES DESTINATION "${GLFW_CONFIG_PATH}") install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # Only generate this target if no higher-level project already has if (NOT TARGET uninstall) configure_file(cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${GLFW_BINARY_DIR}/cmake_uninstall.cmake") set_target_properties(uninstall PROPERTIES FOLDER "GLFW3") endif() endif() ``` -------------------------------- ### Verify pyPBD Installation Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/py_getting_started.md Run this command in your Python environment to confirm that the pyPBD library has been successfully installed and can be imported. ```shell python -c "import pypbd" ``` -------------------------------- ### Verify Python Bindings Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Test the installation of the Python bindings by importing the module. ```cpp cd lib python3 -c "import pypbd" ``` -------------------------------- ### Initialize PBD Simulation Source: https://context7.com/interactivecomputergraphics/positionbaseddynamics/llms.txt Initialize the PBD simulation using the Simulation class singleton. Configure time stepping parameters like substeps and solver iterations for optimal performance. This setup is crucial before adding objects to the simulation model. ```python import pypbd as pbd import numpy as np # Activate console logging for debugging pbd.Logger.addConsoleSink(pbd.LogLevel.INFO) # Get the simulation singleton sim = pbd.Simulation.getCurrent() # Initialize with default settings (timestep, collision detection, etc.) sim.initDefault() # Access the simulation model for adding objects model = sim.getModel() # Configure time stepping parameters ts = sim.getTimeStep() ts.setValueUInt(pbd.TimeStepController.NUM_SUB_STEPS, 5) # Number of substeps ts.setValueUInt(pbd.TimeStepController.MAX_ITERATIONS, 1) # Solver iterations # Run simulation loop for frame in range(1000): for substep in range(8): # Multiple sim steps per render frame sim.getTimeStep().step(model) # Print timing statistics pbd.Timing.printAverageTimes() ``` -------------------------------- ### Installation Rules for GLFW Library Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/src/CMakeLists.txt Defines installation rules for the GLFW library, specifying destinations for runtime binaries, archives, and libraries based on build configurations. ```cmake if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Create custom target for pybind11 module installation Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/pyPBD/CMakeLists.txt Defines a custom CMake target 'pypbd_install' that builds a Python wheel and installs it using pip. This facilitates the distribution and installation of the Python bindings. ```cmake add_custom_target(pypbd_install ${PYTHON_EXECUTABLE} setup.py bdist_wheel COMMAND ${PYTHON_EXECUTABLE} -m pip install -I build/dist/py*.whl WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) ``` -------------------------------- ### Configure and Install Eigen Files Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/Eigen/CMakeLists.txt Filters files in the Eigen directory to exclude specific patterns and installs the remaining files and the src directory. ```cmake include(RegexUtils) test_escape_string_as_regex() file(GLOB Eigen_directory_files "*") escape_string_as_regex(ESCAPED_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") foreach(f ${Eigen_directory_files}) if(NOT f MATCHES "\\.txt" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/[.].+" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/src") list(APPEND Eigen_directory_files_to_install ${f}) endif() endforeach(f ${Eigen_directory_files}) install(FILES ${Eigen_directory_files_to_install} DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen COMPONENT Devel ) install(DIRECTORY src DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen COMPONENT Devel FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### Project CMake Minimum Requirements and Setup Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/CMakeLists.txt Sets the minimum CMake version and project name. Includes common compile options and module path settings. ```cmake cmake_minimum_required(VERSION 3.10) project(PositionBasedDynamics) ``` ```cmake set(PROJECT_PATH ${PROJECT_SOURCE_DIR}) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-idirafter${PROJECT_SOURCE_DIR}) else() include_directories(${PROJECT_SOURCE_DIR}) endif() ``` ```cmake set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH}) ``` ```cmake set_property(GLOBAL PROPERTY USE_FOLDERS ON) ``` ```cmake include(${PROJECT_PATH}/CMake/Common.cmake) ``` ```cmake if (NOT WIN32) message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") endif() ``` ```cmake if (DEFINED PBD_EXTERNALINSTALLDIR) set(ExternalInstallDir "${PBD_EXTERNALINSTALLDIR}" CACHE INTERNAL "External install directory") else() set(ExternalInstallDir "${PROJECT_BINARY_DIR}" CACHE INTERNAL "External install directory") endif() ``` -------------------------------- ### Install pyPBD using pip Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/py_getting_started.md Install the pyPBD package using pip. Ensure you are one directory above the cloned source directory and that the trailing slash is included. ```shell pip install PositionBasedDynamics/ ``` -------------------------------- ### Install NumPy Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/py_getting_started.md Install the NumPy library, which may be a required dependency for pyPBD. Future releases might include it as a direct dependency. ```shell pip install numpy ``` -------------------------------- ### Non-Windows OpenGL Setup Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/SceneLoaderDemo/CMakeLists.txt Configures OpenGL for non-Windows systems by finding the OpenGL package and including its directories and libraries. This is crucial for cross-platform compatibility. ```cmake set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) include_directories( ${OPENGL_INCLUDE_DIRS}) set( SIMULATION_LINK_LIBRARIES ${SIMULATION_LINK_LIBRARIES} ${OPENGL_LIBRARIES} ) ``` -------------------------------- ### Configure Python Include Directories Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt Sets the relative installation path for Python headers based on available CMake variables. ```cmake if(USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS) file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${Python_INCLUDE_DIRS}) elseif(USE_PYTHON_INCLUDE_DIR AND DEFINED PYTHON_INCLUDE_DIR) file(RELATIVE_PATH CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX} ${PYTHON_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Create and Activate Virtualenv Virtual Environment Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/py_getting_started.md Use this command to create a new virtual environment with Python 3.7 using virtualenv and activate it for the installation process. ```shell python3 -m virtualenv venv --python=python3.7 source venv/bin/activate ``` -------------------------------- ### Execute a standard demo Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/getting_started.md Navigate to the binary directory and run a specific simulation demo executable. ```cpp cd ../bin ./BarDemo ``` -------------------------------- ### Run Simulation on Windows Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Execute the scene loader demo from the command line. ```cpp ./SceneLoaderDemo ../data/scenes/CarScene.json ``` -------------------------------- ### Add Uninstall Target Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/CMakeLists.txt Adds a custom CMake target named 'uninstall' that executes a script to remove files installed by the 'install' target. This provides a convenient way to clean up installed files. ```cmake # Add uninstall target add_custom_target ( uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EigenUninstall.cmake) ) ``` -------------------------------- ### Build Project on Linux Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Clone the repository and compile the project using CMake and make. ```bash git clone https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git cd PositionBasedDynamics mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release -DUSE_PYTHON_BINDINGS= .. make -j 4 ``` -------------------------------- ### Configure Target Properties and Dependencies Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/PositionBasedElasticRodsDemo/CMakeLists.txt Sets up include directories, target properties, and dependencies for the ElasticRodDemo. ```cmake find_package( Eigen3 REQUIRED ) include_directories( ${EIGEN3_INCLUDE_DIR} ) include_directories(${PROJECT_PATH}/extern/freeglut/include) include_directories(${PROJECT_PATH}/extern/glew/include) set_target_properties(ElasticRodDemo PROPERTIES FOLDER "Demos") set_target_properties(ElasticRodDemo PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) set_target_properties(ElasticRodDemo PROPERTIES RELWITHDEBINFO_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX}) set_target_properties(ElasticRodDemo PROPERTIES MINSIZEREL_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX}) add_dependencies(ElasticRodDemo ${SIMULATION_DEPENDENCIES}) target_link_libraries(ElasticRodDemo ${SIMULATION_LINK_LIBRARIES}) VIS_SOURCE_GROUPS() ``` -------------------------------- ### Configure Win32 backend Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/CMakeLists.txt Sets up dependencies for the Win32 windowing backend. ```cmake if (_GLFW_WIN32) list(APPEND glfw_PKG_LIBS "-lgdi32") if (GLFW_USE_HYBRID_HPG) set(_GLFW_USE_HYBRID_HPG 1) endif() endif() ``` -------------------------------- ### Example Distance Constraint Gradient Function Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/GenericConstraints.dox An example of a gradient function for a distance constraint. It calculates the normalized vector between the two particles. ```cpp void GenericDistanceConstraint::gradientFct( const unsigned int i, const unsigned int numberOfParticles, const float mass[], const Eigen::Vector3f x[], void *userData, Eigen::Matrix &jacobian) { Eigen::Vector3f n = x[i] - x[1 - i]; n.normalize(); jacobian = n.transpose(); } ``` -------------------------------- ### Example Distance Constraint Function Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/GenericConstraints.dox An example of a constraint function for a distance constraint. It calculates the difference between the current distance and the rest length. ```cpp void GenericDistanceConstraint::constraintFct( const unsigned int numberOfParticles, const float mass[], const Eigen::Vector3f x[], void *userData, Eigen::Matrix &constraintValue) { float restLength = *(float*)userData; Eigen::Matrix C; C(0, 0) = (x[1] - x[0]).norm() - restLength; constraintValue = C; } ``` -------------------------------- ### Set Target Properties and Dependencies Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/CouplingDemos/CMakeLists.txt Configures build postfixes, dependencies, and link libraries for the demo executable. ```cmake set_target_properties(RigidBodyClothCouplingDemo PROPERTIES FOLDER "Demos") set_target_properties(RigidBodyClothCouplingDemo PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) set_target_properties(RigidBodyClothCouplingDemo PROPERTIES RELWITHDEBINFO_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX}) set_target_properties(RigidBodyClothCouplingDemo PROPERTIES MINSIZEREL_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX}) add_dependencies(RigidBodyClothCouplingDemo ${SIMULATION_DEPENDENCIES}) target_link_libraries(RigidBodyClothCouplingDemo ${SIMULATION_LINK_LIBRARIES}) ``` -------------------------------- ### Run Simulation with OpenGL Override Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/build_from_source.md Execute the demo with a specific OpenGL version override if required by the system. ```bash cd ../bin MESA_GL_VERSION_OVERRIDE=3.3 ./SceneLoaderDemo ../data/Scenes/CarScene.json ``` -------------------------------- ### Configure and Build Demos with CMake Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/CMakeLists.txt Defines a list of demo projects and conditionally adds their subdirectories based on user-defined build options. ```cmake include(Visualization/CMakeLists.txt) # search all demos set(PBD_DEMOS BarDemo ClothDemo CosseratRodsDemo CouplingDemos DistanceFieldDemos FluidDemo GenericConstraintsDemos PositionBasedElasticRodsDemo RigidBodyDemos SceneLoaderDemo StiffRodsDemos ) if (NOT PBD_LIBS_ONLY) foreach (_demo_name ${PBD_DEMOS}) option(Build_${_demo_name} "Build ${_demo_name}" ON) if (Build_${_demo_name}) add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/${_demo_name}) endif (Build_${_demo_name}) endforeach () endif() install(DIRECTORY ./Common DESTINATION include/Demos FILES_MATCHING PATTERN "*.h") ``` -------------------------------- ### Configure Simulation Dependencies and OpenGL Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/CouplingDemos/CMakeLists.txt Sets up library links and dependencies, including platform-specific OpenGL configuration for Windows and non-Windows systems. ```cmake set(SIMULATION_LINK_LIBRARIES imgui glfw PositionBasedDynamics Simulation Utils) set(SIMULATION_DEPENDENCIES imgui glfw PositionBasedDynamics Simulation Utils CopyPBDShaders CopyPBDModels CopyImguiFonts) if(WIN32) set(SIMULATION_LINK_LIBRARIES opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES}) #set(SIMULATION_DEPENDENCIES ${SIMULATION_DEPENDENCIES}) else() set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) include_directories( ${OPENGL_INCLUDE_DIRS}) set(SIMULATION_LINK_LIBRARIES ${SIMULATION_LINK_LIBRARIES} ${OPENGL_LIBRARIES} ) endif() ``` -------------------------------- ### Set Target Properties and Dependencies Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/GenericConstraintsDemos/CMakeLists.txt Configures build properties, dependencies, and linking for the demo executables. ```cmake find_package( Eigen3 REQUIRED ) include_directories( ${EIGEN3_INCLUDE_DIR} ) include_directories(${PROJECT_PATH}/extern/freeglut/include) include_directories(${PROJECT_PATH}/extern/glew/include) set_target_properties(GenericParticleConstraintsDemo PROPERTIES FOLDER "Demos") set_target_properties(GenericParticleConstraintsDemo PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) set_target_properties(GenericParticleConstraintsDemo PROPERTIES RELWITHDEBINFO_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX}) set_target_properties(GenericParticleConstraintsDemo PROPERTIES MINSIZEREL_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX}) add_dependencies(GenericParticleConstraintsDemo ${SIMULATION_DEPENDENCIES}) target_link_libraries(GenericParticleConstraintsDemo ${SIMULATION_LINK_LIBRARIES}) set_target_properties(GenericRigidBodyConstraintsDemo PROPERTIES FOLDER "Demos") set_target_properties(GenericRigidBodyConstraintsDemo PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) set_target_properties(GenericRigidBodyConstraintsDemo PROPERTIES RELWITHDEBINFO_POSTFIX ${CMAKE_RELWITHDEBINFO_POSTFIX}) set_target_properties(GenericRigidBodyConstraintsDemo PROPERTIES MINSIZEREL_POSTFIX ${CMAKE_MINSIZEREL_POSTFIX}) add_dependencies(GenericRigidBodyConstraintsDemo ${SIMULATION_DEPENDENCIES}) target_link_libraries(GenericRigidBodyConstraintsDemo ${SIMULATION_LINK_LIBRARIES}) VIS_SOURCE_GROUPS() ``` -------------------------------- ### Install Eigen Export Targets Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/CMakeLists.txt Installs the Eigen export targets, making them available for other CMake projects to find and use. This ensures proper integration when Eigen is used as a dependency. ```cmake install (TARGETS eigen EXPORT Eigen3Targets) ``` -------------------------------- ### Define Eigen Installation Paths Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/CMakeLists.txt Sets CMake variables for Eigen's include directory and root directory based on installation prefixes. These are used for configuring package information. ```cmake set ( EIGEN_DEFINITIONS "") set ( EIGEN_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}" ) set ( EIGEN_ROOT_DIR ${CMAKE_INSTALL_PREFIX} ) ``` -------------------------------- ### Build PositionBasedDynamics with CMake Source: https://context7.com/interactivecomputergraphics/positionbaseddynamics/llms.txt Commands to clone, configure, and build the library from source. Includes options for double precision, OpenMP, and Python bindings. ```bash # Clone repository git clone https://github.com/InteractiveComputerGraphics/PositionBasedDynamics.git cd PositionBasedDynamics # Create build directory mkdir build && cd build # Configure with CMake cmake .. \ -DCMAKE_BUILD_TYPE=Release \ -DUSE_DOUBLE_PRECISION=OFF \ -DUSE_OpenMP=ON \ -DUSE_PYTHON_BINDINGS=ON # Build cmake --build . --config Release -j8 # Install Python bindings pip install ../ ``` -------------------------------- ### Example Isometric Bending Constraint Function Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/GenericConstraints.dox An example of a constraint function for an isometric bending constraint using double precision. It calculates energy based on particle positions and a user-provided matrix. ```cpp void GenericIsometricBendingConstraint::constraintFct( const unsigned int numberOfParticles, const float invMass[], const Eigen::Vector3d x[], void *userData, Eigen::Matrix &constraintValue) { Eigen::Matrix4f *Q = (Eigen::Matrix4f*)userData; double energy = 0.0; for (unsigned char k = 0; k < 4; k++) for (unsigned char j = 0; j < 4; j++) energy += (double) (*Q)(j, k)*(x[k].dot(x[j])); energy *= 0.5; constraintValue(0, 0) = energy; } ``` -------------------------------- ### Configure OSMesa backend Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/CMakeLists.txt Sets up OSMesa for offscreen rendering contexts. ```cmake if (_GLFW_OSMESA) find_package(OSMesa REQUIRED) list(APPEND glfw_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}") endif() ``` -------------------------------- ### Configure Simulation Dependencies and OpenGL Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/PositionBasedElasticRodsDemo/CMakeLists.txt Sets up library dependencies and handles platform-specific OpenGL linking requirements. ```cmake set(SIMULATION_LINK_LIBRARIES imgui glfw PositionBasedDynamics Simulation Utils) set(SIMULATION_DEPENDENCIES imgui glfw PositionBasedDynamics Simulation Utils CopyPBDShaders CopyImguiFonts) if(WIN32) set(SIMULATION_LINK_LIBRARIES opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES}) #set(SIMULATION_DEPENDENCIES ${SIMULATION_DEPENDENCIES}) else() set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) include_directories( ${OPENGL_INCLUDE_DIRS}) set(SIMULATION_LINK_LIBRARIES ${SIMULATION_LINK_LIBRARIES} ${OPENGL_LIBRARIES} ) endif() ``` -------------------------------- ### Get Git Revision Description Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Utils/CMakeLists.txt Retrieves the Git commit hash and checks for local changes to include in the build version. ```cmake include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC GIT_SHA1) ``` ```cmake git_local_changes(GIT_LOCAL_CHANGES) if (${GIT_LOCAL_CHANGES} STREQUAL "DIRTY") set(COMPILER_MESSAGE "#pragma WARNING(Local changes not committed.)") endif() ``` -------------------------------- ### Configuring GLFW Header and PCF File Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/CMakeLists.txt Copies and configures `glfw_config.h` and `glfw3.pc` using template files, ensuring correct build-time configurations are embedded. ```cmake configure_file(src/glfw_config.h.in src/glfw_config.h @ONLY) configure_file(src/glfw3.pc.in src/glfw3.pc @ONLY) ``` -------------------------------- ### Generate pkg-config File Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt Configures and installs a pkg-config file for pybind11, handling path resolution across different CMake versions. ```cmake # pkg-config support if(NOT prefix_for_pc_file) if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}") set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}") else() set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}") if(CMAKE_VERSION VERSION_LESS 3.20) set(prefix_for_pc_file "${pcfiledir}/..") while(pc_datarootdir) get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY) string(APPEND prefix_for_pc_file "/..") endwhile() else() cmake_path(RELATIVE_PATH CMAKE_INSTALL_PREFIX BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR OUTPUT_VARIABLE prefix_for_pc_file) endif() endif() endif() join_paths(includedir_for_pc_file "${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/") ``` -------------------------------- ### Create and Activate Conda Virtual Environment Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/py_getting_started.md Use this command to create a new virtual environment with Python 3.7 and activate it for the installation process. ```shell conda create --name venv python=3.7 conda activate venv ``` -------------------------------- ### Pybind11 CMake Options Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt Defines boolean options for controlling Pybind11 installation, testing, and Python integration. These options are typically set in a CMakeLists.txt file. ```cmake option(PYBIND11_INSTALL "Install pybind11 header files?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_TEST "Build pybind11 test suite?" ${PYBIND11_MASTER_PROJECT}) option(PYBIND11_NOPYTHON "Disable search for Python" OFF) option(PYBIND11_DISABLE_HANDLE_TYPE_NAME_DEFAULT_IMPLEMENTATION "To enforce that a handle_type_name<> specialization exists" OFF) option(PYBIND11_SIMPLE_GIL_MANAGEMENT "Use simpler GIL management logic that does not support disassociation" OFF) set(PYBIND11_INTERNALS_VERSION "" CACHE STRING "Override the ABI version, may be used to enable the unstable ABI.") option(PYBIND11_USE_CROSSCOMPILING "Respect CMAKE_CROSSCOMPILING" OFF) ``` -------------------------------- ### Python Include Directory Option Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/pybind/CMakeLists.txt A CMake dependent option to control whether pybind11 headers are installed in the Python include directory. It depends on PYBIND11_INSTALL being set. ```cmake cmake_dependent_option( USE_PYTHON_INCLUDE_DIR "Install pybind11 headers in Python include directory instead of default installation prefix" OFF "PYBIND11_INSTALL" OFF) ``` -------------------------------- ### Configure Dear ImGui Library in CMake Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/imgui/CMakeLists.txt Defines the library target, includes necessary source files, and sets up dependencies for GLFW and OpenGL. ```cmake set(IMGUI_HEADERS imconfig.h imgui.h imgui_internal.h imstb_rectpack.h imstb_textedit.h imstb_truetype.h backends/imgui_impl_glfw.h backends/imgui_impl_opengl3.h backends/imgui_impl_opengl3_loader.h ) set(IMGUI_SOURCES imgui.cpp imgui_demo.cpp # useful examples of how to use imgui imgui_draw.cpp imgui_tables.cpp imgui_widgets.cpp backends/imgui_impl_glfw.cpp backends/imgui_impl_opengl3.cpp ) add_library(imgui ${IMGUI_HEADERS} ${IMGUI_SOURCES} ) target_compile_definitions(imgui PUBLIC -DIMGUI_IMPL_OPENGL_LOADER_GLAD) add_dependencies(imgui glfw) target_link_libraries(imgui PUBLIC glfw) target_include_directories(glfw PUBLIC ${CMAKE_CURRENT_LIST_DIR}) set_target_properties(imgui PROPERTIES FOLDER "External Dependencies") ``` -------------------------------- ### Execute the SceneLoaderDemo Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/doc/getting_started.md Run the scene loader simulator by providing the path to a JSON scene file. ```cpp cd ../bin ./SceneLoaderDemo ../data/Scenes/CarScene.json ``` -------------------------------- ### Eigen3 CMake Configuration Script Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/CMakeLists.txt The primary CMake configuration file for the Eigen3 project. It handles environment setup, version extraction, and compiler flag management. ```cmake cmake_minimum_required(VERSION 3.5.0) project(Eigen3) # guard against in-source builds if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt. ") endif() # Alias Eigen_*_DIR to Eigen3_*_DIR: set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR}) set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR}) # guard against bad build-type strings if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() ############################################################################# # retrieve version information # ############################################################################# # automatically parse the version number file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header) string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}") set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}") string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}") set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}") string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}") set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}") set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION}) # if we are not in a git clone if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git) # if the git program is absent or this will leave the EIGEN_GIT_REVNUM string empty, # but won't stop CMake. execute_process(COMMAND git ls-remote --refs -q ${CMAKE_SOURCE_DIR} HEAD OUTPUT_VARIABLE EIGEN_GIT_OUTPUT) endif() # extract the git rev number from the git output... if(EIGEN_GIT_OUTPUT) string(REGEX MATCH "^([0-9;a-f]+).*" EIGEN_GIT_CHANGESET_MATCH "${EIGEN_GIT_OUTPUT}") set(EIGEN_GIT_REVNUM "${CMAKE_MATCH_1}") endif() #...and show it next to the version number if(EIGEN_GIT_REVNUM) set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (git rev ${EIGEN_GIT_REVNUM})") else() set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}") endif() include(CheckCXXCompilerFlag) include(GNUInstallDirs) include(CMakeDependentOption) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) option(EIGEN_TEST_CXX11 "Enable testing with C++11 and C++11 features (e.g. Tensor module)." OFF) macro(ei_add_cxx_compiler_flag FLAG) string(REGEX REPLACE "-" "" SFLAG1 ${FLAG}) string(REGEX REPLACE "\\+" "p" SFLAG ${SFLAG1}) check_cxx_compiler_flag(${FLAG} COMPILER_SUPPORT_${SFLAG}) if(COMPILER_SUPPORT_${SFLAG}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") endif() endmacro() check_cxx_compiler_flag("-std=c++11" EIGEN_COMPILER_SUPPORT_CPP11) if(EIGEN_TEST_CXX11) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS OFF) if(EIGEN_COMPILER_SUPPORT_CPP11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif() else() #set(CMAKE_CXX_STANDARD 03) #set(CMAKE_CXX_EXTENSIONS OFF) ei_add_cxx_compiler_flag("-std=c++03") endif() # Determine if we should build shared libraries on this platform. get_cmake_property(EIGEN_BUILD_SHARED_LIBS TARGET_SUPPORTS_SHARED_LIBS) ############################################################################# # find how to link to the standard libraries # ############################################################################# find_package(StandardMathLibrary) set(EIGEN_TEST_CUSTOM_LINKER_FLAGS "" CACHE STRING "Additional linker flags when linking unit tests.") set(EIGEN_TEST_CUSTOM_CXX_FLAGS "" CACHE STRING "Additional compiler flags when compiling unit tests.") set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "") if(NOT STANDARD_MATH_LIBRARY_FOUND) message(FATAL_ERROR "Can't link to the standard math library. Please report to the Eigen developers, telling them about your platform.") else() if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO} ${STANDARD_MATH_LIBRARY}") else() set(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO "${STANDARD_MATH_LIBRARY}") endif() endif() if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) message(STATUS "Standard libraries to link to explicitly: ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}") else() message(STATUS "Standard libraries to link to explicitly: none") endif() option(EIGEN_BUILD_BTL "Build benchmark suite" OFF) ``` -------------------------------- ### Configure Cloth Simulation Constraints Source: https://context7.com/interactivecomputergraphics/positionbaseddynamics/llms.txt Sets up distance and bending constraints for a cloth model using XPBD methods. ```python # 4 = distance constraints (XPBD) sim_method = 2 stiffness = 1.0 poisson_ratio = 0.3 model.addClothConstraints( triModel, sim_method, stiffness, stiffness, stiffness, stiffness, # xx, yy, xy stiffness poisson_ratio, poisson_ratio, # Poisson ratios False, False # normalize stretch/shear ) # Bending methods: # 1 = dihedral angle (PBD) # 2 = isometric bending (PBD) # 3 = isometric bending (XPBD) bending_method = 2 bending_stiffness = 0.01 model.addBendingConstraints(triModel, bending_method, bending_stiffness) print(f"Triangles: {triModel.getParticleMesh().numFaces()}") print(f"Vertices: {nRows * nCols}") # Update normals after each simulation step for rendering for triModel in model.getTriangleModels(): triModel.updateMeshNormals(model.getParticles()) ``` -------------------------------- ### Write Package Version File Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/eigen/CMakeLists.txt Writes the Eigen3ConfigVersion.cmake file, specifying the package version and compatibility. This helps CMake determine if the installed version meets the requirements of a project. ```cmake set ( _Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) unset (CMAKE_SIZEOF_VOID_P) write_basic_package_version_file (Eigen3ConfigVersion.cmake VERSION ${EIGEN_VERSION_NUMBER} COMPATIBILITY SameMajorVersion) set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P}) ``` -------------------------------- ### Configure Wayland backend Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/glfw/CMakeLists.txt Locates Wayland dependencies and checks for system-specific requirements like memfd_create. ```cmake if (_GLFW_WAYLAND) find_package(ECM REQUIRED NO_MODULE) list(APPEND CMAKE_MODULE_PATH "${ECM_MODULE_PATH}") find_package(Wayland REQUIRED Client Cursor Egl) find_package(WaylandScanner REQUIRED) find_package(WaylandProtocols 1.15 REQUIRED) list(APPEND glfw_PKG_DEPS "wayland-client") list(APPEND glfw_INCLUDE_DIRS "${Wayland_INCLUDE_DIRS}") list(APPEND glfw_LIBRARIES "${Wayland_LIBRARIES}" "${CMAKE_THREAD_LIBS_INIT}") find_package(XKBCommon REQUIRED) list(APPEND glfw_INCLUDE_DIRS "${XKBCOMMON_INCLUDE_DIRS}") include(CheckIncludeFiles) include(CheckFunctionExists) check_function_exists(memfd_create HAVE_MEMFD_CREATE) if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") find_package(EpollShim) if (EPOLLSHIM_FOUND) list(APPEND glfw_INCLUDE_DIRS "${EPOLLSHIM_INCLUDE_DIRS}") list(APPEND glfw_LIBRARIES "${EPOLLSHIM_LIBRARIES}") endif() endif() endif() ``` -------------------------------- ### Configure External Dependencies and Include Paths Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/CouplingDemos/CMakeLists.txt Finds Eigen3 and sets include directories for external libraries like freeglut and glew. ```cmake find_package( Eigen3 REQUIRED ) include_directories( ${EIGEN3_INCLUDE_DIR} ) include_directories(${PROJECT_PATH}/extern/freeglut/include) include_directories(${PROJECT_PATH}/extern/glew/include) VIS_SOURCE_GROUPS() ``` -------------------------------- ### Write basic PLY data Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/extern/happly/README.md Shows how to create a PLY object, add elements and properties, and save to a file. ```cpp #include "happly.h" // Suppose these hold your data std::vector elementA_prop1; std::vector elementA_prop2; std::vector> elementB_listProp; // Create an empty object happly::PLYData plyOut; // Add elements plyOut.addElement("elementA", 20); plyOut.addElement("elementB", 42); // Add properties to those elements plyOut.getElement("elementA").addProperty("prop1", elementA_prop1); plyOut.getElement("elementA").addProperty("prop2", elementA_prop2); plyOut.getElement("elementB").addListProperty("listprop1", elementB_listProp); // Write the object to file plyOut.write("my_output_file.ply", happly::DataFormat::Binary); ``` -------------------------------- ### Set Simulation Libraries and Dependencies Source: https://github.com/interactivecomputergraphics/positionbaseddynamics/blob/master/Demos/StiffRodsDemos/CMakeLists.txt Configures the libraries and dependencies for the simulation. Includes platform-specific OpenGL libraries for Windows. ```cmake set(SIMULATION_LINK_LIBRARIES imgui glfw MD5 PositionBasedDynamics Simulation Utils) set(SIMULATION_DEPENDENCIES imgui glfw MD5 PositionBasedDynamics Simulation Utils CopyPBDShaders CopyPBDModels CopyPBDScenes CopyImguiFonts) if(WIN32) set(SIMULATION_LINK_LIBRARIES opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES}) #set(SIMULATION_DEPENDENCIES ${SIMULATION_DEPENDENCIES}) else() set(OpenGL_GL_PREFERENCE GLVND) find_package(OpenGL REQUIRED) include_directories( ${OPENGL_INCLUDE_DIRS}) set(SIMULATION_LINK_LIBRARIES ${SIMULATION_LINK_LIBRARIES} ${OPENGL_LIBRARIES} ) endif() ```