Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 24 additions & 43 deletions NodeToPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,43 @@

if "bpy" in locals():
import importlib
importlib.reload(export_operator)
importlib.reload(ntp_options)
importlib.reload(ui)
importlib.reload(compositor)
importlib.reload(geometry)
importlib.reload(shader)
importlib.reload(options)
else:
from . import export_operator
from . import ntp_options
from . import ui
from . import compositor
from . import geometry
from . import shader
from . import options

import bpy


class NodeToPythonMenu(bpy.types.Menu):
bl_idname = "NODE_MT_node_to_python"
bl_label = "Node To Python"

@classmethod
def poll(cls, context):
return True

def draw(self, context):
layout = self.layout.column_flow(columns=1)
layout.operator_context = 'INVOKE_DEFAULT'


classes = [
NodeToPythonMenu,
#options
options.NTPOptions,
options.NTPOptionsPanel,
#compositor
compositor.operator.NTPCompositorOperator,
compositor.ui.NTPCompositorScenesMenu,
compositor.ui.NTPCompositorGroupsMenu,
compositor.ui.NTPCompositorPanel,
#geometry
geometry.operator.NTPGeoNodesOperator,
geometry.ui.NTPGeoNodesMenu,
geometry.ui.NTPGeoNodesPanel,
#material
shader.operator.NTPShaderOperator,
shader.ui.NTPShaderMenu,
shader.ui.NTPShaderPanel,
]
modules = [export_operator, ntp_options]
for parent_module in [ui, compositor, geometry, shader]:
if hasattr(parent_module, "modules"):
modules += parent_module.modules
else:
raise Exception(f"Module {parent_module} does not have list of modules")

def register():
for cls in classes:
bpy.utils.register_class(cls)
scene = bpy.types.Scene
scene.ntp_options = bpy.props.PointerProperty(type=options.NTPOptions)
for module in modules:
if hasattr(module, "classes"):
for cls in getattr(module, "classes"):
bpy.utils.register_class(cls)
if hasattr(module, "register_props"):
getattr(module, "register_props")()

def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.ntp_options
for module in modules:
if hasattr(module, "classes"):
for cls in getattr(module, "classes"):
bpy.utils.unregister_class(cls)
if hasattr(module, "unregister_props"):
getattr(module, "unregister_props")()

if __name__ == "__main__":
register()
7 changes: 6 additions & 1 deletion NodeToPython/compositor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
from . import operator
from . import ui

import bpy
import bpy

modules = [
operator
]
modules += ui.modules
10 changes: 7 additions & 3 deletions NodeToPython/compositor/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

COMP_OP_RESERVED_NAMES = {SCENE, BASE_NAME, END_NAME, NODE}

class NTPCompositorOperator(NTP_Operator):
bl_idname = "node.ntp_compositor"
class NTP_OT_Compositor(NTP_Operator):
bl_idname = "ntp.compositor"
bl_label = "Compositor to Python"
bl_options = {'REGISTER', 'UNDO'}

Expand Down Expand Up @@ -280,4 +280,8 @@ def execute(self, context):

self._report_finished("compositor nodes")

return {'FINISHED'}
return {'FINISHED'}

classes: list[type] = [
NTP_OT_Compositor
]
83 changes: 0 additions & 83 deletions NodeToPython/compositor/ui.py

This file was deleted.

17 changes: 17 additions & 0 deletions NodeToPython/compositor/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if "bpy" in locals():
import importlib
importlib.reload(panel)
importlib.reload(scenes)
importlib.reload(compositor_node_groups)
else:
from . import panel
from . import scenes
from . import compositor_node_groups

import bpy

modules : list = [
panel,
scenes,
compositor_node_groups
]
122 changes: 122 additions & 0 deletions NodeToPython/compositor/ui/compositor_node_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import bpy

from . import panel

def register_props():
bpy.types.Scene.ntp_compositor_node_group_slots = bpy.props.CollectionProperty(
type=NTP_PG_CompositorNodeGroupSlot
)
bpy.types.Scene.ntp_compositor_node_group_slots_index = bpy.props.IntProperty()

def unregister_props():
del bpy.types.Scene.ntp_compositor_node_group_slots
del bpy.types.Scene.ntp_compositor_node_group_slots_index

