-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LOOKDEVX-670 Improved USD type support #2364
Merged
seando-adsk
merged 4 commits into
dev
from
t_gamaj/LOOKDEVX-670/translate_new_types_from_usd
May 19, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4f34c98
LOOKDEVX-670 Improved USD type support
JGamache-autodesk 2bda5dc
Make testAttribute compatible with earlier Ufe
JGamache-autodesk ce3af81
Make attribute test compatible with all Ufe versions
JGamache-autodesk 9d32752
Responding to review comment.
JGamache-autodesk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,8 +177,10 @@ U getUsdAttributeVectorAsUfe(const PXR_NS::UsdAttribute& attr, const PXR_NS::Usd | |
|
||
PXR_NS::VtValue vt; | ||
if (attr.Get(&vt, time) && vt.IsHolding<T>()) { | ||
T gfVec = vt.UncheckedGet<T>(); | ||
U ret(gfVec[0], gfVec[1], gfVec[2]); | ||
T gfVec = vt.UncheckedGet<T>(); | ||
U ret; | ||
constexpr size_t num = ret.vector.size(); | ||
std::copy(gfVec.data(), gfVec.data() + num, ret.vector.data()); | ||
return ret; | ||
} | ||
|
||
|
@@ -192,10 +194,74 @@ void setUsdAttributeVectorFromUfe( | |
const PXR_NS::UsdTimeCode& time) | ||
{ | ||
T vec; | ||
vec.Set(value.x(), value.y(), value.z()); | ||
std::copy(value.vector.data(), value.vector.data() + value.vector.size(), vec.data()); | ||
setUsdAttr<T>(attr, vec); | ||
} | ||
|
||
template <typename T, typename U> | ||
U getUsdAttributeColorAsUfe(const PXR_NS::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But since we are accessing the inner class, we must create a specialization for colors because the name of the inner class is different. |
||
if (!attr.IsValid() || !attr.HasValue()) | ||
return U(); | ||
|
||
PXR_NS::VtValue vt; | ||
if (attr.Get(&vt, time) && vt.IsHolding<T>()) { | ||
T gfVec = vt.UncheckedGet<T>(); | ||
U ret; | ||
std::copy(gfVec.data(), gfVec.data() + ret.color.size(), ret.color.data()); | ||
return ret; | ||
} | ||
|
||
return U(); | ||
} | ||
|
||
template <typename T, typename U> | ||
void setUsdAttributeColorFromUfe( | ||
PXR_NS::UsdAttribute& attr, | ||
const U& value, | ||
const PXR_NS::UsdTimeCode& time) | ||
{ | ||
T vec; | ||
std::copy(value.color.data(), value.color.data() + value.color.size(), vec.data()); | ||
setUsdAttr<T>(attr, vec); | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
template <typename T, typename U> | ||
U getUsdAttributeMatrixAsUfe(const PXR_NS::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time) | ||
{ | ||
if (!attr.IsValid() || !attr.HasValue()) | ||
return U(); | ||
|
||
PXR_NS::VtValue vt; | ||
if (attr.Get(&vt, time) && vt.IsHolding<T>()) { | ||
T gfMat = vt.UncheckedGet<T>(); | ||
U ret; | ||
std::copy( | ||
gfMat.data(), | ||
gfMat.data() + ret.matrix.size() * ret.matrix.size(), | ||
ret.matrix[0].data()); | ||
return ret; | ||
} | ||
|
||
return U(); | ||
} | ||
|
||
template <typename T, typename U> | ||
void setUsdAttributeMatrixFromUfe( | ||
PXR_NS::UsdAttribute& attr, | ||
const U& value, | ||
const PXR_NS::UsdTimeCode& time) | ||
{ | ||
T mat; | ||
std::copy( | ||
value.matrix[0].data(), | ||
value.matrix[0].data() + value.matrix.size() * value.matrix.size(), | ||
mat.data()); | ||
setUsdAttr<T>(attr, mat); | ||
} | ||
#endif | ||
|
||
class UsdUndoableCommand : public Ufe::UndoableCommand | ||
{ | ||
public: | ||
|
@@ -384,6 +450,64 @@ std::string UsdAttributeGeneric::nativeType() const | |
return fUsdAttr.GetTypeName().GetType().GetTypeName(); | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
//------------------------------------------------------------------------------ | ||
// UsdAttributeFilename: | ||
//------------------------------------------------------------------------------ | ||
|
||
UsdAttributeFilename::UsdAttributeFilename( | ||
const UsdSceneItem::Ptr& item, | ||
const PXR_NS::UsdAttribute& usdAttr) | ||
: Ufe::AttributeFilename(item) | ||
, UsdAttribute(item, usdAttr) | ||
{ | ||
} | ||
|
||
/*static*/ | ||
UsdAttributeFilename::Ptr | ||
UsdAttributeFilename::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr) | ||
{ | ||
auto attr = std::make_shared<UsdAttributeFilename>(item, usdAttr); | ||
return attr; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// UsdAttributeFilename - Ufe::AttributeFilename overrides | ||
//------------------------------------------------------------------------------ | ||
|
||
std::string UsdAttributeFilename::get() const | ||
{ | ||
PXR_NS::VtValue vt; | ||
if (fUsdAttr.Get(&vt, getCurrentTime(sceneItem())) && vt.IsHolding<SdfAssetPath>()) { | ||
SdfAssetPath path = vt.UncheckedGet<SdfAssetPath>(); | ||
return path.GetAssetPath(); | ||
} | ||
|
||
return std::string(); | ||
} | ||
|
||
void UsdAttributeFilename::set(const std::string& value) | ||
{ | ||
SdfAssetPath path(value); | ||
setUsdAttr<PXR_NS::SdfAssetPath>(fUsdAttr, path); | ||
} | ||
|
||
Ufe::UndoableCommand::Ptr UsdAttributeFilename::setCmd(const std::string& value) | ||
{ | ||
auto self = std::dynamic_pointer_cast<UsdAttributeFilename>(shared_from_this()); | ||
if (!TF_VERIFY(self, kErrorMsgInvalidType)) | ||
return nullptr; | ||
|
||
std::string errMsg; | ||
if (!MayaUsd::ufe::isAttributeEditAllowed(fUsdAttr, &errMsg)) { | ||
MGlobal::displayError(errMsg.c_str()); | ||
return nullptr; | ||
} | ||
|
||
return std::make_shared<SetUndoableCommand<std::string, UsdAttributeFilename>>(self, value); | ||
} | ||
#endif | ||
|
||
//------------------------------------------------------------------------------ | ||
// UsdAttributeEnumString: | ||
//------------------------------------------------------------------------------ | ||
|
@@ -524,17 +648,28 @@ template <> void TypedUsdAttribute<std::string>::set(const std::string& value) | |
|
||
template <> Ufe::Color3f TypedUsdAttribute<Ufe::Color3f>::get() const | ||
{ | ||
return getUsdAttributeVectorAsUfe<GfVec3f, Ufe::Color3f>(fUsdAttr, getCurrentTime(sceneItem())); | ||
return getUsdAttributeColorAsUfe<GfVec3f, Ufe::Color3f>(fUsdAttr, getCurrentTime(sceneItem())); | ||
} | ||
|
||
// Note: cannot use setUsdAttributeVectorFromUfe since it relies on x/y/z | ||
template <> void TypedUsdAttribute<Ufe::Color3f>::set(const Ufe::Color3f& value) | ||
{ | ||
GfVec3f vec; | ||
vec.Set(value.r(), value.g(), value.b()); | ||
setUsdAttr<GfVec3f>(fUsdAttr, vec); | ||
setUsdAttributeColorFromUfe<GfVec3f, Ufe::Color3f>( | ||
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
template <> Ufe::Color4f TypedUsdAttribute<Ufe::Color4f>::get() const | ||
{ | ||
return getUsdAttributeColorAsUfe<GfVec4f, Ufe::Color4f>(fUsdAttr, getCurrentTime(sceneItem())); | ||
} | ||
|
||
template <> void TypedUsdAttribute<Ufe::Color4f>::set(const Ufe::Color4f& value) | ||
{ | ||
setUsdAttributeColorFromUfe<GfVec4f, Ufe::Color4f>( | ||
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
#endif | ||
|
||
template <> Ufe::Vector3i TypedUsdAttribute<Ufe::Vector3i>::get() const | ||
{ | ||
return getUsdAttributeVectorAsUfe<GfVec3i, Ufe::Vector3i>( | ||
|
@@ -547,6 +682,20 @@ template <> void TypedUsdAttribute<Ufe::Vector3i>::set(const Ufe::Vector3i& valu | |
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
template <> Ufe::Vector2f TypedUsdAttribute<Ufe::Vector2f>::get() const | ||
{ | ||
return getUsdAttributeVectorAsUfe<GfVec2f, Ufe::Vector2f>( | ||
fUsdAttr, getCurrentTime(sceneItem())); | ||
} | ||
|
||
template <> void TypedUsdAttribute<Ufe::Vector2f>::set(const Ufe::Vector2f& value) | ||
{ | ||
setUsdAttributeVectorFromUfe<GfVec2f, Ufe::Vector2f>( | ||
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
#endif | ||
|
||
template <> Ufe::Vector3f TypedUsdAttribute<Ufe::Vector3f>::get() const | ||
{ | ||
return getUsdAttributeVectorAsUfe<GfVec3f, Ufe::Vector3f>( | ||
|
@@ -559,6 +708,20 @@ template <> void TypedUsdAttribute<Ufe::Vector3f>::set(const Ufe::Vector3f& valu | |
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
template <> Ufe::Vector4f TypedUsdAttribute<Ufe::Vector4f>::get() const | ||
{ | ||
return getUsdAttributeVectorAsUfe<GfVec4f, Ufe::Vector4f>( | ||
fUsdAttr, getCurrentTime(sceneItem())); | ||
} | ||
|
||
template <> void TypedUsdAttribute<Ufe::Vector4f>::set(const Ufe::Vector4f& value) | ||
{ | ||
setUsdAttributeVectorFromUfe<GfVec4f, Ufe::Vector4f>( | ||
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
#endif | ||
|
||
template <> Ufe::Vector3d TypedUsdAttribute<Ufe::Vector3d>::get() const | ||
{ | ||
return getUsdAttributeVectorAsUfe<GfVec3d, Ufe::Vector3d>( | ||
|
@@ -571,6 +734,32 @@ template <> void TypedUsdAttribute<Ufe::Vector3d>::set(const Ufe::Vector3d& valu | |
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
template <> Ufe::Matrix3d TypedUsdAttribute<Ufe::Matrix3d>::get() const | ||
{ | ||
return getUsdAttributeMatrixAsUfe<GfMatrix3d, Ufe::Matrix3d>( | ||
fUsdAttr, getCurrentTime(sceneItem())); | ||
} | ||
|
||
template <> void TypedUsdAttribute<Ufe::Matrix3d>::set(const Ufe::Matrix3d& value) | ||
{ | ||
setUsdAttributeMatrixFromUfe<GfMatrix3d, Ufe::Matrix3d>( | ||
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
|
||
template <> Ufe::Matrix4d TypedUsdAttribute<Ufe::Matrix4d>::get() const | ||
{ | ||
return getUsdAttributeMatrixAsUfe<GfMatrix4d, Ufe::Matrix4d>( | ||
fUsdAttr, getCurrentTime(sceneItem())); | ||
} | ||
|
||
template <> void TypedUsdAttribute<Ufe::Matrix4d>::set(const Ufe::Matrix4d& value) | ||
{ | ||
setUsdAttributeMatrixFromUfe<GfMatrix4d, Ufe::Matrix4d>( | ||
fUsdAttr, value, getCurrentTime(sceneItem())); | ||
} | ||
#endif | ||
|
||
template <typename T> T TypedUsdAttribute<T>::get() const | ||
{ | ||
if (!hasValue()) | ||
|
@@ -661,6 +850,20 @@ UsdAttributeColorFloat3::create(const UsdSceneItem::Ptr& item, const PXR_NS::Usd | |
return attr; | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
//------------------------------------------------------------------------------ | ||
// UsdAttributeColorFloat4: | ||
//------------------------------------------------------------------------------ | ||
|
||
/*static*/ | ||
UsdAttributeColorFloat4::Ptr | ||
UsdAttributeColorFloat4::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr) | ||
{ | ||
auto attr = std::make_shared<UsdAttributeColorFloat4>(item, usdAttr); | ||
return attr; | ||
} | ||
#endif | ||
|
||
//------------------------------------------------------------------------------ | ||
// UsdAttributeInt3: | ||
//------------------------------------------------------------------------------ | ||
|
@@ -673,6 +876,20 @@ UsdAttributeInt3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribu | |
return attr; | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
//------------------------------------------------------------------------------ | ||
// UsdAttributeFloat2: | ||
//------------------------------------------------------------------------------ | ||
|
||
/*static*/ | ||
UsdAttributeFloat2::Ptr | ||
UsdAttributeFloat2::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr) | ||
{ | ||
auto attr = std::make_shared<UsdAttributeFloat2>(item, usdAttr); | ||
return attr; | ||
} | ||
#endif | ||
|
||
//------------------------------------------------------------------------------ | ||
// UsdAttributeFloat3: | ||
//------------------------------------------------------------------------------ | ||
|
@@ -685,6 +902,20 @@ UsdAttributeFloat3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttri | |
return attr; | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
//------------------------------------------------------------------------------ | ||
// UsdAttributeFloat4: | ||
//------------------------------------------------------------------------------ | ||
|
||
/*static*/ | ||
UsdAttributeFloat4::Ptr | ||
UsdAttributeFloat4::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr) | ||
{ | ||
auto attr = std::make_shared<UsdAttributeFloat4>(item, usdAttr); | ||
return attr; | ||
} | ||
#endif | ||
|
||
//------------------------------------------------------------------------------ | ||
// UsdAttributeDouble3: | ||
//------------------------------------------------------------------------------ | ||
|
@@ -697,6 +928,32 @@ UsdAttributeDouble3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttr | |
return attr; | ||
} | ||
|
||
#if (UFE_PREVIEW_VERSION_NUM >= 4015) | ||
//------------------------------------------------------------------------------ | ||
// UsdAttributeMatrix3d: | ||
//------------------------------------------------------------------------------ | ||
|
||
/*static*/ | ||
UsdAttributeMatrix3d::Ptr | ||
UsdAttributeMatrix3d::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr) | ||
{ | ||
auto attr = std::make_shared<UsdAttributeMatrix3d>(item, usdAttr); | ||
return attr; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
// UsdAttributeMatrix4d: | ||
//------------------------------------------------------------------------------ | ||
|
||
/*static*/ | ||
UsdAttributeMatrix4d::Ptr | ||
UsdAttributeMatrix4d::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr) | ||
{ | ||
auto attr = std::make_shared<UsdAttributeMatrix4d>(item, usdAttr); | ||
return attr; | ||
} | ||
#endif | ||
|
||
#if 0 | ||
// Note: if we were to implement generic attribute setting (via string) this | ||
// would be the way it could be done. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support 2 and 4 component vectors. Still works pre-0.4.15.