jaredyork / physics-shaper

An open source editor for defining physics shapes, exportable to a variety of frameworks.
6 stars 0 forks source link

Default export format is incompatible with Phaser 3 Matter physics #1

Open sbine opened 5 years ago

sbine commented 5 years ago

Hi there, Thanks for this great open source editor! I'm playing around with Phaser 3 and tried to use an export file from this tool to create a complex shape, but it seems (at least for the Matter physics engine) that Phaser expects the "type" of the shape to be fromPhysicsEditor: https://github.com/photonstorm/phaser/blob/c91ed91ce37ae0838ee36adc56c63e81d48ebe66/src/physics/matter-js/components/SetBody.js#L229

while this tool exports "type" as fromPhysicsShaper: https://github.com/jaredyork/physics-shaper/blob/3b9284f0f209a7b733351d44cf6f318a2c480e8b/src/js/SceneMain.js#L14

I had to change this value to fromPhysicsEditor in my export file to get my shapes to load correctly. For anyone else who may be Googling, the error thrown was:

Uncaught TypeError: Cannot read property 'position' of null
    at Object.Body.setPosition (Body.js?667f:441)
    at MatterImage.setPosition (Transform.js?1165:208)
    at new MatterImage (MatterImage.js?8b64:123)
    at Factory.image (Factory.js?6eda:545)
    at Scene.create (index.js?b635:82)
    at SceneManager.create (SceneManager.js?cec0:612)
    at SceneManager.loadComplete (SceneManager.js?cec0:524)
    at LoaderPlugin.emit (index.js?ba10:183)
    at LoaderPlugin.loadComplete (LoaderPlugin.js?868d:917)
    at LoaderPlugin.fileProcessComplete (LoaderPlugin.js?868d:883)

Perhaps you could change this value in the export, or add a note to the README explaining how to modify the export file for Phaser 3 matter physics?

jaredyork commented 4 years ago

Hi Sara,

Sorry this issue has been left for over six months. I ran into a bit of a dead end then. Everything worked except I've had to try to figure out the JSON format PhysicsEditor uses (the program used to generate this JSON: http://labs.phaser.io/assets/physics/fruit-shapes.json). That's why the project has been inactive for all this time since I've been unable to find an answer. I will continue to look for answers regarding the format.