美文网首页
python脚本控制TeturePacker批量打包资源

python脚本控制TeturePacker批量打包资源

作者: 咸鱼而已 | 来源:发表于2017-02-24 19:01 被阅读40次

利用python脚本,批量打包碎图。会先更新svn,然后执行打包操作

#!/usr/bin/python  
#encoding=utf-8  
import io
import os
import sys  
import hashlib  
import string  
import re

rootPath = os.path.abspath(os.path.join(sys.argv[0], os.pardir))

# # input paths
ImageDir= os.path.join(rootPath, "ddzplist_1")

# svn update
svnCommand = "svn up"
os.system(svnCommand)

# temporary path to place the sprite sheets
# OutputDir = "/Users/xy/Documents/tempPlist/"

#PNG
OutputDir =  os.path.join(rootPath, "tempPlist") #通用 中 PNG输出目录

# # path of the texture packer command line tool
TP="TexturePacker"

print("ImageDir = " + ImageDir)
print("OutputDir = " + OutputDir)
print("TP = " + TP)


#文件输出目录
def createPath(cPath):
    if not os.path.isdir(cPath):
        os.mkdir(cPath)

def clearPath(cPath):
    os.system("rm -rf "+cPath)

def create_img(inputPath,sheetSuffix, textureFormat, sheetName):
    cmdtmp = TP +\
        " --sheet " + os.path.join(OutputDir,sheetName) +".{sheetSuffix}" \
        " --data "+ os.path.join(OutputDir,sheetName)+ ".plist"\
        " --dither-fs-alpha" \
        " --size-constraints NPOT" \
        " --disable-rotation" \
        " --trim-mode None" \
        " --border-padding 0" \
        " --texture-format {textureFormat}" \
        " --opt RGBA8888 " \
        " --shape-padding 0" \
        " --padding 0" \
        " --extrude 0" \
        " --max-width 2048" \
        " {inputPath}" \
        # " --content-protection af72a24555b7618b7cc45afd62c0aa7e" \
        # " --force-word-aligned " \
        # " --etc1-quality high-perceptual" \
        # " --force-squared" \
        # " --pvr-quality best" \
        
    cmdtmp = cmdtmp.format(
        sheetSuffix = sheetSuffix,      #输出的纹理格式
        inputPath = inputPath,
        textureFormat=textureFormat     #纹理格式
        )
    os.system(cmdtmp)

if __name__ == '__main__':
    clearPath(OutputDir)
    createPath(OutputDir)
    for sheet in os.listdir(ImageDir):
        iPath = os.path.join(ImageDir, sheet)
        # print("==========>>>>>"+sssheet)
        if os.path.isdir(iPath): 
            # print(iPath)

            create_img(iPath,'png',"png", sheet);
            # create_img(iPath,'pvr.ccz',"pvr2ccz", sheet);

相关文章

网友评论

      本文标题:python脚本控制TeturePacker批量打包资源

      本文链接:https://www.haomeiwen.com/subject/qygwwttx.html