@inweb/viewer-three 27.4.2 → 27.4.4

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.
@@ -38259,6 +38259,19 @@ void main() {
38259
38259
  }
38260
38260
  }
38261
38261
 
38262
+ const GL_TO_THREE_WRAP = {
38263
+ 33071: ClampToEdgeWrapping,
38264
+ 33648: MirroredRepeatWrapping,
38265
+ 10497: RepeatWrapping,
38266
+ };
38267
+ const GL_TO_THREE_FILTER = {
38268
+ 9728: NearestFilter,
38269
+ 9729: LinearFilter,
38270
+ 9984: NearestMipmapNearestFilter,
38271
+ 9985: LinearMipmapNearestFilter,
38272
+ 9986: NearestMipmapLinearFilter,
38273
+ 9987: LinearMipmapLinearFilter,
38274
+ };
38262
38275
  const GL_COMPONENT_TYPES = {
38263
38276
  5120: Int8Array,
38264
38277
  5121: Uint8Array,
@@ -38301,6 +38314,7 @@ void main() {
38301
38314
  this.pendingRequests = [];
38302
38315
  this.batchTimeout = null;
38303
38316
  this.textureLoader = new TextureLoader();
38317
+ this.textureLoader.crossOrigin = "anonymous";
38304
38318
  this.materials = new Map();
38305
38319
  this.textureCache = new Map();
38306
38320
  this.materialCache = new Map();
@@ -38312,7 +38326,7 @@ void main() {
38312
38326
  async initialize(loader) {
38313
38327
  const json = await this.loadController.loadJson();
38314
38328
  if (json.asset === undefined || json.asset.version[0] < 2) {
38315
- throw new Error("GltfStructure: Unsupported asset. glTF versions >=2.0 are supported.");
38329
+ throw new Error("DynamicLoader: Unsupported asset. glTF versions >=2.0 are supported.");
38316
38330
  }
38317
38331
  this.json = json;
38318
38332
  this.loader = loader;
@@ -38340,7 +38354,9 @@ void main() {
38340
38354
  scheduleRequest(request) {
38341
38355
  return new Promise((resolve, reject) => {
38342
38356
  if (this.loadingAborted) {
38343
- reject(this.criticalError || new Error("Structure loading has been aborted due to critical error"));
38357
+ reject(
38358
+ this.criticalError || new Error("DynamicLoader: Structure loading has been aborted due to critical error")
38359
+ );
38344
38360
  return;
38345
38361
  }
38346
38362
  this.pendingRequests.push({
@@ -38379,7 +38395,7 @@ void main() {
38379
38395
  }
38380
38396
  }
38381
38397
  console.error(
38382
- `❌ Critical error for structure "${this.id}". All further loading aborted.`,
38398
+ `DynamicLoader: Critical error for structure "${this.id}". All further loading aborted.`,
38383
38399
  `\n Error: ${error.message || error}`,
38384
38400
  `\n Rejected ${requests.length} pending chunk requests.`
38385
38401
  );
@@ -38449,7 +38465,7 @@ void main() {
38449
38465
  const promises = finalRanges.map(async (range, index) => {
38450
38466
  if (this.loadingAborted) {
38451
38467
  for (const req of range.requests) {
38452
- req._reject(this.criticalError || new Error("Structure loading aborted"));
38468
+ req._reject(this.criticalError || new Error("DynamicLoader: Structure loading aborted"));
38453
38469
  }
38454
38470
  return;
38455
38471
  }
@@ -38472,7 +38488,10 @@ void main() {
38472
38488
  if (this.isCriticalHttpError(error)) {
38473
38489
  this.abortLoading(error);
38474
38490
  } else {
38475
- console.warn(`Failed to load chunk ${index + 1}/${finalRanges.length} (${range.start}-${range.end}):`, error);
38491
+ console.warn(
38492
+ `DynamicLoader: Failed to load chunk ${index + 1}/${finalRanges.length} (${range.start}-${range.end}):`,
38493
+ error
38494
+ );
38476
38495
  }
38477
38496
  } finally {
38478
38497
  this.loader.releaseChunkSlot();
@@ -38491,7 +38510,7 @@ void main() {
38491
38510
  createTypedArray(buffer, offset, length, componentType) {
38492
38511
  try {
38493
38512
  if (!buffer || !(buffer instanceof ArrayBuffer)) {
38494
- throw new Error("Invalid buffer");
38513
+ throw new Error("DynamicLoader: Invalid buffer");
38495
38514
  }
38496
38515
  let elementSize;
38497
38516
  switch (componentType) {
@@ -38508,20 +38527,22 @@ void main() {
38508
38527
  elementSize = 4;
38509
38528
  break;
38510
38529
  default:
38511
- throw new Error(`Unsupported component type: ${componentType}`);
38530
+ throw new Error(`DynamicLoader: Unsupported component type: ${componentType}`);
38512
38531
  }
38513
38532
  const numElements = length / elementSize;
38514
38533
  if (!Number.isInteger(numElements)) {
38515
- throw new Error(`Invalid length ${length} for component type ${componentType}`);
38534
+ throw new Error(`DynamicLoader: Invalid length ${length} for component type ${componentType}`);
38516
38535
  }
38517
38536
  if (length > buffer.byteLength) {
38518
- throw new Error(`Buffer too small: need ${length} bytes, but buffer is ${buffer.byteLength} bytes`);
38537
+ throw new Error(
38538
+ `DynamicLoader: Buffer too small: need ${length} bytes, but buffer is ${buffer.byteLength} bytes`
38539
+ );
38519
38540
  }
38520
38541
  const ArrayType = GL_COMPONENT_TYPES[componentType];
38521
38542
  return new ArrayType(buffer, offset, numElements);
38522
38543
  } catch (error) {
38523
38544
  if (error.name !== "AbortError") {
38524
- console.error("Error creating typed array:", {
38545
+ console.warn("DynamicLoader: Error creating typed array:", {
38525
38546
  bufferSize: buffer?.byteLength,
38526
38547
  offset,
38527
38548
  length,
@@ -38534,7 +38555,7 @@ void main() {
38534
38555
  }
38535
38556
  async createBufferAttribute(accessorIndex) {
38536
38557
  if (!this.json) {
38537
- throw new Error("No GLTF structure loaded");
38558
+ throw new Error("DynamicLoader: No GLTF structure loaded");
38538
38559
  }
38539
38560
  const gltf = this.json;
38540
38561
  const accessor = gltf.accessors[accessorIndex];
@@ -38551,7 +38572,7 @@ void main() {
38551
38572
  return attribute;
38552
38573
  } catch (error) {
38553
38574
  if (error.name !== "AbortError") {
38554
- console.error("Error creating buffer attribute:", {
38575
+ console.warn("DynamicLoader: Error creating buffer attribute:", {
38555
38576
  error,
38556
38577
  accessor,
38557
38578
  bufferView,
@@ -38572,7 +38593,7 @@ void main() {
38572
38593
  case 5126:
38573
38594
  return 4;
38574
38595
  default:
38575
- throw new Error(`Unknown component type: ${componentType}`);
38596
+ throw new Error(`DynamicLoader: Unknown component type: ${componentType}`);
38576
38597
  }
38577
38598
  }
38578
38599
  getNumComponents(type) {
@@ -38592,31 +38613,50 @@ void main() {
38592
38613
  case "MAT4":
38593
38614
  return 16;
38594
38615
  default:
38595
- throw new Error(`Unknown type: ${type}`);
38616
+ throw new Error(`DynamicLoader: Unknown type: ${type}`);
38596
38617
  }
38597
38618
  }
38598
38619
  async loadTextures() {
38599
38620
  if (!this.json.textures) return;
38600
38621
  const loadTexture = async (imageIndex) => {
38601
- const image = this.json.images[imageIndex];
38602
- if (image.uri) {
38603
- const fullUrl = await this.loadController.resolveURL(image.uri);
38604
- return this.textureLoader.loadAsync(fullUrl);
38605
- } else if (image.bufferView !== undefined) {
38606
- const bufferView = this.json.bufferViews[image.bufferView];
38607
- const array = await this.getBufferView(bufferView.byteOffset || 0, bufferView.byteLength, 5121);
38608
- const blob = new Blob([array], { type: image.mimeType });
38609
- const url = URL.createObjectURL(blob);
38610
- const texture = await this.textureLoader.loadAsync(url);
38611
- URL.revokeObjectURL(url);
38612
- texture.flipY = false;
38613
- return texture;
38622
+ let textureName = `index_${imageIndex}`;
38623
+ try {
38624
+ const image = this.json.images[imageIndex];
38625
+ textureName = image.uri || image.name || textureName;
38626
+ if (image.uri) {
38627
+ const fullUrl = await this.loadController.resolveURL(image.uri);
38628
+ return await this.textureLoader.loadAsync(fullUrl);
38629
+ } else if (image.bufferView !== undefined) {
38630
+ const bufferView = this.json.bufferViews[image.bufferView];
38631
+ const array = await this.getBufferView(bufferView.byteOffset || 0, bufferView.byteLength, 5121);
38632
+ const blob = new Blob([array], { type: image.mimeType });
38633
+ const url = URL.createObjectURL(blob);
38634
+ const texture = await this.textureLoader.loadAsync(url);
38635
+ URL.revokeObjectURL(url);
38636
+ return texture;
38637
+ }
38638
+ } catch {
38639
+ console.warn(`DynamicLoader: Error loading texture ${textureName}`);
38614
38640
  }
38615
38641
  };
38616
38642
  const texturePromises = [];
38617
38643
  for (let i = 0; i < this.json.textures.length; i++) {
38618
38644
  texturePromises.push(
38619
- loadTexture(this.json.textures[i].source).then((texture) => this.textureCache.set(i, texture))
38645
+ loadTexture(this.json.textures[i].source).then((texture) => {
38646
+ if (texture) {
38647
+ const samplerDef =
38648
+ this.json.textures[i].sampler !== undefined && this.json.samplers
38649
+ ? this.json.samplers[this.json.textures[i].sampler]
38650
+ : {};
38651
+ texture.magFilter = GL_TO_THREE_FILTER[samplerDef.magFilter] || LinearFilter;
38652
+ texture.minFilter = GL_TO_THREE_FILTER[samplerDef.minFilter] || LinearMipmapLinearFilter;
38653
+ texture.wrapS = GL_TO_THREE_WRAP[samplerDef.wrapS] || RepeatWrapping;
38654
+ texture.wrapT = GL_TO_THREE_WRAP[samplerDef.wrapT] || RepeatWrapping;
38655
+ texture.flipY = false;
38656
+ texture.needsUpdate = true;
38657
+ }
38658
+ this.textureCache.set(i, texture);
38659
+ })
38620
38660
  );
38621
38661
  }
38622
38662
  await Promise.all(texturePromises);
@@ -38647,8 +38687,14 @@ void main() {
38647
38687
  params.opacity = pbr.baseColorFactor[3];
38648
38688
  if (params.opacity < 1.0) params.transparent = true;
38649
38689
  }
38650
- if (pbr.baseColorTexture) {
38651
- params.map = this.textureCache.get(pbr.baseColorTexture.index);
38690
+ if (pbr.baseColorTexture !== undefined) {
38691
+ const texture = this.textureCache.get(pbr.baseColorTexture.index);
38692
+ if (texture) {
38693
+ params.map = texture;
38694
+ if (!pbr.baseColorFactor) {
38695
+ params.color = new Color(0xffffff);
38696
+ }
38697
+ }
38652
38698
  }
38653
38699
  }
38654
38700
  if (materialDef.emissiveFactor) {
@@ -38678,10 +38724,58 @@ void main() {
38678
38724
  params.polygonOffset = true;
38679
38725
  params.polygonOffsetFactor = 1;
38680
38726
  params.polygonOffsetUnits = 1;
38681
- if (materialDef.normalTexture) {
38682
- params.normalMap = this.textureCache.get(materialDef.normalTexture.index);
38727
+ if (params.map && !materialDef.pbrMetallicRoughness?.baseColorFactor) {
38728
+ params.color = new Color(0xffffff);
38729
+ }
38730
+ if (materialDef.normalTexture !== undefined) {
38731
+ const normalMap = this.textureCache.get(materialDef.normalTexture.index);
38732
+ if (normalMap) {
38733
+ params.normalMap = normalMap;
38734
+ }
38735
+ }
38736
+ if (materialDef.emissiveTexture !== undefined) {
38737
+ const emissiveMap = this.textureCache.get(materialDef.emissiveTexture.index);
38738
+ if (emissiveMap) {
38739
+ params.emissiveMap = emissiveMap;
38740
+ }
38741
+ }
38742
+ const usePBR = materialDef.pbrMetallicRoughness?.metallicRoughnessTexture !== undefined;
38743
+ if (usePBR) {
38744
+ params.metalness =
38745
+ materialDef.pbrMetallicRoughness?.metallicFactor !== undefined
38746
+ ? materialDef.pbrMetallicRoughness.metallicFactor
38747
+ : 1.0;
38748
+ params.roughness =
38749
+ materialDef.pbrMetallicRoughness?.roughnessFactor !== undefined
38750
+ ? materialDef.pbrMetallicRoughness.roughnessFactor
38751
+ : 1.0;
38752
+ if (materialDef.pbrMetallicRoughness?.metallicRoughnessTexture !== undefined) {
38753
+ const map = this.textureCache.get(materialDef.pbrMetallicRoughness.metallicRoughnessTexture.index);
38754
+ if (map) {
38755
+ params.metalnessMap = map;
38756
+ params.roughnessMap = map;
38757
+ }
38758
+ }
38759
+ material = new MeshStandardMaterial(params);
38760
+ } else {
38761
+ material = new MeshPhongMaterial(params);
38762
+ }
38763
+ if (material.map) material.map.colorSpace = SRGBColorSpace;
38764
+ if (material.emissiveMap) material.emissiveMap.colorSpace = SRGBColorSpace;
38765
+ if (material.normalMap) {
38766
+ if (materialDef.normalTexture?.scale !== undefined) {
38767
+ material.normalScale.set(materialDef.normalTexture.scale, materialDef.normalTexture.scale);
38768
+ }
38769
+ }
38770
+ if (materialDef.occlusionTexture !== undefined) {
38771
+ const aoMap = this.textureCache.get(materialDef.occlusionTexture.index);
38772
+ if (aoMap) {
38773
+ material.aoMap = aoMap;
38774
+ if (materialDef.occlusionTexture.strength !== undefined) {
38775
+ material.aoMapIntensity = materialDef.occlusionTexture.strength;
38776
+ }
38777
+ }
38683
38778
  }
38684
- material = new MeshPhongMaterial(params);
38685
38779
  }
38686
38780
  return material;
38687
38781
  }
@@ -39085,7 +39179,7 @@ void main() {
39085
39179
  memoryLimit = Math.max(memoryLimit, 2 * 1024 * 1024 * 1024);
39086
39180
  console.log(`Available memory set to ${Math.round(memoryLimit / (1024 * 1024 * 1024))}GB`);
39087
39181
  } catch (error) {
39088
- console.warn("Error detecting available memory:", error);
39182
+ console.warn("DynamicLoader: Error detecting available memory:", error);
39089
39183
  }
39090
39184
  return memoryLimit;
39091
39185
  }
@@ -39250,7 +39344,7 @@ void main() {
39250
39344
  if (entry?.lines?.uuid) uniqueMaterialIds.add(entry.lines.uuid);
39251
39345
  }
39252
39346
  } catch (exp) {
39253
- console.error("Error adding material to uniqueMaterialIds", exp);
39347
+ console.warn("DynamicLoader: Error collecting material stats", exp);
39254
39348
  }
39255
39349
  }
39256
39350
  }
@@ -39271,7 +39365,7 @@ void main() {
39271
39365
  this._webglInfoCache = { renderer: null, vendor: null };
39272
39366
  }
39273
39367
  } catch (e) {
39274
- console.error("Error getting webgl info", e);
39368
+ console.warn("DynamicLoader: Error getting webgl info", e);
39275
39369
  this._webglInfoCache = { renderer: null, vendor: null };
39276
39370
  }
39277
39371
  }
@@ -39528,7 +39622,7 @@ void main() {
39528
39622
  if (node.structure && node.structure.loadingAborted) {
39529
39623
  return;
39530
39624
  }
39531
- console.error(`Error loading node ${nodeId}:`, error);
39625
+ console.warn(`DynamicLoader: Error loading node ${nodeId}:`, error);
39532
39626
  }
39533
39627
  }
39534
39628
  unloadNode(nodeId) {
@@ -39581,7 +39675,7 @@ void main() {
39581
39675
  await structure.loadTextures();
39582
39676
  await structure.loadMaterials();
39583
39677
  } catch (error) {
39584
- console.error("Error loading materials:", error);
39678
+ console.error("DynamicLoader: Error loading materials:", error);
39585
39679
  throw error;
39586
39680
  }
39587
39681
  }
@@ -39589,14 +39683,14 @@ void main() {
39589
39683
  }
39590
39684
  async processSceneHierarchy() {
39591
39685
  if (this.structures.length === 0) {
39592
- throw new Error("No GLTF structures loaded");
39686
+ throw new Error("DynamicLoader: No GLTF structures loaded");
39593
39687
  }
39594
39688
  this.nodesToLoad = [];
39595
39689
  let estimatedSize = 0;
39596
39690
  for (const structure of this.structures) {
39597
39691
  const gltf = structure.getJson();
39598
39692
  if (!gltf.scenes || !gltf.scenes.length) {
39599
- console.warn("No scenes found in GLTF structure");
39693
+ console.warn("DynamicLoader: No scenes found in GLTF structure");
39600
39694
  continue;
39601
39695
  }
39602
39696
  estimatedSize += gltf.buffers[0].byteLength;
@@ -39838,7 +39932,6 @@ void main() {
39838
39932
  color: 0x808080,
39839
39933
  specular: 0x222222,
39840
39934
  shininess: 10,
39841
- side: DoubleSide,
39842
39935
  });
39843
39936
  }
39844
39937
  }
@@ -40309,7 +40402,6 @@ void main() {
40309
40402
  }
40310
40403
  });
40311
40404
  if (totalObjectsToMerge > 0) {
40312
- console.log(`Pre-allocating transform texture for ${totalObjectsToMerge} objects`);
40313
40405
  this.maxObjectId = totalObjectsToMerge;
40314
40406
  this.initTransformTexture();
40315
40407
  this.initializeObjectVisibility();
@@ -40372,7 +40464,7 @@ void main() {
40372
40464
  let processedGroups = 0;
40373
40465
  for (const group of materialGroups) {
40374
40466
  if (!group.material) {
40375
- console.warn("Skipping mesh group with null material");
40467
+ console.warn("DynamicLoader: Skipping mesh group with null material");
40376
40468
  continue;
40377
40469
  }
40378
40470
  try {
@@ -40457,7 +40549,7 @@ void main() {
40457
40549
  await this.yieldToUI();
40458
40550
  }
40459
40551
  } catch (error) {
40460
- console.error("Failed to merge meshes for material:", error);
40552
+ console.warn("DynamicLoader: Failed to merge meshes for material:", error);
40461
40553
  group.objects.forEach((mesh) => {
40462
40554
  mesh.visible = true;
40463
40555
  });
@@ -40469,7 +40561,7 @@ void main() {
40469
40561
  for (const group of materialGroups) {
40470
40562
  if (group.objects.length === 0) continue;
40471
40563
  if (!group.material) {
40472
- console.warn("Skipping line group with null material");
40564
+ console.warn("DynamicLoader: Skipping line group with null material");
40473
40565
  continue;
40474
40566
  }
40475
40567
  const handles = new Set();
@@ -40579,7 +40671,7 @@ void main() {
40579
40671
  let processedGroups = 0;
40580
40672
  for (const group of materialGroups) {
40581
40673
  if (!group.material) {
40582
- console.warn("Skipping line segment group with null material");
40674
+ console.warn("DynamicLoader: Skipping line segment group with null material");
40583
40675
  continue;
40584
40676
  }
40585
40677
  try {
@@ -40667,7 +40759,7 @@ void main() {
40667
40759
  await this.yieldToUI();
40668
40760
  }
40669
40761
  } catch (error) {
40670
- console.warn("Failed to merge line segments for material:", error);
40762
+ console.warn("DynamicLoader: Failed to merge line segments for material:", error);
40671
40763
  group.objects.forEach((line) => {
40672
40764
  line.visible = true;
40673
40765
  });
@@ -40678,7 +40770,7 @@ void main() {
40678
40770
  let processedGroups = 0;
40679
40771
  for (const group of materialGroups) {
40680
40772
  if (!group.material) {
40681
- console.warn("Skipping points group with null material");
40773
+ console.warn("DynamicLoader: Skipping points group with null material");
40682
40774
  continue;
40683
40775
  }
40684
40776
  try {
@@ -40750,7 +40842,7 @@ void main() {
40750
40842
  await this.yieldToUI();
40751
40843
  }
40752
40844
  } catch (error) {
40753
- console.warn("Failed to merge points for material:", error);
40845
+ console.warn("DynamicLoader: Failed to merge points for material:", error);
40754
40846
  group.objects.forEach((points) => {
40755
40847
  points.visible = true;
40756
40848
  });
@@ -40830,7 +40922,7 @@ void main() {
40830
40922
  obj.geometry.dispose();
40831
40923
  });
40832
40924
  } catch (error) {
40833
- console.error("Failed to merge geometries:", error);
40925
+ console.warn("DynamicLoader: Failed to merge geometries:", error);
40834
40926
  lineSegmentsArray.forEach((obj) => {
40835
40927
  obj.visible = true;
40836
40928
  rootGroup.add(obj);
@@ -40934,11 +41026,11 @@ void main() {
40934
41026
  }
40935
41027
  applyObjectTransforms(objectTransformMap) {
40936
41028
  if (this.mergedObjectMap.size === 0) {
40937
- console.warn("No merged objects to transform");
41029
+ console.warn("DynamicLoader: No merged objects to transform");
40938
41030
  return;
40939
41031
  }
40940
41032
  if (!this.transformData) {
40941
- console.warn("Transform texture not initialized");
41033
+ console.warn("DynamicLoader: Transform texture not initialized");
40942
41034
  return;
40943
41035
  }
40944
41036
  this.objectTransforms = objectTransformMap;
@@ -41121,7 +41213,7 @@ void main() {
41121
41213
  }
41122
41214
  syncHiddenObjects() {
41123
41215
  if (this.mergedObjectMap.size === 0) {
41124
- console.log("No merged objects to sync");
41216
+ console.warn("DynamicLoader: No merged objects to sync");
41125
41217
  return;
41126
41218
  }
41127
41219
  if (this.objectVisibility.length > 0) {