Skip to content

Commit

Permalink
(docs): add a README describing physijs changes
Browse files Browse the repository at this point in the history
- this makes it more explicit why it's been vendored in -- it has
  incompatible changes -- and makes more explicit what those changes
  are with documentation (instead of just commit messages)
  - it also explains why those changes were made, with lots of links
    as there's a decent bit of context around that
    - and this context is key to what made this library possible, so
      it's good to have finally documented it!

- also add the same worker links to the app root README for anyone
  who might want more info on those

- (pkg): modify package.json files config so that this new README
  isn't included in the package
  • Loading branch information
agilgur5 committed Nov 25, 2019
1 parent ac3f5ee commit bdf5e4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ npm install -S physijs-webpack
var Physijs = require('physijs-webpack');
```

and install `worker-loader` with:
and install [`worker-loader`](https://github.com/webpack-contrib/worker-loader) with:

```bash
npm install -D worker-loader
Expand All @@ -42,7 +42,7 @@ npm install -D worker-loader
var Physijs = require('physijs-webpack/browserify');
```

and install `webworkify` with:
and install [`webworkify`](https://github.com/browserify/webworkify) with:

```bash
npm install -D webworkify
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "PhysiJS port for bundlers with out-of-the-box support for Webpack and Browserify",
"main": "webpack.js",
"files": [
"physijs/*",
"physijs/**/*.js",
"webpack.js",
"browserify.js",
"browserify-worker-stub.js"
Expand Down
18 changes: 18 additions & 0 deletions physijs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# PhysiJS Changes

The files here are 99.9% the same as the original [`physijs`](https://github.com/chandlerprall/Physijs) code.
There are a few small modifications to make it compatible with bundlers and work out-of-the-box with zero config:

- accepting the `PhysijsWorker` constructor function as an argument instead of just using `new Worker(...)`
- this allows for custom workers, such as those of [`worker-loader`](https://github.com/webpack-contrib/worker-loader) and [`webworkify`](https://github.com/browserify/webworkify)
- it also means one no longer has to set `Physijs.scripts.worker`
- `require`ing `ammo.js` directly in the `physijs_worker.js` file instead of using [`importScripts`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers#Importing_scripts_and_libraries)
- this can only be done because of the extra functionality we get from a bundler and its custom worker
- this means one no longer has to set `Physijs.scripts.ammo`
- slightly change the `Ammo` code so it doesn't try to `require` anything in its Emscripten header
- Emscripten (or at least the old version that was used to create Physijs's old vendored `ammo.js`) output both web and node code in one file, so it caused issues when being parsed by bundlers (can read more [here](https://github.com/agilgur5/physijs-webpack/commit/0174f2c073f62684c764b83cacf66102445d2218))

[`silviopaganini/physijs-browserify`](https://github.com/silviopaganini/physijs-browserify), which this library was originally based off, also made some changes:

- exporting as a CJS module with `module.exports` instead of a global with `window.Physijs`
- accepting [`THREE`](https://github.com/mrdoob/three.js) as an argument instead of assuming it exists as a global

0 comments on commit bdf5e4a

Please sign in to comment.