diff --git a/src/prim-types.hh b/src/prim-types.hh index bb41b460..cc306722 100644 --- a/src/prim-types.hh +++ b/src/prim-types.hh @@ -1680,7 +1680,31 @@ class TypedAttributeWithFallback { void set_value_empty() { _empty = true; } - bool is_value_empty() const { return _empty; } + bool has_connections() const { return _paths.size(); } + + bool is_value_empty() const { + if (has_connections()) { + return false; + } + + if (_empty) { + return true; + } + + if (_attrib) { + return false; + } + + return true; + } + + bool has_value() const { + if (_empty) { + return false; + } + + return true; + } const T &get_value() const { if (_attrib) { @@ -1694,7 +1718,7 @@ class TypedAttributeWithFallback { // for `uniform` attribute only void set_blocked(bool onoff) { _blocked = onoff; } - bool is_connection() const { return _paths.size(); } + bool is_connection() const { return _paths.size() && !has_value() ; } void set_connection(const Path &path) { _paths.clear(); @@ -1714,6 +1738,8 @@ class TypedAttributeWithFallback { return nonstd::nullopt; } + void clear_connections() { _paths.clear(); } + // value set? bool authored() const { if (_empty) { // authored with empty value. diff --git a/src/tydra/attribute-eval-typed-animatable-fallback.cc b/src/tydra/attribute-eval-typed-animatable-fallback.cc index 1c6a327b..f7ce7b5a 100644 --- a/src/tydra/attribute-eval-typed-animatable-fallback.cc +++ b/src/tydra/attribute-eval-typed-animatable-fallback.cc @@ -28,7 +28,9 @@ bool EvaluateTypedAttributeImpl( const double t, const value::TimeSampleInterpolationType tinterp) { - if (attr.is_connection()) { + if (attr.has_value()) { + return attr.get_value(value); + } if (attr.has_connections()) { // Follow connection target Path(singple targetPath only). std::vector pv = attr.connections(); if (pv.empty()) { @@ -81,8 +83,8 @@ bool EvaluateTypedAttributeImpl( PUSH_ERROR_AND_RETURN( fmt::format("Attribute `{}` is ValueBlocked(None).", attr_name)); } else { - - return attr.get_value(value); + PUSH_ERROR_AND_RETURN( + fmt::format("Internal error. Invalid TypedAttributeWithFallback>.", value::TypeTraits::type_name())); } @@ -140,12 +142,23 @@ bool EvaluateTypedAnimatableAttribute( (*err) += "Attribute is Blocked.\n"; } return false; + } else if (tattr.has_value()) { + const Animatable &value = tattr.get_value(); + T v; + if (value.get(t, &v, tinterp)) { + return true; + } else { + if (err) { + (*err) += fmt::format("Failed to get TypedAnimatableAttribute value: {} \n", attr_name); + } + return false; + } } else if (tattr.is_value_empty()) { if (err) { (*err) += "Attribute value is empty.\n"; } return false; - } else if (tattr.is_connection()) { + } else if (tattr.has_connections()) { // Follow targetPath Attribute attr = ToAttributeConnection(tattr); @@ -170,16 +183,6 @@ bool EvaluateTypedAnimatableAttribute( } } else { - const Animatable &value = tattr.get_value(); - T v; - if (value.get(t, &v, tinterp)) { - return true; - } else { - if (err) { - (*err) += fmt::format("Failed to get TypedAnimatableAttribute value: {} \n", attr_name); - } - return false; - } if (err) { (*err) += fmt::format("[Internal error] Invalid TypedAttribute? : {} \n", attr_name); diff --git a/src/tydra/attribute-eval-typed-animatable.cc b/src/tydra/attribute-eval-typed-animatable.cc index 966b2bb2..e4a504ae 100644 --- a/src/tydra/attribute-eval-typed-animatable.cc +++ b/src/tydra/attribute-eval-typed-animatable.cc @@ -28,7 +28,11 @@ bool EvaluateTypedAttributeImpl( const double t, const value::TimeSampleInterpolationType tinterp) { - if (attr.is_connection()) { + if (attr.has_value()) { + + return attr.get_value(value); + + } else if (attr.has_connection()) { // Follow connection target Path(singple targetPath only). std::vector pv = attr.connections(); if (pv.empty()) { @@ -82,7 +86,7 @@ bool EvaluateTypedAttributeImpl( fmt::format("Attribute `{}` is ValueBlocked(None).", attr_name)); } else { - return attr.get_value(value); + PUSH_ERROR_AND_RETURN("Internal error. Invalid TypedAttribute> value."); } diff --git a/src/tydra/attribute-eval-typed-fallback.cc b/src/tydra/attribute-eval-typed-fallback.cc index eaaf6978..8c9d9668 100644 --- a/src/tydra/attribute-eval-typed-fallback.cc +++ b/src/tydra/attribute-eval-typed-fallback.cc @@ -31,7 +31,10 @@ bool EvaluateTypedAttributeImpl( const double t, const value::TimeSampleInterpolationType tinterp) { - if (attr.is_connection()) { + if (attr.has_value()) { + return attr.get_value(value); + + } else if (attr.has_connection()) { // Follow connection target Path(singple targetPath only). std::vector pv = attr.connections(); if (pv.empty()) { @@ -84,8 +87,8 @@ bool EvaluateTypedAttributeImpl( PUSH_ERROR_AND_RETURN( fmt::format("Attribute `{}` is ValueBlocked(None).", attr_name)); } else { - - return attr.get_value(value); + PUSH_ERROR_AND_RETURN( + fmt::format("Internal error. Attribute `{}` has invalid form of TypedAttributeWithFallback<{}>.", attr_name, value::TypeTraits::type_name())); } @@ -141,12 +144,15 @@ bool EvaluateTypedAttribute( (*err) += "Attribute is Blocked.\n"; } return false; + } else if (tattr.has_value()) { + (*value_out) = tattr.get_value(); + return true; } else if (tattr.is_value_empty()) { if (err) { (*err) += "Attribute value is empty.\n"; } return false; - } else if (tattr.is_connection()) { + } else if (tattr.has_connections()) { // Follow targetPath Attribute attr = ToAttributeConnection(tattr); @@ -170,11 +176,11 @@ bool EvaluateTypedAttribute( (*err) += fmt::format("Type mismatch. Value producing attribute has type {}, but requested type is {}. Attribute: {}", value.type_name(), tattr.type_name(), attr_name); } - } else { - (*value_out) = tattr.get_value(); - return true; } - return false; + + PUSH_ERROR_AND_RETURN(fmt::format("Internal error. Attribute {} has invalid form of TypedAttributeWithFallback<{}>.", + attr_name, value::TypeTraits::type_name())); + } // template instanciations diff --git a/tests/usda/multi-attribute-004.usda b/tests/usda/multi-attribute-004.usda new file mode 100644 index 00000000..c02ee366 --- /dev/null +++ b/tests/usda/multi-attribute-004.usda @@ -0,0 +1,7 @@ +#usda 1.0 + +def "bora" { + float val = 100.5 ( elementSize = 2 ) + float val.timeSamples = {0: 1.0, 2: 2.0, 3: 3.0} + #float val.connect = +}