Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flattening produces invalid document #2117

Open
pablode opened this issue Nov 17, 2024 · 0 comments
Open

Flattening produces invalid document #2117

pablode opened this issue Nov 17, 2024 · 0 comments

Comments

@pablode
Copy link
Contributor

pablode commented Nov 17, 2024

I'm running into an issue where when I flatten following document

Show code
<?xml version="1.0"?>
<materialx version="1.38" xmlns:xi="http://www.w3.org/2001/XInclude">
  <UsdPreviewSurface name="Surface" type="surfaceshader">
    <input name="diffuseColor" type="color3" output="diffuseColor_rgb" nodegraph="prismarine2" colorspace="srgb_texture" />
    <input name="normal" type="vector3" output="normal_out" nodegraph="prismarine2" />
    <input name="roughness" type="float" output="roughness_r" nodegraph="prismarine2" colorspace="lin_rec709" />
    <input name="metallic" type="float" value="0" />
    <input name="opacity" type="float" value="1" />
    <input name="useSpecularWorkflow" type="integer" value="0" />
  </UsdPreviewSurface>
  <surfacematerial name="prismarine" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="Surface" />
  </surfacematerial>
  <nodegraph name="prismarine2">
    <UsdUVTexture name="DiffuseTexture" type="multioutput" nodedef="ND_UsdUVTexture">
      <input name="file" type="filename" value="/Users/pablode/Work/usd-wg-assets/full_assets/McUsd/McUsd_materials/tex/prismarine.png" />
      <input name="wrapS" type="string" value="periodic" />
      <input name="wrapT" type="string" value="periodic" />
      <input name="st" type="vector2" nodename="UVReader" />
    </UsdUVTexture>
    <UsdPrimvarReader name="UVReader" type="vector2" nodedef="ND_UsdPrimvarReader_vector2">
      <input name="fallback" type="vector2" value="0, 0" />
      <input name="varname" type="string" value="st" />
    </UsdPrimvarReader>
    <output name="diffuseColor_rgb" type="color3" output="rgb" nodename="DiffuseTexture" />
    <convert name="convert0" type="vector3" nodedef="ND_convert_color3_vector3">
      <input name="in" type="color3" output="rgb" nodename="NormalTexture" colorspace="lin_rec709" />
    </convert>
    <UsdUVTexture name="NormalTexture" type="multioutput" nodedef="ND_UsdUVTexture">
      <input name="bias" type="color4" value="-1, -1, -1, 0" />
      <input name="file" type="filename" value="/Users/pablode/Work/usd-wg-assets/full_assets/McUsd/McUsd_materials/tex/prismarine_n.png" />
      <input name="scale" type="color4" value="2, 2, 2, 1" />
      <input name="wrapS" type="string" value="periodic" />
      <input name="wrapT" type="string" value="periodic" />
      <input name="st" type="vector2" nodename="UVReader" />
    </UsdUVTexture>
    <output name="normal_out" type="vector3" nodename="convert0" />
    <UsdUVTexture name="RoughnessTexture" type="multioutput" nodedef="ND_UsdUVTexture">
      <input name="file" type="filename" value="/Users/pablode/Work/usd-wg-assets/full_assets/McUsd/McUsd_materials/tex/prismarine_r.png" />
      <input name="wrapS" type="string" value="periodic" />
      <input name="wrapT" type="string" value="periodic" />
      <input name="st" type="vector2" nodename="UVReader" />
    </UsdUVTexture>
    <output name="roughness_r" type="float" output="r" nodename="RoughnessTexture" />
  </nodegraph>
</materialx>

using this code

for (mx::NodeGraphPtr graph : doc->getNodeGraphs())
{
    if (graph->getActiveSourceUri() == doc->getSourceUri())
    {
        graph->flattenSubgraphs();
    }
}

an invalid document is produced:

