@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.
Files changed (104) hide show
  1. package/.temp/Go2.bin +0 -0
  2. package/.temp/textures/0_1.exr +0 -0
  3. package/.temp/textures/1_1.jpg +0 -0
  4. package/CHANGELOG.md +395 -394
  5. package/README.md +35 -35
  6. package/dist/cache/cache.d.ts +54 -54
  7. package/dist/cache/cache.js +257 -257
  8. package/dist/cache/index.d.ts +1 -1
  9. package/dist/cache/index.js +1 -1
  10. package/dist/cli/index.d.ts +2 -2
  11. package/dist/cli/index.js +154 -154
  12. package/dist/config/index.d.ts +53 -53
  13. package/dist/config/index.js +152 -152
  14. package/dist/constants.d.ts +5 -5
  15. package/dist/constants.js +5 -5
  16. package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +24 -24
  17. package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +54 -54
  18. package/dist/extensions/NEEDLE_compression_texture/index.d.ts +1 -1
  19. package/dist/extensions/NEEDLE_compression_texture/index.js +1 -1
  20. package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +26 -26
  21. package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +85 -85
  22. package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +1 -1
  23. package/dist/extensions/NEEDLE_mesh_compression/index.js +1 -1
  24. package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +27 -27
  25. package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +897 -897
  26. package/dist/extensions/NEEDLE_opaque/index.d.ts +3 -3
  27. package/dist/extensions/NEEDLE_opaque/index.js +28 -28
  28. package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +48 -48
  29. package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +69 -69
  30. package/dist/extensions/NEEDLE_progressive/index.d.ts +1 -1
  31. package/dist/extensions/NEEDLE_progressive/index.js +1 -1
  32. package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +23 -23
  33. package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +41 -41
  34. package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +25 -25
  35. package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +67 -67
  36. package/dist/extensions/index.d.ts +7 -7
  37. package/dist/extensions/index.js +17 -17
  38. package/dist/extensions/utils.d.ts +6 -6
  39. package/dist/extensions/utils.js +72 -72
  40. package/dist/functions/weld.3.d.ts +76 -76
  41. package/dist/functions/weld.3.js +414 -414
  42. package/dist/index.d.ts +8 -8
  43. package/dist/index.js +8 -8
  44. package/dist/scripts/index.d.ts +2 -2
  45. package/dist/scripts/index.js +2 -2
  46. package/dist/scripts/pack-gltf.d.ts +16 -16
  47. package/dist/scripts/pack-gltf.js +120 -120
  48. package/dist/scripts/stats.d.ts +2 -2
  49. package/dist/scripts/stats.js +18 -18
  50. package/dist/transforms/index.d.ts +9 -9
  51. package/dist/transforms/index.js +9 -9
  52. package/dist/transforms/needle_animation_transform.d.ts +2 -2
  53. package/dist/transforms/needle_animation_transform.js +5 -5
  54. package/dist/transforms/needle_asset.d.ts +3 -3
  55. package/dist/transforms/needle_asset.js +35 -35
  56. package/dist/transforms/needle_common.d.ts +16 -16
  57. package/dist/transforms/needle_common.js +1 -1
  58. package/dist/transforms/needle_mesh_transform.d.ts +10 -10
  59. package/dist/transforms/needle_mesh_transform.js +140 -140
  60. package/dist/transforms/needle_progressive.d.ts +42 -42
  61. package/dist/transforms/needle_progressive.js +921 -921
  62. package/dist/transforms/needle_texture_transform.d.ts +13 -13
  63. package/dist/transforms/needle_texture_transform.js +202 -196
  64. package/dist/transforms/needle_toktx.d.ts +25 -25
  65. package/dist/transforms/needle_toktx.js +230 -230
  66. package/dist/transforms/needle_webp.d.ts +13 -13
  67. package/dist/transforms/needle_webp.js +37 -37
  68. package/dist/transforms/toktx.d.ts +52 -52
  69. package/dist/transforms/toktx.js +221 -221
  70. package/dist/transforms/toktx_types.d.ts +78 -78
  71. package/dist/transforms/toktx_types.js +62 -62
  72. package/dist/transforms/util.d.ts +21 -21
  73. package/dist/transforms/util.js +90 -90
  74. package/dist/utils/compression_utils.d.ts +2 -2
  75. package/dist/utils/compression_utils.js +6 -6
  76. package/dist/utils/fileutils.d.ts +6 -6
  77. package/dist/utils/fileutils.js +141 -141
  78. package/dist/utils/guid.d.ts +1 -1
  79. package/dist/utils/guid.js +5 -5
  80. package/dist/utils/index.d.ts +10 -9
  81. package/dist/utils/index.js +10 -9
  82. package/dist/utils/merge.d.ts +12 -12
  83. package/dist/utils/merge.js +31 -31
  84. package/dist/utils/mesh.d.ts +13 -13
  85. package/dist/utils/mesh.js +107 -107
  86. package/dist/utils/nodeio.d.ts +5 -5
  87. package/dist/utils/nodeio.js +14 -14
  88. package/dist/utils/stats.d.ts +54 -53
  89. package/dist/utils/stats.js +191 -166
  90. package/dist/utils/texture.d.ts +2 -2
  91. package/dist/utils/texture.js +8 -8
  92. package/dist/utils/validate.d.ts +5 -0
  93. package/dist/utils/validate.js +16 -0
  94. package/dist/utils/version.d.ts +1 -1
  95. package/dist/utils/version.js +5 -5
  96. package/package.json +77 -76
  97. package/scripts/clear-caches.mjs +3 -3
  98. package/scripts/defaults.mjs +11 -11
  99. package/scripts/fileutils.mjs +5 -5
  100. package/scripts/index.mjs +41 -41
  101. package/scripts/limit-caches.mjs +3 -3
  102. package/scripts/make-progressive.mjs +16 -16
  103. package/scripts/pack-gltf.mjs +107 -107
  104. package/tsconfig.json +19 -19
