├── .github └── workflows │ ├── main.yml │ └── release.yml ├── .gitignore ├── .gitmodules ├── Dockerfile ├── LICENSE ├── NOTICE.md ├── README.md ├── dist ├── NOTICE.md ├── README.md ├── helloworld.html └── package.json ├── docker-compose.yaml ├── generate.sh ├── make-debug.sh ├── make-profile.sh ├── make.sh └── types ├── generate.js ├── generate_types.sh ├── jsconfig.json ├── package-lock.json └── package.json /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: PhysX-JS-WebIDL - Build Library 2 | 3 | on: 4 | push 5 | 6 | jobs: 7 | build: 8 | name: Build PhysX-JS-WebIDL 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout Repository 12 | uses: actions/checkout@v4 13 | with: 14 | lfs: true 15 | submodules: recursive 16 | 17 | - name: Set up Docker Compose 18 | run: | 19 | sudo apt-get update 20 | sudo apt-get install -y docker-compose 21 | 22 | - name: Build Docker Environment 23 | run: sudo docker compose up 24 | 25 | - name: Build PhysX-JS-WebIDL 26 | run: sudo docker compose run --rm builder ./make.sh 27 | 28 | # Upload the build results - Retained for 90 days by default 29 | - name: Upload Build Artifacts 30 | uses: actions/upload-artifact@v4 31 | if: ${{ always() }} 32 | with: 33 | name: Build Products 34 | path: dist 35 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: PhysX-JS-WebIDL - Release Library 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | build: 10 | name: Build PhysX-JS-WebIDL 11 | runs-on: ubuntu-latest 12 | environment: publish 13 | permissions: 14 | contents: write 15 | id-token: write 16 | 17 | steps: 18 | - name: Checkout Repository 19 | uses: actions/checkout@v4 20 | with: 21 | lfs: true 22 | submodules: recursive 23 | 24 | - name: Set up Docker Compose 25 | run: | 26 | sudo apt-get update 27 | sudo apt-get install -y docker-compose 28 | 29 | - name: Build Docker Environment 30 | run: sudo docker compose up 31 | 32 | - name: Build PhysX-JS-WebIDL 33 | run: sudo docker compose run --rm builder ./make.sh 34 | 35 | - name: Create release 36 | uses: ncipollo/release-action@v1 37 | with: 38 | allowUpdates: true 39 | artifacts: "dist/*" 40 | draft: true 41 | updateOnlyUnreleased: true 42 | 43 | - name: Setup node 44 | uses: actions/setup-node@v4 45 | with: 46 | node-version: '20.x' 47 | registry-url: 'https://registry.npmjs.org' 48 | 49 | - name: Publish to npmjs 50 | working-directory: ./dist 51 | run: npm publish --provenance --access public 52 | env: 53 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 54 | 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "PhysX"] 2 | path = PhysX 3 | url = git@github.com:fabmax/PhysX.git 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM emscripten/emsdk:3.1.51 2 | 3 | RUN apt-get update 4 | RUN apt-get install python3 -y 5 | RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash \ 6 | && export NVM_DIR="$HOME/.nvm" \ 7 | && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \ 8 | && nvm install 20.17.0 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Max Thiele 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NOTICE.md: -------------------------------------------------------------------------------- 1 | # Notices for physx-js-webidl 2 | 3 | * Project home: https://github.com/fabmax/physx-js-webidl 4 | 5 | ## Declared Project Licenses 6 | 7 | This program and the accompanying materials are made available under the terms 8 | of the **MIT License** which is available at https://opensource.org/licenses/MIT 9 | 10 | ## Third-party Content 11 | 12 | This software includes a binary distribution of [NVIDIA PhysX 5.6.0](https://github.com/NVIDIAGameWorks/PhysX). 13 | 14 | NVIDIA PhysX comes under the following license: 15 | 16 | ``` 17 | Copyright (c) 2021 NVIDIA Corporation. All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | * Redistributions of source code must retain the above copyright 23 | notice, this list of conditions and the following disclaimer. 24 | * Redistributions in binary form must reproduce the above copyright 25 | notice, this list of conditions and the following disclaimer in the 26 | documentation and/or other materials provided with the distribution. 27 | * Neither the name of NVIDIA CORPORATION nor the names of its 28 | contributors may be used to endorse or promote products derived 29 | from this software without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 32 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 34 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 35 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 36 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 37 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 38 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 39 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # physx-js-webidl 2 | Javascript/WASM bindings for Nvidia PhysX 5.6.0. 3 | 4 | Looking for pre-built binaries / build instructions? See [below](#pre-built-binaries) 5 | 6 | ## Library coverage 7 | 8 | The bindings include most major parts of the PhysX SDK (excluding CUDA stuff, which is not possible with WASM): 9 | - [x] Basics 10 | - Static and dynamic actors 11 | - All geometry types (box, capsule, sphere, plane, convex mesh, triangle mesh and height field) 12 | - [x] All joint types (revolute, spherical, prismatic, fixed, distance and D6) 13 | - [x] Articulations 14 | - [x] Vehicles 15 | - [x] Character controllers 16 | - [x] Scene serialization 17 | 18 | ## Getting started 19 | There is a basic [hello world example](dist/helloworld.html): 10 boxes falling on the ground (drawn as wireframe on a plain canvas). 20 | 21 | ## Documentation 22 | The API is very close to the original PhysX C++ API, so you can simply use the official 23 | [PhysX API documentation](https://nvidia-omniverse.github.io/PhysX/physx/5.6.0/index.html) 24 | 25 | However, in order to make the bindings work with emscripten a few additional wrappers are needed here and there. So it might 26 | make sense to also take a look into the [PhysXWasm.idl](https://github.com/fabmax/PhysX/blob/webidl-bindings/physx/source/webidlbindings/src/wasm/PhysXWasm.idl) 27 | interface definiton file. 28 | 29 | Update as of `v2.2.0`: Thanks to Shannon Poole, PhysX enums can now be accessed by their qualified names (e.g. `PhysX.PxIDENTITYEnum.PxIdentity`, 30 | see also the hello world demo mentioned above). 31 | 32 | ## Demos 33 | I use this library in my engine [kool](https://github.com/fabmax/kool) and have a few demos in place: 34 | - [Vehicle](https://fabmax.github.io/kool/kool-js/?demo=phys-vehicle): Basic vehicle demo with a few obstacles. 35 | - [Character](https://fabmax.github.io/kool/kool-js/?demo=phys-terrain): 3rd person character demo on an island. 36 | - [Ragdolls](https://fabmax.github.io/kool/kool-js/?demo=phys-ragdoll): A simple ragdoll demo. 37 | - [Joints](https://fabmax.github.io/kool/kool-js/?demo=phys-joints): A chain running over two gears. 38 | - [Collision](https://fabmax.github.io/kool/kool-js/?demo=physics): The obligatory box (and other shapes) collision physics demo. 39 | 40 | However, the demos are written in kotlin, not javascript. 41 | 42 | ## Pre-built binaries 43 | This library is published as a [npm package](https://www.npmjs.com/package/physx-js-webidl): 44 | ``` 45 | npm i physx-js-webidl 46 | ``` 47 | Alternatively you can grab the pre-built binaries (.wasm + support .js) from the latest [Release](https://github.com/fabmax/physx-js-webidl/releases). 48 | 49 | ## Building 50 | In order to build the library you need a recent version of the [emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) - I'm 51 | using version `3.1.51`. Alternatively, you can use docker as described below. 52 | After successful build, the binaries (.wasm + support .js) will appear in the `dist` directory. 53 | 54 | ``` 55 | # Clone this repo 56 | git clone https://github.com/fabmax/physx-js-webidl 57 | 58 | # Enter that directory 59 | cd physx-js-webidl 60 | 61 | # Download submodule containing the PhysX code 62 | git submodule update --init 63 | 64 | # Generate build-scripts 65 | ./generate.sh 66 | 67 | # Build 68 | ./make.sh 69 | ``` 70 | 71 | To add bindings to additional PhysX interfaces you only have to edit the 72 | [PhysXJs.idl](https://github.com/fabmax/PhysX/blob/webidl-bindings/physx/source/webidlbindings/src/wasm/PhysXWasm.idl) 73 | file located in `PhysX/physx/source/webidlbindings/src/wasm/` and recompile the library. 74 | 75 | ### Build with Docker 76 | 77 | The docker build also generates typescript definitions. 78 | 79 | ``` 80 | # Build the image 81 | docker compose up 82 | 83 | # Build Release 84 | docker compose run --rm builder ./make.sh 85 | 86 | # Build Profile 87 | docker compose run --rm builder ./make-profile.sh 88 | 89 | # Build Debug 90 | docker compose run --rm builder ./make-debug.sh 91 | ``` 92 | 93 | -------------------------------------------------------------------------------- /dist/NOTICE.md: -------------------------------------------------------------------------------- 1 | # Notices for physx-js-webidl 2 | 3 | * Project home: https://github.com/fabmax/physx-js-webidl 4 | 5 | ## Declared Project Licenses 6 | 7 | This program and the accompanying materials are made available under the terms 8 | of the **MIT License** which is available at https://opensource.org/licenses/MIT 9 | 10 | ## Third-party Content 11 | 12 | This software includes a binary distribution of [NVIDIA PhysX 5.6.0](https://github.com/NVIDIAGameWorks/PhysX). 13 | 14 | NVIDIA PhysX comes under the following license: 15 | 16 | ``` 17 | Copyright (c) 2021 NVIDIA Corporation. All rights reserved. 18 | 19 | Redistribution and use in source and binary forms, with or without 20 | modification, are permitted provided that the following conditions 21 | are met: 22 | * Redistributions of source code must retain the above copyright 23 | notice, this list of conditions and the following disclaimer. 24 | * Redistributions in binary form must reproduce the above copyright 25 | notice, this list of conditions and the following disclaimer in the 26 | documentation and/or other materials provided with the distribution. 27 | * Neither the name of NVIDIA CORPORATION nor the names of its 28 | contributors may be used to endorse or promote products derived 29 | from this software without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 32 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 34 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 35 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 36 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 37 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 38 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 39 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42 | ``` -------------------------------------------------------------------------------- /dist/README.md: -------------------------------------------------------------------------------- 1 | # physx-js-webidl 2 | Javascript/WASM bindings for Nvidia PhysX 5.6.0. 3 | 4 | Looking for pre-built binaries / build instructions? See [below](#pre-built-binaries) 5 | 6 | ## Library coverage 7 | 8 | The bindings include most major parts of the PhysX SDK (excluding CUDA stuff, which is not possible with WASM): 9 | - [x] Basics 10 | - Static and dynamic actors 11 | - All geometry types (box, capsule, sphere, plane, convex mesh, triangle mesh and height field) 12 | - [x] All joint types (revolute, spherical, prismatic, fixed, distance and D6) 13 | - [x] Articulations 14 | - [x] Vehicles 15 | - [x] Character controllers 16 | - [x] Scene serialization 17 | 18 | ## Getting started 19 | There is a basic [hello world example](dist/helloworld.html): 10 boxes falling on the ground (drawn as wireframe on a plain canvas). 20 | 21 | ## Documentation 22 | The API is very close to the original PhysX C++ API, so you can simply use the official 23 | [PhysX API documentation](https://nvidia-omniverse.github.io/PhysX/physx/5.6.0/index.html) 24 | 25 | However, in order to make the bindings work with emscripten a few additional wrappers are needed here and there. So it might 26 | make sense to also take a look into the [PhysXWasm.idl](https://github.com/fabmax/PhysX/blob/webidl-bindings/physx/source/webidlbindings/src/wasm/PhysXWasm.idl) 27 | interface definiton file. 28 | 29 | Update as of `v2.2.0`: Thanks to Shannon Poole, PhysX enums can now be accessed by their qualified names (e.g. `PhysX.PxIDENTITYEnum.PxIdentity`, 30 | see also the hello world demo mentioned above). 31 | 32 | ## Demos 33 | I use this library in my engine [kool](https://github.com/fabmax/kool) and have a few demos in place: 34 | - [Vehicle](https://fabmax.github.io/kool/kool-js/?demo=phys-vehicle): Basic vehicle demo with a few obstacles. 35 | - [Character](https://fabmax.github.io/kool/kool-js/?demo=phys-terrain): 3rd person character demo on an island. 36 | - [Ragdolls](https://fabmax.github.io/kool/kool-js/?demo=phys-ragdoll): A simple ragdoll demo. 37 | - [Joints](https://fabmax.github.io/kool/kool-js/?demo=phys-joints): A chain running over two gears. 38 | - [Collision](https://fabmax.github.io/kool/kool-js/?demo=physics): The obligatory box (and other shapes) collision physics demo. 39 | 40 | However, the demos are written in kotlin, not javascript. 41 | 42 | ## Pre-built binaries 43 | This library is published as a [npm package](https://www.npmjs.com/package/physx-js-webidl): 44 | ``` 45 | npm i physx-js-webidl 46 | ``` 47 | Alternatively you can grab the pre-built binaries (.wasm + support .js) from the latest [Release](https://github.com/fabmax/physx-js-webidl/releases). 48 | 49 | ## Building 50 | In order to build the library you need a recent version of the [emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) - I'm 51 | using version `3.1.51`. Alternatively, you can use docker as described below. 52 | After successful build, the binaries (.wasm + support .js) will appear in the `dist` directory. 53 | 54 | ``` 55 | # Clone this repo 56 | git clone https://github.com/fabmax/physx-js-webidl 57 | 58 | # Enter that directory 59 | cd physx-js-webidl 60 | 61 | # Download submodule containing the PhysX code 62 | git submodule update --init 63 | 64 | # Generate build-scripts 65 | ./generate.sh 66 | 67 | # Build 68 | ./make.sh 69 | ``` 70 | 71 | To add bindings to additional PhysX interfaces you only have to edit the 72 | [PhysXJs.idl](https://github.com/fabmax/PhysX/blob/webidl-bindings/physx/source/webidlbindings/src/wasm/PhysXWasm.idl) 73 | file located in `PhysX/physx/source/webidlbindings/src/wasm/` and recompile the library. 74 | 75 | ### Build with Docker 76 | 77 | The docker build also generates typescript definitions. 78 | 79 | ``` 80 | # Build the image 81 | docker compose up 82 | 83 | # Build Release 84 | docker compose run --rm builder ./make.sh 85 | 86 | # Build Profile 87 | docker compose run --rm builder ./make-profile.sh 88 | 89 | # Build Debug 90 | docker compose run --rm builder ./make-debug.sh 91 | ``` 92 | 93 | -------------------------------------------------------------------------------- /dist/helloworld.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |