Newer
Older
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
""""Nodes based User interface for shaders exported to POV textures."""
import bpy
from bpy.utils import register_class, unregister_class
from bpy.types import Menu, Node, NodeSocket, CompositorNodeTree, TextureNodeTree, Operator
from bpy.props import (
StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
)
import nodeitems_utils
from nodeitems_utils import NodeCategory, NodeItem
# ---------------------------------------------------------------- #
# ---------------------------------------------------------------- #
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
class PovraySocketUniversal(NodeSocket):
bl_idname = "PovraySocketUniversal"
bl_label = "Povray Socket"
value_unlimited: bpy.props.FloatProperty(default=0.0)
value_0_1: bpy.props.FloatProperty(min=0.0, max=1.0, default=0.0)
value_0_10: bpy.props.FloatProperty(min=0.0, max=10.0, default=0.0)
value_000001_10: bpy.props.FloatProperty(min=0.000001, max=10.0, default=0.0)
value_1_9: bpy.props.IntProperty(min=1, max=9, default=1)
value_0_255: bpy.props.IntProperty(min=0, max=255, default=0)
percent: bpy.props.FloatProperty(min=0.0, max=100.0, default=0.0)
def draw(self, context, layout, node, text):
space = context.space_data
tree = space.edit_tree
links = tree.links
if self.is_linked:
value = []
for link in links:
if link.from_node == node:
inps = link.to_node.inputs
for inp in inps:
if inp.bl_idname == "PovraySocketFloat_0_1" and inp.is_linked:
prop = "value_0_1"
if prop not in value:
value.append(prop)
if inp.bl_idname == "PovraySocketFloat_000001_10" and inp.is_linked:
prop = "value_000001_10"
if prop not in value:
value.append(prop)
if inp.bl_idname == "PovraySocketFloat_0_10" and inp.is_linked:
prop = "value_0_10"
if prop not in value:
value.append(prop)
if inp.bl_idname == "PovraySocketInt_1_9" and inp.is_linked:
prop = "value_1_9"
if prop not in value:
value.append(prop)
if inp.bl_idname == "PovraySocketInt_0_255" and inp.is_linked:
prop = "value_0_255"
if prop not in value:
value.append(prop)
if inp.bl_idname == "PovraySocketFloatUnlimited" and inp.is_linked:
prop = "value_unlimited"
if prop not in value:
value.append(prop)
if len(value) == 1:
layout.prop(self, "%s" % value[0], text=text)
else:
layout.prop(self, "percent", text="Percent")
else:
layout.prop(self, "percent", text=text)
def draw_color(self, context, node):
return (1, 0, 0, 1)
class PovraySocketFloat_0_1(NodeSocket):
bl_idname = "PovraySocketFloat_0_1"
bl_label = "Povray Socket"
default_value: bpy.props.FloatProperty(
description="Input node Value_0_1", min=0, max=1, default=0
)
def draw(self, context, layout, node, text):
if self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "default_value", text=text, slider=True)
def draw_color(self, context, node):
return (0.5, 0.7, 0.7, 1)
class PovraySocketFloat_0_10(NodeSocket):
bl_idname = "PovraySocketFloat_0_10"
bl_label = "Povray Socket"
default_value: bpy.props.FloatProperty(
description="Input node Value_0_10", min=0, max=10, default=0
)
def draw(self, context, layout, node, text):
if node.bl_idname == "ShaderNormalMapNode" and node.inputs[2].is_linked:
layout.label(text="")
self.hide_value = True
if self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "default_value", text=text, slider=True)
def draw_color(self, context, node):
return (0.65, 0.65, 0.65, 1)
class PovraySocketFloat_10(NodeSocket):
bl_idname = "PovraySocketFloat_10"
bl_label = "Povray Socket"
default_value: bpy.props.FloatProperty(
description="Input node Value_10", min=-10, max=10, default=0
)
def draw(self, context, layout, node, text):
if node.bl_idname == "ShaderNormalMapNode" and node.inputs[2].is_linked:
layout.label(text="")
self.hide_value = True
if self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "default_value", text=text, slider=True)
def draw_color(self, context, node):
return (0.65, 0.65, 0.65, 1)
class PovraySocketFloatPositive(NodeSocket):
bl_idname = "PovraySocketFloatPositive"
bl_label = "Povray Socket"
default_value: bpy.props.FloatProperty(
description="Input Node Value Positive", min=0.0, default=0
)
def draw(self, context, layout, node, text):
if self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "default_value", text=text, slider=True)
def draw_color(self, context, node):
return (0.045, 0.005, 0.136, 1)
class PovraySocketFloat_000001_10(NodeSocket):
bl_idname = "PovraySocketFloat_000001_10"
bl_label = "Povray Socket"
default_value: bpy.props.FloatProperty(min=0.000001, max=10, default=0.000001)
def draw(self, context, layout, node, text):
if self.is_output or self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "default_value", text=text, slider=True)
def draw_color(self, context, node):
return (1, 0, 0, 1)
class PovraySocketFloatUnlimited(NodeSocket):
bl_idname = "PovraySocketFloatUnlimited"
bl_label = "Povray Socket"
default_value: bpy.props.FloatProperty(default=0.0)
def draw(self, context, layout, node, text):
if self.is_linked:
layout.label(text=text)
else:
layout.prop(self, "default_value", text=text, slider=True)
def draw_color(self, context, node):
return (0.7, 0.7, 1, 1)
Loading
Loading full blame...