packTextures
npm install pack_texturessh
npm install pack_textures
`
$3
`js
const { packTextures, packTexturesByBase64OrBuffer } = require('pack_textures');
//nodejs读写文件使用,传文件夹路径及存储路径
packTextures(
inDir,
outPath,
maxWidth,
maxHeight,
powerOf2,
shapePadding,
borderPadding,
allowRotation,
trim,
useShtSuffix,
compressionLevel,
includeJpg
)
//写出json文件格式
const json = {
"a.png": {
"x": 464,//x,y,w,h为图集上的切图位置数据
"y": 2,
"w": 160,
"h": 180,
"ox": 0,//ox,oy为偏移数据,trim裁剪的数据,在原始图上的偏移{x:0,y:0,sw:200,sh:200}
"oy": 0,
"sw": 160,//sw,sh为原始宽高
"sh": 180,
"ro": false//是否旋转
},
"b.png": {
"x": 2,
"y": 134,
"w": 130,
"h": 460,
"ox": 0,
"oy": 0,
"sw": 130,
"sh": 460,
"ro": true
}
....
}
//nodejs不进行文件读写,返回纯数据自行处理
packTexturesByBase64OrBuffer(
base64OrBuffer,
maxWidth,
maxHeight,
powerOf2,
shapePadding,
borderPadding,
allowRotation,
trim,
compressionLevel,
)
// 返回数组
// {
// atlas,
// buffer,
// base64
// }[]
`
$3
`sh
npm install pack_textures -g
packTextures -i ./input -o ./output
`
$3
`sh
npm install pack_textures
npx packInBrowser
`
`js
//package.json里使用
{
"scripts": {
"pack": "packInBrowser"
}
}
``