chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.77k stars 455 forks source link

[Bug Fix] Migrate to ES6 classes #334

Open paxorus opened 2 years ago

paxorus commented 2 years ago

Problem

Issue: #329

Users are hitting the fatal error Uncaught TypeError: class constructors must be invoked with 'new' when trying to create Physijs Scene with recent versions of Three.js. This is due to the outdated inheritance method used by THREE.Scene.call( this, params ).

Solution

Update to ES6 classes, everywhere. Also, convert Eventable to be a mix-in. This should make Physi.js basically compatible with the current version of Three.js (r143). This is a giant diff, converting all classes to ES6 at once, because of compatibility issues between ES6 classes (prototype read-only) and the old inheritance method (modifies prototype).

Please review the file side-by-side with the current physi.js, locally in two editor windows, as the Git diff computed very poorly, despite there being no changes to business logic. The number of lines changed is in the dozens, not 1,000.

Testing

Ran my personal project (https://github.com/paxorus/physi-creator) which uses Scene and several Mesh types with this version of the code. The error was gone.