@needle-tools/gltf-build-pipeline 2.16.0-next.fc19d36 → 3.0.0-alpha
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/CHANGELOG.md +25 -0
- package/README.md +41 -2
- package/dist/cli/index.js +4154 -232
- package/package.json +9 -14
- package/tools/pmrem/pkg/pmrem_wasm.d.ts +25 -0
- package/tools/pmrem/pkg/pmrem_wasm.js +110 -0
- package/tools/pmrem/pkg/pmrem_wasm_bg.wasm +0 -0
- package/dist/cache/cache.d.ts +0 -58
- package/dist/cache/cache.js +0 -330
- package/dist/cache/index.d.ts +0 -2
- package/dist/cache/index.js +0 -2
- package/dist/cache/job-cache.d.ts +0 -26
- package/dist/cache/job-cache.js +0 -84
- package/dist/cli/index.d.ts +0 -2
- package/dist/config/index.d.ts +0 -53
- package/dist/config/index.js +0 -156
- package/dist/constants.d.ts +0 -7
- package/dist/constants.js +0 -7
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.d.ts +0 -24
- package/dist/extensions/NEEDLE_compression_texture/NEEDLE_compression_texture.js +0 -54
- package/dist/extensions/NEEDLE_compression_texture/index.d.ts +0 -1
- package/dist/extensions/NEEDLE_compression_texture/index.js +0 -1
- package/dist/extensions/NEEDLE_lightmaps/index.d.ts +0 -39
- package/dist/extensions/NEEDLE_lightmaps/index.js +0 -257
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.d.ts +0 -27
- package/dist/extensions/NEEDLE_mesh_compression/NEEDLE_mesh_compression.js +0 -88
- package/dist/extensions/NEEDLE_mesh_compression/index.d.ts +0 -1
- package/dist/extensions/NEEDLE_mesh_compression/index.js +0 -1
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.d.ts +0 -27
- package/dist/extensions/NEEDLE_opaque/NEEDLE_opaque.js +0 -1048
- package/dist/extensions/NEEDLE_opaque/index.d.ts +0 -3
- package/dist/extensions/NEEDLE_opaque/index.js +0 -30
- package/dist/extensions/NEEDLE_pmrem/index.d.ts +0 -21
- package/dist/extensions/NEEDLE_pmrem/index.js +0 -95
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.d.ts +0 -48
- package/dist/extensions/NEEDLE_progressive/NEEDLE_progressive.js +0 -69
- package/dist/extensions/NEEDLE_progressive/index.d.ts +0 -1
- package/dist/extensions/NEEDLE_progressive/index.js +0 -1
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.d.ts +0 -23
- package/dist/extensions/NEEDLE_progressive_mesh_settings/index.js +0 -41
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.d.ts +0 -25
- package/dist/extensions/NEEDLE_progressive_texture_settings/index.js +0 -38
- package/dist/extensions/index.d.ts +0 -15
- package/dist/extensions/index.js +0 -34
- package/dist/extensions/utils.d.ts +0 -9
- package/dist/extensions/utils.js +0 -79
- package/dist/functions/weld.3.d.ts +0 -76
- package/dist/functions/weld.3.js +0 -414
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/scripts/index.d.ts +0 -2
- package/dist/scripts/index.js +0 -2
- package/dist/scripts/pack-gltf.d.ts +0 -17
- package/dist/scripts/pack-gltf.js +0 -152
- package/dist/scripts/stats.d.ts +0 -5
- package/dist/scripts/stats.js +0 -20
- package/dist/transforms/index.d.ts +0 -9
- package/dist/transforms/index.js +0 -9
- package/dist/transforms/needle_animation_transform.d.ts +0 -2
- package/dist/transforms/needle_animation_transform.js +0 -5
- package/dist/transforms/needle_asset.d.ts +0 -3
- package/dist/transforms/needle_asset.js +0 -50
- package/dist/transforms/needle_common.d.ts +0 -17
- package/dist/transforms/needle_common.js +0 -1
- package/dist/transforms/needle_mesh_transform.d.ts +0 -15
- package/dist/transforms/needle_mesh_transform.js +0 -223
- package/dist/transforms/needle_pmrem.d.ts +0 -21
- package/dist/transforms/needle_pmrem.js +0 -238
- package/dist/transforms/needle_progressive.d.ts +0 -45
- package/dist/transforms/needle_progressive.js +0 -1101
- package/dist/transforms/needle_texture_transform.d.ts +0 -15
- package/dist/transforms/needle_texture_transform.js +0 -267
- package/dist/transforms/needle_toktx.d.ts +0 -26
- package/dist/transforms/needle_toktx.js +0 -250
- package/dist/transforms/needle_webp.d.ts +0 -15
- package/dist/transforms/needle_webp.js +0 -53
- package/dist/transforms/toktx.d.ts +0 -52
- package/dist/transforms/toktx.js +0 -221
- package/dist/transforms/toktx_types.d.ts +0 -78
- package/dist/transforms/toktx_types.js +0 -62
- package/dist/transforms/util.d.ts +0 -21
- package/dist/transforms/util.js +0 -90
- package/dist/utils/analytics.d.ts +0 -24
- package/dist/utils/analytics.js +0 -128
- package/dist/utils/compression_utils.d.ts +0 -2
- package/dist/utils/compression_utils.js +0 -6
- package/dist/utils/fileutils.d.ts +0 -22
- package/dist/utils/fileutils.js +0 -195
- package/dist/utils/guid.d.ts +0 -1
- package/dist/utils/guid.js +0 -5
- package/dist/utils/index.d.ts +0 -10
- package/dist/utils/index.js +0 -10
- package/dist/utils/merge.d.ts +0 -12
- package/dist/utils/merge.js +0 -31
- package/dist/utils/mesh.d.ts +0 -13
- package/dist/utils/mesh.js +0 -124
- package/dist/utils/nodeio.d.ts +0 -11
- package/dist/utils/nodeio.js +0 -116
- package/dist/utils/stats.d.ts +0 -70
- package/dist/utils/stats.js +0 -265
- package/dist/utils/test-assert.d.ts +0 -8
- package/dist/utils/test-assert.js +0 -18
- package/dist/utils/texture.d.ts +0 -5
- package/dist/utils/texture.js +0 -14
- package/dist/utils/validate.d.ts +0 -6
- package/dist/utils/validate.js +0 -17
- package/dist/utils/version.d.ts +0 -1
- package/dist/utils/version.gen.d.ts +0 -1
- package/dist/utils/version.gen.js +0 -1
- package/dist/utils/version.js +0 -4
- package/scripts/clear-caches.mjs +0 -4
- package/scripts/defaults.mjs +0 -12
- package/scripts/fileutils.mjs +0 -6
- package/scripts/index.mjs +0 -41
- package/scripts/limit-caches.mjs +0 -4
- package/scripts/make-progressive.mjs +0 -16
- package/scripts/pack-gltf.mjs +0 -107
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-build-pipeline",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha",
|
|
4
4
|
"description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
5
|
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json"
|
|
8
|
+
},
|
|
7
9
|
"readme": "README.md",
|
|
8
10
|
"author": {
|
|
9
11
|
"name": "Needle",
|
|
@@ -20,7 +22,6 @@
|
|
|
20
22
|
},
|
|
21
23
|
"files": [
|
|
22
24
|
"dist",
|
|
23
|
-
"scripts",
|
|
24
25
|
"tools/pmrem",
|
|
25
26
|
"README.md",
|
|
26
27
|
"CHANGELOG.md"
|
|
@@ -29,18 +30,10 @@
|
|
|
29
30
|
"#package.json": "./package.json"
|
|
30
31
|
},
|
|
31
32
|
"scripts": {
|
|
32
|
-
"start": "node scripts/index.mjs",
|
|
33
33
|
"dev": "npm-watch compile",
|
|
34
|
-
"publish-package": "npm
|
|
35
|
-
"prepublishOnly": "npm run compile",
|
|
36
|
-
"compile": "node tools/prebuild.mjs && (tsc || exit 1) && node tools/postbuild.mjs",
|
|
37
|
-
"clear-caches": "node scripts/clear-caches.mjs",
|
|
38
|
-
"limit-caches": "node scripts/limit-caches.mjs",
|
|
39
|
-
"transform": "node scripts/index.mjs",
|
|
40
|
-
"transform:make-progressive": "node scripts/make-progressive.mjs",
|
|
41
|
-
"transform:pack-gltf": "node --no-experimental-fetch scripts/pack-gltf.mjs",
|
|
42
|
-
"pack-gltf": "node --no-experimental-fetch scripts/pack-gltf.mjs",
|
|
43
|
-
"dev:pack-gltf": "npm run compile && node scripts/pack-gltf.mjs",
|
|
34
|
+
"publish-package": "npm publish",
|
|
35
|
+
"prepublishOnly": "NEEDLE_BUILD_MODE=publish npm run compile && node tools/check-no-test-key.mjs",
|
|
36
|
+
"compile": "node tools/prebuild.mjs && (tsc || exit 1) && node tools/bundle.mjs && node tools/postbuild.mjs",
|
|
44
37
|
"test": "tsx tests/utils/download-fixtures.ts && vitest run",
|
|
45
38
|
"test:watch": "vitest",
|
|
46
39
|
"test:setup": "tsx tests/utils/download-fixtures.ts",
|
|
@@ -48,6 +41,7 @@
|
|
|
48
41
|
},
|
|
49
42
|
"devDependencies": {
|
|
50
43
|
"@types/node": "^22.19.15",
|
|
44
|
+
"esbuild": "^0.28.0",
|
|
51
45
|
"gltf-validator": "^2.0.0-dev.3.9",
|
|
52
46
|
"npm-watch": "^0.13.0",
|
|
53
47
|
"tsx": "^4.19.0",
|
|
@@ -69,6 +63,7 @@
|
|
|
69
63
|
"command-line-args": "^5.2.1",
|
|
70
64
|
"draco3dgltf": "^1.5.3",
|
|
71
65
|
"glob": "^7.2.0",
|
|
66
|
+
"jose": "^6.2.3",
|
|
72
67
|
"meshoptimizer": "0.25.0",
|
|
73
68
|
"micromatch": "^4.0.5",
|
|
74
69
|
"ndarray": "^1.0.19",
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Decode a Radiance `.hdr` file and re-encode it as an EXR (`SMALL_LOSSLESS`).
|
|
6
|
+
*/
|
|
7
|
+
export function hdr_to_exr(input: Uint8Array): Uint8Array;
|
|
8
|
+
|
|
4
9
|
export function pmrem_exr(input: Uint8Array): Uint8Array;
|
|
5
10
|
|
|
6
11
|
/**
|
|
@@ -14,6 +19,22 @@ export function pmrem_exr_resized(input: Uint8Array, target_width: number): Uint
|
|
|
14
19
|
*/
|
|
15
20
|
export function pmrem_exr_resized_with_filter(input: Uint8Array, target_width: number, filter: string): Uint8Array;
|
|
16
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Decode a Radiance `.hdr` file, run PMREM, and return PMREM EXR bytes.
|
|
24
|
+
* Output is structurally identical to `pmrem_exr`.
|
|
25
|
+
*/
|
|
26
|
+
export function pmrem_hdr(input: Uint8Array): Uint8Array;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* PMREM from HDR with optional downscale to `target_width` (Lanczos3).
|
|
30
|
+
*/
|
|
31
|
+
export function pmrem_hdr_resized(input: Uint8Array, target_width: number): Uint8Array;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* PMREM from HDR with optional downscale and selectable filter.
|
|
35
|
+
*/
|
|
36
|
+
export function pmrem_hdr_resized_with_filter(input: Uint8Array, target_width: number, filter: string): Uint8Array;
|
|
37
|
+
|
|
17
38
|
/**
|
|
18
39
|
* Resize equirectangular EXR to target width (maintain aspect), returning EXR bytes.
|
|
19
40
|
*/
|
|
@@ -33,9 +54,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
33
54
|
|
|
34
55
|
export interface InitOutput {
|
|
35
56
|
readonly memory: WebAssembly.Memory;
|
|
57
|
+
readonly hdr_to_exr: (a: number, b: number, c: number) => void;
|
|
36
58
|
readonly pmrem_exr: (a: number, b: number, c: number) => void;
|
|
37
59
|
readonly pmrem_exr_resized: (a: number, b: number, c: number, d: number) => void;
|
|
38
60
|
readonly pmrem_exr_resized_with_filter: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
61
|
+
readonly pmrem_hdr: (a: number, b: number, c: number) => void;
|
|
62
|
+
readonly pmrem_hdr_resized: (a: number, b: number, c: number, d: number) => void;
|
|
63
|
+
readonly pmrem_hdr_resized_with_filter: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
39
64
|
readonly resize_equirect_exr: (a: number, b: number, c: number, d: number) => void;
|
|
40
65
|
readonly resize_equirect_exr_with_filter: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
41
66
|
readonly split_pmrem_exr_to_zip: (a: number, b: number, c: number) => void;
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/* @ts-self-types="./pmrem_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Decode a Radiance `.hdr` file and re-encode it as an EXR (`SMALL_LOSSLESS`).
|
|
5
|
+
* @param {Uint8Array} input
|
|
6
|
+
* @returns {Uint8Array}
|
|
7
|
+
*/
|
|
8
|
+
export function hdr_to_exr(input) {
|
|
9
|
+
try {
|
|
10
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
11
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
|
|
12
|
+
const len0 = WASM_VECTOR_LEN;
|
|
13
|
+
wasm.hdr_to_exr(retptr, ptr0, len0);
|
|
14
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
15
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
16
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
17
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
18
|
+
if (r3) {
|
|
19
|
+
throw takeObject(r2);
|
|
20
|
+
}
|
|
21
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
22
|
+
wasm.__wbindgen_export2(r0, r1 * 1, 1);
|
|
23
|
+
return v2;
|
|
24
|
+
} finally {
|
|
25
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
3
29
|
/**
|
|
4
30
|
* @param {Uint8Array} input
|
|
5
31
|
* @returns {Uint8Array}
|
|
@@ -83,6 +109,90 @@ export function pmrem_exr_resized_with_filter(input, target_width, filter) {
|
|
|
83
109
|
}
|
|
84
110
|
}
|
|
85
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Decode a Radiance `.hdr` file, run PMREM, and return PMREM EXR bytes.
|
|
114
|
+
* Output is structurally identical to `pmrem_exr`.
|
|
115
|
+
* @param {Uint8Array} input
|
|
116
|
+
* @returns {Uint8Array}
|
|
117
|
+
*/
|
|
118
|
+
export function pmrem_hdr(input) {
|
|
119
|
+
try {
|
|
120
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
121
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
|
|
122
|
+
const len0 = WASM_VECTOR_LEN;
|
|
123
|
+
wasm.pmrem_hdr(retptr, ptr0, len0);
|
|
124
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
125
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
126
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
127
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
128
|
+
if (r3) {
|
|
129
|
+
throw takeObject(r2);
|
|
130
|
+
}
|
|
131
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
132
|
+
wasm.__wbindgen_export2(r0, r1 * 1, 1);
|
|
133
|
+
return v2;
|
|
134
|
+
} finally {
|
|
135
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* PMREM from HDR with optional downscale to `target_width` (Lanczos3).
|
|
141
|
+
* @param {Uint8Array} input
|
|
142
|
+
* @param {number} target_width
|
|
143
|
+
* @returns {Uint8Array}
|
|
144
|
+
*/
|
|
145
|
+
export function pmrem_hdr_resized(input, target_width) {
|
|
146
|
+
try {
|
|
147
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
148
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
|
|
149
|
+
const len0 = WASM_VECTOR_LEN;
|
|
150
|
+
wasm.pmrem_hdr_resized(retptr, ptr0, len0, target_width);
|
|
151
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
152
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
153
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
154
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
155
|
+
if (r3) {
|
|
156
|
+
throw takeObject(r2);
|
|
157
|
+
}
|
|
158
|
+
var v2 = getArrayU8FromWasm0(r0, r1).slice();
|
|
159
|
+
wasm.__wbindgen_export2(r0, r1 * 1, 1);
|
|
160
|
+
return v2;
|
|
161
|
+
} finally {
|
|
162
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* PMREM from HDR with optional downscale and selectable filter.
|
|
168
|
+
* @param {Uint8Array} input
|
|
169
|
+
* @param {number} target_width
|
|
170
|
+
* @param {string} filter
|
|
171
|
+
* @returns {Uint8Array}
|
|
172
|
+
*/
|
|
173
|
+
export function pmrem_hdr_resized_with_filter(input, target_width, filter) {
|
|
174
|
+
try {
|
|
175
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
176
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_export);
|
|
177
|
+
const len0 = WASM_VECTOR_LEN;
|
|
178
|
+
const ptr1 = passStringToWasm0(filter, wasm.__wbindgen_export, wasm.__wbindgen_export3);
|
|
179
|
+
const len1 = WASM_VECTOR_LEN;
|
|
180
|
+
wasm.pmrem_hdr_resized_with_filter(retptr, ptr0, len0, target_width, ptr1, len1);
|
|
181
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
182
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
183
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
184
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
185
|
+
if (r3) {
|
|
186
|
+
throw takeObject(r2);
|
|
187
|
+
}
|
|
188
|
+
var v3 = getArrayU8FromWasm0(r0, r1).slice();
|
|
189
|
+
wasm.__wbindgen_export2(r0, r1 * 1, 1);
|
|
190
|
+
return v3;
|
|
191
|
+
} finally {
|
|
192
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
86
196
|
/**
|
|
87
197
|
* Resize equirectangular EXR to target width (maintain aspect), returning EXR bytes.
|
|
88
198
|
* @param {Uint8Array} input
|
|
Binary file
|
package/dist/cache/cache.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { ExtensibleProperty } from "@gltf-transform/core";
|
|
4
|
-
import { Logger } from "@donmccurdy/caporal";
|
|
5
|
-
/**
|
|
6
|
-
* Clear the cache.
|
|
7
|
-
* This will remove all files in the cache directory.
|
|
8
|
-
*/
|
|
9
|
-
export declare function clearCache(logger?: Logger): void;
|
|
10
|
-
export declare const cacheSizeLimit: number;
|
|
11
|
-
/**
|
|
12
|
-
* Ensure that the cache size does not exceed the given maximum size in MB.
|
|
13
|
-
* @param maxSizeMB The maximum size in MB.
|
|
14
|
-
*/
|
|
15
|
-
export declare function limitCacheSize(maxSizeMB?: number): void;
|
|
16
|
-
/**
|
|
17
|
-
* Add data to the cache.
|
|
18
|
-
* @param key The key to store the data under.
|
|
19
|
-
* @param bytes The data to store as a Uint8Array.
|
|
20
|
-
*/
|
|
21
|
-
export declare function addToCache(key: string, bytes: Uint8Array | Buffer): void;
|
|
22
|
-
/**
|
|
23
|
-
* Try to get the data from the cache.
|
|
24
|
-
* @param key The key to look up.
|
|
25
|
-
* @returns The data as a Uint8Array or null if not found.
|
|
26
|
-
* @throws If the cache file is corrupted.
|
|
27
|
-
*/
|
|
28
|
-
export declare function tryGetFromCache(key: string): Uint8Array | null;
|
|
29
|
-
/** Add meta data to the cache.
|
|
30
|
-
* @param key The key to store the meta data for.
|
|
31
|
-
* @param meta The meta data object to store. It will be serialized to JSON and stored in a file with the key as the name with the extension ".meta".
|
|
32
|
-
*/
|
|
33
|
-
export declare function addMetaToCache(key: string, meta: object): void;
|
|
34
|
-
/** Try to get the meta data from the cache.
|
|
35
|
-
* @param key The key to look up.
|
|
36
|
-
* @param ignoreVersion If true, the version check is skipped. If false, the version must match the current build pipeline version.
|
|
37
|
-
* @returns The meta data object or null if not found.
|
|
38
|
-
*/
|
|
39
|
-
export declare function tryGetMetaFromCache(key: string, ignoreVersion?: boolean): object | null;
|
|
40
|
-
/**
|
|
41
|
-
* Get the cache key for a property.
|
|
42
|
-
* @param property The property to get the key for.
|
|
43
|
-
* @returns The key as a string.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getKey(property: ExtensibleProperty): string;
|
|
46
|
-
export declare function getKeyWithHash(property: ExtensibleProperty): {
|
|
47
|
-
key: string;
|
|
48
|
-
hash: string;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Get the hash for a property or an object.
|
|
52
|
-
* @param property The property to get the hash for.
|
|
53
|
-
* @param level The current level of recursion.
|
|
54
|
-
* @returns The hash as a number.
|
|
55
|
-
*/
|
|
56
|
-
export declare function getHash(property: ExtensibleProperty | object, level?: number): string;
|
|
57
|
-
export declare function hashBuffer(buffer: ArrayBufferLike, offset?: number, length?: number): number;
|
|
58
|
-
export declare function hashString(str: string): number;
|
package/dist/cache/cache.js
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import { ExtensibleProperty, Texture, Primitive, Accessor, Mesh } from "@gltf-transform/core";
|
|
2
|
-
import tmp from 'tmp';
|
|
3
|
-
import fs, { statSync } from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { getVersion } from "../utils/version.js";
|
|
6
|
-
// import * as CHECKDISCSPACE from 'check-disk-space'
|
|
7
|
-
import xxhash from "xxhash-wasm";
|
|
8
|
-
let xxHashModule = null;
|
|
9
|
-
xxhash().then(module => {
|
|
10
|
-
xxHashModule = module;
|
|
11
|
-
}).catch(() => { });
|
|
12
|
-
/**
|
|
13
|
-
* Get the available space on the cache directory in bytes.
|
|
14
|
-
*/
|
|
15
|
-
// export async function getCacheAvailableSpaceOnDisc(): Promise<number> {
|
|
16
|
-
// try {
|
|
17
|
-
// const dir = getCacheDirectory();
|
|
18
|
-
// const res = await CHECKDISCSPACE.default(dir).catch(() => { return { free: 0 } });
|
|
19
|
-
// return res.free;
|
|
20
|
-
// }
|
|
21
|
-
// catch (e) {
|
|
22
|
-
// console.error(`Error checking disk space: ${e}`);
|
|
23
|
-
// }
|
|
24
|
-
// return 0;
|
|
25
|
-
// }
|
|
26
|
-
const buildPipelineVersion = getVersion(false);
|
|
27
|
-
const debugLogs = process.argv.includes("--debug");
|
|
28
|
-
/**
|
|
29
|
-
* Clear the cache.
|
|
30
|
-
* This will remove all files in the cache directory.
|
|
31
|
-
*/
|
|
32
|
-
export function clearCache(logger) {
|
|
33
|
-
const dir = getCacheDirectory(true);
|
|
34
|
-
fs.rmSync(dir, { recursive: true });
|
|
35
|
-
if (!logger)
|
|
36
|
-
console.log(`Cleared cache at ${dir}`);
|
|
37
|
-
else
|
|
38
|
-
logger.info(`Cleared cache at ${dir}`);
|
|
39
|
-
}
|
|
40
|
-
export const cacheSizeLimit = 1024 * 5;
|
|
41
|
-
/**
|
|
42
|
-
* Ensure that the cache size does not exceed the given maximum size in MB.
|
|
43
|
-
* @param maxSizeMB The maximum size in MB.
|
|
44
|
-
*/
|
|
45
|
-
export function limitCacheSize(maxSizeMB = cacheSizeLimit) {
|
|
46
|
-
const dir = getCacheDirectory(true);
|
|
47
|
-
console.log(`Limit cache size to ${maxSizeMB.toFixed(2)} MB at ${dir}`);
|
|
48
|
-
let totalSize = 0;
|
|
49
|
-
const files = new Array();
|
|
50
|
-
function recurseDirectories(dir) {
|
|
51
|
-
fs.readdirSync(dir).forEach(file => {
|
|
52
|
-
const path = `${dir}/${file}`;
|
|
53
|
-
const stats = statSync(path);
|
|
54
|
-
if (stats.isDirectory()) {
|
|
55
|
-
recurseDirectories(path);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
totalSize += stats.size;
|
|
59
|
-
files.push({ path, size: stats.size });
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
recurseDirectories(dir);
|
|
64
|
-
const maxSizeInBytes = maxSizeMB * 1024 * 1024;
|
|
65
|
-
console.log(`Current cache size is ${(totalSize / (1024 * 1024)).toFixed(1)} MB`);
|
|
66
|
-
if (totalSize < maxSizeInBytes)
|
|
67
|
-
return;
|
|
68
|
-
files.sort((a, b) => {
|
|
69
|
-
const mtimeA = fs.statSync(a.path).mtimeMs;
|
|
70
|
-
const mtimeB = fs.statSync(b.path).mtimeMs;
|
|
71
|
-
return mtimeA - mtimeB;
|
|
72
|
-
});
|
|
73
|
-
const targetSize = maxSizeInBytes * 0.9;
|
|
74
|
-
// remove oldest files first
|
|
75
|
-
let filesRemoved = 0;
|
|
76
|
-
while (totalSize > targetSize) {
|
|
77
|
-
const file = files.shift();
|
|
78
|
-
if (!file)
|
|
79
|
-
break;
|
|
80
|
-
if (fs.statSync(file.path).isDirectory()) {
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
filesRemoved++;
|
|
84
|
-
fs.rmSync(file.path);
|
|
85
|
-
totalSize -= file.size;
|
|
86
|
-
}
|
|
87
|
-
console.log(`Cache size reduced to ${(totalSize / (1024 * 1024)).toFixed(1)} MB (${filesRemoved} files removed)`);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Add data to the cache.
|
|
91
|
-
* @param key The key to store the data under.
|
|
92
|
-
* @param bytes The data to store as a Uint8Array.
|
|
93
|
-
*/
|
|
94
|
-
export function addToCache(key, bytes) {
|
|
95
|
-
const dir = getCacheDirectory();
|
|
96
|
-
const path = `${dir}/${key}.bin`;
|
|
97
|
-
if (debugLogs)
|
|
98
|
-
console.log(`Added ${(bytes.byteLength / 1024).toFixed(1)} KB to cache at \"${path}\"`);
|
|
99
|
-
if (bytes instanceof Buffer)
|
|
100
|
-
bytes = new Uint8Array(bytes);
|
|
101
|
-
fs.writeFileSync(path, bytes);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Try to get the data from the cache.
|
|
105
|
-
* @param key The key to look up.
|
|
106
|
-
* @returns The data as a Uint8Array or null if not found.
|
|
107
|
-
* @throws If the cache file is corrupted.
|
|
108
|
-
*/
|
|
109
|
-
export function tryGetFromCache(key) {
|
|
110
|
-
const dir = getCacheDirectory();
|
|
111
|
-
const path = `${dir}/${key}.bin`;
|
|
112
|
-
if (fs.existsSync(path)) {
|
|
113
|
-
const bytes = fs.readFileSync(path);
|
|
114
|
-
if (bytes instanceof Buffer)
|
|
115
|
-
return new Uint8Array(bytes);
|
|
116
|
-
return bytes;
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
/** Add meta data to the cache.
|
|
121
|
-
* @param key The key to store the meta data for.
|
|
122
|
-
* @param meta The meta data object to store. It will be serialized to JSON and stored in a file with the key as the name with the extension ".meta".
|
|
123
|
-
*/
|
|
124
|
-
export function addMetaToCache(key, meta) {
|
|
125
|
-
const dir = getCacheDirectory();
|
|
126
|
-
const metaPath = `${dir}/${key}.meta`;
|
|
127
|
-
meta['needle-build-pipeline:version'] = buildPipelineVersion;
|
|
128
|
-
fs.writeFileSync(metaPath, JSON.stringify(meta));
|
|
129
|
-
}
|
|
130
|
-
/** Try to get the meta data from the cache.
|
|
131
|
-
* @param key The key to look up.
|
|
132
|
-
* @param ignoreVersion If true, the version check is skipped. If false, the version must match the current build pipeline version.
|
|
133
|
-
* @returns The meta data object or null if not found.
|
|
134
|
-
*/
|
|
135
|
-
export function tryGetMetaFromCache(key, ignoreVersion = false) {
|
|
136
|
-
try {
|
|
137
|
-
const dir = getCacheDirectory();
|
|
138
|
-
const path = `${dir}/${key}.meta`;
|
|
139
|
-
if (fs.existsSync(path)) {
|
|
140
|
-
const bytes = fs.readFileSync(path);
|
|
141
|
-
if (bytes?.length > 0) {
|
|
142
|
-
const text = bytes.toString('utf-8');
|
|
143
|
-
if (text) {
|
|
144
|
-
const obj = JSON.parse(text);
|
|
145
|
-
if (ignoreVersion)
|
|
146
|
-
return obj;
|
|
147
|
-
if (obj['needle-build-pipeline:version'] === buildPipelineVersion)
|
|
148
|
-
return obj;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
console.error(`Error reading cache meta: ${e.message}`);
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Get the cache key for a property.
|
|
161
|
-
* @param property The property to get the key for.
|
|
162
|
-
* @returns The key as a string.
|
|
163
|
-
*/
|
|
164
|
-
export function getKey(property) {
|
|
165
|
-
let prefix = "prop";
|
|
166
|
-
if (property instanceof Texture) {
|
|
167
|
-
prefix = "image";
|
|
168
|
-
}
|
|
169
|
-
let hash = getHash(property);
|
|
170
|
-
const key = `${prefix}-${hash}`;
|
|
171
|
-
return key;
|
|
172
|
-
}
|
|
173
|
-
export function getKeyWithHash(property) {
|
|
174
|
-
let prefix = "prop";
|
|
175
|
-
if (property instanceof Texture) {
|
|
176
|
-
prefix = "image";
|
|
177
|
-
}
|
|
178
|
-
let hash = getHash(property);
|
|
179
|
-
const key = `${prefix}-${hash}`;
|
|
180
|
-
return { key, hash };
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Get the hash for a property or an object.
|
|
184
|
-
* @param property The property to get the hash for.
|
|
185
|
-
* @param level The current level of recursion.
|
|
186
|
-
* @returns The hash as a number.
|
|
187
|
-
*/
|
|
188
|
-
export function getHash(property, level = 0) {
|
|
189
|
-
let hashStr = "";
|
|
190
|
-
let hash = 0;
|
|
191
|
-
if (property instanceof ExtensibleProperty) {
|
|
192
|
-
const extensions = property.listExtensions();
|
|
193
|
-
const extras = property.getExtras();
|
|
194
|
-
hash += hashObject({
|
|
195
|
-
extensions,
|
|
196
|
-
extras,
|
|
197
|
-
});
|
|
198
|
-
if (property instanceof Texture) {
|
|
199
|
-
const image = property.getImage();
|
|
200
|
-
const bytes = image?.buffer;
|
|
201
|
-
if (bytes)
|
|
202
|
-
hash += hashBuffer(bytes, image.byteOffset, image.byteLength);
|
|
203
|
-
}
|
|
204
|
-
else if (property instanceof Mesh) {
|
|
205
|
-
const weights = property.getWeights();
|
|
206
|
-
hash += hashObject(weights);
|
|
207
|
-
const primitives = property.listPrimitives();
|
|
208
|
-
for (const prim of primitives) {
|
|
209
|
-
hash += hashString(getHash(prim, level + 1));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else if (property instanceof Primitive) {
|
|
213
|
-
const indices = property.getIndices();
|
|
214
|
-
const attributes = property.listAttributes();
|
|
215
|
-
const targets = property.listTargets();
|
|
216
|
-
// TODO: hash buffer view if possible
|
|
217
|
-
const semantics = property.listSemantics();
|
|
218
|
-
const semanticsNames = semantics.map(s => {
|
|
219
|
-
return {
|
|
220
|
-
name: s,
|
|
221
|
-
};
|
|
222
|
-
});
|
|
223
|
-
hash += hashObject({
|
|
224
|
-
indices,
|
|
225
|
-
attributes,
|
|
226
|
-
targets,
|
|
227
|
-
semantics: semanticsNames
|
|
228
|
-
});
|
|
229
|
-
if (indices) {
|
|
230
|
-
const indexBuffer = indices.getArray();
|
|
231
|
-
if (indexBuffer) {
|
|
232
|
-
hash += hashBuffer(indexBuffer.buffer, indexBuffer.byteOffset, indexBuffer.byteLength);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// We can not pass the whole buffer into hashObject since very large meshes will cause errors when trying to stringify
|
|
236
|
-
// See https://linear.app/needle/issue/NE-6414
|
|
237
|
-
for (const sem of semantics) {
|
|
238
|
-
const arr = property.getAttribute(sem)?.getArray();
|
|
239
|
-
if (arr) {
|
|
240
|
-
hash += hashBuffer(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
hash += hashObject(property);
|
|
247
|
-
}
|
|
248
|
-
return hashStr + hash;
|
|
249
|
-
}
|
|
250
|
-
const cleanBuildPipelineVersion = getVersion(false).replace(/[^a-zA-Z0-9]/g, "_");
|
|
251
|
-
function getCacheDirectory(root) {
|
|
252
|
-
const tmpDir = path.join(tmp.tmpdir, "Needle", "build-pipeline-cache", root ? "" : cleanBuildPipelineVersion);
|
|
253
|
-
if (!fs.existsSync(tmpDir)) {
|
|
254
|
-
fs.mkdirSync(tmpDir, { recursive: true });
|
|
255
|
-
}
|
|
256
|
-
return tmpDir;
|
|
257
|
-
}
|
|
258
|
-
function hashObject(obj, depth = 0) {
|
|
259
|
-
if (obj instanceof Accessor) {
|
|
260
|
-
const buffer = obj.getArray();
|
|
261
|
-
return hashBuffer(buffer.buffer);
|
|
262
|
-
}
|
|
263
|
-
else if (obj == null) {
|
|
264
|
-
return 0;
|
|
265
|
-
}
|
|
266
|
-
if (typeof obj !== 'object') {
|
|
267
|
-
return hashString(String(obj));
|
|
268
|
-
}
|
|
269
|
-
try {
|
|
270
|
-
const seen = new WeakSet();
|
|
271
|
-
const str = JSON.stringify(obj, (_key, value) => {
|
|
272
|
-
if (typeof value === 'object' && value !== null) {
|
|
273
|
-
if (seen.has(value))
|
|
274
|
-
return undefined;
|
|
275
|
-
seen.add(value);
|
|
276
|
-
}
|
|
277
|
-
if (typeof value === 'function')
|
|
278
|
-
return undefined;
|
|
279
|
-
return value;
|
|
280
|
-
});
|
|
281
|
-
return hashString(str);
|
|
282
|
-
}
|
|
283
|
-
catch (err) {
|
|
284
|
-
console.warn("WARN: [Cache] error during hashing of object:\n" + err);
|
|
285
|
-
if (debugLogs)
|
|
286
|
-
debugger;
|
|
287
|
-
let fallbackHash = 0;
|
|
288
|
-
if (typeof obj === 'object' && obj !== null) {
|
|
289
|
-
for (const key in obj) {
|
|
290
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
291
|
-
const value = obj[key];
|
|
292
|
-
fallbackHash += hashString(key);
|
|
293
|
-
if (typeof value === 'object' && value !== null) {
|
|
294
|
-
if (depth > 10) {
|
|
295
|
-
fallbackHash += hashString("[object]");
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
fallbackHash += hashObject(value, depth + 1);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
fallbackHash += hashString(String(value));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
return fallbackHash;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
export function hashBuffer(buffer, offset, length) {
|
|
311
|
-
if (xxHashModule) {
|
|
312
|
-
const view = new Uint8Array(buffer, offset, length);
|
|
313
|
-
return xxHashModule.h32Raw(view);
|
|
314
|
-
}
|
|
315
|
-
let hash = 0;
|
|
316
|
-
const view = new Uint8Array(buffer, offset, length);
|
|
317
|
-
for (let i = 0; i < view.length; i++) {
|
|
318
|
-
hash = ((hash << 5) - hash) + view[i];
|
|
319
|
-
hash |= 0;
|
|
320
|
-
}
|
|
321
|
-
return hash;
|
|
322
|
-
}
|
|
323
|
-
export function hashString(str) {
|
|
324
|
-
let hash = 0;
|
|
325
|
-
for (let i = 0; i < str.length; i++) {
|
|
326
|
-
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
|
327
|
-
hash |= 0;
|
|
328
|
-
}
|
|
329
|
-
return hash;
|
|
330
|
-
}
|
package/dist/cache/index.d.ts
DELETED
package/dist/cache/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ILogger } from '@gltf-transform/core';
|
|
2
|
-
import { Config } from '../config/index.js';
|
|
3
|
-
interface JobCacheOptions {
|
|
4
|
-
compress: boolean;
|
|
5
|
-
progressive: boolean;
|
|
6
|
-
config: Config;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Compute a job cache key from pipeline options and input file content.
|
|
10
|
-
* The key uniquely identifies a specific input + configuration combination.
|
|
11
|
-
* Currently only supports .glb files (hashes the full file content).
|
|
12
|
-
* @returns The job key string, or null if the file format is not supported.
|
|
13
|
-
*/
|
|
14
|
-
export declare function computeJobKey(options: JobCacheOptions, inputFilePath: string): string | null;
|
|
15
|
-
/**
|
|
16
|
-
* Save the result of a completed job to the cache.
|
|
17
|
-
* Stores the content of each output file and a manifest linking them.
|
|
18
|
-
*/
|
|
19
|
-
export declare function saveJobResult(jobKey: string, outputFiles: string[], logger: ILogger): void;
|
|
20
|
-
/**
|
|
21
|
-
* Try to restore a previously cached job result.
|
|
22
|
-
* Loads all cached files into memory first, then writes them only if all are available.
|
|
23
|
-
* Returns the list of restored file paths, or null if the cache is incomplete.
|
|
24
|
-
*/
|
|
25
|
-
export declare function tryRestoreJobResult(jobKey: string, outputDir: string, logger: ILogger): string[] | null;
|
|
26
|
-
export {};
|