Skip to content

Commit

Permalink
Register arnold outputs as Sdr output properties #1211 (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienblor authored Jul 27, 2022
1 parent c205a41 commit 83539c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ndr/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ NDR_REGISTER_PARSER_PLUGIN(NdrArnoldParserPlugin);
TF_DEFINE_PRIVATE_TOKENS(_tokens,
(arnold)
((arnoldPrefix, "arnold:"))
((outputsPrefix, "outputs:"))
(binary));
// clang-format on

Expand Down Expand Up @@ -119,8 +120,12 @@ NdrNodeUniquePtr NdrArnoldParserPlugin::Parse(const NdrNodeDiscoveryResult& disc
properties.reserve(props.size());
for (const auto& property : props) {
const auto& propertyName = property.GetName();

// check if this attribute is an output #1121
bool isOutput = TfStringStartsWith(propertyName, _tokens->outputsPrefix);

// In case `info:id` is set on the nodes.
if (TfStringContains(propertyName.GetString(), ":")) {
if (!isOutput && TfStringContains(propertyName.GetString(), ":")) {
continue;
}
const auto propertyStack = property.GetPropertyStack();
Expand All @@ -138,13 +143,14 @@ NdrNodeUniquePtr NdrArnoldParserPlugin::Parse(const NdrNodeDiscoveryResult& disc
propertyName, // name
attr.GetTypeName(), // typeName
v, // defaultValue
false, // isOutput
isOutput, // isOutput
0, // arraySize
NdrTokenMap(), // metadata
NdrTokenMap(), // hints
NdrOptionVec() // options
NdrTokenMap(), // metadata
NdrTokenMap(), // hints
NdrOptionVec() // options
}));
}

return NdrNodeUniquePtr(new SdrShaderNode(
discoveryResult.identifier, // identifier
discoveryResult.version, // version
Expand Down
12 changes: 12 additions & 0 deletions ndr/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ PXR_NAMESPACE_OPEN_SCOPE
// clang-format off
TF_DEFINE_PRIVATE_TOKENS(_tokens,
((filename, "arnold:filename"))
((output, "outputs:out"))

);
// clang-format on

Expand Down Expand Up @@ -339,6 +341,16 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry)
const auto filename = AiNodeEntryGetFilename(nodeEntry);
prim.SetMetadata(_tokens->filename, VtValue(TfToken(filename == nullptr ? "<built-in>" : filename)));


// For shaders, we want to add an attribute for the output type
// FIXME : add support for multiple outputs
if (AiNodeEntryGetType(nodeEntry) == AI_NODE_SHADER) {
const auto* conversion = _GetDefaultValueConversion(AiNodeEntryGetOutputType(nodeEntry));
if (conversion != nullptr) {
prim.CreateAttribute(_tokens->output, conversion->type, false);
}
}

auto paramIter = AiNodeEntryGetParamIterator(nodeEntry);

while (!AiParamIteratorFinished(paramIter)) {
Expand Down

0 comments on commit 83539c8

Please sign in to comment.