From d575886090bfa15443683263d6c698f002703e78 Mon Sep 17 00:00:00 2001 From: "ADS\\blaines" Date: Mon, 14 Nov 2022 18:00:17 +0100 Subject: [PATCH 1/3] Declare metadatas in Sdr registry #55 --- common/constant_strings.h | 6 ++ ndr/parser.cpp | 169 ++++++++++++++++++++++++++++++++------ ndr/utils.cpp | 132 +++++++++++++++++++++++++++-- 3 files changed, 274 insertions(+), 33 deletions(-) diff --git a/common/constant_strings.h b/common/constant_strings.h index a23121d0dc..c5cda7d660 100644 --- a/common/constant_strings.h +++ b/common/constant_strings.h @@ -83,6 +83,7 @@ ASTR2(renderPassPrimIdReader, "HdArnoldRenderPass_prim_id_reader"); ASTR2(renderPassPrimIdWriter, "HdArnoldRenderPass_prim_id_writer"); ASTR2(render_context, "RENDER_CONTEXT"); ASTR2(sidedness_prefix, "sidedness:"); +ASTR2(ui_groups, "ui.groups"); ASTR2(visibility_prefix, "visibility:"); ASTR(AA_sample_clamp); @@ -101,6 +102,7 @@ ASTR(crypto_asset); ASTR(crypto_material); ASTR(crypto_object); ASTR(custom_attributes); +ASTR(desc); ASTR(FLOAT); ASTR(GI_diffuse_depth); ASTR(GI_diffuse_samples); @@ -298,6 +300,7 @@ ASTR(interactive_fps_min); ASTR(interactive_target_fps); ASTR(interactive_target_fps_min); ASTR(ior); +ASTR(label); ASTR(latlong); ASTR(layer_enable_filtering); ASTR(layer_half_precision); @@ -306,6 +309,7 @@ ASTR(light_filter); ASTR(light_group); ASTR(light_path_expressions); ASTR(linear); +ASTR(linkable); ASTR(log_flags_console); ASTR(log_flags_file); ASTR(mask); @@ -399,6 +403,8 @@ ASTR(shutter_start); ASTR(sidedness); ASTR(skydome_light); ASTR(smoothing); +ASTR(softmax); +ASTR(softmin); ASTR(specular); ASTR(specularColor); ASTR(specular_IOR); diff --git a/ndr/parser.cpp b/ndr/parser.cpp index fc1e42ff3b..a624768239 100644 --- a/ndr/parser.cpp +++ b/ndr/parser.cpp @@ -56,6 +56,12 @@ TF_DEFINE_PRIVATE_TOKENS(_tokens, (arnold) ((arnoldPrefix, "arnold:")) ((outputsPrefix, "outputs:")) + ((uigroups, "ui:groups")) + (uimin) + (uimax) + (uisoftmin) + (uisoftmax) + (enumValues) (binary)); // clang-format on @@ -99,6 +105,85 @@ NdrArnoldParserPlugin::NdrArnoldParserPlugin() {} NdrArnoldParserPlugin::~NdrArnoldParserPlugin() {} + +void _ReadShaderAttribute(const UsdAttribute &attr, NdrPropertyUniquePtrVec &properties, const std::string &folder) +{ + const TfToken& attrName = attr.GetName(); + const std::string& attrNameStr = attrName.GetString(); + + // check if this attribute is an output #1121 + bool isOutput = TfStringStartsWith(attrName, _tokens->outputsPrefix); + if (!isOutput && TfStringContains(attrNameStr, ":")) { + // In case `info:id` is set on the nodes. + return; + } + + VtValue v; + attr.Get(&v); + // The utility function takes care of the conversion and figuring out + // parameter types, so we just have to blindly pass all required + // parameters. + VtDictionary customData = attr.GetCustomData(); + NdrTokenMap metadata; + NdrTokenMap hints; + + // For enum attributres, all enum fields should be set as "options" + // to this attribute + NdrOptionVec options; + auto it = customData.find(_tokens->enumValues); + if (it != customData.end()) { + VtStringArray enumValues = it->second.Get(); + for (const auto &enumValue : enumValues) { + TfToken enumValTf(enumValue.c_str()); + options.emplace_back(enumValTf, enumValTf); + } + } + + // USD supports a builtin list of metadatas. Only these ones + // need to be declared in the "metadata" section. + static const auto supportedMetadatas = { + SdrPropertyMetadata->Page, + SdrPropertyMetadata->Connectable, + SdrPropertyMetadata->Label, + SdrPropertyMetadata->Help + }; + + if (!folder.empty()) { + metadata.insert({SdrPropertyMetadata->Page, folder}); + } + for (const auto &m : supportedMetadatas) { + const auto it = customData.find(m); + if (it != customData.end()) + metadata.insert({m, TfStringify(it->second)}); + } + + // For metadatas that aren't USD builtins, we need to set + // them as "hints", otherwise USD will complain + static const auto supportedHints = { + _tokens->uimin, + _tokens->uimax, + _tokens->uisoftmin, + _tokens->uisoftmax + }; + + for (const auto &h : supportedHints) { + const auto it = customData.find(h); + if (it != customData.end()) + hints.insert({h, TfStringify(it->second)}); + } + + properties.emplace_back(SdrShaderPropertyUniquePtr(new ArnoldShaderProperty{ + isOutput ? attr.GetBaseName() : attr.GetName(), // name + attr.GetTypeName(), // typeName + v, // defaultValue + isOutput, // isOutput + 0, // arraySize + metadata, // metadata + hints, // hints + options // options + })); +} + NdrNodeUniquePtr NdrArnoldParserPlugin::Parse(const NdrNodeDiscoveryResult& discoveryResult) { auto shaderDefs = NdrArnoldGetShaderDefs(); @@ -118,39 +203,75 @@ NdrNodeUniquePtr NdrArnoldParserPlugin::Parse(const NdrNodeDiscoveryResult& disc NdrPropertyUniquePtrVec properties; const auto props = prim.GetAuthoredProperties(); properties.reserve(props.size()); + + VtDictionary primCustomData = prim.GetCustomData(); + // keep track of which attributes were declared, to avoid + // doing it twice for the same parameter + std::unordered_set declaredAttributes; + + // If this node entry has a metadata ui.groups, we use it to determine + // the UI grouping and ordering. We will expect it to be defined as e.g. : + // "Base: base base_color metalness, Specular: specular specular_color" + if (primCustomData.find(_tokens->uigroups) != primCustomData.end()) { + VtValue groupsVal = primCustomData[_tokens->uigroups]; + // Get ui.groups metadata as a string + std::string uigroupsStr = groupsVal.Get(); + if (!uigroupsStr.empty()) { + // First, split for each group, with the "," separator + const auto uigroupList = TfStringSplit(uigroupsStr, ","); + for (const auto& uigroupElem : uigroupList) { + if (uigroupElem.empty()) + continue; + // The first part before ":" represents the group UI label, + // the second contains the ordered list of attributes included + // in this group + const auto uigroupSplit = TfStringSplit(uigroupElem, ":"); + // If no ":" separator is found, we use this to set the attribute ordering + // but no label is set. + std::string folder = (uigroupSplit.size() > 1) ? uigroupSplit[0] : ""; + std::string uigroupAttrs = uigroupSplit.back(); + + // The list of attributes for a given group is separated by spaces + const auto &uigroupAttrList = TfStringSplit(uigroupAttrs, " "); + for (const auto& uigroupAttr : uigroupAttrList) { + if (uigroupAttr.empty()) + continue; + + // if this attribute was previously declared, skip it + if (declaredAttributes.find(uigroupAttr) != declaredAttributes.end()) + continue; + + // Add this attribute to the properties list + declaredAttributes.insert(uigroupAttr); + UsdAttribute attr = prim.GetAttribute(TfToken(uigroupAttr.c_str())); + if (attr) { + _ReadShaderAttribute(attr, properties, folder); + } + } + } + } + } + + // Now loop over all usd properties that were declared, and add + // the ones that weren't added previously with ui.groups for (const UsdProperty& property : props) { const TfToken& propertyName = property.GetName(); const std::string& propertyNameStr = propertyName.GetString(); - TfToken outputName; - // check if this attribute is an output #1121 - bool isOutput = TfStringStartsWith(propertyName, _tokens->outputsPrefix); - - if (!isOutput && TfStringContains(propertyNameStr, ":")) { - // In case `info:id` is set on the nodes. - continue; - } const auto propertyStack = property.GetPropertyStack(); if (propertyStack.empty()) { continue; } + const auto attr = prim.GetAttribute(propertyName); - VtValue v; - attr.Get(&v); - // The utility function takes care of the conversion and figuring out - // parameter types, so we just have to blindly pass all required - // parameters. - // TODO(pal): Read metadata and hints. - properties.emplace_back(SdrShaderPropertyUniquePtr(new ArnoldShaderProperty{ - isOutput ? property.GetBaseName() : propertyName, // name - attr.GetTypeName(), // typeName - v, // defaultValue - isOutput, // isOutput - 0, // arraySize - NdrTokenMap(), // metadata - NdrTokenMap(), // hints - NdrOptionVec() // options - })); + // If this attribute was already declared in the above code + // for ui.groups, we don't want to declare it again + if (declaredAttributes.find(propertyNameStr) != declaredAttributes.end()) + continue; + + declaredAttributes.insert(propertyNameStr); + _ReadShaderAttribute(attr, properties, ""); + } return NdrNodeUniquePtr(new SdrShaderNode( diff --git a/ndr/utils.cpp b/ndr/utils.cpp index 6865531b83..bb136133a7 100644 --- a/ndr/utils.cpp +++ b/ndr/utils.cpp @@ -33,11 +33,12 @@ #include #include +#include #include "../arnold_usd.h" #include - +#include #include #if ARNOLD_VERSION_NUMBER > 60201 @@ -51,7 +52,12 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_PRIVATE_TOKENS(_tokens, ((filename, "arnold:filename")) ((output, "outputs:out")) - + ((uigroups, "ui:groups")) + (uimin) + (uimax) + (uisoftmin) + (uisoftmax) + (enumValues) ); // clang-format on @@ -333,7 +339,6 @@ const ArrayConversion* _GetArrayConversion(uint8_t type) } } -// TODO(pal): Read in metadata // TODO(pal): We could also setup a metadata to store the raw arnold type, // for cases where multiple arnold types map to a single sdf type. void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) @@ -341,6 +346,14 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) const auto filename = AiNodeEntryGetFilename(nodeEntry); prim.SetMetadata(_tokens->filename, VtValue(TfToken(filename == nullptr ? "" : filename))); + VtDictionary primCustomData; + AtString uigroups; + // Check if the Arnold node entry has a metadata ui.groups, to determine + // the grouping and order of attributes in the UI. + if (AiMetaDataGetStr(nodeEntry, AtString(), str::ui_groups, &uigroups)) + primCustomData[_tokens->uigroups] = std::string(uigroups.c_str()); + + prim.SetCustomData(primCustomData); // For shaders, we want to add an attribute for the output type // FIXME : add support for multiple outputs @@ -354,11 +367,14 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) prim.CreateAttribute(_tokens->output, SdfValueTypeNames->String, false); } auto paramIter = AiNodeEntryGetParamIterator(nodeEntry); - + while (!AiParamIteratorFinished(paramIter)) { const auto* pentry = AiParamIteratorGetNext(paramIter); const auto paramType = AiParamGetType(pentry); - + const AtString paramName = AiParamGetName(pentry); + UsdAttribute attr; + VtDictionary customData; + if (paramType == AI_TYPE_ARRAY) { const auto* defaultValue = AiParamGetDefault(pentry); if (defaultValue == nullptr) { @@ -373,7 +389,7 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) if (conversion == nullptr) { continue; } - auto attr = prim.CreateAttribute(TfToken(AiParamGetName(pentry).c_str()), conversion->type, false); + attr = prim.CreateAttribute(TfToken(paramName.c_str()), conversion->type, false); if (conversion->f != nullptr) { attr.Set(conversion->f(array)); @@ -383,14 +399,113 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) if (conversion == nullptr) { continue; } - auto attr = prim.CreateAttribute(TfToken(AiParamGetName(pentry).c_str()), conversion->type, false); + attr = prim.CreateAttribute(TfToken(paramName.c_str()), conversion->type, false); if (conversion->f != nullptr) { attr.Set(conversion->f(*AiParamGetDefault(pentry), pentry)); } } - } + // For enum attributes, get all the allowed enum values and + // set them as customData through the metadata "enumValues" + if (paramType == AI_TYPE_ENUM) { + VtStringArray enumValues; + for (int ei=0 ;; ei++) + { + const char* enumStr = AiEnumGetString(AiParamGetEnum(pentry), ei); + if (!enumStr) + break; + enumValues.push_back(enumStr); + } + customData[_tokens->enumValues] = enumValues; + } + + bool foundLabel = false; + // Get all metadatas for this attribute + AtMetaDataIterator* metadataIter = AiNodeEntryGetMetaDataIterator(nodeEntry, paramName); + while(!AiMetaDataIteratorFinished(metadataIter)) { + const AtMetaDataEntry* metadata = AiMetaDataIteratorGetNext(metadataIter); + if (!metadata) + continue; + + TfToken usdMetadata; + // For now we only support a hardcoded list of metadatas + if (metadata->name == str::linkable) + usdMetadata = SdrPropertyMetadata->Connectable; + else if (metadata->name == str::_min) + usdMetadata = _tokens->uimin; + else if (metadata->name == str::_max) + usdMetadata = _tokens->uimax; + else if (metadata->name == str::softmin) + usdMetadata = _tokens->uisoftmin; + else if (metadata->name == str::softmax) + usdMetadata = _tokens->uisoftmax; + else if (metadata->name == str::label) { + usdMetadata = SdrPropertyMetadata->Label; + foundLabel = true; + } else if (metadata->name == str::desc) + usdMetadata = SdrPropertyMetadata->Help; + else + continue; + + // Get the metadata value + VtValue metadataValue; + switch(metadata->type) { + case AI_TYPE_INT: + customData[usdMetadata] = metadata->value.INT(); + break; + case AI_TYPE_BYTE: + customData[usdMetadata] = metadata->value.BYTE(); + break; + case AI_TYPE_UINT: + customData[usdMetadata] = metadata->value.UINT(); + break; + case AI_TYPE_BOOLEAN: + customData[usdMetadata] = metadata->value.BOOL(); + break; + case AI_TYPE_FLOAT: + customData[usdMetadata] = metadata->value.FLT(); + break; + case AI_TYPE_RGB: + customData[usdMetadata] = metadata->value.RGB(); + break; + case AI_TYPE_RGBA: + customData[usdMetadata] = metadata->value.RGBA(); + break; + case AI_TYPE_VECTOR: + customData[usdMetadata] = metadata->value.VEC(); + break; + case AI_TYPE_VECTOR2: + customData[usdMetadata] = metadata->value.VEC2(); + break; + case AI_TYPE_STRING: + customData[usdMetadata] = metadata->value.STR().c_str(); + break; + default: + break; + } + } + AiMetaDataIteratorDestroy(metadataIter); + + // If no "label" metadata is found for this attribute, we want to make one. + // e.g. base_color => "Base Color" + if (!foundLabel) { + std::string attrLabel(paramName.c_str()); + bool capitalize = true; + for (size_t i = 0; i < attrLabel.length(); ++i) { + if (attrLabel[i] == '_') { + capitalize = true; + attrLabel[i] = ' '; + } else { + if (capitalize) + attrLabel[i] = toupper(attrLabel[i]); + capitalize = false; + } + } + customData[SdrPropertyMetadata->Label] = attrLabel; + } + attr.SetCustomData(customData); + } AiParamIteratorDestroy(paramIter); } @@ -438,7 +553,6 @@ UsdStageRefPtr NdrArnoldGetShaderDefs() auto prim = stage->DefinePrim(SdfPath(TfStringPrintf("/%s", AiNodeEntryGetName(nodeEntry)))); _ReadArnoldShaderDef(prim, nodeEntry); } - AiNodeEntryIteratorDestroy(nodeIter); if (!hasActiveUniverse) { From 8cb2d9ca7f09fd05e1d020ffc64edf8991ecdc64 Mon Sep 17 00:00:00 2001 From: "ADS\\blaines" Date: Sat, 19 Nov 2022 21:03:02 +0100 Subject: [PATCH 2/3] Improvements in the Sdr metadatas #55 --- common/constant_strings.h | 3 + ndr/parser.cpp | 1 + ndr/utils.cpp | 157 +++++++++++++++++++++++--------------- 3 files changed, 100 insertions(+), 61 deletions(-) diff --git a/common/constant_strings.h b/common/constant_strings.h index c5cda7d660..df976aef18 100644 --- a/common/constant_strings.h +++ b/common/constant_strings.h @@ -217,6 +217,7 @@ ASTR(crease_idxs); ASTR(crease_sharpness); ASTR(curves); ASTR(cylinder_light); +ASTR(dcc); ASTR(defaultPrim); ASTR(depth_pointer); ASTR(diffuse); @@ -258,6 +259,7 @@ ASTR(gaussian_filter); ASTR(geometry); ASTR(ginstance); ASTR(grids); +ASTR(hide); ASTR(husk); ASTR(hydra); ASTR(id); @@ -443,6 +445,7 @@ ASTR(translation); ASTR(transmission); ASTR(twrap); ASTR(uniform); +ASTR(usd); ASTR(useMetadata); ASTR(useSpecularWorkflow); ASTR(use_light_group); diff --git a/ndr/parser.cpp b/ndr/parser.cpp index a624768239..4cbc587ab0 100644 --- a/ndr/parser.cpp +++ b/ndr/parser.cpp @@ -145,6 +145,7 @@ void _ReadShaderAttribute(const UsdAttribute &attr, NdrPropertyUniquePtrVec &pro SdrPropertyMetadata->Page, SdrPropertyMetadata->Connectable, SdrPropertyMetadata->Label, + SdrPropertyMetadata->Role, SdrPropertyMetadata->Help }; diff --git a/ndr/utils.cpp b/ndr/utils.cpp index bb136133a7..8fd36aa224 100644 --- a/ndr/utils.cpp +++ b/ndr/utils.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #if ARNOLD_VERSION_NUMBER > 60201 // Arnold AiArrayGetXXXFuncs are not available anymore. @@ -328,6 +329,10 @@ const DefaultValueConversion* _GetDefaultValueConversion(uint8_t type) } } +static bool _StrEndsWith(const std::string &str, const std::string &suffix) +{ + return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); +} const ArrayConversion* _GetArrayConversion(uint8_t type) { const auto& atm = _ArrayTypeConversionMap(); @@ -339,20 +344,80 @@ const ArrayConversion* _GetArrayConversion(uint8_t type) } } +VtValue _ReadArnoldMetadata(const AtMetaDataEntry *metadata) +{ + if (metadata == nullptr) + return VtValue(); + // Get the metadata value + switch(metadata->type) { + case AI_TYPE_INT: + return VtValue(metadata->value.INT()); + case AI_TYPE_BYTE: + return VtValue(metadata->value.BYTE()); + case AI_TYPE_UINT: + return VtValue(metadata->value.UINT()); + case AI_TYPE_BOOLEAN: + return VtValue(metadata->value.BOOL()); + case AI_TYPE_FLOAT: + return VtValue(metadata->value.FLT()); + case AI_TYPE_RGB: + return VtValue(metadata->value.RGB()); + case AI_TYPE_RGBA: + return VtValue(metadata->value.RGBA()); + case AI_TYPE_VECTOR: + return VtValue(metadata->value.VEC()); + case AI_TYPE_VECTOR2: + return VtValue(metadata->value.VEC2()); + case AI_TYPE_STRING: + return VtValue(metadata->value.STR().c_str()); + default: + break; + } + return VtValue(); +} // TODO(pal): We could also setup a metadata to store the raw arnold type, // for cases where multiple arnold types map to a single sdf type. -void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) -{ +void _ReadArnoldShaderDef(UsdStageRefPtr stage, const AtNodeEntry* nodeEntry) +{ + VtDictionary primCustomData; + bool hide = false; + // Get all metadatas for this shader + AtMetaDataIterator* nodeMetadataIter = AiNodeEntryGetMetaDataIterator(nodeEntry); + while(!AiMetaDataIteratorFinished(nodeMetadataIter)) { + const AtMetaDataEntry* metadata = AiMetaDataIteratorGetNext(nodeMetadataIter); + std::string metadataName(metadata->name.c_str()); + if (metadataName.empty()) + continue; + + TfToken usdPrimMetadata(metadataName.c_str()); + + if (metadata->type == AI_TYPE_STRING && + (_StrEndsWith(metadataName, ".classification") || + _StrEndsWith(metadataName, ".category"))) { + usdPrimMetadata = SdrPropertyMetadata->Role; + + } else if (metadata->name == str::ui_groups) { + usdPrimMetadata = _tokens->uigroups; + } else if (metadata->type == AI_TYPE_BOOLEAN && + (metadata->name == str::hide || _StrEndsWith(metadataName, ".hide"))) { + hide |= metadata->value.BOOL(); + continue; + } else if (metadata->type == AI_TYPE_STRING && metadata->name == str::dcc) { + AtString dcc = metadata->value.STR(); + if (!dcc.empty() && dcc != str::usd) + continue; + } + primCustomData[usdPrimMetadata] = _ReadArnoldMetadata(metadata); + } + AiMetaDataIteratorDestroy(nodeMetadataIter); + + if (hide) + return; + + auto prim = stage->DefinePrim(SdfPath(TfStringPrintf("/%s", AiNodeEntryGetName(nodeEntry)))); const auto filename = AiNodeEntryGetFilename(nodeEntry); prim.SetMetadata(_tokens->filename, VtValue(TfToken(filename == nullptr ? "" : filename))); - VtDictionary primCustomData; - AtString uigroups; - // Check if the Arnold node entry has a metadata ui.groups, to determine - // the grouping and order of attributes in the UI. - if (AiMetaDataGetStr(nodeEntry, AtString(), str::ui_groups, &uigroups)) - primCustomData[_tokens->uigroups] = std::string(uigroups.c_str()); - prim.SetCustomData(primCustomData); // For shaders, we want to add an attribute for the output type @@ -366,12 +431,17 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) // create an output type for imagers prim.CreateAttribute(_tokens->output, SdfValueTypeNames->String, false); } + auto paramIter = AiNodeEntryGetParamIterator(nodeEntry); while (!AiParamIteratorFinished(paramIter)) { const auto* pentry = AiParamIteratorGetNext(paramIter); const auto paramType = AiParamGetType(pentry); const AtString paramName = AiParamGetName(pentry); + if (paramName.empty()) + continue; + + UsdAttribute attr; VtDictionary customData; @@ -406,6 +476,7 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) } } + // For enum attributes, get all the allowed enum values and // set them as customData through the metadata "enumValues" if (paramType == AI_TYPE_ENUM) { @@ -426,67 +497,32 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) while(!AiMetaDataIteratorFinished(metadataIter)) { const AtMetaDataEntry* metadata = AiMetaDataIteratorGetNext(metadataIter); if (!metadata) - continue; + continue; TfToken usdMetadata; // For now we only support a hardcoded list of metadatas if (metadata->name == str::linkable) - usdMetadata = SdrPropertyMetadata->Connectable; + usdMetadata = SdrPropertyMetadata->Connectable; else if (metadata->name == str::_min) - usdMetadata = _tokens->uimin; + usdMetadata = _tokens->uimin; else if (metadata->name == str::_max) - usdMetadata = _tokens->uimax; + usdMetadata = _tokens->uimax; else if (metadata->name == str::softmin) - usdMetadata = _tokens->uisoftmin; + usdMetadata = _tokens->uisoftmin; else if (metadata->name == str::softmax) - usdMetadata = _tokens->uisoftmax; + usdMetadata = _tokens->uisoftmax; else if (metadata->name == str::label) { - usdMetadata = SdrPropertyMetadata->Label; - foundLabel = true; + usdMetadata = SdrPropertyMetadata->Label; + foundLabel = true; } else if (metadata->name == str::desc) - usdMetadata = SdrPropertyMetadata->Help; + usdMetadata = SdrPropertyMetadata->Help; else - continue; - - // Get the metadata value - VtValue metadataValue; - switch(metadata->type) { - case AI_TYPE_INT: - customData[usdMetadata] = metadata->value.INT(); - break; - case AI_TYPE_BYTE: - customData[usdMetadata] = metadata->value.BYTE(); - break; - case AI_TYPE_UINT: - customData[usdMetadata] = metadata->value.UINT(); - break; - case AI_TYPE_BOOLEAN: - customData[usdMetadata] = metadata->value.BOOL(); - break; - case AI_TYPE_FLOAT: - customData[usdMetadata] = metadata->value.FLT(); - break; - case AI_TYPE_RGB: - customData[usdMetadata] = metadata->value.RGB(); - break; - case AI_TYPE_RGBA: - customData[usdMetadata] = metadata->value.RGBA(); - break; - case AI_TYPE_VECTOR: - customData[usdMetadata] = metadata->value.VEC(); - break; - case AI_TYPE_VECTOR2: - customData[usdMetadata] = metadata->value.VEC2(); - break; - case AI_TYPE_STRING: - customData[usdMetadata] = metadata->value.STR().c_str(); - break; - default: - break; - } + usdMetadata = TfToken(metadata->name.c_str()); + + customData[usdMetadata] = _ReadArnoldMetadata(metadata); } AiMetaDataIteratorDestroy(metadataIter); - + // If no "label" metadata is found for this attribute, we want to make one. // e.g. base_color => "Base Color" if (!foundLabel) { @@ -502,11 +538,12 @@ void _ReadArnoldShaderDef(UsdPrim& prim, const AtNodeEntry* nodeEntry) capitalize = false; } } - customData[SdrPropertyMetadata->Label] = attrLabel; + customData[SdrPropertyMetadata->Label] = attrLabel.c_str(); } attr.SetCustomData(customData); } AiParamIteratorDestroy(paramIter); + } } // namespace @@ -549,9 +586,7 @@ UsdStageRefPtr NdrArnoldGetShaderDefs() if (!AiMetaDataGetStr(nodeEntry, AtString(), s_subtype, &subtype) || strcmp(subtype.c_str(), "imager")) continue; } - - auto prim = stage->DefinePrim(SdfPath(TfStringPrintf("/%s", AiNodeEntryGetName(nodeEntry)))); - _ReadArnoldShaderDef(prim, nodeEntry); + _ReadArnoldShaderDef(stage, nodeEntry); } AiNodeEntryIteratorDestroy(nodeIter); From b96ef16913f85a9250a740883206d471e5104c5d Mon Sep 17 00:00:00 2001 From: "ADS\\blaines" Date: Tue, 22 Nov 2022 13:44:19 +0100 Subject: [PATCH 3/3] Fix typo in the comments #55 --- ndr/parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndr/parser.cpp b/ndr/parser.cpp index 4cbc587ab0..4c150531b7 100644 --- a/ndr/parser.cpp +++ b/ndr/parser.cpp @@ -127,7 +127,7 @@ void _ReadShaderAttribute(const UsdAttribute &attr, NdrPropertyUniquePtrVec &pro NdrTokenMap metadata; NdrTokenMap hints; - // For enum attributres, all enum fields should be set as "options" + // For enum attributes, all enum fields should be set as "options" // to this attribute NdrOptionVec options; auto it = customData.find(_tokens->enumValues);