Skip to content
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

USDGeomScope support in Proxy Shape #185

Merged
merged 9 commits into from
Jan 29, 2020
Merged

Conversation

murphyeoin
Copy link
Contributor

@murphyeoin murphyeoin commented Dec 20, 2019

Description

Currently any Prim of type USDGeomScope will get translated to an AL_USDMaya_Transform on any relevant Proxy Shape related operation e.g;

  • AL_usdmaya_ProxyShapeImportAllTransforms
  • AL_usdmaya_TranslatePrim
  • transiently on selection
    etc.

We want to avail of 2 characteristics of Scopes when translating to maya:

  1. Their maya transforms are locked
  2. They cannot be animated and therefore don't need a time input

We now translate those to a new MPxTransform derived node called "Scope"

What was done?

  • created Scope MPxNode
  • created BasicTransformationMatrix which is used by the Scope MPxNode
  • have the original Transform and TransformationMatrix inherit from them as they are relatively simple and lightweight
  • updated any code which makes assumptions about AL_usdmaya_transform being the only transform type (most of this is ProxyShape/Selection related) and ideally use the base Scope class pointer
  • update code to create Scope nodes where appropriate (i.e mostly when translating from USDGeomScope nodes)
  • refactored the transform node creation in ProxyShapeSelection - there were 2 methods performing more or less the same node creation
  • add/update some tests etc

Doing this work made me remember we have a weird hack in AL_USDMaya which allows creation of arbitrary transform nodes. This works by tagging an Xform in USD with the
"al_usdmaya_transformType" metadatum... It allows you to create custom transform types without needing to add a proper factory/plugin system or create an explicit dependency on the type - basically a poor man's factory. How this stuff interacts with AL_usdmaya transforms and scopes is anyone's guess really. At least the code is mostly in one place now

Future work

  • add standard import/export functionality for Scopes - wasn't needed by us, but should be done to make the feature complete
  • as mentioned above the effort could be made to refactor the code to make transforms a plugin - currently the code for supporting AL_USDMaya_Transform, AL_USDMaya_Scope, and user-defined types is smeared a bit all over the codebase - although this refactor has made it a bit more general (most code should work with any type that derives from Scope).
  • Consider having an interface for the custom Transform types (currently Scope, Transform) and matrices (BasicTransformationMatrix, TransformationMatrix) rather than having one inherit from the other

* create Scope MPxNode, MTransformationMatrix, add/update some tests etc

* filled in a few missing methods and conditionals - tests are passing now

* fleshing out scope behaviour

* scope tests now working as expected

* selection store support for scope

* add todos

* basic bounding box working - spliced in Dan Englessons improvements to boundingBox() and a mixed hierarchy of scope/xforms/geom seems to frame in maya-2019

* support time

* rename transform() method to getTransformNode() to make it easier to find

* Transform now subclasses from Scope

* refactored Scope/Transform nodes and their TransformationMatrix classes to an inheritance relationship to support nicer  handling of new/multiple types

* addressed code review comments

* replace transform2() method with more sensible getTransMatrix()

* show node type when print refcounts

* addressed hopefully final review comnents

* refactor proxy select node creation logic, prioritise custom node types over AL_USDMaya scope/transform

* extract mayaNodeCreation from makeUsdTransformChain for eventual reuse

* update makeUsdTransformsInternal to use new createMayaNode method

* dynamic cast when requesting transform type to avoid problems with custom types

* remove todos, update unit test

* A slight change so that Transform now inherits the attributes from Scope, rather than making new copies of them.

* Check for both Scope::kTypeId and Transform::kTypeId

* reordered the node registration
kreppene pushed a commit to kreppene/maya-usd that referenced this pull request Jan 7, 2020
@kxl-adsk
Copy link

@pilarmolinalopez can you help review this change?

@fowlertADSK fowlertADSK self-requested a review January 21, 2020 18:20
@fowlertADSK
Copy link
Contributor

