new CellSpacePartitioning(width, height, depth, cellsX, cellsY, cellsZ)
Constructs a new spatial index with the given values.
Parameters:
Name | Type | Description |
---|---|---|
width |
Number | The width of the entire spatial index. |
height |
Number | The height of the entire spatial index. |
depth |
Number | The depth of the entire spatial index. |
cellsX |
Number | The amount of cells along the x-axis. |
cellsY |
Number | The amount of cells along the y-axis. |
cellsZ |
Number | The amount of cells along the z-axis. |
Members
-
cells :Array.<Cell>
-
The list of partitions.
-
cellsX :Number
-
The amount of cells along the x-axis.
-
cellsY :Number
-
The amount of cells along the y-axis.
-
cellsZ :Number
-
The amount of cells along the z-axis.
-
depth :Number
-
The depth of the entire spatial index.
-
height :Number
-
The height of the entire spatial index.
-
width :Number
-
The width of the entire spatial index.
Methods
-
addEntityToPartition(entity, index) → {CellSpacePartitioning}
-
Adds an entity to a specific partition.
Parameters:
Name Type Description entity
GameEntity The entity to add.
index
Number The partition index.
-
addPolygon(polygon) → {CellSpacePartitioning}
-
Adds a polygon to the spatial index. A polygon is approximated with an AABB.
Parameters:
Name Type Description polygon
Polygon The polygon to add.
-
fromJSON(json) → {CellSpacePartitioning}
-
Restores this instance from the given JSON object.
Parameters:
Name Type Description json
Object The JSON object.
-
getIndexForPosition(position) → {Number}
-
Computes the partition index for the given position vector.
Parameters:
Name Type Description position
Vector3 The given position.
Returns:
Number -The partition index.
-
makeEmpty() → {CellSpacePartitioning}
-
Removes all entities from all partitions.
-
query(position, radius, result) → {Array.<Any>}
-
Performs a query to the spatial index according the the given position and radius. The method approximates the query position and radius with an AABB and then performs an intersection test with all non-empty cells in order to determine relevant partitions. Stores the result in the given result array.
Parameters:
Name Type Description position
Vector3 The given query position.
radius
Number The given query radius.
result
Array.<Any> The result array.
Returns:
Array.<Any> -The result array.
-
removeEntityFromPartition(entity, index) → {CellSpacePartitioning}
-
Removes an entity from a specific partition.
Parameters:
Name Type Description entity
GameEntity The entity to remove.
index
Number The partition index.
-
resolveReferences(entities) → {CellSpacePartitioning}
-
Restores UUIDs with references to GameEntity objects.
Parameters:
Name Type Description entities
Map.<String, GameEntity> Maps game entities to UUIDs.
-
toJSON() → {Object}
-
Transforms this instance into a JSON object.
Returns:
Object -The JSON object.
-
updateEntity(entity, currentIndex) → {Number}
-
Updates the partitioning index of a given game entity.
Parameters:
Name Type Description entity
GameEntity The entity to update.
currentIndex
Number The current partition index of the entity.
Returns:
Number -The new partitioning index for the given game entity.