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

Maya-128422 Override PrimReader #3164

Merged
merged 13 commits into from
Jul 11, 2023

Conversation

samuelliu-adsk
Copy link
Collaborator

@samuelliu-adsk samuelliu-adsk commented Jun 15, 2023

The Register functions are overloaded to provide backward compatibility. Registering a prim reader without providing ContextSupport will be treated as "fallback"

/// 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);

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.

Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

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.

Copy link
Collaborator Author

@samuelliu-adsk samuelliu-adsk Jun 23, 2023

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...

  1. 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..
  2. 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!

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:

  1. 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.
  2. In the actual state, the PrimReader Read method can handle all attributes (standard or vendor specific). That is not the question. But the CanImport static method has no clue on which UsdPrim (besides its type) it is replying.

@samuelliu-adsk samuelliu-adsk requested a review from vlasovi June 19, 2023 18:33
@samuelliu-adsk samuelliu-adsk marked this pull request as ready for review June 19, 2023 18:37
@@ -41,6 +41,7 @@ class UsdMayaShaderReader : public UsdMayaPrimReader
MAYAUSD_CORE_PUBLIC
UsdMayaShaderReader(const UsdMayaPrimReaderArgs&);

/*
Copy link
Collaborator

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

Copy link
Collaborator

@vlasovi vlasovi 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 to me. The only thing is to remove the commented out code.

vlasovi
vlasovi previously approved these changes Jun 20, 2023
@samuelliu-adsk samuelliu-adsk added adsk Related to Autodesk plugin import-export Related to Import and/or Export labels Jun 29, 2023
vlasovi
vlasovi previously approved these changes Jul 5, 2023
TF_DEBUG(PXRUSDMAYA_REGISTRY)
.Msg("No usdMaya reader plugin for TfType %s. No maya plugin.\n", typeName.GetText());
_reg[typeName] = nullptr;
//_reg[typeName] = nullptr;

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

@samuelliu-adsk samuelliu-adsk removed the ready-for-merge Development process is finished, PR is ready for merge label Jul 5, 2023
@samuelliu-adsk samuelliu-adsk force-pushed the samuelliu-adsk/MAYA-128422/primread-condition branch from c5f4362 to 96e3e55 Compare July 6, 2023 19:31
static void Register(
boost::python::object cl,
const std::string& typeName,
const UsdMayaPrimReaderRegistry::ContextPredicateFn pred = nullptr)

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");
}

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

@samuelliu-adsk samuelliu-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Jul 10, 2023
Copy link
Collaborator

@seando-adsk seando-adsk left a 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.

@seando-adsk seando-adsk merged commit a1c54f4 into dev Jul 11, 2023
@seando-adsk seando-adsk deleted the samuelliu-adsk/MAYA-128422/primread-condition branch July 11, 2023 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adsk Related to Autodesk plugin import-export Related to Import and/or Export ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants