pyb2d3 0.6.0__tar.gz → 0.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.gitignore +4 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/CMakeLists.txt +6 -33
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/PKG-INFO +1 -1
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/README.md +26 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/default_frontend.py +58 -10
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/frontend_base.py +107 -51
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/sample_base.py +13 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyproject.toml +6 -1
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/ipycanvas_frontend.py +114 -53
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/render_loop.py +31 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/ui.py +78 -84
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyproject.toml +6 -4
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/__init__.py +2 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/canvas_widget.js +557 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/canvas_widget.py +74 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/exp.ipynb +91 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/jupyter_debug_draw.py +263 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/jupyter_frontend.py +254 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/render_loop.py +43 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/ui.py +395 -0
- pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyproject.toml +32 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/opengl_frontend.py +123 -67
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyproject.toml +3 -3
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_pygame/pyb2d3_sandbox_pygame/pygame_frontend.py +40 -8
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_pygame/pyb2d3_sandbox_pygame/sample_to_video.py +3 -5
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_pygame/pyproject.toml +4 -3
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/dev-environment.yaml +13 -3
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/emscripten_forge/recipe/recipe.yaml.template +2 -2
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/__init__.py +2 -0
- pyb2d3-0.7.2/examples/pyb2d3_samples/examples_common/__init__.py +2 -0
- pyb2d3-0.7.2/examples/pyb2d3_samples/examples_common/text.py +54 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/goo_game.py +0 -2
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/jump.py +8 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/meteor.py +17 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/newtons_cradle.py +18 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/soft_bodies.py +5 -1
- pyb2d3-0.7.2/examples/pyb2d3_samples/text.py +43 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/tumbler.py +8 -29
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/pyproject.toml +5 -2
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/scripts/build_emscripten_forge_pkg.sh +16 -2
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/scripts/build_lite_env.sh +2 -1
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/scripts/build_lite_page.sh +1 -1
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_batch_api.cpp +0 -1
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/module/pyb2d3/__init__.py +10 -0
- pyb2d3-0.7.2/tests/conftest.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/tests/headless_test_frontend.py +4 -9
- pyb2d3-0.6.0/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/render_loop.py +0 -70
- pyb2d3-0.6.0/examples/pyb2d3_samples/examples_common/__init__.py +0 -1
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.clang-format +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.github/workflows/conda.yaml +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.github/workflows/docs.yaml +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.github/workflows/emscripten.yaml +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.github/workflows/publish.yaml +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/.pre-commit-config.yaml +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/LICENSE +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/build_pkg.sh +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/__init__.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/widgets.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/__init__.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/debug_draw_offscreen.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/debug_draw_vanilla.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_ipycanvas/pyb2d3_sandbox_ipycanvas/init.js +0 -0
- /pyb2d3-0.6.0/extra_licenses/README → /pyb2d3-0.7.2/companion_packages/pyb2d3_sandbox_jupyter/pyb2d3_sandbox_jupyter/canvas_widget.css +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/LICENSE-Box2D +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/LICENSE-box2d-py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/__init__.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/debug_draw_gl.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/draw.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shader.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/background.fs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/background.vs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/circle.fs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/circle.vs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_capsule.fs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_capsule.vs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_circle.fs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_circle.vs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_polygon.fs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_polygon.vs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_opengl/pyb2d3_sandbox_opengl/shaders/solid_polygon_debug.vs +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox_pygame/pyb2d3_sandbox_pygame/__init__.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/.gitignore +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/Makefile +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/conf.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/doc_tools/__init__.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/index.rst +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/src/about_the_docs.rst +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/src/api.rst +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/src/differences.rst +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/src/installation.rst +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/docs/src/samples/index.rst +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/emscripten_forge/recipe/build_pkg.sh +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/emscripten_forge/recipe/test_pyb2d3.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/billard.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/cast_ray_callback.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/chain_builder.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/coupled_minigolf.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/examples_common/ragdoll.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/joints.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/mirror.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/ragdoll.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/raycast.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/examples/pyb2d3_samples/shapes.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/extra_licenses/LICENSE_BOX2D +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/extra_licenses/LICENSE_NANOBIND +0 -0
- /pyb2d3-0.6.0/tests/conftest.py → /pyb2d3-0.7.2/extra_licenses/README +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/batch_api/batch_exporters.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/batch_api/ndarray_traits.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/batch_api.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/debug_draw.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/numpy_utils.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/py_chain_def.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/py_converter.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/threadpool.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/world_to_canvas.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/include/pyb2d3/wrapper_structs.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/scripts/README.md +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/scripts/examples_to_notebooks.sh +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_box2d_types.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_box2d_wrapper_structs.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_collision.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_extras.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_math_functions.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_threadpool.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/export_world_to_canvas.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/main.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/py_debug_draw.cpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/src/py_debug_draw.hpp +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/tests/__init__.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/tests/test_pyb2d3.py +0 -0
- {pyb2d3-0.6.0 → pyb2d3-0.7.2}/tests/test_samples.py +0 -0
|
@@ -35,36 +35,6 @@ else()
|
|
|
35
35
|
endif()
|
|
36
36
|
|
|
37
37
|
if(EMSCRIPTEN)
|
|
38
|
-
# set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
|
|
39
|
-
# set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1")
|
|
40
|
-
# set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1")
|
|
41
|
-
# set(CMAKE_STRIP FALSE) # used by default in pybind11 on .so modules
|
|
42
|
-
|
|
43
|
-
# # Create a target that holds Python module information
|
|
44
|
-
# add_library(MyFakePythonModule INTERFACE)
|
|
45
|
-
|
|
46
|
-
# # Define the include directories
|
|
47
|
-
# set_target_properties(MyFakePythonModule PROPERTIES
|
|
48
|
-
# INTERFACE_INCLUDE_DIRECTORIES "${Python_INCLUDE_DIRS}"
|
|
49
|
-
# )
|
|
50
|
-
|
|
51
|
-
# # Define the link libraries (the actual Python library)
|
|
52
|
-
# set_target_properties(MyFakePythonModule PROPERTIES
|
|
53
|
-
# INTERFACE_LINK_LIBRARIES "${Python_LIBRARIES}"
|
|
54
|
-
# )
|
|
55
|
-
|
|
56
|
-
# # Optionally, if nanobind uses the Python executable path:
|
|
57
|
-
# set_target_properties(MyFakePythonModule PROPERTIES
|
|
58
|
-
# INTERFACE_COMPILE_DEFINITIONS "PYTHON_EXECUTABLE=\"${Python_EXECUTABLE}\""
|
|
59
|
-
# )
|
|
60
|
-
|
|
61
|
-
# # Attempt to create an alias (might not fully satisfy the check)
|
|
62
|
-
# add_library(Python::Module ALIAS MyFakePythonModule)
|
|
63
|
-
|
|
64
|
-
# add f-exception flag to cxx and c flags linker-flags
|
|
65
|
-
# export CFLAGS="$CFLAGS -sWASM_BIGINT -fexceptions"
|
|
66
|
-
# export CXXFLAGS="$CXXFLAGS -sWASM_BIGINT -fexceptions"
|
|
67
|
-
# export LDFLAGS="$LDFLAGS -sWASM_BIGINT -fexceptions"
|
|
68
38
|
|
|
69
39
|
find_package(Python COMPONENTS Interpreter Development REQUIRED)
|
|
70
40
|
else()
|
|
@@ -104,11 +74,16 @@ endif()
|
|
|
104
74
|
if(NOT EMSCRIPTEN)
|
|
105
75
|
nanobind_add_module(_pyb2d3 STABLE_ABI ${PY_SOURCES})
|
|
106
76
|
else()
|
|
107
|
-
|
|
108
77
|
nanobind_add_module(_pyb2d3 ${PY_SOURCES})
|
|
109
78
|
endif()
|
|
110
79
|
|
|
111
80
|
|
|
81
|
+
# pass side module flags
|
|
82
|
+
if(EMSCRIPTEN)
|
|
83
|
+
set_target_properties(_pyb2d3 PROPERTIES LINK_FLAGS "-sSIDE_MODULE=1")
|
|
84
|
+
endif()
|
|
85
|
+
|
|
86
|
+
|
|
112
87
|
if(NOT PYB2D3_NO_THREADING)
|
|
113
88
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
114
89
|
find_package(Threads REQUIRED)
|
|
@@ -119,7 +94,6 @@ endif()
|
|
|
119
94
|
target_include_directories(_pyb2d3
|
|
120
95
|
PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
|
121
96
|
|
|
122
|
-
#add definitions
|
|
123
97
|
if(PYB2D3_NO_THREADING)
|
|
124
98
|
target_compile_definitions(_pyb2d3 PRIVATE PYB2D3_NO_THREADING)
|
|
125
99
|
endif()
|
|
@@ -149,7 +123,6 @@ if(DEFINED SKBUILD)
|
|
|
149
123
|
message(STATUS "using SKBUILD" ${SKBUILD})
|
|
150
124
|
install(TARGETS _pyb2d3 LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
|
|
151
125
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/module/pyb2d3/ DESTINATION ${SKBUILD_PROJECT_NAME})
|
|
152
|
-
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${SKBUILD_PROJECT_NAME}/include)
|
|
153
126
|
else()
|
|
154
127
|
message(STATUS "not using SKBUILD")
|
|
155
128
|
endif()
|
|
@@ -15,6 +15,8 @@ Install the python bindings with:
|
|
|
15
15
|
pip install pyb2d3
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
# conda based package
|
|
19
21
|
|
|
20
22
|
SOON!
|
|
@@ -60,3 +62,27 @@ That way, changes to the pure python code are immediately available without the
|
|
|
60
62
|
```bash
|
|
61
63
|
PYTHONPATH=$(pwd)/src/module pytest
|
|
62
64
|
```
|
|
65
|
+
|
|
66
|
+
# Testbed
|
|
67
|
+
|
|
68
|
+
To install the testbed use:
|
|
69
|
+
```bash
|
|
70
|
+
python -m pip install "pkg @ git+https://git@github.com/derthorsten/pyb2d3.git#subdirectory=companion_packages/pyb2d3_sandbox"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The testbed needs a frontend to run.
|
|
74
|
+
There are several frontends available, e.g.:
|
|
75
|
+
- opengl-based:
|
|
76
|
+
```bash
|
|
77
|
+
python -m pip install "pkg @ git+https://git@github.com/derthorsten/pyb2d3.git#subdirectory=companion_packages/pyb2d3_sandbox_opengl"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- pygame-based
|
|
81
|
+
```bash
|
|
82
|
+
python -m pip install "pkg @ git+https://git@github.com/derthorsten/pyb2d3.git#subdirectory=companion_packages/pyb2d3_sandbox_opengl"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- ipycanvas-based
|
|
86
|
+
```bash
|
|
87
|
+
python -m pip install "pkg @ git+https://git@github.com/derthorsten/pyb2d3.git#subdirectory=companion_packages/pyb2d3_sandbox_ipycanvas"
|
|
88
|
+
```
|
{pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/default_frontend.py
RENAMED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import traceback
|
|
2
|
+
import os
|
|
2
3
|
|
|
3
4
|
_CachedDefaultFrontend = None
|
|
4
5
|
|
|
6
|
+
has_pyjs = False
|
|
7
|
+
try:
|
|
8
|
+
import pyjs # noqa
|
|
9
|
+
|
|
10
|
+
has_pyjs = True
|
|
11
|
+
except ImportError:
|
|
12
|
+
pass
|
|
13
|
+
|
|
5
14
|
|
|
6
15
|
def is_notebook() -> bool:
|
|
7
16
|
try:
|
|
@@ -16,11 +25,37 @@ def is_notebook() -> bool:
|
|
|
16
25
|
return False # Probably standard Python interpreter
|
|
17
26
|
|
|
18
27
|
|
|
28
|
+
def compare_case_insensitive(a: str, b: str) -> bool:
|
|
29
|
+
"""
|
|
30
|
+
Compare two strings case-insensitively.
|
|
31
|
+
"""
|
|
32
|
+
return a.lower() == b.lower()
|
|
33
|
+
|
|
34
|
+
|
|
19
35
|
def get_default_frontend():
|
|
20
36
|
global _CachedDefaultFrontend
|
|
21
37
|
if _CachedDefaultFrontend is not None:
|
|
22
38
|
return _CachedDefaultFrontend
|
|
23
39
|
|
|
40
|
+
# check for certain env variables
|
|
41
|
+
PYB2D3_SANDBOX_DEFAULT_FRONTEND = os.environ.get("PYB2D3_SANDBOX_DEFAULT_FRONTEND", None)
|
|
42
|
+
if PYB2D3_SANDBOX_DEFAULT_FRONTEND:
|
|
43
|
+
if compare_case_insensitive(PYB2D3_SANDBOX_DEFAULT_FRONTEND, "OPENGL"):
|
|
44
|
+
from pyb2d3_sandbox_opengl import OpenglFrontend
|
|
45
|
+
|
|
46
|
+
_CachedDefaultFrontend = OpenglFrontend
|
|
47
|
+
return _CachedDefaultFrontend
|
|
48
|
+
elif compare_case_insensitive(PYB2D3_SANDBOX_DEFAULT_FRONTEND, "PYGAME"):
|
|
49
|
+
from pyb2d3_sandbox_pygame import PygameFrontend
|
|
50
|
+
|
|
51
|
+
_CachedDefaultFrontend = PygameFrontend
|
|
52
|
+
return _CachedDefaultFrontend
|
|
53
|
+
elif compare_case_insensitive(PYB2D3_SANDBOX_DEFAULT_FRONTEND, "IPYCANVAS"):
|
|
54
|
+
from pyb2d3_sandbox_ipycanvas import IpycanvasFrontend
|
|
55
|
+
|
|
56
|
+
_CachedDefaultFrontend = IpycanvasFrontend
|
|
57
|
+
return _CachedDefaultFrontend
|
|
58
|
+
|
|
24
59
|
tracebacks = []
|
|
25
60
|
|
|
26
61
|
if not is_notebook():
|
|
@@ -51,16 +86,29 @@ Tracebacks of the import errors:
|
|
|
51
86
|
{"".join(tracebacks)}""")
|
|
52
87
|
|
|
53
88
|
else:
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
# for vanilla-Jupyter we use "jupyter-frontend"
|
|
90
|
+
if not has_pyjs:
|
|
91
|
+
has_jupyter_frontend = True
|
|
92
|
+
try:
|
|
93
|
+
from pyb2d3_sandbox_jupyter import JupyterFrontend
|
|
94
|
+
except ImportError:
|
|
95
|
+
has_jupyter_frontend = False
|
|
96
|
+
tracebacks.append(traceback.format_exc())
|
|
97
|
+
if has_jupyter_frontend:
|
|
98
|
+
_CachedDefaultFrontend = JupyterFrontend
|
|
99
|
+
return _CachedDefaultFrontend
|
|
100
|
+
# for lite-Jupyter we use "ipycanvas-frontend"
|
|
101
|
+
else:
|
|
102
|
+
# Check if IpycanvasFrontend is available
|
|
103
|
+
has_ipycanvas_frontend = True
|
|
104
|
+
try:
|
|
105
|
+
from pyb2d3_sandbox_ipycanvas import IpycanvasFrontend
|
|
106
|
+
except ImportError:
|
|
107
|
+
has_ipycanvas_frontend = False
|
|
108
|
+
tracebacks.append(traceback.format_exc())
|
|
109
|
+
if has_ipycanvas_frontend:
|
|
110
|
+
_CachedDefaultFrontend = IpycanvasFrontend
|
|
111
|
+
return _CachedDefaultFrontend
|
|
64
112
|
|
|
65
113
|
raise ImportError(f"""No default frontend available. Please install pyb2d3-sandbox-ipycanvas for Jupyter notebook support.
|
|
66
114
|
Tracebacks of the import errors:
|
{pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/frontend_base.py
RENAMED
|
@@ -124,13 +124,15 @@ class DebugDrawSettings:
|
|
|
124
124
|
|
|
125
125
|
@dataclass
|
|
126
126
|
class FrontendBaseSettings:
|
|
127
|
-
canvas_shape: tuple = (
|
|
128
|
-
|
|
129
|
-
fps: int = 60
|
|
130
|
-
fixed_delta_t: bool = True # If True, use a fixed delta time for the physics simulation
|
|
127
|
+
canvas_shape: tuple = (800, 800)
|
|
131
128
|
|
|
129
|
+
hertz: int = 60 # Physics update frequency
|
|
130
|
+
speed: float = 1.0 # Speed multiplier for the simulation
|
|
132
131
|
substeps: int = 5
|
|
132
|
+
|
|
133
|
+
# depcrecated as as we center examples automatically
|
|
133
134
|
ppm: float = 40.0 # Pixels per meter
|
|
135
|
+
|
|
134
136
|
debug_draw: DebugDrawSettings = field(default_factory=DebugDrawSettings)
|
|
135
137
|
multi_click_delay_ms: int = 350 # Delay in milliseconds to wait for multi-clicks
|
|
136
138
|
headless: bool = False # If True, run in headless mode (no GUI)
|
|
@@ -194,6 +196,25 @@ class TripleClickEvent(MouseEvent):
|
|
|
194
196
|
super().__init__(world_position, handled)
|
|
195
197
|
|
|
196
198
|
|
|
199
|
+
class KeyDownEvent(Event):
|
|
200
|
+
def __init__(self, key, ctrl=False, shift=False, meta=False, alt=False, handled=False):
|
|
201
|
+
super().__init__(handled)
|
|
202
|
+
self.key = key
|
|
203
|
+
self.ctrl = ctrl
|
|
204
|
+
self.shift = shift
|
|
205
|
+
self.meta = meta
|
|
206
|
+
self.alt = alt
|
|
207
|
+
|
|
208
|
+
def __repr__(self):
|
|
209
|
+
return f"KeyDownEvent(key={self.key}, ctrl={self.ctrl}, shift={self.shift}, meta={self.meta}, alt={self.alt})"
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class KeyUpEvent(Event):
|
|
213
|
+
def __init__(self, key, handled=False):
|
|
214
|
+
super().__init__(handled)
|
|
215
|
+
self.key = key
|
|
216
|
+
|
|
217
|
+
|
|
197
218
|
class MultiClickHandler:
|
|
198
219
|
def __init__(self, delayed_time_ms, on_click, on_double_click=None, on_triple_click=None):
|
|
199
220
|
self.delayed_time = delayed_time_ms / 1000.0
|
|
@@ -286,6 +307,24 @@ class FrontendBase(ABC):
|
|
|
286
307
|
self.sample_update_time = None
|
|
287
308
|
self._multi_click_handler = None
|
|
288
309
|
|
|
310
|
+
# the last time when the world was updated
|
|
311
|
+
self.last_world_update_time = None
|
|
312
|
+
|
|
313
|
+
# the dt for the physics update
|
|
314
|
+
self.physics_update_dt = 1 / self.settings.hertz
|
|
315
|
+
|
|
316
|
+
self._is_paused = False
|
|
317
|
+
|
|
318
|
+
# store which key is currently pressed
|
|
319
|
+
self._pressed_keys = set()
|
|
320
|
+
|
|
321
|
+
def set_paused(self):
|
|
322
|
+
self._is_paused = True
|
|
323
|
+
self.last_world_update_time = None
|
|
324
|
+
|
|
325
|
+
def set_running(self):
|
|
326
|
+
self._is_paused = False
|
|
327
|
+
|
|
289
328
|
def set_sample(self, sample_class, sample_settings=None):
|
|
290
329
|
self.sample_class = sample_class
|
|
291
330
|
self.sample_settings = sample_settings
|
|
@@ -340,65 +379,57 @@ class FrontendBase(ABC):
|
|
|
340
379
|
# this is used to signal that the frontend is ready to run the sample
|
|
341
380
|
self._set_new_sample(self.sample_class, self.sample_settings)
|
|
342
381
|
|
|
343
|
-
def
|
|
344
|
-
|
|
345
|
-
self.debug_draw.begin_draw()
|
|
346
|
-
|
|
347
|
-
self.sample.pre_debug_draw()
|
|
348
|
-
t0 = time.time()
|
|
349
|
-
if self.settings.debug_draw.enabled:
|
|
350
|
-
self.sample.world.draw(self.debug_draw, call_begin_end=False)
|
|
351
|
-
self.acc_debug_draw_time += time.time() - t0
|
|
352
|
-
|
|
353
|
-
self.sample.post_debug_draw()
|
|
354
|
-
|
|
355
|
-
if self.settings.debug_draw.enabled:
|
|
356
|
-
self.debug_draw.end_draw()
|
|
357
|
-
|
|
358
|
-
def _sample_update_calls(self, dt):
|
|
359
|
-
# Update the world with the given time step
|
|
382
|
+
def update_physics_single_step(self):
|
|
383
|
+
dt = self.settings.speed / self.settings.hertz
|
|
360
384
|
self.sample.pre_update(dt)
|
|
361
|
-
t0 = time.time()
|
|
362
385
|
self.sample.update(dt)
|
|
363
|
-
self.sample_update_time = time.time() - t0
|
|
364
386
|
self.sample.post_update(dt)
|
|
365
|
-
self.acc_update_time += self.sample_update_time
|
|
366
387
|
|
|
367
|
-
def
|
|
368
|
-
if self.
|
|
369
|
-
# if
|
|
388
|
+
def update_physics(self):
|
|
389
|
+
if self._is_paused:
|
|
390
|
+
# if we are paused, we don't update the physics
|
|
391
|
+
return
|
|
392
|
+
expected_dt = 1 / self.settings.hertz
|
|
393
|
+
now = time.perf_counter()
|
|
394
|
+
if self.last_world_update_time is None:
|
|
395
|
+
self.update_physics_single_step()
|
|
396
|
+
self.last_world_update_time = now
|
|
370
397
|
return
|
|
398
|
+
|
|
399
|
+
dt = now - self.last_world_update_time
|
|
400
|
+
|
|
401
|
+
while dt >= expected_dt:
|
|
402
|
+
self.update_physics_single_step()
|
|
403
|
+
dt -= expected_dt
|
|
404
|
+
self.last_world_update_time += expected_dt
|
|
405
|
+
|
|
406
|
+
def update_frontend_logic(self):
|
|
407
|
+
if self._is_paused:
|
|
408
|
+
self._last_world_update_time = None
|
|
371
409
|
# do we need to change the sample class?
|
|
372
410
|
if self.change_sample_class_requested:
|
|
373
411
|
self.change_sample_class_requested = False
|
|
374
412
|
self.sample.post_run()
|
|
375
413
|
self._set_new_sample(self.sample_class, self.sample_settings)
|
|
376
414
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
self._sample_update_calls(dt)
|
|
381
|
-
self._debug_draw_calls()
|
|
382
|
-
else:
|
|
383
|
-
# click handler update
|
|
384
|
-
if self._multi_click_handler:
|
|
385
|
-
self._multi_click_handler.update()
|
|
386
|
-
self._sample_update_calls(dt)
|
|
387
|
-
self._debug_draw_calls()
|
|
388
|
-
self.iteration += 1
|
|
389
|
-
|
|
390
|
-
def on_play(self):
|
|
391
|
-
pass
|
|
415
|
+
# click handler update
|
|
416
|
+
if self._multi_click_handler is not None:
|
|
417
|
+
self._multi_click_handler.update()
|
|
392
418
|
|
|
393
|
-
def
|
|
394
|
-
|
|
419
|
+
def draw_physics(self):
|
|
420
|
+
t0 = time.time()
|
|
421
|
+
if self.settings.debug_draw.enabled:
|
|
422
|
+
self.debug_draw.begin_draw()
|
|
395
423
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
424
|
+
self.sample.pre_debug_draw()
|
|
425
|
+
if self.settings.debug_draw.enabled:
|
|
426
|
+
self.sample.world.draw(self.debug_draw, call_begin_end=False)
|
|
427
|
+
|
|
428
|
+
self.sample.post_debug_draw()
|
|
429
|
+
|
|
430
|
+
if self.settings.debug_draw.enabled:
|
|
431
|
+
self.debug_draw.end_draw()
|
|
432
|
+
self.acc_debug_draw_time += time.time() - t0
|
|
402
433
|
|
|
403
434
|
def stop(self):
|
|
404
435
|
self.set_sample(self.sample_class, self.sample_settings)
|
|
@@ -474,7 +505,7 @@ class FrontendBase(ABC):
|
|
|
474
505
|
transform.offset = world_delta
|
|
475
506
|
|
|
476
507
|
def is_paused(self):
|
|
477
|
-
return
|
|
508
|
+
return self._is_paused
|
|
478
509
|
|
|
479
510
|
@abstractmethod
|
|
480
511
|
def drag_camera(self, delta):
|
|
@@ -491,3 +522,28 @@ class FrontendBase(ABC):
|
|
|
491
522
|
|
|
492
523
|
def add_widget(self, element):
|
|
493
524
|
pass
|
|
525
|
+
|
|
526
|
+
def is_key_pressed(self, key):
|
|
527
|
+
"""Check if a key is pressed."""
|
|
528
|
+
return key in self._pressed_keys
|
|
529
|
+
|
|
530
|
+
def pressed_keys(self):
|
|
531
|
+
"""Get the currently pressed keys set"""
|
|
532
|
+
return self._pressed_keys
|
|
533
|
+
|
|
534
|
+
def _on_key_down(self, event):
|
|
535
|
+
"""Handle key down events."""
|
|
536
|
+
if event.key in self._pressed_keys:
|
|
537
|
+
# if the key is already pressed, we don't add it again
|
|
538
|
+
# this is because some frontend keep fireing the key down event
|
|
539
|
+
# when the key is pressed
|
|
540
|
+
# e.g. the ipycanvas frontend does this
|
|
541
|
+
return
|
|
542
|
+
self._pressed_keys.add(event.key)
|
|
543
|
+
self.sample.on_key_down(event)
|
|
544
|
+
|
|
545
|
+
def _on_key_up(self, event):
|
|
546
|
+
"""Handle key up events."""
|
|
547
|
+
if event.key in self._pressed_keys:
|
|
548
|
+
self._pressed_keys.remove(event.key)
|
|
549
|
+
self.sample.on_key_up(event)
|
{pyb2d3-0.6.0 → pyb2d3-0.7.2}/companion_packages/pyb2d3_sandbox/pyb2d3_sandbox/sample_base.py
RENAMED
|
@@ -187,3 +187,16 @@ class SampleBase(object):
|
|
|
187
187
|
def on_mouse_wheel(self, event):
|
|
188
188
|
# Handle mouse wheel events
|
|
189
189
|
self.frontend.change_zoom(event.delta)
|
|
190
|
+
|
|
191
|
+
def is_key_pressed(self, key):
|
|
192
|
+
return self.frontend.is_key_pressed(key)
|
|
193
|
+
|
|
194
|
+
def pressed_keys(self):
|
|
195
|
+
return self.frontend.pressed_keys()
|
|
196
|
+
|
|
197
|
+
def on_key_down(self, event):
|
|
198
|
+
# print("Key down:", event.key)
|
|
199
|
+
pass
|
|
200
|
+
|
|
201
|
+
def on_key_up(self, event):
|
|
202
|
+
pass
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyb2d3-sandbox"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.7.2"
|
|
4
4
|
description = "sandbox for pyb2d3"
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Dr. Thorsten Beier", email = "derthorstenbeier@gmail.com" }
|
|
@@ -9,6 +9,11 @@ readme = "README.md"
|
|
|
9
9
|
requires-python = ">=3.9"
|
|
10
10
|
license = { text = "MIT" }
|
|
11
11
|
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pyb2d3>=0.7.2"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
12
17
|
[project.urls]
|
|
13
18
|
"Homepage" = "https://github.com/DerThorsten/pyb2d3"
|
|
14
19
|
|