Skip to content

Commit

Permalink
Merge pull request #114 from InteractiveComputerGraphics/python_bindings
Browse files Browse the repository at this point in the history
Python bindings
  • Loading branch information
janbender authored Dec 22, 2021
2 parents d666cba + faeee1f commit 136469f
Show file tree
Hide file tree
Showing 151 changed files with 22,974 additions and 2,376 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,58 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: apt-get update
run: sudo apt-get update --fix-missing
- name: Install packages
run: sudo apt-get -y install xorg-dev freeglut3-dev
- name: configure
run: mkdir build-release && cd build-release && cmake -DCMAKE_BUILD_TYPE=Release ..
- name: build
run: cmake --build build-release

build-manylinux-python:

runs-on: ubuntu-latest
strategy:
matrix:
# python-version: [3.7]
python-version: [cp36-cp36m, cp37-cp37m, cp38-cp38]

steps:
- uses: actions/checkout@v1

# Set up python
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

# Install dependencies
- name: Install dependencies
run: python -m pip install --upgrade twine

- name: Build manylinux Python wheels
uses: digitalillusions/python-wheels-manylinux-build@master
with:
# python-versions: 'cp37-cp37m'
python-versions: '${{ matrix.python-version }}'
build-requirements: ''
system-packages: 'cmake3 libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel'
package-path: ''
pip-wheel-args: '--manylinux-build'

# Upload artifacts
- name: Upload compiled wheel
uses: actions/upload-artifact@master
with:
name: pypbd-linux-${{ matrix.python-version }}
path: wheelhouse
if: always()

# Publish to pypi
- name: Publish wheels to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload wheelhouse/*-manylinux*.whl --skip-existing
40 changes: 40 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,43 @@ jobs:
run: cmake --build build-release --config Release


# Build the python wheel in parallel
build-windows-python:
runs-on: windows-latest
strategy:
matrix:
# python-version: [3.7]
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]

steps:
# Checkout repo
- uses: actions/checkout@v1

# Set up python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

# Install python dependencies
- name: Install dependencies
run: python -m pip install --upgrade pip setuptools wheel twine

# Change directory and run setup py
- name: Run setup py
run: python setup.py bdist_wheel

# Upload artifacts
- name: Upload compiled wheel
uses: actions/upload-artifact@master
with:
name: pypbd-windows-${{ matrix.python-version }}
path: build/dist
if: always()

# Upload wheel to pypi
- name: Upload wheel to pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload build/dist/* --skip-existing
23 changes: 20 additions & 3 deletions CMake/Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ set(PBD_BINARY_DEBUG_POSTFIX "_d" CACHE INTERNAL "Postfix for executables")
set(PBD_BINARY_RELWITHDEBINFO_POSTFIX "_rd" CACHE INTERNAL "Postfix for executables")
set(PBD_BINARY_MINSIZEREL_POSTFIX "_ms" CACHE INTERNAL "Postfix for executables")

include(CMakeDependentOption)

cmake_dependent_option(USE_PYTHON_BINDINGS "Generate Python Bindings using PyBind11" ON "PYTHON_EXECUTABLE" OFF)
if (USE_PYTHON_BINDINGS AND UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
message(STATUS "Adding -fPIC option when generating Python bindings using GCC")
endif ()

option(CI_BUILD "Build on CI System" OFF)
mark_as_advanced(CI_BUILD)

if (NOT WIN32)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -43,9 +55,14 @@ endif (MSVC)
if (UNIX OR MINGW)
set(CMAKE_USE_RELATIVE_PATHS "1")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
# Set compiler flags for "release"
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=native")
# Set compiler flags for "release" Use generic 64 bit instructions when building on CI
if (CI_BUILD)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=x86-64")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=x86-64")
else()
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=native")
endif ()
endif (UNIX OR MINGW)
if(MINGW)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1 -Wa,-mbig-obj")
Expand Down
23 changes: 23 additions & 0 deletions CMake/DataCopyTargets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_custom_target(CopyPBDShaders
${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/data/shaders
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/shaders
COMMENT "Copying PBD shaders"
)
set_target_properties(CopyPBDShaders PROPERTIES FOLDER "Data copy")

add_custom_target(CopyPBDModels
${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/data/models
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/models
COMMENT "Copying PBD models"
)
set_target_properties(CopyPBDModels PROPERTIES FOLDER "Data copy")

add_custom_target(CopyPBDScenes
${CMAKE_COMMAND} -E copy_directory
${PROJECT_SOURCE_DIR}/data/scenes
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/scenes
COMMENT "Copying PBD scenes"
)
set_target_properties(CopyPBDScenes PROPERTIES FOLDER "Data copy")
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

include(${PROJECT_PATH}/CMake/Common.cmake)

add_definitions(-DPBD_DATA_PATH="../data")

if (NOT WIN32)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()
Expand Down Expand Up @@ -42,13 +40,12 @@ if ((DEFINED Discregrid_INCLUDE_DIR) AND (DEFINED Discregrid_DEBUG_LIB) AND (DEF
else()
ExternalProject_Add(
Ext_Discregrid
PREFIX "${ExternalInstallDir}/Discregrid"
PREFIX "${CMAKE_BINARY_DIR}/extern/Discregrid"
GIT_REPOSITORY https://github.com/InteractiveComputerGraphics/Discregrid.git
GIT_TAG "0b69062ff9c56fbb6dcecd296652028bedbacf0e"
INSTALL_DIR ${ExternalInstallDir}/Discregrid
CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=${EXT_CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${ExternalInstallDir}/Discregrid
-DBUILD_AS_SHARED_LIBS:BOOL=0
-DBUILD_CMD_EXECUTABLE:BOOL=0 -DEIGEN3_INCLUDE_DIR:PATH=${EIGEN3_INCLUDE_DIR}
-DBUILD_CMD_EXECUTABLE:BOOL=0 -DEIGEN3_INCLUDE_DIR:PATH=${EIGEN3_INCLUDE_DIR} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
)
ExternalProject_Get_Property(Ext_Discregrid INSTALL_DIR)
set(Discregrid_INCLUDE_DIR ${INSTALL_DIR}/include)
Expand Down Expand Up @@ -78,11 +75,16 @@ endif()
add_subdirectory(PositionBasedDynamics)
add_subdirectory(Simulation)
add_subdirectory(Utils)
if (NOT PBD_NO_DEMOS)
if (NOT PBD_LIBS_ONLY)
include(DataCopyTargets)
add_subdirectory(extern/glfw)
add_subdirectory(extern/AntTweakBar)
add_subdirectory(extern/md5)
add_subdirectory(Demos)
if (USE_PYTHON_BINDINGS)
add_subdirectory(extern/pybind)
add_subdirectory(pyPBD)
endif ()
endif()


Expand Down
8 changes: 8 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.0.1
- extended and modified Python interface
- more Python examples
- bugfixes

2.0.0
- added Python binding
- cleaned up demos
- added XPBD distance constraint
- added XPBD isometric bending constraint
- added XPBD volume constraint
Expand Down
2 changes: 1 addition & 1 deletion Demos/BarDemo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(SIMULATION_LINK_LIBRARIES AntTweakBar glfw PositionBasedDynamics Simulation Utils)
set(SIMULATION_DEPENDENCIES AntTweakBar glfw PositionBasedDynamics Simulation Utils)
set(SIMULATION_DEPENDENCIES AntTweakBar glfw PositionBasedDynamics Simulation Utils CopyPBDShaders)

if(WIN32)
set(SIMULATION_LINK_LIBRARIES opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES})
Expand Down
Loading

0 comments on commit 136469f

Please sign in to comment.