@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/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./config/index.js";
|
|
2
|
-
export * from "./cli/index.js";
|
|
3
|
-
export * from "./utils/index.js";
|
|
4
|
-
export * from "./transforms/index.js";
|
|
5
|
-
export * from "./extensions/index.js";
|
|
6
|
-
export * from "./cache/index.js";
|
|
7
|
-
export * from "./scripts/index.js";
|
|
8
|
-
export * from "./constants.js";
|
|
1
|
+
export * from "./config/index.js";
|
|
2
|
+
export * from "./cli/index.js";
|
|
3
|
+
export * from "./utils/index.js";
|
|
4
|
+
export * from "./transforms/index.js";
|
|
5
|
+
export * from "./extensions/index.js";
|
|
6
|
+
export * from "./cache/index.js";
|
|
7
|
+
export * from "./scripts/index.js";
|
|
8
|
+
export * from "./constants.js";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./config/index.js";
|
|
2
|
-
export * from "./cli/index.js";
|
|
3
|
-
export * from "./utils/index.js";
|
|
4
|
-
export * from "./transforms/index.js";
|
|
5
|
-
export * from "./extensions/index.js";
|
|
6
|
-
export * from "./cache/index.js";
|
|
7
|
-
export * from "./scripts/index.js";
|
|
8
|
-
export * from "./constants.js";
|
|
1
|
+
export * from "./config/index.js";
|
|
2
|
+
export * from "./cli/index.js";
|
|
3
|
+
export * from "./utils/index.js";
|
|
4
|
+
export * from "./transforms/index.js";
|
|
5
|
+
export * from "./extensions/index.js";
|
|
6
|
+
export * from "./cache/index.js";
|
|
7
|
+
export * from "./scripts/index.js";
|
|
8
|
+
export * from "./constants.js";
|
package/dist/scripts/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./pack-gltf.js";
|
|
2
|
-
export * from "./stats.js";
|
|
1
|
+
export * from "./pack-gltf.js";
|
|
2
|
+
export * from "./stats.js";
|
package/dist/scripts/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./pack-gltf.js";
|
|
2
|
-
export * from "./stats.js";
|
|
1
|
+
export * from "./pack-gltf.js";
|
|
2
|
+
export * from "./stats.js";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { ILogger } from '@gltf-transform/core';
|
|
2
|
-
import { FileStats, ProcessStats } from "../utils/index.js";
|
|
3
|
-
import { Config } from '../config/index.js';
|
|
4
|
-
export type PackGLTFOptions = {
|
|
5
|
-
useCache: boolean;
|
|
6
|
-
packedFiles?: Set<string>;
|
|
7
|
-
stats?: ProcessStats;
|
|
8
|
-
file_stats: FileStats[] | null;
|
|
9
|
-
config: Config;
|
|
10
|
-
logger?: ILogger;
|
|
11
|
-
debug: boolean;
|
|
12
|
-
verbose?: boolean;
|
|
13
|
-
};
|
|
14
|
-
/** Compress a glTF file
|
|
15
|
-
*/
|
|
16
|
-
export declare function packGLTF(inputFile: string, outputFile: string, options: PackGLTFOptions): Promise<boolean>;
|
|
1
|
+
import { ILogger } from '@gltf-transform/core';
|
|
2
|
+
import { FileStats, ProcessStats } from "../utils/index.js";
|
|
3
|
+
import { Config } from '../config/index.js';
|
|
4
|
+
export type PackGLTFOptions = {
|
|
5
|
+
useCache: boolean;
|
|
6
|
+
packedFiles?: Set<string>;
|
|
7
|
+
stats?: ProcessStats;
|
|
8
|
+
file_stats: FileStats[] | null;
|
|
9
|
+
config: Config;
|
|
10
|
+
logger?: ILogger;
|
|
11
|
+
debug: boolean;
|
|
12
|
+
verbose?: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Compress a glTF file
|
|
15
|
+
*/
|
|
16
|
+
export declare function packGLTF(inputFile: string, outputFile: string, options: PackGLTFOptions): Promise<boolean>;
|
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { Logger, NodeIO, PropertyType, Verbosity } from '@gltf-transform/core';
|
|
3
|
-
import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
|
|
4
|
-
import draco3d from 'draco3dgltf';
|
|
5
|
-
import { existsSync, readFileSync, statSync, writeFileSync } from 'fs';
|
|
6
|
-
import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
|
|
7
|
-
import { dedup, prune, resample } from '@gltf-transform/functions';
|
|
8
|
-
import { ALL_EXTENSIONS as NEEDLE_EXTENSIONS, NEEDLE_compression_texture, NEEDLE_mesh_compression, } from '../extensions/index.js';
|
|
9
|
-
import { isLOD, isMeshLOD, needle_animation_transform, needle_asset, needle_mesh_transform, needle_texture_transform, } from '../transforms/index.js';
|
|
10
|
-
import { createNewFilestats, writeNodeIO } from "../utils/index.js";
|
|
11
|
-
import { addToCache, getHash, tryGetFromCache, } from "../cache/index.js";
|
|
12
|
-
/** Compress a glTF file
|
|
13
|
-
*/
|
|
14
|
-
export async function packGLTF(inputFile, outputFile, options) {
|
|
15
|
-
if (!options.logger) {
|
|
16
|
-
options.logger = new Logger(Verbosity.INFO);
|
|
17
|
-
}
|
|
18
|
-
const { debug, stats, packedFiles, useCache, logger } = options;
|
|
19
|
-
if (!existsSync(inputFile)) {
|
|
20
|
-
logger.error("WARN: can not pack, file does not exist: " + inputFile);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
// check if it's in the cache.
|
|
24
|
-
// We only need to check mesh LOD files because image LODs are cache via our toktx transform
|
|
25
|
-
// We can not cache the main glTF files because the hash always changes for them
|
|
26
|
-
let cacheKey = undefined;
|
|
27
|
-
if (useCache && isMeshLOD(inputFile)) {
|
|
28
|
-
const existing = readFileSync(inputFile);
|
|
29
|
-
const hash = getHash(existing);
|
|
30
|
-
cacheKey = "packed-" + hash;
|
|
31
|
-
const cached = tryGetFromCache(cacheKey);
|
|
32
|
-
if (cached) {
|
|
33
|
-
logger.info(`→ Loaded compressed file from cache: \"${path.basename(inputFile)}\"`);
|
|
34
|
-
writeFileSync(inputFile, cached);
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (packedFiles) {
|
|
39
|
-
if (packedFiles.has(inputFile))
|
|
40
|
-
return true;
|
|
41
|
-
packedFiles.add(inputFile);
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const config = options.config;
|
|
45
|
-
const prevSizeInMB = statSync(inputFile).size / 1024 / 1024;
|
|
46
|
-
logger.info(`→ Compressing ${prevSizeInMB.toFixed(1)} MB: ${inputFile}`);
|
|
47
|
-
const startTime = Date.now();
|
|
48
|
-
const io = new NodeIO()
|
|
49
|
-
.registerExtensions(ALL_EXTENSIONS)
|
|
50
|
-
.registerExtensions(NEEDLE_EXTENSIONS)
|
|
51
|
-
.registerExtensions([
|
|
52
|
-
NEEDLE_compression_texture,
|
|
53
|
-
NEEDLE_mesh_compression,
|
|
54
|
-
])
|
|
55
|
-
.registerDependencies({
|
|
56
|
-
'draco3d.decoder': await draco3d.createDecoderModule(),
|
|
57
|
-
'draco3d.encoder': await draco3d.createEncoderModule(),
|
|
58
|
-
'meshopt.decoder': MeshoptDecoder,
|
|
59
|
-
'meshopt.encoder': MeshoptEncoder,
|
|
60
|
-
});
|
|
61
|
-
const document = await io.read(inputFile);
|
|
62
|
-
/** @ts-ignore */
|
|
63
|
-
document.getLogger().verbosity = options.debug || options.verbose ? Verbosity.DEBUG : Verbosity.WARN;
|
|
64
|
-
let totalGPUTextureMemory = 0;
|
|
65
|
-
/** @type {Array<import('@gltf-transform/core').Transform>} */
|
|
66
|
-
const transforms = [
|
|
67
|
-
needle_asset(),
|
|
68
|
-
needle_texture_transform({
|
|
69
|
-
file: inputFile,
|
|
70
|
-
useCache,
|
|
71
|
-
noToktx: false,
|
|
72
|
-
debug: debug,
|
|
73
|
-
reportGPUMemory: val => {
|
|
74
|
-
totalGPUTextureMemory += val;
|
|
75
|
-
},
|
|
76
|
-
config,
|
|
77
|
-
}),
|
|
78
|
-
needle_mesh_transform({ file: inputFile, config }, { ratio: 0.75, error: 0.0005 }),
|
|
79
|
-
needle_animation_transform({}),
|
|
80
|
-
resample(),
|
|
81
|
-
// Can not dedup "materials" because progressive textures will then assigned to the wrong material instance
|
|
82
|
-
dedup({ propertyTypes: [PropertyType.MESH, PropertyType.MATERIAL] }),
|
|
83
|
-
// prune(),
|
|
84
|
-
];
|
|
85
|
-
const isProgressiveAsset = isLOD(inputFile);
|
|
86
|
-
// TODO: progressive mesh LODs should not be pruned right now because it will remove e.g. UVs from meshes (and probably blend shapes too) (so we just not do it for any progressive asset)
|
|
87
|
-
if (!isProgressiveAsset) {
|
|
88
|
-
transforms.push(prune({
|
|
89
|
-
// Pruning animations is not supported yet (e.g. if the animation is only referenced by a component)
|
|
90
|
-
propertyTypes: ['MESH', 'MATERIAL', 'TEXTURE']
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
93
|
-
await document.transform(...transforms);
|
|
94
|
-
if (!outputFile)
|
|
95
|
-
outputFile = inputFile;
|
|
96
|
-
await writeNodeIO(io, outputFile, document);
|
|
97
|
-
if (useCache && cacheKey != undefined && existsSync(outputFile))
|
|
98
|
-
addToCache(cacheKey, readFileSync(outputFile));
|
|
99
|
-
const duration = Date.now() - startTime;
|
|
100
|
-
const sizeInMB = statSync(outputFile).size / 1024 / 1024;
|
|
101
|
-
const filename = path.basename(outputFile);
|
|
102
|
-
const gpuMemoryInMB = totalGPUTextureMemory / 1024 / 1024;
|
|
103
|
-
logger.info(`← Compressing done in ${(duration / 1000).toFixed(1)} sec, ${prevSizeInMB.toFixed(1)} MB → ${sizeInMB.toFixed(1)} MB (GPU: ${gpuMemoryInMB.toFixed(1)} MB textures): ${filename} at ${outputFile}`);
|
|
104
|
-
if (stats) {
|
|
105
|
-
stats.totalFilesProcessed++;
|
|
106
|
-
stats.totalFileSizeInMB += sizeInMB;
|
|
107
|
-
stats.totalFileSizeInMBBefore += prevSizeInMB;
|
|
108
|
-
stats.totalGPUMemoryInMB += gpuMemoryInMB;
|
|
109
|
-
}
|
|
110
|
-
const filestats = createNewFilestats(outputFile, document);
|
|
111
|
-
options.file_stats?.push(filestats);
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
logger.error(`packing ${path.basename(inputFile)} failed: ${err}`);
|
|
116
|
-
if (debug)
|
|
117
|
-
throw err;
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { Logger, NodeIO, PropertyType, Verbosity } from '@gltf-transform/core';
|
|
3
|
+
import { ALL_EXTENSIONS } from '@gltf-transform/extensions';
|
|
4
|
+
import draco3d from 'draco3dgltf';
|
|
5
|
+
import { existsSync, readFileSync, statSync, writeFileSync } from 'fs';
|
|
6
|
+
import { MeshoptDecoder, MeshoptEncoder } from 'meshoptimizer';
|
|
7
|
+
import { dedup, prune, resample } from '@gltf-transform/functions';
|
|
8
|
+
import { ALL_EXTENSIONS as NEEDLE_EXTENSIONS, NEEDLE_compression_texture, NEEDLE_mesh_compression, } from '../extensions/index.js';
|
|
9
|
+
import { isLOD, isMeshLOD, needle_animation_transform, needle_asset, needle_mesh_transform, needle_texture_transform, } from '../transforms/index.js';
|
|
10
|
+
import { createNewFilestats, writeNodeIO } from "../utils/index.js";
|
|
11
|
+
import { addToCache, getHash, tryGetFromCache, } from "../cache/index.js";
|
|
12
|
+
/** Compress a glTF file
|
|
13
|
+
*/
|
|
14
|
+
export async function packGLTF(inputFile, outputFile, options) {
|
|
15
|
+
if (!options.logger) {
|
|
16
|
+
options.logger = new Logger(Verbosity.INFO);
|
|
17
|
+
}
|
|
18
|
+
const { debug, stats, packedFiles, useCache, logger } = options;
|
|
19
|
+
if (!existsSync(inputFile)) {
|
|
20
|
+
logger.error("WARN: can not pack, file does not exist: " + inputFile);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
// check if it's in the cache.
|
|
24
|
+
// We only need to check mesh LOD files because image LODs are cache via our toktx transform
|
|
25
|
+
// We can not cache the main glTF files because the hash always changes for them
|
|
26
|
+
let cacheKey = undefined;
|
|
27
|
+
if (useCache && isMeshLOD(inputFile)) {
|
|
28
|
+
const existing = readFileSync(inputFile);
|
|
29
|
+
const hash = getHash(existing);
|
|
30
|
+
cacheKey = "packed-" + hash;
|
|
31
|
+
const cached = tryGetFromCache(cacheKey);
|
|
32
|
+
if (cached) {
|
|
33
|
+
logger.info(`→ Loaded compressed file from cache: \"${path.basename(inputFile)}\"`);
|
|
34
|
+
writeFileSync(inputFile, cached);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (packedFiles) {
|
|
39
|
+
if (packedFiles.has(inputFile))
|
|
40
|
+
return true;
|
|
41
|
+
packedFiles.add(inputFile);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const config = options.config;
|
|
45
|
+
const prevSizeInMB = statSync(inputFile).size / 1024 / 1024;
|
|
46
|
+
logger.info(`→ Compressing ${prevSizeInMB.toFixed(1)} MB: ${inputFile}`);
|
|
47
|
+
const startTime = Date.now();
|
|
48
|
+
const io = new NodeIO()
|
|
49
|
+
.registerExtensions(ALL_EXTENSIONS)
|
|
50
|
+
.registerExtensions(NEEDLE_EXTENSIONS)
|
|
51
|
+
.registerExtensions([
|
|
52
|
+
NEEDLE_compression_texture,
|
|
53
|
+
NEEDLE_mesh_compression,
|
|
54
|
+
])
|
|
55
|
+
.registerDependencies({
|
|
56
|
+
'draco3d.decoder': await draco3d.createDecoderModule(),
|
|
57
|
+
'draco3d.encoder': await draco3d.createEncoderModule(),
|
|
58
|
+
'meshopt.decoder': MeshoptDecoder,
|
|
59
|
+
'meshopt.encoder': MeshoptEncoder,
|
|
60
|
+
});
|
|
61
|
+
const document = await io.read(inputFile);
|
|
62
|
+
/** @ts-ignore */
|
|
63
|
+
document.getLogger().verbosity = options.debug || options.verbose ? Verbosity.DEBUG : Verbosity.WARN;
|
|
64
|
+
let totalGPUTextureMemory = 0;
|
|
65
|
+
/** @type {Array<import('@gltf-transform/core').Transform>} */
|
|
66
|
+
const transforms = [
|
|
67
|
+
needle_asset(),
|
|
68
|
+
needle_texture_transform({
|
|
69
|
+
file: inputFile,
|
|
70
|
+
useCache,
|
|
71
|
+
noToktx: false,
|
|
72
|
+
debug: debug,
|
|
73
|
+
reportGPUMemory: val => {
|
|
74
|
+
totalGPUTextureMemory += val;
|
|
75
|
+
},
|
|
76
|
+
config,
|
|
77
|
+
}),
|
|
78
|
+
needle_mesh_transform({ file: inputFile, config }, { ratio: 0.75, error: 0.0005 }),
|
|
79
|
+
needle_animation_transform({}),
|
|
80
|
+
resample(),
|
|
81
|
+
// Can not dedup "materials" because progressive textures will then assigned to the wrong material instance
|
|
82
|
+
dedup({ propertyTypes: [PropertyType.MESH, PropertyType.MATERIAL] }),
|
|
83
|
+
// prune(),
|
|
84
|
+
];
|
|
85
|
+
const isProgressiveAsset = isLOD(inputFile);
|
|
86
|
+
// TODO: progressive mesh LODs should not be pruned right now because it will remove e.g. UVs from meshes (and probably blend shapes too) (so we just not do it for any progressive asset)
|
|
87
|
+
if (!isProgressiveAsset) {
|
|
88
|
+
transforms.push(prune({
|
|
89
|
+
// Pruning animations is not supported yet (e.g. if the animation is only referenced by a component)
|
|
90
|
+
propertyTypes: ['MESH', 'MATERIAL', 'TEXTURE']
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
await document.transform(...transforms);
|
|
94
|
+
if (!outputFile)
|
|
95
|
+
outputFile = inputFile;
|
|
96
|
+
await writeNodeIO(io, outputFile, document);
|
|
97
|
+
if (useCache && cacheKey != undefined && existsSync(outputFile))
|
|
98
|
+
addToCache(cacheKey, readFileSync(outputFile));
|
|
99
|
+
const duration = Date.now() - startTime;
|
|
100
|
+
const sizeInMB = statSync(outputFile).size / 1024 / 1024;
|
|
101
|
+
const filename = path.basename(outputFile);
|
|
102
|
+
const gpuMemoryInMB = totalGPUTextureMemory / 1024 / 1024;
|
|
103
|
+
logger.info(`← Compressing done in ${(duration / 1000).toFixed(1)} sec, ${prevSizeInMB.toFixed(1)} MB → ${sizeInMB.toFixed(1)} MB (GPU: ${gpuMemoryInMB.toFixed(1)} MB textures): ${filename} at ${outputFile}`);
|
|
104
|
+
if (stats) {
|
|
105
|
+
stats.totalFilesProcessed++;
|
|
106
|
+
stats.totalFileSizeInMB += sizeInMB;
|
|
107
|
+
stats.totalFileSizeInMBBefore += prevSizeInMB;
|
|
108
|
+
stats.totalGPUMemoryInMB += gpuMemoryInMB;
|
|
109
|
+
}
|
|
110
|
+
const filestats = createNewFilestats(outputFile, document);
|
|
111
|
+
options.file_stats?.push(filestats);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
logger.error(`packing ${path.basename(inputFile)} failed: ${err}`);
|
|
116
|
+
if (debug)
|
|
117
|
+
throw err;
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
package/dist/scripts/stats.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FileStats } from "../utils/stats.js";
|
|
2
|
-
export declare function calculateStats(inputfile: string): Promise<FileStats>;
|
|
1
|
+
import { FileStats } from "../utils/stats.js";
|
|
2
|
+
export declare function calculateStats(inputfile: string): Promise<FileStats>;
|
package/dist/scripts/stats.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { NodeIO } from "@gltf-transform/core";
|
|
2
|
-
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
|
3
|
-
import draco3d from 'draco3dgltf';
|
|
4
|
-
import { MeshoptDecoder, MeshoptEncoder } from "meshoptimizer";
|
|
5
|
-
import { createNewFilestats } from "../utils/stats.js";
|
|
6
|
-
export async function calculateStats(inputfile) {
|
|
7
|
-
const io = new NodeIO()
|
|
8
|
-
.registerExtensions(ALL_EXTENSIONS)
|
|
9
|
-
.registerDependencies({
|
|
10
|
-
'draco3d.decoder': await draco3d.createDecoderModule(),
|
|
11
|
-
'draco3d.encoder': await draco3d.createEncoderModule(),
|
|
12
|
-
'meshopt.decoder': MeshoptDecoder,
|
|
13
|
-
'meshopt.encoder': MeshoptEncoder,
|
|
14
|
-
});
|
|
15
|
-
const document = await io.read(inputfile);
|
|
16
|
-
const stats = createNewFilestats(inputfile, document);
|
|
17
|
-
return stats;
|
|
18
|
-
}
|
|
1
|
+
import { NodeIO } from "@gltf-transform/core";
|
|
2
|
+
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
|
3
|
+
import draco3d from 'draco3dgltf';
|
|
4
|
+
import { MeshoptDecoder, MeshoptEncoder } from "meshoptimizer";
|
|
5
|
+
import { createNewFilestats } from "../utils/stats.js";
|
|
6
|
+
export async function calculateStats(inputfile) {
|
|
7
|
+
const io = new NodeIO()
|
|
8
|
+
.registerExtensions(ALL_EXTENSIONS)
|
|
9
|
+
.registerDependencies({
|
|
10
|
+
'draco3d.decoder': await draco3d.createDecoderModule(),
|
|
11
|
+
'draco3d.encoder': await draco3d.createEncoderModule(),
|
|
12
|
+
'meshopt.decoder': MeshoptDecoder,
|
|
13
|
+
'meshopt.encoder': MeshoptEncoder,
|
|
14
|
+
});
|
|
15
|
+
const document = await io.read(inputfile);
|
|
16
|
+
const stats = createNewFilestats(inputfile, document);
|
|
17
|
+
return stats;
|
|
18
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from "./needle_asset.js";
|
|
2
|
-
export * from "./toktx.js";
|
|
3
|
-
export * from "./needle_toktx.js";
|
|
4
|
-
export * from "./needle_progressive.js";
|
|
5
|
-
export * from "./needle_webp.js";
|
|
6
|
-
export * from "./needle_mesh_transform.js";
|
|
7
|
-
export * from "./needle_common.js";
|
|
8
|
-
export * from "./needle_texture_transform.js";
|
|
9
|
-
export * from "./needle_animation_transform.js";
|
|
1
|
+
export * from "./needle_asset.js";
|
|
2
|
+
export * from "./toktx.js";
|
|
3
|
+
export * from "./needle_toktx.js";
|
|
4
|
+
export * from "./needle_progressive.js";
|
|
5
|
+
export * from "./needle_webp.js";
|
|
6
|
+
export * from "./needle_mesh_transform.js";
|
|
7
|
+
export * from "./needle_common.js";
|
|
8
|
+
export * from "./needle_texture_transform.js";
|
|
9
|
+
export * from "./needle_animation_transform.js";
|
package/dist/transforms/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from "./needle_asset.js";
|
|
2
|
-
export * from "./toktx.js";
|
|
3
|
-
export * from "./needle_toktx.js";
|
|
4
|
-
export * from "./needle_progressive.js";
|
|
5
|
-
export * from "./needle_webp.js";
|
|
6
|
-
export * from "./needle_mesh_transform.js";
|
|
7
|
-
export * from "./needle_common.js";
|
|
8
|
-
export * from "./needle_texture_transform.js";
|
|
9
|
-
export * from "./needle_animation_transform.js";
|
|
1
|
+
export * from "./needle_asset.js";
|
|
2
|
+
export * from "./toktx.js";
|
|
3
|
+
export * from "./needle_toktx.js";
|
|
4
|
+
export * from "./needle_progressive.js";
|
|
5
|
+
export * from "./needle_webp.js";
|
|
6
|
+
export * from "./needle_mesh_transform.js";
|
|
7
|
+
export * from "./needle_common.js";
|
|
8
|
+
export * from "./needle_texture_transform.js";
|
|
9
|
+
export * from "./needle_animation_transform.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Transform } from "@gltf-transform/core";
|
|
2
|
-
export declare const needle_animation_transform: (_options: any) => Transform;
|
|
1
|
+
import { Transform } from "@gltf-transform/core";
|
|
2
|
+
export declare const needle_animation_transform: (_options: any) => Transform;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const needle_animation_transform = function (_options) {
|
|
2
|
-
// return resample();
|
|
3
|
-
return (document, _context) => {
|
|
4
|
-
};
|
|
5
|
-
};
|
|
1
|
+
export const needle_animation_transform = function (_options) {
|
|
2
|
+
// return resample();
|
|
3
|
+
return (document, _context) => {
|
|
4
|
+
};
|
|
5
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Document, Transform } from '@gltf-transform/core';
|
|
2
|
-
export declare function writeNeedleAsset(document: Document): void;
|
|
3
|
-
export declare function needle_asset(): Transform;
|
|
1
|
+
import { Document, Transform } from '@gltf-transform/core';
|
|
2
|
+
export declare function writeNeedleAsset(document: Document): void;
|
|
3
|
+
export declare function needle_asset(): Transform;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { createTransform } from '@gltf-transform/functions';
|
|
2
|
-
import { getVersion } from '../index.js';
|
|
3
|
-
const generatorName = "Needle Build Pipeline";
|
|
4
|
-
export function writeNeedleAsset(document) {
|
|
5
|
-
const root = document.getRoot();
|
|
6
|
-
const asset = root.getAsset();
|
|
7
|
-
if (asset) {
|
|
8
|
-
asset.extras = writeNeedleExtras(asset.extras);
|
|
9
|
-
const version = getVersion();
|
|
10
|
-
asset.generator = generatorName;
|
|
11
|
-
if (version?.length > 0) {
|
|
12
|
-
asset.generator += " " + version;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export function needle_asset() {
|
|
17
|
-
return createTransform("needle_asset_transform", (document) => {
|
|
18
|
-
writeNeedleAsset(document);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/** @internal */
|
|
22
|
-
function writeNeedleExtras(extras) {
|
|
23
|
-
if (!extras)
|
|
24
|
-
extras = {};
|
|
25
|
-
if (typeof extras === "object" && !extras["needle"]) {
|
|
26
|
-
let generator = generatorName;
|
|
27
|
-
const version = getVersion();
|
|
28
|
-
if (version?.length > 0)
|
|
29
|
-
generator += " " + version;
|
|
30
|
-
extras["needle"] = {
|
|
31
|
-
generator: generator
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return extras;
|
|
35
|
-
}
|
|
1
|
+
import { createTransform } from '@gltf-transform/functions';
|
|
2
|
+
import { getVersion } from '../index.js';
|
|
3
|
+
const generatorName = "Needle Build Pipeline";
|
|
4
|
+
export function writeNeedleAsset(document) {
|
|
5
|
+
const root = document.getRoot();
|
|
6
|
+
const asset = root.getAsset();
|
|
7
|
+
if (asset) {
|
|
8
|
+
asset.extras = writeNeedleExtras(asset.extras);
|
|
9
|
+
const version = getVersion();
|
|
10
|
+
asset.generator = generatorName;
|
|
11
|
+
if (version?.length > 0) {
|
|
12
|
+
asset.generator += " " + version;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function needle_asset() {
|
|
17
|
+
return createTransform("needle_asset_transform", (document) => {
|
|
18
|
+
writeNeedleAsset(document);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** @internal */
|
|
22
|
+
function writeNeedleExtras(extras) {
|
|
23
|
+
if (!extras)
|
|
24
|
+
extras = {};
|
|
25
|
+
if (typeof extras === "object" && !extras["needle"]) {
|
|
26
|
+
let generator = generatorName;
|
|
27
|
+
const version = getVersion();
|
|
28
|
+
if (version?.length > 0)
|
|
29
|
+
generator += " " + version;
|
|
30
|
+
extras["needle"] = {
|
|
31
|
+
generator: generator
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return extras;
|
|
35
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Document, Texture } from '@gltf-transform/core';
|
|
2
|
-
import { NEEDLE_compression_texture_schema } from '../extensions/index.js';
|
|
3
|
-
import { Config } from '../config/index.js';
|
|
4
|
-
export interface NeedleTransformContext {
|
|
5
|
-
/** full path to the file being processed */
|
|
6
|
-
file: string;
|
|
7
|
-
config: Config;
|
|
8
|
-
debug?: boolean;
|
|
9
|
-
useCache: boolean;
|
|
10
|
-
noToktx: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface INeedleTextureTransformContext {
|
|
13
|
-
prepare(document: Document): Promise<void | boolean>;
|
|
14
|
-
process(index: number, texture: Texture, settings: NEEDLE_compression_texture_schema, context: NeedleTransformContext): Promise<boolean>;
|
|
15
|
-
finalize(document: Document): Promise<void>;
|
|
16
|
-
}
|
|
1
|
+
import { Document, Texture } from '@gltf-transform/core';
|
|
2
|
+
import { NEEDLE_compression_texture_schema } from '../extensions/index.js';
|
|
3
|
+
import { Config } from '../config/index.js';
|
|
4
|
+
export interface NeedleTransformContext {
|
|
5
|
+
/** full path to the file being processed */
|
|
6
|
+
file: string;
|
|
7
|
+
config: Config;
|
|
8
|
+
debug?: boolean;
|
|
9
|
+
useCache: boolean;
|
|
10
|
+
noToktx: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface INeedleTextureTransformContext {
|
|
13
|
+
prepare(document: Document): Promise<void | boolean>;
|
|
14
|
+
process(index: number, texture: Texture, settings: NEEDLE_compression_texture_schema, context: NeedleTransformContext): Promise<boolean>;
|
|
15
|
+
finalize(document: Document): Promise<void>;
|
|
16
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Transform, Document, Primitive, Mesh } from "@gltf-transform/core";
|
|
2
|
-
import { SimplifyOptions, WeldOptions } from "@gltf-transform/functions";
|
|
3
|
-
import { Config } from "../config/index.js";
|
|
4
|
-
declare type MeshTransformContext = {
|
|
5
|
-
file: string;
|
|
6
|
-
config: Config;
|
|
7
|
-
};
|
|
8
|
-
export declare const needle_mesh_transform: (context: MeshTransformContext, simplify: Omit<SimplifyOptions, "simplifier">) => Transform;
|
|
9
|
-
export declare function compressPrimitive(document: Document, mesh: Mesh, prim: Primitive, index: number, weldOptions: Required<WeldOptions>, meshOptions: Required<SimplifyOptions>): Promise<Primitive>;
|
|
10
|
-
export {};
|
|
1
|
+
import { Transform, Document, Primitive, Mesh } from "@gltf-transform/core";
|
|
2
|
+
import { SimplifyOptions, WeldOptions } from "@gltf-transform/functions";
|
|
3
|
+
import { Config } from "../config/index.js";
|
|
4
|
+
declare type MeshTransformContext = {
|
|
5
|
+
file: string;
|
|
6
|
+
config: Config;
|
|
7
|
+
};
|
|
8
|
+
export declare const needle_mesh_transform: (context: MeshTransformContext, simplify: Omit<SimplifyOptions, "simplifier">) => Transform;
|
|
9
|
+
export declare function compressPrimitive(document: Document, mesh: Mesh, prim: Primitive, index: number, weldOptions: Required<WeldOptions>, meshOptions: Required<SimplifyOptions>): Promise<Primitive>;
|
|
10
|
+
export {};
|