@needle-tools/gltf-build-pipeline 2.9.3 → 2.9.5-experimental.0dfa267

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +486 -482
  2. package/README.md +35 -35
  3. package/package.json +78 -78
  4. package/scripts/clear-caches.mjs +3 -3
  5. package/scripts/defaults.mjs +11 -11
  6. package/scripts/fileutils.mjs +5 -5
  7. package/scripts/index.mjs +41 -41
  8. package/scripts/limit-caches.mjs +3 -3
  9. package/scripts/make-progressive.mjs +16 -16
  10. package/scripts/pack-gltf.mjs +106 -106
  11. package/tsconfig.json +19 -19
  12. package/dist/cache/cache.d.ts +0 -55
  13. package/dist/cache/cache.js +0 -289
  14. package/dist/cache/index.d.ts +0 -1
  15. package/dist/cache/index.js +0 -1
  16. package/dist/cli/index.d.ts +0 -2
  17. package/dist/cli/index.js +0 -189
  18. package/dist/config/index.d.ts +0 -53
  19. package/dist/config/index.js +0 -152
  20. package/dist/constants.d.ts +0 -7
  21. package/dist/constants.js +0 -7
  22. package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +0 -24
  23. package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +0 -54
  24. package/dist/extensions/NEEDLE_compression_texture/index.d.ts +0 -1
  25. package/dist/extensions/NEEDLE_compression_texture/index.js +0 -1
  26. package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +0 -27
  27. package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +0 -88
  28. package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +0 -1
  29. package/dist/extensions/NEEDLE_mesh_compression/index.js +0 -1
  30. package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +0 -27
  31. package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +0 -971
  32. package/dist/extensions/NEEDLE_opaque/index.d.ts +0 -3
  33. package/dist/extensions/NEEDLE_opaque/index.js +0 -28
  34. package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +0 -48
  35. package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +0 -69
  36. package/dist/extensions/NEEDLE_progressive/index.d.ts +0 -1
  37. package/dist/extensions/NEEDLE_progressive/index.js +0 -1
  38. package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +0 -23
  39. package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +0 -41
  40. package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +0 -25
  41. package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +0 -67
  42. package/dist/extensions/index.d.ts +0 -7
  43. package/dist/extensions/index.js +0 -17
  44. package/dist/extensions/utils.d.ts +0 -6
  45. package/dist/extensions/utils.js +0 -72
  46. package/dist/functions/weld.3.d.ts +0 -76
  47. package/dist/functions/weld.3.js +0 -414
  48. package/dist/index.d.ts +0 -8
  49. package/dist/index.js +0 -8
  50. package/dist/scripts/index.d.ts +0 -2
  51. package/dist/scripts/index.js +0 -2
  52. package/dist/scripts/pack-gltf.d.ts +0 -15
  53. package/dist/scripts/pack-gltf.js +0 -129
  54. package/dist/scripts/stats.d.ts +0 -2
  55. package/dist/scripts/stats.js +0 -19
  56. package/dist/transforms/index.d.ts +0 -9
  57. package/dist/transforms/index.js +0 -9
  58. package/dist/transforms/needle_animation_transform.d.ts +0 -2
  59. package/dist/transforms/needle_animation_transform.js +0 -5
  60. package/dist/transforms/needle_asset.d.ts +0 -3
  61. package/dist/transforms/needle_asset.js +0 -50
  62. package/dist/transforms/needle_common.d.ts +0 -17
  63. package/dist/transforms/needle_common.js +0 -1
  64. package/dist/transforms/needle_mesh_transform.d.ts +0 -15
  65. package/dist/transforms/needle_mesh_transform.js +0 -218
  66. package/dist/transforms/needle_progressive.d.ts +0 -44
  67. package/dist/transforms/needle_progressive.js +0 -1005
  68. package/dist/transforms/needle_texture_transform.d.ts +0 -13
  69. package/dist/transforms/needle_texture_transform.js +0 -251
  70. package/dist/transforms/needle_toktx.d.ts +0 -26
  71. package/dist/transforms/needle_toktx.js +0 -239
  72. package/dist/transforms/needle_webp.d.ts +0 -15
  73. package/dist/transforms/needle_webp.js +0 -53
  74. package/dist/transforms/toktx.d.ts +0 -52
  75. package/dist/transforms/toktx.js +0 -221
  76. package/dist/transforms/toktx_types.d.ts +0 -78
  77. package/dist/transforms/toktx_types.js +0 -62
  78. package/dist/transforms/util.d.ts +0 -21
  79. package/dist/transforms/util.js +0 -90
  80. package/dist/utils/compression_utils.d.ts +0 -2
  81. package/dist/utils/compression_utils.js +0 -6
  82. package/dist/utils/fileutils.d.ts +0 -19
  83. package/dist/utils/fileutils.js +0 -177
  84. package/dist/utils/guid.d.ts +0 -1
  85. package/dist/utils/guid.js +0 -5
  86. package/dist/utils/index.d.ts +0 -10
  87. package/dist/utils/index.js +0 -10
  88. package/dist/utils/merge.d.ts +0 -12
  89. package/dist/utils/merge.js +0 -31
  90. package/dist/utils/mesh.d.ts +0 -13
  91. package/dist/utils/mesh.js +0 -124
  92. package/dist/utils/nodeio.d.ts +0 -6
  93. package/dist/utils/nodeio.js +0 -86
  94. package/dist/utils/stats.d.ts +0 -70
  95. package/dist/utils/stats.js +0 -258
  96. package/dist/utils/texture.d.ts +0 -5
  97. package/dist/utils/texture.js +0 -14
  98. package/dist/utils/validate.d.ts +0 -5
  99. package/dist/utils/validate.js +0 -17
  100. package/dist/utils/version.d.ts +0 -1
  101. package/dist/utils/version.gen.d.ts +0 -1
  102. package/dist/utils/version.gen.js +0 -1
  103. package/dist/utils/version.js +0 -4
