yield int(pixels[i+1]*255)
yield int(pixels[i+2]*255)
+def pixels_to_rgb_invert_green(pixels):
+ for i in range(0, len(pixels), 4):
+ yield int(pixels[i]*255)
+ yield 255-int(pixels[i+1]*255)
+ yield int(pixels[i+2]*255)
+
def pixels_to_gray(pixels):
for i in range(0, len(pixels), 4):
yield int((pixels[i]+pixels[i+1]+pixels[i+2])*255/3)
def __init__(self):
self.inline_data = True
- def export_texture(self, tex_node, usage='RGB'):
+ def export_texture(self, tex_node, usage='RGB', *, invert_green=False):
image = tex_node.image
from .datafile import Resource, Statement, Token
tex_res = Resource(image.name+".tex2d", "texture2d")
from .util import basename
fn = basename(image.filepath)
- if not self.inline_data and fn:
+ if not self.inline_data and not invert_green and fn:
srgb = "_srgb" if colorspace=='sRGB' else ""
tex_res.statements.append(Statement("external_image"+srgb, fn))
else:
texdata = encode_pixels(pixels_to_rgba(pixels))
elif usage=='GRAY':
texdata = encode_pixels(pixels_to_gray(pixels))
+ elif invert_green:
+ texdata = encode_pixels(pixels_to_rgb_invert_green(pixels))
else:
texdata = encode_pixels(pixels_to_rgb(pixels))
tex_res.statements.append(Statement("raw_data", texdata))
return (l.to_node, l.to_socket)
return (None, None)
+def check_group(node_tree, group, func):
+ output = group.node_tree.nodes["Group Output"]
+ from_node, _ = get_linked_node_and_socket(group.node_tree, output.inputs[0])
+ if from_node:
+ from_node, _ = func(group.node_tree, from_node)
+ if from_node and from_node.type=='GROUP_INPUT':
+ return get_linked_node_and_socket(node_tree, group.inputs[0])
+ return (None, None)
+
+def check_invert_green(node_tree, node):
+ if node.type=='GROUP':
+ return check_group(node_tree, node, check_invert_green)
+ elif node.type!='COMBRGB':
+ return (None, None)
+
+ green, g_sock = get_linked_node_and_socket(node_tree, node.inputs["G"])
+ if not green or green.type!='MATH' or green.operation!='SUBTRACT':
+ return (None, None)
+ green, g_sock = get_linked_node_and_socket(node_tree, green.inputs[1])
+
+ red, r_sock = get_linked_node_and_socket(node_tree, node.inputs["R"])
+ blue, b_sock = get_linked_node_and_socket(node_tree, node.inputs["B"])
+ if not red or red.type!='SEPRGB' or blue!=red or green!=red:
+ return (None, None)
+
+ return get_linked_node_and_socket(node_tree, red.inputs["Image"])
+
class MaterialProperty:
def __init__(self, keyword, tex_keyword, value):
self.keyword = keyword
self.value = value
self.texture = None
self.tex_usage = None
+ self.invert_green = False
def set_from_input(self, node_tree, input_socket, alpha_socket=None):
if self.keyword:
usage = None
if from_node.type=='NORMAL_MAP':
from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"])
+ invert, _ = check_invert_green(node_tree, from_node)
+ if invert:
+ from_node = invert
+ self.invert_green = True
usage = 'RGB'
elif from_node.type=='RGBTOBW':
from_node, _ = get_linked_node_and_socket(node_tree, from_node.inputs["Color"])