Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bodies.fromVertices requires poly-decomp.js for convex shapes #900

Closed
onsah opened this issue Jul 23, 2020 · 4 comments
Closed

Bodies.fromVertices requires poly-decomp.js for convex shapes #900

onsah opened this issue Jul 23, 2020 · 4 comments

Comments

@onsah
Copy link

onsah commented Jul 23, 2020

In the documentations it says that poly-decomp is only needed when the vertices are not convex. But when I try to create a shape with convex vertices it fails with this error:

Uncaught Error: Cannot find module 'poly-decomp'

The problem seems to be these lines:

matter-js/build/matter.js

Lines 6736 to 6738 in 61b1963

if (!decomp) {
decomp = Common._requireGlobal('decomp', 'poly-decomp');
}

The weird thing is that these lines are only present in the built file.

I found a workaround by looking into the source code of Bodies.fromVertices(I use Body.create({ vertices })) so it is not a problem for me at the moment but I was wondering if that was intended. I think it is not because after throwing error if poly-decomp is not loaded, the latter parts of the function still checks for availability of the module.

Snippet to reproduce the error:

let vertices = [
            { x: 100, y: 100 },
            { x: 150, y: 100 },
            { x: 100, y: 150 },
        ];

        console.log(Matter.Vertices.isConvex(vertices)); // prints true

        let body = Bodies.fromVertices(100, 100, vertices); // Gives the error
@liabru
Copy link
Owner

liabru commented Sep 12, 2020

I think there's a known problem with how this is being required, for now are you able to include the module even if you don't use it?

@julian-a-avar-c
Copy link

Why is this marked as duplicate? Is there another issue that goes into more detail?

@codylico
Copy link

Possibly #559?

@liabru
Copy link
Owner

liabru commented Dec 29, 2020

Sorry yes thanks I meant #559. I've just left a reply there with an update, so try using 0.15.0 and let me know how it goes if you can.

@liabru liabru closed this as completed Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants