@needle-tools/gltf-build-pipeline 2.4.0 → 2.5.0-beta
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/dist/cache/cache.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
1
2
|
import { ExtensibleProperty } from "@gltf-transform/core";
|
|
2
3
|
import { Logger } from "@donmccurdy/caporal";
|
|
3
4
|
/**
|
|
@@ -16,7 +17,7 @@ export declare function limitCacheSize(maxSizeMB?: number): void;
|
|
|
16
17
|
* @param key The key to store the data under.
|
|
17
18
|
* @param bytes The data to store as a Uint8Array.
|
|
18
19
|
*/
|
|
19
|
-
export declare function addToCache(key: string, bytes: Uint8Array): void;
|
|
20
|
+
export declare function addToCache(key: string, bytes: Uint8Array | Buffer): void;
|
|
20
21
|
/**
|
|
21
22
|
* Try to get the data from the cache.
|
|
22
23
|
* @param key The key to look up.
|
package/dist/cache/cache.js
CHANGED
|
@@ -91,6 +91,8 @@ export function addToCache(key, bytes) {
|
|
|
91
91
|
const path = `${dir}/${key}.bin`;
|
|
92
92
|
if (debugLogs)
|
|
93
93
|
console.log(`Added ${(bytes.byteLength / 1024).toFixed(1)} KB to cache at \"${path}\"`);
|
|
94
|
+
if (bytes instanceof Buffer)
|
|
95
|
+
bytes = new Uint8Array(bytes);
|
|
94
96
|
fs.writeFileSync(path, bytes);
|
|
95
97
|
}
|
|
96
98
|
/**
|
|
@@ -104,6 +106,8 @@ export function tryGetFromCache(key) {
|
|
|
104
106
|
const path = `${dir}/${key}.bin`;
|
|
105
107
|
if (fs.existsSync(path)) {
|
|
106
108
|
const bytes = fs.readFileSync(path);
|
|
109
|
+
if (bytes instanceof Buffer)
|
|
110
|
+
return new Uint8Array(bytes);
|
|
107
111
|
return bytes;
|
|
108
112
|
}
|
|
109
113
|
return null;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Document, Transform } from '@gltf-transform/core';
|
|
2
|
-
export declare function writeNeedleAsset(document: Document): void;
|
|
2
|
+
export declare function writeNeedleAsset(document: Document, metadata?: Record<string, object | string | number | boolean>): void;
|
|
3
3
|
export declare function needle_asset(): Transform;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createTransform } from '@gltf-transform/functions';
|
|
2
2
|
import { getVersion } from '../index.js';
|
|
3
3
|
const generatorName = "Needle Build Pipeline";
|
|
4
|
-
export function writeNeedleAsset(document) {
|
|
4
|
+
export function writeNeedleAsset(document, metadata) {
|
|
5
5
|
const root = document.getRoot();
|
|
6
6
|
const asset = root.getAsset();
|
|
7
7
|
if (asset) {
|
|
8
8
|
asset.extras = writeNeedleExtras(asset.extras);
|
|
9
|
+
if (metadata)
|
|
10
|
+
asset.extras = Object.assign(asset.extras, metadata);
|
|
9
11
|
const version = getVersion();
|
|
10
12
|
asset.generator = generatorName;
|
|
11
13
|
if (version?.length > 0) {
|
|
@@ -218,7 +218,8 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
|
|
|
218
218
|
const level = LOD_LEVEL[i];
|
|
219
219
|
const lodResult = await createTextureLod({
|
|
220
220
|
doc,
|
|
221
|
-
|
|
221
|
+
inputFilepath: filePath,
|
|
222
|
+
inputFilename: filename,
|
|
222
223
|
basePath: textureLodBasePath,
|
|
223
224
|
level: i,
|
|
224
225
|
texture,
|
|
@@ -269,11 +270,15 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
|
|
|
269
270
|
});
|
|
270
271
|
}
|
|
271
272
|
async function createTextureLod(args, opts) {
|
|
272
|
-
const { doc, file, basePath, level, texture, guid, textureIndex } = args;
|
|
273
|
+
const { doc, inputFilepath: file, basePath, level, texture, guid, textureIndex } = args;
|
|
273
274
|
let slots = args.slots;
|
|
274
275
|
const logger = doc.getLogger();
|
|
275
276
|
const newDoc = new Document();
|
|
276
|
-
writeNeedleAsset(newDoc
|
|
277
|
+
writeNeedleAsset(newDoc, {
|
|
278
|
+
source: {
|
|
279
|
+
filename: args.inputFilename
|
|
280
|
+
}
|
|
281
|
+
});
|
|
277
282
|
const scene = newDoc.createScene();
|
|
278
283
|
const buffer = newDoc.createBuffer();
|
|
279
284
|
// add texture
|
|
@@ -593,7 +598,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
593
598
|
const lod = LODS[level];
|
|
594
599
|
const guid = settings.guid;
|
|
595
600
|
// TODO: check if the LOD level did actually change the mesh - otherwise we can just skip generating lower resolutions
|
|
596
|
-
const lodTask = createMeshLod(doc, outputDirectory, level, mesh, originalMeshInformation, guid, lod, opts);
|
|
601
|
+
const lodTask = createMeshLod(filename, doc, outputDirectory, level, mesh, originalMeshInformation, guid, lod, opts);
|
|
597
602
|
lodTask.then(res => {
|
|
598
603
|
if (res?.success) {
|
|
599
604
|
generatedLODInfos[level] = res;
|
|
@@ -773,7 +778,7 @@ function setPrimitiveData(prim, data) {
|
|
|
773
778
|
* @param guid a unique identifier for the mesh
|
|
774
779
|
* @param error the error to use for simplification. Higher means more simplification
|
|
775
780
|
*/
|
|
776
|
-
async function createMeshLod(doc, basePath, level, mesh, meshInfo, guid, lodLevel, opts) {
|
|
781
|
+
async function createMeshLod(inputFileName, doc, basePath, level, mesh, meshInfo, guid, lodLevel, opts) {
|
|
777
782
|
const logger = doc.getLogger();
|
|
778
783
|
const fileExtension = ".glb";
|
|
779
784
|
const fileName_withoutExtension = "mesh_lod_" + level + "_" + guid;
|
|
@@ -803,7 +808,11 @@ async function createMeshLod(doc, basePath, level, mesh, meshInfo, guid, lodLeve
|
|
|
803
808
|
}
|
|
804
809
|
}
|
|
805
810
|
const newDoc = new Document();
|
|
806
|
-
writeNeedleAsset(newDoc
|
|
811
|
+
writeNeedleAsset(newDoc, {
|
|
812
|
+
"source": {
|
|
813
|
+
filename: inputFileName,
|
|
814
|
+
}
|
|
815
|
+
});
|
|
807
816
|
const newScene = newDoc.createScene();
|
|
808
817
|
newDoc.createBuffer();
|
|
809
818
|
const newNode = newDoc.createNode();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-build-pipeline",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-beta",
|
|
4
4
|
"description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|