@needle-tools/gltf-build-pipeline 2.7.0-alpha.1 → 2.7.0-alpha.2

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,9 @@ 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
+ ## [2.7.0-alpha.2] - 2024-02-13
8
+ - fix: processing for some very large meshes where hashing the meshes failed (for caching the results)
9
+
7
10
  ## [2.7.0-alpha.1] - 2024-01-13
8
11
  - fix: handle LOD omitting and remove deleted files from progressive transform results list
9
12
 
@@ -44,7 +44,7 @@ export declare function tryGetMetaFromCache(key: string, ignoreVersion?: boolean
44
44
  export declare function getKey(property: ExtensibleProperty): string;
45
45
  export declare function getKeyWithHash(property: ExtensibleProperty): {
46
46
  key: string;
47
- hash: number;
47
+ hash: string;
48
48
  };
49
49
  /**
50
50
  * Get the hash for a property or an object.
@@ -52,4 +52,4 @@ export declare function getKeyWithHash(property: ExtensibleProperty): {
52
52
  * @param level The current level of recursion.
53
53
  * @returns The hash as a number.
54
54
  */
55
- export declare function getHash(property: ExtensibleProperty | object, level?: number): number;
55
+ export declare function getHash(property: ExtensibleProperty | object, level?: number): string;
@@ -181,7 +181,7 @@ export function getKeyWithHash(property) {
181
181
  * @returns The hash as a number.
182
182
  */
183
183
  export function getHash(property, level = 0) {
184
- let hash = 0;
184
+ let hash = "";
185
185
  if (property instanceof ExtensibleProperty) {
186
186
  const extensions = property.listExtensions();
187
187
  const extras = property.getExtras();
@@ -209,15 +209,24 @@ export function getHash(property, level = 0) {
209
209
  const attributes = property.listAttributes();
210
210
  const targets = property.listTargets();
211
211
  // TODO: hash buffer view if possible
212
- const semantics = property.listSemantics().map(s => {
213
- return { name: s, array: property.getAttribute(s).getArray() };
212
+ const semantics = property.listSemantics();
213
+ const semanticsNames = semantics.map(s => {
214
+ return {
215
+ name: s,
216
+ };
214
217
  });
215
218
  hash += hashObject({
216
219
  indices,
217
220
  attributes,
218
221
  targets,
219
- semantics
222
+ semantics: semanticsNames
220
223
  });
224
+ // We can not pass the whole buffer into hashObject since very large meshes will cause errors when trying to stringify
225
+ // See https://linear.app/needle/issue/NE-6414
226
+ for (const sem of semantics) {
227
+ const arr = property.getAttribute(sem).getArray();
228
+ hash += hashBuffer(arr.buffer, arr.byteOffset, arr.byteLength);
229
+ }
221
230
  }
222
231
  }
223
232
  else {
@@ -236,13 +245,20 @@ function getCacheDirectory(root) {
236
245
  function hashObject(obj) {
237
246
  if (obj instanceof Accessor) {
238
247
  const buffer = obj.getArray();
239
- return hashBuffer(buffer);
248
+ return hashBuffer(buffer.buffer);
240
249
  }
241
250
  else if (obj == null) {
242
251
  return 0;
243
252
  }
244
- const str = JSON.stringify(obj);
245
- return hashString(str);
253
+ try {
254
+ const str = JSON.stringify(obj);
255
+ return hashString(str);
256
+ }
257
+ catch (err) {
258
+ console.error(err);
259
+ debugger;
260
+ throw err;
261
+ }
246
262
  }
247
263
  function hashBuffer(buffer, offset, length) {
248
264
  let hash = 0;
@@ -397,12 +397,14 @@ async function createTextureLod(args, opts) {
397
397
  if (!existsSync(basePath)) {
398
398
  mkdirSync(basePath, { recursive: true });
399
399
  }
400
- logger.info(`Write texture LOD ${level} to \"${filename}\"`);
400
+ logger.info(`[${NAME}] Write texture LOD ${level} to \"${filename}\"`);
401
401
  newIo.write(outName, newDoc);
402
+ logger.info(`[${NAME}] Generate hash for texture LOD ${level}`);
403
+ const hash = getHash(newTexture);
402
404
  return {
403
405
  outpath: outName,
404
406
  texture: newTexture,
405
- hash: getHash(newTexture).toString(),
407
+ hash: hash,
406
408
  };
407
409
  }
408
410
  function createMeshForMaterial(doc, mat, i) {
@@ -807,6 +809,7 @@ async function createMeshLod(inputFileName, doc, basePath, level, mesh, meshInfo
807
809
  // generate hash for mesh
808
810
  let hash = mesh["needle:mesh-hash"];
809
811
  if (hash === undefined) {
812
+ logger.info(`[${NAME}] Generating hash for mesh \"${mesh.getName()}\"`);
810
813
  hash = getHash(mesh);
811
814
  mesh["needle:mesh-hash"] = hash;
812
815
  }
@@ -1 +1 @@
1
- export declare const version = "2.7.0-alpha.1";
1
+ export declare const version = "2.7.0-alpha.2";
@@ -1 +1 @@
1
- export const version = "2.7.0-alpha.1";
1
+ export const version = "2.7.0-alpha.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-build-pipeline",
3
- "version": "2.7.0-alpha.1",
3
+ "version": "2.7.0-alpha.2",
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",
@@ -24,7 +24,8 @@
24
24
  "scripts": {
25
25
  "start": "node scripts/index.mjs",
26
26
  "dev": "npm-watch compile",
27
- "publish": "npm run compile && npm publish --access public",
27
+ "publish": "npm run compile && npm publish --access public --tag alpha",
28
+ "publish-tag": "npm dist-tag add @needle-tools/gltf-build-pipeline@2.7.0-alpha.1 alpha",
28
29
  "compile": "node tools/prebuild.mjs && (tsc || exit 1) && node tools/postbuild.mjs",
29
30
  "clear-caches": "node scripts/clear-caches.mjs",
30
31
  "limit-caches": "node scripts/limit-caches.mjs",