-
Notifications
You must be signed in to change notification settings - Fork 202
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
Maya-128422 Override PrimReader #3164
Maya-128422 Override PrimReader #3164
Conversation
lib/mayaUsd/fileio/primReader.h
Outdated
/// This static function is expected for all shader readers and allows | ||
/// declaring how well this class can support the current context: | ||
MAYAUSD_CORE_PUBLIC | ||
static ContextSupport CanImport(const UsdMayaJobImportArgs& importArgs); |
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.
Would it bring even more benefit to pass along the CanImport method, the prim being imported so the CanImport method can inspect the prim and see it matches possible even more restrictive conditions for the reader to be appropriate? for example, a given LightPrim having attributes specializing the import (using a specific reader) but otherwise, the user would default back to the Maya Light importer. It would add an even wider scope of possibilities for the reader to be filtered based, not only the arguments being passed, but also on the prim description they are handling.
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.
That feature would be harder to impement and it may have a negative performance impact during the import, so I would wait with implementing it until we have a specific customer request.
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.
Actually, I just double-checked and we call UsdMayaPrimReaderRegistry::FindOrFallback for every single prim we exprort, so implementing this feature will not be that hard as I thought. And since we call FindOrFallback on every prim (although we don't have to now), the performance impact is already there.
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.
Hi @calligrapheric. Neil proposed a way to set priority of readers is through JobContext, so that customers can specify which reader to use for a certain Prim type. Do you think that will solve the situation you mentioned? If so I think the job context does provide more flexibility to customers.
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.
@samuelliu-adsk - it would not solve the issue as I am not suggesting to replace the default Maya reader but to enable the reader registry to make a better discrimination from the available readers for a prim type. The same Prim type could contain or not vendor specific attributes that would be of interest for a given reader. If the prim attributes can be inspected at the CanImport call, it would enable the reader to report it supports the specialized prim or not, otherwise falling back to the default Maya reader. That is my suggestion. I am not against the JobContext idea, but I think that using the CanImport facility is easier on users for now.
The 3ds Max prim writers are working in a similar fashion and it brings flexibility.
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.
Hi @calligrapheric. Good point. For this PR I think we can focus on CanImport for now.
a given LightPrim having attributes specializing the import (using a specific reader) but otherwise, the user would default back to the Maya Light importer
After some thoughts, I think it's a good design but I also doubt inspecting the prim on our side will do much help...
- What if the customer wants to override the default prim reader regardless it contains special attributes or not? In that case we will be forcing it back to default reader..
- Shouldn't the customized prim reader be able to handle non-special attributes already? If not they can't read prims properly..
Let me know if I'm wrong! I would love to hear more suggestions from you!
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.
The CanImport
static method only receives the import args. I propose we add the UsdPrim the PrimReader is asked to act on. To answer your points:
- In my proposition, the PrimReader has the option of inspecting the UsdPrim. To override the default reader, it simply needs to reply it is a supported reader regardless of the UsdPrim content, as in your PR. If two plugins provide a PrimReader supporting the same prim type, then we would need Neil's JobContext for the user to select the one to keep.
- In the actual state, the PrimReader
Read
method can handle all attributes (standard or vendor specific). That is not the question. But theCanImport
static method has no clue on which UsdPrim (besides its type) it is replying.
lib/mayaUsd/fileio/shaderReader.h
Outdated
@@ -41,6 +41,7 @@ class UsdMayaShaderReader : public UsdMayaPrimReader | |||
MAYAUSD_CORE_PUBLIC | |||
UsdMayaShaderReader(const UsdMayaPrimReaderArgs&); | |||
|
|||
/* |
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.
This block should be deleted, not just commented out
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.
Looks good to me. The only thing is to remove the commented out code.
…to inspect the prim
TF_DEBUG(PXRUSDMAYA_REGISTRY) | ||
.Msg("No usdMaya reader plugin for TfType %s. No maya plugin.\n", typeName.GetText()); | ||
_reg[typeName] = nullptr; | ||
//_reg[typeName] = nullptr; |
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.
might want to remove this commented line
c5f4362
to
96e3e55
Compare
static void Register( | ||
boost::python::object cl, | ||
const std::string& typeName, | ||
const UsdMayaPrimReaderRegistry::ContextPredicateFn pred = nullptr) |
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.
The FactoryFnWrapper already handles that situation (see line 129)
maybe use something along those lines
static void Register(boost::python::object cl, const std::string& typeName)
{
bool updated = false;
FactoryFnWrapper fn = FactoryFnWrapper::Register(cl, typeName, updated);
if (!updated)
{
auto type = TfType::FindByName(typeName);
MayaUsdPrimReaderRegistry::Register(type, fn, fn, true);
}
}
TF_ADD_ENUM_NAME(UsdMayaShaderReader::ContextSupport::Fallback, "Fallback"); | ||
TF_ADD_ENUM_NAME(UsdMayaShaderReader::ContextSupport::Unsupported, "Unsupported"); | ||
} | ||
|
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.
might also want to remove line 572
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.
I am not familiar with this code. I had a quick look at the changes and they look ok to me. I'll let the two other reviewers provide code review feedback.
The Register functions are overloaded to provide backward compatibility. Registering a prim reader without providing ContextSupport will be treated as "fallback"