Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browserify Integration is not working (PhysijsWorker is not a constructor) #2

Closed
mpaccione opened this issue Jun 10, 2019 · 3 comments · Fixed by #5
Closed

Browserify Integration is not working (PhysijsWorker is not a constructor) #2

mpaccione opened this issue Jun 10, 2019 · 3 comments · Fixed by #5

Comments

@mpaccione
Copy link

mpaccione commented Jun 10, 2019

Hello I followed the instructions to install for browserfy via npm module.

npm install -S physijs-webpack
npm install -D webworkify

const Physijs = require('physijs-webpack/browserify');
...
const scene = new Physijs.Scene({ reportSize: 4, fixedTimeStep: 1/60 });

However, I get the following error:

Uncaught TypeError: PhysijsWorker is not a constructor at new Physijs.Scene (bundle.js:61514) at Object.2../src/classes/audio (bundle.js:207) at o (bundle.js:1) at r (bundle.js:1) at bundle.js:1

The error occurs here:

// Physijs.Scene
	Physijs.Scene = function( params ) {
		var self = this;

		Eventable.call( this );
		THREE.Scene.call( this );

		this._worker = new PhysijsWorker();   // HERE   

Really looking for a solution here!
I am building this project https://github.com/mpaccione/everest_flight_sim and have found building my own physics engine is beyond my current skills.

@agilgur5
Copy link
Owner

Ah, I think I may have misconfigured the Browserify variant -- per the current docs at least, calling work(...) apparently instantiates the worker right there so it needs to be wrapped in a class (or function) to match the Webpack variant's behavior so that it remains that no external configuration is needed.

This was primarily used in LTLMoPWeb3D which has been using Webpack in recent years, so I didn't extensively test the Browserify integration, my bad. Should probably add some small unit tests to cover this.

I'm not at my computer right now, but if you need a quick fix and want to try on your own you can edit the browserify.js in your node_modules to wrap the call to work in a class & constructor and that should probably do it. I'll have to look into it more later to see how well this matches the Webpack behavior.

Also I don't believe the issue on the physijs core repo is relevant since this issue is with this library's browserify integration (and physijs core does not have one, hence the existence of this library)

@mpaccione
Copy link
Author

Okay, I have a flight leaving from Kathmandu, Nepal today to San Francisco, USA. Including layover its, a day and a half.

If I have time or after I get back into San Francisco I will investigate further if it isn't fixed and see if I can fix it myself and do a PR.

Physijs is perfect for my Three.js project and I look forward to getting this problem solved for myself and everyone else! Thanks for making the NPM Module. :)

@agilgur5 agilgur5 changed the title PhysijsWorker is not a constructor Browserify Integration is not working (PhysijsWorker is not a constructor) Jun 13, 2019
@agilgur5 agilgur5 mentioned this issue Jun 13, 2019
@agilgur5
Copy link
Owner

Physijs is perfect for my Three.js project and I look forward to getting this problem solved for myself and everyone else! Thanks for making the NPM Module. :)

Thanks for the effort and you're welcome!
I saw you made some issues in Three and I just wanted to make sure you were aware that PhysiJS only supports up to Three r73 (i.e. a few years behind). physijs-webpack locks the peerDep to r73 for this very reason. That may limit the features you're able to use and potentially cause some headaches.
Based on chanderprall's previous updates, there's probably a non-trivial amount of work needed to update it to latest Three, but potentially doable (idk, PhysiJS hasn't been maintained in several years) 😕
You might also want to check out WhitestormJS per this repo's README. It's newer but also doesn't seem to have been maintained in the past year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants