mwg API
    Preparing search index...

    Class PinnedDeform

    A pinned-point deformation grid: the renderer-free math behind roadmap item 414.

    The grid holds columns * rows control points over a width * height rest rectangle. Every point stays exactly at its rest position until the game drags it with PinnedDeform.drag (or PinnedDeform.nudge); there is no falloff onto neighbours, no smoothing pass and no whole-sprite rotation, so a Pontifex wingtip can move while the wing root stays bit-identical. UVs are not modelled here at all: this class only tracks positions, and the GPU side (DeformableSprite) leaves its UV buffer untouched.

    import { PinnedDeform } from '@datamoc/mwg/two-d/render';

    const wing = new PinnedDeform({ columns: 4, rows: 3, width: 96, height: 64 });
    wing.drag(wing.indexOf(3, 0), 99, -6); // the wingtip follows the bone
    console.log(wing.at(wing.indexOf(0, 1))); // { x: 0, y: 32 } - the pinned root never moves
    console.log(wing.movedCount()); // 1 - only the dragged tip left its rest position
    Index
    columns: number
    height: number
    rows: number
    width: number
    • Move one control point to an absolute local position. Only that point changes; every other point stays pinned at rest.

      Parameters

      • index: number
      • x: number
      • y: number

      Returns void

    • the flat index of the point at (column, row); throws a RangeError outside the grid

      Parameters

      • column: number
      • row: number

      Returns number

    • whether a point currently sits away from its rest position

      Parameters

      • index: number

      Returns boolean

    • Shift one control point by a delta; the rest stay pinned, as with drag.

      Parameters

      • index: number
      • dx: number
      • dy: number

      Returns void

    • Adopt externally built rest positions, clearing every offset. DeformableSprite uses this to adopt the GPU plane's own floats, so pinned vertices stay bit-identical to what the mesh already renders instead of nearly equal.

      Parameters

      • rest: Float32Array

      Returns void

    • Return one point to rest, or every point when called without an index.

      Parameters

      • Optionalindex: number

      Returns void

    • Write every current position into into, which must hold exactly count * 2 floats. The mesh side calls this with its GPU position array.

      Parameters

      • into: Float32Array

      Returns void