@needle-tools/gltf-progressive 1.1.0-alpha.1 → 1.2.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.
@@ -232,7 +232,7 @@ export class LODsManager {
232
232
  plugin.onAfterUpdatedLOD?.(this.renderer, scene, camera, object, levels);
233
233
  }
234
234
  state.lastLodLevel_Mesh = levels.mesh_lod;
235
- state.lasLodLevel_Texture = levels.texture_lod;
235
+ state.lastLodLevel_Texture = levels.texture_lod;
236
236
  }
237
237
  /** Load progressive textures for the given material
238
238
  * @param material the material to load the textures for
@@ -338,7 +338,7 @@ export class LODsManager {
338
338
  const mesh_lods = mesh_lods_info?.lods;
339
339
  const has_mesh_lods = mesh_lods && mesh_lods.length > 0;
340
340
  const texture_lods_minmax = NEEDLE_progressive.getMaterialMinMaxLODsCount(mesh.material);
341
- const has_texture_lods = texture_lods_minmax?.min != Infinity && texture_lods_minmax.min > 0 && texture_lods_minmax.max > 0;
341
+ const has_texture_lods = texture_lods_minmax?.min_count != Infinity && texture_lods_minmax.min_count > 0 && texture_lods_minmax.max_count > 0;
342
342
  // We can skip all this if we dont have any LOD information
343
343
  if (!has_mesh_lods && !has_texture_lods) {
344
344
  result.mesh_lod = 0;
@@ -486,9 +486,34 @@ export class LODsManager {
486
486
  }
487
487
  }
488
488
  result.mesh_lod = mesh_level;
489
- if (texture_lods_minmax?.min && texture_lods_minmax.min > 0 && texture_lods_minmax.max > 0) {
490
- const t = Math.min(1, Math.max(0, state.lastScreenCoverage * 3));
491
- result.texture_lod = lerp(texture_lods_minmax.max, 0, t);
489
+ if (has_texture_lods) {
490
+ // If this is the first time a texture LOD is requested we want to get the highest LOD to not display the minimal resolution that the root glTF contains as long while we wait for loading of e.g. the 8k LOD 0 texture
491
+ if (state.lastLodLevel_Texture < 0) {
492
+ result.texture_lod = texture_lods_minmax.max_count - 1;
493
+ if (debugProgressiveLoading) {
494
+ const level = texture_lods_minmax.lods[texture_lods_minmax.max_count - 1];
495
+ if (debugProgressiveLoading)
496
+ console.log(`First Texture LOD ${result.texture_lod} (${level.max_height}px) - ${mesh.name}`);
497
+ }
498
+ }
499
+ else {
500
+ const factor = state.lastScreenCoverage * 1.5;
501
+ const screenSize = this.renderer.domElement.clientHeight / window.devicePixelRatio;
502
+ const pixelSizeOnScreen = screenSize * factor;
503
+ for (let i = texture_lods_minmax.lods.length - 1; i >= 0; i--) {
504
+ const lod = texture_lods_minmax.lods[i];
505
+ if (lod.max_height > pixelSizeOnScreen) {
506
+ result.texture_lod = i;
507
+ if (result.texture_lod < state.lastLodLevel_Texture) {
508
+ if (debugProgressiveLoading)
509
+ console.log(`Texture LOD changed ${state.lastLodLevel_Texture} → ${result.texture_lod} (${lod.max_height}px: ${(100 * state.lastScreenCoverage).toFixed(2)} % = ${pixelSizeOnScreen.toFixed(0)}px) - ${mesh.name}`);
510
+ }
511
+ break;
512
+ }
513
+ }
514
+ // const t = Math.min(1, Math.max(0, state.lastScreenCoverage * 1.1));
515
+ // result.texture_lod = lerp(texture_lods_minmax.max_count, 0, t);
516
+ }
492
517
  }
493
518
  else {
494
519
  result.texture_lod = 0;
@@ -500,8 +525,8 @@ function lerp(a, b, t) {
500
525
  }
501
526
  class LOD_state {
502
527
  frames = 0;
503
- lastLodLevel_Mesh = 0;
504
- lasLodLevel_Texture = 0;
528
+ lastLodLevel_Mesh = -1;
529
+ lastLodLevel_Texture = -1;
505
530
  lastScreenCoverage = 0;
506
531
  lastScreenspaceVolume = new Vector3();
507
532
  lastCentrality = 0;
@@ -111,7 +111,7 @@ class RegisterModelviewerDataPlugin {
111
111
  if (textureData?.extensions?.[EXTENSION_NAME]) {
112
112
  const ext = textureData.extensions[EXTENSION_NAME];
113
113
  if (ext && url) {
114
- NEEDLE_progressive.registerTexture(url, value, ext.lods.length, ext);
114
+ NEEDLE_progressive.registerTexture(url, value, ext.lods.length, textureIndex, ext);
115
115
  }
116
116
  }
117
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-progressive",
3
- "version": "1.1.0-alpha.1",
3
+ "version": "1.2.0-alpha",
4
4
  "description": "three.js support for loading glTF or GLB files that contain progressive loading data",
5
5
  "homepage": "https://needle.tools",
6
6
  "author": {