Ejemplo n.º 1
0
def get_current_scene():
    '''
    :description get the current scene path
    :param None
    :example
        from core import scene
        scene.get_current_scene()
    '''
    # NodegraphAPI.GetProjectFile()
    # NodegraphAPI.GetProjectAssetID()
    return NodegraphAPI.GetSourceFile()
    def bake(self, parentWidget=None):
        """
        Performs the bake based on the settings of this current node
        parameter settings. If a parentWidget is provided, we create a progress
        widget and setup callbacks to update it. If no parentWidget is provided
        we can run this without calling any UI code.

        @type parentWidget: C{QtWidgets.QWidget}
        @param parentWidget: Parent for the progress widget. If set to None,
            the progress callback is not produced.
        """
        graphState = NodegraphAPI.GetCurrentGraphState()
        frameTime = graphState.getTime()
        node = self
        inputPorts = node.getInputPorts()
        numPorts = len(inputPorts)
        if numPorts < 2:
            log.error("Requires at least two input ports to bake a USD Look")
        variantSetName = node.getParameter("variantSetName").getValue(
            frameTime)
        rootPrimName = node.getParameter("rootPrimName").getValue(frameTime)
        alwaysCreateVariantSet = bool(
            node.getParameter("alwaysCreateVariantSet").getValue(frameTime) ==
            "Yes")
        looksFilename = node.getParameter("looksFilename").getValue(frameTime)
        looksFileFormat = node.getParameter("looksFileFormat").getValue(
            frameTime)
        createCompleteUsdAssemblyFile = bool(
            node.getParameter("createCompleteUsdAssemblyFile").getValue(
                frameTime))
        assemblyFilename = node.getParameter("assemblyFilename").getValue(
            frameTime)
        payloadFilename = node.getParameter("payloadFilename").getValue(
            frameTime)
        createVariantSet = alwaysCreateVariantSet or (len(inputPorts) > 2)
        additionalSettings = {
            "variantSetName": variantSetName,
            "rootPrimName": rootPrimName,
            "createVariantSet": createVariantSet,
            "looksFileFormat": looksFileFormat,
            "looksFilename": looksFilename,
            "createCompleteUsdAssemblyFile": createCompleteUsdAssemblyFile,
            "assemblyFilename": assemblyFilename,
            "payloadFilename": payloadFilename,
        }
        # Ensure the interruptWidget is only created in a UI session
        if parentWidget:
            import UI4
            self.__timer = time.time()
            self.__interruptWidget = UI4.Widgets.ModalProcessInterruptWidget(
                self.__interruptCallback, minWidth=512)
        else:
            self.__interruptWidget = None
            self.__timer = None

        assetId = node.getParameter("saveTo").getValue(frameTime)
        rootLocationsParam = node.getParameter("rootLocations")
        rootLocations = [
            x.getValue(frameTime) for x in rootLocationsParam.getChildren()
        ]

        # Retrieve the Ops for each of the inputs
        referenceOp, passNamesAndOps = self.__getBakerOps(
            self._getPassInputPortNames(), graphState)

        sourceFile = NodegraphAPI.GetOriginalSourceFile()
        if not sourceFile:
            # Use legacy API call in case this file was created in a very old
            # version of Katana (1.6.11 or earlier)
            sourceFile = NodegraphAPI.GetSourceFile()
        sourceAsset = NodegraphAPI.GetKatanaSceneName()

        #When updating to the later version of the LookFileBakeAPI, dont
        # forget to update require3DInput from the Node.py
        baker = LookFileBaker("UsdExport")
        baker.progressCallback = self.__progressCallback
        baker.additionalSettings = additionalSettings
        baker.sourceAsset = sourceAsset
        baker.sourceFile = sourceFile

        if self.__interruptWidget:
            self.__interruptWidget.show()
            self.__interruptWidget.update("Saving Materials To %s" % assetId,
                                          True)

        try:
            baker.bakeAndPublish(referenceOp, passNamesAndOps, rootLocations,
                                 assetId)
        finally:
            if self.__interruptWidget:
                self.__interruptWidget.close()
                self.__interruptWidget.setParent(None)
                self.__interruptWidget.deleteLater()
                self.__interruptWidget = None