@needle-tools/gltf-build-pipeline 1.4.6 → 1.4.8

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 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.8] - 2023-04-22
8
+ - fix: update sharp package to `^0.32.6`
9
+ - change: NEEDLE_progressive meshes max LOD error increased
10
+
11
+ ## [1.4.7] - 2023-04-16
12
+ - add: `asset.extras.needle` now contains information about used build pipeline
13
+
7
14
  ## [1.4.6] - 2023-04-10
8
15
  - fix: NEEDLE_progressive meshes do not revert primitive data for skinned meshes anymore. See NE-4596
9
16
 
@@ -1,2 +1,3 @@
1
- import { Transform } from '@gltf-transform/core';
1
+ import { Document, Transform } from '@gltf-transform/core';
2
+ export declare function writeNeedleAsset(document: Document): void;
2
3
  export declare function needle_asset(): Transform;
@@ -1,17 +1,35 @@
1
1
  import { createTransform } from '@gltf-transform/functions';
2
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
+ }
3
16
  export function needle_asset() {
4
17
  return createTransform("needle_asset_transform", (document) => {
5
- const root = document.getRoot();
6
- const asset = root.getAsset();
7
- if (asset) {
8
- const version = getVersion();
9
- if (!asset.generator.startsWith("Needle glTF Build Pipeline")) {
10
- asset.generator = "Needle glTF Build Pipeline";
11
- if (version?.length > 0) {
12
- asset.generator += " " + version;
13
- }
14
- }
15
- }
18
+ writeNeedleAsset(document);
16
19
  });
17
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
+ }
@@ -7,7 +7,7 @@ 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";
9
9
  import { foreachGLTF, generateGuid } from '../utils/index.js';
10
- import { needle_asset } from './needle_asset.js';
10
+ import { needle_asset, writeNeedleAsset } from './needle_asset.js';
11
11
  import { MeshoptDecoder, MeshoptSimplifier } from 'meshoptimizer';
12
12
  import { compressPrimitive } from './needle_mesh_transform.js';
13
13
  import { calculateMeshDensity, getMeshInformation } from "../utils/mesh.js";
@@ -155,7 +155,7 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
155
155
  continue;
156
156
  }
157
157
  const textureGuid = settings.guid?.length ? settings.guid : generateGuid(path + "_texture_" + index.toString());
158
- const outPath = createTextureLod(textureLodBasePath, 0, texture, slots, textureGuid, textureIndex);
158
+ const outPath = createTextureLod(doc, textureLodBasePath, 0, texture, slots, textureGuid, textureIndex);
159
159
  if (!outPath) {
160
160
  continue;
161
161
  }
@@ -190,7 +190,7 @@ export function make_progressive_textures(filePath, _options = TEXTURE_RESIZE_DE
190
190
  logger.debug(`Progressive transform finished in ${((Date.now() - startTime) / 1000).toFixed(1)} sec.`);
191
191
  });
192
192
  }
193
- function createTextureLod(basePath, level, texture, slots, guid, textureIndex) {
193
+ function createTextureLod(doc, basePath, level, texture, slots, guid, textureIndex) {
194
194
  // const imageBytes = texture.getImage();
195
195
  // if (imageBytes) {
196
196
  // // write bytes
@@ -199,6 +199,7 @@ function createTextureLod(basePath, level, texture, slots, guid, textureIndex) {
199
199
  // return outPath;
200
200
  // }
201
201
  const newDoc = new Document();
202
+ writeNeedleAsset(newDoc);
202
203
  newDoc.createScene();
203
204
  newDoc.createBuffer();
204
205
  // add texture
@@ -341,7 +342,7 @@ export function make_progressive_meshes(filePath, _options, opts) {
341
342
  const t = l / MAX_LODS;
342
343
  const latest = LODS[LODS.length - 1];
343
344
  const ratio = latest.ratio * .5;
344
- const error = .05;
345
+ const error = Math.min(.013 * (l + 1), 0.05);
345
346
  LODS.push({
346
347
  ratio: ratio,
347
348
  error,
@@ -604,6 +605,7 @@ async function createMeshLod(doc, basePath, level, mesh, meshInfo, guid, lodLeve
604
605
  }
605
606
  }
606
607
  const newDoc = new Document();
608
+ writeNeedleAsset(newDoc);
607
609
  const newScene = newDoc.createScene();
608
610
  newDoc.createBuffer();
609
611
  const newNode = newDoc.createNode();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
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",
@@ -30,7 +30,7 @@
30
30
  "ndarray-pixels": "^2.0.1",
31
31
  "p-limit": "3.1.0",
32
32
  "semver": "^7.3.7",
33
- "sharp": "^0.31.3",
33
+ "sharp": "^0.32.6",
34
34
  "tmp": "^0.2.1",
35
35
  "uuid": "^9.0.1"
36
36
  },