nape-js API
    Preparing search index...

    Class Polygon

    A convex polygon physics shape.

    Hierarchy (View Summary)

    Index

    Constructors

    • Create a Polygon from a list of Vec2 vertices. Vertices must form a convex polygon in counter-clockwise order.

      Parameters

      • OptionallocalVerts: any

        Vertices as Array<Vec2>, Vec2List, or GeomPoly.

      • Optionalmaterial: Material

        Material to assign (uses default if omitted).

      • Optionalfilter: InteractionFilter

        InteractionFilter to assign (uses default if omitted).

      Returns Polygon

    Accessors

    • get angDrag(): number

      Angular drag coefficient for this shape.

      Returns number

    • get area(): number

      Cross-sectional area of this shape.

      Returns number

    • get castBody(): any

      Cast to Body — returns the Body wrapper if this is a Body, else null.

      Returns any

    • get castCapsule(): Shape | null

      Cast to Capsule, or null if this is not a capsule.

      Returns Shape | null

    • get castCircle(): Shape | null

      Cast to Circle, or null if this is not a circle.

      Returns Shape | null

    • get castCompound(): any

      Cast to Compound — returns the Compound wrapper if this is a Compound, else null.

      Returns any

    • get castPolygon(): Shape | null

      Cast to Polygon, or null if this is not a polygon.

      Returns Shape | null

    • get castShape(): any

      Cast to Shape — returns the Shape wrapper if this is a Shape, else null.

      Returns any

    • get fluidEnabled(): boolean

      If true, this shape participates in fluid interaction.

      Returns boolean

    • set fluidEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get id(): number

      Unique numeric identifier for this interactor.

      Returns number

    • get inertia(): number

      Contribution to moment of inertia (about local centroid, unit density).

      Returns number

    • get localVerts(): any

      The list of local-space vertices defining this polygon's shape.

      Returns any

    • get sensorEnabled(): boolean

      If true, this shape acts as a sensor (no physical response, only callbacks).

      Returns boolean

    • set sensorEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get userData(): Record<string, unknown>

      User-defined data storage object.

      Returns Record<string, unknown>

    • get worldCOM(): Vec2

      World-space centre of mass of this shape (read-only, lazy-computed).

      Returns Vec2

    • get worldVerts(): any

      World-space vertices of this polygon, updated each simulation step.

      Returns any

    Methods

    • Return true if the given world-space point lies inside this shape. Requires the shape to be attached to a Body.

      Parameters

      • point: Vec2

        The world-space point to test.

      Returns boolean

      True if the point is inside this shape.

    • Create a deep copy of this shape with the same type, geometry, material, and filter.

      Returns Shape

      A new Shape instance independent of this one.

    • Rotate the shape's local vertices by angle radians.

      Parameters

      • angle: number

        Rotation in radians.

      Returns Shape

      this for chaining.

    • Scale the shape's local geometry. Circles require uniform scaling.

      Parameters

      • scaleX: number

        Horizontal scale factor (must be non-zero).

      • scaleY: number

        Vertical scale factor (must be non-zero).

      Returns Shape

      this for chaining.

    • Apply a Mat23 affine transform to the shape's local geometry.

      Parameters

      • matrix: { _inner: any }

        The transformation matrix (must be non-singular; Circles require equiorthogonal).

      Returns Shape

      this for chaining.

    • Validate the polygon geometry and return a string describing any issues, or "valid" if the polygon is well-formed.

      Returns any

      A validation result string from the underlying ZPP_Polygon.

    • Create an axis-aligned rectangular polygon centred at the origin.

      Parameters

      • width: number

        Rectangle width.

      • height: number = width

        Rectangle height (defaults to width for a square).

      • weak: boolean = false

        If true, returned Vec2s are marked weak and will be auto-disposed.

      Returns Vec2[]

      Array of four Vec2 corner vertices.

    • Create an axis-aligned rectangle at the given position.

      Parameters

      • x: number

        Left edge x coordinate.

      • y: number

        Top edge y coordinate.

      • width: number

        Rectangle width.

      • height: number

        Rectangle height.

      • weak: boolean = false

        If true, returned Vec2s are marked weak and will be auto-disposed.

      Returns Vec2[]

      Array of four Vec2 corner vertices.

    • Create a regular polygon (or ellipse approximation) centred at the origin.

      Parameters

      • xRadius: number

        Horizontal radius of the circumscribed ellipse.

      • yRadius: number

        Vertical radius of the circumscribed ellipse.

      • edgeCount: number

        Number of sides (must be >= 3).

      • angleOffset: number = 0.0

        Rotation offset in radians applied to all vertices (default 0).

      • weak: boolean = false

        If true, returned Vec2s are marked weak and will be auto-disposed.

      Returns Vec2[]

      Array of edgeCount Vec2 vertices.