@needle-tools/gltf-build-pipeline 2.16.0-next.eb5a640 → 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 +13 -1
- package/dist/cli/index.js +4154 -258
- 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 -59
- package/dist/cache/cache.js +0 -350
- package/dist/cache/index.d.ts +0 -2
- package/dist/cache/index.js +0 -2
- package/dist/cache/job-cache.d.ts +0 -28
- package/dist/cache/job-cache.js +0 -86
- package/dist/cli/index.d.ts +0 -2
- package/dist/config/index.d.ts +0 -64
- package/dist/config/index.js +0 -161
- 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 -1078
- package/dist/extensions/NEEDLE_opaque/index.d.ts +0 -2
- 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 -19
- package/dist/scripts/pack-gltf.js +0 -187
- package/dist/scripts/stats.d.ts +0 -5
- package/dist/scripts/stats.js +0 -20
- package/dist/transforms/index.d.ts +0 -12
- package/dist/transforms/index.js +0 -12
- 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_audio.d.ts +0 -12
- package/dist/transforms/needle_audio.js +0 -104
- package/dist/transforms/needle_audio_ffmpeg.d.ts +0 -14
- package/dist/transforms/needle_audio_ffmpeg.js +0 -51
- package/dist/transforms/needle_audio_registry.d.ts +0 -38
- package/dist/transforms/needle_audio_registry.js +0 -47
- 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 -53
- package/dist/transforms/needle_progressive.js +0 -1117
- package/dist/transforms/needle_texture_transform.d.ts +0 -15
- package/dist/transforms/needle_texture_transform.js +0 -271
- 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 -208
- 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 -9
- package/dist/utils/index.js +0 -9
- 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 -273
- 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 -9
- package/dist/utils/validate.js +0 -24
- 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/dist/cache/job-cache.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// TODO: avoid storing LOD files twice in cache. Currently LODs are stored by the per-asset cache
|
|
2
|
-
// (e.g. "image-{hash}", "packed-{hash}") AND again by the job cache ("job-{key}-fN").
|
|
3
|
-
// Instead, progressive_results should carry { path, cacheKey? } so the job manifest can reference
|
|
4
|
-
// existing per-asset cache keys for LODs and only store the main GLB under a job-specific key.
|
|
5
|
-
// This requires threading cache key collection through make_progressive and packGLTF.
|
|
6
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { addMetaToCache, addToCache, tryGetFromCache, tryGetMetaFromCache, hashBuffer, hashString } from './cache.js';
|
|
9
|
-
/**
|
|
10
|
-
* Compute a job cache key from pipeline options and input file content.
|
|
11
|
-
* The key uniquely identifies a specific input + configuration combination.
|
|
12
|
-
* Currently only supports .glb files (hashes the full file content).
|
|
13
|
-
* @returns The job key string, or null if the file format is not supported.
|
|
14
|
-
*/
|
|
15
|
-
// TODO: add support for .gltf files (need to hash referenced .bin files as well)
|
|
16
|
-
export function computeJobKey(options, inputFilePath) {
|
|
17
|
-
if (!inputFilePath.endsWith('.glb'))
|
|
18
|
-
return null;
|
|
19
|
-
const fileBytes = readFileSync(inputFilePath);
|
|
20
|
-
const fileHash = hashBuffer(fileBytes.buffer, fileBytes.byteOffset, fileBytes.byteLength);
|
|
21
|
-
const optionsStr = JSON.stringify({
|
|
22
|
-
compress: options.compress,
|
|
23
|
-
progressive: options.progressive,
|
|
24
|
-
config: options.config,
|
|
25
|
-
});
|
|
26
|
-
const optionsHash = hashString(optionsStr);
|
|
27
|
-
return `job-${optionsHash}-${fileHash}`;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Save the result of a completed job to the cache.
|
|
31
|
-
* Stores the content of each output file and a manifest linking them.
|
|
32
|
-
* The caller should include all output files including external sidecar files
|
|
33
|
-
* (e.g. .pmrem.ktx2) collected via PackGLTFOptions.externalFiles.
|
|
34
|
-
*/
|
|
35
|
-
export function saveJobResult(jobKey, outputFiles, logger) {
|
|
36
|
-
const entries = [];
|
|
37
|
-
for (let i = 0; i < outputFiles.length; i++) {
|
|
38
|
-
const filePath = outputFiles[i];
|
|
39
|
-
if (!existsSync(filePath))
|
|
40
|
-
continue;
|
|
41
|
-
const cacheKey = `${jobKey}-f${i}`;
|
|
42
|
-
const content = readFileSync(filePath);
|
|
43
|
-
addToCache(cacheKey, content);
|
|
44
|
-
entries.push({
|
|
45
|
-
fileName: path.basename(filePath),
|
|
46
|
-
cacheKey,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
if (entries.length === 0)
|
|
50
|
-
return;
|
|
51
|
-
const manifest = { entries };
|
|
52
|
-
addMetaToCache(jobKey, manifest);
|
|
53
|
-
logger.debug(`[Job Cache] Saved ${entries.length} file(s) for job ${jobKey}`);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Try to restore a previously cached job result.
|
|
57
|
-
* Loads all cached files into memory first, then writes them only if all are available.
|
|
58
|
-
* Returns the list of restored file paths, or null if the cache is incomplete.
|
|
59
|
-
*/
|
|
60
|
-
export function tryRestoreJobResult(jobKey, outputDir, logger) {
|
|
61
|
-
const manifest = tryGetMetaFromCache(jobKey);
|
|
62
|
-
if (!manifest?.entries?.length)
|
|
63
|
-
return null;
|
|
64
|
-
// Load all entries into memory — fail fast if any are missing
|
|
65
|
-
const loaded = [];
|
|
66
|
-
for (const entry of manifest.entries) {
|
|
67
|
-
const cached = tryGetFromCache(entry.cacheKey);
|
|
68
|
-
if (!cached) {
|
|
69
|
-
logger.debug(`[Job Cache] Cache miss: missing entry ${entry.cacheKey}`);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
loaded.push({ entry, data: cached });
|
|
73
|
-
}
|
|
74
|
-
// All entries present — write to output directory
|
|
75
|
-
if (!existsSync(outputDir)) {
|
|
76
|
-
mkdirSync(outputDir, { recursive: true });
|
|
77
|
-
}
|
|
78
|
-
const restoredPaths = [];
|
|
79
|
-
for (const { entry, data } of loaded) {
|
|
80
|
-
const outPath = path.join(outputDir, entry.fileName);
|
|
81
|
-
writeFileSync(outPath, data);
|
|
82
|
-
restoredPaths.push(outPath);
|
|
83
|
-
}
|
|
84
|
-
logger.info(`[Job Cache] Restored ${restoredPaths.length} file(s) from cache`);
|
|
85
|
-
return restoredPaths;
|
|
86
|
-
}
|
package/dist/cli/index.d.ts
DELETED
package/dist/config/index.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ILogger } from "@gltf-transform/core";
|
|
2
|
-
declare type Usecase = "default" | "product" | "world";
|
|
3
|
-
export declare const UsecaseOptions: string[];
|
|
4
|
-
/**
|
|
5
|
-
* The config object contains information about how a file should be processed.
|
|
6
|
-
*/
|
|
7
|
-
export type Config = {
|
|
8
|
-
/** High-level configuration */
|
|
9
|
-
usecase: Usecase;
|
|
10
|
-
textures?: {
|
|
11
|
-
lods: boolean;
|
|
12
|
-
};
|
|
13
|
-
meshes?: {
|
|
14
|
-
lods: boolean;
|
|
15
|
-
};
|
|
16
|
-
audio?: {
|
|
17
|
-
/** Enable Opus/Ogg compression of externally referenced audio files. Default: true. */
|
|
18
|
-
enabled?: boolean;
|
|
19
|
-
/** Opus encoding bitrate in kbps. Default: 64. */
|
|
20
|
-
bitrate?: number;
|
|
21
|
-
};
|
|
22
|
-
exr?: {
|
|
23
|
-
/** Enable EXR -> KTX2 HDR conversion via PMREM. When false, EXR textures (bundled or
|
|
24
|
-
* externally referenced) are left untouched. Default: true. */
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Create a config object with the given usecase.
|
|
30
|
-
*/
|
|
31
|
-
export declare function createConfig(usecase: string): {
|
|
32
|
-
usecase: Usecase;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Get the config object either provided by a CLI path or a needle.config.json file in the parent directory.
|
|
36
|
-
*
|
|
37
|
-
* @example CLI argument where the path points to a json file containing the config as `Config`
|
|
38
|
-
* ```sh
|
|
39
|
-
* node script.js --config path/to/my-optimization-config.json
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @example needle.config.json - the usecase can be provided as a string
|
|
43
|
-
* ```json
|
|
44
|
-
* {
|
|
45
|
-
* "optimization": "product"
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @example needle.config.json - the whole config object can be provided
|
|
50
|
-
* ```json
|
|
51
|
-
* {
|
|
52
|
-
* "optimization": {
|
|
53
|
-
* "usecase": "product"
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
export declare function getConfig(configPath?: string, fallbackSearchDirectory?: string, opts?: {
|
|
61
|
-
logger: ILogger;
|
|
62
|
-
}): Config;
|
|
63
|
-
export declare function searchConfig(directory: string, logger: ILogger): Config | null;
|
|
64
|
-
export {};
|
package/dist/config/index.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { Logger, Verbosity } from "@gltf-transform/core";
|
|
2
|
-
import { existsSync, readFileSync, statSync } from "fs";
|
|
3
|
-
import path, { dirname, resolve } from "path";
|
|
4
|
-
export const UsecaseOptions = ["product", "world"];
|
|
5
|
-
const defaultConfig = {
|
|
6
|
-
usecase: "default",
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Create a config object with the given usecase.
|
|
10
|
-
*/
|
|
11
|
-
export function createConfig(usecase) {
|
|
12
|
-
if (!UsecaseOptions.includes(usecase)) {
|
|
13
|
-
throw new Error(`Invalid usecase: \"${usecase}\". Valid usecases: ${UsecaseOptions.join(", ")}`);
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
usecase: usecase
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Get the config object either provided by a CLI path or a needle.config.json file in the parent directory.
|
|
21
|
-
*
|
|
22
|
-
* @example CLI argument where the path points to a json file containing the config as `Config`
|
|
23
|
-
* ```sh
|
|
24
|
-
* node script.js --config path/to/my-optimization-config.json
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @example needle.config.json - the usecase can be provided as a string
|
|
28
|
-
* ```json
|
|
29
|
-
* {
|
|
30
|
-
* "optimization": "product"
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @example needle.config.json - the whole config object can be provided
|
|
35
|
-
* ```json
|
|
36
|
-
* {
|
|
37
|
-
* "optimization": {
|
|
38
|
-
* "usecase": "product"
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
export function getConfig(configPath, fallbackSearchDirectory, opts) {
|
|
46
|
-
let logger = opts?.logger;
|
|
47
|
-
if (!logger) {
|
|
48
|
-
logger = new Logger(Verbosity.WARN);
|
|
49
|
-
}
|
|
50
|
-
if (configPath != null) {
|
|
51
|
-
configPath = resolve(process.cwd(), configPath);
|
|
52
|
-
if (!existsSync(configPath)) {
|
|
53
|
-
throw new Error(`No config found at \"${configPath}\"`);
|
|
54
|
-
}
|
|
55
|
-
const isDirectory = statSync(configPath).isDirectory();
|
|
56
|
-
if (isDirectory) {
|
|
57
|
-
const res = searchConfig(configPath, logger);
|
|
58
|
-
if (res) {
|
|
59
|
-
return res;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw new Error(`No config found in directory \"${configPath}\"`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const res = resolveConfig(configPath, readFileSync(configPath, "utf8"), logger);
|
|
66
|
-
if (res) {
|
|
67
|
-
return res;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
throw new Error(`Failed parsing config at \"${configPath}\"`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Always return a fresh shallow copy. Callers (notably the CLI) mutate the
|
|
74
|
-
// returned object (`config.usecase = ...`); returning the cache by reference
|
|
75
|
-
// would let those mutations poison subsequent getConfig() calls.
|
|
76
|
-
if (_cachedConfig !== undefined) {
|
|
77
|
-
return { ..._cachedConfig };
|
|
78
|
-
}
|
|
79
|
-
// Resolve the config once and cache it
|
|
80
|
-
// Check if a needle.config.json exists in the directory from which the script is run (or any parent directory)
|
|
81
|
-
if (fallbackSearchDirectory) {
|
|
82
|
-
const result = searchConfig(fallbackSearchDirectory, logger);
|
|
83
|
-
if (result) {
|
|
84
|
-
_cachedConfig = { ...defaultConfig, ...result };
|
|
85
|
-
logger.info(`Using config with usecase: ${_cachedConfig.usecase}`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// If no config was found, use the default config. Store a copy in the cache
|
|
89
|
-
// so we never alias defaultConfig directly — that way even if a downstream
|
|
90
|
-
// bug ever returned the cache by reference, defaultConfig itself stays clean.
|
|
91
|
-
if (!_cachedConfig) {
|
|
92
|
-
logger.debug("No config found. Using default config.");
|
|
93
|
-
_cachedConfig = { ...defaultConfig };
|
|
94
|
-
}
|
|
95
|
-
return { ..._cachedConfig };
|
|
96
|
-
}
|
|
97
|
-
let _cachedConfig = undefined;
|
|
98
|
-
export function searchConfig(directory, logger) {
|
|
99
|
-
if (statSync(directory).isFile()) {
|
|
100
|
-
directory = dirname(directory);
|
|
101
|
-
}
|
|
102
|
-
directory = directory.replaceAll("\\", "/");
|
|
103
|
-
while (directory.length > 0) {
|
|
104
|
-
const configPath = path.join(directory, "needle.config.json");
|
|
105
|
-
if (existsSync(configPath)) {
|
|
106
|
-
const content = readFileSync(configPath, "utf8");
|
|
107
|
-
const config = resolveConfig(configPath, content, logger);
|
|
108
|
-
if (config) {
|
|
109
|
-
return config;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const lastSlash = directory.lastIndexOf("/");
|
|
113
|
-
if (lastSlash < 0) {
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
directory = directory.slice(0, lastSlash);
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
const loggedConfigPaths = new Set();
|
|
121
|
-
function resolveConfig(filename, content, logger) {
|
|
122
|
-
// Handle config being part of `needle.config.json`
|
|
123
|
-
if (filename.endsWith("needle.config.json")) {
|
|
124
|
-
try {
|
|
125
|
-
const config = JSON.parse(content);
|
|
126
|
-
if (config.gltf) {
|
|
127
|
-
logger.info(`Found \"gltf\" config at \"${filename.replaceAll("\\", "/")}\".`);
|
|
128
|
-
// If the optimization config is a string, it's the usecase
|
|
129
|
-
if (typeof config.gltf === "string") {
|
|
130
|
-
return createConfig(config.gltf);
|
|
131
|
-
}
|
|
132
|
-
return config.gltf;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
if (!loggedConfigPaths.has(filename)) {
|
|
136
|
-
logger.debug(`No \"gltf\" config found in needle.config.json at \"${filename.replaceAll("\\", "/")}\". You may add a \"gltf\" field to the config with the optimization config. Example: { \"gltf\": { \"usecase\": \"product\" } }. Using default config for glTF optimization now.`);
|
|
137
|
-
loggedConfigPaths.add(filename);
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
catch (err) {
|
|
143
|
-
logger.error(`Failed parsing config \"${err.message}\" at ${filename.replaceAll("\\", "/")}`);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Handle config being the content of the file
|
|
147
|
-
else if (content.trimStart().startsWith("{")) {
|
|
148
|
-
try {
|
|
149
|
-
return JSON.parse(content);
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
if (err instanceof Error)
|
|
153
|
-
logger.error(`Failed parsing config \"${err.message}\" at ${filename.replaceAll("\\", "/")}`);
|
|
154
|
-
else
|
|
155
|
-
logger.error(`Failed parsing config \"${err}\" at ${filename.replaceAll("\\", "/")}`);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
logger.error("Invalid config file format. Expected JSON object at " + filename.replaceAll("\\", "/"));
|
|
160
|
-
}
|
|
161
|
-
}
|
package/dist/constants.d.ts
DELETED
package/dist/constants.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Extension, ExtensionProperty, PropertyType, ReaderContext, WriterContext } from "@gltf-transform/core";
|
|
2
|
-
export declare const EXTENSION_NAME = "NEEDLE_compression_texture";
|
|
3
|
-
export declare interface NEEDLE_compression_texture_schema {
|
|
4
|
-
mode: "none" | "auto" | "webp" | "UASTC" | "ETC1S" | "world" | "product";
|
|
5
|
-
slot: string;
|
|
6
|
-
/** quality in range of 0 - 1 */
|
|
7
|
-
quality: number;
|
|
8
|
-
maxSize: number;
|
|
9
|
-
}
|
|
10
|
-
export declare class NEEDLE_compression_texture extends Extension {
|
|
11
|
-
static EXTENSION_NAME: string;
|
|
12
|
-
extensionName: string;
|
|
13
|
-
create(toktxInfo: NEEDLE_compression_texture_schema): NEEDLE_compression_texture_property;
|
|
14
|
-
read(context: ReaderContext): this;
|
|
15
|
-
write(context: WriterContext): this;
|
|
16
|
-
}
|
|
17
|
-
export declare class NEEDLE_compression_texture_property extends ExtensionProperty {
|
|
18
|
-
static EXTENSION_NAME: string;
|
|
19
|
-
extensionName: string;
|
|
20
|
-
parentTypes: PropertyType[];
|
|
21
|
-
propertyType: any;
|
|
22
|
-
init(): void;
|
|
23
|
-
model: NEEDLE_compression_texture_schema;
|
|
24
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Extension, ExtensionProperty, PropertyType } from "@gltf-transform/core";
|
|
2
|
-
import { getTextureDefinition } from "../utils.js";
|
|
3
|
-
export const EXTENSION_NAME = "NEEDLE_compression_texture";
|
|
4
|
-
const debugLog = false;
|
|
5
|
-
export class NEEDLE_compression_texture extends Extension {
|
|
6
|
-
static EXTENSION_NAME = EXTENSION_NAME;
|
|
7
|
-
extensionName = EXTENSION_NAME;
|
|
8
|
-
create(toktxInfo) {
|
|
9
|
-
const ext = new NEEDLE_compression_texture_property(this.document.getGraph(), "");
|
|
10
|
-
ext.model = toktxInfo;
|
|
11
|
-
return ext;
|
|
12
|
-
}
|
|
13
|
-
read(context) {
|
|
14
|
-
if (debugLog)
|
|
15
|
-
console.log("READ " + EXTENSION_NAME);
|
|
16
|
-
if (!context.jsonDoc.json.textures)
|
|
17
|
-
return this;
|
|
18
|
-
context.textures?.forEach((tex, _) => {
|
|
19
|
-
const textureDefinition = getTextureDefinition(context, tex);
|
|
20
|
-
if (textureDefinition?.extensions && textureDefinition.extensions[EXTENSION_NAME]) {
|
|
21
|
-
const prop = new NEEDLE_compression_texture_property(this.document.getGraph(), EXTENSION_NAME);
|
|
22
|
-
prop.model = textureDefinition.extensions[EXTENSION_NAME];
|
|
23
|
-
tex.setExtension(EXTENSION_NAME, prop);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
write(context) {
|
|
29
|
-
if (debugLog)
|
|
30
|
-
console.log("WRITE " + EXTENSION_NAME);
|
|
31
|
-
const root = this.document.getRoot();
|
|
32
|
-
const textures = root.listTextures();
|
|
33
|
-
for (const tex of textures) {
|
|
34
|
-
const ext = tex.getExtension(EXTENSION_NAME);
|
|
35
|
-
if (ext) {
|
|
36
|
-
const def = getTextureDefinition(context, tex);
|
|
37
|
-
if (def) {
|
|
38
|
-
def.extensions = def.extensions || {};
|
|
39
|
-
def.extensions[EXTENSION_NAME] = ext.model;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export class NEEDLE_compression_texture_property extends ExtensionProperty {
|
|
47
|
-
static EXTENSION_NAME = EXTENSION_NAME;
|
|
48
|
-
init() {
|
|
49
|
-
this.extensionName = EXTENSION_NAME;
|
|
50
|
-
this.parentTypes = [PropertyType.TEXTURE];
|
|
51
|
-
this.propertyType = EXTENSION_NAME;
|
|
52
|
-
}
|
|
53
|
-
model;
|
|
54
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./NEEDLE_compression_texture.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./NEEDLE_compression_texture.js";
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Extension, PropertyType, ReaderContext, WriterContext } from '@gltf-transform/core';
|
|
2
|
-
/**
|
|
3
|
-
* NEEDLE_lightmaps gltf-transform extension.
|
|
4
|
-
*
|
|
5
|
-
* Handles both embedded (`/textures/N` pointer) and external (`sunrise.exr` pointer) lightmaps.
|
|
6
|
-
*
|
|
7
|
-
* - **preread(TEXTURE)**: Injects external EXR files into the JSON document so the core reader
|
|
8
|
-
* creates proper Texture objects from them.
|
|
9
|
-
* - **read()**: Resolves `/textures/N` pointers to Texture objects. Sets references so that
|
|
10
|
-
* gltf-transform doesn't prune/dedup referenced textures.
|
|
11
|
-
* - **write()**: Updates pointer strings:
|
|
12
|
-
* - Embedded textures: resolves to the new `/textures/N` index in the output.
|
|
13
|
-
* - External textures: uses the Texture's current URI (e.g. updated by PMREM to `.pmrem.ktx2`).
|
|
14
|
-
*/
|
|
15
|
-
export declare class NEEDLE_lightmaps_ext extends Extension {
|
|
16
|
-
static readonly EXTENSION_NAME = "NEEDLE_lightmaps";
|
|
17
|
-
readonly extensionName = "NEEDLE_lightmaps";
|
|
18
|
-
readonly prereadTypes: PropertyType[];
|
|
19
|
-
readonly prewriteTypes: PropertyType[];
|
|
20
|
-
/** The raw extension JSON from the input (mutated in-place during write) */
|
|
21
|
-
private extensionData;
|
|
22
|
-
/** Entries with resolved Texture references */
|
|
23
|
-
private resolved;
|
|
24
|
-
/** Image indices injected during preread (for external EXR files) */
|
|
25
|
-
private injectedImageIndices;
|
|
26
|
-
/** The ExtensionProperty that holds references to prevent dedup/prune */
|
|
27
|
-
private lightmapProp;
|
|
28
|
-
preread(context: ReaderContext, _propertyType: PropertyType): this;
|
|
29
|
-
read(context: ReaderContext): this;
|
|
30
|
-
prewrite(context: WriterContext, _propertyType: PropertyType): this;
|
|
31
|
-
write(context: WriterContext): this;
|
|
32
|
-
private pointersResolved;
|
|
33
|
-
private resolvePointers;
|
|
34
|
-
/**
|
|
35
|
-
* Find (or create) a texture def in the output JSON that references the given Texture.
|
|
36
|
-
* This replicates the logic from the opaque system's TextureIndexResolver.
|
|
37
|
-
*/
|
|
38
|
-
private findOrCreateTextureIndex;
|
|
39
|
-
}
|