Skip to content

Commit abac963

Browse files
committed
Minor improvement to ergonomics of checking if a DfsObject is instanced
1 parent 693ca4d commit abac963

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

bdk_addon/bsp/operators.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -778,15 +778,12 @@ def _get_or_add_material(material: Material | None) -> int:
778778
level_object.bdk.level.brushes.clear()
779779

780780
for brush_index, dfs_object in enumerate(brush_objects):
781-
brush_object = dfs_object.obj
782-
instance_objects = dfs_object.instance_objects
783-
is_instanced_brush = len(instance_objects) > 0
784-
if is_instanced_brush:
781+
if dfs_object.is_instanced:
785782
# Skip brushes that are instanced, as we cannot change their texturing.
786783
continue
787784
level_brush = level_object.bdk.level.brushes.add()
788785
level_brush.index = brush_index
789-
level_brush.brush_object = brush_object
786+
level_brush.brush_object = dfs_object.obj
790787

791788
timer = time.time()
792789

@@ -797,8 +794,7 @@ def _get_or_add_material(material: Material | None) -> int:
797794

798795
brushes: list[Brush] = []
799796
for brush_index, dfs_object in enumerate(brush_objects):
800-
801-
if dfs_object.instance_objects:
797+
if dfs_object.is_instanced:
802798
instanced_brush_indices.append(brush_index)
803799

804800
brush_object = dfs_object.obj

bdk_addon/dfs.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def __init__(self, obj: Object, instance_objects: List[Object], matrix_world: Ma
2323
@property
2424
def is_visible(self) -> bool:
2525
"""
26-
Check if the object is visible.
27-
28-
@return: True if the object is visible, False otherwise.
26+
Return whether the object is visible.
2927
"""
3028
if self.instance_objects:
3129
return self.instance_objects[-1].visible_get()
@@ -34,13 +32,19 @@ def is_visible(self) -> bool:
3432
@property
3533
def is_selected(self) -> bool:
3634
"""
37-
Check if the object is selected.
38-
@return: True if the object is selected, False otherwise.
35+
Return whether the object is selected.
3936
"""
4037
if self.instance_objects:
4138
return self.instance_objects[-1].select_get()
4239
return self.obj.select_get()
4340

41+
@property
42+
def is_instanced(self) -> bool:
43+
"""
44+
Return whether the object is part of an instance.
45+
"""
46+
return len(self.instance_objects) > 0
47+
4448

4549
def _dfs_object_children(obj: Object, collection: Collection) -> Iterable[Object]:
4650
"""
@@ -85,9 +89,9 @@ def dfs_collection_objects(collection: Collection) -> Iterable[DfsObject]:
8589

8690
def _dfs_collection_objects_recursive(
8791
collection: Collection,
88-
instance_objects: Optional[List[Object]] = None,
92+
instance_objects: list[Object] | None = None,
8993
matrix_world: Matrix = Matrix.Identity(4),
90-
visited: Optional[Set[Object]]=None
94+
visited: set[Object] | None = None
9195
) -> Iterable[DfsObject]:
9296
"""
9397
Depth-first search of objects in a collection, including recursing into instances.

0 commit comments

Comments
 (0)