def test_RoundTrip(self): usdFile = 'original.usda' abcFile = 'converted.abc' time = Usd.TimeCode.EarliestTime() self.assertTrue(UsdAbc._WriteAlembic(usdFile, abcFile)) origStage = Usd.Stage.Open(usdFile) stage = Usd.Stage.Open(abcFile) prim = stage.GetPrimAtPath('/World/geom/CenterCross/UpLeft') creaseIndices = prim.GetAttribute('creaseIndices').Get(time) expectedCreaseIndices = [ 0, 1, 3, 2, 0, 4, 5, 7, 6, 4, 1, 5, 0, 4, 2, 6, 3, 7 ] for c, e in zip(creaseIndices, expectedCreaseIndices): self.assertTrue(Gf.IsClose(c, e, 1e-5)) creaseLengths = prim.GetAttribute('creaseLengths').Get(time) expectedCreaseLengths = [5, 5, 2, 2, 2, 2] for c, e in zip(creaseLengths, expectedCreaseLengths): self.assertTrue(Gf.IsClose(c, e, 1e-5)) creaseSharpnesses = prim.GetAttribute('creaseSharpnesses').Get(time) expectedCreaseSharpness = [1000, 1000, 1000, 1000, 1000, 1000] for c, e in zip(creaseSharpnesses, expectedCreaseSharpness): self.assertTrue(Gf.IsClose(c, e, 1e-5)) faceVertexCounts = prim.GetAttribute('faceVertexCounts').Get(time) expectedFaceVertexCounts = [4, 4, 4, 4, 4, 4] for c, e in zip(faceVertexCounts, expectedFaceVertexCounts): self.assertTrue(Gf.IsClose(c, e, 1e-5)) # The writer will revrse the orientation because alembic only supports # left handed winding order. faceVertexIndices = prim.GetAttribute('faceVertexIndices').Get(time) expectedFaceVertexIndices = [ 2, 6, 4, 0, 4, 5, 1, 0, 6, 7, 5, 4, 1, 5, 7, 3, 2, 3, 7, 6, 0, 1, 3, 2 ] for c, e in zip(faceVertexIndices, expectedFaceVertexIndices): self.assertTrue(Gf.IsClose(c, e, 1e-5)) # Check layer/stage metadata transfer self.assertEqual(origStage.GetDefaultPrim().GetPath(), stage.GetDefaultPrim().GetPath()) self.assertEqual(origStage.GetTimeCodesPerSecond(), stage.GetTimeCodesPerSecond()) self.assertEqual(origStage.GetFramesPerSecond(), stage.GetFramesPerSecond()) self.assertEqual(origStage.GetStartTimeCode(), stage.GetStartTimeCode()) self.assertEqual(origStage.GetEndTimeCode(), stage.GetEndTimeCode()) self.assertEqual(UsdGeom.GetStageUpAxis(origStage), UsdGeom.GetStageUpAxis(stage))
def test_upAxis(self): stage = Usd.Stage.CreateInMemory() self.assertTrue(stage) self.assertEqual(UsdGeom.GetStageUpAxis(stage), UsdGeom.GetFallbackUpAxis()) self.assertTrue(UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.y)) self.assertEqual(UsdGeom.GetStageUpAxis(stage), UsdGeom.Tokens.y) with Usd.EditContext(stage, Usd.EditTarget(stage.GetSessionLayer())): self.assertTrue(UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.z)) self.assertEqual(UsdGeom.GetStageUpAxis(stage), UsdGeom.Tokens.z) # Setting illegal value should raise with self.assertRaises(Tf.ErrorException): UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.x)
def __init__(self, *args, **kwargs): super(RootNode, self).__init__(*args, **kwargs) if self._layer is not None: self.parameter('defaultPrim').setValue(self._layer.defaultPrim) if self._layer.HasStartTimeCode(): self.parameter('startTimeCode').setValue( self._layer.startTimeCode) if self._layer.HasEndTimeCode(): self.parameter('endTimeCode').setValue(self._layer.endTimeCode) # how to get layer's upAxis, not stage? if self._stage is not None: upAxis = UsdGeom.GetStageUpAxis(self._stage) self.parameter('upAxis').setValue(upAxis)
def CheckStage(self, usdStage): from pxr import UsdGeom if not usdStage.HasAuthoredMetadata(UsdGeom.Tokens.upAxis): self._AddFailedCheck("Stage does not specify an upAxis.") elif self._consumerLevelChecks: upAxis = UsdGeom.GetStageUpAxis(usdStage) if upAxis != UsdGeom.Tokens.y: self._AddFailedCheck( "Stage specifies upAxis '%s'. upAxis should" " be '%s'." % (upAxis, UsdGeom.Tokens.y)) if not usdStage.HasAuthoredMetadata(UsdGeom.Tokens.metersPerUnit): self._AddFailedCheck("Stage does not specify its linear scale " "in metersPerUnit.") if self._assetLevelChecks: defaultPrim = usdStage.GetDefaultPrim() if not defaultPrim: self._AddFailedCheck( "Stage has missing or invalid defaultPrim.")
def _CheckStage(self, usdStage, allLayers): if self._arkit: from pxr import UsdGeom if not self._skipARKitRootLayerCheck: self._CheckARKitCompatibility(usdStage, allLayers) upAxis = UsdGeom.GetStageUpAxis(usdStage) if upAxis != UsdGeom.Tokens.y: self._AddFailedCheck( "Stage has upAxis '%s'. upAxis should be '%s'." % (upAxis, UsdGeom.Tokens.y), ruleNum=7) if self._rootPackageOnly: self._CheckRootPackage(usdStage) return 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 set_stage_up_axis(self): up_axis = UsdGeom.GetStageUpAxis(self.stage) if up_axis == UsdGeom.Tokens.y: self.stage_up_axis = 'y' elif up_axis == UsdGeom.Tokens.z: self.stage_up_axis = 'z'
def CheckStage(self, usdStage): from pxr import UsdGeom upAxis = UsdGeom.GetStageUpAxis(usdStage) if upAxis != UsdGeom.Tokens.y: self._AddFailedCheck("Stage has upAxis '%s'. upAxis should be " "'%s'." % (upAxis, UsdGeom.Tokens.y))
def import_usd(app, file_path, options, xsi_toolkit): if DEBUG_MODE: imp.reload(utils) imp.reload(prim_xform) imp.reload(prim_mesh) imp.reload(prim_pointcloud) imp.reload(prim_hair) imp.reload(prim_light) imp.reload(prim_camera) imp.reload(materials) start_time = time.time() progress_bar = xsi_toolkit.ProgressBar progress_bar.Caption = "" progress_bar.CancelEnabled = False progress_bar.Visible = True is_clear = options.get("clear_scene", False) options["instances"] = { } # key - path of the imported master object, value - link to the corresponding xsi-object options["file_path"] = file_path options["project_path"] = app.ActiveProject3.Path options["file_name"] = utils.get_file_name_from_path( file_path) # without extension options["import_camera"] = False cameras_to_remove = [] if is_clear: progress_bar.Caption = "Clear the scene" if options["is_materials"]: # clear material library materials.import_clear_library(app, options["file_name"]) scene_root = app.ActiveProject2.ActiveScene.Root for child in scene_root.Children: if utils.is_contains_camera(child): cameras_to_remove.append(child) else: progress_bar.Caption = "Clear the scene: delete " + child.Name app.DeleteObj("B:" + child.Name) stage = Usd.Stage.Open(file_path) up_axis = UsdGeom.GetStageUpAxis(stage) options["up_axis"] = up_axis # Y or Z (for Softimage Y is more convinient) root = stage.GetPseudoRoot() for item in root.GetChildren(): import_item(app, options, item, stage, app.ActiveProject2.ActiveScene.Root, progress_bar, is_root=True) if is_clear: progress_bar.Caption = "Final clean" for cam_index in range( len(cameras_to_remove) + (0 if options["import_camera"] else -1) ): # delete all cameras except the last one, if there are no any new cameras in the imported scene app.DeleteObj("B:" + cameras_to_remove[cam_index].Name) progress_bar.Visible = False finish_time = time.time() print("[USD Import]: total import time " + str(finish_time - start_time) + " seconds")
def set_default_prim(source, target): default_prim = source.GetDefaultPrim() target.SetDefaultPrim(default_prim) axis = UsdGeom.GetStageUpAxis(source) UsdGeom.SetStageUpAxis(target, axis)
materialName2Index[matName] = r_model.Materials.__len__() - 1 else: attr.LayerIndex = materialName2Index[matName] r_model.Objects.AddMesh(r_mesh, attr) for child in prim.GetChildren(): process_child(child, transform) # # the 'root' pseudoRoot = stage.GetPseudoRoot() rootPrims = pseudoRoot.GetChildren() initialTransform = Gf.Transform() # an Identity # Check for Y up upAxis = UsdGeom.GetStageUpAxis(stage) if upAxis == 'Y': ninetyAroundX = Gf.Rotation((1, 0, 0), 90) initialTransform.SetRotation(ninetyAroundX) # Begin iteration for prim in rootPrims: process_child(prim, initialTransform) # done r_model.Write(sys.argv[2], 5)