self.input = None
checks = [self.check_group,
+ self.check_scale,
self.check_gray,
+ self.check_extract,
self.check_normal,
- self.check_invert_green,
+ self.check_invert_channels,
self.check_additive_blend,
self.check_texture]
for c in checks:
self.data = inner.data
return self.set_input_from_linked(self.node.inputs[0])
+ def check_scale(self):
+ if self.node.type!='MATH':
+ return
+
+ if self.node.operation=='MULTIPLY':
+ for i in range(2):
+ if not self.node.inputs[i].is_linked:
+ self.type = 'SCALE'
+ self.data = self.node.inputs[i].default_value
+ return self.set_input_from_linked(self.node.inputs[1-i])
+
def check_gray(self):
if self.node.type=='RGBTOBW':
self.type = 'GRAY'
self.set_input_from_linked(self.node.inputs["Color"])
+ def check_extract(self):
+ if self.node.type=='SEPRGB':
+ self.type = 'EXTRACT'
+ self.data = self.socket.name[0]
+ return self.set_input_from_linked(self.node.inputs["Image"])
+
def check_normal(self):
if self.node.type=='NORMAL_MAP':
self.type = 'NORMAL'
return self.set_input_from_linked(self.node.inputs["Color"])
- def check_invert_green(self):
+ def check_invert_channels(self):
if self.node.type!='COMBRGB':
return
from .util import get_linked_node_and_socket
- green, _ = get_linked_node_and_socket(self.node_tree, self.node.inputs["G"])
- if not green or green.type!='MATH' or green.operation!='SUBTRACT':
- return
- green, _ = get_linked_node_and_socket(self.node_tree, green.inputs[1])
+ separate = None
+ invert_channels = ""
+ for c in ("R", "G", "B"):
+ from_node, _ = get_linked_node_and_socket(self.node_tree, self.node.inputs[c])
+ if from_node.type=='MATH' and from_node.operation=='SUBTRACT' and not from_node.inputs[0].is_linked and from_node.inputs[0].default_value==1.0:
+ invert_channels += c
+ from_node, _ = get_linked_node_and_socket(self.node_tree, from_node.inputs[1])
- red, _ = get_linked_node_and_socket(self.node_tree, self.node.inputs["R"])
- blue, _ = get_linked_node_and_socket(self.node_tree, self.node.inputs["B"])
- if not red or red.type!='SEPRGB' or blue!=red or green!=red:
- return
+ if from_node.type=='SEPRGB' and (separate is None or from_node==separate):
+ separate = from_node
+ else:
+ return
+
+ self.type = 'INVERT'
+ self.data = invert_channels
- self.type = 'INVERT_GREEN'
- return self.set_input_from_linked(red.inputs["Image"])
+ return self.set_input_from_linked(separate.inputs["Image"])
def check_additive_blend(self):
if self.node.type=='ADD_SHADER':
self.value = value
self.texture = None
self.tex_channels = None
+ self.scale = 1.0
def set_from_input(self, node_tree, input_socket, alpha_socket=None):
if self.keyword:
channels = ['R', 'G', 'B']
elif n.type=='GRAY':
channels = ['Y']
- elif n.type=='INVERT_GREEN':
- channels[1] = '~G'
+ elif n.type=='EXTRACT':
+ channels = [n.data]
+ elif n.type=='INVERT':
+ channels = ['~'+c if c in n.data else c for c in channels]
+ elif n.type=='SCALE':
+ self.scale = n.data
elif n.type=='TEXTURE':
self.texture = n.node
n = n.input
if alpha_from and alpha_from!=self.texture:
raise Exception("Separate textures for color and alpha are not supported")
- if self.texture:
+ if self.scale==0.0 and self.keyword and type(self.value)!=tuple:
+ self.texture = None
+ self.value = self.scale
+ elif self.scale!=1.0:
+ raise Exception("Unsupported material property scale {}".format(self.scale))
+ elif self.texture:
if channels:
self.tex_channels = channels
elif alpha_from: