Debug
Volver a la referencia

Debug

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

10 símbolos

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.

Parámetros

linesTLines

The lines useLines gave.

nextFloat32Array<ArrayBufferLike> | typeOperator

What they draw now.

Ejemplo

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();
};
Ver el código · 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.

Parámetros

optionsTUseHelperAxisOptions

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

Ejemplo

const Level = () => {
    useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 1, z: 4, rotationX: -0.2 } });
    useHelperAxis({ size: 2, negative: true });
    return createScene();
};
Ver el código · 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.

Parámetros

optionsTUseHelperGridOptions

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

Ejemplo

const Level = () => {
    useCamera3d({ projection: 'perspective', fov: 60, transform: { y: 4, z: 8, rotationX: -0.45 } });
    useHelperGrid({ half: 5 });
    return createScene();
};
Ver el código · 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.

Parámetros

optionsTUseLinesOptions

The first lines, and where they are drawn from.

Ejemplo

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();
};
Ver el código · 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.

Propiedades

from{ x, y, z }

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

to{ x, y, z }

Where it ends.

coloropcionalTColorOption

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

Ver el código · gameobjects/lines/lines_state.ts:14

TLinesOptionstypenacatamalon

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

Propiedades

nameopcionalstring

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

transformopcionalPartial<TTransform3d>

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

zIndexopcionalnumber

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

visibleopcionalboolean

Whether they start drawn. Default true.

Ver el código · gameobjects/lines/new_lines.ts:21

TUseHelperAxisOptionstypenacatamalon

TUseHelperAxisOptions: TLinesOptions & { size, negative, colors }

What useHelperAxis is asked for.

Propiedades

sizeopcionalnumber

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

negativeopcionalboolean

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

colorsopcionalTHelperAxisColors

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

nameopcionalstring

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

transformopcionalPartial<TTransform3d>

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

zIndexopcionalnumber

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

visibleopcionalboolean

Whether they start drawn. Default true.

Ver el código · hooks/helpers/use_helper_axis.ts:27

TUseHelperGridOptionstypenacatamalon

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

What useHelperGrid is asked for.

Propiedades

halfopcionalnumber

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

stepopcionalnumber

How far apart its lines are. Default 1.

coloropcionalTColorOption

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

xColoropcionalTColorOption | null

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

zColoropcionalTColorOption | null

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

nameopcionalstring

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

transformopcionalPartial<TTransform3d>

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

zIndexopcionalnumber

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

visibleopcionalboolean

Whether they start drawn. Default true.

Ver el código · hooks/helpers/use_helper_grid.ts:14

TUseLinesOptionstypenacatamalon

TUseLinesOptions: TLinesOptions & { lines }

What useLines is asked for.

Propiedades

linesopcionaltypeOperator | 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.

nameopcionalstring

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

transformopcionalPartial<TTransform3d>

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

zIndexopcionalnumber

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

visibleopcionalboolean

Whether they start drawn. Default true.

Ver el código · hooks/helpers/use_lines.ts:11