@needle-tools/gltf-build-pipeline 2.2.1-alpha.2 → 2.2.1-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.temp/Go2.bin +0 -0
- package/.temp/textures/0_1.exr +0 -0
- package/.temp/textures/1_1.jpg +0 -0
- package/CHANGELOG.md +395 -394
- package/README.md +35 -35
- package/dist/cache/cache.d.ts +54 -54
- package/dist/cache/cache.js +257 -257
- package/dist/cache/index.d.ts +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +154 -154
- package/dist/config/index.d.ts +53 -53
- package/dist/config/index.js +152 -152
- package/dist/constants.d.ts +5 -5
- package/dist/constants.js +5 -5
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +24 -24
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +54 -54
- package/dist/extensions/NEEDLE_compression_texture/index.d.ts +1 -1
- package/dist/extensions/NEEDLE_compression_texture/index.js +1 -1
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +26 -26
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +85 -85
- package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +1 -1
- package/dist/extensions/NEEDLE_mesh_compression/index.js +1 -1
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +27 -27
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +897 -897
- package/dist/extensions/NEEDLE_opaque/index.d.ts +3 -3
- package/dist/extensions/NEEDLE_opaque/index.js +28 -28
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +48 -48
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +69 -69
- package/dist/extensions/NEEDLE_progressive/index.d.ts +1 -1
- package/dist/extensions/NEEDLE_progressive/index.js +1 -1
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +23 -23
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +41 -41
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +25 -25
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +67 -67
- package/dist/extensions/index.d.ts +7 -7
- package/dist/extensions/index.js +17 -17
- package/dist/extensions/utils.d.ts +6 -6
- package/dist/extensions/utils.js +72 -72
- package/dist/functions/weld.3.d.ts +76 -76
- package/dist/functions/weld.3.js +414 -414
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/scripts/index.d.ts +2 -2
- package/dist/scripts/index.js +2 -2
- package/dist/scripts/pack-gltf.d.ts +16 -16
- package/dist/scripts/pack-gltf.js +120 -120
- package/dist/scripts/stats.d.ts +2 -2
- package/dist/scripts/stats.js +18 -18
- package/dist/transforms/index.d.ts +9 -9
- package/dist/transforms/index.js +9 -9
- package/dist/transforms/needle_animation_transform.d.ts +2 -2
- package/dist/transforms/needle_animation_transform.js +5 -5
- package/dist/transforms/needle_asset.d.ts +3 -3
- package/dist/transforms/needle_asset.js +35 -35
- package/dist/transforms/needle_common.d.ts +16 -16
- package/dist/transforms/needle_common.js +1 -1
- package/dist/transforms/needle_mesh_transform.d.ts +10 -10
- package/dist/transforms/needle_mesh_transform.js +140 -140
- package/dist/transforms/needle_progressive.d.ts +42 -42
- package/dist/transforms/needle_progressive.js +921 -921
- package/dist/transforms/needle_texture_transform.d.ts +13 -13
- package/dist/transforms/needle_texture_transform.js +202 -196
- package/dist/transforms/needle_toktx.d.ts +25 -25
- package/dist/transforms/needle_toktx.js +230 -230
- package/dist/transforms/needle_webp.d.ts +13 -13
- package/dist/transforms/needle_webp.js +37 -37
- package/dist/transforms/toktx.d.ts +52 -52
- package/dist/transforms/toktx.js +221 -221
- package/dist/transforms/toktx_types.d.ts +78 -78
- package/dist/transforms/toktx_types.js +62 -62
- package/dist/transforms/util.d.ts +21 -21
- package/dist/transforms/util.js +90 -90
- package/dist/utils/compression_utils.d.ts +2 -2
- package/dist/utils/compression_utils.js +6 -6
- package/dist/utils/fileutils.d.ts +6 -6
- package/dist/utils/fileutils.js +141 -141
- package/dist/utils/guid.d.ts +1 -1
- package/dist/utils/guid.js +5 -5
- package/dist/utils/index.d.ts +10 -9
- package/dist/utils/index.js +10 -9
- package/dist/utils/merge.d.ts +12 -12
- package/dist/utils/merge.js +31 -31
- package/dist/utils/mesh.d.ts +13 -13
- package/dist/utils/mesh.js +107 -107
- package/dist/utils/nodeio.d.ts +5 -5
- package/dist/utils/nodeio.js +14 -14
- package/dist/utils/stats.d.ts +54 -53
- package/dist/utils/stats.js +191 -166
- package/dist/utils/texture.d.ts +2 -2
- package/dist/utils/texture.js +8 -8
- package/dist/utils/validate.d.ts +5 -0
- package/dist/utils/validate.js +16 -0
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/version.js +5 -5
- package/package.json +77 -76
- package/scripts/clear-caches.mjs +3 -3
- package/scripts/defaults.mjs +11 -11
- package/scripts/fileutils.mjs +5 -5
- package/scripts/index.mjs +41 -41
- package/scripts/limit-caches.mjs +3 -3
- package/scripts/make-progressive.mjs +16 -16
- package/scripts/pack-gltf.mjs +107 -107
- package/tsconfig.json +19 -19
package/dist/cli/index.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
#! /usr/bin/env node
|
|
2
|
-
import { program } from '@donmccurdy/caporal';
|
|
3
|
-
import { calculateStats, packGLTF } from "../scripts/index.js";
|
|
4
|
-
import { printStats, writeFileStatsToFile } from '../utils/stats.js';
|
|
5
|
-
import { getVersion } from '../utils/version.js';
|
|
6
|
-
import { UsecaseOptions, createConfig, getConfig } from '../config/index.js';
|
|
7
|
-
import { make_progressive } from '../transforms/needle_progressive.js';
|
|
8
|
-
import { cacheSizeLimit, clearCache } from '../cache/cache.js';
|
|
9
|
-
import { statSync } from 'fs';
|
|
10
|
-
import { foreachGLTF, getDirName, isDirectory } from '../utils/fileutils.js';
|
|
11
|
-
import path, { dirname } from 'path';
|
|
12
|
-
import { ERROR_CODES } from '../constants.js';
|
|
13
|
-
// For testing / dev you can run `npm link` in the package directory
|
|
14
|
-
// For removing the link run `npm rm --global @needle-tools/gltf-build-pipeline`
|
|
15
|
-
program
|
|
16
|
-
.command("version", "Print current verison")
|
|
17
|
-
.action(async ({ logger }) => {
|
|
18
|
-
logger.info(getVersion());
|
|
19
|
-
})
|
|
20
|
-
.command("clear-caches", "Clear all caches")
|
|
21
|
-
.help(`Clears all cached files
|
|
22
|
-
Caches are limited to ${cacheSizeLimit} MB disc space by default.
|
|
23
|
-
`)
|
|
24
|
-
.action(async ({ logger }) => {
|
|
25
|
-
logger.info("Clearing caches");
|
|
26
|
-
clearCache(logger);
|
|
27
|
-
})
|
|
28
|
-
.command("stats", "Calculate glTF stats")
|
|
29
|
-
.help(`
|
|
30
|
-
`)
|
|
31
|
-
.argument('<input>', "Path to a glTF, GLB or VRM file OR a directory")
|
|
32
|
-
.argument('<output>', "Output path for the stats", { default: null, validator: program.STRING })
|
|
33
|
-
.action(async ({ logger, args, options }) => {
|
|
34
|
-
logger.level = "info";
|
|
35
|
-
logger.info("Calculating stats for \"" + args.input + "\"");
|
|
36
|
-
const input = args.input.toString();
|
|
37
|
-
const filestats = new Array();
|
|
38
|
-
await foreachGLTF(input, async (file) => {
|
|
39
|
-
const stats = await calculateStats(file);
|
|
40
|
-
filestats.push(stats);
|
|
41
|
-
});
|
|
42
|
-
let output = args.ourput?.toString();
|
|
43
|
-
if (!output) {
|
|
44
|
-
if (isDirectory(input)) {
|
|
45
|
-
output = path.join(input, "stats.needle.json");
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
output = input + ".needle.stats.json";
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
logger.info("Writing stats to: " + output);
|
|
52
|
-
writeFileStatsToFile(filestats, output);
|
|
53
|
-
})
|
|
54
|
-
.command("transform", "Transform (progressive loading) and compress glTF, GLB or VRM files")
|
|
55
|
-
.help(`
|
|
56
|
-
This will produce multiple versions of the input file, each with a different level of optimization.
|
|
57
|
-
Each version will be compressed and written to the output directory.
|
|
58
|
-
`)
|
|
59
|
-
.argument('<input>', "The input glTF, GLB or VRM file that should be compressed OR a directory that contains files to be compressed")
|
|
60
|
-
// .argument('<output>', "The output file. If not provided, the input file will be overwritten.", { default: "" })
|
|
61
|
-
.option("--compress", `When enabled files will be compressed`, { validator: program.BOOLEAN, default: true })
|
|
62
|
-
.option("--progressive", `When enabled files will processed to be progressively loaded`, { validator: program.BOOLEAN, default: true })
|
|
63
|
-
.option("--usecase <usecase>", `The usecase for the compression. This will set the compression settings. Possible options: [${UsecaseOptions.join(", ")}]`, { validator: program.STRING })
|
|
64
|
-
.option("--config <config>", "The path to a JSON file containing the compression settings. This can also be a needle.config.json file with a \"compression\" object or usecase string.", { validator: program.STRING })
|
|
65
|
-
.option("--stats", "Output a stats file next to input file (or inside the input directory). It will be named as the input file/directory \"<input>.needle.stats.json\"", { validator: program.BOOLEAN, default: false })
|
|
66
|
-
.option("--cache", "Use \"--cache False\" to disable caching.\nWhen caching is enabled then previously processed files will be detected and loaded from disc cache instead of being processed again if settings or the file contents have not changed.", { validator: program.BOOLEAN, default: true })
|
|
67
|
-
.option("--debug", "Enable for more verbose outout with \"--debug True\"", { validator: program.BOOLEAN, default: false })
|
|
68
|
-
.option("--verbose", "Enable for more verbose outout with \"--verbose True\"", { validator: program.BOOLEAN, default: false })
|
|
69
|
-
.action(async ({ logger, args, options }) => {
|
|
70
|
-
if (options.compress === false && options.progressive === false) {
|
|
71
|
-
logger.error("You need to enable at least one of the options: --compress or --progressive");
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
logger.info("Transforming glTF file: " + args.input);
|
|
75
|
-
const stats = {
|
|
76
|
-
startTime: Date.now(),
|
|
77
|
-
totalGPUMemoryInMB: 0,
|
|
78
|
-
totalFilesProcessed: 0,
|
|
79
|
-
totalFileSizeInMB: 0,
|
|
80
|
-
totalFileSizeInMBBefore: 0,
|
|
81
|
-
};
|
|
82
|
-
const file = args.input.toString();
|
|
83
|
-
let config = getConfig(options.config?.toString(), file, {
|
|
84
|
-
logger
|
|
85
|
-
});
|
|
86
|
-
if (options.usecase) {
|
|
87
|
-
logger.info("Using usecase: " + options.usecase);
|
|
88
|
-
config = { ...createConfig(options.usecase.toString()), ...config, };
|
|
89
|
-
if (config.usecase != "default" && config.usecase != options.usecase.toString()) {
|
|
90
|
-
logger.warn(`Conflicting usecase. Your specific config at \"${options.config}\" has a different usecase than the one provided by the CLI: \"${options.usecase}\". Using the usecase from the config file.`);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
config.usecase = options.usecase.toString();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const output = options.output?.toString() || file;
|
|
97
|
-
const outputIsDirectory = statSync(output).isDirectory();
|
|
98
|
-
const outDir = outputIsDirectory ? output : dirname(output);
|
|
99
|
-
const file_stats = options.stats === true ? new Array : null;
|
|
100
|
-
const set = new Set();
|
|
101
|
-
const useCache = options.cache !== false;
|
|
102
|
-
const debug = options.debug === true;
|
|
103
|
-
await foreachGLTF(file, async (file) => {
|
|
104
|
-
logger.info("→ Transform " + file);
|
|
105
|
-
const progressive_results = new Array();
|
|
106
|
-
if (options.progressive === true) {
|
|
107
|
-
if (await make_progressive({
|
|
108
|
-
path: file,
|
|
109
|
-
results: progressive_results,
|
|
110
|
-
config,
|
|
111
|
-
debug,
|
|
112
|
-
useCache,
|
|
113
|
-
}).catch(err => {
|
|
114
|
-
logger.error(err);
|
|
115
|
-
process.exit(ERROR_CODES.PROGRESSIVE_FAILED);
|
|
116
|
-
}) === false) {
|
|
117
|
-
process.exit(ERROR_CODES.PROGRESSIVE_FAILED);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (options.compress === true) {
|
|
121
|
-
const opts = {
|
|
122
|
-
config,
|
|
123
|
-
stats,
|
|
124
|
-
packedFiles: set,
|
|
125
|
-
debug,
|
|
126
|
-
useCache,
|
|
127
|
-
logger: logger,
|
|
128
|
-
file_stats,
|
|
129
|
-
};
|
|
130
|
-
for (const res of progressive_results) {
|
|
131
|
-
if (await packGLTF(res, res, opts) === false) {
|
|
132
|
-
process.exit(ERROR_CODES.PACKING_FAILED);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (await packGLTF(file, file, opts) === false) {
|
|
136
|
-
process.exit(ERROR_CODES.PACKING_FAILED);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
printStats(stats, logger, config);
|
|
141
|
-
if (options.stats) {
|
|
142
|
-
const statsFile = (outputIsDirectory ? (path.join(file, getDirName(file))) : file) + ".needle.stats.json";
|
|
143
|
-
writeFileStatsToFile(file_stats, statsFile);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
program.run().catch(err => {
|
|
147
|
-
// Since we still invoke this package with paths when running npm scripts we need to ignore this error
|
|
148
|
-
// We might want to move this code here into an extra package.
|
|
149
|
-
if (err.message.includes("Unknown command") && !err.message.includes("Did you mean")) {
|
|
150
|
-
// ignore
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
throw err;
|
|
154
|
-
});
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
import { program } from '@donmccurdy/caporal';
|
|
3
|
+
import { calculateStats, packGLTF } from "../scripts/index.js";
|
|
4
|
+
import { printStats, writeFileStatsToFile } from '../utils/stats.js';
|
|
5
|
+
import { getVersion } from '../utils/version.js';
|
|
6
|
+
import { UsecaseOptions, createConfig, getConfig } from '../config/index.js';
|
|
7
|
+
import { make_progressive } from '../transforms/needle_progressive.js';
|
|
8
|
+
import { cacheSizeLimit, clearCache } from '../cache/cache.js';
|
|
9
|
+
import { statSync } from 'fs';
|
|
10
|
+
import { foreachGLTF, getDirName, isDirectory } from '../utils/fileutils.js';
|
|
11
|
+
import path, { dirname } from 'path';
|
|
12
|
+
import { ERROR_CODES } from '../constants.js';
|
|
13
|
+
// For testing / dev you can run `npm link` in the package directory
|
|
14
|
+
// For removing the link run `npm rm --global @needle-tools/gltf-build-pipeline`
|
|
15
|
+
program
|
|
16
|
+
.command("version", "Print current verison")
|
|
17
|
+
.action(async ({ logger }) => {
|
|
18
|
+
logger.info(getVersion());
|
|
19
|
+
})
|
|
20
|
+
.command("clear-caches", "Clear all caches")
|
|
21
|
+
.help(`Clears all cached files
|
|
22
|
+
Caches are limited to ${cacheSizeLimit} MB disc space by default.
|
|
23
|
+
`)
|
|
24
|
+
.action(async ({ logger }) => {
|
|
25
|
+
logger.info("Clearing caches");
|
|
26
|
+
clearCache(logger);
|
|
27
|
+
})
|
|
28
|
+
.command("stats", "Calculate glTF stats")
|
|
29
|
+
.help(`
|
|
30
|
+
`)
|
|
31
|
+
.argument('<input>', "Path to a glTF, GLB or VRM file OR a directory")
|
|
32
|
+
.argument('<output>', "Output path for the stats", { default: null, validator: program.STRING })
|
|
33
|
+
.action(async ({ logger, args, options }) => {
|
|
34
|
+
logger.level = "info";
|
|
35
|
+
logger.info("Calculating stats for \"" + args.input + "\"");
|
|
36
|
+
const input = args.input.toString();
|
|
37
|
+
const filestats = new Array();
|
|
38
|
+
await foreachGLTF(input, async (file) => {
|
|
39
|
+
const stats = await calculateStats(file);
|
|
40
|
+
filestats.push(stats);
|
|
41
|
+
});
|
|
42
|
+
let output = args.ourput?.toString();
|
|
43
|
+
if (!output) {
|
|
44
|
+
if (isDirectory(input)) {
|
|
45
|
+
output = path.join(input, "stats.needle.json");
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
output = input + ".needle.stats.json";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
logger.info("Writing stats to: " + output);
|
|
52
|
+
writeFileStatsToFile(filestats, output);
|
|
53
|
+
})
|
|
54
|
+
.command("transform", "Transform (progressive loading) and compress glTF, GLB or VRM files")
|
|
55
|
+
.help(`
|
|
56
|
+
This will produce multiple versions of the input file, each with a different level of optimization.
|
|
57
|
+
Each version will be compressed and written to the output directory.
|
|
58
|
+
`)
|
|
59
|
+
.argument('<input>', "The input glTF, GLB or VRM file that should be compressed OR a directory that contains files to be compressed")
|
|
60
|
+
// .argument('<output>', "The output file. If not provided, the input file will be overwritten.", { default: "" })
|
|
61
|
+
.option("--compress", `When enabled files will be compressed`, { validator: program.BOOLEAN, default: true })
|
|
62
|
+
.option("--progressive", `When enabled files will processed to be progressively loaded`, { validator: program.BOOLEAN, default: true })
|
|
63
|
+
.option("--usecase <usecase>", `The usecase for the compression. This will set the compression settings. Possible options: [${UsecaseOptions.join(", ")}]`, { validator: program.STRING })
|
|
64
|
+
.option("--config <config>", "The path to a JSON file containing the compression settings. This can also be a needle.config.json file with a \"compression\" object or usecase string.", { validator: program.STRING })
|
|
65
|
+
.option("--stats", "Output a stats file next to input file (or inside the input directory). It will be named as the input file/directory \"<input>.needle.stats.json\"", { validator: program.BOOLEAN, default: false })
|
|
66
|
+
.option("--cache", "Use \"--cache False\" to disable caching.\nWhen caching is enabled then previously processed files will be detected and loaded from disc cache instead of being processed again if settings or the file contents have not changed.", { validator: program.BOOLEAN, default: true })
|
|
67
|
+
.option("--debug", "Enable for more verbose outout with \"--debug True\"", { validator: program.BOOLEAN, default: false })
|
|
68
|
+
.option("--verbose", "Enable for more verbose outout with \"--verbose True\"", { validator: program.BOOLEAN, default: false })
|
|
69
|
+
.action(async ({ logger, args, options }) => {
|
|
70
|
+
if (options.compress === false && options.progressive === false) {
|
|
71
|
+
logger.error("You need to enable at least one of the options: --compress or --progressive");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
logger.info("Transforming glTF file: " + args.input);
|
|
75
|
+
const stats = {
|
|
76
|
+
startTime: Date.now(),
|
|
77
|
+
totalGPUMemoryInMB: 0,
|
|
78
|
+
totalFilesProcessed: 0,
|
|
79
|
+
totalFileSizeInMB: 0,
|
|
80
|
+
totalFileSizeInMBBefore: 0,
|
|
81
|
+
};
|
|
82
|
+
const file = args.input.toString();
|
|
83
|
+
let config = getConfig(options.config?.toString(), file, {
|
|
84
|
+
logger
|
|
85
|
+
});
|
|
86
|
+
if (options.usecase) {
|
|
87
|
+
logger.info("Using usecase: " + options.usecase);
|
|
88
|
+
config = { ...createConfig(options.usecase.toString()), ...config, };
|
|
89
|
+
if (config.usecase != "default" && config.usecase != options.usecase.toString()) {
|
|
90
|
+
logger.warn(`Conflicting usecase. Your specific config at \"${options.config}\" has a different usecase than the one provided by the CLI: \"${options.usecase}\". Using the usecase from the config file.`);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
config.usecase = options.usecase.toString();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const output = options.output?.toString() || file;
|
|
97
|
+
const outputIsDirectory = statSync(output).isDirectory();
|
|
98
|
+
const outDir = outputIsDirectory ? output : dirname(output);
|
|
99
|
+
const file_stats = options.stats === true ? new Array : null;
|
|
100
|
+
const set = new Set();
|
|
101
|
+
const useCache = options.cache !== false;
|
|
102
|
+
const debug = options.debug === true;
|
|
103
|
+
await foreachGLTF(file, async (file) => {
|
|
104
|
+
logger.info("→ Transform " + file);
|
|
105
|
+
const progressive_results = new Array();
|
|
106
|
+
if (options.progressive === true) {
|
|
107
|
+
if (await make_progressive({
|
|
108
|
+
path: file,
|
|
109
|
+
results: progressive_results,
|
|
110
|
+
config,
|
|
111
|
+
debug,
|
|
112
|
+
useCache,
|
|
113
|
+
}).catch(err => {
|
|
114
|
+
logger.error(err);
|
|
115
|
+
process.exit(ERROR_CODES.PROGRESSIVE_FAILED);
|
|
116
|
+
}) === false) {
|
|
117
|
+
process.exit(ERROR_CODES.PROGRESSIVE_FAILED);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (options.compress === true) {
|
|
121
|
+
const opts = {
|
|
122
|
+
config,
|
|
123
|
+
stats,
|
|
124
|
+
packedFiles: set,
|
|
125
|
+
debug,
|
|
126
|
+
useCache,
|
|
127
|
+
logger: logger,
|
|
128
|
+
file_stats,
|
|
129
|
+
};
|
|
130
|
+
for (const res of progressive_results) {
|
|
131
|
+
if (await packGLTF(res, res, opts) === false) {
|
|
132
|
+
process.exit(ERROR_CODES.PACKING_FAILED);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (await packGLTF(file, file, opts) === false) {
|
|
136
|
+
process.exit(ERROR_CODES.PACKING_FAILED);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
printStats(stats, logger, config);
|
|
141
|
+
if (options.stats) {
|
|
142
|
+
const statsFile = (outputIsDirectory ? (path.join(file, getDirName(file))) : file) + ".needle.stats.json";
|
|
143
|
+
writeFileStatsToFile(file_stats, statsFile);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
program.run().catch(err => {
|
|
147
|
+
// Since we still invoke this package with paths when running npm scripts we need to ignore this error
|
|
148
|
+
// We might want to move this code here into an extra package.
|
|
149
|
+
if (err.message.includes("Unknown command") && !err.message.includes("Did you mean")) {
|
|
150
|
+
// ignore
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
throw err;
|
|
154
|
+
});
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { ILogger } from "@gltf-transform/core";
|
|
2
|
-
declare type Usecase = "default" | "product" | "world";
|
|
3
|
-
export declare const UsecaseOptions: string[];
|
|
4
|
-
/**
|
|
5
|
-
* The config object contains information about how a file should be processed.
|
|
6
|
-
*/
|
|
7
|
-
export type Config = {
|
|
8
|
-
/** High-level configuration */
|
|
9
|
-
usecase: Usecase;
|
|
10
|
-
textures?: {
|
|
11
|
-
lods: boolean;
|
|
12
|
-
};
|
|
13
|
-
meshes?: {
|
|
14
|
-
lods: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Create a config object with the given usecase.
|
|
19
|
-
*/
|
|
20
|
-
export declare function createConfig(usecase: string): {
|
|
21
|
-
usecase: Usecase;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Get the config object either provided by a CLI path or a needle.config.json file in the parent directory.
|
|
25
|
-
*
|
|
26
|
-
* @example CLI argument where the path points to a json file containing the config as `Config`
|
|
27
|
-
* ```sh
|
|
28
|
-
* node script.js --config path/to/my-optimization-config.json
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @example needle.config.json - the usecase can be provided as a string
|
|
32
|
-
* ```json
|
|
33
|
-
* {
|
|
34
|
-
* "optimization": "product"
|
|
35
|
-
* }
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* @example needle.config.json - the whole config object can be provided
|
|
39
|
-
* ```json
|
|
40
|
-
* {
|
|
41
|
-
* "optimization": {
|
|
42
|
-
* "usecase": "product"
|
|
43
|
-
* }
|
|
44
|
-
* }
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
export declare function getConfig(configPath?: string, fallbackSearchDirectory?: string, opts?: {
|
|
50
|
-
logger: ILogger;
|
|
51
|
-
}): Config;
|
|
52
|
-
export declare function searchConfig(directory: string, logger: ILogger): Config | null;
|
|
53
|
-
export {};
|
|
1
|
+
import { ILogger } from "@gltf-transform/core";
|
|
2
|
+
declare type Usecase = "default" | "product" | "world";
|
|
3
|
+
export declare const UsecaseOptions: string[];
|
|
4
|
+
/**
|
|
5
|
+
* The config object contains information about how a file should be processed.
|
|
6
|
+
*/
|
|
7
|
+
export type Config = {
|
|
8
|
+
/** High-level configuration */
|
|
9
|
+
usecase: Usecase;
|
|
10
|
+
textures?: {
|
|
11
|
+
lods: boolean;
|
|
12
|
+
};
|
|
13
|
+
meshes?: {
|
|
14
|
+
lods: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Create a config object with the given usecase.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createConfig(usecase: string): {
|
|
21
|
+
usecase: Usecase;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Get the config object either provided by a CLI path or a needle.config.json file in the parent directory.
|
|
25
|
+
*
|
|
26
|
+
* @example CLI argument where the path points to a json file containing the config as `Config`
|
|
27
|
+
* ```sh
|
|
28
|
+
* node script.js --config path/to/my-optimization-config.json
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example needle.config.json - the usecase can be provided as a string
|
|
32
|
+
* ```json
|
|
33
|
+
* {
|
|
34
|
+
* "optimization": "product"
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example needle.config.json - the whole config object can be provided
|
|
39
|
+
* ```json
|
|
40
|
+
* {
|
|
41
|
+
* "optimization": {
|
|
42
|
+
* "usecase": "product"
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
export declare function getConfig(configPath?: string, fallbackSearchDirectory?: string, opts?: {
|
|
50
|
+
logger: ILogger;
|
|
51
|
+
}): Config;
|
|
52
|
+
export declare function searchConfig(directory: string, logger: ILogger): Config | null;
|
|
53
|
+
export {};
|