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

Instance import, part 1 #794

Merged
merged 6 commits into from
Oct 16, 2020
Merged

Instance import, part 1 #794

merged 6 commits into from
Oct 16, 2020

Conversation

JGamache-autodesk
Copy link
Collaborator

Brings in the original @sirpalee / @pmolodo instancing code from the following Luma branch.

This code adds an Instance Mode option on import to either build instances or flatten the scene.

Updates:

  • Merged with latest dev
  • masters are loaded recursively and on demand, allowing import of instances inside other instances.
  • added unit tests for instance imports based on USD instancing scenarios by @pmolodo

Bug fixes:

  • Saves the Maya shape name instead of using the generic name "Shape"
  • XformOp errors on import could result in geometries with (0, 0, 0) scaling. Will now default to (1, 1, 1).

Fixes #340, fixes #723, fixes #310

Still todo:
The following issues have been found and will likely be fixed in a follow-up update:

  • Extra transforms get inserted between the instantiation transform and the instanced shape (also happens for regular non-instanced hierarchies where shapes in the middle of the hierarchy also gain a transform).
  • Instanced hierarchies will export as piecewise instances. A transform where all children are instances should generate a single USD master.

sirpalee and others added 3 commits February 26, 2020 11:32
…instances

# Conflicts:
#	lib/mayaUsd/fileio/jobs/jobArgs.cpp
#	lib/mayaUsd/fileio/jobs/jobArgs.h
#	lib/mayaUsd/fileio/jobs/readJob.cpp
#	lib/mayaUsd/fileio/jobs/readJob.h
#	plugin/pxr/maya/lib/usdMaya/importCommand.cpp
Copy link
Contributor

@mattyjams mattyjams left a comment

Choose a reason for hiding this comment

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

I think I'll have to defer to @pmolodo for the final approval since he's much more knowledgable on this subject than I am, but it generally looks good to me. I had just a few mostly minor notes.

const UsdPrimRange range = UsdPrimRange::PreAndPostVisit(rootPrim);
_PrimReaderMap primReaderMap;
const UsdPrimRange range =
mArgs.instanceMode == UsdMayaJobImportArgsTokens->flatten ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect that there might some day be more instanceMode options, or could this equality be replaced with buildInstances from above?

Copy link
Collaborator Author

@JGamache-autodesk JGamache-autodesk Oct 13, 2020

Choose a reason for hiding this comment

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

Not sure about that one. With the current code, using instanceMode=anything_but_flatten_or_build would end up not loading any instance, which was the old behavior before this patch.

Is that a valid mode that should be preserved in the Import options? I would call it "ignore"...

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think it makes sense to preserve the behavior where instances in USD are ignored. If I'm reading the changes in jobArgs.cpp correctly, I think we'll fallback to building instances if instanceMode was given something bogus?

My main thought here was just whether we could re-use the buildInstances boolean from above. No big deal though.

pCube1_pCubeShape1 [Scope]
pCubeShape1 [Mesh]

The goal would be for Maya to skip all [Scope] items and end up with:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh... so maybe this explains the missing type names in the USD above. Prims with the Scope type name are different from the typeless prims we have at the moment though. Do we really mean Scope here and we should add that type name above, or should this read typeless here instead?

Comment on lines 85 to 86
primPath="/",
instanceMode="buildInstances")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this setting of primPath can be removed, since that should be the default? Similarly, instanceMode=buildInstances looks like it was made the default as well, but I'm ok with that staying since I think it makes the intent of the test clear.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Isn't primPath the defaultPrim, which would be pCube1 in the test scenes?

Copy link
Contributor

@pmolodo pmolodo left a comment

Choose a reason for hiding this comment

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

So, I don't have too much additional to add to what @mattyjams said - mostly looks good.

My one concern is that, if we do release as is, and later want to support "cleaning up" the "extra" Scope args, it will obviously change the resulting maya scene. If we release this as is, people may become dependent on the behavior implemented in this PR... and I'd hate to lock us into having the unnecessary xforms. Are we ok with making a potentially breaking change to eliminate them in the future?

}
}

over "InstanceSources"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Prototypes would be bad too, because in the latest updates to USD, they're replacing "master" with "Prototype". (Which is going to require a some API changes here, but there's already post-20.08-incompatibilities in the existing maya_usd codebase, so we can punt on that for now).

And if we can't use Prototypes... then I might prefer the current InstanceSources over something which is essentially generic, like InstanceModels or InstanceAssets. I see where you're coming from, but:

  • sources is NOT the same term as the "official" term (which was masters, and is now prototypes)
  • conceptually they DO convey something similar... but the basic problem is that what we're trying to do IS something conceptually similar to what the "official" USD-created masters do. So it's a bit of a catch 22 - any name that accurately describes or invokes what the purpose here is automatically going to be treading pretty close to "masters"/"prototypes". So I'd rather go with the option that has some descriptive value, as long as it avoids the "official" term.

@mattyjams , would it help if it were named something more maya-centric, like say, MayaExportedInstanceSources? If we eventually want to implement special behavior for prims located here (which we will, if we ever do the eliminate-Scopes thing later), then it would be good to have it named a bit less generically, anyway.

Also investigated and fixed a few asserts poppping up in the test suite.
…instances

# Conflicts:
#	lib/mayaUsd/fileio/jobs/jobArgs.cpp
#	lib/mayaUsd/fileio/jobs/jobArgs.h
Copy link
Contributor

@pmolodo pmolodo 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. I'd still like to change the name of "InstanceSources" to be more maya-specific, but I suppose we can make that a separate PR if you'd prefer.

if (status) {
while (masterNode.childCount()) {
masterNode.removeChildAt(masterNode.childCount() - 1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some sort of error or something that happens if you don't remove the children before deleting the parent? Since these child removals aren't done via a MDGModifier, will this undo properly? (Though - not sure if the the import command as a whole is even undoable...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With the special builds we use, we get asserts about incorrect children counts on file->new because the instance count and children count differ. It is not something you will see with a shipped Maya cut.

}
}

over "InstanceSources"
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think it would, but I don't think it should be a problem to change it there too...

Copy link
Contributor

@mattyjams mattyjams 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!

const UsdPrimRange range = UsdPrimRange::PreAndPostVisit(rootPrim);
_PrimReaderMap primReaderMap;
const UsdPrimRange range =
mArgs.instanceMode == UsdMayaJobImportArgsTokens->flatten ?
Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think it makes sense to preserve the behavior where instances in USD are ignored. If I'm reading the changes in jobArgs.cpp correctly, I think we'll fallback to building instances if instanceMode was given something bogus?

My main thought here was just whether we could re-use the buildInstances boolean from above. No big deal though.

upAxis = "Y"
)

def Xform "pCube1" (
Copy link
Contributor

Choose a reason for hiding this comment

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

One small nit-pick with the type names here, but it looks like we ended up with type names everywhere. I would think the majority of the time when you have a prim referencing other prims, you likely want a typeless def for the prim doing the referencing. I think in most cases below, the type names between the referencer and the referenced agree, so I don't think it's a practical issue here. Typeless defs let the type of the referenced prim shine through to the referencer whatever that type may be, so you don't have to match the types yourself. Specifying a different type on the referencer will actually change the type of the composed prim, which is pretty rarely what you intend.

@JGamache-autodesk JGamache-autodesk added the ready-for-merge Development process is finished, PR is ready for merge label Oct 16, 2020
@kxl-adsk kxl-adsk merged commit 56b29e2 into dev Oct 16, 2020
@kxl-adsk kxl-adsk deleted the pr/pxr/maya_importing_instances branch October 16, 2020 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
import-export Related to Import and/or Export ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
6 participants