forked from taichi-dev/taichi_elements
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sockets.py
134 lines (93 loc) · 3.55 KB
/
sockets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import bpy
socket_colors = {
'NUMBER': (0.3, 0.3, 0.3, 1.0),
'STRUCT': (0.0, 1.0, 0.0, 1.0),
'ADD': (0.0, 0.0, 0.0, 0.25),
'STRING': (1.0, 0.5, 0.0, 1.0)
}
class ElementsBaseSocket(bpy.types.NodeSocket):
bl_idname = 'elements_base_socket'
split_factor = 0.6
def get_value(self):
if not self.is_output and len(self.links):
from_socket = self.links[0].from_socket
if from_socket.bl_idname == self.bl_idname:
if hasattr(from_socket, 'get_value'):
return from_socket.get_value()
else:
return self.value
else:
return self.value
def draw(self, context, layout, node, text):
if not len(self.links) or self.is_output:
if self.text:
row = layout.split(factor=self.split_factor)
row.label(text=self.text)
row.prop(self, 'value', text='')
else:
row = layout.split(factor=1.0)
row.prop(self, 'value', text='')
else:
layout.label(text=self.text)
class ElementsIntegerSocket(ElementsBaseSocket):
bl_idname = 'elements_integer_socket'
value: bpy.props.IntProperty(default=0)
text: bpy.props.StringProperty(default='Integer')
def draw_color(self, context, node):
return socket_colors['NUMBER']
class ElementsFloatSocket(ElementsBaseSocket):
bl_idname = 'elements_float_socket'
value: bpy.props.FloatProperty(default=0.0)
text: bpy.props.StringProperty(default='Float')
def draw_color(self, context, node):
return socket_colors['NUMBER']
class Elements3dVectorFloatSocket(ElementsBaseSocket):
bl_idname = 'elements_3d_vector_float_socket'
value: bpy.props.FloatVectorProperty(default=(0.0, 0.0, 0.0), size=3)
text: bpy.props.StringProperty(default='Float')
def draw_color(self, context, node):
return socket_colors['NUMBER']
class ElementsStructSocket(ElementsBaseSocket):
bl_idname = 'elements_struct_socket'
text: bpy.props.StringProperty(default='Value')
def get_value(self):
if not self.is_output and len(self.links):
from_socket = self.links[0].from_socket
if from_socket.bl_idname == self.bl_idname:
return self.links[0].from_node.get_class()
else:
return None
else:
return None
def draw_color(self, context, node):
return socket_colors['STRUCT']
def draw(self, context, layout, node, text):
layout.label(text=self.text)
class ElementsAddSocket(bpy.types.NodeSocket):
bl_idname = 'elements_add_socket'
text: bpy.props.StringProperty(default='')
def draw_color(self, context, node):
return socket_colors['ADD']
def draw(self, context, layout, node, text):
layout.label(text=self.text)
class ElementsFolderSocket(ElementsBaseSocket):
bl_idname = 'elements_folder_socket'
value: bpy.props.StringProperty(subtype='DIR_PATH')
text: bpy.props.StringProperty(default='Folder')
split_factor = 0.3
def draw_color(self, context, node):
return socket_colors['STRING']
socket_classes = [
ElementsIntegerSocket,
ElementsFloatSocket,
Elements3dVectorFloatSocket,
ElementsStructSocket,
ElementsAddSocket,
ElementsFolderSocket
]
def register():
for socket_class in socket_classes:
bpy.utils.register_class(socket_class)
def unregister():
for socket_class in reversed(socket_classes):
bpy.utils.unregister_class(socket_class)