xeolabs / xeogl

A WebGL-based 3D engine for technical visualization. Not actively maintained.
http://xeogl.org
Other
1.15k stars 264 forks source link

Convert to ES6 #272

Closed xeolabs closed 5 years ago

xeolabs commented 6 years ago

Also use rollup, which will build xeogl as an ES6 module in build/xeogl.module.js, and as a UMD module in build/xeogl.js.

Doing the conversion in this branch: https://github.com/xeolabs/xeogl/tree/es6

MichaelDeBoey commented 6 years ago

@xeolabs Are you planning on releasing this as an npm package too btw? The unofficial one (https://www.npmjs.com/package/@wikifactory/xeogl) is still at v0.7.2, so it would be nice to have an official package published 🙂

xeolabs commented 6 years ago

@MichaelDeBoey yip will do!

xeolabs commented 5 years ago

The xeogl ES6 branch is now largely working if anyone needs to preview it. Will merge into master when I've updated the docs. Feedback is super welcome, please comment in this issue if you have any questions or feedback.

Change docs (WIP): https://github.com/xeolabs/xeogl/wiki/Updates-in-xeogl-v0.9 Repo branch: https://github.com/xeolabs/xeogl/tree/es6

Rollup is building two versions of xeogl: a UMD module and an EC6 module, in the build dir: https://github.com/xeolabs/xeogl/tree/es6/build

The UMD version should work just like v0.8, ie. with a global xeogl namespace.

xeolabs commented 5 years ago

BTW, the main breaking API change with this ES6 upgrade is that the default Scene is no longer settable/gettable via a property on the xeogl namespace - now that's supported with a pair of setter and getter methods.

In v0.8 (EC5), it was:

// Get default scene, internally creating first if needed
var theDefaultScene = xeogl.scene; 

// Set the default scene
xeogl.scene = new xeogl.Scene({... });

// Subsequently created components will be within xeogl.scene
// if no scene is explicitly provided for them.

Reason

In the EC6 conversion, xeogl.js is the rollup "input" file, which effectively assembles the xeogl namespace via a bunch of exports.

Unfortunately, you can't export an object property, the way xeogl.scene was defined in v0.8.

Therefore, I was forced to replace that with setDefaultScene() and getDefaultScene() methods, which can be exported.

Accordingly, I needed to update a few examples that referenced that default Scene.

Maybe there's something I missed - some hacky thing I can do to keep that dynamic xeogl.property?

Not sure, if anyone has tips let me know!

xeolabs commented 5 years ago

I've just released v0.9, which converts xeogl to #ECMA6 - https://github.com/xeolabs/xeogl/wiki/Updates-in-xeogl-v0.9

Next step: publish the core library as an npm package, along with some of the non-core components like GLTFModel. Just got some reading to do on all of that first.