-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Concave polygons #15
Comments
Currently only convex polygons are supported, although I may implement convex decomposition in the future. |
+1 |
Is there an easy way to "glue" multiple convex shapes together? |
@ponychicken you could try using really small and stiff constraints between edges (e.g. the wheels on the cars demo) but it may not be good enough in practice. I'm considering implementing pin constraints when I get time, which would allow this. |
Ok, thanks. |
I implemented a convex decomposition algorithm in geom.js, maybe you can reuse (parts of) it. It is a little more complex than a simple ear-clipping algorithm, but produces less convex parts and less vertices on the edge of the polygon. It's used in svg2physics to allow you to turn SVG images into Box2D physics scenes. |
Concave and compound bodies are now supported in the compound-concave branch. You can also try them out in this demo. Hopefully these should be merged into master soon! |
@liabru |
Yea from my testing it's now stable enough in most use cases, so it should be in landing in master within the next week (unless I find new issues but I think I've solved most). The API for this is also now unlikely to change very much, so I'd say it's ready to start using. It's obviously not mature and battle tested yet, but this obviously will take time and I'll be fixing issues as they come in. |
This feature has been merged into master. |
Can I create holes that way? So I could place a ball inside a ball? |
@donaldpipowitch holes are possible if you have a good enough convex decomposition algorithm, or you just define all the convex parts by hand. Check out the SVG demo and the source code. Also see the compound demo. Note that if you use |
Thank you. |
Just to be sure: This isn't tagged in And I get this warning I require |
Correct, only master right now.
That's the right package, but it probably won't work if you're using node rather than browser. Currently it just expects Do you need support for this? I've added an issue you can track. |
@liabru I had no luck using poly-decomp with an SVG containing a hole. (It seems to treat the hole as a solid shape and ignores the outer shape.) I tried other libraries (https://github.com/mattdesl/svg-mesh-3d which returns a "simplicial complex"), but had no luck either. Could you create an example with an SVG containing a hole, if this is possible with poly-decomp? If not, I think there are other libraries which could help with triangulation like https://github.com/mapbox/earcut, which are maybe better as poly-decomp? Purpose: I want to have a body with a hole which contains other bodies. The body is parsed from the path of an SVG. |
Strange, I've usually had success with holes using poly-decomp (but it's not a guarantee). As for an example, just look at the SVG demo (ok those arn't exactly holes, but trust me I do have projects that have them). It probably depends on how the hole is constructed. You often need to experiment with your SVG a bit until it works. Have you tried playing with the Be aware though that the SVG to absolute conversion is limited and may have some bugs, so even with a good decomposer you may still get bad results with certain SVGs. You should certainly try https://github.com/mapbox/earcut as I expect it's more robust, but the downside is that it creates triangle parts rather than convex parts which is more optimal, but performance should still be reasonable. I wonder if there's some easy heuristic for joining triangles... If you do try it, tell me how you get on, I'd be interested in adding support for earcut. There's also libtess which may even be better. |
@liabru Thank you for your fast response. Playing with
|
I've experimented with both Either way, |
@liabru I'm curious if you would be willing to consider the PathToPoints project as an alternative to poly-demp? |
Is there an example with |
You can try this SO answer but whether it works for you may depend on the nature of your SVG, so you might want to post it. That said, I'm mostly replying for the sake of future visitors since your post was 3 years ago and you've probably moved on by now. |
For those who want to make @mapbox/earcut to work with matter.js: you will have to apply this Pull Request, because the position of a convex VertexSet is messed up. Would be great to use whatever algorithm you want though… |
Is there any way to make concave polygons with matter.js?
The text was updated successfully, but these errors were encountered: