Skip to content

Commit

Permalink
Fix so that we don't remove normalmap and tangent inputs if they alre…
Browse files Browse the repository at this point in the history
…ady exist when adding default inputs. (#12)
  • Loading branch information
kwokcb committed Dec 6, 2023
1 parent ab1afe0 commit ab695ad
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/materialxgltf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1952,15 +1952,23 @@ def materialX2glTF(self, doc, gltfJson, resetMaterials):
path = shaderNode.getNamePath()
if category == MTLX_GLTF_PBR_CATEGORY and path not in pbrNodes:
if addInputsFromNodeDef:
hasNormal = shaderNode.getInput('normal')
hasTangent = shaderNode.getInput('tangent')
shaderNode.addInputsFromNodeDef()
shaderNode.removeChild('tangent')
shaderNode.removeChild('normal')
if not hasNormal:
shaderNode.removeChild('tangent')
if not hasTangent:
shaderNode.removeChild('normal')
pbrNodes[path] = shaderNode
elif category == MTLX_UNLIT_CATEGORY_STRING and path not in unlitNodes:
if addInputsFromNodeDef:
hasNormal = shaderNode.getInput('normal')
hasTangent = shaderNode.getInput('tangent')
shaderNode.addInputsFromNodeDef()
shaderNode.removeChild('tangent')
shaderNode.removeChild('normal')
if not hasNormal:
shaderNode.removeChild('tangent')
if not hasTangent:
shaderNode.removeChild('normal')
unlitNodes[path] = shaderNode

materials_count = len(pbrNodes) + len(unlitNodes)
Expand Down Expand Up @@ -2349,7 +2357,7 @@ def materialX2glTF(self, doc, gltfJson, resetMaterials):
if imageNode:
fileInput = imageNode.getInput(mx.Implementation.FILE_ATTRIBUTE)
filename = EMPTY_STRING
if fileInput and fileInput.getAttribute(mx.TypedElement.TYPE_ATTRIBUTE) == mx.FILENAME_TYPE_STRING:
if fileInput and fileInput.getAttribute(mx.TypedElement.TYPE_ATTRIBUTE) == mx.FILENAME_TYPE_STRING:
filename = fileInput.getResolvedValueString()
if len(filename) == 0:
imageNode = None
Expand Down

0 comments on commit ab695ad

Please sign in to comment.