armory/blender/arm/make_compositor.py

61 lines
1.4 KiB
Python
Raw Normal View History

2016-06-22 12:21:15 +02:00
import bpy
from bpy.types import NodeTree, Node, NodeSocket
from bpy.props import *
2017-03-15 12:30:14 +01:00
import arm.nodes as nodes
2016-06-22 12:21:15 +02:00
def parse_defs(node_group):
2017-05-22 20:44:06 +02:00
if node_group == None:
return ''
2016-10-19 13:28:06 +02:00
rn = nodes.get_node_by_type(node_group, 'COMPOSITE')
if rn == None:
return ''
2016-08-15 23:45:03 +02:00
parse_defs.defs = []
2016-10-19 13:28:06 +02:00
build_node(node_group, nodes.get_input_node(node_group, rn, 0))
2016-08-15 23:45:03 +02:00
# To string
s = ''
for d in parse_defs.defs:
s += d
return s
2016-08-15 23:45:03 +02:00
def add_def(s):
# Only push unique
for d in parse_defs.defs:
if d == s:
return
parse_defs.defs.append(s)
2016-08-15 23:45:03 +02:00
def build_node(node_group, node):
2016-12-03 13:27:42 +01:00
if node == None:
return
# Inputs to follow
inps = []
2016-08-15 23:45:03 +02:00
if node.type == 'RGBTOBW':
add_def('_CompoBW')
inps.append(0)
elif node.type == 'TONEMAP':
add_def('_CompoTonemap')
inps.append(0)
elif node.type == 'LENSDIST':
add_def('_CompoFishEye')
inps.append(0)
elif node.type == 'GLARE':
add_def('_CompoGlare')
inps.append(0)
elif node.type == 'ELLIPSEMASK':
add_def('_CompoVignette')
elif node.type == 'MIX_RGB':
inps.append(1)
inps.append(2)
elif node.type == 'BLUR':
inps.append(0)
2016-08-15 23:45:03 +02:00
# Build next stage
for inp in inps:
if node.inputs[inp].is_linked:
2016-10-19 13:28:06 +02:00
next_node = nodes.get_input_node(node_group, node, inp)
build_node(node_group, next_node)