BLEN-350: Fix error with Add shader node #3

Merged
Bogdan Nagirniak merged 5 commits from BLEN-350 into materialx-addon 2023-03-17 14:45:35 +01:00
Showing only changes of commit 2542da4b3e - Show all commits

View File

@ -31,6 +31,10 @@ def enabled(val):
return True
def get_node_type(node):
return node.getType() if isinstance(node, mx.Node) else node.nodedef.getType()
class ShaderNodeBsdfPrincipled(NodeParser):
nodegraph_path = ""
@ -228,29 +232,27 @@ class ShaderNodeMixShader(NodeParser):
return None
if shader2 is None:
mix = self.create_node('mix', shader1.getType().lower(), prefix='PBR', inputs={
mix = self.create_node('mix', get_node_type(shader1).lower(), prefix='PBR', inputs={
'fg': shader1,
'mix': factor
})
if shader1 is None:
mix = self.create_node('mix', shader2.getType().lower(), prefix='PBR', inputs={
mix = self.create_node('mix', get_node_type(shader2).lower(), prefix='PBR', inputs={
'bg': shader2,
'mix': factor
})
if shader1 is not None and shader2 is not None:
shader1_type = shader1.getType().lower()
shader2_type = shader2.getType().lower()
shader1_type = get_node_type(shader1)
shader2_type = get_node_type(shader2)
if shader1_type != shader2_type:
log.warn(f'Types of input shaders must be the same.'
f' First shader type: {shader1_type}, second shader type: {shader2_type}')
return None
mix = self.create_node('mix', shader1_type, prefix='PBR', inputs={
mix = self.create_node('mix', shader1_type.lower(), prefix='PBR', inputs={
'fg': shader1,
'bg': shader2,
'mix': factor
@ -260,7 +262,7 @@ class ShaderNodeMixShader(NodeParser):
return None
result = self.create_node('surface', 'surfaceshader', prefix='PBR', inputs={
'bsdf': mix,
mix.nodedef.getType().lower(): mix,
'opacity': 1.0
})
@ -280,26 +282,25 @@ class ShaderNodeAddShader(NodeParser):
return None
if shader2 is None:
add = self.create_node('add', shader1.getType().lower(), prefix='PBR', inputs={
add = self.create_node('add', get_node_type(shader1).lower(), prefix='PBR', inputs={
'in1': shader1
})
if shader1 is None:
add = self.create_node('add', shader2.getType().lower(), prefix='PBR', inputs={
add = self.create_node('add', get_node_type(shader2).lower(), prefix='PBR', inputs={
'in2': shader2
})
if shader1 is not None and shader2 is not None:
shader1_type = shader1.getType().lower()
shader2_type = shader2.getType().lower()
shader1_type = get_node_type(shader1)
shader2_type = get_node_type(shader2)
if shader1_type != shader2_type:
log.warn(f'Types of input shaders must be the same.'
f' First shader type: {shader1_type}, second shader type: {shader2_type}')
return None
add = self.create_node('add', shader1_type, prefix='PBR', inputs={
add = self.create_node('add', shader1_type.lower(), prefix='PBR', inputs={
'in1': shader1,
'in2': shader2
})