예제 #1
0
    def setTextures(self, fileNames):
        """ 
        Specifies the textures to be used in the UV viewer.
        File ranges (eg. diffuse.(1001-1020)#.tx) will be expanded
        As will non-limited file ranges (eg. diffuse.#.tx) 
        """
        del self.__fileNames[:]

        # insert individual files into self.__fileNames
        for file in fileNames:
            if file == None:
                continue

            fsPlugin = AssetAPI.GetDefaultFileSequencePlugin()
            if fsPlugin.isFileSequence(file):
                fs = fsPlugin.getFileSequence(file)
                frames = fs.getFrameList()
                if len(frames) > 0:
                    # Limited frame range
                    for frame in frames:
                        path = fs.getResolvedPath(frame)
                        if os.path.exists(path):
                            self.__fileNames.append(path)
                else:
                    # Unlimited frame range
                    paths = self.__getPathsFromUnlimitedSequence(file)
                    self.__fileNames.extend(paths)

            else:
                self.__fileNames.append(file)
예제 #2
0
    def resolvePath(self, assetId, frame):  # TODO -- This may need some work to work properly. How do Shotgun and Katana work with file sequences?
        """
        Resolves the given asset ID and if it comes as a file
        sequence then we will resolve that file sequence to the specified
        frame using the currently selected FileSequence plug-in
        """
        resolvedAsset = self.resolveAsset(assetId)
        if not resolvedAsset:
            return

        # Get the fileSequence plug-in and if the resolvedAsset is a file sequence
        # path, then use frame to resolve it
        fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
        if fileSequencePlugin:
            if fileSequencePlugin.isFileSequence(resolvedAsset):
                # Get the FileSequence object and resolve the sequence with frame
                fileSequence = fileSequencePlugin.getFileSequence(resolvedAsset)
                resolvedAsset = fileSequence.getResolvedPath(frame)

        return resolvedAsset
예제 #3
0
 def resolvePath(self, assetId, frame):
     """
     Resolves the asset ID and inserts the specified frame using the
     currently selected FileSequence plug-in.
     """        
     if self.isAssetId(assetId):
         # Resolve the asset
         resolvedAsset = self.resolveAsset(assetId)
     else:
         resolvedAsset = assetId
     
     # Get the fileSequence plug-in and if the resolvedAsset is a file 
     # sequence path, then use frame to resolve it
     fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
     if fileSequencePlugin:
         if fileSequencePlugin.isFileSequence(resolvedAsset):
             # Get the FileSequence object and resolve the sequence with 
             # the frame passed to this function.
             fileSequence = fileSequencePlugin.getFileSequence(resolvedAsset)
             resolvedAsset = fileSequence.getResolvedPath(frame)
     
     return resolvedAsset
예제 #4
0
    def createAssetAndPath(self, txn, assetType, fields, args,
                           createDirectory):
        """
        Builds an asset ID using the fields provided and prepares to publish
        an asset of a given asset type. This is the first step of publishing
        and Katana will use the resolved value of the asset ID returned by this
        as the location to write out the asset.
        
        Returns "None" for unsupported asset types or if this step fails (for
        example when the directory structure could not be written to).  
        """
        # Create the asset filename and attributes dict.
        assetFile = None

        # The postCreateAsset() call will set "published" to True. We will save
        # "published" as an attribute so that we can save it in the asset.info
        # file in the same way as the other attributes
        attrs = {"published": "False"}
        attrs["comment"] = args.get("comment", "")

        # In some cases Katana will provide "versionUp" as a boolean argument.
        # If it is "True" then we will increase whatever version is provided
        # by the assetId. In a real asset management system this feature could
        # be implemented by increasing the latest available version for the
        # provided asset.
        self._incrementVersion(fields, args)

        # Get the string that contains the fields joined by "/"
        fieldsStr = self._getFieldsStrFromFields(fields)
        if not fieldsStr:
            log.warning("createAssetAndPath(): no fieldsStr! Aborting")
            return None

        # This section will look into the different Asset Types.
        # For most asset types  an argument called "file" can optionally be
        # specified with an explicit file name that will be set in the asset's
        # directory or an absolute path to a file outside the database's
        # directories
        if assetType == AssetAPI.kAssetTypeKatanaScene:
            assetFile = args.get("file", "scene.katana")

        elif assetType == AssetAPI.kAssetTypeImage:
            ext = args.get("ext", "exr")
            colorspace = args.get("colorspace", "lnf")
            res = args.get("res", "misc")

            attrs["ext"] = ext
            attrs["colorspace"] = colorspace
            attrs["res"] = res

            # Images published for the catalog are handled differently.
            if args.get("context") == AssetAPI.kAssetContextCatalog:
                # The filename of the exported sequences is passed to
                # postCreateAsset and handled there.
                assetFile = ""

            else:
                # Now we are going to build the asset filename
                assetFile = None

                # Check if we can get how to represent a file sequence path
                # using the currently selected FileSequence plug-in
                fileSequencePlugin = AssetAPI.GetDefaultFileSequencePlugin()
                if fileSequencePlugin:
                    # Get the prefix and suffix of the sequence string
                    assetFileName = str("image_%s." % colorspace)
                    assetExtension = str(".%s" % ext)

                    assetFile = fileSequencePlugin.buildFileSequenceString(
                        assetFileName, assetExtension, 4)
                else:
                    log.warning("createAssetAndPath(): No FileSequencePlugin "
                                "found! Aborting.")
                    return None

        elif assetType == AssetAPI.kAssetTypeLookFile:
            assetFile = args.get("file", "lookfile.klf")

        elif assetType == AssetAPI.kAssetTypeFCurveFile:
            assetFile = "fcurve.xml"

        elif assetType == AssetAPI.kAssetTypeGafferRig:
            assetFile = "rig.gprig"

        elif assetType == AssetAPI.kAssetTypeGafferThreeRig:
            assetFile = "rig.rig"

        elif assetType == AssetAPI.kAssetTypeScenegraphXml:
            assetFile = args.get("file", "scene.xml")

        elif assetType == AssetAPI.kAssetTypeScenegraphBookmarks:
            assetFile = args.get("file", "scenegraph_bookmarks.xml")

        elif assetType == AssetAPI.kAssetTypeLookFileMgrSettings:
            assetFile = args.get("file", "lfmsettings.lfmexport")

        elif assetType == AssetAPI.kAssetTypeMacro:
            assetFile = args.get("file", "node.macro")

        else:
            log.error("createAssetAndPath(): Invalid asset type: \"%s\"" %
                      assetType)
            return None

        # We don't pay attention to 'createDirectory' because we always have to
        # create the dir to keep the info file at least.
        dir = os.path.join(self._getBaseDir(), fieldsStr)
        if not os.path.exists(dir):
            os.makedirs(dir)

        # Create the info file that will keep the filename, asset type and the
        # extra attributes of the asset.
        self._writeAssetInfoFile(dir, assetFile, assetType, attrs)

        resultAssetId = self.buildAssetId(fields)

        return resultAssetId