Engine API Reference - v2.22.0-beta.29
    Preparing search index...

    Class WireRenderer

    Renders wireframe shapes for a single frame, for debugging and visualization. Shapes are submitted as line segments to the layer given by WireRenderer#layer, which defaults to the LAYERID_IMMEDIATE layer, and are discarded once the frame has been rendered, so they must be issued again on every frame they should be visible.

    The renderer holds the state used by the shapes it draws - WireRenderer#color, WireRenderer#layer, WireRenderer#depthTest, WireRenderer#segments and WireRenderer#transform. Fields can be assigned between calls, and drawing many shapes with the same state allocates nothing:

    const wire = new WireRenderer(app);
    wire.color = Color.RED;

    app.on('update', () => {
    for (const item of items) {
    wire.sphere(item.position, item.radius);
    }
    });

    A second set of state is simply a second instance. Instances hold no GPU resources, and those sharing a layer and depth test mode submit into the same batch, so using several has no additional rendering cost:

    const xray = new WireRenderer(app);
    xray.depthTest = false;

    These are thin lines, one pixel wide. For thick lines with caps, joins and dashes, intended as part of the rendered scene rather than as a debugging aid, see WideLineRenderer instead.

    Index
    • Creates a new WireRenderer instance.

      Parameters

      Returns WireRenderer

      const wire = new WireRenderer(app);
      
    color: Color = ...

    The color used by shapes, specified in sRGB color space. The alpha component is respected. Defaults to white.

    depthTest: boolean = true

    Whether shapes are depth tested against the depth buffer. Defaults to true.

    layer: Layer | null = null

    The layer shapes are rendered into, or null to use the LAYERID_IMMEDIATE layer. Defaults to null.

    segments: number = 20

    The number of line segments used to approximate a full circle. Defaults to 20.

    transform: Mat4 | null = null

    A matrix applied to every point of every shape, or null for no transform. Assign this to draw a group of shapes in the local space of a node. Defaults to null.

    • Renders an arrow, as a shaft with four barbs at its tip.

      Parameters

      • from: Vec3

        The tail of the arrow.

      • to: Vec3

        The tip of the arrow.

      Returns void

      wire.arrow(position, position.clone().add(velocity));
      
    • Renders the three axes of a matrix, colored red, green and blue for x, y and z respectively. This function ignores WireRenderer#color.

      Parameters

      • matrix: Mat4

        The transform whose axes are rendered.

      • size: number

        The length of each axis.

      Returns void

      wire.axes(entity.getWorldTransform(), 1);
      
    • Renders the edges of a box specified by its min and max corners.

      Parameters

      • min: Vec3

        The min corner of the box.

      • max: Vec3

        The max corner of the box.

      Returns void

      wire.boxMinMax(new Vec3(-1, -1, -1), new Vec3(1, 1, 1));
      
    • Renders a capsule as a ring and hemispherical cap at each end, joined by four side lines.

      Parameters

      • start: Vec3

        The center of the start cap sphere.

      • end: Vec3

        The center of the end cap sphere.

      • radius: number

        The radius of the capsule.

      Returns void

      wire.capsule(feet, head, 0.4);
      
    • Renders a circle lying in the plane described by a normal.

      Parameters

      • center: Vec3

        The center of the circle.

      • normal: Vec3

        The normal of the plane containing the circle. Need not be normalized.

      • radius: number

        The radius of the circle.

      Returns void

      wire.circle(Vec3.ZERO, Vec3.UP, 5);
      
    • Renders a cone as a base ring joined to its apex by four side lines. The parameters match those describing a spot light, so a light's cone can be visualized directly.

      Parameters

      • apex: Vec3

        The tip of the cone.

      • direction: Vec3

        The direction the cone opens along. Need not be normalized.

      • angle: number

        The half-angle of the cone, in degrees, measured from direction to the cone edge.

      • length: number

        The distance from the apex to the base.

      Returns void

      wire.cone(position, direction, 30, 10);
      
    • Renders a cylinder as a ring at each end joined by four side lines.

      Parameters

      • start: Vec3

        The center of the start cap.

      • end: Vec3

        The center of the end cap.

      • radius: number

        The radius of the cylinder.

      Returns void

      wire.cylinder(base, tip, 0.5);
      
    • Renders the edges of a view frustum. The camera does not need to be enabled or rendering, so the view volume of an inactive camera can be visualized.

      Parameters

      Returns void

      wire.frustum(otherCamera.camera);
      
    • Renders the shape and extent of a light, using the light's own color. An omni light is drawn as a sphere of its range, a spot light as its cone, and a directional light as an arrow showing the direction it shines in. A light shines along the negative y-axis of its entity, so the shape follows that axis rather than the entity's forward direction.

      Parameters

      • light: LightComponent

        The light to render.

      • Optionalsize: number = 1

        The length of the arrow used for a directional light, which has no inherent extent. Defaults to 1.

      Returns void

      wire.light(entity.light);
      
    • Renders a single line segment.

      Parameters

      • start: Vec3

        The start of the line, in world space.

      • end: Vec3

        The end of the line, in world space.

      Returns void

      wire.line(new Vec3(0, 0, 0), new Vec3(0, 1, 0));
      
    • Renders discrete line segments, formed by consecutive pairs of points.

      Parameters

      • positions: Vec3[]

        The points to draw lines between. The length must be a multiple of two.

      • Optionalcolors: Color[]

        One color per point, or undefined to use WireRenderer#color. The color of each segment is interpolated between its ends.

      Returns void

      wire.lines([start, end], [Color.RED, Color.WHITE]);
      
    • Renders discrete line segments from packed arrays of numbers. This is the fastest of the line functions, as it avoids reading individual Vec3 and Color instances.

      Parameters

      • positions: number[] | Float32Array<ArrayBufferLike>

        Packed xyz coordinates, forming pairs of points.

      • Optionalcolors: number[] | Float32Array<ArrayBufferLike>

        Packed rgba values, one color per point, or undefined to use WireRenderer#color.

      Returns void

      wire.linesPacked([0, 0, 0, 0, 1, 0]);
      
    • Renders a closed strip of connected line segments, joining the last point back to the first.

      Parameters

      • positions: Vec3[]

        The points of the loop, in order.

      • Optionalcolors: Color[]

        One color per point, or undefined to use WireRenderer#color.

      Returns void

      wire.loop(outline);
      
    • Renders a square section of a plane, with a short stub along its normal.

      The rotation of the square within its plane is derived from the normal, and no such derivation is continuous over all directions. An animated normal will therefore make the square appear to jump as it passes the direction where the derivation switches. To rotate a square smoothly, pass a fixed normal and drive WireRenderer#transform instead.

      Parameters

      • center: Vec3

        The center of the square.

      • normal: Vec3

        The normal of the plane. Need not be normalized.

      • size: number

        The side length of the square.

      Returns void

      wire.plane(Vec3.ZERO, Vec3.UP, 10);
      
    • Renders a small axis-aligned cross marking a position.

      Parameters

      • position: Vec3

        The position to mark.

      • size: number

        The overall length of each arm of the cross.

      Returns void

      wire.point(hit.point, 0.2);
      
    • Renders an open strip of connected line segments.

      Parameters

      • positions: Vec3[]

        The points of the strip, in order.

      • Optionalcolors: Color[]

        One color per point, or undefined to use WireRenderer#color.

      Returns void

      wire.polyline(trajectory);
      
    • Renders a sphere as three great circles, one in each of the primary planes.

      Parameters

      • center: Vec3

        The center of the sphere.

      • radius: number

        The radius of the sphere.

      Returns void

      wire.sphere(new Vec3(0, 1, 0), 0.5);