Show code
<?xml version="1.0"?>
<materialx version="1.38" xmlns:xi="http://www.w3.org/2001/XInclude">
  <UsdPreviewSurface name="Surface" type="surfaceshader">
    <input name="diffuseColor" type="color3" output="diffuseColor_rgb" nodegraph="prismarine2" colorspace="srgb_texture" />
    <input name="normal" type="vector3" output="normal_out" nodegraph="prismarine2" />
    <input name="roughness" type="float" output="roughness_r" nodegraph="prismarine2" colorspace="lin_rec709" />
    <input name="metallic" type="float" value="0" />
    <input name="opacity" type="float" value="1" />
    <input name="useSpecularWorkflow" type="integer" value="0" />
  </UsdPreviewSurface>
  <surfacematerial name="prismarine" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="Surface" />
  </surfacematerial>
  <nodegraph name="prismarine2">
    <image name="image_reader" type="color4">
      <input name="file" type="filename" value="/Users/pablode/Work/usd-wg-assets/full_assets/McUsd/McUsd_materials/tex/prismarine.png" />
      <input name="default" type="color4" value="0, 0, 0, 1" />
      <input name="texcoord" type="vector2" nodename="UVReader" />
      <input name="uaddressmode" type="string" value="periodic" />
      <input name="vaddressmode" type="string" value="periodic" />
    </image>
    <multiply name="image_scale" type="color4">
      <input name="in1" type="color4" nodename="image_reader" />
      <input name="in2" type="color4" value="1, 1, 1, 1" />
    </multiply>
    <add name="image_bias" type="color4">
      <input name="in1" type="color4" nodename="image_scale" />
      <input name="in2" type="color4" value="0, 0, 0, 0" />
    </add>
    <geompropvalue name="primvar" type="vector2">
      <input name="geomprop" type="string" value="st" />
      <input name="default" type="vector2" value="0, 0" />
    </geompropvalue>
    <output name="diffuseColor_rgb" type="color3" output="" nodename="image_bias" />
    <convert name="convert0" type="vector3" nodedef="ND_convert_color3_vector3">
      <input name="in" type="color3" output="" nodename="image_bias2" colorspace="lin_rec709" />
    </convert>
    <image name="image_reader2" type="color4">
      <input name="file" type="filename" value="/Users/pablode/Work/usd-wg-assets/full_assets/McUsd/McUsd_materials/tex/prismarine_n.png" />
      <input name="default" type="color4" value="0, 0, 0, 1" />
      <input name="texcoord" type="vector2" nodename="primvar" />
      <input name="uaddressmode" type="string" value="periodic" />
      <input name="vaddressmode" type="string" value="periodic" />
    </image>
    <multiply name="image_scale2" type="color4">
      <input name="in1" type="color4" nodename="image_reader2" />
      <input name="in2" type="color4" value="2, 2, 2, 1" />
    </multiply>
    <add name="image_bias2" type="color4">
      <input name="in1" type="color4" nodename="image_scale2" />
      <input name="in2" type="color4" value="-1, -1, -1, 0" />
    </add>
    <output name="normal_out" type="vector3" nodename="convert0" />
    <image name="image_reader3" type="color4">
      <input name="file" type="filename" value="/Users/pablode/Work/usd-wg-assets/full_assets/McUsd/McUsd_materials/tex/prismarine_r.png" />
      <input name="default" type="color4" value="0, 0, 0, 1" />
      <input name="texcoord" type="vector2" nodename="primvar" />
      <input name="uaddressmode" type="string" value="periodic" />
      <input name="vaddressmode" type="string" value="periodic" />
    </image>
    <multiply name="image_scale3" type="color4">
      <input name="in1" type="color4" nodename="image_reader3" />
      <input name="in2" type="color4" value="1, 1, 1, 1" />
    </multiply>
    <add name="image_bias3" type="color4">
      <input name="in1" type="color4" nodename="image_scale3" />
      <input name="in2" type="color4" value="0, 0, 0, 0" />
    </add>
    <output name="roughness_r" type="float" output="" nodename="image_bias3" />
  </nodegraph>
</materialx>

The issue here is that the image_reader node still references a UVReader node which does not exist anymore, unlike the other two image nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant