Skip to content

Commit

Permalink
Support clips Prim metadatum.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Sep 30, 2023
1 parent 75fc5c6 commit d77c5e5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/ascii-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ static void RegisterPrimMetas(
// NOTE: items are expected to be all string type.
metas["sdrMetadata"] = AsciiParser::VariableDef(value::kDictionary, "sdrMetadata");

metas["clips"] =
AsciiParser::VariableDef(value::kDictionary, "clips");


// USDZ extension
metas["sceneName"] = AsciiParser::VariableDef(value::kString, "sceneName");
Expand Down Expand Up @@ -2489,6 +2492,8 @@ bool AsciiParser::ParseMetaValue(const VariableDef &def, MetaVariable *outvar) {

bool array_qual{false};

DCOUT("parseMeta: vartype " << vartype);

if (endsWith(vartype, "[]")) {
vartype = removeSuffix(vartype, "[]");
array_qual = true;
Expand Down
4 changes: 4 additions & 0 deletions src/pprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ std::string print_prim_metas(const PrimMeta &meta, const uint32_t indent) {
ss << pprint::Indent(indent) << "active = " << to_string(meta.active.value()) << "\n";
}

if (meta.clips) {
ss << print_customData(meta.clips.value(), "clips", indent);
}

if (meta.instanceable) {
ss << pprint::Indent(indent) << "instanceable = " << to_string(meta.instanceable.value()) << "\n";
}
Expand Down
8 changes: 8 additions & 0 deletions src/prim-types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,14 @@ void PrimMetas::update_from(const PrimMetas &rhs, const bool override_authored)
}
}

if (rhs.clips) {
if (clips) {
OverrideDictionary(clips.value(), rhs.clips.value(), override_authored);
} else if (override_authored) {
clips = rhs.clips;
}
}

if (rhs.customData) {
if (customData) {
OverrideDictionary(customData.value(), rhs.customData.value(), override_authored);
Expand Down
3 changes: 2 additions & 1 deletion src/prim-types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ struct PrimMetas {
sdrMetadata; // 'sdrMetadata' (usdShade Prim only?)

nonstd::optional<bool> instanceable; // 'instanceable'
nonstd::optional<Dictionary> clips; // 'clips'

// String representation of Kind.
// For user-defined Kind, it returns `_kind_str`
Expand Down Expand Up @@ -868,7 +869,7 @@ struct PrimMetas {
return (active || hidden || kind || customData || references || payload ||
inherits || variants || variantSets || specializes || displayName ||
sceneName || doc || comment || unregisteredMetas.size() || meta.size() || apiSchemas ||
sdrMetadata || assetInfo || instanceable);
sdrMetadata || assetInfo || instanceable || clips);
}

//
Expand Down
18 changes: 18 additions & 0 deletions src/usda-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,24 @@ class USDAReader::Impl {
"`dictionary`. got type `"
<< var.type_name() << "`");
}
} else if (meta.first == "clips") {
DCOUT("clips. type = " << var.type_name());
if (var.type_id() == value::TypeTraits<Dictionary>::type_id()) {
if (auto pv = var.get_value<Dictionary>()) {
out->clips = pv.value();
} else {
PUSH_ERROR_AND_RETURN_TAG(kTag,
"(Internal error?) `clips` metadataum is not type "
"`dictionary`. got type `"
<< var.type_name() << "`");
}

} else {
PUSH_ERROR_AND_RETURN(
"(Internal error?) `clips` metadataum is not type "
"`dictionary`. got type `"
<< var.type_name() << "`");
}
} else if (meta.first == "assetInfo") {
DCOUT("assetInfo. type = " << var.type_name());
if (auto pv = var.get_value<Dictionary>()) {
Expand Down
9 changes: 9 additions & 0 deletions src/usdc-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,15 @@ bool USDCReader::Impl::ParsePrimSpec(const crate::FieldValuePairVector &fvs,
kTag, "`assetInfo` must be type `dictionary`, but got type `"
<< fv.second.type_name() << "`");
}
} else if (fv.first == "clips") {
// CustomData(dict)
if (auto pv = fv.second.as<CustomDataType>()) {
primMeta.clips = (*pv);
} else {
PUSH_ERROR_AND_RETURN_TAG(
kTag, "`clips` must be type `dictionary`, but got type `"
<< fv.second.type_name() << "`");
}
} else if (fv.first == "kind") {
if (auto pv = fv.second.as<value::token>()) {

Expand Down
14 changes: 14 additions & 0 deletions tests/usda/clips-primmeta-001.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#usda 1.0
over "GEO" (
clips = {
dictionary geo = {
double2[] active = [(1004, 0)]
asset[] assetPaths = [@payload/animated_data.1004.usdc@]
asset manifestAssetPath = @./clip.manifest.usda@
string primPath = "/root/remi/body_M_hrc/GEO"
double2[] times = []
}
}
)
{ }

Binary file added tests/usdc/clips-primmeta-001.usdc
Binary file not shown.

0 comments on commit d77c5e5

Please sign in to comment.