Documentation
    Preparing search index...

    Class DebugDrawBuffer

    A growable world-space line list with a colour per vertex — the transport every provider in this module writes into, and the only drawing primitive §113's visualizations need (a point is drawn as a cross of lines; see DebugDrawBuffer.addPoint).

    const buffer = new DebugDrawBuffer();
    buffer.clear(); // once per frame
    collectContactPoints(events, buffer);
    buffer.writePositions(geometry.positions); // feed a "lines" geometry

    See the module header for the float layout, the growth policy, and why non-finite coordinates are stored rather than rejected.

    Index
    • get capacity(): number

      Segments the current backing store holds. Doubles on overflow and never shrinks — including across DebugDrawBuffer.clear — so a steady-state overlay stops allocating.

      Returns number

    • get data(): Float32Array

      The whole capacity-sized backing store, by reference — the zero-alloc read path, to be used together with DebugDrawBuffer.floatLength. The reference changes when the buffer grows, so re-read it rather than caching it across frames.

      Returns Float32Array

    • get floatLength(): number

      Live floats: lineCount * DEBUG_SEGMENT_FLOATS. Everything in DebugDrawBuffer.data beyond this is stale and must not be read.

      Returns number

    • get lineCount(): number

      Segments written since the last DebugDrawBuffer.clear.

      Returns number

    • Appends an axis-aligned cross centred on center, arm half-length size: three segments, appended in X, Y, Z order — (±size, 0, 0), (0, ±size, 0), (0, 0, ±size).

      In a 2D scene (§7a: Y-up, everything at z = 0) the Z arm is a single pixel seen down the camera axis. It is drawn anyway rather than branching on a dimension this package cannot see; it costs one segment and it is what makes the same cross usable in 3D.

      Parameters

      Returns void

      RangeError if size is not finite and positive.

    • Appends one segment from from to to.

      Coordinates are stored verbatim, including non-finite ones — see the module header.

      Parameters

      Returns void

    • Appends one segment from raw components — the form the providers use, since it lets them offset an endpoint without a scratch vector.

      Parameters

      • x0: number
      • y0: number
      • z0: number
      • x1: number
      • y1: number
      • z1: number
      • red: number
      • green: number
      • blue: number
      • alpha: number

      Returns void

    • Draws a point as a cross — an alias of DebugDrawBuffer.addCross, spelled the way a caller thinks of it.

      A line list has no point primitive (GL.POINTS is not in GeometryDrawMode, which is "triangles" | "lines"), so every point in §113's list — a contact, a body origin — is three segments of 2 * size length. size is a world-space half-extent, not a pixel radius: this package cannot see a camera, so a screen-constant size is not expressible here and is the caller's to choose per scale.

      Parameters

      Returns void

    • Appends origin → origin + vector * scale as one segment — the shape §113's "velocity and force vectors" take.

      No arrowhead. A head is three more segments and a screen-space size to pick, and the direction is already readable from the segment's endpoints; the tip is the second vertex. Heads can be added later without a layout change.

      Parameters

      Returns void

      RangeError if scale is not finite.

    • Drops every segment. Keeps the backing store (see DebugDrawBuffer.capacity) and does not zero it: stale floats past DebugDrawBuffer.floatLength are unreachable through every accessor here.

      Returns void

    • A view of exactly the live floats.

      Convenience for tests and one-shot inspection: subarray copies no data but does allocate a view object, so a per-frame path should use DebugDrawBuffer.data with DebugDrawBuffer.floatLength instead.

      Returns Float32Array

    • Copies the live segments' colours into out — 8 floats per segment (straight RGBA per vertex, two vertices), the layout BufferGeometry.colors wants alongside the positions DebugDrawBuffer.writePositions produces.

      This is the other half of the split: the buffer interleaves position and colour per vertex (module header), a GL vertex attribute wants each stream contiguous, and these two methods are the de-interleave. No expansion happens — the colour is already stored per vertex, so a future gradient segment (two different endpoint colours) comes out correct without a change here.

      Allocates nothing. Returns the number of floats written, which is DebugDrawBuffer.colorFloatLength. Floats in out past that are left untouched, exactly as DebugDrawBuffer.writePositions leaves them.

      Parameters

      • out: Float32Array
      • Optionaloffset: number

      Returns number

      RangeError if out cannot hold the segments at offset.

    • Copies the live segments into out as positions only — 6 floats per segment, the layout BufferGeometry's positions wants with mode: "lines".

      Allocates nothing. Returns the number of floats written, which is DebugDrawBuffer.positionFloatLength. Floats in out past that are left untouched — a geometry sized for the worst case keeps its stale tail, so either size out exactly per frame or accept that the extra segments still draw. (Collapsing the tail to a degenerate point is a caller policy, not a buffer one.)

      Parameters

      • out: Float32Array
      • Optionaloffset: number

      Returns number

      RangeError if out cannot hold the segments at offset.

    • DebugDrawBuffer.writePositions restricted to the segments whose first vertex carries exactly color — how one mixed buffer feeds several single-colour UnlitMaterial draws while the render path has no vertex-colour attribute (module header).

      The comparison is exact float equality on all four components, which is the right test precisely because colours here are constants copied out of a literal or DEBUG_DRAW_DEFAULT_COLORS — nothing computes a colour, so nothing needs a tolerance.

      Allocates nothing. Returns the number of floats written.

      Parameters

      • out: Float32Array
      • color: DebugColor
      • Optionaloffset: number

      Returns number

      RangeError if out is too small for the matching segments.