nape-js API
    Preparing search index...

    Function fractureBody

    • Fracture a body into multiple pieces using Voronoi decomposition.

      Takes the first polygon shape on the body, generates Voronoi cells within it, clips each cell to the original polygon, and creates a new dynamic body for each fragment. Fragments inherit the original body's linear and angular velocity, plus an optional radial explosion impulse.

      Parameters

      • body: Body

        The body to fracture. Must have at least one polygon shape.

      • impactPoint: Vec2

        World-space point where the fracture originates. Used as the center bias for site generation and explosion impulse direction.

      • Optionaloptions: FractureOptions

        Fracture configuration.

      Returns FractureResult

      A FractureResult with the array of fragment bodies.

      If the body has no polygon shapes.

      const result = fractureBody(box, Vec2.get(100, 50), {
      fragmentCount: 12,
      explosionImpulse: 200,
      });
      // result.fragments are already in the space