Skip to content

Commit

Permalink
w.i.p
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed May 2, 2024
1 parent d336d0b commit 27d6ba0
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 26 deletions.
30 changes: 28 additions & 2 deletions src/prim-types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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.
Expand Down
31 changes: 17 additions & 14 deletions src/tydra/attribute-eval-typed-animatable-fallback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> pv = attr.connections();
if (pv.empty()) {
Expand Down Expand Up @@ -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<Animatable<{}>>.", value::TypeTraits<T>::type_name()));

}

Expand Down Expand Up @@ -140,12 +142,23 @@ bool EvaluateTypedAnimatableAttribute(
(*err) += "Attribute is Blocked.\n";
}
return false;
} else if (tattr.has_value()) {
const Animatable<T> &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);
Expand All @@ -170,16 +183,6 @@ bool EvaluateTypedAnimatableAttribute(
}

} else {
const Animatable<T> &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);
Expand Down
8 changes: 6 additions & 2 deletions src/tydra/attribute-eval-typed-animatable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> pv = attr.connections();
if (pv.empty()) {
Expand Down Expand Up @@ -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<Animatable<T>> value.");

}

Expand Down
22 changes: 14 additions & 8 deletions src/tydra/attribute-eval-typed-fallback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> pv = attr.connections();
if (pv.empty()) {
Expand Down Expand Up @@ -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<T>::type_name()));

}

Expand Down Expand Up @@ -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);
Expand All @@ -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<T>::type_name()));

}

// template instanciations
Expand Down
7 changes: 7 additions & 0 deletions tests/usda/multi-attribute-004.usda
Original file line number Diff line number Diff line change
@@ -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 = </bora.value>
}

0 comments on commit 27d6ba0

Please sign in to comment.