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

Write non-connected uvSet names #3339

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
#include <string>
#include <utility>

// Certain applications do not currently support reading
// TexCoord names via connections, and instead expect a default value.
TF_DEFINE_ENV_SETTING(
MAYAUSD_PROVIDE_DEFAULT_TEXCOORD_PRIMVAR_NAME,
false,
"Add a default value for texcoord names in addition to connections");

PXR_NAMESPACE_OPEN_SCOPE

// clang-format off
Expand Down Expand Up @@ -649,6 +656,47 @@ class _UVMappingManager
}
_uvNamesToMaterial[largestSet] = material;
}

if (TfGetEnvSetting(MAYAUSD_PROVIDE_DEFAULT_TEXCOORD_PRIMVAR_NAME)) {
// We'll traverse the material prims children and look for items
// with connections, and use that to set the value
TfToken readerType { "UsdPrimvarReader_float2" };
TfToken shaderID;

UsdShadeConnectableAPI source;
TfToken sourceInputName;
UsdShadeAttributeType sourceType;
VtValue varnameValue;
auto materialPrim = material.GetPrim();
for (const auto child : materialPrim.GetDescendants()) {
if (!child.IsA<UsdShadeShader>()) {
continue;
}

auto shader = UsdShadeShader(child);
if (shader.GetShaderId(&shaderID) && shaderID != readerType) {
continue;
}

auto varnameInput = shader.GetInput(TfToken("varname"));
if (!varnameInput) {
continue;
}

if (!UsdShadeConnectableAPI::GetConnectedSource(
varnameInput, &source, &sourceInputName, &sourceType)) {
continue;
}

auto targetVarname = material.GetInput(sourceInputName);
if (!targetVarname) {
continue;
}

targetVarname.Get(&varnameValue);
varnameInput.Set(varnameValue);
}
}
}

const UsdShadeMaterial& getMaterial(const TfToken& shapeName)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading