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
- fixed require for external libraries, closes #629, closes #559, closes #593, closes #365, closes #629 — committed to Zagorakiss/matter-js by liabru 6 years ago
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:Using
global.decomp = require('poly-decomp')is working for me with WebpackNo solutions for me thus far…
This worked for me (using Parcel as the bundler):
I am having the same issue. Currently tried to use the import in my index.js file
import decomp from 'poly-decomp'window.decomp = decompthat 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, causingBodies.fromVertices()to complain. Adding decomp.js as a separate file within the html page (loaded before the compiled scripts) seems to solve the problem.