Debug
Back to the reference

Debug

Lines, grids and axes drawn over the scene, to see what the game is doing.

10 symbols

setLinesfunctionnacatamalon

setLines(lines: TLines, next: Float32Array<ArrayBufferLike> | typeOperator) => void

Replaces what a set of lines draws, from the next frame on.

Two forms, for two sizes of job:

  • A few lines, as a list: { from, to, color } each, the colour as text ('#ffcc00'). An outline, a path, an arrow.
  • Thousands, rewritten every frame, as a Float32Array: seven numbers a corner, x, y, z, r, g, b, a, the colour from 0 to 1, and two corners a line. A cloth, a field of stars, rain. Fill the same array every frame: it is copied, so it can be reused straight away.

Either form can be shorter or longer than the last.

Parameters

linesTLines

The lines useLines gave.

nextFloat32Array<ArrayBufferLike> | typeOperator

What they draw now.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', fov: 60, transform: { z: 6 } });
    const box = useLines();
    const at = new Float32Array(7 * 2 * 4);

    useUpdate((_delta, time) => {
        // A square turning on the floor, written as numbers: four lines, two corners each.
        for (let i = 0; i < 4; i++) {
            for (const [end, turn] of [[0, i], [1, i + 1]]) {
                const angle = time + (turn * Math.PI) / 2;
                at.set([Math.cos(angle), 0, Math.sin(angle), 0.3, 1, 0.6, 1], (i * 2 + end) * 7);
            }
        }
        setLines(box, at);
    });

    return createScene();
};
View source · hooks/helpers/use_lines.ts:107

useHelperAxisfunctionhooknacatamalon

useHelperAxis(options: TUseHelperAxisOptions) => TLines

Draws the three axes as coloured lines from where it is placed: X red, Y green, Z blue, the colours every 3D tool uses.

Made inside something, it shows which way that thing is turned, because the lines are measured from it and turn with it. Made in the scene, it marks the world's origin.

Parameters

optionsTUseHelperAxisOptions

How long the arms are, their colours, and where the gizmo goes.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 1, z: 4, rotationX: -0.2 } });
    useHelperAxis({ size: 2, negative: true });
    return createScene();
};
View source · hooks/helpers/use_helper_axis.ts:84

useHelperGridfunctionhooknacatamalon

useHelperGrid(options: TUseHelperGridOptions) => TLines

Draws a floor grid on the ground plane, the one every 3D editor shows, with its middle lines in the colours of the X and Z axes.

It is drawn in the scene like anything else, so a model standing on it hides the lines behind it instead of the grid being painted over everything. Raise it, turn it or stand it up with transform.

Parameters

optionsTUseHelperGridOptions

How big it is, how close its lines are, and their colours.

Example

const Level = () => {
    useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 4, z: 8, rotationX: -0.45 } });
    useHelperGrid({ half: 5 });
    return createScene();
};
View source · hooks/helpers/use_helper_grid.ts:65

useLinesfunctionhooknacatamalon

useLines(options: TUseLinesOptions) => TLines

Draws any lines you like. setLines changes them at any time.

The one to reach for when what has to be seen changes: an outline that follows what the player picked, the path an enemy is about to take, the shape of a collider being tuned. The axis gizmo and the floor grid are this with the corners worked out for you.

What it gives back is the lines as a scene keeps them, like a sprite: visible, transform and zIndex are changed on it directly. Their corners are measured from transform, so lines made inside a moving thing move with it.

Lines are drawn in the scene's 3D view: models in front hide them, and they hide what is behind them. They are one pixel wide.

Parameters

optionsTUseLinesOptions

The first lines, and where they are drawn from.

Example

declare const target: { x: number; y: number; z: number };

const Level = () => {
    useCamera3d({ projection: 'perspective', fov: 60, transform: { z: 6 } });
    const path = useLines();

    useUpdate(() => {
        // One yellow line from the origin to wherever the enemy is heading.
        setLines(path, [{ from: { x: 0, y: 0, z: 0 }, to: target, color: '#ffcc00' }]);
    });

    return createScene();
};
View source · hooks/helpers/use_lines.ts:57

TLinetypenacatamalon

One line, said as where it starts and ends and its colour: what setLines takes when there are a few, and a Float32Array when there are thousands.

Properties

from{ x, y, z }

Where it starts, measured from where the lines are placed.

to{ x, y, z }

Where it ends.

coloroptionalTColorOption

Its colour, as text ('#ffcc00') or a colour. White if left out.

View source · gameobjects/lines/lines_state.ts:14

TLinesOptionstypenacatamalon

What every way of making lines shares: where they go, and whether they are drawn.

Properties

nameoptionalstring

What to call it when you look at it. The engine never looks it up: to find it, name its box.

transformoptionalPartial<TTransform3d>

Where the lines are drawn from. Left out, the place of whatever they are made in.

zIndexoptionalnumber

Draw order within the scene, as for any other drawing.

visibleoptionalboolean

Whether they start drawn. Default true.

View source · gameobjects/lines/new_lines.ts:21

TUseHelperAxisOptionstypenacatamalon

TUseHelperAxisOptions: TLinesOptions & { size, negative, colors }

What useHelperAxis is asked for.

Properties

sizeoptionalnumber

How long each arm is, in world units. Default 1.

negativeoptionalboolean

Also draw the other half of each axis, dimmed, so all six directions show. Default false.

colorsoptionalTHelperAxisColors

The colour of any arm. Left out, the usual ones: X red, Y green, Z blue.

nameoptionalstring

What to call it when you look at it. The engine never looks it up: to find it, name its box.

transformoptionalPartial<TTransform3d>

Where the lines are drawn from. Left out, the place of whatever they are made in.

zIndexoptionalnumber

Draw order within the scene, as for any other drawing.

visibleoptionalboolean

Whether they start drawn. Default true.

View source · hooks/helpers/use_helper_axis.ts:27

TUseHelperGridOptionstypenacatamalon

TUseHelperGridOptions: TLinesOptions & { half, step, color, xColor, zColor }

What useHelperGrid is asked for.

Properties

halfoptionalnumber

How far the grid reaches from its middle, in world units, on both sides. Default 10.

stepoptionalnumber

How far apart its lines are. Default 1.

coloroptionalTColorOption

The colour of the ordinary lines. Default a dim grey.

xColoroptionalTColorOption | null

The colour of the middle line along X. Default red. null draws it like the rest.

zColoroptionalTColorOption | null

The colour of the middle line along Z. Default blue. null draws it like the rest.

nameoptionalstring

What to call it when you look at it. The engine never looks it up: to find it, name its box.

transformoptionalPartial<TTransform3d>

Where the lines are drawn from. Left out, the place of whatever they are made in.

zIndexoptionalnumber

Draw order within the scene, as for any other drawing.

visibleoptionalboolean

Whether they start drawn. Default true.

View source · hooks/helpers/use_helper_grid.ts:14

TUseLinesOptionstypenacatamalon

TUseLinesOptions: TLinesOptions & { lines }

What useLines is asked for.

Properties

linesoptionaltypeOperator | Float32Array

The first lines to draw, in either of the forms setLines takes. Left out, it starts empty, which is normal for lines rewritten every frame.

nameoptionalstring

What to call it when you look at it. The engine never looks it up: to find it, name its box.

transformoptionalPartial<TTransform3d>

Where the lines are drawn from. Left out, the place of whatever they are made in.

zIndexoptionalnumber

Draw order within the scene, as for any other drawing.

visibleoptionalboolean

Whether they start drawn. Default true.

View source · hooks/helpers/use_lines.ts:11