question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MeshBuilder.CreatePolygon and PolygonMeshBuilder API is inconsistent

See original GitHub issue

Hello, I’m migrating not from babylonjs@3.3.0 to @babylonjs/core@4.0.0-alpha.18 to try out the new and long waited tree shaking! (@sebavan 👑)

And getting the following error: ReferenceError: earcut is not defined at new PolygonMeshBuilder.

This is because MeshBuilder.CreatePolygon API doesn’t support earcut injection: Babylon.js/src/Meshes/meshBuilder.ts: screen shot 2019-01-14 at 16 22 21

screen shot 2019-01-14 at 16 24 14

Help will be very much appreciated, Tomer.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
treedboxcommented, Sep 16, 2020

With Webpack , install earcut via npm: npm i --save-dev earcut

Then in your .ts or .js file:

import earcut from "earcut";

const mesh = MeshBuilder.CreatePolygon(name, options, scene, earcut)

In the documentation you can see that after scene, the next optional parameter is earcutInjection, this is the way. https://doc.babylonjs.com/api/classes/babylon.meshbuilder#createpolygon

3reactions
kutomercommented, Aug 12, 2019
  const earcut = require('earcut');
  window.earcut = earcut;

Not a nice solution, but I can say that it works…

Using Electron & Webpack & Vue. I’ve put it into main.js Afaik, earcut will be injected globally (into window), which isn’t nice considering that the principle of SFC’s are broken this way.

… But it works

@Fusseldieb, This was a temporary solution I used until @deltakosh solution, you can inject earcut into CreatePolygon, so there is no real reason to manually referance the global scope:

const mesh = MeshBuilder.CreatePolygon("name", { // ... }, scene, require('earcut'));

I’m using @babylonjs/core@4.0.0 and it’s working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PolygonMeshBuilder vs MeshBuilder.createPolygon - Questions
My problem starts when I want to move it to my angular application. How should I use PolygonMeshBuilder to work like MeshBuilder.CreatePolygon?
Read more >
Parametric Shapes - BabylonJS Guide
You must set at least the shape property. Example : var polygon = BABYLON.MeshBuilder.CreatePolygon("polygon", {shape: myShape, sideOrientation: BABYLON ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found