@needle-tools/gltf-build-pipeline 1.4.3 → 1.4.5
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 +7 -0
- package/dist/transforms/needle_progressive.js +21 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All notable changes to this package will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [1.4.5] - 2023-04-05
|
|
8
|
+
- fix: generating mesh and texture LOD for glbs without `NEEDLE_` extension
|
|
9
|
+
- fix: guid generation for progressive meshes when no `NEEDLE_` extension is present
|
|
10
|
+
|
|
11
|
+
## [1.4.4] - 2023-04-03
|
|
12
|
+
- change: clamp simplification error for LOD meshes to 5%
|
|
13
|
+
|
|
7
14
|
## [1.4.3] - 2023-04-02
|
|
8
15
|
- release
|
|
9
16
|
- fix: generate cache key for meshes
|
|
@@ -2,7 +2,7 @@ import { BufferUtils, Document, NodeIO, PropertyType } from '@gltf-transform/cor
|
|
|
2
2
|
import { SIMPLIFY_DEFAULTS, WELD_DEFAULTS, listTextureSlots, sparse } from '@gltf-transform/functions';
|
|
3
3
|
import { NEEDLE_PROGRESSIVE_EXTENSION_NAME, NEEDLE_progressive } from "../extensions/NEEDLE_progressive/index.js";
|
|
4
4
|
import { createOpaqueExtension, currentGenerator, NEEDLE_compression_texture, NEEDLE_mesh_compression, NEEDLE_progressive_mesh_settings, NEEDLE_progressive_texture_settings, registerExtensions as registerDefaultExtensions } from '../extensions/index.js';
|
|
5
|
-
import path from 'path';
|
|
5
|
+
import path, { basename } from 'path';
|
|
6
6
|
import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs';
|
|
7
7
|
import { addMetaToCache, addToCache, getHash, getKey, tryGetFromCache, tryGetMetaFromCache } from '../cache/index.js';
|
|
8
8
|
import sharp from "sharp";
|
|
@@ -97,6 +97,7 @@ const NAME = 'NEEDLE_progressive';
|
|
|
97
97
|
export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DEFAULTS, opts) {
|
|
98
98
|
console.log("Make progressive: " + filePath);
|
|
99
99
|
const startTime = Date.now();
|
|
100
|
+
const filename = basename(filePath);
|
|
100
101
|
const options = { ...TEXTURE_RESIZE_DEFAULTS, ..._options };
|
|
101
102
|
const directory = path.dirname(filePath);
|
|
102
103
|
// const fileNameWithoutExtension = path.basename(filePath, path.extname(filePath));
|
|
@@ -122,13 +123,23 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
|
|
|
122
123
|
logger.debug(`[${NAME}] Skipping, [${slots.join(', ')}] excluded by "slots" parameter. ${textureIndex}`);
|
|
123
124
|
continue;
|
|
124
125
|
}
|
|
125
|
-
|
|
126
|
+
let settings = texture.getExtension(NEEDLE_progressive_texture_settings.EXTENSION_NAME);
|
|
126
127
|
if (!settings) {
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
const size = texture.getSize();
|
|
129
|
+
if (size?.length >= 2 && size[0] <= 128 && size[1] <= 128) {
|
|
130
|
+
logger.warn(`[${NAME}] Skipping texture[${textureIndex}], no settings found`);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
settings = {
|
|
135
|
+
guid: generateGuid(filename + "_texture_" + index.toString()),
|
|
136
|
+
maxSize: 128,
|
|
137
|
+
};
|
|
138
|
+
logger.debug(`[${NAME}] No settings found for texture[${index}] - will use default settings (maxSize: ${settings.maxSize}, guid: ${settings.guid})`);
|
|
139
|
+
}
|
|
129
140
|
}
|
|
130
|
-
if (
|
|
131
|
-
logger.warn(`[${NAME}] Skipping, settings are invalid ${
|
|
141
|
+
if (settings.maxSize == undefined || settings.maxSize <= 0) {
|
|
142
|
+
logger.warn(`[${NAME}] Skipping texture[${textureIndex}], settings are invalid (maxSize: ${settings.maxSize})`);
|
|
132
143
|
continue;
|
|
133
144
|
}
|
|
134
145
|
options.size[0] = settings.maxSize;
|
|
@@ -330,7 +341,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
330
341
|
const t = l / MAX_LODS;
|
|
331
342
|
const latest = LODS[LODS.length - 1];
|
|
332
343
|
const ratio = latest.ratio * .5;
|
|
333
|
-
const error = .05
|
|
344
|
+
const error = .05;
|
|
334
345
|
LODS.push({
|
|
335
346
|
ratio: ratio,
|
|
336
347
|
error,
|
|
@@ -343,10 +354,10 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
343
354
|
const root = doc.getRoot();
|
|
344
355
|
const meshes = root.listMeshes();
|
|
345
356
|
for (const mesh of meshes) {
|
|
346
|
-
await processMesh(mesh);
|
|
357
|
+
await processMesh(mesh, { filename });
|
|
347
358
|
}
|
|
348
359
|
console.log(`[${NAME}]: Finished generating progressive meshes for \"${filename}\"`);
|
|
349
|
-
async function processMesh(mesh) {
|
|
360
|
+
async function processMesh(mesh, args) {
|
|
350
361
|
/** The size and vertex count of the original mesh */
|
|
351
362
|
const originalMeshInformation = getMeshInformation(mesh);
|
|
352
363
|
const { totalVertexCount: originalTotalVertexCount, maxVertexCount: originalMaxVertexCount } = originalMeshInformation;
|
|
@@ -358,7 +369,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
|
|
|
358
369
|
}
|
|
359
370
|
else {
|
|
360
371
|
settings = {
|
|
361
|
-
guid: generateGuid(
|
|
372
|
+
guid: generateGuid(args.filename + "_mesh_" + index.toString()),
|
|
362
373
|
generateLods: true,
|
|
363
374
|
};
|
|
364
375
|
logger.debug(`[${NAME}] No settings found for mesh[${index}] with ${originalTotalVertexCount} vertices (max: ${originalMaxVertexCount}) - will use default settings (guid: ${settings.guid})`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-build-pipeline",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Pipeline and tools for optimizing gltf files using gltf-transform and compression settings within glTF extensions",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"type": "module",
|