Ejemplo n.º 1
0
	def k_checkTexfiles(self):
		texfiles=cc.ls(type='file')
		for texfile in texfiles:
			#判断有无自定义属性
			userAttrs=cc.listAttr(texfile,ud=1)
			if userAttrs:
				#获取有无UDIM模式
				ktexmode=cc.getAttr(texfile+'.uvTilingMode')
				#如果无:
				if not ktexmode:
					for userAttr in userAttrs:
						#判断自定义内容是否 Tex 开头
						if userAttr[:3]=='Tex':
							#获取自定义属性的 内容
							userTex=cc.getAttr(texfile+"."+userAttr)

							##########设置节点内容 及 加入到节点数据#############
							ktemp={'path':userTex,'port':('.'+userAttr)}
							if self.kNodedate.has_key('kmayaTex_userTex'):
								if self.kNodedate['kmayaTex_userTex'].has_key(texfile):
									self.kNodedate['kmayaTex_userTex'][texfile].append(ktemp)
								else:
									self.kNodedate['kmayaTex_userTex'].update({texfile:[ktemp]})
							else:self.kNodedate['kmayaTex_userTex']={texfile:[ktemp]}
							####################################################


							#添加入总数组
							if userTex and not userTex in self.kmayaTex:
								if os.path.exists(userTex):
									#print texfile
									self.kmayaTex.append(userTex)
									#print userTex
									userTex_tx=os.path.splitext(userTex)[0]+'.tx'
									if os.path.exists(userTex_tx) and not userTex_tx in self.kmayaTex:
										self.kmayaTex.append(userTex_tx)
										#print userTex_tx


				#有UDIM模式
				else:
					for userAttr in userAttrs:
						#判断自定义内容是否 Tex 开头
						if userAttr[:3]=='Tex':
							userTex=cc.getAttr(texfile+"."+userAttr)


							##########设置节点内容 及 加入到节点数据#############
							ktemp={'path':userTex,'port':('.'+userAttr)}
							if self.kNodedate.has_key('kmayaTex_userTex'):
								if self.kNodedate['kmayaTex_userTex'].has_key(texfile):
									self.kNodedate['kmayaTex_userTex'][texfile].append(ktemp)
								else:
									self.kNodedate['kmayaTex_userTex'].update({texfile:[ktemp]})
							else:self.kNodedate['kmayaTex_userTex']={texfile:[ktemp]}
							#####################################################


							#获取自定义内容 的UDIM贴图
							k_getUDIMp=k.getFilePatternString(userTex, False, ktexmode)    
							k_exudims=k.findAllFilesForPattern(k_getUDIMp,None)
							#添加贴图入总数组
							for k_exudim in k_exudims:
								if k_exudim and not k_exudim in self.kmayaTex:
									#print texfile
									self.kmayaTex.append(k_exudim)	
									#print k_exudim	

									k_exudim_tx=os.path.splitext(k_exudim)[0]+'.tx'
									if os.path.exists(k_exudim_tx) and not k_exudim_tx in self.kmayaTex:
										self.kmayaTex.append(k_exudim_tx)
										#print k_exudim_tx		


			else:
				ktexfile=cc.getAttr(texfile+'.fileTextureName')
				ktexmode=cc.getAttr(texfile+'.uvTilingMode')

				##########设置节点内容 及 加入到节点数据#############
				ktemp={'path':ktexfile,'port':'.fileTextureName'}
				if self.kNodedate.has_key('kmayaTex_default'):
					self.kNodedate['kmayaTex_default'].update({texfile:[ktemp]})
				else:self.kNodedate['kmayaTex_default']={texfile:[ktemp]}
				#####################################################
				
				if not ktexmode:
					if ktexfile and not os.path.isabs(ktexfile):
						ktexfile=self.projectDir+ktexfile
					ktexfile=ktexfile.replace('\\','/')
					if ktexfile and not ktexfile in self.kmayaTex:
						if os.path.exists(ktexfile):
							#print texfile
							self.kmayaTex.append(ktexfile)
							#print ktexfile

							ktexfile_tx=os.path.splitext(ktexfile)[0]+'.tx'
							if os.path.exists(ktexfile_tx) and not ktexfile_tx in self.kmayaTex:
								self.kmayaTex.append(ktexfile_tx)
								#print ktexfile_tx	

				else:
					if ktexfile and not os.path.isabs(ktexfile):
						ktexfile=self.projectDir+ktexfile
					ktexfile=ktexfile.replace('\\','/')	
					#maya内部UDIM命令
					k_getUDIMp=k.getFilePatternString(ktexfile, False, ktexmode) 
					k_exudim=k.findAllFilesForPattern(k_getUDIMp,None)
					for ktexfile in k_exudim:
						if ktexfile and not ktexfile in self.kmayaTex:
							#print texfile
							self.kmayaTex.append(ktexfile)
							#print ktexfile

							ktexfile_tx=os.path.splitext(ktexfile)[0]+'.tx'
							if os.path.exists(ktexfile_tx) and not ktexfile_tx in self.kmayaTex:
								self.kmayaTex.append(ktexfile_tx)
								#print ktexfile_tx

		#先判断插件有没开,防止找不到节点类型
		if cc.pluginInfo("mtoa",q=1,l=1):
			aiTexfiles=cc.ls(type='aiImage')
			if aiTexfiles:
				for aiTexfile in aiTexfiles:
					#返回文件路径
					aiTexfilesname = cc.getAttr(aiTexfile+'.filename')
					#判断是否为空 及 在总数组有无重复 及 文件是否存在
					if aiTexfilesname and not aiTexfilesname in self.kaiTex:
						if os.path.exists(aiTexfilesname):
							#print aiTexfilesname
							self.kaiTex.append(aiTexfilesname)

							#判断此文件有无tx版本的路径
							aiTexfilesname_tx=os.path.splitext(aiTexfilesname)[0]+'.tx'
							#判断文件是否存在 及 在总数组有无重复
							if os.path.exists(aiTexfilesname_tx) and not aiTexfilesname_tx in self.kaiTex:
								self.kaiTex.append(aiTexfilesname_tx)
								#print aiTexfilesname_tx

		#先判断插件有没开,防止找不到节点类型
		if cc.pluginInfo("vrayformaya",q=1,l=1):
			Vptexfiles=cc.ls(type='VRayPtex')
			if Vptexfiles:
				for Vptexfile in Vptexfiles:
					#返回文件路径
					Vptexfilename = cc.getAttr(Vptexfile+'.ptexFile')
					#判断是否为空 及 在总数组有无重复 及 文件是否存在
					if Vptexfilename and not Vptexfilename in self.kVpTex:
						if os.path.exists(Vptexfilename):
							#print Vptexfilename
							self.kaiTex.append(Vptexfilename)

							#判断此文件有无tx版本的路径
							Vptexfilename_tx=os.path.splitext(Vptexfilename)[0]+'.tx'
							#判断文件是否存在 及 在总数组有无重复
							if os.path.exists(Vptexfilename_tx) and not Vptexfilename_tx in self.kaiTex:
								self.kaiTex.append(Vptexfilename_tx)
								#print Vptexfilename_tx



			
		self.kTexture=list(set(self.kmayaTex+self.kaiTex+self.kVpTex))
