mwg API
    Preparing search index...

    Class ClothSprite

    A garment that follows with a slight lag: a Cloth simulation driving a textured mesh on the GPU path 414 ships (roadmap 423). The cloth spans the texture, the top edge starts pinned (a waistband, a held scarf end), and update(dt) steps the simulation and re-uploads the vertex buffer; UVs are never rewritten and the sprite itself is never rotated, so a skirt bends while its print stays printed. Pin more points to hang it, unpin to let it fall, and drive setWind from the weather or the run cycle.

    import { ClothSprite } from '@datamoc/mwg/two-d/render';
    import type { Texture2D } from '@datamoc/mwg/two-d/render';

    declare const tunicTexture: Texture2D;

    const tunic = new ClothSprite(tunicTexture, { segmentsX: 6, segmentsY: 8, gravity: { x: 0, y: 900 } });
    tunic.update(1 / 60); // the hem answers gravity, the waistband stays pinned
    console.log(tunic.movedCount()); // > 0 - everything below the pinned edge travelled

    Hierarchy

    • MeshPlane
      • ClothSprite
    Index
    • the flat index of the point at (column, row)

      Parameters

      • column: number
      • row: number

      Returns number

    • the current position of one mesh point

      Parameters

      • index: number

      Returns { x: number; y: number }

    • release a pinned point; it keeps its current position and moves from there

      Parameters

      • index: number

      Returns void

    • Step the cloth and re-upload the vertex buffer. Under reduced motion a decorative garment holds its shape instead of swaying.

      Parameters

      • dt: number

      Returns void