Jump to content

Latest Preview: Earcut required in Canvas2D, but never exported


Recommended Posts

Hi I have spoken to @Nockawa already and he suggested I turn to the forums which I agreed with. When using a bundler such as Webpack, the developer imports the the BabylonJS library rather than including it in a script tag. The problem that arises is that Earcut has been defined in it's own namespace and is available only in the babylon.js file or globally when using script tags. However in Webpack each imported module is treated as an isolated scope and doesn't have access to other modules or global variables unless they have specifically been required/provided. Because Earcut is never exported and in it's own namespace it is literally unreachable for module bundlers:

> babylon.js defines Earcut module
> babylon.js defines and exports BABYLON module

> Webpack provides the BABYLON module from babylon.js to all other libraries

> babylon.canvas2d.js extends and exports BABYLON module
x babylon.canvas2d.js uses BABYLON and Earcut (but Earcut is not provided nor in the same namespace)

This leave 2 solutions as I see it:

  1. Add Earcut to the BABYLON namespace so that they get exported together and can both be provided by bundlers.
  2. Keep Earcut in it's own namespace and export it so that it can be imported by both babylon.js and babylon.canvas2d.js or provided using a bundler.

Ping @Deltakosh, moving forward it might be worth looking into npm more. They offer the for example the option to add @next version tag for alphas/betas of packages. I am sure Babylon.JS would benefit from having more users testing/working with the preview build and finding issues.

Kind Regards


Link to comment
Share on other sites

My 2 cents - Earcut should not be a part of the babylon namespace, as it is not a part of babylon. There is also the OS license that we should consider, and, in general, the fact that the developer of the module might need to approve such a move.

That would be like adding jQuery to the angular namespace, because angular can use jquery. Sounds rather wrong :)

I like the 2nd option, which is exporting Earcut as an external dependency.

If you want to provide a very simple project that I can download and experiment with offline, it would be wonderful!


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...