Skip to content

Commit 136469f

Browse files
authored
Merge pull request #114 from InteractiveComputerGraphics/python_bindings
Python bindings
2 parents d666cba + faeee1f commit 136469f

File tree

151 files changed

+22974
-2376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+22974
-2376
lines changed

.github/workflows/build-linux.yml

+49
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,58 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v1
12+
- name: apt-get update
13+
run: sudo apt-get update --fix-missing
1214
- name: Install packages
1315
run: sudo apt-get -y install xorg-dev freeglut3-dev
1416
- name: configure
1517
run: mkdir build-release && cd build-release && cmake -DCMAKE_BUILD_TYPE=Release ..
1618
- name: build
1719
run: cmake --build build-release
20+
21+
build-manylinux-python:
22+
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
# python-version: [3.7]
27+
python-version: [cp36-cp36m, cp37-cp37m, cp38-cp38]
28+
29+
steps:
30+
- uses: actions/checkout@v1
31+
32+
# Set up python
33+
- name: Set up Python 3.8
34+
uses: actions/setup-python@v1
35+
with:
36+
python-version: 3.8
37+
38+
# Install dependencies
39+
- name: Install dependencies
40+
run: python -m pip install --upgrade twine
41+
42+
- name: Build manylinux Python wheels
43+
uses: digitalillusions/python-wheels-manylinux-build@master
44+
with:
45+
# python-versions: 'cp37-cp37m'
46+
python-versions: '${{ matrix.python-version }}'
47+
build-requirements: ''
48+
system-packages: 'cmake3 libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel'
49+
package-path: ''
50+
pip-wheel-args: '--manylinux-build'
51+
52+
# Upload artifacts
53+
- name: Upload compiled wheel
54+
uses: actions/upload-artifact@master
55+
with:
56+
name: pypbd-linux-${{ matrix.python-version }}
57+
path: wheelhouse
58+
if: always()
59+
60+
# Publish to pypi
61+
- name: Publish wheels to PyPI
62+
env:
63+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
64+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
65+
run: |
66+
twine upload wheelhouse/*-manylinux*.whl --skip-existing

.github/workflows/build-windows.yml

+40
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,43 @@ jobs:
1919
run: cmake --build build-release --config Release
2020

2121

22+
# Build the python wheel in parallel
23+
build-windows-python:
24+
runs-on: windows-latest
25+
strategy:
26+
matrix:
27+
# python-version: [3.7]
28+
python-version: [2.7, 3.5, 3.6, 3.7, 3.8]
29+
30+
steps:
31+
# Checkout repo
32+
- uses: actions/checkout@v1
33+
34+
# Set up python
35+
- name: Set up Python ${{ matrix.python-version }}
36+
uses: actions/setup-python@v1
37+
with:
38+
python-version: ${{ matrix.python-version }}
39+
40+
# Install python dependencies
41+
- name: Install dependencies
42+
run: python -m pip install --upgrade pip setuptools wheel twine
43+
44+
# Change directory and run setup py
45+
- name: Run setup py
46+
run: python setup.py bdist_wheel
47+
48+
# Upload artifacts
49+
- name: Upload compiled wheel
50+
uses: actions/upload-artifact@master
51+
with:
52+
name: pypbd-windows-${{ matrix.python-version }}
53+
path: build/dist
54+
if: always()
55+
56+
# Upload wheel to pypi
57+
- name: Upload wheel to pypi
58+
env:
59+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
60+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
61+
run: twine upload build/dist/* --skip-existing

CMake/Common.cmake

+20-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ set(PBD_BINARY_DEBUG_POSTFIX "_d" CACHE INTERNAL "Postfix for executables")
1212
set(PBD_BINARY_RELWITHDEBINFO_POSTFIX "_rd" CACHE INTERNAL "Postfix for executables")
1313
set(PBD_BINARY_MINSIZEREL_POSTFIX "_ms" CACHE INTERNAL "Postfix for executables")
1414

15+
include(CMakeDependentOption)
16+
17+
cmake_dependent_option(USE_PYTHON_BINDINGS "Generate Python Bindings using PyBind11" ON "PYTHON_EXECUTABLE" OFF)
18+
if (USE_PYTHON_BINDINGS AND UNIX)
19+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
20+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
21+
message(STATUS "Adding -fPIC option when generating Python bindings using GCC")
22+
endif ()
23+
24+
option(CI_BUILD "Build on CI System" OFF)
25+
mark_as_advanced(CI_BUILD)
26+
1527
if (NOT WIN32)
1628
if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
1729
if (NOT CMAKE_BUILD_TYPE)
@@ -43,9 +55,14 @@ endif (MSVC)
4355
if (UNIX OR MINGW)
4456
set(CMAKE_USE_RELATIVE_PATHS "1")
4557
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
46-
# Set compiler flags for "release"
47-
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native")
48-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=native")
58+
# Set compiler flags for "release" Use generic 64 bit instructions when building on CI
59+
if (CI_BUILD)
60+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=x86-64")
61+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=x86-64")
62+
else()
63+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=native")
64+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=native")
65+
endif ()
4966
endif (UNIX OR MINGW)
5067
if(MINGW)
5168
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1 -Wa,-mbig-obj")

CMake/DataCopyTargets.cmake

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
add_custom_target(CopyPBDShaders
2+
${CMAKE_COMMAND} -E copy_directory
3+
${PROJECT_SOURCE_DIR}/data/shaders
4+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/shaders
5+
COMMENT "Copying PBD shaders"
6+
)
7+
set_target_properties(CopyPBDShaders PROPERTIES FOLDER "Data copy")
8+
9+
add_custom_target(CopyPBDModels
10+
${CMAKE_COMMAND} -E copy_directory
11+
${PROJECT_SOURCE_DIR}/data/models
12+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/models
13+
COMMENT "Copying PBD models"
14+
)
15+
set_target_properties(CopyPBDModels PROPERTIES FOLDER "Data copy")
16+
17+
add_custom_target(CopyPBDScenes
18+
${CMAKE_COMMAND} -E copy_directory
19+
${PROJECT_SOURCE_DIR}/data/scenes
20+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/scenes
21+
COMMENT "Copying PBD scenes"
22+
)
23+
set_target_properties(CopyPBDScenes PROPERTIES FOLDER "Data copy")

CMakeLists.txt

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
1313

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

16-
add_definitions(-DPBD_DATA_PATH="../data")
17-
1816
if (NOT WIN32)
1917
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
2018
endif()
@@ -42,13 +40,12 @@ if ((DEFINED Discregrid_INCLUDE_DIR) AND (DEFINED Discregrid_DEBUG_LIB) AND (DEF
4240
else()
4341
ExternalProject_Add(
4442
Ext_Discregrid
45-
PREFIX "${ExternalInstallDir}/Discregrid"
43+
PREFIX "${CMAKE_BINARY_DIR}/extern/Discregrid"
4644
GIT_REPOSITORY https://github.com/InteractiveComputerGraphics/Discregrid.git
4745
GIT_TAG "0b69062ff9c56fbb6dcecd296652028bedbacf0e"
4846
INSTALL_DIR ${ExternalInstallDir}/Discregrid
4947
CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=${EXT_CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=${ExternalInstallDir}/Discregrid
50-
-DBUILD_AS_SHARED_LIBS:BOOL=0
51-
-DBUILD_CMD_EXECUTABLE:BOOL=0 -DEIGEN3_INCLUDE_DIR:PATH=${EIGEN3_INCLUDE_DIR}
48+
-DBUILD_CMD_EXECUTABLE:BOOL=0 -DEIGEN3_INCLUDE_DIR:PATH=${EIGEN3_INCLUDE_DIR} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
5249
)
5350
ExternalProject_Get_Property(Ext_Discregrid INSTALL_DIR)
5451
set(Discregrid_INCLUDE_DIR ${INSTALL_DIR}/include)
@@ -78,11 +75,16 @@ endif()
7875
add_subdirectory(PositionBasedDynamics)
7976
add_subdirectory(Simulation)
8077
add_subdirectory(Utils)
81-
if (NOT PBD_NO_DEMOS)
78+
if (NOT PBD_LIBS_ONLY)
79+
include(DataCopyTargets)
8280
add_subdirectory(extern/glfw)
8381
add_subdirectory(extern/AntTweakBar)
8482
add_subdirectory(extern/md5)
8583
add_subdirectory(Demos)
84+
if (USE_PYTHON_BINDINGS)
85+
add_subdirectory(extern/pybind)
86+
add_subdirectory(pyPBD)
87+
endif ()
8688
endif()
8789

8890

Changelog.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2.0.1
2+
- extended and modified Python interface
3+
- more Python examples
4+
- bugfixes
5+
6+
2.0.0
7+
- added Python binding
8+
- cleaned up demos
19
- added XPBD distance constraint
210
- added XPBD isometric bending constraint
311
- added XPBD volume constraint

Demos/BarDemo/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(SIMULATION_LINK_LIBRARIES AntTweakBar glfw PositionBasedDynamics Simulation Utils)
2-
set(SIMULATION_DEPENDENCIES AntTweakBar glfw PositionBasedDynamics Simulation Utils)
2+
set(SIMULATION_DEPENDENCIES AntTweakBar glfw PositionBasedDynamics Simulation Utils CopyPBDShaders)
33

44
if(WIN32)
55
set(SIMULATION_LINK_LIBRARIES opengl32.lib glu32.lib ${SIMULATION_LINK_LIBRARIES})

0 commit comments

Comments
 (0)