When I'm trying to use ExtrudePolygon(), I get a ReferenceError: earcut is undefined

Hi,

That’s in the title, when I call ExtrudePolygon(), I get a ReferenceError: earcut is undefined.
Both on Babylon 6 and 7.
The last build (7.25.1) was downloaded today from the cdn https://cdn.babylonjs.com/babylon.js.

It appears that the bug does not exist on Playground.

The source code for the function is:

function ExtrudePolygon(name, options, scene, earcutInjection) {
    if (scene === void 0) { scene = null; }
    if (earcutInjection === void 0) { earcutInjection = earcut; }
    return CreatePolygon(name, options, scene, earcutInjection);
}

So no earcut defined.

I suppose it is a global, or maybe an external package?

EDIT: Ok, so it seems that it depends on this package, but I found that it is a bit strange that it is not included in the BabylonJS bundle, particularly without any mention of it in the doc and the API reference.

Hello :slight_smile:

FYI the CDN server also serves a version of earcut : https://cdn.babylonjs.com/earcut.min.js

I think the above CDN link is used by the Playground itself.

The doc says :

earcutInjection: any
can be used to inject your own earcut reference

I think it’s because earcut is subject to be used even regardless of BabylonJS. So in a project where earcut is already used, and on top of it you would use BabylonJS, then you can pass your earcut reference instead of having a new (conflicting) version embedded in BabylonJS bundle

++ :slight_smile:
Tricotou

2 Likes