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 5 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) @handle_temporary.register(bpy.types.NodeTree)
def _(temporary, parent): def _(temporary, parent):
self.exit_stack.enter_context(TemporaryObject(temporary, bpy.data.node_groups.remove)) # NodeTrees are reuseable, so make sure we haven't already encountered it.
log_msg(f"'{parent.name}' generated NodeTree '{temporary.name}'") 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": if temporary.bl_idname == "PlasmaNodeTree":
parent_so = self.mgr.find_create_object(plSceneObject, bl=parent) parent_so = self.mgr.find_create_object(plSceneObject, bl=parent)
self.want_node_trees[temporary.name].add((parent, parent_so)) 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: class PlasmaModifierLogicWiz:
def convert_logic(self, bo, **kwargs): def convert_logic(self, bo, **kwargs):
"""Creates, converts, and returns an unmanaged NodeTree for this logic wizard. If the wizard """Attempts to look up an already existing logic tree matching the name provided and returns
fails during conversion, the temporary tree is deleted for you. However, on success, you it, if found. If not, creates, converts, and returns an unmanaged NodeTree for this wizard.
are responsible for removing the tree from Blender, if applicable.""" 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) name = kwargs.pop("name", self.key_name)
assert not "tree" in kwargs assert not "tree" in kwargs
tree = bpy.data.node_groups.new(name, "PlasmaNodeTree")
kwargs["tree"] = tree node_groups = bpy.data.node_groups
try: tree = node_groups.get(name)
self.logicwiz(bo, **kwargs) if tree is None:
except: tree = node_groups.new(name, "PlasmaNodeTree")
bpy.data.node_groups.remove(tree) kwargs["tree"] = tree
raise try:
else: self.logicwiz(bo, **kwargs)
return tree 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: def _create_python_file_node(self, tree, filename: str, attributes: Dict[str, Any]) -> bpy.types.Node:
pfm_node = tree.nodes.new("PlasmaPythonFileNode") pfm_node = tree.nodes.new("PlasmaPythonFileNode")

Loading…
Cancel
Save