GithubHelp home page GithubHelp logo

physx-js's Introduction

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 /examples for how this can be used in Node, Browser and Browser w/ 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/[email protected]/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/[email protected]/dist/physx.release.wasm'
    }
    return path
  }
})

Development

You may want to make your own builds from source, or modify the bindings yourself. The full PhysX API isn't covered yet but more will be added in the future.

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

The scripts run from this repo expect the repo prestomation/PhysX#emscripten_wip to be mounted here at ./PhysX.

// Install dependencies
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)
// This is all that needs to be run after making changes to bindings.
npm run make

These scripts 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/physx/source/physxwebbindings/src/PxWebBindings.cpp and then run npm run make to rebuild.

physx-js's People

Contributors

ashconnell avatar zach-capalbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

physx-js's Issues

Are there any metrics about performance of this library?

It sounds ideal to get to use physx in the web, especially for applications that have separate web and native clients. Does this library have any performance metrics comparing it to other popular js bindings such as Ammo or Bullet? Thanks.

physx-js as ES6 module

Hello,

I am trying to use physx-js v0.7.0 as ES6 module but I have this error:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/wasm". Strict MIME type checking is enforced for module scripts per HTML spec.

Sandbox: https://plnkr.co/edit/B0kWbwZqFipXnFIX?preview

<body>
    <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>

    <script type="importmap">
        {
            "imports": {
                "physx-js": "https://cdn.jsdelivr.net/npm/[email protected]/dist/physx.release.js",
                "physx-js-wasm": "https://cdn.jsdelivr.net/npm/[email protected]/dist/physx.release.wasm"
            }
        }
    </script>

    <script type="module">
        import physx from "physx-js";
        import physxModule from "physx-js-wasm";

        const PhysX = physx({
            locateFile(path)
            {
                if (path.endsWith(".wasm"))
                {
                    return physxModule;
                }
                return path;
            },
            onRuntimeInitialized()
            {
                console.log("PhysX loaded");
            }
        });
    </script>
</body>

Unable to npm install

I'm not terribly familiar with npm so I'm not entirely sure if this is an issue on my end or not(sorry if it is), but I'm unable to run npm install after cloning the repo. This is the log that I get

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/10.12.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'install' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session af4b2e3d4e35ebdf
5 silly install runPreinstallTopLevelLifecycles
6 silly preinstall [email protected]
7 info lifecycle [email protected]~preinstall: [email protected]
8 silly install loadCurrentTree
9 silly install readLocalPackageData
10 timing stage:loadCurrentTree Completed in 8ms
11 silly install loadIdealTree
12 silly install cloneCurrentTreeToIdealTree
13 timing stage:loadIdealTree:cloneCurrentTree Completed in 0ms
14 silly install loadShrinkwrap
15 timing stage:loadIdealTree:loadShrinkwrap Completed in 1ms
16 silly install loadAllDepsIntoIdealTree
17 silly fetchPackageMetaData error for physx@github:prestomation/PhysX#emscripten_wip premature close
18 timing stage:rollbackFailedOptional Completed in 0ms
19 timing stage:runTopLevelLifecycles Completed in 18019ms
20 silly saveTree [email protected]
21 verbose stack Error: premature close
21 verbose stack     at PassThrough.onclose (/usr/local/lib/node_modules/npm/node_modules/end-of-stream/index.js:47:67)
21 verbose stack     at PassThrough.emit (events.js:187:15)
21 verbose stack     at emitCloseNT (internal/streams/destroy.js:59:8)
21 verbose stack     at process._tickCallback (internal/process/next_tick.js:63:19)
22 verbose cwd /Users/kalegd/Documents/workspace/xr_websites/experiments/physx/tmp/physx-js
23 verbose Darwin 18.7.0
24 verbose argv "/usr/local/Cellar/node/10.12.0/bin/node" "/usr/local/bin/npm" "install"
25 verbose node v10.12.0
26 verbose npm  v6.4.1
27 error premature close
28 verbose exit [ 1, true ]

It looks like the error is in this line
17 silly fetchPackageMetaData error for physx@github:prestomation/PhysX#emscripten_wip premature close

But I have no idea why as that's a valid branch

(side note, thank you for putting up this up! I've really enjoyed integrating PhysX with three.js over the past month!)

Compilation errors

I'm using this code to build PhysX, and hitting a couple of errors during the make stage that prevent the build from completing.

First error was this:

/src/PhysX/physx/source/physx/src/NpBatchQuery.cpp:369:33: error: variable 'hitsSpaceLeft' is uninitialized when passed as a const reference argument here [-Werror,-Wuninitialized-const-reference]
        PxU32 hitsSpaceLeft; PX_UNUSED(hitsSpaceLeft);
                                       ^~~~~~~~~~~~~
1 error generated.

I was able to workaround by adjusting the line in NpBatchQuery.cpp to initialize histSpaceLeft like this

        PxU32 hitsSpaceLeft = 0; PX_UNUSED(hitsSpaceLeft);

That resolved that error, but then I hit another error.

/src/PhysX/physx/source/physxextensions/src/ExtSharedQueueEntryPool.h:104:33: error: ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~' [-Werror,-Wdtor-name]
Ext::SharedQueueEntryPool<Alloc>::~SharedQueueEntryPool()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
                                ::SharedQueueEntryPool
1 error generated.

The PhysX code I am building is from this repo:
https://github.com/diarmidmackenzie/PhysX-1/tree/joint-projection

Which has just one change vs. this:
https://github.com/zach-capalbo/PhysX

Which has only a few changes vs. this:
https://github.com/ashconnell/PhysX

None of these changes seem in any way related to the errors above. It seems odd to be hitting compiler errors in core PhysX code that I've not touched at all. Could my build somehow be running with different compiler, or different compiler flags vs. what other people have run?

I am running in a WSL2 VM on Windows, with Docker Desktop. My understanding was that the build environment should be entirely contained inside the docker container, so shouldn't be affected by the underlying OS it's running on.

Next step, I'm going to try a clean check-out of https://github.com/ashconnell/physx-js and https://github.com/ashconnell/PhysX and see if I get any better results...

Selfbuilt release has dependency to wasi_snapshot_preview1 and cannot be loaded in browser

Hi,

I managed to run the build procedure and got my own physx.release.js and .wasm files. However when I try to load them in a browser I get the error "WebAssembly.instantiate(): Import #43 module="wasi_snapshot_preview1" error: module is not an object or function"

I did some googling and apparently WASI is a module which provides system functions within a Node environment and is not available in browsers.

The publicly available physx-js release does not have that issue so I'm guessing it's some kind of config issue and/or I'm doing something wrong?

Collision detection does not work with versions > 0.0.6

Hi!

I am a very beginner with JS and webpack so I may just be doing something wrong. I tried the following steps:

  • Cloned this repo.
  • cd example
  • npm install
  • npm run start.

And I get the expect results with falling cubes hitting the ground.

However, if I modify the package.json and set the physx-rs dependency to its latest version 0.0.9, re-run npm install and npm run start, I see the falling cubes but they just pass through the ground instead of hitting it. Is there some additional PhysX scene configuration do to in order to make the version 0.0.9 of physx-rs work?

Publish all build configurations

We currently only build the release configuration, but it would be nice to build the others (debug, profile, checked) and publish those to npm as well.

emscripten.xml missing

I'm try to build PhysX 4.1 But it shows

image
image
There is no preset named emscripten.xml
Can you upload the emscripten.xml preset?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.