Browse Source

Allow `NodeTree`s to be reused in the `pre_export` phase.

Logic trees can be shared, so it is conceivable that a logic tree might
be pre-exported more than once. They can already be created by artists
and referenced from multiple Advanced Logic modifiers, so this is good
for consistency.
pull/414/head
Adam Johnson 6 months ago
parent
commit
1cf33ba286
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 8
      korman/exporter/convert.py
  2. 28
      korman/properties/modifiers/base.py

8
korman/exporter/convert.py

@ -510,8 +510,12 @@ class Exporter:
@handle_temporary.register(bpy.types.NodeTree)
def _(temporary, parent):
self.exit_stack.enter_context(TemporaryObject(temporary, bpy.data.node_groups.remove))
log_msg(f"'{parent.name}' generated NodeTree '{temporary.name}'")
# NodeTrees are reuseable, so make sure we haven't already encountered it.
if not temporary.name in self.want_node_trees:
self.exit_stack.enter_context(TemporaryObject(temporary, bpy.data.node_groups.remove))
log_msg(f"'{parent.name}' generated NodeTree '{temporary.name}'")
else:
log_msg(f"'{parent.name}' reused NodeTree '{temporary.name}'")
if temporary.bl_idname == "PlasmaNodeTree":
parent_so = self.mgr.find_create_object(plSceneObject, bl=parent)
self.want_node_trees[temporary.name].add((parent, parent_so))

28
korman/properties/modifiers/base.py

@ -181,20 +181,24 @@ class PlasmaModifierProperties(bpy.types.PropertyGroup):
class PlasmaModifierLogicWiz:
def convert_logic(self, bo, **kwargs):
"""Creates, converts, and returns an unmanaged NodeTree for this logic wizard. If the wizard
fails during conversion, the temporary tree is deleted for you. However, on success, you
are responsible for removing the tree from Blender, if applicable."""
"""Attempts to look up an already existing logic tree matching the name provided and returns
it, if found. If not, creates, converts, and returns an unmanaged NodeTree for this wizard.
If the wizard fails during conversion, the temporary tree is deleted for you. However, on
success, you are responsible for removing the tree from Blender, if applicable."""
name = kwargs.pop("name", self.key_name)
assert not "tree" in kwargs
tree = bpy.data.node_groups.new(name, "PlasmaNodeTree")
kwargs["tree"] = tree
try:
self.logicwiz(bo, **kwargs)
except:
bpy.data.node_groups.remove(tree)
raise
else:
return tree
node_groups = bpy.data.node_groups
tree = node_groups.get(name)
if tree is None:
tree = node_groups.new(name, "PlasmaNodeTree")
kwargs["tree"] = tree
try:
self.logicwiz(bo, **kwargs)
except:
bpy.data.node_groups.remove(tree)
raise
return tree
def _create_python_file_node(self, tree, filename: str, attributes: Dict[str, Any]) -> bpy.types.Node:
pfm_node = tree.nodes.new("PlasmaPythonFileNode")

Loading…
Cancel
Save