class NTP_PG_CompositorNodeGroupSlot(bpy.types.PropertyGroup):
"""
TODO: There's a bug where the filtering doesn't update when renaming a
slotted object. For now, we'll need to just remove and re-add the slot
to the UI list.
"""
name: bpy.props.StringProperty(
name="Node Tree Name",
default=""
)

def poll_node_tree(self, node_tree: bpy.types.NodeTree) -> bool:
scene = bpy.context.scene

for slot in scene.ntp_compositor_node_group_slots:
if slot is not self and slot.node_tree == node_tree:
return False
return node_tree.bl_idname == 'CompositorNodeTree'

def update_node_tree(self, context):
if self.node_tree:
self.name = self.node_tree.name
else:
self.name = "Compositor Node Group"

node_tree: bpy.props.PointerProperty(
name="Node Tree",
type=bpy.types.NodeTree,
poll=poll_node_tree,
update=update_node_tree
)

class NTP_OT_AddCompositorNodeGroupSlot(bpy.types.Operator):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine a lot of these classes could probably inherit from a common base class, might not have time for this release though

bl_idname = "ntp.add_compositor_node_group_slot"
bl_label = "Add Compositor Node Group Slot"
bl_description = "Add Compositor Node Group Slot"

def execute(self, context):
slots = context.scene.ntp_compositor_node_group_slots
slots.add()
context.scene.ntp_compositor_node_group_slots_index = len(slots) - 1
return {'FINISHED'}

class NTP_OT_RemoveCompositorNodeGroupSlot(bpy.types.Operator):
bl_idname = "ntp.remove_compositor_node_group_slot"
bl_label = "Remove Compositor Node Group Slot"
bl_description = "Remove Compositor Node Group Slot"

def execute(self, context):
slots = context.scene.ntp_compositor_node_group_slots
idx = context.scene.ntp_compositor_node_group_slots_index

if idx >= 0 and idx < len(slots):
slots.remove(idx)
context.scene.ntp_compositor_node_group_slots_index = min(
max(0, idx - 1), len(slots) - 1
)
return {'FINISHED'}

class NTP_UL_CompositorNodeGroup(bpy.types.UIList):
bl_idname = "NTP_UL_compositor_node_group"

def draw_item(self, context, layout, data, item, icon, active_data, active):
if item:
layout.prop_search(item, "node_tree", bpy.data, "node_groups", text="")

class NTP_PT_CompositorNodeGroup(bpy.types.Panel):
bl_idname = "NTP_PT_compositor_node_group"
bl_label = "Node Groups"
bl_parent_id = panel.NTP_PT_Compositor.bl_idname
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_context = ''
bl_category = "NodeToPython"
bl_description = ("List of compositor node group objects to replicate.\n"
"These are typically subgroups within a larger scene tree")
bl_options = {'DEFAULT_CLOSED'}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@classmethod
def poll(cls, context):
return True

def draw(self, context):
layout = self.layout
row = layout.row()
row.template_list(
NTP_UL_CompositorNodeGroup.bl_idname, "",
context.scene, "ntp_compositor_node_group_slots",
context.scene, "ntp_compositor_node_group_slots_index",
rows=1
)

col = row.column(align=True)
col.operator(NTP_OT_AddCompositorNodeGroupSlot.bl_idname,
icon="ADD", text="")
col.operator(NTP_OT_RemoveCompositorNodeGroupSlot.bl_idname,
icon="REMOVE", text="")

classes: list[type] = [
NTP_PG_CompositorNodeGroupSlot,
NTP_OT_AddCompositorNodeGroupSlot,
NTP_OT_RemoveCompositorNodeGroupSlot,
NTP_UL_CompositorNodeGroup,
NTP_PT_CompositorNodeGroup
]
27 changes: 27 additions & 0 deletions NodeToPython/compositor/ui/panel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import bpy

class NTP_PT_Compositor(bpy.types.Panel):
bl_label = "Compositor to Python"
bl_idname = "NTP_PT_compositor"
bl_space_type = 'NODE_EDITOR'
bl_region_type = 'UI'
bl_context = ''
bl_category = "NodeToPython"
bl_options = {'DEFAULT_CLOSED'}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

@classmethod
def poll(cls, context):
return True

def draw_header(self, context):
layout = self.layout

def draw(self, context):
layout = self.layout

classes: list[type] = [
NTP_PT_Compositor
]
Loading