Ejemplo n.º 2
0
	def k_checkTexfiles(self):
		texfiles=cc.ls(type='file')
		for texfile in texfiles:
			#判断有无自定义属性
			userAttrs=cc.listAttr(texfile,ud=1)
			if userAttrs:
				#获取有无UDIM模式
				ktexmode=cc.getAttr(texfile+'.uvTilingMode')
				#如果无:
				if not ktexmode:
					for userAttr in userAttrs:
						#判断自定义内容是否 Tex 开头
						if userAttr[:3]=='Tex':
							#获取自定义属性的 内容
							userTex=cc.getAttr(texfile+"."+userAttr)
							#添加入总数组
							if userTex and not userTex in self.kmayaTex:
								if os.path.exists(userTex):
									print texfile
									self.kmayaTex.append(userTex)
									print userTex
									userTex_tx=os.path.splitext(userTex)[0]+'.tx'
									if os.path.exists(userTex_tx):
										self.kmayaTex.append(userTex_tx)
										print userTex_tx

										
				#有UDIM模式
				else:
					for userAttr in userAttrs:
						#判断自定义内容是否 Tex 开头
						if userAttr[:3]=='Tex':
							userTex=cc.getAttr(texfile+"."+userAttr)
							#获取自定义内容 的UDIM贴图
							k_getUDIMp=k.getFilePatternString(userTex, False, ktexmode)    
							k_exudims=k.findAllFilesForPattern(k_getUDIMp,None)
							#添加贴图入总数组
							for k_exudim in k_exudims:
								if k_exudim and not k_exudim in self.kmayaTex:
									print texfile
									self.kmayaTex.append(k_exudim)	
									print k_exudim	

									k_exudim_tx=os.path.splitext(k_exudim)[0]+'.tx'
									if os.path.exists(k_exudim_tx):
										self.kmayaTex.append(k_exudim_tx)
										print k_exudim_tx		


			else:
				ktexfile=cc.getAttr(texfile+'.fileTextureName')
				ktexmode=cc.getAttr(texfile+'.uvTilingMode')
				if not ktexmode:
					if ktexfile and not os.path.isabs(ktexfile):
						ktexfile=self.projectDir+ktexfile
					ktexfile=ktexfile.replace('\\','/')
					if ktexfile and not ktexfile in self.kmayaTex:
						if os.path.exists(ktexfile):
							print texfile
							self.kmayaTex.append(ktexfile)
							print ktexfile

							ktexfile_tx=os.path.splitext(ktexfile)[0]+'.tx'
							if os.path.exists(ktexfile_tx):
								self.kmayaTex.append(ktexfile_tx)
								print ktexfile_tx	

				else:
					if ktexfile and not os.path.isabs(ktexfile):
						ktexfile=self.projectDir+ktexfile
					ktexfile=ktexfile.replace('\\','/')	
					k_getUDIMp=k.getFilePatternString(ktexfile, False, ktexmode) 
					k_exudim=k.findAllFilesForPattern(k_getUDIMp,None)
					for ktexfile in k_exudim:
						if ktexfile and not ktexfile in self.kmayaTex:
							print texfile
							self.kmayaTex.append(ktexfile)
							print ktexfile

							ktexfile_tx=os.path.splitext(ktexfile)[0]+'.tx'
							if os.path.exists(ktexfile_tx):
								self.kmayaTex.append(ktexfile_tx)
								print ktexfile_tx
