1.0.8 • Published 1 year ago

@cocos/physx v1.0.8

Weekly downloads
109
License
ISC
Repository
github
Last release
1 year ago

PhysX JS

PhysX for JavaScript.

This repo complements the work being done over at prestomation/PhysX to create emscripten bindings for NVIDIAGameWorks/PhysX. At some point the prestomation/PhysX fork may be merged into NVIDIAGameWorks/PhysX and this repo will be updated to track that repo instead.

This repo serves multiple purposes:

  • Provide a Docker workflow for compiling and building PhysX to WebAssembly via Emscripten
  • Provide a Docker workflow for adding new bindings (the whole PhysX API is not currently covered yet)
  • To publish WebAssembly files to npm (physx-js) so that they can be used in projects via npm or CDN

Example

There is an example with threejs and physx-js using Webpack in the /example folder. The example is also available to preview here, it's hosted on now

Usage via npm

npm install physx-js

The physx.release.js file can be imported via Webpack or included as a script on the page

The physx.release.wasm file needs to be served in a static/public folder so that it can be loaded in a browser environment

See /example for how this can be done using Webpack.

Usage via CDN (jsDelivr)

You may want to load the WebAssembly files via CDN, in which case you can use jsDelivr's npm mirror, loaded as a script:

<script src="https://cdn.jsdelivr.net/npm/physx-js/dist/physx.release.js">

You can also target a specific version:

<script src="https://cdn.jsdelivr.net/npm/physx-js@0.0.6/dist/physx.release.js">

Then configure this to also load the wasm file from the same place:

PHYSX({
  locateFile(path) {
    if (path.endsWith('.wasm')) {
      return 'https://cdn.jsdelivr.net/npm/physx-js@0.0.6/dist/physx.release.wasm'
    }
    return path
  }
})

Development

You can build the source yourself and/or add new bindings. The full PhysX API isn't covered yet but more will be added

The only dependencies you need to do this are Docker, node and npm. All other dependencies are managed inside the docker image.

// Clone this repo
git clone https://github.com/ashconnell/physx-js.git

// Install/update the PhysX source dependency
npm install

// Generate the project (i believe this only needs to be run once, can take a while)
npm run generate

// Build WebAssembly files (physx.release.js and physx.release.wasm)
npm run make

This will start a docker container, mount the PhysX source code and then build and compile it using emscripten.

The output files (js and wasm) are copied into ./dist

If you want to add new bindings, edit physx/source/physxwebbindings/src/PxWebBindings.cpp and then run npm run make to build it.

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6-beta.1

3 years ago

1.0.6-beta.2

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago