Skip to content

Conversation

@zhijie-os
Copy link

I was trying to create Body with the method Matter.Bodies.fromVertices.

I installed poly-decomp package to enable automatic concave vertices decomposition and supply the the method Matter.Bodies.fromVertices with vertices from drawing.

success

However, for certain sets of vertices, the method Matter.Bodies.fromVertices would return undefined at line 354 of ./src/factory/Bodies.js

            return parts[0];

no_parts_error

This is due to

  1. The quickDecomp() returns empty list of decomposition near line 278 of ./src/factory/Bodies.js
            // use the quick decomposition algorithm (Bayazit)
            var decomposed = decomp.quickDecomp(concave);
  1. The decomposition only contains small parts being skipped near line 293 of ./src/factory/Bodies.js
            // skip small chunks
            if (minimumArea > 0 && Vertices.area(chunkVertices) < minimumArea)
                  continue;

My change checks if the parts array is empty. If the array is empty, fallback to convex hull and ignore the decomposition.
The final result would look like the following.

no_parts_error_handled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant