Skip to content

Commit e6e5797

Browse files
committed
refactor: zone output items now handled like other attrs
1 parent e467dc8 commit e6e5797

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

ntp_operator.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
INDEX = "i"
2020
IMAGE_DIR_NAME = "imgs"
2121
IMAGE_PATH = "image_path"
22+
ITEM = "item"
2223
BASE_DIR = "base_dir"
2324

2425
RESERVED_NAMES = {
2526
INDEX,
2627
IMAGE_DIR_NAME,
2728
IMAGE_PATH,
29+
ITEM,
2830
BASE_DIR
2931
}
3032

@@ -312,6 +314,10 @@ def _set_settings_defaults(self, node: Node) -> None:
312314
continue
313315

314316
setting_str = f"{node_var}.{attr_name}"
317+
"""
318+
A switch statement would've been nice here,
319+
but Blender 3.0 was on Python v3.9
320+
"""
315321
if st == ST.ENUM:
316322
if attr != '':
317323
self._write(f"{setting_str} = {enum_to_py_str(attr)}")
@@ -352,6 +358,10 @@ def _set_settings_defaults(self, node: Node) -> None:
352358
self._load_image(attr, f"{node_var}.{attr_name}")
353359
elif st == ST.IMAGE_USER:
354360
self._image_user_settings(attr, f"{node_var}.{attr_name}")
361+
elif st == ST.SIM_OUTPUT_ITEMS:
362+
self._output_zone_items(attr, f"{node_var}.{attr_name}", True)
363+
elif st == ST.REPEAT_OUTPUT_ITEMS:
364+
self._output_zone_items(attr, f"{node_var}.{attr_name}", False)
355365
elif st == ST.INDEX_SWITCH_ITEMS:
356366
self._index_switch_items(attr, f"{node_var}.{attr_name}")
357367
elif st == ST.ENUM_DEFINITION:
@@ -1060,6 +1070,28 @@ def _image_user_settings(self, img_user: bpy.types.ImageUser,
10601070
self._write(f"{img_user_var}.{img_usr_attr} = "
10611071
f"{getattr(img_user, img_usr_attr)}")
10621072

1073+
if bpy.app.version >= (3, 6, 0):
1074+
def _output_zone_items(self, output_items, items_str: str,
1075+
is_sim: bool) -> None:
1076+
"""
1077+
Set items for a zone's output
1078+
1079+
output_items (NodeGeometry(Simulation/Repeat)OutputItems): items
1080+
to copy
1081+
items_str (str):
1082+
"""
1083+
self._write(f"{items_str}.clear()")
1084+
for i, item in enumerate(output_items):
1085+
socket_type = enum_to_py_str(item.socket_type)
1086+
name = str_to_py_str(item.name)
1087+
self._write(f"# Create item {name}")
1088+
self._write(f"{items_str}.new({socket_type}, {name})")
1089+
1090+
if is_sim:
1091+
item_var = f"{items_str}[{i}]"
1092+
ad = enum_to_py_str(item.attribute_domain)
1093+
self._write(f"{item_var}.attribute_domain = {ad}")
1094+
10631095
if bpy.app.version >= (4, 1, 0):
10641096
def _index_switch_items(self, switch_items: bpy.types.NodeIndexSwitchItems,
10651097
items_str: str) -> None:

utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ST(Enum):
2929
CURVE_MAPPING = auto()
3030
NODE_TREE = auto()
3131

32+
SIM_OUTPUT_ITEMS = auto()
33+
REPEAT_OUTPUT_ITEMS = auto()
3234
ENUM_DEFINITION = auto()
3335
INDEX_SWITCH_ITEMS = auto()
3436
BAKE_ITEMS = auto()

0 commit comments

Comments
 (0)