Skip to content

Latest commit

 

History

History
126 lines (107 loc) · 6.53 KB

File metadata and controls

126 lines (107 loc) · 6.53 KB
order category name sourcePath type componentSignature
7.17
@threlte/extras
<Grid>
packages/extras/src/lib/components/Grid/Grid.svelte
component
extends props
name type default required
plane
'xz' | 'xy' | 'zy'
'xz'
false
name type default required
cellColor
ColorRepresentation
'#000000'
false
name type default required
cellSize
number
1
false
name type default required
cellThickness
number
1
false
name type default required
sectionColor
ColorRepresentation
'#0000ee'
false
name type default required
sectionSize
number
10
false
name type default required
sectionThickness
number
2
false
name type default required
gridSize
number | [number, number]
[20,20]
false
name type default required
followCamera
boolean
false
false
name type default required
infiniteGrid
boolean
false
false
name type default required
fadeDistance
number
100
false
name type default required
fadeStrength
number
1
false
name type default required
type
'grid' | 'lines' | 'circular' | 'polar'
'grid'
false
name type default required description
axis
'x' | 'y' | 'z'
'x'
false
'line' only. Designates the world axis along which the line will be oriented.
name type default required description
maxRadius
number
0
false
'circular' and 'polar' only. 0 removes the constraint.
name type default required description
cellDividers
number
6
false
'polar' only. How many lines will divide the polar grid. Specifies the number of lines that will subdivide the polar grid. For instance, 2 dividers will quarter the grid into 4 sections of 90° each, while 6 dividers will divide the grid into 12 segments, each measuring 30°.
name type default required description
sectionDividers
number
2
false
'polar' only. Specifies the number of lines that will subdivide the polar grid. For instance, 2 dividers will quarter the grid into 4 sections of 90° each, while 6 dividers will divide the grid into 12 segments, each measuring 30°.
name type default required
side
THREE.Side
THREE.DoubleSide
false

A robust grid implementation with multiple tweakable parameters.

Usage

This component provides sensible defaults. You can initialize the default grid with just <Grid>. ref passes a reference from the <T.Mesh/> the grid is constructed on.

Grid types

The grid type can be selected by setting the type parameter. The available grid types are:

  • grid: represents a standard box grid. It does not require any additional properties. (default)
  • lines: grid consisting of lines that align along a single world axis. You specify this axis by providing either x, y or z to the axis property.
  • circular: grid formed of concentric circles. It includes a maxRadius property that sets the maximum growth extent for the grid. A value of 0 removes this limit, allowing the grid to occupy the entire geometry, even if it results in incomplete circles.
  • polar: similar to the circular type, but it also features lines that subdivide the concentric circles. It too has a maxRadius property. Additionally, it has two properties for specifying dividers: cellDivider and sectionDivider. These determine how many lines will segment the circle into various sectors. For example, 2 lines result in 4 segments at 90° each, while 6 lines create 12 sectors at 30° apiece.
Grid Lines Circular Polar
Grid preview Grid preview Grid preview Grid preview

Cells and Sections

Grid is split into cells and sections. Cell is meant to represent the smallest units on your grid, whereas section is a group of cells. You can adjust the size of the grid by changing the cellSize and sectionSize parameters. Size is in Three world units, so for example a mesh with BoxGeometry(1,1,1) will fit perfectly into a size 1 cell. By default a cell is 1 unit and a section 10, which means that a grid of 10x10 cells will be outlined with a section line.

Lines

You can adjust the color and thickness of cell and section lines with cellColor, cellThickness, sectionColor, sectionThickness.

Grid size and fading

The <Grid> component is a THREE.Mesh with a PlaneGeometry attached to it. The gridSize parameter defines the size of the PlaneGeometry. You can extend the grid into infinity if you set the infiniteGrid parameter to true. Changing fadeDistance sets how far from the camera position the grid begins to fade by having its alpha reduced. fadeStrength determines how fast it happens (exponent). fadeStrength = 0 means that there is no fading (not recommended for large grids).

Custom geometry

You have the option to insert your own custom geometry into the <Grid/> slot. The preceding example demonstrates this by showcasing a preview of a terrain-like geometry generated using Perlin noise.

<Grid>
  <T.BoxGeometry />
</Grid>

Follow camera

Setting followCamera to true applies a transform that moves the grid to the camera's position on the chosen plane.