[Proc Gen] BSP.to_heightmap and BSPMap class #206

Open
opened 2026-01-12 00:10:08 +00:00 by john · 0 comments
Owner

Parent Issue: #192
Depends On: #193 (HeightMap core), #202 (BSP core), #203 (BSPNode), #204 (BSP iteration)

Overview

Add method to convert BSP node selection to a HeightMap, and implement the BSPMap subclass.

Specification

BSP.to_heightmap

def to_heightmap(self,
                 size: tuple[int, int] = None,
                 select: str = "leaves",
                 nodes: list[BSPNode] = None,
                 shrink: int = 0,
                 value: float = 1.0) -> BSPMap
Parameter Type Description
size (int, int) Output size. Default: bounds size.
select str "leaves", "all", or "internal". Default: "leaves".
nodes list[BSPNode] Override: specific nodes only.
shrink int Pixels to shrink from each node's bounds. Default: 0.
value float Value inside selected regions. Default: 1.0.

BSPMap Class

BSPMap extends HeightMap with BSP-specific context and operations.

Properties

Property Type Description
bsp BSP Read-only. The tree that created this map.
nodes tuple[BSPNode, ...] Read-only. Nodes represented in this map.
shrink int Read-only. Margin applied from bounds.

Methods

def inverse(self) -> BSPMap

Return a new BSPMap with walls instead of rooms.

def expand(self, amount: int = 1) -> BSPMap
def contract(self, amount: int = 1) -> BSPMap

Return new BSPMap with adjusted bounds.

def with_nodes(self, nodes: list[BSPNode]) -> BSPMap
def with_shrink(self, shrink: int) -> BSPMap

Return new BSPMap with different parameters.

Example

bsp = mcrfpy.BSP(bounds=((0, 0), (80, 50)))
bsp.split_recursive(depth=4, min_size=(8, 8))

# Get room mask with 1-tile margin for walls
rooms = bsp.to_heightmap(select="leaves", shrink=1)

# Apply to grid
grid.apply_threshold(rooms, range=(0.5, 1.0), walkable=True)

Implementation Notes

  • BSPMap inherits all HeightMap methods
  • inverse() fills BSP bounds with 1.0, then subtracts rooms
  • shrink creates margin from node edges (for wall thickness)
  • Selected regions get value, unselected get 0.0

Acceptance Criteria

  • to_heightmap creates correct BSPMap
  • shrink parameter reduces room sizes correctly
  • inverse() produces wall layout
  • BSPMap works with all HeightMap operations
  • Visual demo showing room/wall masks
**Parent Issue:** #192 **Depends On:** #193 (HeightMap core), #202 (BSP core), #203 (BSPNode), #204 (BSP iteration) ## Overview Add method to convert BSP node selection to a HeightMap, and implement the BSPMap subclass. ## Specification ### BSP.to_heightmap ```python def to_heightmap(self, size: tuple[int, int] = None, select: str = "leaves", nodes: list[BSPNode] = None, shrink: int = 0, value: float = 1.0) -> BSPMap ``` | Parameter | Type | Description | |-----------|------|-------------| | `size` | `(int, int)` | Output size. Default: bounds size. | | `select` | `str` | `"leaves"`, `"all"`, or `"internal"`. Default: `"leaves"`. | | `nodes` | `list[BSPNode]` | Override: specific nodes only. | | `shrink` | `int` | Pixels to shrink from each node's bounds. Default: 0. | | `value` | `float` | Value inside selected regions. Default: 1.0. | ### BSPMap Class BSPMap extends HeightMap with BSP-specific context and operations. #### Properties | Property | Type | Description | |----------|------|-------------| | `bsp` | `BSP` | Read-only. The tree that created this map. | | `nodes` | `tuple[BSPNode, ...]` | Read-only. Nodes represented in this map. | | `shrink` | `int` | Read-only. Margin applied from bounds. | #### Methods ```python def inverse(self) -> BSPMap ``` Return a new BSPMap with walls instead of rooms. ```python def expand(self, amount: int = 1) -> BSPMap def contract(self, amount: int = 1) -> BSPMap ``` Return new BSPMap with adjusted bounds. ```python def with_nodes(self, nodes: list[BSPNode]) -> BSPMap def with_shrink(self, shrink: int) -> BSPMap ``` Return new BSPMap with different parameters. ### Example ```python bsp = mcrfpy.BSP(bounds=((0, 0), (80, 50))) bsp.split_recursive(depth=4, min_size=(8, 8)) # Get room mask with 1-tile margin for walls rooms = bsp.to_heightmap(select="leaves", shrink=1) # Apply to grid grid.apply_threshold(rooms, range=(0.5, 1.0), walkable=True) ``` ## Implementation Notes - BSPMap inherits all HeightMap methods - `inverse()` fills BSP bounds with 1.0, then subtracts rooms - `shrink` creates margin from node edges (for wall thickness) - Selected regions get `value`, unselected get 0.0 ## Acceptance Criteria - [ ] `to_heightmap` creates correct BSPMap - [ ] `shrink` parameter reduces room sizes correctly - [ ] `inverse()` produces wall layout - [ ] BSPMap works with all HeightMap operations - [ ] Visual demo showing room/wall masks
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
john/McRogueFace#206
No description provided.