Hey Eoin. I started writing up some comments/questions as part of a review and I think the direction most of my thoughts were going were towards things like how general the transform classes are and if some of this might belong in a common area instead of just being in the AL plugin (similar to the discussion in PR #158). I’ve been slowed down by a bunch of other stuff, but maybe you can answer that question before I spend too much time on it. Do we think that there is functionality here that would be nice to have down in the core lib next to or as part of the proxy base class that is shared with the other plugins?

I think the answer is “Yes, eventually”, but right now it’s only the AL plugin that would use it.

@murphyeoin
Copy link
Contributor Author

Hi Tim, in this case the functionality is very AL Proxy Shape live interaction workflow specific - there's not even a general maya->USD Scope importer/exporter..

@kxl-adsk
Copy link

Totally makes sense, Eoin.

@@ -1637,7 +1637,9 @@ bool ProxyShape::lockTransformAttribute(const SdfPath& path, const bool lock)
r.setLocked(lock);
s.setLocked(lock);

if (lock && MFnDependencyNode(lockObject).typeId() == AL_USDMAYA_TRANSFORM)
MFnDependencyNode fn(lockObject);
Scope* transformNode = static_cast<Scope*>(fn.userNode());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this one and the one on line 2144 be dynamic_cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right -It would be OK to use static_cast if the data had been pre-filtered to only allow Scopes or classes derived from it, or we were doing some kind of checking earlier on in the method, but as "lockObject" can be any maya object we should either be doing those checks or using a dynamic_cast to check that it's a valid Scope at run -time... (add some minor performance cost). Will update. Thanks!

// that has ANY attribute that connected to rotateAxis, it will cause the rotateAxis to evaluate INCORRECTLY,
// even on the BASE transform class!
// See this gist for full reproduction details:
// https://gist.github.com/elrond79/f9ddb277da3eab2948d27ddb1f84aba0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you happen to know if we have an internal bug for this? If not we should get one logged. It does sound familiar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure...(If that was addressed to me)

@fowlertADSK
Copy link
Contributor

Appreciate the added tests for the new class, have you only been able to run them on Linux? If not, I'll build it and run them locally tomorrow morning.

@murphyeoin
Copy link
Contributor Author

Hi Tim, yes have only been able to run on Linux. This code has been in production for a while though, so I think it's mostly error free

Copy link
Contributor

@pilarmolinalopez pilarmolinalopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same question as Tim has regarding static_cast vs dynamic_cast in those lines. Everything else looks good, I'll mark it as approved on my part waiting on that.

I was also able to build it and run the unit tests in Linux.

m_primPath = addStringAttr("primPath", "pp", kReadable | kWritable | kStorable | kConnectable | kAffectsWorldSpace, true);
m_inStageData = addDataAttr("inStageData", "isd", MayaUsdStageData::mayaTypeId, kWritable | kStorable | kConnectable | kHidden | kAffectsWorldSpace);
addInheritedAttr("primPath");
addInheritedAttr("inStageData");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I am spending some time today trying to get it built and see if the tests pass. This is a line you'll have problems with. Paul removed this function and replaced it with something slightly different. See commit 476826f

@fowlertADSK
Copy link
Contributor

I managed to pull your changes into the branch where Hamed and I were working on getting the tests to run/pass on Windows and I think I got a successful run (after changing a couple lines where the functions you were using had been removed). You'll have to update those but then I'd be ready to close this one.

@murphyeoin
Copy link
Contributor Author

@fowlertADSK @kxl-adsk addressed comments, merged latest dev

Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix compilation errors in strict mode


/// \brief return the prim this transform matrix is attached to
/// \return the prim this transform matrix is controlling
inline const UsdPrim& prim() const

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/git/usd/maya-usd/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/TransformationMatrix.h:310:25: error: 'prim' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override]
inline const UsdPrim& prim() const
^
/git/usd/maya-usd/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/BasicTransformationMatrix.h:73:26: note: overridden virtual function is here
virtual const UsdPrim& prim() const

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, there is no value in making the virtual method inlined.

//--------------------------------------------------------------------------------------------------------------------
/// Data members
//--------------------------------------------------------------------------------------------------------------------
bool updateTransformInProgress = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/git/usd/maya-usd/plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/Scope.h:110:8: error: private field 'updateTransformInProgress' is not used [-Werror,-Wunused-private-field]
bool updateTransformInProgress = false;

if (ptr->typeId()==AL::usdmaya::nodes::Transform::kTypeId)
{
//It's a transform
AL::usdmaya::nodes::BasicTransformationMatrix* matrix = ptr->transform();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/git/usd/maya-usd/plugin/al/plugin/AL_USDMayaTestPlugin/AL/usdmaya/nodes/test_ScopeMatrix.cpp:130:56: error: unused variable 'matrix' [-Werror,-Wunused-variable]
AL::usdmaya::nodes::BasicTransformationMatrix* matrix = ptr->transform();

@kxl-adsk
Copy link

@murphyeoin attaching patch I used to fix compilation errors.
strict_mode_patch.txt

@murphyeoin
Copy link
Contributor Author

Thanks @kxl-adsk can you confirm that running the compiler in strict mode is part of your standard testing process? If so should we just make it part of the build? (perhaps as an additional target? )

@kxl-adsk
Copy link

Yes, we run the compiler in strict mode on all platforms. You can pass it to build.py like this --build-args=",-DPXR_STRICT_BUILD_MODE=1"

@murphyeoin
Copy link
Contributor Author

Hi @kxl-adsk I fixed them in our fork and have updated. I will add the strict mode compile to our build script as the aim is that we're all testing the same thing. Any other flags in your build-args that we should know about? Thanks

@kxl-adsk
Copy link

At the moment, no, there is nothing else.

Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you!

@kxl-adsk kxl-adsk merged commit bda180b into Autodesk:dev Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants