@needle-tools/gltf-progressive 2.1.0-experimental.3 → 2.1.1
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 +20 -0
- package/gltf-progressive.js +430 -430
- package/gltf-progressive.min.js +7 -7
- package/gltf-progressive.umd.cjs +7 -7
- package/lib/extension.js +15 -10
- package/lib/loaders.d.ts +3 -3
- package/lib/loaders.js +30 -7
- package/lib/lods_manager.js +25 -9
- package/lib/version.js +2 -2
- package/package.json +1 -1
package/lib/lods_manager.js
CHANGED
|
@@ -309,9 +309,6 @@ export class LODsManager {
|
|
|
309
309
|
// TODO: we currently can not switch texture lods because we need better caching for the textures internally (see copySettings in progressive + NE-4431)
|
|
310
310
|
let textureLOD = levels.texture_lod;
|
|
311
311
|
if (object.material && textureLOD >= 0) {
|
|
312
|
-
const debugLevel = object["DEBUG:LOD"];
|
|
313
|
-
if (debugLevel != undefined)
|
|
314
|
-
textureLOD = debugLevel;
|
|
315
312
|
this.loadProgressiveTextures(object.material, textureLOD);
|
|
316
313
|
}
|
|
317
314
|
for (const plugin of plugins) {
|
|
@@ -343,6 +340,11 @@ export class LODsManager {
|
|
|
343
340
|
else if (level < material[$currentLOD]) {
|
|
344
341
|
update = true;
|
|
345
342
|
}
|
|
343
|
+
const debugLevel = material["DEBUG:LOD"];
|
|
344
|
+
if (debugLevel != undefined) {
|
|
345
|
+
update = material[$currentLOD] != debugLevel;
|
|
346
|
+
level = debugLevel;
|
|
347
|
+
}
|
|
346
348
|
if (update) {
|
|
347
349
|
material[$currentLOD] = level;
|
|
348
350
|
NEEDLE_progressive.assignTextureLOD(material, level).then(_ => {
|
|
@@ -359,7 +361,13 @@ export class LODsManager {
|
|
|
359
361
|
loadProgressiveMeshes(mesh, level) {
|
|
360
362
|
if (!mesh)
|
|
361
363
|
return Promise.resolve(null);
|
|
362
|
-
|
|
364
|
+
let update = mesh[$currentLOD] !== level;
|
|
365
|
+
const debugLevel = mesh["DEBUG:LOD"];
|
|
366
|
+
if (debugLevel != undefined) {
|
|
367
|
+
update = mesh[$currentLOD] != debugLevel;
|
|
368
|
+
level = debugLevel;
|
|
369
|
+
}
|
|
370
|
+
if (update) {
|
|
363
371
|
mesh[$currentLOD] = level;
|
|
364
372
|
const originalGeometry = mesh.geometry;
|
|
365
373
|
return NEEDLE_progressive.assignMeshLOD(mesh, level).then(res => {
|
|
@@ -456,7 +464,7 @@ export class LODsManager {
|
|
|
456
464
|
}
|
|
457
465
|
boundingBox = skinnedMesh.boundingBox;
|
|
458
466
|
}
|
|
459
|
-
if (boundingBox
|
|
467
|
+
if (boundingBox) {
|
|
460
468
|
const cam = camera;
|
|
461
469
|
// hack: if the mesh has vertex colors, has less than 100 vertices we always select the highest LOD
|
|
462
470
|
if (mesh.geometry.attributes.color && mesh.geometry.attributes.color.count < 100) {
|
|
@@ -481,7 +489,7 @@ export class LODsManager {
|
|
|
481
489
|
// High distortions would lead to lower LOD levels.
|
|
482
490
|
// "Centrality" of the calculated screen-space bounding box could be a factor here –
|
|
483
491
|
// what's the distance of the bounding box to the center of the screen?
|
|
484
|
-
if (LODsManager.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
492
|
+
if (cam.isPerspectiveCamera && LODsManager.isInside(this._tempBox, this.projectionScreenMatrix)) {
|
|
485
493
|
result.mesh_lod = 0;
|
|
486
494
|
result.texture_lod = 0;
|
|
487
495
|
return;
|
|
@@ -489,7 +497,7 @@ export class LODsManager {
|
|
|
489
497
|
this._tempBox.applyMatrix4(this.projectionScreenMatrix);
|
|
490
498
|
// TODO might need to be adjusted for cameras that are rendered during an XR session but are
|
|
491
499
|
// actually not XR cameras (e.g. a render texture)
|
|
492
|
-
if (this.renderer.xr.enabled && cam.fov > 70) {
|
|
500
|
+
if (this.renderer.xr.enabled && (cam.isPerspectiveCamera) && cam.fov > 70) {
|
|
493
501
|
// calculate centrality of the bounding box - how close is it to the screen center
|
|
494
502
|
const min = this._tempBox.min;
|
|
495
503
|
const max = this._tempBox.max;
|
|
@@ -522,7 +530,13 @@ export class LODsManager {
|
|
|
522
530
|
if (canvasHeight > 0)
|
|
523
531
|
boxSize.multiplyScalar(canvasHeight / screen.availHeight);
|
|
524
532
|
}
|
|
525
|
-
|
|
533
|
+
if (camera.isPerspectiveCamera) {
|
|
534
|
+
boxSize.x *= camera.aspect;
|
|
535
|
+
}
|
|
536
|
+
else if (camera.isOrthographicCamera) {
|
|
537
|
+
// const cam = camera as OrthographicCamera;
|
|
538
|
+
// boxSize.x *= cam.zoom * .01;
|
|
539
|
+
}
|
|
526
540
|
const matView = camera.matrixWorldInverse;
|
|
527
541
|
const box2 = this._tempBox2;
|
|
528
542
|
box2.copy(boundingBox);
|
|
@@ -618,6 +632,7 @@ export class LODsManager {
|
|
|
618
632
|
}
|
|
619
633
|
const screenSize = canvasHeight / window.devicePixelRatio;
|
|
620
634
|
const pixelSizeOnScreen = screenSize * factor;
|
|
635
|
+
let foundLod = false;
|
|
621
636
|
for (let i = texture_lods_minmax.lods.length - 1; i >= 0; i--) {
|
|
622
637
|
let lod = texture_lods_minmax.lods[i];
|
|
623
638
|
if (saveDataEnabled && lod.max_height >= 2048) {
|
|
@@ -625,7 +640,8 @@ export class LODsManager {
|
|
|
625
640
|
}
|
|
626
641
|
if (isMobileDevice() && lod.max_height > 4096)
|
|
627
642
|
continue; // skip 8k textures on mobile devices (for now)
|
|
628
|
-
if (lod.max_height > pixelSizeOnScreen) {
|
|
643
|
+
if (lod.max_height > pixelSizeOnScreen || (!foundLod && i === 0)) {
|
|
644
|
+
foundLod = true;
|
|
629
645
|
result.texture_lod = i;
|
|
630
646
|
if (result.texture_lod < state.lastLodLevel_Texture) {
|
|
631
647
|
const lod_pixel_height = lod.max_height;
|
package/lib/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// replaced at build time
|
|
2
|
-
export const version = "2.1.
|
|
2
|
+
export const version = "2.1.1";
|
|
3
3
|
globalThis["GLTF_PROGRESSIVE_VERSION"] = version;
|
|
4
|
-
console.debug(`[gltf-progressive] version ${version}`);
|
|
4
|
+
console.debug(`[gltf-progressive] version ${version || "-"}`);
|
package/package.json
CHANGED