freshfork / p5.EasyCam

A p5.js library for easy 3D camera control.
https://freshfork.github.io/p5.EasyCam
MIT License
136 stars 33 forks source link

Updates, NPM, and Instance Mode #26

Open JackWH opened 1 year ago

JackWH commented 1 year ago

Hi! 👋 Is this library still maintained? I've been unable to import it (cleanly, anyway) into a Yarn/TypeScript project, as no package is published on npm.

Furthermore, when I tried to copy the source code in manually, I couldn't get it to work with p5's Instance Mode. The library seems to assume p5 is always available globally, which is rarely the case in modern JS projects.

Thanks!

jwdunn1 commented 1 year ago

Yes, this library in maintained. 1) Coincidentally, a new NPM package was published this morning. 2) The TypeScript issue #13 is still under review with a testable version merged into the repo (after the npm package was published). 3) Yes, p5.EasyCam works in instance mode: example 1 example 2

JackWH commented 1 year ago

Thanks @jwdunn1 for the speedy reply 👍 The instance mode issue is a little different, I've added some clarification below.

The npm package doesn't export any methods, so it can't be imported as a module. Instead the plugin has to be loaded into the global scope. In instance mode p5 won't always be available in the global scope, and the p5 class also might be imported under an alias.

These lines seem to be causing the problem. They assume a p5 variable is available at runtime. Even if the p5 runtime is loaded and available, hard-coding onto the p5.prototype prevents using this plugin in a class which has a p5 instance assigned to a property. More info here.

If you'd welcome a PR for this, I can have a go at it! 😊

jwdunn1 commented 1 year ago

Fascinating! Thanks for your insights. Yes, contributions are welcome!

JackWH commented 1 year ago

I got a prototype working last night, just need to make sure it stays backwards-compatible in the global context. Will get a PR up when I get some time to come back to this over the next few days. Thanks!

jwdunn1 commented 1 year ago

@JackWH Were you able to import the modified version (from the PR) successfully into your Yarn/TypeScript project?