Ejemplo n.º 3
0
    def extract_TexturePack(self):

        from maya import cmds
        from maya.app.general.fileTexturePathResolver import (
            getFilePatternString,
            findAllFilesForPattern,
        )

        package_path = self.create_package()
        package_path = env_embedded_path(package_path)

        if "fileNodePath" not in self.context.data:
            self.context.data["fileNodePath"] = dict()

        # Extract textures
        #
        self.log.info("Extracting textures..")

        # Get latest hashes
        path = [
            avalon.api.Session["AVALON_PROJECT"],
            avalon.api.Session["AVALON_ASSET"],
            self.data["subset"],
            -1,  # latest version
            "TexturePack"
        ]
        representation = avalon.io.locate(path)
        if representation is None:
            # Never been published
            latest_hashes = dict()
        else:
            representation = avalon.io.find_one({"_id": representation})
            latest_hashes = representation["data"]["hashes"]

        processed_pattern = dict()

        # Hash file to check which to copy and which to remain old link
        for file_node in self.member:

            tiling_mode = cmds.getAttr(file_node + ".uvTilingMode")
            is_sequence = cmds.getAttr(file_node + ".useFrameExtension")
            img_path = cmds.getAttr(file_node + ".fileTextureName",
                                    expandEnvironmentVariables=True)

            pattern = getFilePatternString(img_path, is_sequence, tiling_mode)
            img_name = os.path.basename(img_path)

            if pattern in processed_pattern:

                final_pattern = processed_pattern[pattern]

                dir_name = os.path.dirname(final_pattern)
                final_path = os.path.join(dir_name, img_name)
                SKIP = True

            else:

                paths = [package_path]
                paths.append(os.path.basename(pattern))  # image pattern name

                final_pattern = os.path.join(*paths)
                processed_pattern[pattern] = final_pattern

                paths.pop()  # Change to file path from fileNode
                paths.append(img_name)
                final_path = os.path.join(*paths)
                SKIP = False

            self.context.data["fileNodePath"][file_node] = final_path
            self.log.info("FileNode: {!r}".format(file_node))
            self.log.info("Texture Path: {!r}".format(final_pattern))

            if SKIP:
                self.log.info("Skipped.")
                continue

            # Files to be transfered
            curreent_files = findAllFilesForPattern(pattern, None) or [pattern]
            self.log.debug("File count: {}".format(len(curreent_files)))

            for file in curreent_files:
                if not file:
                    # (TODO) This should not happen. This is a hot-fix.
                    continue
                hash_value = hash_file(file)

                img_name = os.path.basename(file)
                paths.pop()  # Change to resloved file path
                paths.append(img_name)
                final_path = os.path.join(*paths)

                try:

                    published_file = latest_hashes[hash_value]
                    _expand = os.path.expandvars(published_file)
                    if not os.path.isfile(_expand):
                        self.log.warning("Published file not exists, "
                                         "copy new one. ({})"
                                         "".format(_expand))
                        # Jump to add file
                        raise KeyError("Published file not exists.")

                except KeyError:

                    latest_hashes[hash_value] = final_path
                    self.add_file(file, final_path)
                    self.log.debug("File added: {0} -> {1}"
                                   "".format(file, final_path))

                else:
                    self.add_hardlink(published_file, final_path)
                    self.log.debug("Hardlink added: {0} -> {1}"
                                   "".format(file, final_path))

        self.add_data({"hashes": latest_hashes})
