matter-js: Concave polygons not working even after I installed poly-decomp (node server)

I’ve installed poly-decomp with npm install poly-decomp. I then put decomp = require('poly-decomp') above matter = require('matter-js'), when I run my code, it still says poly-decomp.js required. I dug in matter.js code and changed line 6541 to decomp = require('poly-decomp'). It doesn’t give the same message anymore, but my shape is still just convex.

I ran console.log(decomp) after line 6541, and it returned

{ decomp: [Function: polygonDecomp],
quickDecomp: [Function: polygonQuickDecomp],
isSimple: [Function: polygonIsSimple],
removeCollinearPoints: [Function: polygonRemoveCollinearPoints],
makeCCW: [Function: polygonMakeCCW] }

which I think is what it should return. I dug even farther and made sure that line 6763 was being run, and it is. Although, when I console.log(decomp.makeCCW(concave)); on line 6769, it returns undefined. What should I do to make it work? Right now it isn’t giving me the error message, but it isn’t making the shape concave.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 28 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the info guys, sorry that this is still an issue. While I look into it more, I think this temporary fix should work with the latest version. Make sure you put it somewhere early on, before you use Bodies.fromVertices:

window.decomp = require('poly-decomp');

all solutions above doesn’t work Webpack replaces window.decomp = require('poly-decomp'); by __webpack_provided_window_dot_decomp = __WEBPACK_IMPORTED_MODULE_0_poly_decomp___default.a;

so global window is remains untouched

Using global.decomp = require('poly-decomp') is working for me with Webpack

No solutions for me thus far…

This worked for me (using Parcel as the bundler):

import decomp from 'poly-decomp';
window.decomp = decomp;

I am having the same issue. Currently tried to use the import in my index.js file

import decomp from 'poly-decomp' window.decomp = decomp

that did not solve the issue.

Then tried to include it in the HTML

<script src="./src/decomp.js"></script> <script src="./src/index.js"></script>

Here are package versions.

“matter-js”: “^0.14.1”, “poly-decomp”: “^0.2.1”

"npm install poly-decomp --save " helped me in new create-react-app project with matter 0.16.

@liabru Gave it a shot, still seeing the issue though: Can't resolve 'poly-decomp'

Hey @jobtalle, If your using webpack I managed to get poly-decomp detected by including a couple lines to my webpack.config.js file.

At the top of your webpack file include…

const webpack = require('webpack')

… and in the plugins array insert

new webpack.ProvidePlugin({ 'window.decomp': 'poly-decomp' })

Hope this helps.

It looks like there is an issue with compiled JS renaming the decomp, causing Bodies.fromVertices() to complain. Adding decomp.js as a separate file within the html page (loaded before the compiled scripts) seems to solve the problem.