コード例 #1
0
ファイル: primViewItem.py プロジェクト: simpassi/USD
    def propagateDrawMode(item,
                          primView,
                          parentDrawMode='',
                          parentDrawModeIsInherited=None):
        # If this item does not support draw mode, none of its descendants
        # can support it. Hence, stop recursion here.
        #
        # Call push() here to ensure that supportsDrawMode has been populated
        # for the item.
        item.push()
        if not item.supportsDrawMode:
            return

        from primTreeWidget import DrawModeWidget
        drawModeWidget = item.drawModeWidget
        if drawModeWidget:
            drawModeWidget.RefreshDrawMode()
        else:
            modelAPI = UsdGeom.ModelAPI(item.prim)
            item.computedDrawMode = modelAPI.ComputeModelDrawMode(
                parentDrawMode)
            item.isDrawModeInherited = item._isComputedDrawModeInherited(
                parentDrawModeIsInherited=parentDrawModeIsInherited)
            item.emitDataChanged()

        # Traverse down to children to update their drawMode.
        for child in [item.child(i) for i in xrange(item.childCount())]:
            PrimViewItem.propagateDrawMode(
                child,
                primView,
                parentDrawMode=item.computedDrawMode,
                parentDrawModeIsInherited=item.isDrawModeInherited)
コード例 #2
0
    def testExport_GeomModelAPI_MotionAPI(self):
        """Tests export with both the GeomModelAPI and MotionAPI."""
        cmds.file(new=True, force=True)
        cmds.usdImport(file=self.inputUsdFile,
                       shadingMode=[
                           ["none", "default"],
                       ],
                       apiSchema=['GeomModelAPI', 'MotionAPI'])

        newUsdFilePath = os.path.abspath('UsdAttrsNew_TwoAPIs.usda')
        # usdExport used to export all API schemas found as dynamic attributes. We now
        # require the list to be explicit, mirroring the way usdImport works.
        cmds.usdExport(file=newUsdFilePath,
                       shadingMode='none',
                       apiSchema=['GeomModelAPI', 'MotionAPI'])
        newUsdStage = Usd.Stage.Open(newUsdFilePath)

        world = newUsdStage.GetPrimAtPath('/World')
        self.assertEqual(world.GetAppliedSchemas(),
                         ['MotionAPI', 'GeomModelAPI'])

        geomModelAPI = UsdGeom.ModelAPI(world)
        self.assertEqual(geomModelAPI.GetModelCardTextureXPosAttr().Get(),
                         'right.png')

        motionAPI = UsdGeom.MotionAPI(world)
        self.assertAlmostEqual(motionAPI.GetVelocityScaleAttr().Get(),
                               4.2,
                               places=6)
コード例 #3
0
    def _ValidateCards(self, nodeName):
        """
        Checks that the root prim on the stage has its drawmode properly set.
        """
        drawModeAttr = cmds.getAttr('%s.drawMode' % nodeName)
        self.assertEqual(drawModeAttr, 'cards')

        prim = UsdMaya.GetPrim(nodeName)
        primModelAPI = UsdGeom.ModelAPI(prim)
        self.assertEqual(primModelAPI.ComputeModelDrawMode(), 'cards')
コード例 #4
0
    def test_Basic(self):
        stage = Usd.Stage.CreateInMemory()
        self.assertTrue(stage)

        model = UsdGeom.Xform.Define(stage, '/Model')
        self.assertTrue(model)
        modelPrim = model.GetPrim()

        modelPrim.SetMetadata('kind', 'component')

        modelSpace = Gf.Matrix4d(2.0).SetTranslate(Gf.Vec3d(10, 20, 30))
        model.MakeMatrixXform().Set(modelSpace)

        geomModel = UsdGeom.ModelAPI(modelPrim)
        cnstrTarget = geomModel.CreateConstraintTarget("rootXf")
        self.assertTrue(cnstrTarget)

        rootXf = cnstrTarget.GetAttr()
        self.assertTrue(rootXf)

        cnstrTarget = geomModel.GetConstraintTarget("rootXf")
        self.assertTrue(cnstrTarget)

        cnstrTarget.SetIdentifier('RootXf')
        self.assertEqual(cnstrTarget.GetIdentifier(), 'RootXf')

        localConstraintSpace = Gf.Matrix4d(1.0).SetRotate(
            Gf.Rotation(Gf.Vec3d(1, 1, 0), 45))
        cnstrTarget.Set(localConstraintSpace)

        self.assertEqual(
            cnstrTarget.ComputeInWorldSpace(Usd.TimeCode.Default()),
            localConstraintSpace * modelSpace)

        # Test various types-- anything that is backed by Matrix4d is valid.
        rootXf.SetTypeName(Sdf.ValueTypeNames.Double)
        self.assertFalse(cnstrTarget)
        rootXf.SetTypeName(Sdf.ValueTypeNames.Frame4d)
        self.assertTrue(cnstrTarget)
        rootXf.SetTypeName(Sdf.ValueTypeNames.Matrix4d)
        self.assertTrue(cnstrTarget)

        invalidCnstrTarget = modelPrim.CreateAttribute(
            'invalidConstraintTargetName', Sdf.ValueTypeNames.Matrix4d)
        self.assertFalse(UsdGeom.ConstraintTarget(invalidCnstrTarget))

        wrongTypeCnstrTarget = modelPrim.CreateAttribute(
            'constraintTargets:invalidTypeXf', Sdf.ValueTypeNames.Float)
        self.assertFalse(UsdGeom.ConstraintTarget(wrongTypeCnstrTarget))

        # After removing model-ness, the constraint target is no longer valid
        modelPrim.ClearMetadata('kind')
        self.assertFalse(cnstrTarget)
        self.assertFalse(cnstrTarget.IsValid())
        self.assertFalse(UsdGeom.ConstraintTarget(rootXf))
