nape-js API
    Preparing search index...

    Function createConcaveBody

    • Create a Body from concave (non-convex) polygon vertices.

      Accepts arbitrary simple polygon vertices (concave or convex), performs validation, optional simplification, and convex decomposition via GeomPoly.convexDecomposition(). Each convex partition becomes a Polygon shape on the returned body.

      If the input is already convex, a single Polygon shape is created (no decomposition overhead).

      Parameters

      • vertices: GeomPoly | Vec2[]

        Polygon vertices as Vec2[] or GeomPoly. Must form a simple (non-self-intersecting) polygon with at least 3 vertices.

      • Optionaloptions: ConcaveBodyOptions

        Optional configuration (body type, material, filter, etc.)

      Returns Body

      A Body containing one or more convex Polygon shapes.

      If vertices are null/undefined, fewer than 3, degenerate (zero area), or self-intersecting.

      // L-shaped concave polygon
      const body = createConcaveBody([
      Vec2.get(0, 0), Vec2.get(100, 0), Vec2.get(100, 50),
      Vec2.get(50, 50), Vec2.get(50, 100), Vec2.get(0, 100),
      ]);
      body.space = space;