Skip to content

Commit

Permalink
blender: Implement more node graph conversion scaffolding
Browse files Browse the repository at this point in the history
Parsing a few nodes correctly already! :^)
  • Loading branch information
vkoskiv committed Dec 16, 2023
1 parent 00ced9c commit 8bdb1c3
Showing 1 changed file with 53 additions and 13 deletions.
66 changes: 53 additions & 13 deletions bindings/nodes/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,68 @@ def parse_color(input):
vals = input.default_value
print("foobar {}".format(vals))
return NodeColorConstant(cr_color(vals[0], vals[1], vals[2], vals[3]))
case 'ShaderNodeTexImage':
return warning_color
case 'ShaderNodeTexChecker':
return warning_color
case 'ShaderNodeBlackbody':
return warning_color
case 'ShaderNodeCombineRGB':
return warning_color
case 'ShaderNodeCombineHSL':
return warning_color
# case 'ShaderNodeTexImage':
# return warning_color
# case 'ShaderNodeTexChecker':
# return warning_color
# case 'ShaderNodeBlackbody':
# return warning_color
# case 'ShaderNodeCombineRGB':
# return warning_color
# case 'ShaderNodeCombineHSL':
# return warning_color
# vec_to_color is implicit in blender nodes
case 'ShaderNodeTexGradient':
# case 'ShaderNodeTexGradient':
# return warning_color
case _:
print("Unknown color node of type {}, maybe fix.".format(input.bl_idname))
return warning_color

def parse_value(input):
match input.bl_idname:
case 'NodeSocketFloat':
if input.is_linked:
return parse_value(input.links[0].from_node)
return NodeValueConstant(input.default_value)
case 'NodeSocketFloatFactor':
# note: same as Float, but range is [0,1]
if input.is_linked:
return parse_value(input.links[0].from_node)
return NodeValueConstant(input.default_value)
case _:
print("Unknown value node of type {}, maybe fix.".format(input.bl_idname))

def parse_vector(input):
match input.bl_idname:
case 'NodeSocketVector':
if input.is_linked:
return parse_vector(input.links[0].from_node)
vec = input.default_value
return NodeVectorConstant(cr_vector(vec[0], vec[1], vec[2]))
case _:
print("Unknown vector node of type {}, maybe fix.".format(input.bl_idname))

warning_shader = NodeShaderDiffuse(warning_color)

def parse_node(input):
match input.type:
case 'BSDF_DIFFUSE':
match input.bl_idname:
case 'ShaderNodeBsdfDiffuse':
color = parse_color(input.inputs['Color'])
return NodeShaderDiffuse(color) # note: missing roughness + normal
case 'ShaderNodeBsdfGlass':
color = parse_color(input.inputs['Color'])
rough = parse_value(input.inputs['Roughness'])
ior = parse_value(input.inputs['IOR'])
# note: skipping normal
return NodeShaderGlass(color, rough, ior)
case 'ShaderNodeBsdfTransparent':
color = parse_color(input.inputs['Color'])
return NodeShaderTransparent(color)
case 'ShaderNodeBsdfTranslucent':
color = parse_color(input.inputs['Color'])
return NodeShaderTranslucent(color)
case _:
print("Unknown shader node of type {}, maybe fix.".format(input.bl_idname))
return warning_shader


Expand Down

0 comments on commit 8bdb1c3

Please sign in to comment.