collision_shape_processor
AUTO-GENERATED FILE – DO NOT EDIT MANUALLY
Processes collision shapes to determine tile offsets for grid-based placement.
Source File: addons/grid_building/placement/manager/components/mapper/collision_shape_processor.gd
Extends: RefCounted
Private Properties
- Property:
_cache_manager: GeometryCacheManager(private)
Constants
- Constant:
GeometryCacheManager = preload("res://addons/grid_building/placement/manager/components/mapper/geometry_cache_manager.gd")
Public Methods
get_tile_offsets_for_collision_object
Computes tile offsets for all collision shapes in a collision object.
This is the main entry point for collision-to-tile mapping. It processes all shapes attached to the collision object and returns their combined tile coverage as offsets relative to a calculated center tile.
Tile Shape Detection:
Automatically reads tile shape from map.tile_set.tile_shape to ensure
single source of truth. Supports TileSet.TILE_SHAPE_SQUARE and TileSet.TILE_SHAPE_ISOMETRIC.
Returns: Dictionary[Vector2i, Array] mapping tile offsets to collision objects
Private Methods
_init
Flags: private
Initializes the processor with required dependencies.
Parameters:
cache_manager: GeometryCacheManager for polygon bounds caching
_initialize_collision_mapping
Flags: private
Validates that required dependencies are available for collision mapping.
_process_shape_offsets
Flags: private
Processes shape offsets for a single collision test setup.
Iterates through all shapes in the test setup and calculates which tiles they overlap with based on the tile shape defined in the map’s TileSet.
rect_test_setup: Shape and collision test configuration
@param test_data: Overall test setup containing epsilon values
@param map: TileMapLayer providing tile configuration via its TileSet
@param center_tile: Reference tile position for offset calculations
@param tile_size: Size of each tile in world coordinates
@param shape_epsilon: Minimum overlap threshold for shape-tile intersection
@param col_obj: Collision object being processed
@returns Dictionary[Vector2i, Array] mapping tile offsets to collision objects for this shape setup
_calculate_tile_range
Flags: private
Calculates the tile range that needs to be checked for a shape.
Determines the bounding box of tiles that might intersect with the shape. Uses actual polygon vertices (which already have rotation/scale/skew applied) instead of AABB to avoid over-expansion under rotation.
@param shape: Shape2D to calculate range for @param bounds: AABB of the shape (fallback for optimization hints) @param map: TileMapLayer providing tile configuration via its TileSet @param tile_size: Size of each tile in world coordinates @param shape_transform: Transform of the shape in world space @param start_tile: Output parameter for the starting tile coordinate @param end_exclusive: Output parameter for the ending tile coordinate (exclusive) @param shape_polygon: Transformed polygon vertices (rotation/scale/skew already applied)
_compute_shape_tile_offsets
Flags: private
Computes which tiles a shape overlaps with, returning offset positions.
For each tile in the specified range, calculates the intersection area between the shape and tile using the tile geometry defined in the map’s TileSet. Returns tile positions relative to the center tile.
@param shape: Shape2D to compute overlaps for @param shape_transform: Transform of the shape in world space @param map: TileMapLayer providing tile configuration via its TileSet @param tile_size: Size of each tile in world coordinates @param shape_epsilon: Minimum overlap threshold for inclusion @param start_tile: Starting tile coordinate for range @param end_exclusive: Ending tile coordinate for range (exclusive) @param center_tile: Reference tile for calculating relative offsets @param shape_polygon: Polygon representation of the shape @returns Array of Vector2i offsets relative to center_tile
_enforce_horizontal_symmetry
Flags: private
Enforces horizontal symmetry for circular and capsule shapes.
For shapes that should be symmetrical (circles and capsules), ensures that if a tile offset exists on one side, the corresponding mirror offset also exists. This prevents asymmetrical collision detection for symmetric shapes.
@param shape_offsets: Array of tile offsets to make symmetric (modified in-place)
_merge_offsets_into_positions
Flags: private
Merges shape offsets into the collision positions dictionary.
Adds each calculated tile offset to the collision positions dictionary, ensuring each collision object is properly tracked for its affected tiles.
@param shape_offsets: Array of tile offsets to merge @param collision_positions: Dictionary mapping tile positions to collision objects @param col_obj: Collision object being processed
_merge_collision_positions
Flags: private
Merges two collision position dictionaries.
Combines the contents of source_positions into target_positions, ensuring each collision object is properly tracked for its affected tiles.
@param target_positions: Dictionary to merge into (modified in-place) @param source_positions: Dictionary to merge from