@@ -1,52 +1,52 @@
1
- import { Document, ILogger, vec2, Texture } from '@gltf-transform/core';
2
- import { ETC1SOptions, UASTCOptions } from './toktx_types.js';
3
- export declare const KTX_SOFTWARE_VERSION_MIN = "4.3.0";
4
- export declare const Filter: {
5
- BOX: string;
6
- TENT: string;
7
- BELL: string;
8
- BSPLINE: string;
9
- MITCHELL: string;
10
- LANCZOS3: string;
11
- LANCZOS4: string;
12
- LANCZOS6: string;
13
- LANCZOS12: string;
14
- BLACKMAN: string;
15
- KAISER: string;
16
- GAUSSIAN: string;
17
- CATMULLROM: string;
18
- QUADRATIC_INTERP: string;
19
- QUADRATIC_APPROX: string;
20
- QUADRATIC_MIX: string;
21
- };
22
- /**********************************************************************************************
23
- * Interfaces.
24
- */
25
- export declare const Mode: {
26
- ETC1S: string;
27
- UASTC: string;
28
- };
29
- export type TextureModeArgs = {
30
- doc: Document;
31
- texture: Texture;
32
- index: number;
33
- options: ETC1SOptions | UASTCOptions;
34
- };
35
- export type TextureParamsArgs = {
36
- doc: Document;
37
- texture: Texture;
38
- index: number;
39
- params: Array<string | number>;
40
- };
41
- export interface ToktxOptions {
42
- toktxPath?: string;
43
- /** return false if texture should not be compressed */
44
- modifyOptions?: (args: TextureModeArgs) => void | boolean;
45
- modifyParams?: (args: TextureParamsArgs) => void;
46
- }
47
- /**********************************************************************************************
48
- * Utilities.
49
- */
50
- /** Create CLI parameters from the given options. Attempts to write only non-default options. */
51
- export declare function createParams(texture: Texture, slots: string[], channels: number, size: vec2, logger: ILogger, numTextures: number, options: ETC1SOptions | UASTCOptions): (string | number)[];
52
- export declare function checkKTXSoftware(logger: ILogger, env?: any): Promise<string | null>;
1
+ import { Document, ILogger, vec2, Texture } from '@gltf-transform/core';
2
+ import { ETC1SOptions, UASTCOptions } from './toktx_types.js';
3
+ export declare const KTX_SOFTWARE_VERSION_MIN = "4.3.0";
4
+ export declare const Filter: {
5
+ BOX: string;
6
+ TENT: string;
7
+ BELL: string;
8
+ BSPLINE: string;
9
+ MITCHELL: string;
10
+ LANCZOS3: string;
11
+ LANCZOS4: string;
12
+ LANCZOS6: string;
13
+ LANCZOS12: string;
14
+ BLACKMAN: string;
15
+ KAISER: string;
16
+ GAUSSIAN: string;
17
+ CATMULLROM: string;
18
+ QUADRATIC_INTERP: string;
19
+ QUADRATIC_APPROX: string;
20
+ QUADRATIC_MIX: string;
21
+ };
22
+ /**********************************************************************************************
23
+ * Interfaces.
24
+ */
25
+ export declare const Mode: {
26
+ ETC1S: string;
27
+ UASTC: string;
28
+ };
29
+ export type TextureModeArgs = {
30
+ doc: Document;
31
+ texture: Texture;
32
+ index: number;
33
+ options: ETC1SOptions | UASTCOptions;
34
+ };
35
+ export type TextureParamsArgs = {
36
+ doc: Document;
37
+ texture: Texture;
38
+ index: number;
39
+ params: Array<string | number>;
40
+ };
41
+ export interface ToktxOptions {
42
+ toktxPath?: string;
43
+ /** return false if texture should not be compressed */
44
+ modifyOptions?: (args: TextureModeArgs) => void | boolean;
45
+ modifyParams?: (args: TextureParamsArgs) => void;
46
+ }
47
+ /**********************************************************************************************
48
+ * Utilities.
49
+ */
50
+ /** Create CLI parameters from the given options. Attempts to write only non-default options. */
51
+ export declare function createParams(texture: Texture, slots: string[], channels: number, size: vec2, logger: ILogger, numTextures: number, options: ETC1SOptions | UASTCOptions): (string | number)[];
52
+ export declare function checkKTXSoftware(logger: ILogger, env?: any): Promise<string | null>;
@@ -1,221 +1,221 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- import micromatch from 'micromatch';
3
- import os from 'os';
4
- import semver from 'semver';
5
- import tmp from 'tmp';
6
- import { TextureChannel } from '@gltf-transform/core';
7
- import { execSync } from 'child_process';
8
- import { spawn, commandExists, waitExit, MICROMATCH_OPTIONS } from './util.js';
9
- import { TextureResizeFilter, getTextureColorSpace } from '@gltf-transform/functions';
10
- import { ETC1S_DEFAULTS, UASTC_DEFAULTS } from './toktx_types.js';
11
- tmp.setGracefulCleanup();
12
- const NUM_CPUS = os.cpus().length || 1; // microsoft/vscode#112122
13
- export const KTX_SOFTWARE_VERSION_MIN = '4.3.0';
14
- export const Filter = {
15
- BOX: 'box',
16
- TENT: 'tent',
17
- BELL: 'bell',
18
- BSPLINE: 'b-spline',
19
- MITCHELL: 'mitchell',
20
- LANCZOS3: 'lanczos3',
21
- LANCZOS4: 'lanczos4',
22
- LANCZOS6: 'lanczos6',
23
- LANCZOS12: 'lanczos12',
24
- BLACKMAN: 'blackman',
25
- KAISER: 'kaiser',
26
- GAUSSIAN: 'gaussian',
27
- CATMULLROM: 'catmullrom',
28
- QUADRATIC_INTERP: 'quadratic_interp',
29
- QUADRATIC_APPROX: 'quadratic_approx',
30
- QUADRATIC_MIX: 'quadratic_mix',
31
- };
32
- const GLOBAL_DEFAULTS = {
33
- resizeFilter: TextureResizeFilter.LANCZOS3,
34
- filter: Filter.LANCZOS4,
35
- filterScale: 1,
36
- pattern: null,
37
- slots: null,
38
- // See: https://github.com/donmccurdy/glTF-Transform/pull/389#issuecomment-1089842185
39
- jobs: 2 * NUM_CPUS,
40
- cleanup: true,
41
- limitInputPixels: true,
42
- };
43
- const { R, G, A } = TextureChannel;
44
- /**********************************************************************************************
45
- * Interfaces.
46
- */
47
- export const Mode = {
48
- ETC1S: 'etc1s',
49
- UASTC: 'uastc',
50
- };
51
- /**********************************************************************************************
52
- * Utilities.
53
- */
54
- /** Create CLI parameters from the given options. Attempts to write only non-default options. */
55
- export function createParams(texture, slots, channels, size, logger, numTextures, options) {
56
- const colorSpace = getTextureColorSpace(texture);
57
- const params = ['--generate-mipmap'];
58
- if (options.filter !== GLOBAL_DEFAULTS.filter) {
59
- params.push('--mipmap-filter', options.filter);
60
- }
61
- if (options.filterScale !== GLOBAL_DEFAULTS.filterScale) {
62
- params.push('--mipmap-filter-scale', options.filterScale);
63
- }
64
- // See: https://github.com/KhronosGroup/KTX-Software/issues/600
65
- const isNormalMap = slots.find((slot) => micromatch.isMatch(slot, '*normal*', MICROMATCH_OPTIONS));
66
- if (options.mode === Mode.UASTC) {
67
- const _options = options;
68
- params.push('--encode', 'uastc');
69
- params.push('--uastc-quality', _options.level);
70
- if (_options.rdo && !isNormalMap) {
71
- params.push('--uastc-rdo');
72
- if (_options.rdoLambda !== UASTC_DEFAULTS.rdoLambda) {
73
- params.push('--uastc-rdo-l', _options.rdoLambda);
74
- }
75
- if (_options.rdoDictionarySize !== UASTC_DEFAULTS.rdoDictionarySize) {
76
- params.push('--uastc-rdo-d', _options.rdoDictionarySize);
77
- }
78
- if (_options.rdoBlockScale !== UASTC_DEFAULTS.rdoBlockScale) {
79
- params.push('--uastc-rdo-b', _options.rdoBlockScale);
80
- }
81
- if (_options.rdoStdDev !== UASTC_DEFAULTS.rdoStdDev) {
82
- params.push('--uastc-rdo-s', _options.rdoStdDev);
83
- }
84
- if (!_options.rdoMultithreading) {
85
- params.push('--uastc-rdo-m');
86
- }
87
- }
88
- if (_options.zstd && _options.zstd > 0) {
89
- params.push('--zstd', _options.zstd);
90
- }
91
- }
92
- else {
93
- const _options = options;
94
- params.push('--encode', 'basis-lz');
95
- if (_options.quality !== ETC1S_DEFAULTS.quality) {
96
- params.push('--qlevel', _options.quality);
97
- }
98
- if (_options.compression !== ETC1S_DEFAULTS.compression) {
99
- params.push('--clevel', _options.compression);
100
- }
101
- if (_options.rdo && !isNormalMap) {
102
- if (_options.maxEndpoints !== ETC1S_DEFAULTS.maxEndpoints) {
103
- params.push('--max-endpoints', _options.maxEndpoints);
104
- }
105
- if (_options.maxSelectors !== ETC1S_DEFAULTS.maxSelectors) {
106
- params.push('--max-selectors', _options.maxSelectors);
107
- }
108
- if (_options.rdoThreshold !== ETC1S_DEFAULTS.rdoThreshold) {
109
- params.push('--endpoint-rdo-threshold', _options.rdoThreshold);
110
- params.push('--selector-rdo-threshold', _options.rdoThreshold);
111
- }
112
- }
113
- else {
114
- params.push('--no-endpoint-rdo', '--no-selector-rdo');
115
- }
116
- }
117
- // See: https://github.com/donmccurdy/glTF-Transform/issues/215
118
- if (colorSpace === 'srgb') {
119
- params.push('--assign-oetf', 'srgb', '--assign-primaries', 'bt709');
120
- }
121
- else if (colorSpace === 'srgb-linear') {
122
- params.push('--assign-oetf', 'linear', '--assign-primaries', 'bt709');
123
- }
124
- else if (slots.length && !colorSpace) {
125
- params.push('--assign-oetf', 'linear', '--assign-primaries', 'none');
126
- }
127
- if (channels === R) {
128
- params.push('--format', 'R8_UNORM');
129
- }
130
- else if (channels === G || channels === (R | G)) {
131
- params.push('--format', 'R8G8_UNORM');
132
- }
133
- else if (!(channels & A)) {
134
- params.push('--format', colorSpace === 'srgb' ? 'R8G8B8_SRGB' : 'R8G8B8_UNORM');
135
- }
136
- else {
137
- params.push('--format', colorSpace === 'srgb' ? 'R8G8B8A8_SRGB' : 'R8G8B8A8_UNORM');
138
- }
139
- if (options.jobs && options.jobs > 1 && numTextures > 1) {
140
- // See: https://github.com/donmccurdy/glTF-Transform/pull/389#issuecomment-1089842185
141
- const threads = Math.max(2, Math.min(NUM_CPUS, Math.round((3 * NUM_CPUS) / numTextures)));
142
- params.push('--threads', threads);
143
- }
144
- return params;
145
- }
146
- let didLogToktxVersion = false;
147
- export async function checkKTXSoftware(logger, env) {
148
- let failedFindingToktx = false;
149
- const proc = spawn('toktx', ['--version'], { env: env });
150
- proc.on('error', (err) => {
151
- if (err.message.endsWith("ENOENT")) {
152
- failedFindingToktx = true;
153
- }
154
- });
155
- const [status, stdout, stderr] = await waitExit(proc);
156
- if (failedFindingToktx) {
157
- console.log(`WARN: Unable to find "toktx". Confirm KTX-Software is installed from: https://github.com/KhronosGroup/KTX-Software.`);
158
- return null;
159
- }
160
- const version = (stdout || stderr)
161
- .replace(/toktx\s+/, '')
162
- .replace(/~\d+/, '')
163
- .trim();
164
- if (status !== 0 || !semver.valid(semver.clean(version))) {
165
- throw new Error('Unable to find "toktx" version. Confirm KTX-Software is installed from:\n\nhttps://github.com/KhronosGroup/KTX-Software.');
166
- }
167
- else if (semver.lt(semver.clean(version), KTX_SOFTWARE_VERSION_MIN)) {
168
- logger.warn(`toktx: Expected KTX-Software >= v${KTX_SOFTWARE_VERSION_MIN}, found ${version}.`);
169
- return null;
170
- }
171
- else {
172
- if (!didLogToktxVersion)
173
- logger.debug(`toktx: Found KTX-Software ${version}.`);
174
- didLogToktxVersion = true;
175
- }
176
- return semver.clean(version);
177
- }
178
- async function toktxCommandExistsSync(env) {
179
- if (env) {
180
- // if env is defined use that to check if toktx is installed
181
- try {
182
- execSync('toktx --version', { encoding: 'utf-8', env: env });
183
- return true;
184
- }
185
- catch (error) {
186
- return false;
187
- }
188
- }
189
- else if (!await commandExists('toktx')) {
190
- return false;
191
- }
192
- return true;
193
- }
194
- function isPowerOfTwo(value) {
195
- if (value <= 2)
196
- return true;
197
- return (value & (value - 1)) === 0 && value !== 0;
198
- }
199
- function preferredPowerOfTwo(value) {
200
- if (value <= 4)
201
- return 4;
202
- const lo = floorPowerOfTwo(value);
203
- const hi = ceilPowerOfTwo(value);
204
- if (hi - value > value - lo)
205
- return lo;
206
- return hi;
207
- }
208
- function floorPowerOfTwo(value) {
209
- return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
210
- }
211
- function ceilPowerOfTwo(value) {
212
- return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
213
- }
214
- function isMultipleOfFour(value) {
215
- return value % 4 === 0;
216
- }
217
- function ceilMultipleOfFour(value) {
218
- if (value <= 4)
219
- return 4;
220
- return value % 4 ? value + 4 - (value % 4) : value;
221
- }
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ import micromatch from 'micromatch';
3
+ import os from 'os';
4
+ import semver from 'semver';
5
+ import tmp from 'tmp';
6
+ import { TextureChannel } from '@gltf-transform/core';
7
+ import { execSync } from 'child_process';
8
+ import { spawn, commandExists, waitExit, MICROMATCH_OPTIONS } from './util.js';
9
+ import { TextureResizeFilter, getTextureColorSpace } from '@gltf-transform/functions';
10
+ import { ETC1S_DEFAULTS, UASTC_DEFAULTS } from './toktx_types.js';
11
+ tmp.setGracefulCleanup();
12
+ const NUM_CPUS = os.cpus().length || 1; // microsoft/vscode#112122
13
+ export const KTX_SOFTWARE_VERSION_MIN = '4.3.0';
14
+ export const Filter = {
15
+ BOX: 'box',
16
+ TENT: 'tent',
17
+ BELL: 'bell',
18
+ BSPLINE: 'b-spline',
19
+ MITCHELL: 'mitchell',
20
+ LANCZOS3: 'lanczos3',
21
+ LANCZOS4: 'lanczos4',
22
+ LANCZOS6: 'lanczos6',
23
+ LANCZOS12: 'lanczos12',
24
+ BLACKMAN: 'blackman',
25
+ KAISER: 'kaiser',
26
+ GAUSSIAN: 'gaussian',
27
+ CATMULLROM: 'catmullrom',
28
+ QUADRATIC_INTERP: 'quadratic_interp',
29
+ QUADRATIC_APPROX: 'quadratic_approx',
30
+ QUADRATIC_MIX: 'quadratic_mix',
31
+ };
32
+ const GLOBAL_DEFAULTS = {
33
+ resizeFilter: TextureResizeFilter.LANCZOS3,
34
+ filter: Filter.LANCZOS4,
35
+ filterScale: 1,
36
+ pattern: null,
37
+ slots: null,
38
+ // See: https://github.com/donmccurdy/glTF-Transform/pull/389#issuecomment-1089842185
39
+ jobs: 2 * NUM_CPUS,
40
+ cleanup: true,
41
+ limitInputPixels: true,
42
+ };
43
+ const { R, G, A } = TextureChannel;
44
+ /**********************************************************************************************
45
+ * Interfaces.
46
+ */
47
+ export const Mode = {
48
+ ETC1S: 'etc1s',
49
+ UASTC: 'uastc',
50
+ };
51
+ /**********************************************************************************************
52
+ * Utilities.
53
+ */
54
+ /** Create CLI parameters from the given options. Attempts to write only non-default options. */
55
+ export function createParams(texture, slots, channels, size, logger, numTextures, options) {
56
+ const colorSpace = getTextureColorSpace(texture);
57
+ const params = ['--generate-mipmap'];
58
+ if (options.filter !== GLOBAL_DEFAULTS.filter) {
59
+ params.push('--mipmap-filter', options.filter);
60
+ }
61
+ if (options.filterScale !== GLOBAL_DEFAULTS.filterScale) {
62
+ params.push('--mipmap-filter-scale', options.filterScale);
63
+ }
64
+ // See: https://github.com/KhronosGroup/KTX-Software/issues/600
65
+ const isNormalMap = slots.find((slot) => micromatch.isMatch(slot, '*normal*', MICROMATCH_OPTIONS));
66
+ if (options.mode === Mode.UASTC) {
67
+ const _options = options;
68
+ params.push('--encode', 'uastc');
69
+ params.push('--uastc-quality', _options.level);
70
+ if (_options.rdo && !isNormalMap) {
71
+ params.push('--uastc-rdo');
72
+ if (_options.rdoLambda !== UASTC_DEFAULTS.rdoLambda) {
73
+ params.push('--uastc-rdo-l', _options.rdoLambda);
74
+ }
75
+ if (_options.rdoDictionarySize !== UASTC_DEFAULTS.rdoDictionarySize) {
76
+ params.push('--uastc-rdo-d', _options.rdoDictionarySize);
77
+ }
78
+ if (_options.rdoBlockScale !== UASTC_DEFAULTS.rdoBlockScale) {
79
+ params.push('--uastc-rdo-b', _options.rdoBlockScale);
80
+ }
81
+ if (_options.rdoStdDev !== UASTC_DEFAULTS.rdoStdDev) {
82
+ params.push('--uastc-rdo-s', _options.rdoStdDev);
83
+ }
84
+ if (!_options.rdoMultithreading) {
85
+ params.push('--uastc-rdo-m');
86
+ }
87
+ }
88
+ if (_options.zstd && _options.zstd > 0) {
89
+ params.push('--zstd', _options.zstd);
90
+ }
91
+ }
92
+ else {
93
+ const _options = options;
94
+ params.push('--encode', 'basis-lz');
95
+ if (_options.quality !== ETC1S_DEFAULTS.quality) {
96
+ params.push('--qlevel', _options.quality);
97
+ }
98
+ if (_options.compression !== ETC1S_DEFAULTS.compression) {
99
+ params.push('--clevel', _options.compression);
100
+ }
101
+ if (_options.rdo && !isNormalMap) {
102
+ if (_options.maxEndpoints !== ETC1S_DEFAULTS.maxEndpoints) {
103
+ params.push('--max-endpoints', _options.maxEndpoints);
104
+ }
105
+ if (_options.maxSelectors !== ETC1S_DEFAULTS.maxSelectors) {
106
+ params.push('--max-selectors', _options.maxSelectors);
107
+ }
108
+ if (_options.rdoThreshold !== ETC1S_DEFAULTS.rdoThreshold) {
109
+ params.push('--endpoint-rdo-threshold', _options.rdoThreshold);
110
+ params.push('--selector-rdo-threshold', _options.rdoThreshold);
111
+ }
112
+ }
113
+ else {
114
+ params.push('--no-endpoint-rdo', '--no-selector-rdo');
115
+ }
116
+ }
117
+ // See: https://github.com/donmccurdy/glTF-Transform/issues/215
118
+ if (colorSpace === 'srgb') {
119
+ params.push('--assign-oetf', 'srgb', '--assign-primaries', 'bt709');
120
+ }
121
+ else if (colorSpace === 'srgb-linear') {
122
+ params.push('--assign-oetf', 'linear', '--assign-primaries', 'bt709');
123
+ }
124
+ else if (slots.length && !colorSpace) {
125
+ params.push('--assign-oetf', 'linear', '--assign-primaries', 'none');
126
+ }
127
+ if (channels === R) {
128
+ params.push('--format', 'R8_UNORM');
129
+ }
130
+ else if (channels === G || channels === (R | G)) {
131
+ params.push('--format', 'R8G8_UNORM');
132
+ }
133
+ else if (!(channels & A)) {
134
+ params.push('--format', colorSpace === 'srgb' ? 'R8G8B8_SRGB' : 'R8G8B8_UNORM');
135
+ }
136
+ else {
137
+ params.push('--format', colorSpace === 'srgb' ? 'R8G8B8A8_SRGB' : 'R8G8B8A8_UNORM');
138
+ }
139
+ if (options.jobs && options.jobs > 1 && numTextures > 1) {
140
+ // See: https://github.com/donmccurdy/glTF-Transform/pull/389#issuecomment-1089842185
141
+ const threads = Math.max(2, Math.min(NUM_CPUS, Math.round((3 * NUM_CPUS) / numTextures)));
142
+ params.push('--threads', threads);
143
+ }
144
+ return params;
145
+ }
146
+ let didLogToktxVersion = false;
147
+ export async function checkKTXSoftware(logger, env) {
148
+ let failedFindingToktx = false;
149
+ const proc = spawn('toktx', ['--version'], { env: env });
150
+ proc.on('error', (err) => {
151
+ if (err.message.endsWith("ENOENT")) {
152
+ failedFindingToktx = true;
153
+ }
154
+ });
155
+ const [status, stdout, stderr] = await waitExit(proc);
156
+ if (failedFindingToktx) {
157
+ console.log(`WARN: Unable to find "toktx". Confirm KTX-Software is installed from: https://github.com/KhronosGroup/KTX-Software.`);
158
+ return null;
159
+ }
160
+ const version = (stdout || stderr)
161
+ .replace(/toktx\s+/, '')
162
+ .replace(/~\d+/, '')
163
+ .trim();
164
+ if (status !== 0 || !semver.valid(semver.clean(version))) {
165
+ throw new Error('Unable to find "toktx" version. Confirm KTX-Software is installed from:\n\nhttps://github.com/KhronosGroup/KTX-Software.');
166
+ }
167
+ else if (semver.lt(semver.clean(version), KTX_SOFTWARE_VERSION_MIN)) {
168
+ logger.warn(`toktx: Expected KTX-Software >= v${KTX_SOFTWARE_VERSION_MIN}, found ${version}.`);
169
+ return null;
170
+ }
171
+ else {
172
+ if (!didLogToktxVersion)
173
+ logger.debug(`toktx: Found KTX-Software ${version}.`);
174
+ didLogToktxVersion = true;
175
+ }
176
+ return semver.clean(version);
177
+ }
178
+ async function toktxCommandExistsSync(env) {
179
+ if (env) {
180
+ // if env is defined use that to check if toktx is installed
181
+ try {
182
+ execSync('toktx --version', { encoding: 'utf-8', env: env });
183
+ return true;
184
+ }
185
+ catch (error) {
186
+ return false;
187
+ }
188
+ }
189
+ else if (!await commandExists('toktx')) {
190
+ return false;
191
+ }
192
+ return true;
193
+ }
194
+ function isPowerOfTwo(value) {
195
+ if (value <= 2)
196
+ return true;
197
+ return (value & (value - 1)) === 0 && value !== 0;
198
+ }
199
+ function preferredPowerOfTwo(value) {
200
+ if (value <= 4)
201
+ return 4;
202
+ const lo = floorPowerOfTwo(value);
203
+ const hi = ceilPowerOfTwo(value);
204
+ if (hi - value > value - lo)
205
+ return lo;
206
+ return hi;
207
+ }
208
+ function floorPowerOfTwo(value) {
209
+ return Math.pow(2, Math.floor(Math.log(value) / Math.LN2));
210
+ }
211
+ function ceilPowerOfTwo(value) {
212
+ return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
213
+ }
214
+ function isMultipleOfFour(value) {
215
+ return value % 4 === 0;
216
+ }
217
+ function ceilMultipleOfFour(value) {
218
+ if (value <= 4)
219
+ return 4;
220
+ return value % 4 ? value + 4 - (value % 4) : value;
221
+ }