# BabylonNative - PolygonMeshBuilder not implemented correctly?

**URL:** <https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024>\
**Category:** Bugs\
**Tags:** native, babylon-native\
**Created:** [August 13, 2022, 9:24am UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024 "2022-08-13T09:24:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cr0c](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cr0c/32/25991_2.png) [@Cr0c](https://forum.babylonjs.com/u/Cr0c)\
**Post date:** [August 13, 2022, 9:24am UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/1 "2022-08-13T09:24:07Z")

</div>

BabylonNative

```auto
this.xrPlanes.onPlaneAddedObservable.add(plane => {
 console.log('abc: ', plane);
 plane.polygonDefinition.push(plane.polygonDefinition[0]);
 var polygon_triangulation = new BABYLON.PolygonMeshBuilder("name", plane.polygonDefinition.map((p) => new BABYLON.Vector2(p.x, p.z)), this.scene);

```

on last line error `Uncaught Error: earcut is not defined`

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [August 13, 2022, 9:39am UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/2 "2022-08-13T09:39:14Z")

</div>

Do you have earcut.js?

---

<div class="post-metadata">

**Author:** ![Cr0c](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cr0c/32/25991_2.png) [@Cr0c](https://forum.babylonjs.com/u/Cr0c)\
**Post date:** [August 13, 2022, 9:43am UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/3 "2022-08-13T09:43:02Z")

</div>

It’s BABYLON NATIVE, I haven’t any external js. All engine js needs compiled to player.

---

<div class="post-metadata">

**Author:** ![Cr0c](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cr0c/32/25991_2.png) [@Cr0c](https://forum.babylonjs.com/u/Cr0c)\
**Post date:** [August 13, 2022, 10:01am UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/4 "2022-08-13T10:01:13Z")

</div>

```auto
this.gl = new BABYLON.GlowLayer("glow", this.scene, {mainTextureSamples: 4});

```

results is black screen (no render) - not implemented correcttly?

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [August 13, 2022, 10:07am UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/5 "2022-08-13T10:07:28Z")

</div>

The PolygonMeshBuilder still needs the earcut plugin to work.  
I’m a bit underqualified to say more about babylon native

CC: @Cedric @bghgary who ever is around first 🙂

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [August 13, 2022, 12:04pm UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/6 "2022-08-13T12:04:41Z")

</div>

You can add it as an injection

> **[PolygonMeshBuilder | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/BABYLON.PolygonMeshBuilder#constructor)**
>
> Builds a polygon \[API\]

---

<div class="post-metadata">

**Author:** ![Cr0c](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cr0c/32/25991_2.png) [@Cr0c](https://forum.babylonjs.com/u/Cr0c)\
**Post date:** [August 13, 2022, 12:56pm UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/7 "2022-08-13T12:56:01Z")

</div>

BabylonNative can’t import modules, only embedded classes

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 15, 2022, 1:47pm UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/8 "2022-08-15T13:47:35Z")

</div>

Adding @srzerbetto @Cedric and @bghgary

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [August 15, 2022, 2:21pm UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/9 "2022-08-15T14:21:54Z")

</div>

@Cr0c , how are you using Babylon Native? Are you creating a project from the templates we have on the Github repo?

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [August 15, 2022, 2:48pm UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/10 "2022-08-15T14:48:48Z")

</div>

@Cr0c , you actually CAN load dependencies on Babylon Native. However, it need to be done on the C++ side where the js scripts get loaded. Usually in the samples we have a ScriptLoader that ir responsible for loading all js scripts required for the application to run (babylon.max.js, and others).

If you have earcut.min.js in your applications folder you can do the following using the ScriptLoader C++ object:

```auto
Babylon::ScriptLoader loader{*runtime};
        loader.Eval("document = {}", "");
        loader.LoadScript("app:///Scripts/ammo.js");
        //Add earcut before babylon.max.js
        loader.LoadScript("app:///Scripts/earcut.min.js");
        loader.LoadScript("app:///Scripts/babylon.max.js");
        loader.LoadScript("app:///Scripts/babylonjs.loaders.js");
        loader.LoadScript("app:///Scripts/babylonjs.materials.js");
        loader.LoadScript("app:///Scripts/babylon.gui.js");
        loader.LoadScript("app:///Scripts/meshwriter.min.js");

```

This will make earcut available to babylon.js.  
To get the earcut.min.js you can use npm to install it and add it to the list of scripts in CMake file like we do in our samples.

If you need extra instructions on how to do that let me know.

---

<div class="post-metadata">

**Author:** ![Cr0c](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cr0c/32/25991_2.png) [@Cr0c](https://forum.babylonjs.com/u/Cr0c)\
**Post date:** [August 17, 2022, 5:42pm UTC](https://forum.babylonjs.com/t/babylonnative-polygonmeshbuilder-not-implemented-correctly/33024/13 "2022-08-17T17:42:05Z")

</div>

I am inject all earcut to meshwriter directly as `var earcut = function(...) {...}` and comment all `export earcut...`