Ejemplo n.º 4
0
    def k_checkTexfiles(self):
        texfiles = cc.ls(type='file')
        for texfile in texfiles:
            userAttrs = cc.listAttr(texfile, ud=1)
            if userAttrs:
                ktexmode = cc.getAttr(texfile + '.uvTilingMode')
                if not ktexmode:
                    for userAttr in userAttrs:
                        if userAttr[:3] == 'Tex':
                            userTex = cc.getAttr(texfile + "." + userAttr)
                            self.k_Nodedate2('kmayaTex_userTex', texfile,
                                             ('.' + userAttr), userTex)
                            #####################################################

                            if userTex and not userTex in self.kmayaTex:
                                if os.path.exists(userTex):
                                    self.kmayaTex.append(userTex)
                                    userTex_tx = os.path.splitext(
                                        userTex)[0] + '.tx'
                                    if os.path.exists(
                                            userTex_tx
                                    ) and not userTex_tx in self.kmayaTex:
                                        self.kmayaTex.append(userTex_tx)

                else:
                    for userAttr in userAttrs:
                        if userAttr[:3] == 'Tex':
                            userTex = cc.getAttr(texfile + "." + userAttr)
                            self.k_Nodedate2('kmayaTex_userTex', texfile,
                                             ('.' + userAttr), userTex)
                            #####################################################
                            k_getUDIMp = k.getFilePatternString(
                                userTex, False, ktexmode)
                            k_exudims = k.findAllFilesForPattern(
                                k_getUDIMp, None)
                            for k_exudim in k_exudims:
                                if k_exudim and not k_exudim in self.kmayaTex:
                                    self.kmayaTex.append(k_exudim)

                                    k_exudim_tx = os.path.splitext(
                                        k_exudim)[0] + '.tx'
                                    if os.path.exists(
                                            k_exudim_tx
                                    ) and not k_exudim_tx in self.kmayaTex:
                                        self.kmayaTex.append(k_exudim_tx)

            else:
                ktexfile = cc.getAttr(texfile + '.fileTextureName')
                ktexmode = cc.getAttr(texfile + '.uvTilingMode')

                if not ktexmode:
                    if ktexfile and not os.path.isabs(ktexfile):
                        ktexfile = self.projectDir + ktexfile
                    ktexfile = ktexfile.replace('\\', '/')

                    if ktexfile:
                        self.k_Nodedate('kmayaTex_default', texfile,
                                        '.fileTextureName', ktexfile)
                        #####################################################

                        if not ktexfile in self.kmayaTex and os.path.exists(
                                ktexfile):
                            self.kmayaTex.append(ktexfile)
                            ktexfile_tx = os.path.splitext(ktexfile)[0] + '.tx'
                            if os.path.exists(
                                    ktexfile_tx
                            ) and not ktexfile_tx in self.kmayaTex:
                                self.kmayaTex.append(ktexfile_tx)

                else:
                    if ktexfile and not os.path.isabs(ktexfile):
                        ktexfile = self.projectDir + ktexfile
                    ktexfile = ktexfile.replace('\\', '/')

                    if ktexfile:
                        self.k_Nodedate('kmayaTex_default', texfile,
                                        '.fileTextureName', ktexfile)
                        #####################################################

                        k_getUDIMp = k.getFilePatternString(
                            ktexfile, False, ktexmode)
                        k_exudim = k.findAllFilesForPattern(k_getUDIMp, None)
                        for ktexfile in k_exudim:
                            if not ktexfile in self.kmayaTex:
                                self.kmayaTex.append(ktexfile)
                                ktexfile_tx = os.path.splitext(
                                    ktexfile)[0] + '.tx'
                                if os.path.exists(
                                        ktexfile_tx
                                ) and not ktexfile_tx in self.kmayaTex:
                                    self.kmayaTex.append(ktexfile_tx)

        if cc.pluginInfo("mtoa", q=1, l=1):
            aiTexfiles = cc.ls(type='aiImage')
            if aiTexfiles:
                for aiTexfile in aiTexfiles:
                    aiTexfilesname = cc.getAttr(aiTexfile + '.filename')
                    if aiTexfilesname:
                        self.k_Nodedate('kaiTex', aiTexfile, '.filename',
                                        aiTexfilesname)
                        #####################################################

                        if not aiTexfilesname in self.kaiTex and os.path.exists(
                                aiTexfilesname):
                            self.kaiTex.append(aiTexfilesname)

                            aiTexfilesname_tx = os.path.splitext(
                                aiTexfilesname)[0] + '.tx'
                            if os.path.exists(
                                    aiTexfilesname_tx
                            ) and not aiTexfilesname_tx in self.kaiTex:
                                self.kaiTex.append(aiTexfilesname_tx)

        if cc.pluginInfo("vrayformaya", q=1, l=1):
            Vptexfiles = cc.ls(type='VRayPtex')
            if Vptexfiles:
                for Vptexfile in Vptexfiles:
                    Vptexfilename = cc.getAttr(Vptexfile + '.ptexFile')
                    if Vptexfilename:
                        self.k_Nodedate('kVpTex', Vptexfile, '.ptexFile',
                                        Vptexfilename)
                        #####################################################

                        if not Vptexfilename in self.kVpTex and os.path.exists(
                                Vptexfilename):
                            self.kaiTex.append(Vptexfilename)
                            Vptexfilename_tx = os.path.splitext(
                                Vptexfilename)[0] + '.tx'
                            if os.path.exists(
                                    Vptexfilename_tx
                            ) and not Vptexfilename_tx in self.kaiTex:
                                self.kaiTex.append(Vptexfilename_tx)

        self.kTexture = list(set(self.kmayaTex + self.kaiTex + self.kVpTex))
Ejemplo n.º 5
0
    # The first step is to get this attributes values, and the file path
    imagePath = cmds.getAttr(s_file + ".fileTextureName")
    tiling_mode = cmds.getAttr(s_file + ".uvTilingMode")
    frame_extension = cmds.getAttr(s_file + ".useFrameExtension")

    # If frame_extension is 1 means that is an animated texture
    if frame_extension == 1:
        print("Type: Animated texture\n")

        # We get the template that Maya use to detect all file set, that is,
        # the part of file name that is repeated
        pattern = ftpr.getFilePatternString(imagePath, True, False)

        # We store all the elements that follow that template
        fileList = ftpr.findAllFilesForPattern(pattern, None)

        # And, finally, to be able to indicate in which frame that texture is
        # displayed, we store the offset, so we will start from frame 0, and we
        # add the offset value to indicate correctly in which frame it is
        offset = cmds.getAttr(s_file + ".frameOffset")
        counter = 0

        # We print on the screen the value of these frame plus the offset, and
        # the path of the file. To access the item, its enough to access the
        # position pointed by the counter, since it increases one by one and
        # start in 0
        for frameImage in fileList:
            print "Frame [", (counter + int(offset)), "]:", fileList[counter]
            counter = counter + 1
    else: