Jump to content

[BUG] poly2tri reference in babylon imported from npm as modules


croustibat
 Share

Recommended Posts

Hi,

I recently encountered a small problem when I refactored my project relying on polygon mesh builder using ES6 modules and npm.

If I include babylon js and poly2tri with npm and import it using 
 

import poly2tri from 'poly2tri';
import BABYLON from 'babylonjs';

This way, the poly2tri package is available locally.

So, I get an error saying:

"PolygonMeshBuilder cannot be used because poly2tri is not referenced"

It probably comes from there (babylon.polygonMesh.ts):

if (!("poly2tri" in window)) {
    throw "PolygonMeshBuilder cannot be used because poly2tri is not referenced";
}

So, I'm forced to do the following before using PolygonMeshBuilder (which is not a very good way to go IMO):

window.poly2tri = poly2tri;

Shouldn't it be:

if (!("poly2tri" in window || polytri)) {
    throw "PolygonMeshBuilder cannot be used because poly2tri is not referenced";
}

EDIT: Sorry, I put this in the wrong place, and I can't delete it neither move it.

Edited by croustibat
Wrong place to post it!
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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