-
-
Save Celeborn2BeAlive/0f76c1c426117812c9563d903ec46540 to your computer and use it in GitHub Desktop.
Basic script for Blender Python nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from bpy.props import IntProperty, FloatProperty, PointerProperty | |
import nodeitems_utils | |
from nodeitems_utils import NodeItem, NodeCategory | |
bl_info = { | |
"name": "Custom nodes", | |
"category": "Node", | |
} | |
class CustomPropertyGroup(bpy.types.PropertyGroup): | |
int_value = IntProperty() | |
float_value = FloatProperty() | |
def draw(self, context, layout): | |
row = layout.row() | |
row.prop(self, "int_value") | |
row = layout.row() | |
row.prop(self, "float_value") | |
class CustomPanel(bpy.types.Panel): | |
bl_idname = "CustomPanel" | |
bl_label = "Custom Panel" | |
bl_space_type = 'PROPERTIES' | |
bl_region_type = 'WINDOW' | |
bl_context = "render" | |
@classmethod | |
def poll(cls, context): | |
return True | |
def draw(self, context): | |
context.scene.custom_properties.draw(context, self.layout) | |
class CustomNodeTree(bpy.types.NodeTree): | |
bl_description = "Custom Node Trees" | |
bl_icon = "MESH_TORUS" | |
bl_idname = "CustomNodeTree" | |
bl_label = "Custom node tree" | |
class CustomNodeSocket(bpy.types.NodeSocket): | |
bl_idname = "CustomNodeSocket" | |
bl_label = "Custom Node Socket" | |
def draw(self, context, layout, node, x): | |
layout.label(self.name) | |
def draw_color(self, context, node): | |
return (1,1,1,1) | |
class CustomNode(bpy.types.Node): | |
bl_idname = "CustomNode" | |
bl_label = "Custom Node" | |
custom_properties = PointerProperty(type=CustomPropertyGroup) | |
def init(self, context): | |
self.inputs.new("CustomNodeSocket", "in") | |
self.outputs.new("CustomNodeSocket", "out") | |
def draw_buttons(self, context, layout): | |
self.custom_properties.draw(context, layout) | |
class CustomNodeCategory(NodeCategory): | |
@classmethod | |
def poll(cls, context): | |
return context.space_data.tree_type == "CustomNodeTree" | |
categories = [ | |
CustomNodeCategory("CUSTOM_CATEGORY", "Category", items = [ | |
NodeItem("CustomNode"), | |
]), | |
] | |
def register(): | |
bpy.utils.register_class(CustomNodeTree) | |
bpy.utils.register_class(CustomNodeSocket) | |
bpy.utils.register_class(CustomPropertyGroup) | |
bpy.utils.register_class(CustomPanel) | |
bpy.utils.register_class(CustomNode) | |
bpy.types.Scene.custom_properties = PointerProperty(type=CustomPropertyGroup) | |
nodeitems_utils.register_node_categories("CUSTOM_CATEGORIES", categories) | |
def unregister(): | |
bpy.utils.unregister_class(CustomNodeTree) | |
bpy.utils.unregister_class(CustomNodeSocket) | |
bpy.utils.unregister_class(CustomPropertyGroup) | |
bpy.utils.unregister_class(CustomPanel) | |
bpy.utils.unregister_class(CustomNode) | |
del bpy.types.Scene.custom_properties | |
nodeitems_utils.unregister_node_categories("CUSTOM_CATEGORIES") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment