def testSkelMissingJointFromDagPose(self): """ Check that dagPoses that don't contain all desired joints issue an appropriate warning """ mayaFile = os.path.join(self.inputPath, "UsdExportSkeletonTest", "UsdExportSkeletonBindPoseMissingJoints.ma") cmds.file(mayaFile, force=True, open=True) usdFile = os.path.abspath('UsdExportBindPoseMissingJointsTest.usda') joints = cmds.listRelatives('joint_grp', allDescendents=True, type='joint') bindMembers = cmds.dagPose('dagPose1', q=1, members=1) nonBindJoints = [j for j in joints if j not in bindMembers] self.assertEqual(nonBindJoints, [u'joint4']) delegate = UsdUtils.CoalescingDiagnosticDelegate() cmds.select('joint_grp') cmds.mayaUSDExport(mergeTransformAndShape=True, file=usdFile, shadingMode='none', exportSkels='auto', selection=True) messages = delegate.TakeUncoalescedDiagnostics() warnings = [x.commentary for x in messages if x.diagnosticCode == Tf.TF_DIAGNOSTIC_WARNING_TYPE] missingJointWarnings = [x for x in warnings if 'is not a member of dagPose' in x] self.assertEqual(len(missingJointWarnings), 1) self.assertIn("Node 'joint4' is not a member of dagPose 'dagPose1'", missingJointWarnings[0])
def CheckCompliance(self, inputFile): from pxr import Sdf, Usd, UsdUtils if not Usd.Stage.IsSupportedFile(inputFile): _AddError("Cannot open file '%s' on a USD stage." % args.inputFile) return # Collect all warnings using a diagnostic delegate. delegate = UsdUtils.CoalescingDiagnosticDelegate() usdStage = Usd.Stage.Open(inputFile) stageOpenDiagnostics = delegate.TakeUncoalescedDiagnostics() for rule in self._rules: rule.CheckStage(usdStage) rule.CheckDiagnostics(stageOpenDiagnostics) with Ar.ResolverContextBinder(usdStage.GetPathResolverContext()): # This recursively computes all of inputFiles's external # dependencies. (allLayers, allAssets, unresolvedPaths) = \ UsdUtils.ComputeAllDependencies(Sdf.AssetPath(inputFile)) for rule in self._rules: rule.CheckUnresolvedPaths(unresolvedPaths) rule.CheckDependencies(usdStage, allLayers, allAssets) if self._rootPackageOnly: rootLayer = usdStage.GetRootLayer() if rootLayer.GetFileFormat().IsPackage(): packagePath = Ar.SplitPackageRelativePathInner( rootLayer.identifier)[0] self._CheckPackage(packagePath) else: self._AddError( "Root layer of the USD stage (%s) doesn't belong to " "a package, but 'rootPackageOnly' is True!" % Usd.Describe(usdStage)) else: # Process every package just once by storing them all in a set. packages = set() for layer in allLayers: if _IsPackageOrPackagedLayer(layer): packagePath = Ar.SplitPackageRelativePathInner( layer.identifier)[0] packages.add(packagePath) self._CheckLayer(layer) for package in packages: self._CheckPackage(package) # Traverse the entire stage and check every prim. from pxr import Usd # Author all variant switches in the session layer. usdStage.SetEditTarget(usdStage.GetSessionLayer()) allPrimsIt = iter( Usd.PrimRange.Stage(usdStage, Usd.TraverseInstanceProxies())) self._TraverseRange(allPrimsIt, isStageRoot=True)
def __init__(self, inputFile, arkit=False, skipARKitRootLayerCheck=False, rootPackageOnly=False, skipVariants=False, verbose=False): self._arkit = arkit self._skipARKitRootLayerCheck = skipARKitRootLayerCheck self._rootPackageOnly = rootPackageOnly self._doVariants = not skipVariants self._verbose = verbose self._failedChecks = [] self._errors = [] self._violatedRules = set() self._checkedPackages = set() from pxr import Ar, Sdf, Usd, UsdUtils if not Usd.Stage.IsSupportedFile(inputFile): _AddError("Cannot open file '%s' on a USD stage." % args.inputFile) return # Collect all warnings using a diagnostic delegate. delegate = UsdUtils.CoalescingDiagnosticDelegate() usdStage = Usd.Stage.Open(inputFile) allDiagnostics = delegate.TakeUncoalescedDiagnostics() if self._arkit: for diag in allDiagnostics: # "_ReportErrors" is the name of the function that issues # warnings about unresolved references, sublayers and other # composition arcs. if '_ReportErrors' in diag.sourceFunction and \ 'usd/stage.cpp' in diag.sourceFileName: self._AddFailedCheck(diag.commentary, ruleNum=4) with Ar.ResolverContextBinder(usdStage.GetPathResolverContext()): # This recursively computes all of inputFiles's external # dependencies. (allLayerDeps, allAssetDeps, unresolvedPaths) = \ UsdUtils.ComputeAllDependencies(Sdf.AssetPath(inputFile)) self._CheckDependencies(usdStage, allLayerDeps, allAssetDeps, unresolvedPaths) self._CheckStage(usdStage, allLayerDeps)
# KIND, either express or implied. See the Apache License for the specific # language governing permissions and limitations under the Apache License. # from pxr import Tf, Sdf, UsdUtils # Constructing an sdf path with "" gives a tf warning def _genWarning(): Tf.Warn('.') EXPECTED_LINE_NO = 30 EXPECTED_FUNC_NAME = '__main__._genWarning' delegate = UsdUtils.CoalescingDiagnosticDelegate() # Test dumping of diagnostics (this will be compared in baseline/output.txt) for i in range(0, 10): _genWarning() delegate.DumpCoalescedDiagnosticsToStdout() # Test collection of unfiltered diagnostics for i in range(0, 3): _genWarning() unfiltered = delegate.TakeUncoalescedDiagnostics() assert len(unfiltered) == 3 for i in range(0, 3): assert unfiltered[i].sourceLineNumber == EXPECTED_LINE_NO