Matter-js: Bodies.fromVertices requires poly-decomp.js for convex shapes

Created on 23 Jul 2020  路  4Comments  路  Source: liabru/matter-js

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:
https://github.com/liabru/matter-js/blob/61b19632491d447be5f46e027f4ae56c47f92c90/build/matter.js#L6736-L6738

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
bug duplicate

Most helpful comment

Possibly liabru/matter-js#559?

All 4 comments

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?

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

Possibly liabru/matter-js#559?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maximilianberndt picture maximilianberndt  路  4Comments

BlueInt32 picture BlueInt32  路  4Comments

djipco picture djipco  路  4Comments

jack-guy picture jack-guy  路  3Comments

Zhaopengyang picture Zhaopengyang  路  3Comments