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 entityGameEntity The entity to add.
indexNumber The partition index.
-
addPolygon(polygon) → {CellSpacePartitioning}
-
Adds a polygon to the spatial index. A polygon is approximated with an AABB.
Parameters:
Name Type Description polygonPolygon The polygon to add.
-
fromJSON(json) → {CellSpacePartitioning}
-
Restores this instance from the given JSON object.
Parameters:
Name Type Description jsonObject The JSON object.
-
getIndexForPosition(position) → {Number}
-
Computes the partition index for the given position vector.
Parameters:
Name Type Description positionVector3 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 positionVector3 The given query position.
radiusNumber The given query radius.
resultArray.<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 entityGameEntity The entity to remove.
indexNumber The partition index.
-
resolveReferences(entities) → {CellSpacePartitioning}
-
Restores UUIDs with references to GameEntity objects.
Parameters:
Name Type Description entitiesMap.<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 entityGameEntity The entity to update.
currentIndexNumber The current partition index of the entity.
Returns:
Number -The new partitioning index for the given game entity.