package/README.md CHANGED
@@ -1,35 +1,35 @@
1
- # glTF Build Pipeline
2
-
3
- Creating optimized glTF, GLB and VRM files for the web.
4
- Includes support for generating LOD quality level for textures and meshes that can be used with [@needle-tools/gltf-progressive](https://www.npmjs.com/package/@needle-tools/gltf-progressive)
5
-
6
- ## Examples
7
-
8
- - [Example on Github](https://github.com/needle-engine/progressive-meshes-sample)
9
-
10
-
11
- ## Usage
12
-
13
- In general all files that have been processed by this package are valid glTF/GLB files.
14
- The glTF Build Pipeline package is meant to be used as a last step before delivery.
15
- That means:
16
- - files are meant to be loaded e.g. in a web runtime like three.js
17
- - files are not to be opened in Blender again to be further edited
18
-
19
- To load progressively enhanced glTF files in any three.js based engine see examples at [@needle-tools/gltf-progressive](https://www.npmjs.com/package/@needle-tools/gltf-progressive)
20
-
21
- ### Installation
22
-
23
- `npx @needle-tools/gltf-build-pipeline@latest`
24
-
25
- ### Commands
26
- - `gltf-build-pipeline help` - use help to see options for each command
27
- - `gltf-build-pipeline compress <input>`
28
- - `gltf-build-pipeline transform <input>`
29
-
30
- # Contact ✒️
31
- <b>[🌵 needle — tools for creators](https://needle.tools)</b> •
32
- [Twitter](https://twitter.com/NeedleTools) •
33
- [Discord](https://discord.needle.tools) •
34
- [Forum](https://forum.needle.tools)
35
-
1
+ # glTF Build Pipeline
2
+
3
+ Creating optimized glTF, GLB and VRM files for the web.
4
+ Includes support for generating LOD quality level for textures and meshes that can be used with [@needle-tools/gltf-progressive](https://www.npmjs.com/package/@needle-tools/gltf-progressive)
5
+
6
+ ## Examples
7
+
8
+ - [Example on Github](https://github.com/needle-engine/progressive-meshes-sample)
9
+
10
+
11
+ ## Usage
12
+
13
+ In general all files that have been processed by this package are valid glTF/GLB files.
14
+ The glTF Build Pipeline package is meant to be used as a last step before delivery.
15
+ That means:
16
+ - files are meant to be loaded e.g. in a web runtime like three.js
17
+ - files are not to be opened in Blender again to be further edited
18
+
19
+ To load progressively enhanced glTF files in any three.js based engine see examples at [@needle-tools/gltf-progressive](https://www.npmjs.com/package/@needle-tools/gltf-progressive)
20
+
21
+ ### Installation
22
+
23
+ `npx @needle-tools/gltf-build-pipeline@latest`
24
+
25
+ ### Commands
26
+ - `gltf-build-pipeline help` - use help to see options for each command
27
+ - `gltf-build-pipeline compress <input>`
28
+ - `gltf-build-pipeline transform <input>`
29
+
30
+ # Contact ✒️
31
+ <b>[🌵 needle — tools for creators](https://needle.tools)</b> •
32
+ [Twitter](https://twitter.com/NeedleTools) •
33
+ [Discord](https://discord.needle.tools) •
34
+ [Forum](https://forum.needle.tools)
35
+
package/package.json CHANGED
@@ -1,78 +1,78 @@
1
- {
2
- "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "2.9.3",
4
- "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
- "main": "dist/index.js",
6
- "type": "module",
7
- "readme": "README.md",
8
- "author": {
9
- "name": "Needle",
10
- "email": "help@needle.tools",
11
- "url": "https://needle.tools/"
12
- },
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/needle-tools/needle-gltf-extensions.git"
16
- },
17
- "bin": {
18
- "gltf-build-pipeline": "dist/cli/index.js",
19
- "needle-gltf": "dist/cli/index.js"
20
- },
21
- "imports": {
22
- "#package.json": "./package.json"
23
- },
24
- "scripts": {
25
- "start": "node scripts/index.mjs",
26
- "dev": "npm-watch compile",
27
- "publish": "npm run compile && npm publish --access public --tag latest",
28
- "publish-tag": "npm dist-tag add @needle-tools/gltf-build-pipeline@2.7.0 latest",
29
- "compile": "node tools/prebuild.mjs && (tsc || exit 1) && node tools/postbuild.mjs",
30
- "clear-caches": "node scripts/clear-caches.mjs",
31
- "limit-caches": "node scripts/limit-caches.mjs",
32
- "transform": "node scripts/index.mjs",
33
- "transform:make-progressive": "node scripts/make-progressive.mjs",
34
- "transform:pack-gltf": "node --no-experimental-fetch scripts/pack-gltf.mjs",
35
- "pack-gltf": "node --no-experimental-fetch scripts/pack-gltf.mjs",
36
- "dev:pack-gltf": "npm run compile && node scripts/pack-gltf.mjs"
37
- },
38
- "devDependencies": {
39
- "@types/node": "^18.7.23",
40
- "npm-watch": "^0.13.0",
41
- "typescript": "^4.9.5"
42
- },
43
- "optionalDependencies": {
44
- "@img/sharp-darwin-arm64": "^0.33.4",
45
- "@img/sharp-darwin-x64": "^0.33.4",
46
- "@img/sharp-linux-arm": "^0.33.4",
47
- "@img/sharp-win32-x64": "^0.33.4"
48
- },
49
- "dependencies": {
50
- "@donmccurdy/caporal": "~0.0.10",
51
- "@gltf-transform/core": "^4.1.1",
52
- "@gltf-transform/extensions": "^4.1.1",
53
- "@gltf-transform/functions": "^4.1.1",
54
- "command-exists": "^1.2.9",
55
- "command-line-args": "^5.2.1",
56
- "draco3dgltf": "^1.5.3",
57
- "glob": "^7.2.0",
58
- "meshoptimizer": "^0.18.1",
59
- "micromatch": "^4.0.5",
60
- "ndarray": "^1.0.19",
61
- "ndarray-lanczos": "^0.3.0",
62
- "ndarray-pixels": "^2.0.1",
63
- "p-limit": "3.1.0",
64
- "semver": "^7.3.7",
65
- "sharp": "^0.33.4",
66
- "tmp": "^0.2.1",
67
- "uuid": "^9.0.1"
68
- },
69
- "watch": {
70
- "compile": {
71
- "patterns": [
72
- "src"
73
- ],
74
- "extensions": "ts",
75
- "quiet": false
76
- }
77
- }
78
- }
1
+ {
2
+ "name": "@needle-tools/gltf-build-pipeline",
3
+ "version": "2.9.5-experimental.0dfa267",
4
+ "description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "readme": "README.md",
8
+ "author": {
9
+ "name": "Needle",
10
+ "email": "help@needle.tools",
11
+ "url": "https://needle.tools/"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/needle-tools/needle-gltf-extensions.git"
16
+ },
17
+ "bin": {
18
+ "gltf-build-pipeline": "dist/cli/index.js",
19
+ "needle-gltf": "dist/cli/index.js"
20
+ },
21
+ "imports": {
22
+ "#package.json": "./package.json"
23
+ },
24
+ "scripts": {
25
+ "start": "node scripts/index.mjs",
26
+ "dev": "npm-watch compile",
27
+ "publish-package": "npm run compile && npm publish",
28
+ "publish-package-tag": "npm dist-tag add @needle-tools/gltf-build-pipeline@2.7.0 latest",
29
+ "compile": "node tools/prebuild.mjs && (tsc || exit 1) && node tools/postbuild.mjs",
30
+ "clear-caches": "node scripts/clear-caches.mjs",
31
+ "limit-caches": "node scripts/limit-caches.mjs",
32
+ "transform": "node scripts/index.mjs",
33
+ "transform:make-progressive": "node scripts/make-progressive.mjs",
34
+ "transform:pack-gltf": "node --no-experimental-fetch scripts/pack-gltf.mjs",
35
+ "pack-gltf": "node --no-experimental-fetch scripts/pack-gltf.mjs",
36
+ "dev:pack-gltf": "npm run compile && node scripts/pack-gltf.mjs"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^18.7.23",
40
+ "npm-watch": "^0.13.0",
41
+ "typescript": "^4.9.5"
42
+ },
43
+ "optionalDependencies": {
44
+ "@img/sharp-darwin-arm64": "^0.33.4",
45
+ "@img/sharp-darwin-x64": "^0.33.4",
46
+ "@img/sharp-linux-arm": "^0.33.4",
47
+ "@img/sharp-win32-x64": "^0.33.4"
48
+ },
49
+ "dependencies": {
50
+ "@donmccurdy/caporal": "~0.0.10",
51
+ "@gltf-transform/core": "4.1.3",
52
+ "@gltf-transform/extensions": "4.1.3",
53
+ "@gltf-transform/functions": "4.1.3",
54
+ "command-exists": "^1.2.9",
55
+ "command-line-args": "^5.2.1",
56
+ "draco3dgltf": "^1.5.3",
57
+ "glob": "^7.2.0",
58
+ "meshoptimizer": "^0.18.1",
59
+ "micromatch": "^4.0.5",
60
+ "ndarray": "^1.0.19",
61
+ "ndarray-lanczos": "^0.3.0",
62
+ "ndarray-pixels": "^2.0.1",
63
+ "p-limit": "3.1.0",
64
+ "semver": "^7.3.7",
65
+ "sharp": "^0.33.4",
66
+ "tmp": "^0.2.1",
67
+ "uuid": "^9.0.1"
68
+ },
69
+ "watch": {
70
+ "compile": {
71
+ "patterns": [
72
+ "src"
73
+ ],
74
+ "extensions": "ts",
75
+ "quiet": false
76
+ }
77
+ }
78
+ }
@@ -1,4 +1,4 @@
1
-
2
- import { clearCache } from '../dist/cache/index.js';
3
-
1
+
2
+ import { clearCache } from '../dist/cache/index.js';
3
+
4
4
  clearCache();
@@ -1,12 +1,12 @@
1
- import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
2
- import { ALL_EXTENSIONS as NEEDLE_EXTENSIONS } from "../dist/extensions/NEEDLE_opaque/index.js";
3
- import { NEEDLE_progressive } from '../dist/index.js';
4
-
5
-
6
- export function registerExtensions(node) {
7
- node.registerExtensions(ALL_EXTENSIONS);
8
- node.registerExtensions(NEEDLE_EXTENSIONS);
9
- node.registerExtensions([
10
- NEEDLE_progressive
11
- ])
1
+ import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
2
+ import { ALL_EXTENSIONS as NEEDLE_EXTENSIONS } from "../dist/extensions/NEEDLE_opaque/index.js";
3
+ import { NEEDLE_progressive } from '../dist/index.js';
4
+
5
+
6
+ export function registerExtensions(node) {
7
+ node.registerExtensions(ALL_EXTENSIONS);
8
+ node.registerExtensions(NEEDLE_EXTENSIONS);
9
+ node.registerExtensions([
10
+ NEEDLE_progressive
11
+ ])
12
12
  }
@@ -1,6 +1,6 @@
1
- import { foreachGLTF as foreach } from '../dist/index.js';
2
-
3
-
4
- export function foreachGLTF(args, callback) {
5
- return foreach(args, callback);
1
+ import { foreachGLTF as foreach } from '../dist/index.js';
2
+
3
+
4
+ export function foreachGLTF(args, callback) {
5
+ return foreach(args, callback);
6
6
  }
package/scripts/index.mjs CHANGED
@@ -1,41 +1,41 @@
1
-
2
- import { spawnSync } from "child_process";
3
- import { getVersion } from "../dist/index.js";
4
-
5
- const workingDir = process.cwd();
6
-
7
- // Original invoked dir set by npm
8
- // const dir = process.env.INIT_CWD;
9
-
10
-
11
- const defaultArgs = { shell: true, cwd: workingDir, stdio: 'inherit' }
12
-
13
- function getCommandLineArgs(_cmd) {
14
- // Wrap paths with parentheses if they contain spaces
15
- const args = process.argv.slice(2);
16
- for (let i = 0; i < args.length; i++) {
17
- const arg = args[i];
18
- if (arg.includes("\\") || arg.includes("/")) {
19
- if (arg.includes(" "))
20
- args[i] = "\"" + arg + "\"";
21
- }
22
- }
23
- return args;
24
- }
25
-
26
-
27
- function runWithArgs(cmd) {
28
- const commandline_args = getCommandLineArgs(cmd).join(" ");
29
- spawnSync(cmd + " " + commandline_args, defaultArgs);
30
- }
31
-
32
- try {
33
- const startTime = Date.now();
34
- runWithArgs("node scripts/make-progressive.mjs");
35
- runWithArgs("node scripts/pack-gltf.mjs");
36
- const durationInMinutes = ((Date.now() - startTime) / 1000 / 60).toFixed(1);
37
- console.log(`[Needle Build Pipeline] v${getVersion()} — Finished progressive transform and optimization in ${durationInMinutes} minutes.`);
38
- }
39
- catch (err) {
40
- console.error("Failed running commandline args:", err.message);
41
- }
1
+
2
+ import { spawnSync } from "child_process";
3
+ import { getVersion } from "../dist/index.js";
4
+
5
+ const workingDir = process.cwd();
6
+
7
+ // Original invoked dir set by npm
8
+ // const dir = process.env.INIT_CWD;
9
+
10
+
11
+ const defaultArgs = { shell: true, cwd: workingDir, stdio: 'inherit' }
12
+
13
+ function getCommandLineArgs(_cmd) {
14
+ // Wrap paths with parentheses if they contain spaces
15
+ const args = process.argv.slice(2);
16
+ for (let i = 0; i < args.length; i++) {
17
+ const arg = args[i];
18
+ if (arg.includes("\\") || arg.includes("/")) {
19
+ if (arg.includes(" "))
20
+ args[i] = "\"" + arg + "\"";
21
+ }
22
+ }
23
+ return args;
24
+ }
25
+
26
+
27
+ function runWithArgs(cmd) {
28
+ const commandline_args = getCommandLineArgs(cmd).join(" ");
29
+ spawnSync(cmd + " " + commandline_args, defaultArgs);
30
+ }
31
+
32
+ try {
33
+ const startTime = Date.now();
34
+ runWithArgs("node scripts/make-progressive.mjs");
35
+ runWithArgs("node scripts/pack-gltf.mjs");
36
+ const durationInMinutes = ((Date.now() - startTime) / 1000 / 60).toFixed(1);
37
+ console.log(`[Needle Build Pipeline] v${getVersion()} — Finished progressive transform and optimization in ${durationInMinutes} minutes.`);
38
+ }
39
+ catch (err) {
40
+ console.error("Failed running commandline args:", err.message);
41
+ }
@@ -1,4 +1,4 @@
1
-
2
- import { limitCacheSize } from '../dist/cache/index.js';
3
-
1
+
2
+ import { limitCacheSize } from '../dist/cache/index.js';
3
+
4
4
  limitCacheSize(512);
@@ -1,16 +1,16 @@
1
- import { getConfig, getVersion } from '../dist/index.js';
2
- import { make_progressive } from '../dist/transforms/needle_progressive.js';
3
-
4
- const args = process.argv;
5
-
6
- console.log(`[Needle Build Pipeline] transform to progressive — version ${getVersion()}`)
7
-
8
- make_progressive({
9
- path: args,
10
- results: [],
11
- config: getConfig(),
12
- debug: args.includes("--debug"),
13
- useCache: args.includes("--no-caching") === false,
14
- });
15
-
16
-
1
+ import { getConfig, getVersion } from '../dist/index.js';
2
+ import { make_progressive } from '../dist/transforms/needle_progressive.js';
3
+
4
+ const args = process.argv;
5
+
6
+ console.log(`[Needle Build Pipeline] transform to progressive — version ${getVersion()}`)
7
+
8
+ make_progressive({
9
+ path: args,
10
+ results: [],
11
+ config: getConfig(),
12
+ debug: args.includes("--debug"),
13
+ useCache: args.includes("--no-caching") === false,
14
+ });
15
+
16
+
@@ -1,107 +1,107 @@
1
- import commandLineArgs from "command-line-args";
2
- import { foreachGLTF } from './fileutils.mjs';
3
- import { getVersion, limitCacheSize, getConfig, packGLTF, printStats } from '../dist/index.js';
4
- import { Logger, Verbosity } from "@gltf-transform/core";
5
-
6
- console.log(`[Needle Build Pipeline] pack glTF — version ${getVersion()}`)
7
-
8
- const args = process.argv;
9
- const showHelp = args.includes("help");
10
-
11
- const optionDefinitions = [
12
- { name: 'debug', type: Boolean },
13
- { name: 'toktxPath', type: String, multiple: true },
14
- { name: 'file', type: String, multiple: true },
15
- ];
16
- let options = undefined;
17
- try {
18
- options = commandLineArgs(optionDefinitions);
19
- }
20
- catch (err) {
21
- if (args?.includes("debug"))
22
- console.log("Failed parsing commandline args:", err.message);
23
- options = {
24
- file: [...process.argv],
25
- debug: args?.includes("debug"),
26
- toktxPath: new Array(),
27
- };
28
- for (const arg of args) {
29
- if (arg.includes("KTX-Software")) {
30
- options.toktxPath = [arg];
31
- break;
32
- }
33
- }
34
- }
35
-
36
- const toktxPaths = options?.toktxPath?.join(";");
37
- if (showHelp) {
38
- if (!toktxPaths) {
39
- console.log("You can define a toktx search path by adding --toktxPath <path> to the command line. The command may appear multiple times");
40
- }
41
- else console.log("Toktx path at " + toktxPaths);
42
- }
43
-
44
- // console.log(args);
45
- const debug = options?.debug ?? false;
46
- if (debug) {
47
- console.log(options);
48
- }
49
-
50
- let allowCaching = true;
51
- if (args.includes("--no-caching")) {
52
- allowCaching = false;
53
- }
54
- else console.log("Use --no-caching to disable caching");
55
-
56
- const noToktx = args.includes("no-toktx");
57
- if (noToktx)
58
- console.log("Using toktx is disabled");
59
-
60
- const packedFiles = new Set();
61
-
62
- /**
63
- * @type {import("../dist/index.js").ProcessStats}
64
- */
65
- const stats = {
66
- startTime: Date.now(),
67
- totalGPUMemoryInMB: 0,
68
- totalFilesProcessed: 0,
69
- totalFileSizeInMB: 0,
70
- totalFileSizeInMBBefore: 0,
71
- };
72
-
73
- const config = getConfig();
74
-
75
-
76
- /** Compress a glTF file
77
- * @param {string} file
78
- */
79
- async function packFile(file) {
80
- return packGLTF(file, file, {
81
- config,
82
- debug,
83
- packedFiles,
84
- useCache: allowCaching,
85
- stats,
86
- })
87
- }
88
-
89
- const inputArgs = args.slice(2);
90
- let failed = false;
91
- const logger = new Logger(Verbosity.INFO);
92
-
93
- foreachGLTF(inputArgs, async (file) => {
94
- const res = await packFile(file);
95
- if (!res) failed = true;
96
- }).then(async () => {
97
- if (allowCaching) {
98
- limitCacheSize();
99
- }
100
- printStats(stats, logger, config);
101
- if (failed) {
102
- process.exit(1);
103
- }
104
- }).catch(err => {
105
- console.error("ERR: packing failed: " + err.message);
106
- if (debug) throw err;
1
+ import commandLineArgs from "command-line-args";
2
+ import { foreachGLTF } from './fileutils.mjs';
3
+ import { getVersion, limitCacheSize, getConfig, packGLTF, printStats } from '../dist/index.js';
4
+ import { Logger, Verbosity } from "@gltf-transform/core";
5
+
6
+ console.log(`[Needle Build Pipeline] pack glTF — version ${getVersion()}`)
7
+
8
+ const args = process.argv;
9
+ const showHelp = args.includes("help");
10
+
11
+ const optionDefinitions = [
12
+ { name: 'debug', type: Boolean },
13
+ { name: 'toktxPath', type: String, multiple: true },
14
+ { name: 'file', type: String, multiple: true },
15
+ ];
16
+ let options = undefined;
17
+ try {
18
+ options = commandLineArgs(optionDefinitions);
19
+ }
20
+ catch (err) {
21
+ if (args?.includes("debug"))
22
+ console.log("Failed parsing commandline args:", err.message);
23
+ options = {
24
+ file: [...process.argv],
25
+ debug: args?.includes("debug"),
26
+ toktxPath: new Array(),
27
+ };
28
+ for (const arg of args) {
29
+ if (arg.includes("KTX-Software")) {
30
+ options.toktxPath = [arg];
31
+ break;
32
+ }
33
+ }
34
+ }
35
+
36
+ const toktxPaths = options?.toktxPath?.join(";");
37
+ if (showHelp) {
38
+ if (!toktxPaths) {
39
+ console.log("You can define a toktx search path by adding --toktxPath <path> to the command line. The command may appear multiple times");
40
+ }
41
+ else console.log("Toktx path at " + toktxPaths);
42
+ }
43
+
44
+ // console.log(args);
45
+ const debug = options?.debug ?? false;
46
+ if (debug) {
47
+ console.log(options);
48
+ }
49
+
50
+ let allowCaching = true;
51
+ if (args.includes("--no-caching")) {
52
+ allowCaching = false;
53
+ }
54
+ else console.log("Use --no-caching to disable caching");
55
+
56
+ const noToktx = args.includes("no-toktx");
57
+ if (noToktx)
58
+ console.log("Using toktx is disabled");
59
+
60
+ const packedFiles = new Set();
61
+
62
+ /**
63
+ * @type {import("../dist/index.js").ProcessStats}
64
+ */
65
+ const stats = {
66
+ startTime: Date.now(),
67
+ totalGPUMemoryInMB: 0,
68
+ totalFilesProcessed: 0,
69
+ totalFileSizeInMB: 0,
70
+ totalFileSizeInMBBefore: 0,
71
+ };
72
+
73
+ const config = getConfig();
74
+
75
+
76
+ /** Compress a glTF file
77
+ * @param {string} file
78
+ */
79
+ async function packFile(file) {
80
+ return packGLTF(file, file, {
81
+ config,
82
+ debug,
83
+ packedFiles,
84
+ useCache: allowCaching,
85
+ stats,
86
+ })
87
+ }
88
+
89
+ const inputArgs = args.slice(2);
90
+ let failed = false;
91
+ const logger = new Logger(Verbosity.INFO);
92
+
93
+ foreachGLTF(inputArgs, async (file) => {
94
+ const res = await packFile(file);
95
+ if (!res) failed = true;
96
+ }).then(async () => {
97
+ if (allowCaching) {
98
+ limitCacheSize();
99
+ }
100
+ printStats(stats, logger, config);
101
+ if (failed) {
102
+ process.exit(1);
103
+ }
104
+ }).catch(err => {
105
+ console.error("ERR: packing failed: " + err.message);
106
+ if (debug) throw err;
107
107
  });
package/tsconfig.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "rootDir": "src",
5
- "outDir": "dist",
6
- "declaration": true,
7
- "moduleResolution": "NodeNext",
8
- "module": "NodeNext",
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "resolveJsonModule": true,
12
- "lib": [
13
- "ESNext",
14
- "DOM"
15
- ],
16
- },
17
- "include": [
18
- "src/index.ts",
19
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "declaration": true,
7
+ "moduleResolution": "NodeNext",
8
+ "module": "NodeNext",
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "resolveJsonModule": true,
12
+ "lib": [
13
+ "ESNext",
14
+ "DOM"
15
+ ],
16
+ },
17
+ "include": [
18
+ "src/index.ts",
19
+ ]
20
20
  }