Skip to content

Commit

Permalink
Fix clippingPlanes type definition.
Browse files Browse the repository at this point in the history
[USDA] Fix `vector3d` and `vector4d` are not parsed correctly.
Support more usdShade property metadataum.
  • Loading branch information
syoyo committed Sep 13, 2023
1 parent 3a97d4c commit d7f74cb
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/ascii-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ static void RegisterPropMetas(

metas["interpolation"] = AsciiParser::VariableDef(value::kToken, "interpolation");

// usdShade
metas["bindMaterialAs"] = AsciiParser::VariableDef(value::kToken, "bindMaterialAs");
metas["connectability"] = AsciiParser::VariableDef(value::kToken, "connectability");
metas["renderType"] = AsciiParser::VariableDef(value::kToken, "renderType");
metas["outputName"] = AsciiParser::VariableDef(value::kToken, "outputName");
metas["sdrMetadata"] = AsciiParser::VariableDef(value::kDictionary, "sdrMetadata");
}


Expand Down Expand Up @@ -364,6 +369,8 @@ static void RegisterPrimAttrTypes(std::set<std::string> &d) {
d.insert(value::kTexCoord4d);
d.insert(value::kVector3f);
d.insert(value::kVector4f);
d.insert(value::kVector3d);
d.insert(value::kVector4d);
d.insert(value::kColor3h);
d.insert(value::kColor3f);
d.insert(value::kColor3d);
Expand Down
16 changes: 16 additions & 0 deletions src/pprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,22 @@ std::string print_attr_metas(const AttrMeta &meta, const uint32_t indent) {
ss << pprint::Indent(indent) << "bindMaterialAs = " << quote(to_string(meta.bindMaterialAs.value())) << "\n";
}

if (meta.connectability) {
ss << pprint::Indent(indent) << "connectability = " << quote(to_string(meta.connectability.value())) << "\n";
}

if (meta.outputName) {
ss << pprint::Indent(indent) << "outputName = " << quote(to_string(meta.outputName.value())) << "\n";
}

if (meta.renderType) {
ss << pprint::Indent(indent) << "renderType = " << quote(to_string(meta.renderType.value())) << "\n";
}

if (meta.sdrMetadata) {
ss << pprint::Indent(indent) << print_customData(meta.sdrMetadata.value(), "sdrMetadata", indent);
}

if (meta.hidden) {
ss << pprint::Indent(indent) << "hidden = " << to_string(meta.hidden.value()) << "\n";
}
Expand Down
9 changes: 7 additions & 2 deletions src/prim-types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -892,13 +892,18 @@ struct AttrMetas {

nonstd::optional<double> weight; // usdSkel inbetween BlendShape weight.

// usdShade
nonstd::optional<value::token> connectability; // NOTE: applies to attr
nonstd::optional<value::token> outputName; // NOTE: applies to rel
nonstd::optional<value::token> renderType; // NOTE: applies to prop
nonstd::optional<Dictionary> sdrMetadata; // NOTE: applies to attr(also seen in prim meta)
//
// MaterialBinding
//
// Could be arbitrary token value so use `token[]` type.
// For now, either `weakerThanDescendants` or `strongerThanDescendants` are
// valid token.
nonstd::optional<value::token> bindMaterialAs; // 'bindMaterialAs'
nonstd::optional<value::token> bindMaterialAs; // 'bindMaterialAs' NOTE: applies to rel.

std::map<std::string, MetaVariable> meta; // other meta values

Expand All @@ -908,7 +913,7 @@ struct AttrMetas {

bool authored() const {
return (interpolation || elementSize || hidden || customData || weight ||
bindMaterialAs || meta.size() || stringData.size());
connectability || outputName || renderType || sdrMetadata || bindMaterialAs || meta.size() || stringData.size());
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/usdGeom.hh
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ struct GeomCamera : public GPrim {
// Properties
//

TypedAttribute<std::vector<value::float4>> clippingPlanes;
TypedAttribute<Animatable<std::vector<value::float4>>> clippingPlanes; // float4[]
TypedAttributeWithFallback<Animatable<value::float2>> clippingRange{
value::float2({0.1f, 1000000.0f})};
TypedAttributeWithFallback<Animatable<float>> exposure{0.0f}; // in EV
Expand Down
50 changes: 50 additions & 0 deletions src/usdc-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ bool USDCReader::Impl::ParseProperty(const SpecType spec_type,
nonstd::optional<CustomDataType> customData;
nonstd::optional<double> weight;
nonstd::optional<value::token> bindMaterialAs;
nonstd::optional<value::token> connectability;
nonstd::optional<value::token> renderType;
nonstd::optional<value::token> outputName;
nonstd::optional<CustomDataType> sdrMetadata;
nonstd::optional<value::StringData> comment;
nonstd::optional<Variability> variability;
Property::Type propType{Property::Type::EmptyAttrib};
Expand Down Expand Up @@ -1129,6 +1133,38 @@ bool USDCReader::Impl::ParseProperty(const SpecType spec_type,
PUSH_ERROR_AND_RETURN_TAG(
kTag, "`connectionChildren` field is not `PathVector` type.");
}
} else if (fv.first == "connectability") {
if (auto pv = fv.second.get_value<value::token>()) {
connectability = pv.value();
} else {
PUSH_ERROR_AND_RETURN_TAG(
kTag, "`connectability` must be type `token`, but got type `"
<< fv.second.type_name() << "`");
}
} else if (fv.first == "outputName") {
if (auto pv = fv.second.get_value<value::token>()) {
outputName = pv.value();
} else {
PUSH_ERROR_AND_RETURN_TAG(
kTag, "`outputName` must be type `token`, but got type `"
<< fv.second.type_name() << "`");
}
} else if (fv.first == "renderType") {
if (auto pv = fv.second.get_value<value::token>()) {
renderType = pv.value();
} else {
PUSH_ERROR_AND_RETURN_TAG(
kTag, "`renderType` must be type `token`, but got type `"
<< fv.second.type_name() << "`");
}
} else if (fv.first == "sdrMetadata") {
if (auto pv = fv.second.get_value<CustomDataType>()) {
sdrMetadata = pv.value();
} else {
PUSH_ERROR_AND_RETURN_TAG(
kTag, "`sdrMetadata` must be type `dictionary`, but got type `"
<< fv.second.type_name() << "`");
}
} else if (fv.first == "customData") {
// CustomData(dict)
if (auto pv = fv.second.get_value<CustomDataType>()) {
Expand Down Expand Up @@ -1236,6 +1272,20 @@ bool USDCReader::Impl::ParseProperty(const SpecType spec_type,
if (bindMaterialAs) {
meta.bindMaterialAs = bindMaterialAs.value();
}
if (outputName) {
meta.outputName = outputName.value();
}
if (sdrMetadata) {
meta.sdrMetadata = sdrMetadata.value();
}
if (connectability) {
meta.connectability = connectability.value();
}
if (renderType) {
meta.renderType = renderType.value();
}



// FIXME: SpecType supercedes propType.
if (propType == Property::Type::EmptyAttrib) {
Expand Down
8 changes: 8 additions & 0 deletions tests/usda/attr-metadataum-001.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#usda 1.0

def Sphere "world"
{
float[] weights = [0.0, 1.0, 2.0] (
renderType = "material"
)
}
5 changes: 5 additions & 0 deletions tests/usda/vector3d-001.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#usda 1.0

def "bora" {
vector3d dora = (1, 2, 3)
}

0 comments on commit d7f74cb

Please sign in to comment.