threejs-worldgen
    Preparing search index...

    Class HexGrid

    The H3 hexagonal hierarchical index laid over a world.

    • Planets use their own directions: a planet-centred point maps to latitude asin(y / |p|) and longitude atan2(x, z), the same convention as World.frameAt. A resolution's metric size scales with the radius: edge(res) = H3 edge(res) × radius / 6 371 007 m. On a 120 km planet, resolution 8 (531 m on Earth) is 10 m across; resolution 3 (69 km on Earth) is 1.3 km.
    • Flat worlds map local metres onto an Earth-sized globe near the equator (equirectangular around PLANE_ANCHOR): latitude = −z / R⊕, longitude = anchor + x / R⊕. Cell sizes then match H3's published resolutions in metres (res 8 ≈ 531 m edge, 0.74 km²). Within ±2000 km of the origin cells are within 5 % of their nominal size; beyond that they stretch east–west by 1 / cos(latitude).

    Local positions are [x, z] in a LocalFrame (x east, z south): the world itself on flat worlds, a tangent plane (gnomonic projection) on planets.

    const grid = new HexGrid(world)
    const res = grid.resolutionFor(400) // the resolution whose edge is nearest 400 m
    const cell = grid.cellAtLocal(120, -40, res)
    grid.centerLocal(cell) // [x, z] of the cell centre
    grid.boundaryLocal(cell) // hexagon corners, [x, z][]
    Index
    world: World

    The world the index is laid over.

    • get scale(): number

      Metres per radian of H3 latitude/longitude: the planet radius, or H3's Earth radius on flat worlds.

      Returns number

    • get sizeFactor(): number

      Linear size of this world's cells relative to H3's published Earth sizes (1 on flat worlds).

      Returns number

    • Area of a cell on this world, m².

      Parameters

      • cell: string

      Returns number

    • Corners of a cell (6, or 5 for pentagons, plus extra points where it crosses an icosahedron edge) as local [x, z], counter-clockwise seen from above.

      Parameters

      • cell: string

      Returns [number, number][]

    • Cell containing a base-surface world position.

      Parameters

      • px: number
      • py: number
      • pz: number
      • res: number

      Returns string

    • Cell containing local [x, z].

      Parameters

      • x: number
      • z: number
      • res: number

      Returns string

    • Local [x, z] of a cell's centre.

      Parameters

      • cell: string
      • out: [number, number] = ...

      Returns [number, number]

    • The descendants of cell at a finer resolution (7 per level; 6 under pentagons).

      Parameters

      • cell: string
      • res: number

      Returns string[]

    • Every cell within k steps of cell (its k-ring disk, cell included).

      Parameters

      • cell: string
      • k: number

      Returns string[]

    • Average hexagon edge length at res on this world, metres.

      Parameters

      • res: number

      Returns number

    • Base-surface world position of a latitude/longitude in degrees (on the sphere, or [x, 0, z]).

      Parameters

      • lat: number
      • lng: number
      • out: Vec3 = ...

      Returns Vec3

    • Base-surface world position under local [x, z] (on the sphere, or [x, 0, z]).

      Parameters

      • x: number
      • z: number
      • out: Vec3 = ...

      Returns Vec3

    • The ancestor of cell at a coarser resolution.

      Parameters

      • cell: string
      • res: number

      Returns string

    • Resolution of a cell.

      Parameters

      • cell: string

      Returns number

    • The resolution (0…15) whose average edge length is closest (in ratio) to metres on this world.

      Parameters

      • metres: number

      Returns number

    • [latitude, longitude] in degrees of a base-surface world position (planet-centred, or [x, ·, z]).

      Parameters

      • px: number
      • py: number
      • pz: number

      Returns [number, number]

    • Local [x, z] of a base-surface world position (NaN on the far side of a planet).

      Parameters

      • p: Vec3
      • out: [number, number] = ...

      Returns [number, number]