Skip to content

Commit

Permalink
added optional skip for the two sizing steps
Browse files Browse the repository at this point in the history
  • Loading branch information
cpietsch committed May 1, 2023
1 parent fdb3b13 commit 641db8a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
25 changes: 17 additions & 8 deletions bin/textures
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
const textures = require("../src/textures.js");

const argv = require("yargs")
.usage("Usage: vikus-viewer-script \"/path/to/large/images/*.jpg\" [options]")
.command("\"/path/to/large/images/*.jpg\"", "Glob to input images")
.example("vikus-viewer-script \"/path/to/large/images/*.jpg\"", "create VV textures from jpgs")
.usage('Usage: vikus-viewer-script "/path/to/large/images/*.jpg" [options]')
.command('"/path/to/large/images/*.jpg"', "Glob to input images")
.example(
'vikus-viewer-script "/path/to/large/images/*.jpg"',
"create VV textures from jpgs"
)
.demandCommand(1)
.describe("output", "Path to output folder")
.default("output", "./data")
Expand All @@ -18,14 +21,20 @@ const argv = require("yargs")
.describe("textureQuality", "Texture image quality (0-100)")
.default("textureQuality", 60)
.describe("spriteSize", "Resolution of images for spritesheets")
.default("spriteSize", 256)
.describe("spriteQuality", "Quality of jpg compression for spritesheets (0-100)")
.default("spriteSize", 128)
.describe(
"spriteQuality",
"Quality of jpg compression for spritesheets (0-100)"
)
.default("spriteQuality", 70)
.describe("spriteFormat", "spritesheets format (jpg or png)")
.default("spriteFormat", "jpg")
.describe("largeSize", "resolution of full sized images")
.describe("largeSize", "resolution of full sized images, (0 to disable)")
.default("largeSize", 4096)
.describe("mediumSize", "resolution of images loaded on the fly")
.describe(
"mediumSize",
"resolution of images loaded on the fly, (0 to disable)"
)
.default("mediumSize", 1024)
.help("h")
.alias("h", "help").argv;
Expand All @@ -35,5 +44,5 @@ const argv = require("yargs")
const inputPath = argv._[0];

(async function main() {
await textures.run(inputPath, argv)
await textures.run(inputPath, argv);
})();
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"main": "src/index.js",
"scripts": {},
"engines": {
"node": ">=16.15.1"
"node": ">=v16.15.1"
},
"dependencies": {
"@mapbox/shelf-pack": "^3.2.0",
Expand Down
30 changes: 16 additions & 14 deletions src/textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const cascade = require("./cascade.js");
const sharpsheet = require("sharpsheet");

exports.run = async function textures(inputPath, options) {

const textureRes1 = options.largeSize || 4096;
const textureRes2 = options.mediumSize || 1024;
const textureRes3 = options.spriteSize || 256;
const textureRes3 = options.spriteSize || 128;
const outputPath = options.output || "./data";
const textureFormat = options.textureFormat || "jpg";
const textureQuality = options.textureQuality || 60;
Expand All @@ -19,20 +18,21 @@ exports.run = async function textures(inputPath, options) {
const workPath = createPath(path.resolve(outputPath));
const spritesPath = createPath(workPath + "/sprites");
const tmpPath = createPath(workPath + "/tmp");
const textureRes1Path = createPath(workPath + "/" + textureRes1);
const textureRes2Path = createPath(workPath + "/" + textureRes2);
const textureRes1Path =
textureRes1 && createPath(workPath + "/" + textureRes1);
const textureRes2Path =
textureRes2 && createPath(workPath + "/" + textureRes2);
const textureRes3Path = createPath(tmpPath + "/" + textureRes3);


const resizeSteps = [
{
textureRes1 && {
width: textureRes1,
height: textureRes1,
format: textureFormat,
quality: textureQuality,
path: textureRes1Path,
},
{
textureRes2 && {
width: textureRes2,
height: textureRes2,
format: textureFormat,
Expand All @@ -52,28 +52,30 @@ exports.run = async function textures(inputPath, options) {

const resizer = cascade.run(inputPath, resizeSteps, { skipExisting });

let spritesheetFiles = []
let spritesheetFiles = [];
for await (const operation of resizer) {
console.log(operation.progress, operation.file);
if (operation.log[2]) spritesheetFiles.push(operation.log[2])
if (operation.log[2]) spritesheetFiles.push(operation.log[2]);
else console.error("Error with file", operation.file);
}

if(multipe){
if (multipe) {
// this only works if the _ is only used fpr multipage files
spritesheetFiles = spritesheetFiles.filter(file => file.indexOf("_") == -1)
spritesheetFiles = spritesheetFiles.filter(
(file) => file.indexOf("_") == -1
);
}

const spriter = await sharpsheet(spritesheetFiles, spritesPath, {
outputFormat: spriteFormat,
outputQuality: spriteQuality,
dimension: 2048
dimension: 2048,
});

console.log("done");
}
};

function createPath(path) {
if (!fs.existsSync(path)) fs.mkdirSync(path);
return path;
}
}

0 comments on commit 641db8a

Please sign in to comment.