利用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);
网友评论