Skip to content

Commit

Permalink
renamed Grid.base_plane_offset to first_brush_plane
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-biscuits committed Jul 1, 2023
1 parent d1bf1f5 commit 4daf569
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
15 changes: 8 additions & 7 deletions bsp_tool/branches/respawn/titanfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ class GeoSet(base.Struct): # LUMP 87 (0057)
primitive: List[int] # embedded Primitive?
# primitive.unique_contents: int # index into UniqueContents
# primitive.index: int # index into Brushes / TricollHeaders
# primitive.type: PrimitiveType # Brushes or Tricoll
# primitive.type: PrimitiveType # Brush / Tricoll
__slots__ = ["straddle_group", "num_primitives", "primitive"]
_format = "2HI"
_bitfields = {"primitive": {"unique_contents": 8, "index": 16, "type": 8}}
Expand All @@ -470,10 +470,10 @@ class Grid(base.Struct): # LUMP 85 (0055)
# mins = offset * scale
# maxs = (offset + count) * scale
# NOTE: bounds covers Models[0]
num_straddle_groups: int # linked to geosets, objects straddling many gridcells?
base_plane_offset: int # first plane for brushes to index
num_straddle_groups: int # linked to GeoSets, for objects in multiple GridCells?
first_brush_plane: int # index of first Plane indexed by Brushes
# other planes might be used by portals, unsure
__slots__ = ["scale", "offset", "count", "num_straddle_groups", "base_plane_offset"]
__slots__ = ["scale", "offset", "count", "num_straddle_groups", "first_brush_plane"]
_format = "f6i"
_arrays = {"offset": [*"xy"], "count": [*"xy"]}

Expand Down Expand Up @@ -1238,11 +1238,12 @@ def get_brush_sides(bsp, brush_index: int) -> Dict[str, Any]:
brush_planes.append((vector.vec3(**{axis: -1}), -min_dist))
# non-axial planes
for i in range(brush.num_plane_offsets):
brush_plane_offset = brush.brush_side_offset + i - bsp.CM_BRUSH_SIDE_PLANE_OFFSETS[brush.brush_side_offset + i]
normal, distance = bsp.PLANES[bsp.CM_GRID.base_plane_offset + brush_plane_offset]
offset = brush.brush_side_offset + i
brush_plane_offset = offset - bsp.CM_BRUSH_SIDE_PLANE_OFFSETS[offset]
normal, distance = bsp.PLANES[bsp.CM_GRID.first_brush_plane + brush_plane_offset]
brush_planes.append((-normal, -distance))
out["planes"] = brush_planes
# NOTE: which planes are used is likely filtered by brush side properties
# NOTE: BrushSideProperties likely eliminate some planes
return out


Expand Down
5 changes: 3 additions & 2 deletions bsp_tool/extensions/decompile_rbsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def brush_valve_220(bsp, brush: titanfall.Brush, editor: str = "TrenchBroom", of
# add additional planes
# TODO: some brushes become invalid, might be slicing with bad bevel planes
for i in range(brush.num_plane_offsets):
brush_plane_offset = brush.brush_side_offset + i - bsp.CM_BRUSH_SIDE_PLANE_OFFSETS[brush.brush_side_offset + i]
normal, distance = bsp.PLANES[bsp.CM_GRID.base_plane_offset + brush_plane_offset]
offset = brush.brush_side_offset + i
brush_plane_offset = offset - bsp.CM_BRUSH_SIDE_PLANE_OFFSETS[offset]
normal, distance = bsp.PLANES[bsp.CM_GRID.first_brush_plane + brush_plane_offset]
brush_planes.append((-normal, -distance))
num_brush_sides = 6 + brush.num_plane_offsets
for j in range(num_brush_sides):
Expand Down
7 changes: 7 additions & 0 deletions tests/branches/respawn/test_titanfall2.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ class TestAssumptions:
@pytest.mark.parametrize("bsp", bsps.values(), ids=bsps.keys())
def test_grid_cells_count(self, bsp: RespawnBsp):
assert len(bsp.CM_GRID_CELLS) == bsp.CM_GRID.count.x * bsp.CM_GRID.count.y + len(bsp.MODELS)


class TestMethods:
@pytest.mark.xfail(raises=AttributeError, reason="MRVN-Radiant doesn't export BrushSideTextureVectors")
@pytest.mark.parametrize("bsp", bsps.values(), ids=bsps.keys())
def test_get_brush_sides(self, bsp: RespawnBsp):
assert len(bsp.get_brush_sides(0)) > 0

0 comments on commit 4daf569

Please sign in to comment.