コード例 #5
0
    def testExport_GeomModelAPI(self):
        """Tests export with the GeomModelAPI."""
        cmds.file(new=True, force=True)
        cmds.usdImport(file=self.inputUsdFile,
                       shadingMode='none',
                       apiSchema=['GeomModelAPI'])

        newUsdFilePath = os.path.abspath('UsdAttrsNew_GeomModelAPI.usda')
        cmds.usdExport(file=newUsdFilePath, shadingMode='none')
        newUsdStage = Usd.Stage.Open(newUsdFilePath)

        world = newUsdStage.GetPrimAtPath('/World')
        self.assertEqual(world.GetAppliedSchemas(), ['GeomModelAPI'])

        geomModelAPI = UsdGeom.ModelAPI(world)
        self.assertEqual(geomModelAPI.GetModelCardTextureXPosAttr().Get(),
                         'right.png')
コード例 #6
0
ファイル: primViewItem.py プロジェクト: zloop1982/USD
    def _extractInfo(self, info):
        ( self.hasArcs,
          self.active,
          self.imageable,
          self.defined,
          self.abstract,
          self.isInMaster,
          self.isInstance,
          self.supportsDrawMode,
          isVisibilityInherited,
          self.visVaries,
          self.name,
          self.typeName ) = info

        parent = self.parent()
        parentIsPrimViewItem = isinstance(parent, PrimViewItem)
        self.computedVis =  parent.computedVis if parentIsPrimViewItem \
                            else UsdGeom.Tokens.inherited
        if self.imageable and self.active:
            if isVisibilityInherited:
                self.vis = UsdGeom.Tokens.inherited
            else:
                self.vis = self.computedVis = UsdGeom.Tokens.invisible

        # If this is the invisible root item, initialize fallback values for 
        # the drawMode related parameters.
        if not parentIsPrimViewItem:
            self.computedDrawMode = ''
            self.isDrawModeInherited = False
            return

        # We don't need to compute drawMode related parameters for primViewItems
        # that don't support draw mode.
        if not self.supportsDrawMode:
            return
        
        self.computedDrawMode = UsdGeom.ModelAPI(self.prim).ComputeModelDrawMode(
            parent.computedDrawMode) if parentIsPrimViewItem else ''


        parentDrawModeIsInherited = parent.isDrawModeInherited if \
                parentIsPrimViewItem else None
        
        self.isDrawModeInherited = self._isComputedDrawModeInherited(
                    parentDrawModeIsInherited)
コード例 #7
0
    def _AssertExpectedStage(self, stage, cardPngRefPath):
        self.assertTrue(stage)

        self.assertTrue(stage.GetPrimAtPath("/PackageTest"))
        self.assertTrue(stage.GetPrimAtPath("/PackageTest/MyAssembly"))
        self.assertTrue(stage.GetPrimAtPath(
                "/PackageTest/MyAssembly/BaseModel1"))
        self.assertTrue(stage.GetPrimAtPath(
                "/PackageTest/MyAssembly/BaseModel1/Geom/MyMesh"))
        self.assertTrue(stage.GetPrimAtPath(
                "/PackageTest/MyAssembly/BaseModel2"))
        self.assertTrue(stage.GetPrimAtPath(
                "/PackageTest/MyAssembly/BaseModel1/Geom/MyMesh"))

        prim = stage.GetPrimAtPath("/PackageTest/Sphere")
        self.assertTrue(prim)
        modelAPI = UsdGeom.ModelAPI(prim)
        self.assertEqual(modelAPI.GetModelCardTextureXNegAttr().Get().path,
                cardPngRefPath)
