Engine API Reference - v2.24.0-beta.18
    Preparing search index...

    Class Grid

    An anti-aliased reference grid whose levels of lines follow the zoom. It follows the camera and fades out with distance, or is sized by its node's scale when not Grid#infinite. It lies at its node's position and rotation; use Grid#spacing to size the cells.

    const grid = new Grid(app.graphicsDevice);
    entity.addComponent('render', {
    meshInstances: grid.meshInstances,
    castShadows: false
    });

    Relevant Engine API examples:

    Index
    • get axisLineThickness(): number

      Gets the axis line thickness in CSS pixels.

      Returns number

    • set axisLineThickness(value: number): void

      Sets the axis line thickness in CSS pixels. Defaults to 2.

      Parameters

      • value: number

      Returns void

    • get contrast(): boolean

      Gets whether the lines contrast with the scene.

      Returns boolean

    • set contrast(value: boolean): void

      Sets whether the lines are black over light parts of the scene and white over dark ones, instead of their theme colors. Needs the scene color map, see CameraComponent#requestSceneColorMap. Defaults to false.

      Parameters

      • value: boolean

      Returns void

    • get depthDither(): boolean

      Gets whether the written depth is dithered.

      Returns boolean

    • set depthDither(value: boolean): void

      Sets whether the written depth is dithered by line coverage, so faint lines partly hide what is behind them. Suits gaussian splats. Defaults to false.

      Parameters

      • value: boolean

      Returns void

    • get depthOffset(): number

      Gets the fraction of the camera distance the grid's depth moves toward the camera by.

      Returns number

    • set depthOffset(value: number): void

      Sets the fraction of the camera distance the grid's depth moves toward the camera by, so a coplanar surface doesn't hide it. Defaults to 0.001.

      Parameters

      • value: number

      Returns void

    • get depthTest(): boolean

      Gets whether the grid is depth tested against the scene.

      Returns boolean

    • set depthTest(value: boolean): void

      Sets whether the grid is depth tested against the scene. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get depthWrite(): boolean

      Gets whether the lines write depth.

      Returns boolean

    • set depthWrite(value: boolean): void

      Sets whether the lines write depth, hiding transparent meshes and gaussian splats behind them. Defaults to false.

      Parameters

      • value: boolean

      Returns void

    • get fadeRange(): Vec2

      Gets the distances from the camera where the grid starts and finishes fading out.

      Returns Vec2

    • set fadeRange(value: Vec2): void

      Sets the distances from the camera where the grid starts and finishes fading out. The end is kept within 90% of the far clip. Defaults to [400, 1000].

      Parameters

      Returns void

    • get infinite(): boolean

      Gets whether the grid has no edge.

      Returns boolean

    • set infinite(value: boolean): void

      Sets whether the grid has no edge. When false, it is sized by its node's scale along the plane's axes. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get majorLineThickness(): number

      Gets the major line thickness in CSS pixels.

      Returns number

    • set majorLineThickness(value: number): void

      Sets the major line thickness in CSS pixels. Defaults to 1.5.

      Parameters

      • value: number

      Returns void

    • get meshInstances(): MeshInstance[]

      Gets the mesh instances to add to a render component or layer: the lines and their depth pass. They have no node, so set one when adding them to a layer directly.

      Returns MeshInstance[]

    • get minorLineThickness(): number

      Gets the minor line thickness in CSS pixels.

      Returns number

    • set minorLineThickness(value: number): void

      Sets the minor line thickness in CSS pixels. Defaults to 1.

      Parameters

      • value: number

      Returns void

    • get showAxes(): boolean

      Gets whether the lines through the origin use the axis colors.

      Returns boolean

    • set showAxes(value: boolean): void

      Sets whether the lines through the origin use the axis colors. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get spacing(): number

      Gets the cell size the levels are scaled from.

      Returns number

    • set spacing(value: number): void

      Sets the cell size the levels are scaled from, in world units. Defaults to 10.

      Parameters

      • value: number

      Returns void

    • get subdivisions(): number

      Gets how many cells of a level fit across one of the level above.

      Returns number

    • set subdivisions(value: number): void

      Sets how many cells of a level fit across one of the level above, or 1 for a single fixed level. Defaults to 10.

      Parameters

      • value: number

      Returns void

    • get visible(): boolean

      Gets whether the grid is visible.

      Returns boolean

    • set visible(value: boolean): void

      Sets whether the grid is visible. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • Destroys the mesh instances and materials. Remove the mesh instances from use first.

      Returns void

    • Sets the theme or part of it. Each color's alpha sets its lines' opacity.

      Parameters

      Returns void

      grid.setTheme({
      axis: { x: new Color(1, 0, 0) },
      minor: new Color(0.5, 0.5, 0.5, 0.5)
      });