PhysicsSpatialGridHelper

@three-blocks/pro
new PhysicsSpatialGridHelper(physics : Physics, options : Object)

Create a spatial grid visualization helper.

Constructor Parameters
The Physics instance.
optionsoptionalObject
Configuration options.
  • cellSizeoptionalnumber
    Size of each grid cell in world units.
    Default is 4.
  • gridExtentoptionalnumber
    Number of cells to show in each direction from center.
    Default is 6.
  • showQueryRadiusoptionalboolean
    Highlight the query radius area.
    Default is true.
  • queryRadiusoptionalnumber
    Radius used for spatial queries (capsule size).
    Default is 3.
  • gridColoroptionalnumber
    Color of grid lines (grey).
    Default is 0x888888.
  • queryColoroptionalnumber
    Color of query radius box (yellow).
    Default is 0x00ff88.
  • activeColoroptionalnumber
    Color of active cells (green).
    Default is 0xffff00.
  • targetoptionalTHREE.Object3D
    Target object to follow (uses interpolated position).
  • enabledoptionalboolean
    Whether to start enabled.
    Default is true.

Methods

setCellSize#

setCellSize(size : number)

Set the cell size (should match PhysicsSpatialGrid.cellSize).

Parameters
sizenumber
Cell size in world units.

setGridExtent#

setGridExtent(extent : number)

Set the grid extent (number of cells from center).

Parameters
extentnumber
Number of cells in each direction.

setQueryRadius#

setQueryRadius(radius : number)

Set the query radius for visualization.

Parameters
radiusnumber
Query radius in world units.

setTarget#

setTarget(target : THREE.Object3D)

Set the target object to follow (uses interpolated position).

Parameters
targetTHREE.Object3D
Target object (e.g., player mesh).

setEnabled#

setEnabled(enabled : boolean)

Enable or disable the helper.

Parameters
enabledboolean
Whether to show the visualization.

toggle#

toggle()

Toggle enabled state.

update#

update()

Update the visualization. Call every frame. Positions the grid around the player and updates the query radius box.

dispose#

dispose()

Dispose of the helper and free resources.