コード例 #8
0
    def __init__(self,
                 primViewItem,
                 refreshFunc,
                 printTiming=False,
                 parent=None):
        QtWidgets.QWidget.__init__(self, parent)

        self._primViewItem = primViewItem
        self._layout = QtWidgets.QHBoxLayout()
        self._layout.setSpacing(0)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self._layout)

        self._comboBox = DrawModeComboBox(self)
        self._modelAPI = UsdGeom.ModelAPI(self._primViewItem.prim)
        # Reducing the width further causes the pop-up dialog to be trimmed
        # and option text to be pruned.
        self._comboBox.setFixedWidth(100)
        self._comboBox.addItem(DrawModes.DEFAULT)
        self._comboBox.addItem(DrawModes.CARDS)
        self._comboBox.addItem(DrawModes.BOUNDS)
        self._comboBox.addItem(DrawModes.ORIGIN)
        self._layout.addWidget(self._comboBox)

        self._clearButton = QtWidgets.QToolButton(self)
        self._clearButton.setText('X')
        self._clearButton.setFixedSize(16, 16)
        retainSizePolicy = self._clearButton.sizePolicy()
        retainSizePolicy.setRetainSizeWhenHidden(True)
        self._clearButton.setSizePolicy(retainSizePolicy)
        self._layout.addWidget(self._clearButton)

        self._currentDrawMode = None
        self.RefreshDrawMode()
        self._firstPaint = True

        self._refreshFunc = refreshFunc
        self._printTiming = printTiming

        self._comboBox.signalPopupHidden.connect(self._PopupHidden)
        self._comboBox.activated.connect(self._UpdateDrawMode)
        self._clearButton.clicked.connect(self._ClearDrawMode)
コード例 #9
0
def _setup_cached_extents_hints(stage, root_path, meshes, times):
    """Add bounding box information to the a UsdSkelRoot Prim.

    Adding an extentsHint onto the root skeleton is an optional part of
    exporting a USD skeleton. But if USD has these values pre-cached,
    it can be used to cull out-of-frame meshes without computing their
    skeleton animation/skinning. This makes interactive viewports much
    faster.

    Note:
        If `root_path` doesn't point to an existing Prim, it will be created.

    Args:
        stage (`pxr.Usd.Stage`):
            The USD object that will be used to get/create the
            `root_path` Prim.
        root_path (str):
            The absolute USD namespace location to the UsdSkelRoot Prim
            that we will add an extents hint to.
        meshes (tuple[str]):
            The paths to each Maya mesh that must be written to-disk.
            e.g. ["|some|pSphere1|pSphereShape1"].
        times (list[float or int]):
            Each distinct time that this function will query and cache
            bounding box information for.

    """
    override = stage.GetPrimAtPath(root_path)

    if not override.IsValid():
        override = stage.OverridePrim(root_path)

    for time_code in times:
        bounding_box = [
            Gf.Vec3f(*point)
            for point in mesher.get_overall_bounding_box(meshes, time_code)
        ]
        UsdGeom.ModelAPI(override).SetExtentsHint(bounding_box, time_code)
コード例 #10
0
    def testExport_GeomModelAPI_MotionAPI(self):
        """Tests export with both the GeomModelAPI and MotionAPI."""
        cmds.file(new=True, force=True)
        usdFile = os.path.abspath('UsdAttrs.usda')
        cmds.usdImport(file=usdFile,
                       shadingMode='none',
                       apiSchema=['GeomModelAPI', 'MotionAPI'])

        newUsdFilePath = os.path.abspath('UsdAttrsNew_TwoAPIs.usda')
        cmds.usdExport(file=newUsdFilePath, shadingMode='none')
        newUsdStage = Usd.Stage.Open(newUsdFilePath)

        world = newUsdStage.GetPrimAtPath('/World')
        self.assertEqual(world.GetAppliedSchemas(),
                         ['MotionAPI', 'GeomModelAPI'])

        geomModelAPI = UsdGeom.ModelAPI(world)
        self.assertEqual(geomModelAPI.GetModelCardTextureXPosAttr().Get(),
                         'right.png')

        motionAPI = UsdGeom.MotionAPI(world)
        self.assertAlmostEqual(motionAPI.GetVelocityScaleAttr().Get(),
                               4.2,
                               places=6)
コード例 #11
0
ファイル: testUsdGeomSchemata.py プロジェクト: yjang/USD
    def test_Bug116593(self):
        from pxr import Gf

        s = Usd.Stage.CreateInMemory()
        prim = s.DefinePrim('/sphere', typeName='Sphere')

        # set with list of tuples
        vec = [(1, 2, 2), (12, 3, 3)]
        self.assertTrue(UsdGeom.ModelAPI(prim).SetExtentsHint(vec))
        self.assertEqual(
            UsdGeom.ModelAPI(prim).GetExtentsHint()[0], Gf.Vec3f(1, 2, 2))
        self.assertEqual(
            UsdGeom.ModelAPI(prim).GetExtentsHint()[1], Gf.Vec3f(12, 3, 3))

        # set with Gf vecs
        vec = [Gf.Vec3f(1, 2, 2), Gf.Vec3f(1, 1, 1)]
        self.assertTrue(UsdGeom.ModelAPI(prim).SetExtentsHint(vec))
        self.assertEqual(
            UsdGeom.ModelAPI(prim).GetExtentsHint()[0], Gf.Vec3f(1, 2, 2))
        self.assertEqual(
            UsdGeom.ModelAPI(prim).GetExtentsHint()[1], Gf.Vec3f(1, 1, 1))
コード例 #12
0
ファイル: primViewItem.py プロジェクト: simpassi/USD
 def _HasAuthoredDrawMode(prim):
     modelAPI = UsdGeom.ModelAPI(prim)
     drawModeAttr = modelAPI.GetModelDrawModeAttr()
     return drawModeAttr and drawModeAttr.HasAuthoredValueOpinion()