@inweb/viewer-three 26.10.6 → 26.11.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.
Files changed (84) hide show
  1. package/dist/plugins/components/AxesHelperComponent.js +23 -1
  2. package/dist/plugins/components/AxesHelperComponent.js.map +1 -1
  3. package/dist/plugins/components/AxesHelperComponent.min.js +1 -1
  4. package/dist/plugins/components/AxesHelperComponent.module.js +24 -2
  5. package/dist/plugins/components/AxesHelperComponent.module.js.map +1 -1
  6. package/dist/plugins/components/ExtentsHelperComponent.js +18 -0
  7. package/dist/plugins/components/ExtentsHelperComponent.js.map +1 -1
  8. package/dist/plugins/components/ExtentsHelperComponent.min.js +1 -1
  9. package/dist/plugins/components/ExtentsHelperComponent.module.js +19 -1
  10. package/dist/plugins/components/ExtentsHelperComponent.module.js.map +1 -1
  11. package/dist/plugins/loaders/GLTFCloudLoader.js +2 -3
  12. package/dist/plugins/loaders/GLTFCloudLoader.js.map +1 -1
  13. package/dist/plugins/loaders/GLTFCloudLoader.min.js +1 -1
  14. package/dist/plugins/loaders/GLTFCloudLoader.module.js +2 -3
  15. package/dist/plugins/loaders/GLTFCloudLoader.module.js.map +1 -1
  16. package/dist/plugins/loaders/GLTFFileLoader.js +2499 -0
  17. package/dist/plugins/loaders/GLTFFileLoader.js.map +1 -0
  18. package/dist/plugins/loaders/GLTFFileLoader.min.js +24 -0
  19. package/dist/plugins/loaders/GLTFFileLoader.module.js +74 -0
  20. package/dist/plugins/loaders/GLTFFileLoader.module.js.map +1 -0
  21. package/dist/plugins/loaders/IFCXLoader.js +5 -7
  22. package/dist/plugins/loaders/IFCXLoader.js.map +1 -1
  23. package/dist/plugins/loaders/IFCXLoader.min.js +1 -1
  24. package/dist/plugins/loaders/IFCXLoader.module.js +5 -7
  25. package/dist/plugins/loaders/IFCXLoader.module.js.map +1 -1
  26. package/dist/plugins/loaders/PotreeLoader.js +1 -2
  27. package/dist/plugins/loaders/PotreeLoader.js.map +1 -1
  28. package/dist/plugins/loaders/PotreeLoader.min.js +1 -1
  29. package/dist/plugins/loaders/PotreeLoader.module.js +1 -2
  30. package/dist/plugins/loaders/PotreeLoader.module.js.map +1 -1
  31. package/dist/viewer-three.js +770 -2777
  32. package/dist/viewer-three.js.map +1 -1
  33. package/dist/viewer-three.min.js +3 -3
  34. package/dist/viewer-three.module.js +609 -206
  35. package/dist/viewer-three.module.js.map +1 -1
  36. package/lib/Viewer/Viewer.d.ts +27 -20
  37. package/lib/Viewer/commands/GetSelected2.d.ts +2 -0
  38. package/lib/Viewer/commands/SelectModel.d.ts +1 -1
  39. package/lib/Viewer/commands/SetSelected2.d.ts +2 -0
  40. package/lib/Viewer/components/index.d.ts +6 -6
  41. package/lib/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.d.ts +0 -1
  42. package/lib/Viewer/loaders/GLTFBinaryExtension.d.ts +5 -0
  43. package/lib/Viewer/loaders/GLTFCloudDynamicLoader.d.ts +2 -2
  44. package/lib/Viewer/loaders/{GLTFFileLoader.d.ts → GLTFFileDynamicLoader.d.ts} +7 -1
  45. package/lib/Viewer/loaders/GLTFLoadingManager.d.ts +4 -3
  46. package/lib/Viewer/loaders/RangesLoader.d.ts +15 -0
  47. package/lib/Viewer/loaders/index.d.ts +22 -14
  48. package/lib/Viewer/models/IModelImpl.d.ts +6 -8
  49. package/lib/Viewer/models/ModelImpl.d.ts +3 -5
  50. package/package.json +5 -5
  51. package/plugins/components/AxesHelperComponent.ts +31 -2
  52. package/plugins/components/ExtentsHelperComponent.ts +25 -0
  53. package/plugins/loaders/GLTFCloudLoader.ts +2 -3
  54. package/{src/Viewer → plugins}/loaders/GLTFFileLoader.ts +21 -12
  55. package/plugins/loaders/IFCX/IFCXCloudLoader.ts +5 -5
  56. package/plugins/loaders/IFCX/IFCXFileLoader.ts +3 -4
  57. package/plugins/loaders/Potree/PotreeFileLoader.ts +3 -4
  58. package/src/Viewer/Viewer.ts +120 -88
  59. package/src/Viewer/commands/ClearSelected.ts +3 -1
  60. package/src/Viewer/commands/GetModels.ts +1 -1
  61. package/src/Viewer/commands/GetSelected.ts +2 -2
  62. package/src/Viewer/commands/GetSelected2.ts +34 -0
  63. package/src/Viewer/commands/HideSelected.ts +3 -1
  64. package/src/Viewer/commands/SelectModel.ts +5 -5
  65. package/src/Viewer/commands/SetSelected.ts +9 -10
  66. package/src/Viewer/commands/SetSelected2.ts +42 -0
  67. package/src/Viewer/commands/ZoomToObjects.ts +5 -6
  68. package/src/Viewer/commands/ZoomToSelected.ts +3 -1
  69. package/src/Viewer/commands/index.ts +4 -0
  70. package/src/Viewer/components/CameraComponent.ts +6 -1
  71. package/src/Viewer/components/ExtentsComponent.ts +4 -1
  72. package/src/Viewer/components/SelectionComponent.ts +2 -0
  73. package/src/Viewer/components/index.ts +6 -6
  74. package/src/Viewer/loaders/DynamicGltfLoader/DynamicGltfLoader.js +253 -22
  75. package/src/Viewer/loaders/DynamicGltfLoader/DynamicModelImpl.ts +20 -10
  76. package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +3 -1
  77. package/src/Viewer/loaders/GLTFBinaryExtension.ts +91 -0
  78. package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +13 -19
  79. package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +145 -0
  80. package/src/Viewer/loaders/GLTFLoadingManager.ts +5 -4
  81. package/src/Viewer/loaders/RangesLoader.ts +95 -0
  82. package/src/Viewer/loaders/index.ts +24 -16
  83. package/src/Viewer/models/IModelImpl.ts +8 -9
  84. package/src/Viewer/models/ModelImpl.ts +30 -17
@@ -171,6 +171,14 @@
171
171
  cancel() {
172
172
  this.abortController.abort();
173
173
  }
174
+ extractFileName(file) {
175
+ const regex = /[^/\\?#:]+(?=\?|#|$)/;
176
+ if (typeof file === "string")
177
+ return (file.match(regex) || [])[0];
178
+ else if (file instanceof globalThis.File)
179
+ return (file.name.match(regex) || [])[0];
180
+ return undefined;
181
+ }
174
182
  };
175
183
  class Loaders {
176
184
  constructor() {
@@ -9059,7 +9067,7 @@
9059
9067
  }
9060
9068
  }
9061
9069
  const _offsetMatrix = new Matrix4();
9062
- const _identityMatrix$1 = new Matrix4();
9070
+ const _identityMatrix = new Matrix4();
9063
9071
  class Skeleton {
9064
9072
  constructor( bones = [], boneInverses = [] ) {
9065
9073
  this.uuid = generateUUID();
@@ -9121,7 +9129,7 @@
9121
9129
  const boneMatrices = this.boneMatrices;
9122
9130
  const boneTexture = this.boneTexture;
9123
9131
  for ( let i = 0, il = bones.length; i < il; i ++ ) {
9124
- const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix$1;
9132
+ const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
9125
9133
  _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
9126
9134
  _offsetMatrix.toArray( boneMatrices, i * 16 );
9127
9135
  }
@@ -18451,7 +18459,7 @@
18451
18459
  }
18452
18460
  }
18453
18461
  const _position = new Vector3();
18454
- const _quaternion$5 = new Quaternion();
18462
+ const _quaternion = new Quaternion();
18455
18463
  const _scale = new Vector3();
18456
18464
  const _orientation = new Vector3();
18457
18465
  class PositionalAudio extends Audio {
@@ -18511,8 +18519,8 @@
18511
18519
  updateMatrixWorld( force ) {
18512
18520
  super.updateMatrixWorld( force );
18513
18521
  if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
18514
- this.matrixWorld.decompose( _position, _quaternion$5, _scale );
18515
- _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion$5 );
18522
+ this.matrixWorld.decompose( _position, _quaternion, _scale );
18523
+ _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
18516
18524
  const panner = this.panner;
18517
18525
  if ( panner.positionX ) {
18518
18526
  const endTime = this.context.currentTime + this.listener.timeDelta;
@@ -35022,7 +35030,8 @@ void main() {
35022
35030
  const selection = viewer.getComponent("SelectionComponent");
35023
35031
  selection.clearSelection();
35024
35032
  viewer.update();
35025
- viewer.emitEvent({ type: "select", data: undefined, handles: [] });
35033
+ viewer.emitEvent({ type: "select", handles: [] });
35034
+ viewer.emitEvent({ type: "select2", handles: [] });
35026
35035
  }
35027
35036
 
35028
35037
  function clearSlices(viewer) {
@@ -35111,22 +35120,31 @@ void main() {
35111
35120
  }
35112
35121
 
35113
35122
  function getModels(viewer) {
35114
- return viewer.models.map((model) => model.handle);
35123
+ return viewer.models.map((model) => model.id);
35115
35124
  }
35116
35125
 
35117
35126
  function getSelected(viewer) {
35118
- const handles = [];
35119
- viewer.models.forEach((model) => handles.push(...model.getHandlesByObjects(viewer.selected)));
35127
+ const handles2 = viewer.executeCommand("getSelected2");
35128
+ const handles = handles2.map((handle) => handle.slice(handle.indexOf(":") + 1));
35120
35129
  return handles;
35121
35130
  }
35122
35131
 
35132
+ function getSelected2(viewer) {
35133
+ const handles2 = [];
35134
+ viewer.models.forEach((model) => {
35135
+ handles2.push(...model.getHandlesByObjects(viewer.selected));
35136
+ });
35137
+ return handles2;
35138
+ }
35139
+
35123
35140
  function hideSelected(viewer) {
35124
35141
  viewer.models.forEach((model) => model.hideObjects(viewer.selected));
35125
35142
  const selection = viewer.getComponent("SelectionComponent");
35126
35143
  selection.clearSelection();
35127
35144
  viewer.update();
35128
35145
  viewer.emitEvent({ type: "hide" });
35129
- viewer.emitEvent({ type: "select", data: undefined, handles: [] });
35146
+ viewer.emitEvent({ type: "select", handles: [] });
35147
+ viewer.emitEvent({ type: "select2", handles: [] });
35130
35148
  }
35131
35149
 
35132
35150
  function isolateSelected(viewer) {
@@ -35153,14 +35171,13 @@ void main() {
35153
35171
  viewer.emit({ type: "resetview" });
35154
35172
  }
35155
35173
 
35156
- function selectModel(viewer, handle) {
35174
+ function selectModel(viewer, id) {
35157
35175
  const selection = viewer.getComponent("SelectionComponent");
35158
35176
  selection.clearSelection();
35159
- viewer.models
35160
- .filter((model) => model.handle === handle)
35161
- .forEach((model) => selection.select(model.getObjects(), model));
35177
+ viewer.models.filter((model) => model.id === id).forEach((model) => selection.select(model.getObjects(), model));
35162
35178
  viewer.update();
35163
- viewer.emit({ type: "select", data: [] });
35179
+ viewer.emitEvent({ type: "select", handles: viewer.getSelected() });
35180
+ viewer.emitEvent({ type: "select2", handles: viewer.getSelected2() });
35164
35181
  }
35165
35182
 
35166
35183
  function setActiveDragger(viewer, dragger = "") {
@@ -35172,16 +35189,31 @@ void main() {
35172
35189
  }
35173
35190
 
35174
35191
  function setSelected(viewer, handles = []) {
35175
- const selection = viewer.getComponent("SelectionComponent");
35176
- selection.clearSelection();
35192
+ const handles2 = [];
35193
+ handles.forEach((handle) => {
35194
+ if (handle.includes(":")) {
35195
+ handles2.push(handle);
35196
+ }
35197
+ else
35198
+ viewer.models.forEach((model) => {
35199
+ handles2.push(`${model.id}:${handle}`);
35200
+ });
35201
+ });
35202
+ viewer.executeCommand("setSelected2", handles2);
35203
+ }
35204
+
35205
+ function setSelected2(viewer, handles = []) {
35206
+ const selectionComponent = viewer.getComponent("SelectionComponent");
35207
+ selectionComponent.clearSelection();
35177
35208
  viewer.models.forEach((model) => {
35178
35209
  const objects = model.getObjectsByHandles(handles);
35179
35210
  model.showObjects(objects);
35180
- selection.select(objects, model);
35211
+ selectionComponent.select(objects, model);
35181
35212
  });
35182
35213
  viewer.update();
35183
35214
  viewer.emitEvent({ type: "show" });
35184
- viewer.emitEvent({ type: "select", data: undefined, handles });
35215
+ viewer.emitEvent({ type: "select", data: undefined, handles: viewer.getSelected() });
35216
+ viewer.emitEvent({ type: "select2", data: undefined, handles });
35185
35217
  }
35186
35218
 
35187
35219
  function showAll(viewer) {
@@ -35195,21 +35227,19 @@ void main() {
35195
35227
  }
35196
35228
 
35197
35229
  function zoomToObjects(viewer, handles = []) {
35198
- const handleSet = new Set(handles);
35199
- const objects = [];
35200
- viewer.scene.traverseVisible((child) => {
35201
- var _a;
35202
- if (handleSet.has((_a = child.userData) === null || _a === void 0 ? void 0 : _a.handle))
35203
- objects.push(child);
35230
+ const extents = new Box3();
35231
+ viewer.models.forEach((model) => {
35232
+ const objects = model.getObjectsByHandles(handles);
35233
+ objects.forEach((object) => extents.expandByObject(object));
35204
35234
  });
35205
- const extents = objects.reduce((result, object) => result.expandByObject(object), new Box3());
35206
35235
  if (extents.isEmpty())
35207
35236
  extents.copy(viewer.extents);
35208
35237
  zoomTo(viewer, extents);
35209
35238
  }
35210
35239
 
35211
35240
  function zoomToSelected(viewer) {
35212
- const extents = viewer.selected.reduce((result, object) => result.expandByObject(object), new Box3());
35241
+ const extents = new Box3();
35242
+ viewer.selected.forEach((object) => extents.expandByObject(object));
35213
35243
  if (extents.isEmpty())
35214
35244
  extents.copy(viewer.extents);
35215
35245
  zoomTo(viewer, extents);
@@ -35226,6 +35256,7 @@ void main() {
35226
35256
  commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
35227
35257
  commands.registerCommand("getModels", getModels);
35228
35258
  commands.registerCommand("getSelected", getSelected);
35259
+ commands.registerCommand("getSelected2", getSelected2);
35229
35260
  commands.registerCommand("hideSelected", hideSelected);
35230
35261
  commands.registerCommand("isolateSelected", isolateSelected);
35231
35262
  commands.registerCommand("regenerateAll", regenerateAll);
@@ -35235,6 +35266,7 @@ void main() {
35235
35266
  commands.registerCommand("setDefaultViewPosition", setDefaultViewPosition);
35236
35267
  commands.registerCommand("setMarkupColor", setMarkupColor);
35237
35268
  commands.registerCommand("setSelected", setSelected);
35269
+ commands.registerCommand("setSelected2", setSelected2);
35238
35270
  commands.registerCommand("showAll", showAll);
35239
35271
  commands.registerCommand("zoomToExtents", zoomToExtents);
35240
35272
  commands.registerCommand("zoomToObjects", zoomToObjects);
@@ -35287,6 +35319,10 @@ void main() {
35287
35319
  this.switchCameraMode(this.viewer.options.cameraMode);
35288
35320
  };
35289
35321
  this.geometryEnd = () => {
35322
+ if (this.viewer.models.length > 1) {
35323
+ this.switchCamera(this.viewer.camera);
35324
+ return;
35325
+ }
35290
35326
  let camera;
35291
35327
  this.viewer.scene.traverse((object) => {
35292
35328
  if (object.isCamera)
@@ -35384,6 +35420,8 @@ void main() {
35384
35420
  const extents = new Box3();
35385
35421
  this.viewer.models.forEach((model) => model.getExtents(extents));
35386
35422
  this.viewer.extents.copy(extents);
35423
+ if (this.viewer.models.length > 1)
35424
+ return;
35387
35425
  this.viewer.extents.getCenter(this.viewer.target);
35388
35426
  };
35389
35427
  this.viewer = viewer;
@@ -36371,6 +36409,7 @@ void main() {
36371
36409
  }
36372
36410
  this.viewer.update();
36373
36411
  this.viewer.emitEvent({ type: "select", data: undefined, handles: this.viewer.getSelected() });
36412
+ this.viewer.emitEvent({ type: "select2", data: undefined, handles: this.viewer.getSelected2() });
36374
36413
  };
36375
36414
  this.onDoubleClick = (event) => {
36376
36415
  if (event.button !== 0)
@@ -36615,2616 +36654,8 @@ void main() {
36615
36654
  components.registerComponent("WCSHelperComponent", (viewer) => new WCSHelperComponent(viewer));
36616
36655
  components.registerComponent("ResetComponent", (viewer) => new ResetComponent(viewer));
36617
36656
 
36618
- function mergeGeometries( geometries, useGroups = false ) {
36619
- const isIndexed = geometries[ 0 ].index !== null;
36620
- const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
36621
- const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
36622
- const attributes = {};
36623
- const morphAttributes = {};
36624
- const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
36625
- const mergedGeometry = new BufferGeometry();
36626
- let offset = 0;
36627
- for ( let i = 0; i < geometries.length; ++ i ) {
36628
- const geometry = geometries[ i ];
36629
- let attributesCount = 0;
36630
- if ( isIndexed !== ( geometry.index !== null ) ) {
36631
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
36632
- return null;
36633
- }
36634
- for ( const name in geometry.attributes ) {
36635
- if ( ! attributesUsed.has( name ) ) {
36636
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
36637
- return null;
36638
- }
36639
- if ( attributes[ name ] === undefined ) attributes[ name ] = [];
36640
- attributes[ name ].push( geometry.attributes[ name ] );
36641
- attributesCount ++;
36642
- }
36643
- if ( attributesCount !== attributesUsed.size ) {
36644
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
36645
- return null;
36646
- }
36647
- if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
36648
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
36649
- return null;
36650
- }
36651
- for ( const name in geometry.morphAttributes ) {
36652
- if ( ! morphAttributesUsed.has( name ) ) {
36653
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
36654
- return null;
36655
- }
36656
- if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
36657
- morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
36658
- }
36659
- if ( useGroups ) {
36660
- let count;
36661
- if ( isIndexed ) {
36662
- count = geometry.index.count;
36663
- } else if ( geometry.attributes.position !== undefined ) {
36664
- count = geometry.attributes.position.count;
36665
- } else {
36666
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
36667
- return null;
36668
- }
36669
- mergedGeometry.addGroup( offset, count, i );
36670
- offset += count;
36671
- }
36672
- }
36673
- if ( isIndexed ) {
36674
- let indexOffset = 0;
36675
- const mergedIndex = [];
36676
- for ( let i = 0; i < geometries.length; ++ i ) {
36677
- const index = geometries[ i ].index;
36678
- for ( let j = 0; j < index.count; ++ j ) {
36679
- mergedIndex.push( index.getX( j ) + indexOffset );
36680
- }
36681
- indexOffset += geometries[ i ].attributes.position.count;
36682
- }
36683
- mergedGeometry.setIndex( mergedIndex );
36684
- }
36685
- for ( const name in attributes ) {
36686
- const mergedAttribute = mergeAttributes( attributes[ name ] );
36687
- if ( ! mergedAttribute ) {
36688
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.' );
36689
- return null;
36690
- }
36691
- mergedGeometry.setAttribute( name, mergedAttribute );
36692
- }
36693
- for ( const name in morphAttributes ) {
36694
- const numMorphTargets = morphAttributes[ name ][ 0 ].length;
36695
- if ( numMorphTargets === 0 ) break;
36696
- mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
36697
- mergedGeometry.morphAttributes[ name ] = [];
36698
- for ( let i = 0; i < numMorphTargets; ++ i ) {
36699
- const morphAttributesToMerge = [];
36700
- for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
36701
- morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
36702
- }
36703
- const mergedMorphAttribute = mergeAttributes( morphAttributesToMerge );
36704
- if ( ! mergedMorphAttribute ) {
36705
- console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
36706
- return null;
36707
- }
36708
- mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
36709
- }
36710
- }
36711
- return mergedGeometry;
36712
- }
36713
- function mergeAttributes( attributes ) {
36714
- let TypedArray;
36715
- let itemSize;
36716
- let normalized;
36717
- let gpuType = -1;
36718
- let arrayLength = 0;
36719
- for ( let i = 0; i < attributes.length; ++ i ) {
36720
- const attribute = attributes[ i ];
36721
- if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
36722
- if ( TypedArray !== attribute.array.constructor ) {
36723
- console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
36724
- return null;
36725
- }
36726
- if ( itemSize === undefined ) itemSize = attribute.itemSize;
36727
- if ( itemSize !== attribute.itemSize ) {
36728
- console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
36729
- return null;
36730
- }
36731
- if ( normalized === undefined ) normalized = attribute.normalized;
36732
- if ( normalized !== attribute.normalized ) {
36733
- console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
36734
- return null;
36735
- }
36736
- if ( gpuType === -1 ) gpuType = attribute.gpuType;
36737
- if ( gpuType !== attribute.gpuType ) {
36738
- console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.' );
36739
- return null;
36740
- }
36741
- arrayLength += attribute.count * itemSize;
36742
- }
36743
- const array = new TypedArray( arrayLength );
36744
- const result = new BufferAttribute( array, itemSize, normalized );
36745
- let offset = 0;
36746
- for ( let i = 0; i < attributes.length; ++ i ) {
36747
- const attribute = attributes[ i ];
36748
- if ( attribute.isInterleavedBufferAttribute ) {
36749
- const tupleOffset = offset / itemSize;
36750
- for ( let j = 0, l = attribute.count; j < l; j ++ ) {
36751
- for ( let c = 0; c < itemSize; c ++ ) {
36752
- const value = attribute.getComponent( j, c );
36753
- result.setComponent( j + tupleOffset, c, value );
36754
- }
36755
- }
36756
- } else {
36757
- array.set( attribute.array, offset );
36758
- }
36759
- offset += attribute.count * itemSize;
36760
- }
36761
- if ( gpuType !== undefined ) {
36762
- result.gpuType = gpuType;
36763
- }
36764
- return result;
36765
- }
36766
- function toTrianglesDrawMode( geometry, drawMode ) {
36767
- if ( drawMode === TrianglesDrawMode ) {
36768
- console.warn( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.' );
36769
- return geometry;
36770
- }
36771
- if ( drawMode === TriangleFanDrawMode || drawMode === TriangleStripDrawMode ) {
36772
- let index = geometry.getIndex();
36773
- if ( index === null ) {
36774
- const indices = [];
36775
- const position = geometry.getAttribute( 'position' );
36776
- if ( position !== undefined ) {
36777
- for ( let i = 0; i < position.count; i ++ ) {
36778
- indices.push( i );
36779
- }
36780
- geometry.setIndex( indices );
36781
- index = geometry.getIndex();
36782
- } else {
36783
- console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
36784
- return geometry;
36785
- }
36786
- }
36787
- const numberOfTriangles = index.count - 2;
36788
- const newIndices = [];
36789
- if ( drawMode === TriangleFanDrawMode ) {
36790
- for ( let i = 1; i <= numberOfTriangles; i ++ ) {
36791
- newIndices.push( index.getX( 0 ) );
36792
- newIndices.push( index.getX( i ) );
36793
- newIndices.push( index.getX( i + 1 ) );
36794
- }
36795
- } else {
36796
- for ( let i = 0; i < numberOfTriangles; i ++ ) {
36797
- if ( i % 2 === 0 ) {
36798
- newIndices.push( index.getX( i ) );
36799
- newIndices.push( index.getX( i + 1 ) );
36800
- newIndices.push( index.getX( i + 2 ) );
36801
- } else {
36802
- newIndices.push( index.getX( i + 2 ) );
36803
- newIndices.push( index.getX( i + 1 ) );
36804
- newIndices.push( index.getX( i ) );
36805
- }
36806
- }
36807
- }
36808
- if ( ( newIndices.length / 3 ) !== numberOfTriangles ) {
36809
- console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
36810
- }
36811
- const newGeometry = geometry.clone();
36812
- newGeometry.setIndex( newIndices );
36813
- newGeometry.clearGroups();
36814
- return newGeometry;
36815
- } else {
36816
- console.error( 'THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:', drawMode );
36817
- return geometry;
36818
- }
36819
- }
36820
-
36821
- class GLTFLoader extends Loader {
36822
- constructor( manager ) {
36823
- super( manager );
36824
- this.dracoLoader = null;
36825
- this.ktx2Loader = null;
36826
- this.meshoptDecoder = null;
36827
- this.pluginCallbacks = [];
36828
- this.register( function ( parser ) {
36829
- return new GLTFMaterialsClearcoatExtension( parser );
36830
- } );
36831
- this.register( function ( parser ) {
36832
- return new GLTFMaterialsDispersionExtension( parser );
36833
- } );
36834
- this.register( function ( parser ) {
36835
- return new GLTFTextureBasisUExtension( parser );
36836
- } );
36837
- this.register( function ( parser ) {
36838
- return new GLTFTextureWebPExtension( parser );
36839
- } );
36840
- this.register( function ( parser ) {
36841
- return new GLTFTextureAVIFExtension( parser );
36842
- } );
36843
- this.register( function ( parser ) {
36844
- return new GLTFMaterialsSheenExtension( parser );
36845
- } );
36846
- this.register( function ( parser ) {
36847
- return new GLTFMaterialsTransmissionExtension( parser );
36848
- } );
36849
- this.register( function ( parser ) {
36850
- return new GLTFMaterialsVolumeExtension( parser );
36851
- } );
36852
- this.register( function ( parser ) {
36853
- return new GLTFMaterialsIorExtension( parser );
36854
- } );
36855
- this.register( function ( parser ) {
36856
- return new GLTFMaterialsEmissiveStrengthExtension( parser );
36857
- } );
36858
- this.register( function ( parser ) {
36859
- return new GLTFMaterialsSpecularExtension( parser );
36860
- } );
36861
- this.register( function ( parser ) {
36862
- return new GLTFMaterialsIridescenceExtension( parser );
36863
- } );
36864
- this.register( function ( parser ) {
36865
- return new GLTFMaterialsAnisotropyExtension( parser );
36866
- } );
36867
- this.register( function ( parser ) {
36868
- return new GLTFMaterialsBumpExtension( parser );
36869
- } );
36870
- this.register( function ( parser ) {
36871
- return new GLTFLightsExtension( parser );
36872
- } );
36873
- this.register( function ( parser ) {
36874
- return new GLTFMeshoptCompression( parser );
36875
- } );
36876
- this.register( function ( parser ) {
36877
- return new GLTFMeshGpuInstancing( parser );
36878
- } );
36879
- }
36880
- load( url, onLoad, onProgress, onError ) {
36881
- const scope = this;
36882
- let resourcePath;
36883
- if ( this.resourcePath !== '' ) {
36884
- resourcePath = this.resourcePath;
36885
- } else if ( this.path !== '' ) {
36886
- const relativeUrl = LoaderUtils.extractUrlBase( url );
36887
- resourcePath = LoaderUtils.resolveURL( relativeUrl, this.path );
36888
- } else {
36889
- resourcePath = LoaderUtils.extractUrlBase( url );
36890
- }
36891
- this.manager.itemStart( url );
36892
- const _onError = function ( e ) {
36893
- if ( onError ) {
36894
- onError( e );
36895
- } else {
36896
- console.error( e );
36897
- }
36898
- scope.manager.itemError( url );
36899
- scope.manager.itemEnd( url );
36900
- };
36901
- const loader = new FileLoader( this.manager );
36902
- loader.setPath( this.path );
36903
- loader.setResponseType( 'arraybuffer' );
36904
- loader.setRequestHeader( this.requestHeader );
36905
- loader.setWithCredentials( this.withCredentials );
36906
- loader.load( url, function ( data ) {
36907
- try {
36908
- scope.parse( data, resourcePath, function ( gltf ) {
36909
- onLoad( gltf );
36910
- scope.manager.itemEnd( url );
36911
- }, _onError );
36912
- } catch ( e ) {
36913
- _onError( e );
36914
- }
36915
- }, onProgress, _onError );
36916
- }
36917
- setDRACOLoader( dracoLoader ) {
36918
- this.dracoLoader = dracoLoader;
36919
- return this;
36920
- }
36921
- setKTX2Loader( ktx2Loader ) {
36922
- this.ktx2Loader = ktx2Loader;
36923
- return this;
36924
- }
36925
- setMeshoptDecoder( meshoptDecoder ) {
36926
- this.meshoptDecoder = meshoptDecoder;
36927
- return this;
36928
- }
36929
- register( callback ) {
36930
- if ( this.pluginCallbacks.indexOf( callback ) === -1 ) {
36931
- this.pluginCallbacks.push( callback );
36932
- }
36933
- return this;
36934
- }
36935
- unregister( callback ) {
36936
- if ( this.pluginCallbacks.indexOf( callback ) !== -1 ) {
36937
- this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
36938
- }
36939
- return this;
36940
- }
36941
- parse( data, path, onLoad, onError ) {
36942
- let json;
36943
- const extensions = {};
36944
- const plugins = {};
36945
- const textDecoder = new TextDecoder();
36946
- if ( typeof data === 'string' ) {
36947
- json = JSON.parse( data );
36948
- } else if ( data instanceof ArrayBuffer ) {
36949
- const magic = textDecoder.decode( new Uint8Array( data, 0, 4 ) );
36950
- if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
36951
- try {
36952
- extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
36953
- } catch ( error ) {
36954
- if ( onError ) onError( error );
36955
- return;
36956
- }
36957
- json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
36958
- } else {
36959
- json = JSON.parse( textDecoder.decode( data ) );
36960
- }
36961
- } else {
36962
- json = data;
36963
- }
36964
- if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
36965
- if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) );
36966
- return;
36967
- }
36968
- const parser = new GLTFParser( json, {
36969
- path: path || this.resourcePath || '',
36970
- crossOrigin: this.crossOrigin,
36971
- requestHeader: this.requestHeader,
36972
- manager: this.manager,
36973
- ktx2Loader: this.ktx2Loader,
36974
- meshoptDecoder: this.meshoptDecoder
36975
- } );
36976
- parser.fileLoader.setRequestHeader( this.requestHeader );
36977
- for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
36978
- const plugin = this.pluginCallbacks[ i ]( parser );
36979
- if ( ! plugin.name ) console.error( 'THREE.GLTFLoader: Invalid plugin found: missing name' );
36980
- plugins[ plugin.name ] = plugin;
36981
- extensions[ plugin.name ] = true;
36982
- }
36983
- if ( json.extensionsUsed ) {
36984
- for ( let i = 0; i < json.extensionsUsed.length; ++ i ) {
36985
- const extensionName = json.extensionsUsed[ i ];
36986
- const extensionsRequired = json.extensionsRequired || [];
36987
- switch ( extensionName ) {
36988
- case EXTENSIONS.KHR_MATERIALS_UNLIT:
36989
- extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
36990
- break;
36991
- case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
36992
- extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
36993
- break;
36994
- case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
36995
- extensions[ extensionName ] = new GLTFTextureTransformExtension();
36996
- break;
36997
- case EXTENSIONS.KHR_MESH_QUANTIZATION:
36998
- extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
36999
- break;
37000
- default:
37001
- if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
37002
- console.warn( 'THREE.GLTFLoader: Unknown extension "' + extensionName + '".' );
37003
- }
37004
- }
37005
- }
37006
- }
37007
- parser.setExtensions( extensions );
37008
- parser.setPlugins( plugins );
37009
- parser.parse( onLoad, onError );
37010
- }
37011
- parseAsync( data, path ) {
37012
- const scope = this;
37013
- return new Promise( function ( resolve, reject ) {
37014
- scope.parse( data, path, resolve, reject );
37015
- } );
37016
- }
37017
- }
37018
- function GLTFRegistry() {
37019
- let objects = {};
37020
- return {
37021
- get: function ( key ) {
37022
- return objects[ key ];
37023
- },
37024
- add: function ( key, object ) {
37025
- objects[ key ] = object;
37026
- },
37027
- remove: function ( key ) {
37028
- delete objects[ key ];
37029
- },
37030
- removeAll: function () {
37031
- objects = {};
37032
- }
37033
- };
37034
- }
37035
- const EXTENSIONS = {
37036
- KHR_BINARY_GLTF: 'KHR_binary_glTF',
37037
- KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
37038
- KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
37039
- KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
37040
- KHR_MATERIALS_DISPERSION: 'KHR_materials_dispersion',
37041
- KHR_MATERIALS_IOR: 'KHR_materials_ior',
37042
- KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
37043
- KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
37044
- KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
37045
- KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
37046
- KHR_MATERIALS_ANISOTROPY: 'KHR_materials_anisotropy',
37047
- KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
37048
- KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
37049
- KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
37050
- KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
37051
- KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
37052
- KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
37053
- EXT_MATERIALS_BUMP: 'EXT_materials_bump',
37054
- EXT_TEXTURE_WEBP: 'EXT_texture_webp',
37055
- EXT_TEXTURE_AVIF: 'EXT_texture_avif',
37056
- EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
37057
- EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
37058
- };
37059
- class GLTFLightsExtension {
37060
- constructor( parser ) {
37061
- this.parser = parser;
37062
- this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
37063
- this.cache = { refs: {}, uses: {} };
37064
- }
37065
- _markDefs() {
37066
- const parser = this.parser;
37067
- const nodeDefs = this.parser.json.nodes || [];
37068
- for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
37069
- const nodeDef = nodeDefs[ nodeIndex ];
37070
- if ( nodeDef.extensions
37071
- && nodeDef.extensions[ this.name ]
37072
- && nodeDef.extensions[ this.name ].light !== undefined ) {
37073
- parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
37074
- }
37075
- }
37076
- }
37077
- _loadLight( lightIndex ) {
37078
- const parser = this.parser;
37079
- const cacheKey = 'light:' + lightIndex;
37080
- let dependency = parser.cache.get( cacheKey );
37081
- if ( dependency ) return dependency;
37082
- const json = parser.json;
37083
- const extensions = ( json.extensions && json.extensions[ this.name ] ) || {};
37084
- const lightDefs = extensions.lights || [];
37085
- const lightDef = lightDefs[ lightIndex ];
37086
- let lightNode;
37087
- const color = new Color( 0xffffff );
37088
- if ( lightDef.color !== undefined ) color.setRGB( lightDef.color[ 0 ], lightDef.color[ 1 ], lightDef.color[ 2 ], LinearSRGBColorSpace );
37089
- const range = lightDef.range !== undefined ? lightDef.range : 0;
37090
- switch ( lightDef.type ) {
37091
- case 'directional':
37092
- lightNode = new DirectionalLight( color );
37093
- lightNode.target.position.set( 0, 0, -1 );
37094
- lightNode.add( lightNode.target );
37095
- break;
37096
- case 'point':
37097
- lightNode = new PointLight( color );
37098
- lightNode.distance = range;
37099
- break;
37100
- case 'spot':
37101
- lightNode = new SpotLight( color );
37102
- lightNode.distance = range;
37103
- lightDef.spot = lightDef.spot || {};
37104
- lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
37105
- lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
37106
- lightNode.angle = lightDef.spot.outerConeAngle;
37107
- lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
37108
- lightNode.target.position.set( 0, 0, -1 );
37109
- lightNode.add( lightNode.target );
37110
- break;
37111
- default:
37112
- throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
37113
- }
37114
- lightNode.position.set( 0, 0, 0 );
37115
- assignExtrasToUserData( lightNode, lightDef );
37116
- if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
37117
- lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) );
37118
- dependency = Promise.resolve( lightNode );
37119
- parser.cache.add( cacheKey, dependency );
37120
- return dependency;
37121
- }
37122
- getDependency( type, index ) {
37123
- if ( type !== 'light' ) return;
37124
- return this._loadLight( index );
37125
- }
37126
- createNodeAttachment( nodeIndex ) {
37127
- const self = this;
37128
- const parser = this.parser;
37129
- const json = parser.json;
37130
- const nodeDef = json.nodes[ nodeIndex ];
37131
- const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {};
37132
- const lightIndex = lightDef.light;
37133
- if ( lightIndex === undefined ) return null;
37134
- return this._loadLight( lightIndex ).then( function ( light ) {
37135
- return parser._getNodeRef( self.cache, lightIndex, light );
37136
- } );
37137
- }
37138
- }
37139
- class GLTFMaterialsUnlitExtension {
37140
- constructor() {
37141
- this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
37142
- }
37143
- getMaterialType() {
37144
- return MeshBasicMaterial;
37145
- }
37146
- extendParams( materialParams, materialDef, parser ) {
37147
- const pending = [];
37148
- materialParams.color = new Color( 1.0, 1.0, 1.0 );
37149
- materialParams.opacity = 1.0;
37150
- const metallicRoughness = materialDef.pbrMetallicRoughness;
37151
- if ( metallicRoughness ) {
37152
- if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
37153
- const array = metallicRoughness.baseColorFactor;
37154
- materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
37155
- materialParams.opacity = array[ 3 ];
37156
- }
37157
- if ( metallicRoughness.baseColorTexture !== undefined ) {
37158
- pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
37159
- }
37160
- }
37161
- return Promise.all( pending );
37162
- }
37163
- }
37164
- class GLTFMaterialsEmissiveStrengthExtension {
37165
- constructor( parser ) {
37166
- this.parser = parser;
37167
- this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
37168
- }
37169
- extendMaterialParams( materialIndex, materialParams ) {
37170
- const parser = this.parser;
37171
- const materialDef = parser.json.materials[ materialIndex ];
37172
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37173
- return Promise.resolve();
37174
- }
37175
- const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
37176
- if ( emissiveStrength !== undefined ) {
37177
- materialParams.emissiveIntensity = emissiveStrength;
37178
- }
37179
- return Promise.resolve();
37180
- }
37181
- }
37182
- class GLTFMaterialsClearcoatExtension {
37183
- constructor( parser ) {
37184
- this.parser = parser;
37185
- this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
37186
- }
37187
- getMaterialType( materialIndex ) {
37188
- const parser = this.parser;
37189
- const materialDef = parser.json.materials[ materialIndex ];
37190
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37191
- return MeshPhysicalMaterial;
37192
- }
37193
- extendMaterialParams( materialIndex, materialParams ) {
37194
- const parser = this.parser;
37195
- const materialDef = parser.json.materials[ materialIndex ];
37196
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37197
- return Promise.resolve();
37198
- }
37199
- const pending = [];
37200
- const extension = materialDef.extensions[ this.name ];
37201
- if ( extension.clearcoatFactor !== undefined ) {
37202
- materialParams.clearcoat = extension.clearcoatFactor;
37203
- }
37204
- if ( extension.clearcoatTexture !== undefined ) {
37205
- pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) );
37206
- }
37207
- if ( extension.clearcoatRoughnessFactor !== undefined ) {
37208
- materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
37209
- }
37210
- if ( extension.clearcoatRoughnessTexture !== undefined ) {
37211
- pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) );
37212
- }
37213
- if ( extension.clearcoatNormalTexture !== undefined ) {
37214
- pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
37215
- if ( extension.clearcoatNormalTexture.scale !== undefined ) {
37216
- const scale = extension.clearcoatNormalTexture.scale;
37217
- materialParams.clearcoatNormalScale = new Vector2( scale, scale );
37218
- }
37219
- }
37220
- return Promise.all( pending );
37221
- }
37222
- }
37223
- class GLTFMaterialsDispersionExtension {
37224
- constructor( parser ) {
37225
- this.parser = parser;
37226
- this.name = EXTENSIONS.KHR_MATERIALS_DISPERSION;
37227
- }
37228
- getMaterialType( materialIndex ) {
37229
- const parser = this.parser;
37230
- const materialDef = parser.json.materials[ materialIndex ];
37231
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37232
- return MeshPhysicalMaterial;
37233
- }
37234
- extendMaterialParams( materialIndex, materialParams ) {
37235
- const parser = this.parser;
37236
- const materialDef = parser.json.materials[ materialIndex ];
37237
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37238
- return Promise.resolve();
37239
- }
37240
- const extension = materialDef.extensions[ this.name ];
37241
- materialParams.dispersion = extension.dispersion !== undefined ? extension.dispersion : 0;
37242
- return Promise.resolve();
37243
- }
37244
- }
37245
- class GLTFMaterialsIridescenceExtension {
37246
- constructor( parser ) {
37247
- this.parser = parser;
37248
- this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
37249
- }
37250
- getMaterialType( materialIndex ) {
37251
- const parser = this.parser;
37252
- const materialDef = parser.json.materials[ materialIndex ];
37253
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37254
- return MeshPhysicalMaterial;
37255
- }
37256
- extendMaterialParams( materialIndex, materialParams ) {
37257
- const parser = this.parser;
37258
- const materialDef = parser.json.materials[ materialIndex ];
37259
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37260
- return Promise.resolve();
37261
- }
37262
- const pending = [];
37263
- const extension = materialDef.extensions[ this.name ];
37264
- if ( extension.iridescenceFactor !== undefined ) {
37265
- materialParams.iridescence = extension.iridescenceFactor;
37266
- }
37267
- if ( extension.iridescenceTexture !== undefined ) {
37268
- pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
37269
- }
37270
- if ( extension.iridescenceIor !== undefined ) {
37271
- materialParams.iridescenceIOR = extension.iridescenceIor;
37272
- }
37273
- if ( materialParams.iridescenceThicknessRange === undefined ) {
37274
- materialParams.iridescenceThicknessRange = [ 100, 400 ];
37275
- }
37276
- if ( extension.iridescenceThicknessMinimum !== undefined ) {
37277
- materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
37278
- }
37279
- if ( extension.iridescenceThicknessMaximum !== undefined ) {
37280
- materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
37281
- }
37282
- if ( extension.iridescenceThicknessTexture !== undefined ) {
37283
- pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
37284
- }
37285
- return Promise.all( pending );
37286
- }
37287
- }
37288
- class GLTFMaterialsSheenExtension {
37289
- constructor( parser ) {
37290
- this.parser = parser;
37291
- this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
37292
- }
37293
- getMaterialType( materialIndex ) {
37294
- const parser = this.parser;
37295
- const materialDef = parser.json.materials[ materialIndex ];
37296
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37297
- return MeshPhysicalMaterial;
37298
- }
37299
- extendMaterialParams( materialIndex, materialParams ) {
37300
- const parser = this.parser;
37301
- const materialDef = parser.json.materials[ materialIndex ];
37302
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37303
- return Promise.resolve();
37304
- }
37305
- const pending = [];
37306
- materialParams.sheenColor = new Color( 0, 0, 0 );
37307
- materialParams.sheenRoughness = 0;
37308
- materialParams.sheen = 1;
37309
- const extension = materialDef.extensions[ this.name ];
37310
- if ( extension.sheenColorFactor !== undefined ) {
37311
- const colorFactor = extension.sheenColorFactor;
37312
- materialParams.sheenColor.setRGB( colorFactor[ 0 ], colorFactor[ 1 ], colorFactor[ 2 ], LinearSRGBColorSpace );
37313
- }
37314
- if ( extension.sheenRoughnessFactor !== undefined ) {
37315
- materialParams.sheenRoughness = extension.sheenRoughnessFactor;
37316
- }
37317
- if ( extension.sheenColorTexture !== undefined ) {
37318
- pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, SRGBColorSpace ) );
37319
- }
37320
- if ( extension.sheenRoughnessTexture !== undefined ) {
37321
- pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
37322
- }
37323
- return Promise.all( pending );
37324
- }
37325
- }
37326
- class GLTFMaterialsTransmissionExtension {
37327
- constructor( parser ) {
37328
- this.parser = parser;
37329
- this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
37330
- }
37331
- getMaterialType( materialIndex ) {
37332
- const parser = this.parser;
37333
- const materialDef = parser.json.materials[ materialIndex ];
37334
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37335
- return MeshPhysicalMaterial;
37336
- }
37337
- extendMaterialParams( materialIndex, materialParams ) {
37338
- const parser = this.parser;
37339
- const materialDef = parser.json.materials[ materialIndex ];
37340
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37341
- return Promise.resolve();
37342
- }
37343
- const pending = [];
37344
- const extension = materialDef.extensions[ this.name ];
37345
- if ( extension.transmissionFactor !== undefined ) {
37346
- materialParams.transmission = extension.transmissionFactor;
37347
- }
37348
- if ( extension.transmissionTexture !== undefined ) {
37349
- pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) );
37350
- }
37351
- return Promise.all( pending );
37352
- }
37353
- }
37354
- class GLTFMaterialsVolumeExtension {
37355
- constructor( parser ) {
37356
- this.parser = parser;
37357
- this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
37358
- }
37359
- getMaterialType( materialIndex ) {
37360
- const parser = this.parser;
37361
- const materialDef = parser.json.materials[ materialIndex ];
37362
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37363
- return MeshPhysicalMaterial;
37364
- }
37365
- extendMaterialParams( materialIndex, materialParams ) {
37366
- const parser = this.parser;
37367
- const materialDef = parser.json.materials[ materialIndex ];
37368
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37369
- return Promise.resolve();
37370
- }
37371
- const pending = [];
37372
- const extension = materialDef.extensions[ this.name ];
37373
- materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
37374
- if ( extension.thicknessTexture !== undefined ) {
37375
- pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
37376
- }
37377
- materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
37378
- const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
37379
- materialParams.attenuationColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
37380
- return Promise.all( pending );
37381
- }
37382
- }
37383
- class GLTFMaterialsIorExtension {
37384
- constructor( parser ) {
37385
- this.parser = parser;
37386
- this.name = EXTENSIONS.KHR_MATERIALS_IOR;
37387
- }
37388
- getMaterialType( materialIndex ) {
37389
- const parser = this.parser;
37390
- const materialDef = parser.json.materials[ materialIndex ];
37391
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37392
- return MeshPhysicalMaterial;
37393
- }
37394
- extendMaterialParams( materialIndex, materialParams ) {
37395
- const parser = this.parser;
37396
- const materialDef = parser.json.materials[ materialIndex ];
37397
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37398
- return Promise.resolve();
37399
- }
37400
- const extension = materialDef.extensions[ this.name ];
37401
- materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
37402
- return Promise.resolve();
37403
- }
37404
- }
37405
- class GLTFMaterialsSpecularExtension {
37406
- constructor( parser ) {
37407
- this.parser = parser;
37408
- this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
37409
- }
37410
- getMaterialType( materialIndex ) {
37411
- const parser = this.parser;
37412
- const materialDef = parser.json.materials[ materialIndex ];
37413
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37414
- return MeshPhysicalMaterial;
37415
- }
37416
- extendMaterialParams( materialIndex, materialParams ) {
37417
- const parser = this.parser;
37418
- const materialDef = parser.json.materials[ materialIndex ];
37419
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37420
- return Promise.resolve();
37421
- }
37422
- const pending = [];
37423
- const extension = materialDef.extensions[ this.name ];
37424
- materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
37425
- if ( extension.specularTexture !== undefined ) {
37426
- pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
37427
- }
37428
- const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
37429
- materialParams.specularColor = new Color().setRGB( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ], LinearSRGBColorSpace );
37430
- if ( extension.specularColorTexture !== undefined ) {
37431
- pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, SRGBColorSpace ) );
37432
- }
37433
- return Promise.all( pending );
37434
- }
37435
- }
37436
- class GLTFMaterialsBumpExtension {
37437
- constructor( parser ) {
37438
- this.parser = parser;
37439
- this.name = EXTENSIONS.EXT_MATERIALS_BUMP;
37440
- }
37441
- getMaterialType( materialIndex ) {
37442
- const parser = this.parser;
37443
- const materialDef = parser.json.materials[ materialIndex ];
37444
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37445
- return MeshPhysicalMaterial;
37446
- }
37447
- extendMaterialParams( materialIndex, materialParams ) {
37448
- const parser = this.parser;
37449
- const materialDef = parser.json.materials[ materialIndex ];
37450
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37451
- return Promise.resolve();
37452
- }
37453
- const pending = [];
37454
- const extension = materialDef.extensions[ this.name ];
37455
- materialParams.bumpScale = extension.bumpFactor !== undefined ? extension.bumpFactor : 1.0;
37456
- if ( extension.bumpTexture !== undefined ) {
37457
- pending.push( parser.assignTexture( materialParams, 'bumpMap', extension.bumpTexture ) );
37458
- }
37459
- return Promise.all( pending );
37460
- }
37461
- }
37462
- class GLTFMaterialsAnisotropyExtension {
37463
- constructor( parser ) {
37464
- this.parser = parser;
37465
- this.name = EXTENSIONS.KHR_MATERIALS_ANISOTROPY;
37466
- }
37467
- getMaterialType( materialIndex ) {
37468
- const parser = this.parser;
37469
- const materialDef = parser.json.materials[ materialIndex ];
37470
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
37471
- return MeshPhysicalMaterial;
37472
- }
37473
- extendMaterialParams( materialIndex, materialParams ) {
37474
- const parser = this.parser;
37475
- const materialDef = parser.json.materials[ materialIndex ];
37476
- if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
37477
- return Promise.resolve();
37478
- }
37479
- const pending = [];
37480
- const extension = materialDef.extensions[ this.name ];
37481
- if ( extension.anisotropyStrength !== undefined ) {
37482
- materialParams.anisotropy = extension.anisotropyStrength;
37483
- }
37484
- if ( extension.anisotropyRotation !== undefined ) {
37485
- materialParams.anisotropyRotation = extension.anisotropyRotation;
37486
- }
37487
- if ( extension.anisotropyTexture !== undefined ) {
37488
- pending.push( parser.assignTexture( materialParams, 'anisotropyMap', extension.anisotropyTexture ) );
37489
- }
37490
- return Promise.all( pending );
37491
- }
37492
- }
37493
- class GLTFTextureBasisUExtension {
37494
- constructor( parser ) {
37495
- this.parser = parser;
37496
- this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
37497
- }
37498
- loadTexture( textureIndex ) {
37499
- const parser = this.parser;
37500
- const json = parser.json;
37501
- const textureDef = json.textures[ textureIndex ];
37502
- if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
37503
- return null;
37504
- }
37505
- const extension = textureDef.extensions[ this.name ];
37506
- const loader = parser.options.ktx2Loader;
37507
- if ( ! loader ) {
37508
- if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
37509
- throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' );
37510
- } else {
37511
- return null;
37512
- }
37513
- }
37514
- return parser.loadTextureImage( textureIndex, extension.source, loader );
37515
- }
37516
- }
37517
- class GLTFTextureWebPExtension {
37518
- constructor( parser ) {
37519
- this.parser = parser;
37520
- this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
37521
- }
37522
- loadTexture( textureIndex ) {
37523
- const name = this.name;
37524
- const parser = this.parser;
37525
- const json = parser.json;
37526
- const textureDef = json.textures[ textureIndex ];
37527
- if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
37528
- return null;
37529
- }
37530
- const extension = textureDef.extensions[ name ];
37531
- const source = json.images[ extension.source ];
37532
- let loader = parser.textureLoader;
37533
- if ( source.uri ) {
37534
- const handler = parser.options.manager.getHandler( source.uri );
37535
- if ( handler !== null ) loader = handler;
37536
- }
37537
- return parser.loadTextureImage( textureIndex, extension.source, loader );
37538
- }
37539
- }
37540
- class GLTFTextureAVIFExtension {
37541
- constructor( parser ) {
37542
- this.parser = parser;
37543
- this.name = EXTENSIONS.EXT_TEXTURE_AVIF;
37544
- }
37545
- loadTexture( textureIndex ) {
37546
- const name = this.name;
37547
- const parser = this.parser;
37548
- const json = parser.json;
37549
- const textureDef = json.textures[ textureIndex ];
37550
- if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
37551
- return null;
37552
- }
37553
- const extension = textureDef.extensions[ name ];
37554
- const source = json.images[ extension.source ];
37555
- let loader = parser.textureLoader;
37556
- if ( source.uri ) {
37557
- const handler = parser.options.manager.getHandler( source.uri );
37558
- if ( handler !== null ) loader = handler;
37559
- }
37560
- return parser.loadTextureImage( textureIndex, extension.source, loader );
37561
- }
37562
- }
37563
- class GLTFMeshoptCompression {
37564
- constructor( parser ) {
37565
- this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
37566
- this.parser = parser;
37567
- }
37568
- loadBufferView( index ) {
37569
- const json = this.parser.json;
37570
- const bufferView = json.bufferViews[ index ];
37571
- if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
37572
- const extensionDef = bufferView.extensions[ this.name ];
37573
- const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
37574
- const decoder = this.parser.options.meshoptDecoder;
37575
- if ( ! decoder || ! decoder.supported ) {
37576
- if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
37577
- throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
37578
- } else {
37579
- return null;
37580
- }
37581
- }
37582
- return buffer.then( function ( res ) {
37583
- const byteOffset = extensionDef.byteOffset || 0;
37584
- const byteLength = extensionDef.byteLength || 0;
37585
- const count = extensionDef.count;
37586
- const stride = extensionDef.byteStride;
37587
- const source = new Uint8Array( res, byteOffset, byteLength );
37588
- if ( decoder.decodeGltfBufferAsync ) {
37589
- return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
37590
- return res.buffer;
37591
- } );
37592
- } else {
37593
- return decoder.ready.then( function () {
37594
- const result = new ArrayBuffer( count * stride );
37595
- decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
37596
- return result;
37597
- } );
37598
- }
37599
- } );
37600
- } else {
37601
- return null;
37602
- }
37603
- }
37604
- }
37605
- class GLTFMeshGpuInstancing {
37606
- constructor( parser ) {
37607
- this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
37608
- this.parser = parser;
37609
- }
37610
- createNodeMesh( nodeIndex ) {
37611
- const json = this.parser.json;
37612
- const nodeDef = json.nodes[ nodeIndex ];
37613
- if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] ||
37614
- nodeDef.mesh === undefined ) {
37615
- return null;
37616
- }
37617
- const meshDef = json.meshes[ nodeDef.mesh ];
37618
- for ( const primitive of meshDef.primitives ) {
37619
- if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
37620
- primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
37621
- primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
37622
- primitive.mode !== undefined ) {
37623
- return null;
37624
- }
37625
- }
37626
- const extensionDef = nodeDef.extensions[ this.name ];
37627
- const attributesDef = extensionDef.attributes;
37628
- const pending = [];
37629
- const attributes = {};
37630
- for ( const key in attributesDef ) {
37631
- pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
37632
- attributes[ key ] = accessor;
37633
- return attributes[ key ];
37634
- } ) );
37635
- }
37636
- if ( pending.length < 1 ) {
37637
- return null;
37638
- }
37639
- pending.push( this.parser.createNodeMesh( nodeIndex ) );
37640
- return Promise.all( pending ).then( results => {
37641
- const nodeObject = results.pop();
37642
- const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
37643
- const count = results[ 0 ].count;
37644
- const instancedMeshes = [];
37645
- for ( const mesh of meshes ) {
37646
- const m = new Matrix4();
37647
- const p = new Vector3();
37648
- const q = new Quaternion();
37649
- const s = new Vector3( 1, 1, 1 );
37650
- const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count );
37651
- for ( let i = 0; i < count; i ++ ) {
37652
- if ( attributes.TRANSLATION ) {
37653
- p.fromBufferAttribute( attributes.TRANSLATION, i );
37654
- }
37655
- if ( attributes.ROTATION ) {
37656
- q.fromBufferAttribute( attributes.ROTATION, i );
37657
- }
37658
- if ( attributes.SCALE ) {
37659
- s.fromBufferAttribute( attributes.SCALE, i );
37660
- }
37661
- instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
37662
- }
37663
- for ( const attributeName in attributes ) {
37664
- if ( attributeName === '_COLOR_0' ) {
37665
- const attr = attributes[ attributeName ];
37666
- instancedMesh.instanceColor = new InstancedBufferAttribute( attr.array, attr.itemSize, attr.normalized );
37667
- } else if ( attributeName !== 'TRANSLATION' &&
37668
- attributeName !== 'ROTATION' &&
37669
- attributeName !== 'SCALE' ) {
37670
- mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
37671
- }
37672
- }
37673
- Object3D.prototype.copy.call( instancedMesh, mesh );
37674
- this.parser.assignFinalMaterial( instancedMesh );
37675
- instancedMeshes.push( instancedMesh );
37676
- }
37677
- if ( nodeObject.isGroup ) {
37678
- nodeObject.clear();
37679
- nodeObject.add( ... instancedMeshes );
37680
- return nodeObject;
37681
- }
37682
- return instancedMeshes[ 0 ];
37683
- } );
37684
- }
37685
- }
37686
- const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
37687
- const BINARY_EXTENSION_HEADER_LENGTH = 12;
37688
- const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
37689
- class GLTFBinaryExtension {
37690
- constructor( data ) {
37691
- this.name = EXTENSIONS.KHR_BINARY_GLTF;
37692
- this.content = null;
37693
- this.body = null;
37694
- const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
37695
- const textDecoder = new TextDecoder();
37696
- this.header = {
37697
- magic: textDecoder.decode( new Uint8Array( data.slice( 0, 4 ) ) ),
37698
- version: headerView.getUint32( 4, true ),
37699
- length: headerView.getUint32( 8, true )
37700
- };
37701
- if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
37702
- throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
37703
- } else if ( this.header.version < 2.0 ) {
37704
- throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' );
37705
- }
37706
- const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
37707
- const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
37708
- let chunkIndex = 0;
37709
- while ( chunkIndex < chunkContentsLength ) {
37710
- const chunkLength = chunkView.getUint32( chunkIndex, true );
37711
- chunkIndex += 4;
37712
- const chunkType = chunkView.getUint32( chunkIndex, true );
37713
- chunkIndex += 4;
37714
- if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
37715
- const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
37716
- this.content = textDecoder.decode( contentArray );
37717
- } else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) {
37718
- const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
37719
- this.body = data.slice( byteOffset, byteOffset + chunkLength );
37720
- }
37721
- chunkIndex += chunkLength;
37722
- }
37723
- if ( this.content === null ) {
37724
- throw new Error( 'THREE.GLTFLoader: JSON content not found.' );
37725
- }
37726
- }
37727
- }
37728
- class GLTFDracoMeshCompressionExtension {
37729
- constructor( json, dracoLoader ) {
37730
- if ( ! dracoLoader ) {
37731
- throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
37732
- }
37733
- this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
37734
- this.json = json;
37735
- this.dracoLoader = dracoLoader;
37736
- this.dracoLoader.preload();
37737
- }
37738
- decodePrimitive( primitive, parser ) {
37739
- const json = this.json;
37740
- const dracoLoader = this.dracoLoader;
37741
- const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
37742
- const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
37743
- const threeAttributeMap = {};
37744
- const attributeNormalizedMap = {};
37745
- const attributeTypeMap = {};
37746
- for ( const attributeName in gltfAttributeMap ) {
37747
- const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
37748
- threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
37749
- }
37750
- for ( const attributeName in primitive.attributes ) {
37751
- const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
37752
- if ( gltfAttributeMap[ attributeName ] !== undefined ) {
37753
- const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
37754
- const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
37755
- attributeTypeMap[ threeAttributeName ] = componentType.name;
37756
- attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
37757
- }
37758
- }
37759
- return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
37760
- return new Promise( function ( resolve, reject ) {
37761
- dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
37762
- for ( const attributeName in geometry.attributes ) {
37763
- const attribute = geometry.attributes[ attributeName ];
37764
- const normalized = attributeNormalizedMap[ attributeName ];
37765
- if ( normalized !== undefined ) attribute.normalized = normalized;
37766
- }
37767
- resolve( geometry );
37768
- }, threeAttributeMap, attributeTypeMap, LinearSRGBColorSpace, reject );
37769
- } );
37770
- } );
37771
- }
37772
- }
37773
- class GLTFTextureTransformExtension {
37774
- constructor() {
37775
- this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
37776
- }
37777
- extendTexture( texture, transform ) {
37778
- if ( ( transform.texCoord === undefined || transform.texCoord === texture.channel )
37779
- && transform.offset === undefined
37780
- && transform.rotation === undefined
37781
- && transform.scale === undefined ) {
37782
- return texture;
37783
- }
37784
- texture = texture.clone();
37785
- if ( transform.texCoord !== undefined ) {
37786
- texture.channel = transform.texCoord;
37787
- }
37788
- if ( transform.offset !== undefined ) {
37789
- texture.offset.fromArray( transform.offset );
37790
- }
37791
- if ( transform.rotation !== undefined ) {
37792
- texture.rotation = transform.rotation;
37793
- }
37794
- if ( transform.scale !== undefined ) {
37795
- texture.repeat.fromArray( transform.scale );
37796
- }
37797
- texture.needsUpdate = true;
37798
- return texture;
37799
- }
37800
- }
37801
- class GLTFMeshQuantizationExtension {
37802
- constructor() {
37803
- this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
37804
- }
37805
- }
37806
- class GLTFCubicSplineInterpolant extends Interpolant {
37807
- constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
37808
- super( parameterPositions, sampleValues, sampleSize, resultBuffer );
37809
- }
37810
- copySampleValue_( index ) {
37811
- const result = this.resultBuffer,
37812
- values = this.sampleValues,
37813
- valueSize = this.valueSize,
37814
- offset = index * valueSize * 3 + valueSize;
37815
- for ( let i = 0; i !== valueSize; i ++ ) {
37816
- result[ i ] = values[ offset + i ];
37817
- }
37818
- return result;
37819
- }
37820
- interpolate_( i1, t0, t, t1 ) {
37821
- const result = this.resultBuffer;
37822
- const values = this.sampleValues;
37823
- const stride = this.valueSize;
37824
- const stride2 = stride * 2;
37825
- const stride3 = stride * 3;
37826
- const td = t1 - t0;
37827
- const p = ( t - t0 ) / td;
37828
- const pp = p * p;
37829
- const ppp = pp * p;
37830
- const offset1 = i1 * stride3;
37831
- const offset0 = offset1 - stride3;
37832
- const s2 = -2 * ppp + 3 * pp;
37833
- const s3 = ppp - pp;
37834
- const s0 = 1 - s2;
37835
- const s1 = s3 - pp + p;
37836
- for ( let i = 0; i !== stride; i ++ ) {
37837
- const p0 = values[ offset0 + i + stride ];
37838
- const m0 = values[ offset0 + i + stride2 ] * td;
37839
- const p1 = values[ offset1 + i + stride ];
37840
- const m1 = values[ offset1 + i ] * td;
37841
- result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
37842
- }
37843
- return result;
37844
- }
37845
- }
37846
- const _quaternion = new Quaternion();
37847
- class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
37848
- interpolate_( i1, t0, t, t1 ) {
37849
- const result = super.interpolate_( i1, t0, t, t1 );
37850
- _quaternion.fromArray( result ).normalize().toArray( result );
37851
- return result;
37852
- }
37853
- }
37854
- const WEBGL_CONSTANTS = {
37855
- POINTS: 0,
37856
- LINES: 1,
37857
- LINE_LOOP: 2,
37858
- LINE_STRIP: 3,
37859
- TRIANGLES: 4,
37860
- TRIANGLE_STRIP: 5,
37861
- TRIANGLE_FAN: 6};
37862
- const WEBGL_COMPONENT_TYPES = {
37863
- 5120: Int8Array,
37864
- 5121: Uint8Array,
37865
- 5122: Int16Array,
37866
- 5123: Uint16Array,
37867
- 5125: Uint32Array,
37868
- 5126: Float32Array
37869
- };
37870
- const WEBGL_FILTERS = {
37871
- 9728: NearestFilter,
37872
- 9729: LinearFilter,
37873
- 9984: NearestMipmapNearestFilter,
37874
- 9985: LinearMipmapNearestFilter,
37875
- 9986: NearestMipmapLinearFilter,
37876
- 9987: LinearMipmapLinearFilter
37877
- };
37878
- const WEBGL_WRAPPINGS = {
37879
- 33071: ClampToEdgeWrapping,
37880
- 33648: MirroredRepeatWrapping,
37881
- 10497: RepeatWrapping
37882
- };
37883
- const WEBGL_TYPE_SIZES = {
37884
- 'SCALAR': 1,
37885
- 'VEC2': 2,
37886
- 'VEC3': 3,
37887
- 'VEC4': 4,
37888
- 'MAT2': 4,
37889
- 'MAT3': 9,
37890
- 'MAT4': 16
37891
- };
37892
- const ATTRIBUTES = {
37893
- POSITION: 'position',
37894
- NORMAL: 'normal',
37895
- TANGENT: 'tangent',
37896
- TEXCOORD_0: 'uv',
37897
- TEXCOORD_1: 'uv1',
37898
- TEXCOORD_2: 'uv2',
37899
- TEXCOORD_3: 'uv3',
37900
- COLOR_0: 'color',
37901
- WEIGHTS_0: 'skinWeight',
37902
- JOINTS_0: 'skinIndex',
37903
- };
37904
- const PATH_PROPERTIES = {
37905
- scale: 'scale',
37906
- translation: 'position',
37907
- rotation: 'quaternion',
37908
- weights: 'morphTargetInfluences'
37909
- };
37910
- const INTERPOLATION = {
37911
- CUBICSPLINE: undefined,
37912
- LINEAR: InterpolateLinear,
37913
- STEP: InterpolateDiscrete
37914
- };
37915
- const ALPHA_MODES = {
37916
- OPAQUE: 'OPAQUE',
37917
- MASK: 'MASK',
37918
- BLEND: 'BLEND'
37919
- };
37920
- function createDefaultMaterial( cache ) {
37921
- if ( cache[ 'DefaultMaterial' ] === undefined ) {
37922
- cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( {
37923
- color: 0xFFFFFF,
37924
- emissive: 0x000000,
37925
- metalness: 1,
37926
- roughness: 1,
37927
- transparent: false,
37928
- depthTest: true,
37929
- side: FrontSide
37930
- } );
37931
- }
37932
- return cache[ 'DefaultMaterial' ];
37933
- }
37934
- function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
37935
- for ( const name in objectDef.extensions ) {
37936
- if ( knownExtensions[ name ] === undefined ) {
37937
- object.userData.gltfExtensions = object.userData.gltfExtensions || {};
37938
- object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ];
37939
- }
37940
- }
37941
- }
37942
- function assignExtrasToUserData( object, gltfDef ) {
37943
- if ( gltfDef.extras !== undefined ) {
37944
- if ( typeof gltfDef.extras === 'object' ) {
37945
- Object.assign( object.userData, gltfDef.extras );
37946
- } else {
37947
- console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras );
37948
- }
37949
- }
37950
- }
37951
- function addMorphTargets( geometry, targets, parser ) {
37952
- let hasMorphPosition = false;
37953
- let hasMorphNormal = false;
37954
- let hasMorphColor = false;
37955
- for ( let i = 0, il = targets.length; i < il; i ++ ) {
37956
- const target = targets[ i ];
37957
- if ( target.POSITION !== undefined ) hasMorphPosition = true;
37958
- if ( target.NORMAL !== undefined ) hasMorphNormal = true;
37959
- if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
37960
- if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
37961
- }
37962
- if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
37963
- const pendingPositionAccessors = [];
37964
- const pendingNormalAccessors = [];
37965
- const pendingColorAccessors = [];
37966
- for ( let i = 0, il = targets.length; i < il; i ++ ) {
37967
- const target = targets[ i ];
37968
- if ( hasMorphPosition ) {
37969
- const pendingAccessor = target.POSITION !== undefined
37970
- ? parser.getDependency( 'accessor', target.POSITION )
37971
- : geometry.attributes.position;
37972
- pendingPositionAccessors.push( pendingAccessor );
37973
- }
37974
- if ( hasMorphNormal ) {
37975
- const pendingAccessor = target.NORMAL !== undefined
37976
- ? parser.getDependency( 'accessor', target.NORMAL )
37977
- : geometry.attributes.normal;
37978
- pendingNormalAccessors.push( pendingAccessor );
37979
- }
37980
- if ( hasMorphColor ) {
37981
- const pendingAccessor = target.COLOR_0 !== undefined
37982
- ? parser.getDependency( 'accessor', target.COLOR_0 )
37983
- : geometry.attributes.color;
37984
- pendingColorAccessors.push( pendingAccessor );
37985
- }
37986
- }
37987
- return Promise.all( [
37988
- Promise.all( pendingPositionAccessors ),
37989
- Promise.all( pendingNormalAccessors ),
37990
- Promise.all( pendingColorAccessors )
37991
- ] ).then( function ( accessors ) {
37992
- const morphPositions = accessors[ 0 ];
37993
- const morphNormals = accessors[ 1 ];
37994
- const morphColors = accessors[ 2 ];
37995
- if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
37996
- if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
37997
- if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
37998
- geometry.morphTargetsRelative = true;
37999
- return geometry;
38000
- } );
38001
- }
38002
- function updateMorphTargets( mesh, meshDef ) {
38003
- mesh.updateMorphTargets();
38004
- if ( meshDef.weights !== undefined ) {
38005
- for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
38006
- mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ];
38007
- }
38008
- }
38009
- if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
38010
- const targetNames = meshDef.extras.targetNames;
38011
- if ( mesh.morphTargetInfluences.length === targetNames.length ) {
38012
- mesh.morphTargetDictionary = {};
38013
- for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
38014
- mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
38015
- }
38016
- } else {
38017
- console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' );
38018
- }
38019
- }
38020
- }
38021
- function createPrimitiveKey( primitiveDef ) {
38022
- let geometryKey;
38023
- const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
38024
- if ( dracoExtension ) {
38025
- geometryKey = 'draco:' + dracoExtension.bufferView
38026
- + ':' + dracoExtension.indices
38027
- + ':' + createAttributesKey( dracoExtension.attributes );
38028
- } else {
38029
- geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode;
38030
- }
38031
- if ( primitiveDef.targets !== undefined ) {
38032
- for ( let i = 0, il = primitiveDef.targets.length; i < il; i ++ ) {
38033
- geometryKey += ':' + createAttributesKey( primitiveDef.targets[ i ] );
38034
- }
38035
- }
38036
- return geometryKey;
38037
- }
38038
- function createAttributesKey( attributes ) {
38039
- let attributesKey = '';
38040
- const keys = Object.keys( attributes ).sort();
38041
- for ( let i = 0, il = keys.length; i < il; i ++ ) {
38042
- attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
38043
- }
38044
- return attributesKey;
38045
- }
38046
- function getNormalizedComponentScale( constructor ) {
38047
- switch ( constructor ) {
38048
- case Int8Array:
38049
- return 1 / 127;
38050
- case Uint8Array:
38051
- return 1 / 255;
38052
- case Int16Array:
38053
- return 1 / 32767;
38054
- case Uint16Array:
38055
- return 1 / 65535;
38056
- default:
38057
- throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
38058
- }
38059
- }
38060
- function getImageURIMimeType( uri ) {
38061
- if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
38062
- if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
38063
- if ( uri.search( /\.ktx2($|\?)/i ) > 0 || uri.search( /^data\:image\/ktx2/ ) === 0 ) return 'image/ktx2';
38064
- return 'image/png';
38065
- }
38066
- const _identityMatrix = new Matrix4();
38067
- class GLTFParser {
38068
- constructor( json = {}, options = {} ) {
38069
- this.json = json;
38070
- this.extensions = {};
38071
- this.plugins = {};
38072
- this.options = options;
38073
- this.cache = new GLTFRegistry();
38074
- this.associations = new Map();
38075
- this.primitiveCache = {};
38076
- this.nodeCache = {};
38077
- this.meshCache = { refs: {}, uses: {} };
38078
- this.cameraCache = { refs: {}, uses: {} };
38079
- this.lightCache = { refs: {}, uses: {} };
38080
- this.sourceCache = {};
38081
- this.textureCache = {};
38082
- this.nodeNamesUsed = {};
38083
- let isSafari = false;
38084
- let safariVersion = -1;
38085
- let isFirefox = false;
38086
- let firefoxVersion = -1;
38087
- if ( typeof navigator !== 'undefined' ) {
38088
- const userAgent = navigator.userAgent;
38089
- isSafari = /^((?!chrome|android).)*safari/i.test( userAgent ) === true;
38090
- const safariMatch = userAgent.match( /Version\/(\d+)/ );
38091
- safariVersion = isSafari && safariMatch ? parseInt( safariMatch[ 1 ], 10 ) : -1;
38092
- isFirefox = userAgent.indexOf( 'Firefox' ) > -1;
38093
- firefoxVersion = isFirefox ? userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : -1;
38094
- }
38095
- if ( typeof createImageBitmap === 'undefined' || ( isSafari && safariVersion < 17 ) || ( isFirefox && firefoxVersion < 98 ) ) {
38096
- this.textureLoader = new TextureLoader( this.options.manager );
38097
- } else {
38098
- this.textureLoader = new ImageBitmapLoader( this.options.manager );
38099
- }
38100
- this.textureLoader.setCrossOrigin( this.options.crossOrigin );
38101
- this.textureLoader.setRequestHeader( this.options.requestHeader );
38102
- this.fileLoader = new FileLoader( this.options.manager );
38103
- this.fileLoader.setResponseType( 'arraybuffer' );
38104
- if ( this.options.crossOrigin === 'use-credentials' ) {
38105
- this.fileLoader.setWithCredentials( true );
38106
- }
38107
- }
38108
- setExtensions( extensions ) {
38109
- this.extensions = extensions;
38110
- }
38111
- setPlugins( plugins ) {
38112
- this.plugins = plugins;
38113
- }
38114
- parse( onLoad, onError ) {
38115
- const parser = this;
38116
- const json = this.json;
38117
- const extensions = this.extensions;
38118
- this.cache.removeAll();
38119
- this.nodeCache = {};
38120
- this._invokeAll( function ( ext ) {
38121
- return ext._markDefs && ext._markDefs();
38122
- } );
38123
- Promise.all( this._invokeAll( function ( ext ) {
38124
- return ext.beforeRoot && ext.beforeRoot();
38125
- } ) ).then( function () {
38126
- return Promise.all( [
38127
- parser.getDependencies( 'scene' ),
38128
- parser.getDependencies( 'animation' ),
38129
- parser.getDependencies( 'camera' ),
38130
- ] );
38131
- } ).then( function ( dependencies ) {
38132
- const result = {
38133
- scene: dependencies[ 0 ][ json.scene || 0 ],
38134
- scenes: dependencies[ 0 ],
38135
- animations: dependencies[ 1 ],
38136
- cameras: dependencies[ 2 ],
38137
- asset: json.asset,
38138
- parser: parser,
38139
- userData: {}
38140
- };
38141
- addUnknownExtensionsToUserData( extensions, result, json );
38142
- assignExtrasToUserData( result, json );
38143
- return Promise.all( parser._invokeAll( function ( ext ) {
38144
- return ext.afterRoot && ext.afterRoot( result );
38145
- } ) ).then( function () {
38146
- for ( const scene of result.scenes ) {
38147
- scene.updateMatrixWorld();
38148
- }
38149
- onLoad( result );
38150
- } );
38151
- } ).catch( onError );
38152
- }
38153
- _markDefs() {
38154
- const nodeDefs = this.json.nodes || [];
38155
- const skinDefs = this.json.skins || [];
38156
- const meshDefs = this.json.meshes || [];
38157
- for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
38158
- const joints = skinDefs[ skinIndex ].joints;
38159
- for ( let i = 0, il = joints.length; i < il; i ++ ) {
38160
- nodeDefs[ joints[ i ] ].isBone = true;
38161
- }
38162
- }
38163
- for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
38164
- const nodeDef = nodeDefs[ nodeIndex ];
38165
- if ( nodeDef.mesh !== undefined ) {
38166
- this._addNodeRef( this.meshCache, nodeDef.mesh );
38167
- if ( nodeDef.skin !== undefined ) {
38168
- meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
38169
- }
38170
- }
38171
- if ( nodeDef.camera !== undefined ) {
38172
- this._addNodeRef( this.cameraCache, nodeDef.camera );
38173
- }
38174
- }
38175
- }
38176
- _addNodeRef( cache, index ) {
38177
- if ( index === undefined ) return;
38178
- if ( cache.refs[ index ] === undefined ) {
38179
- cache.refs[ index ] = cache.uses[ index ] = 0;
38180
- }
38181
- cache.refs[ index ] ++;
38182
- }
38183
- _getNodeRef( cache, index, object ) {
38184
- if ( cache.refs[ index ] <= 1 ) return object;
38185
- const ref = object.clone();
38186
- const updateMappings = ( original, clone ) => {
38187
- const mappings = this.associations.get( original );
38188
- if ( mappings != null ) {
38189
- this.associations.set( clone, mappings );
38190
- }
38191
- for ( const [ i, child ] of original.children.entries() ) {
38192
- updateMappings( child, clone.children[ i ] );
38193
- }
38194
- };
38195
- updateMappings( object, ref );
38196
- ref.name += '_instance_' + ( cache.uses[ index ] ++ );
38197
- return ref;
38198
- }
38199
- _invokeOne( func ) {
38200
- const extensions = Object.values( this.plugins );
38201
- extensions.push( this );
38202
- for ( let i = 0; i < extensions.length; i ++ ) {
38203
- const result = func( extensions[ i ] );
38204
- if ( result ) return result;
38205
- }
38206
- return null;
38207
- }
38208
- _invokeAll( func ) {
38209
- const extensions = Object.values( this.plugins );
38210
- extensions.unshift( this );
38211
- const pending = [];
38212
- for ( let i = 0; i < extensions.length; i ++ ) {
38213
- const result = func( extensions[ i ] );
38214
- if ( result ) pending.push( result );
38215
- }
38216
- return pending;
38217
- }
38218
- getDependency( type, index ) {
38219
- const cacheKey = type + ':' + index;
38220
- let dependency = this.cache.get( cacheKey );
38221
- if ( ! dependency ) {
38222
- switch ( type ) {
38223
- case 'scene':
38224
- dependency = this.loadScene( index );
38225
- break;
38226
- case 'node':
38227
- dependency = this._invokeOne( function ( ext ) {
38228
- return ext.loadNode && ext.loadNode( index );
38229
- } );
38230
- break;
38231
- case 'mesh':
38232
- dependency = this._invokeOne( function ( ext ) {
38233
- return ext.loadMesh && ext.loadMesh( index );
38234
- } );
38235
- break;
38236
- case 'accessor':
38237
- dependency = this.loadAccessor( index );
38238
- break;
38239
- case 'bufferView':
38240
- dependency = this._invokeOne( function ( ext ) {
38241
- return ext.loadBufferView && ext.loadBufferView( index );
38242
- } );
38243
- break;
38244
- case 'buffer':
38245
- dependency = this.loadBuffer( index );
38246
- break;
38247
- case 'material':
38248
- dependency = this._invokeOne( function ( ext ) {
38249
- return ext.loadMaterial && ext.loadMaterial( index );
38250
- } );
38251
- break;
38252
- case 'texture':
38253
- dependency = this._invokeOne( function ( ext ) {
38254
- return ext.loadTexture && ext.loadTexture( index );
38255
- } );
38256
- break;
38257
- case 'skin':
38258
- dependency = this.loadSkin( index );
38259
- break;
38260
- case 'animation':
38261
- dependency = this._invokeOne( function ( ext ) {
38262
- return ext.loadAnimation && ext.loadAnimation( index );
38263
- } );
38264
- break;
38265
- case 'camera':
38266
- dependency = this.loadCamera( index );
38267
- break;
38268
- default:
38269
- dependency = this._invokeOne( function ( ext ) {
38270
- return ext != this && ext.getDependency && ext.getDependency( type, index );
38271
- } );
38272
- if ( ! dependency ) {
38273
- throw new Error( 'Unknown type: ' + type );
38274
- }
38275
- break;
38276
- }
38277
- this.cache.add( cacheKey, dependency );
38278
- }
38279
- return dependency;
38280
- }
38281
- getDependencies( type ) {
38282
- let dependencies = this.cache.get( type );
38283
- if ( ! dependencies ) {
38284
- const parser = this;
38285
- const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
38286
- dependencies = Promise.all( defs.map( function ( def, index ) {
38287
- return parser.getDependency( type, index );
38288
- } ) );
38289
- this.cache.add( type, dependencies );
38290
- }
38291
- return dependencies;
38292
- }
38293
- loadBuffer( bufferIndex ) {
38294
- const bufferDef = this.json.buffers[ bufferIndex ];
38295
- const loader = this.fileLoader;
38296
- if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
38297
- throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
38298
- }
38299
- if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
38300
- return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
38301
- }
38302
- const options = this.options;
38303
- return new Promise( function ( resolve, reject ) {
38304
- loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
38305
- reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
38306
- } );
38307
- } );
38308
- }
38309
- loadBufferView( bufferViewIndex ) {
38310
- const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
38311
- return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
38312
- const byteLength = bufferViewDef.byteLength || 0;
38313
- const byteOffset = bufferViewDef.byteOffset || 0;
38314
- return buffer.slice( byteOffset, byteOffset + byteLength );
38315
- } );
38316
- }
38317
- loadAccessor( accessorIndex ) {
38318
- const parser = this;
38319
- const json = this.json;
38320
- const accessorDef = this.json.accessors[ accessorIndex ];
38321
- if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
38322
- const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
38323
- const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
38324
- const normalized = accessorDef.normalized === true;
38325
- const array = new TypedArray( accessorDef.count * itemSize );
38326
- return Promise.resolve( new BufferAttribute( array, itemSize, normalized ) );
38327
- }
38328
- const pendingBufferViews = [];
38329
- if ( accessorDef.bufferView !== undefined ) {
38330
- pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
38331
- } else {
38332
- pendingBufferViews.push( null );
38333
- }
38334
- if ( accessorDef.sparse !== undefined ) {
38335
- pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) );
38336
- pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) );
38337
- }
38338
- return Promise.all( pendingBufferViews ).then( function ( bufferViews ) {
38339
- const bufferView = bufferViews[ 0 ];
38340
- const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
38341
- const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
38342
- const elementBytes = TypedArray.BYTES_PER_ELEMENT;
38343
- const itemBytes = elementBytes * itemSize;
38344
- const byteOffset = accessorDef.byteOffset || 0;
38345
- const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
38346
- const normalized = accessorDef.normalized === true;
38347
- let array, bufferAttribute;
38348
- if ( byteStride && byteStride !== itemBytes ) {
38349
- const ibSlice = Math.floor( byteOffset / byteStride );
38350
- const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
38351
- let ib = parser.cache.get( ibCacheKey );
38352
- if ( ! ib ) {
38353
- array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
38354
- ib = new InterleavedBuffer( array, byteStride / elementBytes );
38355
- parser.cache.add( ibCacheKey, ib );
38356
- }
38357
- bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
38358
- } else {
38359
- if ( bufferView === null ) {
38360
- array = new TypedArray( accessorDef.count * itemSize );
38361
- } else {
38362
- array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
38363
- }
38364
- bufferAttribute = new BufferAttribute( array, itemSize, normalized );
38365
- }
38366
- if ( accessorDef.sparse !== undefined ) {
38367
- const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
38368
- const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ];
38369
- const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
38370
- const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
38371
- const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
38372
- const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
38373
- if ( bufferView !== null ) {
38374
- bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
38375
- }
38376
- bufferAttribute.normalized = false;
38377
- for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) {
38378
- const index = sparseIndices[ i ];
38379
- bufferAttribute.setX( index, sparseValues[ i * itemSize ] );
38380
- if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] );
38381
- if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] );
38382
- if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] );
38383
- if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' );
38384
- }
38385
- bufferAttribute.normalized = normalized;
38386
- }
38387
- return bufferAttribute;
38388
- } );
38389
- }
38390
- loadTexture( textureIndex ) {
38391
- const json = this.json;
38392
- const options = this.options;
38393
- const textureDef = json.textures[ textureIndex ];
38394
- const sourceIndex = textureDef.source;
38395
- const sourceDef = json.images[ sourceIndex ];
38396
- let loader = this.textureLoader;
38397
- if ( sourceDef.uri ) {
38398
- const handler = options.manager.getHandler( sourceDef.uri );
38399
- if ( handler !== null ) loader = handler;
38400
- }
38401
- return this.loadTextureImage( textureIndex, sourceIndex, loader );
38402
- }
38403
- loadTextureImage( textureIndex, sourceIndex, loader ) {
38404
- const parser = this;
38405
- const json = this.json;
38406
- const textureDef = json.textures[ textureIndex ];
38407
- const sourceDef = json.images[ sourceIndex ];
38408
- const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
38409
- if ( this.textureCache[ cacheKey ] ) {
38410
- return this.textureCache[ cacheKey ];
38411
- }
38412
- const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
38413
- texture.flipY = false;
38414
- texture.name = textureDef.name || sourceDef.name || '';
38415
- if ( texture.name === '' && typeof sourceDef.uri === 'string' && sourceDef.uri.startsWith( 'data:image/' ) === false ) {
38416
- texture.name = sourceDef.uri;
38417
- }
38418
- const samplers = json.samplers || {};
38419
- const sampler = samplers[ textureDef.sampler ] || {};
38420
- texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
38421
- texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
38422
- texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
38423
- texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
38424
- texture.generateMipmaps = ! texture.isCompressedTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
38425
- parser.associations.set( texture, { textures: textureIndex } );
38426
- return texture;
38427
- } ).catch( function () {
38428
- return null;
38429
- } );
38430
- this.textureCache[ cacheKey ] = promise;
38431
- return promise;
38432
- }
38433
- loadImageSource( sourceIndex, loader ) {
38434
- const parser = this;
38435
- const json = this.json;
38436
- const options = this.options;
38437
- if ( this.sourceCache[ sourceIndex ] !== undefined ) {
38438
- return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() );
38439
- }
38440
- const sourceDef = json.images[ sourceIndex ];
38441
- const URL = self.URL || self.webkitURL;
38442
- let sourceURI = sourceDef.uri || '';
38443
- let isObjectURL = false;
38444
- if ( sourceDef.bufferView !== undefined ) {
38445
- sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
38446
- isObjectURL = true;
38447
- const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } );
38448
- sourceURI = URL.createObjectURL( blob );
38449
- return sourceURI;
38450
- } );
38451
- } else if ( sourceDef.uri === undefined ) {
38452
- throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
38453
- }
38454
- const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
38455
- return new Promise( function ( resolve, reject ) {
38456
- let onLoad = resolve;
38457
- if ( loader.isImageBitmapLoader === true ) {
38458
- onLoad = function ( imageBitmap ) {
38459
- const texture = new Texture( imageBitmap );
38460
- texture.needsUpdate = true;
38461
- resolve( texture );
38462
- };
38463
- }
38464
- loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
38465
- } );
38466
- } ).then( function ( texture ) {
38467
- if ( isObjectURL === true ) {
38468
- URL.revokeObjectURL( sourceURI );
38469
- }
38470
- assignExtrasToUserData( texture, sourceDef );
38471
- texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri );
38472
- return texture;
38473
- } ).catch( function ( error ) {
38474
- console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
38475
- throw error;
38476
- } );
38477
- this.sourceCache[ sourceIndex ] = promise;
38478
- return promise;
38479
- }
38480
- assignTexture( materialParams, mapName, mapDef, colorSpace ) {
38481
- const parser = this;
38482
- return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
38483
- if ( ! texture ) return null;
38484
- if ( mapDef.texCoord !== undefined && mapDef.texCoord > 0 ) {
38485
- texture = texture.clone();
38486
- texture.channel = mapDef.texCoord;
38487
- }
38488
- if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
38489
- const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
38490
- if ( transform ) {
38491
- const gltfReference = parser.associations.get( texture );
38492
- texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
38493
- parser.associations.set( texture, gltfReference );
38494
- }
38495
- }
38496
- if ( colorSpace !== undefined ) {
38497
- texture.colorSpace = colorSpace;
38498
- }
38499
- materialParams[ mapName ] = texture;
38500
- return texture;
38501
- } );
38502
- }
38503
- assignFinalMaterial( mesh ) {
38504
- const geometry = mesh.geometry;
38505
- let material = mesh.material;
38506
- const useDerivativeTangents = geometry.attributes.tangent === undefined;
38507
- const useVertexColors = geometry.attributes.color !== undefined;
38508
- const useFlatShading = geometry.attributes.normal === undefined;
38509
- if ( mesh.isPoints ) {
38510
- const cacheKey = 'PointsMaterial:' + material.uuid;
38511
- let pointsMaterial = this.cache.get( cacheKey );
38512
- if ( ! pointsMaterial ) {
38513
- pointsMaterial = new PointsMaterial();
38514
- Material.prototype.copy.call( pointsMaterial, material );
38515
- pointsMaterial.color.copy( material.color );
38516
- pointsMaterial.map = material.map;
38517
- pointsMaterial.sizeAttenuation = false;
38518
- this.cache.add( cacheKey, pointsMaterial );
38519
- }
38520
- material = pointsMaterial;
38521
- } else if ( mesh.isLine ) {
38522
- const cacheKey = 'LineBasicMaterial:' + material.uuid;
38523
- let lineMaterial = this.cache.get( cacheKey );
38524
- if ( ! lineMaterial ) {
38525
- lineMaterial = new LineBasicMaterial();
38526
- Material.prototype.copy.call( lineMaterial, material );
38527
- lineMaterial.color.copy( material.color );
38528
- lineMaterial.map = material.map;
38529
- this.cache.add( cacheKey, lineMaterial );
38530
- }
38531
- material = lineMaterial;
38532
- }
38533
- if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
38534
- let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
38535
- if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
38536
- if ( useVertexColors ) cacheKey += 'vertex-colors:';
38537
- if ( useFlatShading ) cacheKey += 'flat-shading:';
38538
- let cachedMaterial = this.cache.get( cacheKey );
38539
- if ( ! cachedMaterial ) {
38540
- cachedMaterial = material.clone();
38541
- if ( useVertexColors ) cachedMaterial.vertexColors = true;
38542
- if ( useFlatShading ) cachedMaterial.flatShading = true;
38543
- if ( useDerivativeTangents ) {
38544
- if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= -1;
38545
- if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= -1;
38546
- }
38547
- this.cache.add( cacheKey, cachedMaterial );
38548
- this.associations.set( cachedMaterial, this.associations.get( material ) );
38549
- }
38550
- material = cachedMaterial;
38551
- }
38552
- mesh.material = material;
38553
- }
38554
- getMaterialType( ) {
38555
- return MeshStandardMaterial;
38556
- }
38557
- loadMaterial( materialIndex ) {
38558
- const parser = this;
38559
- const json = this.json;
38560
- const extensions = this.extensions;
38561
- const materialDef = json.materials[ materialIndex ];
38562
- let materialType;
38563
- const materialParams = {};
38564
- const materialExtensions = materialDef.extensions || {};
38565
- const pending = [];
38566
- if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
38567
- const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
38568
- materialType = kmuExtension.getMaterialType();
38569
- pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );
38570
- } else {
38571
- const metallicRoughness = materialDef.pbrMetallicRoughness || {};
38572
- materialParams.color = new Color( 1.0, 1.0, 1.0 );
38573
- materialParams.opacity = 1.0;
38574
- if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
38575
- const array = metallicRoughness.baseColorFactor;
38576
- materialParams.color.setRGB( array[ 0 ], array[ 1 ], array[ 2 ], LinearSRGBColorSpace );
38577
- materialParams.opacity = array[ 3 ];
38578
- }
38579
- if ( metallicRoughness.baseColorTexture !== undefined ) {
38580
- pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, SRGBColorSpace ) );
38581
- }
38582
- materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
38583
- materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
38584
- if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
38585
- pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
38586
- pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
38587
- }
38588
- materialType = this._invokeOne( function ( ext ) {
38589
- return ext.getMaterialType && ext.getMaterialType( materialIndex );
38590
- } );
38591
- pending.push( Promise.all( this._invokeAll( function ( ext ) {
38592
- return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams );
38593
- } ) ) );
38594
- }
38595
- if ( materialDef.doubleSided === true ) {
38596
- materialParams.side = DoubleSide;
38597
- }
38598
- const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
38599
- if ( alphaMode === ALPHA_MODES.BLEND ) {
38600
- materialParams.transparent = true;
38601
- materialParams.depthWrite = false;
38602
- } else {
38603
- materialParams.transparent = false;
38604
- if ( alphaMode === ALPHA_MODES.MASK ) {
38605
- materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
38606
- }
38607
- }
38608
- if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) {
38609
- pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
38610
- materialParams.normalScale = new Vector2( 1, 1 );
38611
- if ( materialDef.normalTexture.scale !== undefined ) {
38612
- const scale = materialDef.normalTexture.scale;
38613
- materialParams.normalScale.set( scale, scale );
38614
- }
38615
- }
38616
- if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) {
38617
- pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
38618
- if ( materialDef.occlusionTexture.strength !== undefined ) {
38619
- materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
38620
- }
38621
- }
38622
- if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
38623
- const emissiveFactor = materialDef.emissiveFactor;
38624
- materialParams.emissive = new Color().setRGB( emissiveFactor[ 0 ], emissiveFactor[ 1 ], emissiveFactor[ 2 ], LinearSRGBColorSpace );
38625
- }
38626
- if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) {
38627
- pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, SRGBColorSpace ) );
38628
- }
38629
- return Promise.all( pending ).then( function () {
38630
- const material = new materialType( materialParams );
38631
- if ( materialDef.name ) material.name = materialDef.name;
38632
- assignExtrasToUserData( material, materialDef );
38633
- parser.associations.set( material, { materials: materialIndex } );
38634
- if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
38635
- return material;
38636
- } );
38637
- }
38638
- createUniqueName( originalName ) {
38639
- const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' );
38640
- if ( sanitizedName in this.nodeNamesUsed ) {
38641
- return sanitizedName + '_' + ( ++ this.nodeNamesUsed[ sanitizedName ] );
38642
- } else {
38643
- this.nodeNamesUsed[ sanitizedName ] = 0;
38644
- return sanitizedName;
38645
- }
38646
- }
38647
- loadGeometries( primitives ) {
38648
- const parser = this;
38649
- const extensions = this.extensions;
38650
- const cache = this.primitiveCache;
38651
- function createDracoPrimitive( primitive ) {
38652
- return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]
38653
- .decodePrimitive( primitive, parser )
38654
- .then( function ( geometry ) {
38655
- return addPrimitiveAttributes( geometry, primitive, parser );
38656
- } );
38657
- }
38658
- const pending = [];
38659
- for ( let i = 0, il = primitives.length; i < il; i ++ ) {
38660
- const primitive = primitives[ i ];
38661
- const cacheKey = createPrimitiveKey( primitive );
38662
- const cached = cache[ cacheKey ];
38663
- if ( cached ) {
38664
- pending.push( cached.promise );
38665
- } else {
38666
- let geometryPromise;
38667
- if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
38668
- geometryPromise = createDracoPrimitive( primitive );
38669
- } else {
38670
- geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser );
38671
- }
38672
- cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise };
38673
- pending.push( geometryPromise );
38674
- }
38675
- }
38676
- return Promise.all( pending );
38677
- }
38678
- loadMesh( meshIndex ) {
38679
- const parser = this;
38680
- const json = this.json;
38681
- const extensions = this.extensions;
38682
- const meshDef = json.meshes[ meshIndex ];
38683
- const primitives = meshDef.primitives;
38684
- const pending = [];
38685
- for ( let i = 0, il = primitives.length; i < il; i ++ ) {
38686
- const material = primitives[ i ].material === undefined
38687
- ? createDefaultMaterial( this.cache )
38688
- : this.getDependency( 'material', primitives[ i ].material );
38689
- pending.push( material );
38690
- }
38691
- pending.push( parser.loadGeometries( primitives ) );
38692
- return Promise.all( pending ).then( function ( results ) {
38693
- const materials = results.slice( 0, results.length - 1 );
38694
- const geometries = results[ results.length - 1 ];
38695
- const meshes = [];
38696
- for ( let i = 0, il = geometries.length; i < il; i ++ ) {
38697
- const geometry = geometries[ i ];
38698
- const primitive = primitives[ i ];
38699
- let mesh;
38700
- const material = materials[ i ];
38701
- if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
38702
- primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
38703
- primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
38704
- primitive.mode === undefined ) {
38705
- mesh = meshDef.isSkinnedMesh === true
38706
- ? new SkinnedMesh( geometry, material )
38707
- : new Mesh( geometry, material );
38708
- if ( mesh.isSkinnedMesh === true ) {
38709
- mesh.normalizeSkinWeights();
38710
- }
38711
- if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {
38712
- mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode );
38713
- } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) {
38714
- mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode );
38715
- }
38716
- } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) {
38717
- mesh = new LineSegments( geometry, material );
38718
- } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) {
38719
- mesh = new Line$1( geometry, material );
38720
- } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) {
38721
- mesh = new LineLoop( geometry, material );
38722
- } else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) {
38723
- mesh = new Points( geometry, material );
38724
- } else {
38725
- throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode );
38726
- }
38727
- if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) {
38728
- updateMorphTargets( mesh, meshDef );
38729
- }
38730
- mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) );
38731
- assignExtrasToUserData( mesh, meshDef );
38732
- if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive );
38733
- parser.assignFinalMaterial( mesh );
38734
- meshes.push( mesh );
38735
- }
38736
- for ( let i = 0, il = meshes.length; i < il; i ++ ) {
38737
- parser.associations.set( meshes[ i ], {
38738
- meshes: meshIndex,
38739
- primitives: i
38740
- } );
38741
- }
38742
- if ( meshes.length === 1 ) {
38743
- if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, meshes[ 0 ], meshDef );
38744
- return meshes[ 0 ];
38745
- }
38746
- const group = new Group$1();
38747
- if ( meshDef.extensions ) addUnknownExtensionsToUserData( extensions, group, meshDef );
38748
- parser.associations.set( group, { meshes: meshIndex } );
38749
- for ( let i = 0, il = meshes.length; i < il; i ++ ) {
38750
- group.add( meshes[ i ] );
38751
- }
38752
- return group;
38753
- } );
38754
- }
38755
- loadCamera( cameraIndex ) {
38756
- let camera;
38757
- const cameraDef = this.json.cameras[ cameraIndex ];
38758
- const params = cameraDef[ cameraDef.type ];
38759
- if ( ! params ) {
38760
- console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
38761
- return;
38762
- }
38763
- if ( cameraDef.type === 'perspective' ) {
38764
- camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 );
38765
- } else if ( cameraDef.type === 'orthographic' ) {
38766
- camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar );
38767
- }
38768
- if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name );
38769
- assignExtrasToUserData( camera, cameraDef );
38770
- return Promise.resolve( camera );
38771
- }
38772
- loadSkin( skinIndex ) {
38773
- const skinDef = this.json.skins[ skinIndex ];
38774
- const pending = [];
38775
- for ( let i = 0, il = skinDef.joints.length; i < il; i ++ ) {
38776
- pending.push( this._loadNodeShallow( skinDef.joints[ i ] ) );
38777
- }
38778
- if ( skinDef.inverseBindMatrices !== undefined ) {
38779
- pending.push( this.getDependency( 'accessor', skinDef.inverseBindMatrices ) );
38780
- } else {
38781
- pending.push( null );
38782
- }
38783
- return Promise.all( pending ).then( function ( results ) {
38784
- const inverseBindMatrices = results.pop();
38785
- const jointNodes = results;
38786
- const bones = [];
38787
- const boneInverses = [];
38788
- for ( let i = 0, il = jointNodes.length; i < il; i ++ ) {
38789
- const jointNode = jointNodes[ i ];
38790
- if ( jointNode ) {
38791
- bones.push( jointNode );
38792
- const mat = new Matrix4();
38793
- if ( inverseBindMatrices !== null ) {
38794
- mat.fromArray( inverseBindMatrices.array, i * 16 );
38795
- }
38796
- boneInverses.push( mat );
38797
- } else {
38798
- console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinDef.joints[ i ] );
38799
- }
38800
- }
38801
- return new Skeleton( bones, boneInverses );
38802
- } );
38803
- }
38804
- loadAnimation( animationIndex ) {
38805
- const json = this.json;
38806
- const parser = this;
38807
- const animationDef = json.animations[ animationIndex ];
38808
- const animationName = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
38809
- const pendingNodes = [];
38810
- const pendingInputAccessors = [];
38811
- const pendingOutputAccessors = [];
38812
- const pendingSamplers = [];
38813
- const pendingTargets = [];
38814
- for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
38815
- const channel = animationDef.channels[ i ];
38816
- const sampler = animationDef.samplers[ channel.sampler ];
38817
- const target = channel.target;
38818
- const name = target.node;
38819
- const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
38820
- const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
38821
- if ( target.node === undefined ) continue;
38822
- pendingNodes.push( this.getDependency( 'node', name ) );
38823
- pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
38824
- pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
38825
- pendingSamplers.push( sampler );
38826
- pendingTargets.push( target );
38827
- }
38828
- return Promise.all( [
38829
- Promise.all( pendingNodes ),
38830
- Promise.all( pendingInputAccessors ),
38831
- Promise.all( pendingOutputAccessors ),
38832
- Promise.all( pendingSamplers ),
38833
- Promise.all( pendingTargets )
38834
- ] ).then( function ( dependencies ) {
38835
- const nodes = dependencies[ 0 ];
38836
- const inputAccessors = dependencies[ 1 ];
38837
- const outputAccessors = dependencies[ 2 ];
38838
- const samplers = dependencies[ 3 ];
38839
- const targets = dependencies[ 4 ];
38840
- const tracks = [];
38841
- for ( let i = 0, il = nodes.length; i < il; i ++ ) {
38842
- const node = nodes[ i ];
38843
- const inputAccessor = inputAccessors[ i ];
38844
- const outputAccessor = outputAccessors[ i ];
38845
- const sampler = samplers[ i ];
38846
- const target = targets[ i ];
38847
- if ( node === undefined ) continue;
38848
- if ( node.updateMatrix ) {
38849
- node.updateMatrix();
38850
- }
38851
- const createdTracks = parser._createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target );
38852
- if ( createdTracks ) {
38853
- for ( let k = 0; k < createdTracks.length; k ++ ) {
38854
- tracks.push( createdTracks[ k ] );
38855
- }
38856
- }
38857
- }
38858
- const animation = new AnimationClip( animationName, undefined, tracks );
38859
- assignExtrasToUserData( animation, animationDef );
38860
- return animation;
38861
- } );
38862
- }
38863
- createNodeMesh( nodeIndex ) {
38864
- const json = this.json;
38865
- const parser = this;
38866
- const nodeDef = json.nodes[ nodeIndex ];
38867
- if ( nodeDef.mesh === undefined ) return null;
38868
- return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
38869
- const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
38870
- if ( nodeDef.weights !== undefined ) {
38871
- node.traverse( function ( o ) {
38872
- if ( ! o.isMesh ) return;
38873
- for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
38874
- o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
38875
- }
38876
- } );
38877
- }
38878
- return node;
38879
- } );
38880
- }
38881
- loadNode( nodeIndex ) {
38882
- const json = this.json;
38883
- const parser = this;
38884
- const nodeDef = json.nodes[ nodeIndex ];
38885
- const nodePending = parser._loadNodeShallow( nodeIndex );
38886
- const childPending = [];
38887
- const childrenDef = nodeDef.children || [];
38888
- for ( let i = 0, il = childrenDef.length; i < il; i ++ ) {
38889
- childPending.push( parser.getDependency( 'node', childrenDef[ i ] ) );
38890
- }
38891
- const skeletonPending = nodeDef.skin === undefined
38892
- ? Promise.resolve( null )
38893
- : parser.getDependency( 'skin', nodeDef.skin );
38894
- return Promise.all( [
38895
- nodePending,
38896
- Promise.all( childPending ),
38897
- skeletonPending
38898
- ] ).then( function ( results ) {
38899
- const node = results[ 0 ];
38900
- const children = results[ 1 ];
38901
- const skeleton = results[ 2 ];
38902
- if ( skeleton !== null ) {
38903
- node.traverse( function ( mesh ) {
38904
- if ( ! mesh.isSkinnedMesh ) return;
38905
- mesh.bind( skeleton, _identityMatrix );
38906
- } );
38907
- }
38908
- for ( let i = 0, il = children.length; i < il; i ++ ) {
38909
- node.add( children[ i ] );
38910
- }
38911
- return node;
38912
- } );
38913
- }
38914
- _loadNodeShallow( nodeIndex ) {
38915
- const json = this.json;
38916
- const extensions = this.extensions;
38917
- const parser = this;
38918
- if ( this.nodeCache[ nodeIndex ] !== undefined ) {
38919
- return this.nodeCache[ nodeIndex ];
38920
- }
38921
- const nodeDef = json.nodes[ nodeIndex ];
38922
- const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
38923
- const pending = [];
38924
- const meshPromise = parser._invokeOne( function ( ext ) {
38925
- return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
38926
- } );
38927
- if ( meshPromise ) {
38928
- pending.push( meshPromise );
38929
- }
38930
- if ( nodeDef.camera !== undefined ) {
38931
- pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) {
38932
- return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera );
38933
- } ) );
38934
- }
38935
- parser._invokeAll( function ( ext ) {
38936
- return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex );
38937
- } ).forEach( function ( promise ) {
38938
- pending.push( promise );
38939
- } );
38940
- this.nodeCache[ nodeIndex ] = Promise.all( pending ).then( function ( objects ) {
38941
- let node;
38942
- if ( nodeDef.isBone === true ) {
38943
- node = new Bone();
38944
- } else if ( objects.length > 1 ) {
38945
- node = new Group$1();
38946
- } else if ( objects.length === 1 ) {
38947
- node = objects[ 0 ];
38948
- } else {
38949
- node = new Object3D();
38950
- }
38951
- if ( node !== objects[ 0 ] ) {
38952
- for ( let i = 0, il = objects.length; i < il; i ++ ) {
38953
- node.add( objects[ i ] );
38954
- }
38955
- }
38956
- if ( nodeDef.name ) {
38957
- node.userData.name = nodeDef.name;
38958
- node.name = nodeName;
38959
- }
38960
- assignExtrasToUserData( node, nodeDef );
38961
- if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
38962
- if ( nodeDef.matrix !== undefined ) {
38963
- const matrix = new Matrix4();
38964
- matrix.fromArray( nodeDef.matrix );
38965
- node.applyMatrix4( matrix );
38966
- } else {
38967
- if ( nodeDef.translation !== undefined ) {
38968
- node.position.fromArray( nodeDef.translation );
38969
- }
38970
- if ( nodeDef.rotation !== undefined ) {
38971
- node.quaternion.fromArray( nodeDef.rotation );
38972
- }
38973
- if ( nodeDef.scale !== undefined ) {
38974
- node.scale.fromArray( nodeDef.scale );
38975
- }
38976
- }
38977
- if ( ! parser.associations.has( node ) ) {
38978
- parser.associations.set( node, {} );
38979
- } else if ( nodeDef.mesh !== undefined && parser.meshCache.refs[ nodeDef.mesh ] > 1 ) {
38980
- const mapping = parser.associations.get( node );
38981
- parser.associations.set( node, { ...mapping } );
38982
- }
38983
- parser.associations.get( node ).nodes = nodeIndex;
38984
- return node;
38985
- } );
38986
- return this.nodeCache[ nodeIndex ];
38987
- }
38988
- loadScene( sceneIndex ) {
38989
- const extensions = this.extensions;
38990
- const sceneDef = this.json.scenes[ sceneIndex ];
38991
- const parser = this;
38992
- const scene = new Group$1();
38993
- if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
38994
- assignExtrasToUserData( scene, sceneDef );
38995
- if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
38996
- const nodeIds = sceneDef.nodes || [];
38997
- const pending = [];
38998
- for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
38999
- pending.push( parser.getDependency( 'node', nodeIds[ i ] ) );
39000
- }
39001
- return Promise.all( pending ).then( function ( nodes ) {
39002
- for ( let i = 0, il = nodes.length; i < il; i ++ ) {
39003
- scene.add( nodes[ i ] );
39004
- }
39005
- const reduceAssociations = ( node ) => {
39006
- const reducedAssociations = new Map();
39007
- for ( const [ key, value ] of parser.associations ) {
39008
- if ( key instanceof Material || key instanceof Texture ) {
39009
- reducedAssociations.set( key, value );
39010
- }
39011
- }
39012
- node.traverse( ( node ) => {
39013
- const mappings = parser.associations.get( node );
39014
- if ( mappings != null ) {
39015
- reducedAssociations.set( node, mappings );
39016
- }
39017
- } );
39018
- return reducedAssociations;
39019
- };
39020
- parser.associations = reduceAssociations( scene );
39021
- return scene;
39022
- } );
39023
- }
39024
- _createAnimationTracks( node, inputAccessor, outputAccessor, sampler, target ) {
39025
- const tracks = [];
39026
- const targetName = node.name ? node.name : node.uuid;
39027
- const targetNames = [];
39028
- if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
39029
- node.traverse( function ( object ) {
39030
- if ( object.morphTargetInfluences ) {
39031
- targetNames.push( object.name ? object.name : object.uuid );
39032
- }
39033
- } );
39034
- } else {
39035
- targetNames.push( targetName );
39036
- }
39037
- let TypedKeyframeTrack;
39038
- switch ( PATH_PROPERTIES[ target.path ] ) {
39039
- case PATH_PROPERTIES.weights:
39040
- TypedKeyframeTrack = NumberKeyframeTrack;
39041
- break;
39042
- case PATH_PROPERTIES.rotation:
39043
- TypedKeyframeTrack = QuaternionKeyframeTrack;
39044
- break;
39045
- case PATH_PROPERTIES.translation:
39046
- case PATH_PROPERTIES.scale:
39047
- TypedKeyframeTrack = VectorKeyframeTrack;
39048
- break;
39049
- default:
39050
- switch ( outputAccessor.itemSize ) {
39051
- case 1:
39052
- TypedKeyframeTrack = NumberKeyframeTrack;
39053
- break;
39054
- case 2:
39055
- case 3:
39056
- default:
39057
- TypedKeyframeTrack = VectorKeyframeTrack;
39058
- break;
39059
- }
39060
- break;
39061
- }
39062
- const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
39063
- const outputArray = this._getArrayFromAccessor( outputAccessor );
39064
- for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
39065
- const track = new TypedKeyframeTrack(
39066
- targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
39067
- inputAccessor.array,
39068
- outputArray,
39069
- interpolation
39070
- );
39071
- if ( sampler.interpolation === 'CUBICSPLINE' ) {
39072
- this._createCubicSplineTrackInterpolant( track );
39073
- }
39074
- tracks.push( track );
39075
- }
39076
- return tracks;
39077
- }
39078
- _getArrayFromAccessor( accessor ) {
39079
- let outputArray = accessor.array;
39080
- if ( accessor.normalized ) {
39081
- const scale = getNormalizedComponentScale( outputArray.constructor );
39082
- const scaled = new Float32Array( outputArray.length );
39083
- for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
39084
- scaled[ j ] = outputArray[ j ] * scale;
39085
- }
39086
- outputArray = scaled;
39087
- }
39088
- return outputArray;
39089
- }
39090
- _createCubicSplineTrackInterpolant( track ) {
39091
- track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
39092
- const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
39093
- return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
39094
- };
39095
- track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
39096
- }
39097
- }
39098
- function computeBounds( geometry, primitiveDef, parser ) {
39099
- const attributes = primitiveDef.attributes;
39100
- const box = new Box3();
39101
- if ( attributes.POSITION !== undefined ) {
39102
- const accessor = parser.json.accessors[ attributes.POSITION ];
39103
- const min = accessor.min;
39104
- const max = accessor.max;
39105
- if ( min !== undefined && max !== undefined ) {
39106
- box.set(
39107
- new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
39108
- new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] )
39109
- );
39110
- if ( accessor.normalized ) {
39111
- const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
39112
- box.min.multiplyScalar( boxScale );
39113
- box.max.multiplyScalar( boxScale );
39114
- }
39115
- } else {
39116
- console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
39117
- return;
39118
- }
39119
- } else {
39120
- return;
39121
- }
39122
- const targets = primitiveDef.targets;
39123
- if ( targets !== undefined ) {
39124
- const maxDisplacement = new Vector3();
39125
- const vector = new Vector3();
39126
- for ( let i = 0, il = targets.length; i < il; i ++ ) {
39127
- const target = targets[ i ];
39128
- if ( target.POSITION !== undefined ) {
39129
- const accessor = parser.json.accessors[ target.POSITION ];
39130
- const min = accessor.min;
39131
- const max = accessor.max;
39132
- if ( min !== undefined && max !== undefined ) {
39133
- vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
39134
- vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
39135
- vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
39136
- if ( accessor.normalized ) {
39137
- const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
39138
- vector.multiplyScalar( boxScale );
39139
- }
39140
- maxDisplacement.max( vector );
39141
- } else {
39142
- console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
39143
- }
39144
- }
39145
- }
39146
- box.expandByVector( maxDisplacement );
39147
- }
39148
- geometry.boundingBox = box;
39149
- const sphere = new Sphere();
39150
- box.getCenter( sphere.center );
39151
- sphere.radius = box.min.distanceTo( box.max ) / 2;
39152
- geometry.boundingSphere = sphere;
39153
- }
39154
- function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
39155
- const attributes = primitiveDef.attributes;
39156
- const pending = [];
39157
- function assignAttributeAccessor( accessorIndex, attributeName ) {
39158
- return parser.getDependency( 'accessor', accessorIndex )
39159
- .then( function ( accessor ) {
39160
- geometry.setAttribute( attributeName, accessor );
39161
- } );
39162
- }
39163
- for ( const gltfAttributeName in attributes ) {
39164
- const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
39165
- if ( threeAttributeName in geometry.attributes ) continue;
39166
- pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
39167
- }
39168
- if ( primitiveDef.indices !== undefined && ! geometry.index ) {
39169
- const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) {
39170
- geometry.setIndex( accessor );
39171
- } );
39172
- pending.push( accessor );
39173
- }
39174
- if ( ColorManagement.workingColorSpace !== LinearSRGBColorSpace && 'COLOR_0' in attributes ) {
39175
- console.warn( `THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ColorManagement.workingColorSpace}" not supported.` );
39176
- }
39177
- assignExtrasToUserData( geometry, primitiveDef );
39178
- computeBounds( geometry, primitiveDef, parser );
39179
- return Promise.all( pending ).then( function () {
39180
- return primitiveDef.targets !== undefined
39181
- ? addMorphTargets( geometry, primitiveDef.targets, parser )
39182
- : geometry;
39183
- } );
39184
- }
39185
-
39186
- class GLTFLoadingManager extends LoadingManager {
39187
- constructor(file, params = {}) {
39188
- super();
39189
- this.path = "";
39190
- this.resourcePath = "";
39191
- this.fileURL = "";
39192
- this.dataURLs = new Map();
39193
- this.path = params.path || "";
39194
- const externalFiles = params.externalFiles || new Map();
39195
- if (typeof file === "string") {
39196
- this.fileURL = file;
39197
- this.resourcePath = LoaderUtils.extractUrlBase(file);
39198
- }
39199
- else {
39200
- externalFiles.forEach((value, key) => (this.fileURL = value === file ? key : this.fileURL));
39201
- externalFiles.set(this.fileURL, file);
39202
- }
39203
- externalFiles.forEach((value, key) => {
39204
- let dataURL;
39205
- if (typeof value === "string")
39206
- dataURL = value;
39207
- else
39208
- dataURL = URL.createObjectURL(new Blob([value]));
39209
- this.dataURLs.set(key, dataURL);
39210
- });
39211
- this.setURLModifier((url) => {
39212
- const key = decodeURI(url)
39213
- .replace(this.path, "")
39214
- .replace(this.resourcePath, "")
39215
- .replace(/^(\.?\/)/, "");
39216
- const dataURL = this.dataURLs.get(key);
39217
- return dataURL !== null && dataURL !== void 0 ? dataURL : url;
39218
- });
39219
- }
39220
- dispose() {
39221
- this.dataURLs.forEach(URL.revokeObjectURL);
39222
- }
39223
- }
39224
-
39225
36657
  class ModelImpl {
39226
36658
  constructor(scene) {
39227
- this.handle = "1";
39228
36659
  this.scene = scene;
39229
36660
  }
39230
36661
  dispose() {
@@ -39266,27 +36697,45 @@ void main() {
39266
36697
  }
39267
36698
  return false;
39268
36699
  }
36700
+ hasHandle(handle) {
36701
+ return !handle.includes(":") || handle.split(":", 1)[0] === this.id + "";
36702
+ }
39269
36703
  getOwnObjects(objects) {
39270
36704
  if (!Array.isArray(objects))
39271
36705
  objects = [objects];
39272
36706
  return objects.filter((object) => this.hasObject(object));
39273
36707
  }
36708
+ getOwnHandles(handles) {
36709
+ if (!Array.isArray(handles))
36710
+ handles = [handles];
36711
+ return handles.filter((handle) => this.hasHandle(handle));
36712
+ }
39274
36713
  getObjectsByHandles(handles) {
39275
- const handleSet = new Set(handles);
36714
+ const ownHandles = this.getOwnHandles(handles);
36715
+ if (ownHandles.length === 0)
36716
+ return [];
36717
+ const handleSet = new Set(ownHandles.map((handle) => handle.slice(handle.indexOf(":") + 1)));
39276
36718
  const objects = [];
39277
- this.scene.traverse((object) => handleSet.has(object.userData.handle) && objects.push(object));
36719
+ this.scene.traverse((object) => {
36720
+ const handle = object.userData.handle;
36721
+ if (handle && handleSet.has(handle))
36722
+ objects.push(object);
36723
+ });
39278
36724
  return objects;
39279
36725
  }
39280
36726
  getHandlesByObjects(objects) {
39281
- if (!Array.isArray(objects))
39282
- objects = [objects];
39283
- const handlesSet = new Set();
39284
- this.getOwnObjects(objects).forEach((object) => handlesSet.add(object.userData.handle));
39285
- return Array.from(handlesSet);
36727
+ const ownObjects = this.getOwnObjects(objects);
36728
+ if (ownObjects.length === 0)
36729
+ return [];
36730
+ const handleSet = new Set();
36731
+ ownObjects.forEach((object) => {
36732
+ const handle = object.userData.handle;
36733
+ if (handle)
36734
+ handleSet.add(`${this.id}:${handle}`);
36735
+ });
36736
+ return Array.from(handleSet);
39286
36737
  }
39287
36738
  hideObjects(objects) {
39288
- if (!Array.isArray(objects))
39289
- objects = [objects];
39290
36739
  this.getOwnObjects(objects).forEach((object) => (object.visible = false));
39291
36740
  return this;
39292
36741
  }
@@ -39302,8 +36751,6 @@ void main() {
39302
36751
  return this;
39303
36752
  }
39304
36753
  showObjects(objects) {
39305
- if (!Array.isArray(objects))
39306
- objects = [objects];
39307
36754
  this.getOwnObjects(objects).forEach((object) => {
39308
36755
  object.visible = true;
39309
36756
  object.traverseAncestors((parent) => (parent.visible = true));
@@ -39359,42 +36806,6 @@ void main() {
39359
36806
  }
39360
36807
  }
39361
36808
 
39362
- class GLTFFileLoader extends Loader$1 {
39363
- constructor(viewer) {
39364
- super();
39365
- this.viewer = viewer;
39366
- }
39367
- isSupport(file, format) {
39368
- return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
39369
- /(gltf|glb)$/i.test(format));
39370
- }
39371
- async load(file, format, params) {
39372
- const manager = new GLTFLoadingManager(file, params);
39373
- const loader = new GLTFLoader(manager);
39374
- loader.setPath(manager.path);
39375
- loader.setCrossOrigin(params.crossOrigin || loader.crossOrigin);
39376
- loader.setWithCredentials(params.withCredentials || loader.withCredentials);
39377
- const progress = (event) => {
39378
- const { lengthComputable, loaded, total } = event;
39379
- const progress = lengthComputable ? loaded / total : 1;
39380
- this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
39381
- };
39382
- const gltf = await loader.loadAsync(manager.fileURL, progress);
39383
- if (!this.viewer.scene)
39384
- return this;
39385
- const modelImpl = new ModelImpl(gltf.scene);
39386
- modelImpl.loader = this;
39387
- modelImpl.viewer = this.viewer;
39388
- this.viewer.scene.add(gltf.scene);
39389
- this.viewer.models.push(modelImpl);
39390
- this.viewer.syncOptions();
39391
- this.viewer.syncOverlay();
39392
- this.viewer.update();
39393
- this.viewer.emitEvent({ type: "databasechunk", data: gltf.scene, file });
39394
- return this;
39395
- }
39396
- }
39397
-
39398
36809
  class DynamicModelImpl extends ModelImpl {
39399
36810
  getExtents(target) {
39400
36811
  return target.union(this.gltfLoader.getTotalGeometryExtent());
@@ -39413,31 +36824,40 @@ void main() {
39413
36824
  return this.gltfLoader.originalObjects.has(object);
39414
36825
  }
39415
36826
  getObjectsByHandles(handles) {
39416
- const handlesSet = new Set(handles);
36827
+ const ownHandles = this.getOwnHandles(handles);
36828
+ if (ownHandles.length === 0)
36829
+ return [];
36830
+ const handlesSet = new Set(ownHandles);
39417
36831
  const objects = [];
39418
36832
  handlesSet.forEach((handle) => {
39419
- const handle2 = `${this.modelId}_${handle}`;
39420
- const handles = this.gltfLoader.handleToObjects.get(handle2) || [];
39421
- objects.push(...Array.from(handles));
36833
+ objects.push(...this.gltfLoader.getObjectsByHandle(handle));
39422
36834
  });
39423
36835
  return objects;
39424
36836
  }
39425
36837
  getHandlesByObjects(objects) {
39426
- const handles = super.getHandlesByObjects(objects);
39427
- return handles.map((x) => x.split("_").pop());
36838
+ const ownObjects = this.getOwnObjects(objects);
36839
+ if (ownObjects.length === 0)
36840
+ return [];
36841
+ const handleSet = new Set();
36842
+ ownObjects.forEach((object) => {
36843
+ const handle = object.userData.handle;
36844
+ if (handle)
36845
+ handleSet.add(handle);
36846
+ });
36847
+ return Array.from(handleSet);
39428
36848
  }
39429
36849
  hideObjects(objects) {
39430
- const handles = super.getHandlesByObjects(objects);
36850
+ const handles = this.getHandlesByObjects(objects);
39431
36851
  this.gltfLoader.hideObjects(handles);
39432
36852
  return this;
39433
36853
  }
39434
36854
  isolateObjects(objects) {
39435
- const handles = super.getHandlesByObjects(objects);
36855
+ const handles = this.getHandlesByObjects(objects);
39436
36856
  this.gltfLoader.isolateObjects(new Set(handles));
39437
36857
  return this;
39438
36858
  }
39439
36859
  showObjects(objects) {
39440
- const handles = super.getHandlesByObjects(objects);
36860
+ const handles = this.getHandlesByObjects(objects);
39441
36861
  this.gltfLoader.showObjects(handles);
39442
36862
  return this;
39443
36863
  }
@@ -39501,11 +36921,13 @@ void main() {
39501
36921
  this.materials = new Map();
39502
36922
  this.textureCache = new Map();
39503
36923
  this.materialCache = new Map();
36924
+ this.uri = "";
39504
36925
  }
39505
36926
  async initialize(loader) {
39506
36927
  this.json = await this.loadController.loadJson();
39507
36928
  this.baseUrl = await this.loadController.baseUrl();
39508
36929
  this.loader = loader;
36930
+ this.uri = this.json.buffers[0].uri || "";
39509
36931
  }
39510
36932
  clear() {
39511
36933
  this.json = null;
@@ -39599,7 +37021,7 @@ void main() {
39599
37021
  await this.loader.waitForChunkSlot();
39600
37022
  try {
39601
37023
  const length = range.end - range.start;
39602
- const buffer = await this.loadController.loadBinaryData([{ offset: range.start, length }]);
37024
+ const buffer = await this.loadController.loadBinaryData([{ offset: range.start, length }], this.uri);
39603
37025
  for (const req of range.requests) {
39604
37026
  const relOffset = req.offset - range.start;
39605
37027
  try {
@@ -39916,6 +37338,156 @@ void main() {
39916
37338
  }
39917
37339
  }
39918
37340
 
37341
+ function mergeGeometries( geometries, useGroups = false ) {
37342
+ const isIndexed = geometries[ 0 ].index !== null;
37343
+ const attributesUsed = new Set( Object.keys( geometries[ 0 ].attributes ) );
37344
+ const morphAttributesUsed = new Set( Object.keys( geometries[ 0 ].morphAttributes ) );
37345
+ const attributes = {};
37346
+ const morphAttributes = {};
37347
+ const morphTargetsRelative = geometries[ 0 ].morphTargetsRelative;
37348
+ const mergedGeometry = new BufferGeometry();
37349
+ let offset = 0;
37350
+ for ( let i = 0; i < geometries.length; ++ i ) {
37351
+ const geometry = geometries[ i ];
37352
+ let attributesCount = 0;
37353
+ if ( isIndexed !== ( geometry.index !== null ) ) {
37354
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.' );
37355
+ return null;
37356
+ }
37357
+ for ( const name in geometry.attributes ) {
37358
+ if ( ! attributesUsed.has( name ) ) {
37359
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. All geometries must have compatible attributes; make sure "' + name + '" attribute exists among all geometries, or in none of them.' );
37360
+ return null;
37361
+ }
37362
+ if ( attributes[ name ] === undefined ) attributes[ name ] = [];
37363
+ attributes[ name ].push( geometry.attributes[ name ] );
37364
+ attributesCount ++;
37365
+ }
37366
+ if ( attributesCount !== attributesUsed.size ) {
37367
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. Make sure all geometries have the same number of attributes.' );
37368
+ return null;
37369
+ }
37370
+ if ( morphTargetsRelative !== geometry.morphTargetsRelative ) {
37371
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphTargetsRelative must be consistent throughout all geometries.' );
37372
+ return null;
37373
+ }
37374
+ for ( const name in geometry.morphAttributes ) {
37375
+ if ( ! morphAttributesUsed.has( name ) ) {
37376
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. .morphAttributes must be consistent throughout all geometries.' );
37377
+ return null;
37378
+ }
37379
+ if ( morphAttributes[ name ] === undefined ) morphAttributes[ name ] = [];
37380
+ morphAttributes[ name ].push( geometry.morphAttributes[ name ] );
37381
+ }
37382
+ if ( useGroups ) {
37383
+ let count;
37384
+ if ( isIndexed ) {
37385
+ count = geometry.index.count;
37386
+ } else if ( geometry.attributes.position !== undefined ) {
37387
+ count = geometry.attributes.position.count;
37388
+ } else {
37389
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index ' + i + '. The geometry must have either an index or a position attribute' );
37390
+ return null;
37391
+ }
37392
+ mergedGeometry.addGroup( offset, count, i );
37393
+ offset += count;
37394
+ }
37395
+ }
37396
+ if ( isIndexed ) {
37397
+ let indexOffset = 0;
37398
+ const mergedIndex = [];
37399
+ for ( let i = 0; i < geometries.length; ++ i ) {
37400
+ const index = geometries[ i ].index;
37401
+ for ( let j = 0; j < index.count; ++ j ) {
37402
+ mergedIndex.push( index.getX( j ) + indexOffset );
37403
+ }
37404
+ indexOffset += geometries[ i ].attributes.position.count;
37405
+ }
37406
+ mergedGeometry.setIndex( mergedIndex );
37407
+ }
37408
+ for ( const name in attributes ) {
37409
+ const mergedAttribute = mergeAttributes( attributes[ name ] );
37410
+ if ( ! mergedAttribute ) {
37411
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' attribute.' );
37412
+ return null;
37413
+ }
37414
+ mergedGeometry.setAttribute( name, mergedAttribute );
37415
+ }
37416
+ for ( const name in morphAttributes ) {
37417
+ const numMorphTargets = morphAttributes[ name ][ 0 ].length;
37418
+ if ( numMorphTargets === 0 ) break;
37419
+ mergedGeometry.morphAttributes = mergedGeometry.morphAttributes || {};
37420
+ mergedGeometry.morphAttributes[ name ] = [];
37421
+ for ( let i = 0; i < numMorphTargets; ++ i ) {
37422
+ const morphAttributesToMerge = [];
37423
+ for ( let j = 0; j < morphAttributes[ name ].length; ++ j ) {
37424
+ morphAttributesToMerge.push( morphAttributes[ name ][ j ][ i ] );
37425
+ }
37426
+ const mergedMorphAttribute = mergeAttributes( morphAttributesToMerge );
37427
+ if ( ! mergedMorphAttribute ) {
37428
+ console.error( 'THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the ' + name + ' morphAttribute.' );
37429
+ return null;
37430
+ }
37431
+ mergedGeometry.morphAttributes[ name ].push( mergedMorphAttribute );
37432
+ }
37433
+ }
37434
+ return mergedGeometry;
37435
+ }
37436
+ function mergeAttributes( attributes ) {
37437
+ let TypedArray;
37438
+ let itemSize;
37439
+ let normalized;
37440
+ let gpuType = -1;
37441
+ let arrayLength = 0;
37442
+ for ( let i = 0; i < attributes.length; ++ i ) {
37443
+ const attribute = attributes[ i ];
37444
+ if ( TypedArray === undefined ) TypedArray = attribute.array.constructor;
37445
+ if ( TypedArray !== attribute.array.constructor ) {
37446
+ console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.' );
37447
+ return null;
37448
+ }
37449
+ if ( itemSize === undefined ) itemSize = attribute.itemSize;
37450
+ if ( itemSize !== attribute.itemSize ) {
37451
+ console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.' );
37452
+ return null;
37453
+ }
37454
+ if ( normalized === undefined ) normalized = attribute.normalized;
37455
+ if ( normalized !== attribute.normalized ) {
37456
+ console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.' );
37457
+ return null;
37458
+ }
37459
+ if ( gpuType === -1 ) gpuType = attribute.gpuType;
37460
+ if ( gpuType !== attribute.gpuType ) {
37461
+ console.error( 'THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.' );
37462
+ return null;
37463
+ }
37464
+ arrayLength += attribute.count * itemSize;
37465
+ }
37466
+ const array = new TypedArray( arrayLength );
37467
+ const result = new BufferAttribute( array, itemSize, normalized );
37468
+ let offset = 0;
37469
+ for ( let i = 0; i < attributes.length; ++ i ) {
37470
+ const attribute = attributes[ i ];
37471
+ if ( attribute.isInterleavedBufferAttribute ) {
37472
+ const tupleOffset = offset / itemSize;
37473
+ for ( let j = 0, l = attribute.count; j < l; j ++ ) {
37474
+ for ( let c = 0; c < itemSize; c ++ ) {
37475
+ const value = attribute.getComponent( j, c );
37476
+ result.setComponent( j + tupleOffset, c, value );
37477
+ }
37478
+ }
37479
+ } else {
37480
+ array.set( attribute.array, offset );
37481
+ }
37482
+ offset += attribute.count * itemSize;
37483
+ }
37484
+ if ( gpuType !== undefined ) {
37485
+ result.gpuType = gpuType;
37486
+ }
37487
+ return result;
37488
+ }
37489
+
37490
+ const STRUCTURE_ID_SEPARATOR = ":";
39919
37491
  class DynamicGltfLoader {
39920
37492
  constructor(camera, scene, renderer) {
39921
37493
  this.camera = camera;
@@ -39928,6 +37500,7 @@ void main() {
39928
37500
  geometryerror: [],
39929
37501
  update: [],
39930
37502
  geometrymemory: [],
37503
+ optimizationprogress: [],
39931
37504
  };
39932
37505
  this.loadDistance = 100;
39933
37506
  this.unloadDistance = 150;
@@ -39969,7 +37542,6 @@ void main() {
39969
37542
  this.hiddenHandles = new Set();
39970
37543
  this.newOptimizedObjects = new Set();
39971
37544
  this.oldOptimizeObjects = new Set();
39972
- this.maxConcurrentChunks = 8;
39973
37545
  this.activeChunkLoads = 0;
39974
37546
  this.chunkQueue = [];
39975
37547
  this.objectIdToIndex = new Map();
@@ -39978,6 +37550,7 @@ void main() {
39978
37550
  this.maxConcurrentChunks = 6;
39979
37551
  this.mergedObjectMap = new Map();
39980
37552
  this.mergedGeometryVisibility = new Map();
37553
+ this._webglInfoCache = null;
39981
37554
  }
39982
37555
  setVisibleEdges(visible) {
39983
37556
  this.visibleEdges = visible;
@@ -40081,6 +37654,123 @@ void main() {
40081
37654
  this.updateMemoryIndicator();
40082
37655
  console.log(`Final memory usage: ${Math.round(currentMemoryUsage / (1024 * 1024))}MB`);
40083
37656
  }
37657
+ getStats() {
37658
+ let totalObjects = 0;
37659
+ let renderedObjects = 0;
37660
+ let totalTriangles = 0;
37661
+ let renderedTriangles = 0;
37662
+ let totalLines = 0;
37663
+ let renderedLines = 0;
37664
+ let totalEdges = 0;
37665
+ let renderedEdges = 0;
37666
+ this.scene.traverse((object) => {
37667
+ totalObjects++;
37668
+ const geometry = object.geometry;
37669
+ if (!geometry) return;
37670
+ let triCount = 0;
37671
+ if (geometry.index) {
37672
+ triCount = Math.floor(geometry.index.count / 3);
37673
+ } else if (geometry.attributes && geometry.attributes.position) {
37674
+ triCount = Math.floor(geometry.attributes.position.count / 3);
37675
+ }
37676
+ totalTriangles += triCount;
37677
+ let lineCount = 0;
37678
+ if (geometry.index) {
37679
+ lineCount = Math.floor(geometry.index.count / 2);
37680
+ } else if (geometry.attributes && geometry.attributes.position) {
37681
+ lineCount = Math.floor(geometry.attributes.position.count / 2);
37682
+ }
37683
+ if (object.type === "Line" || object.type === "LineSegments" || object.type === "LineLoop") {
37684
+ if (object.userData.isEdge) {
37685
+ totalEdges += lineCount;
37686
+ } else {
37687
+ totalLines += lineCount;
37688
+ }
37689
+ }
37690
+ if (object.visible !== false) {
37691
+ if (object.isMesh || object.isLine || object.isPoints) {
37692
+ renderedObjects++;
37693
+ if (object.isMesh) {
37694
+ renderedTriangles += triCount;
37695
+ } else if (object.type === "Line" || object.type === "LineSegments" || object.type === "LineLoop") {
37696
+ if (object.userData.isEdge) {
37697
+ renderedEdges += lineCount;
37698
+ } else {
37699
+ renderedLines += lineCount;
37700
+ }
37701
+ }
37702
+ }
37703
+ }
37704
+ });
37705
+ const geometryCount = this.geometryCache ? this.geometryCache.size : 0;
37706
+ const geometryMemoryBytes = Array.from(this.geometryCache?.values?.() || []).reduce((a, b) => a + b, 0);
37707
+ const uniqueMaterialIds = new Set();
37708
+ const uniqueTextureIds = new Set();
37709
+ if (Array.isArray(this.structures)) {
37710
+ for (const structure of this.structures) {
37711
+ console.log(structure.materialCache.values());
37712
+ try {
37713
+ for (const entry of structure.materialCache.values()) {
37714
+ if (entry?.mesh?.uuid) uniqueMaterialIds.add(entry.mesh.uuid);
37715
+ if (entry?.points?.uuid) uniqueMaterialIds.add(entry.points.uuid);
37716
+ if (entry?.lines?.uuid) uniqueMaterialIds.add(entry.lines.uuid);
37717
+ }
37718
+ } catch (exp) {
37719
+ console.error("Error adding material to uniqueMaterialIds", exp);
37720
+ }
37721
+ }
37722
+ }
37723
+ const materialCount = uniqueMaterialIds.size;
37724
+ const textureCount = uniqueTextureIds.size;
37725
+ const estimatedGpuMemoryBytes = geometryMemoryBytes;
37726
+ if (!this._webglInfoCache) {
37727
+ try {
37728
+ const gl = this.renderer.getContext();
37729
+ const dbgInfo = gl.getExtension("WEBGL_debug_renderer_info");
37730
+ if (dbgInfo) {
37731
+ const rendererStr = gl.getParameter(dbgInfo.UNMASKED_RENDERER_WEBGL);
37732
+ const vendorStr = gl.getParameter(dbgInfo.UNMASKED_VENDOR_WEBGL);
37733
+ this._webglInfoCache = { renderer: rendererStr, vendor: vendorStr };
37734
+ } else {
37735
+ this._webglInfoCache = { renderer: null, vendor: null };
37736
+ }
37737
+ } catch (e) {
37738
+ console.error("Error getting webgl info", e);
37739
+ this._webglInfoCache = { renderer: null, vendor: null };
37740
+ }
37741
+ }
37742
+ const size = new Vector2();
37743
+ if (this.renderer && this.renderer.getSize) {
37744
+ this.renderer.getSize(size);
37745
+ }
37746
+ return {
37747
+ scene: {
37748
+ beforeOptimization: {
37749
+ objects: totalObjects - renderedObjects,
37750
+ triangles: totalTriangles - renderedTriangles,
37751
+ lines: totalLines - renderedLines,
37752
+ edges: totalEdges - renderedEdges,
37753
+ },
37754
+ afterOptimization: {
37755
+ objects: renderedObjects,
37756
+ triangles: renderedTriangles,
37757
+ lines: renderedLines,
37758
+ edges: renderedEdges,
37759
+ },
37760
+ },
37761
+ memory: {
37762
+ geometries: { count: geometryCount, bytes: geometryMemoryBytes },
37763
+ textures: { count: textureCount },
37764
+ materials: { count: materialCount },
37765
+ totalEstimatedGpuBytes: estimatedGpuMemoryBytes,
37766
+ },
37767
+ system: {
37768
+ webglRenderer: this._webglInfoCache?.renderer || "",
37769
+ webglVendor: this._webglInfoCache?.vendor || "",
37770
+ viewport: { width: size.x || 0, height: size.y || 0 },
37771
+ },
37772
+ };
37773
+ }
40084
37774
  async loadNode(nodeId, onLoadFinishCb) {
40085
37775
  const node = this.nodes.get(nodeId);
40086
37776
  if (!node || node.loaded || node.loading) return;
@@ -40251,7 +37941,7 @@ void main() {
40251
37941
  if (node.handle) {
40252
37942
  mesh.userData.handle = node.handle;
40253
37943
  } else {
40254
- mesh.userData.handle = `${node.structure.id}_${mesh.userData.handle}`;
37944
+ mesh.userData.handle = `${node.structure.id}${STRUCTURE_ID_SEPARATOR}${mesh.userData.handle}`;
40255
37945
  }
40256
37946
  if (mesh.material.name === "edges") {
40257
37947
  mesh.userData.isEdge = true;
@@ -40397,7 +38087,7 @@ void main() {
40397
38087
  let nodeGroup = null;
40398
38088
  let handle = null;
40399
38089
  if (nodeDef.extras?.handle) {
40400
- handle = `${structure.id}_${nodeDef.extras.handle}`;
38090
+ handle = `${structure.id}${STRUCTURE_ID_SEPARATOR}${nodeDef.extras.handle}`;
40401
38091
  }
40402
38092
  if (nodeDef.camera !== undefined) {
40403
38093
  const camera = this.loadCamera(structure, nodeDef.camera, nodeDef);
@@ -40414,7 +38104,7 @@ void main() {
40414
38104
  if (nodeDef.extras) {
40415
38105
  nodeGroup.userData = { ...nodeDef.extras };
40416
38106
  if (nodeGroup.userData.handle) {
40417
- nodeGroup.userData.handle = `${structure.id}_${nodeGroup.userData.handle}`;
38107
+ nodeGroup.userData.handle = `${structure.id}${STRUCTURE_ID_SEPARATOR}${nodeGroup.userData.handle}`;
40418
38108
  }
40419
38109
  }
40420
38110
  if (nodeDef.matrix) {
@@ -40459,7 +38149,7 @@ void main() {
40459
38149
  this.edgeNodes.push(uniqueNodeId);
40460
38150
  }
40461
38151
  if (meshDef.extras && meshDef.extras.handle) {
40462
- handle = `${structure.id}_${meshDef.extras.handle}`;
38152
+ handle = `${structure.id}${STRUCTURE_ID_SEPARATOR}${meshDef.extras.handle}`;
40463
38153
  }
40464
38154
  this.nodes.set(uniqueNodeId, {
40465
38155
  position: nodeGroup ? nodeGroup.position.clone() : new Vector3().setFromMatrixPosition(nodeMatrix),
@@ -40545,12 +38235,12 @@ void main() {
40545
38235
  }
40546
38236
  }
40547
38237
  async loadNodes() {
40548
- console.time("process nodes");
38238
+ console.time("Process nodes");
40549
38239
  await this.processNodes();
40550
- console.timeEnd("process nodes");
40551
- console.time("optimize scene");
38240
+ console.timeEnd("Process nodes");
38241
+ console.time("Optimize scene");
40552
38242
  await this.optimizeScene();
40553
- console.timeEnd("optimize scene");
38243
+ console.timeEnd("Optimize scene");
40554
38244
  }
40555
38245
  cleanupPartialLoad() {
40556
38246
  this.nodesToLoad.forEach((nodeId) => {
@@ -40871,7 +38561,7 @@ void main() {
40871
38561
  this.handleToObjects.set(fullHandle, new Set());
40872
38562
  }
40873
38563
  this.handleToObjects.get(fullHandle).add(object);
40874
- object.userData.structureId = object.userData.handle.split("_")[0];
38564
+ object.userData.structureId = object.userData.handle.split(STRUCTURE_ID_SEPARATOR)[0];
40875
38565
  }
40876
38566
  getObjectsByHandle(handle) {
40877
38567
  if (!handle) return [];
@@ -40937,10 +38627,28 @@ void main() {
40937
38627
  }
40938
38628
  this.originalObjects.add(object);
40939
38629
  }
40940
- optimizeScene() {
38630
+ yieldToUI() {
38631
+ return new Promise((resolve) => {
38632
+ requestAnimationFrame(() => {
38633
+ setTimeout(resolve, 0);
38634
+ });
38635
+ });
38636
+ }
38637
+ async optimizeScene() {
38638
+ console.log("Starting scene optimization...");
38639
+ this.dispatchEvent("optimizationprogress", {
38640
+ phase: "start",
38641
+ progress: 0,
38642
+ message: "Starting optimization...",
38643
+ });
40941
38644
  this.originalObjects.clear();
40942
38645
  this.originalObjectsToSelection.clear();
40943
38646
  const structureGroups = new Map();
38647
+ this.dispatchEvent("optimizationprogress", {
38648
+ phase: "collecting",
38649
+ progress: 5,
38650
+ message: "Collecting scene objects...",
38651
+ });
40944
38652
  this.scene.traverse((object) => {
40945
38653
  if (object.userData.structureId) {
40946
38654
  const structureId = object.userData.structureId;
@@ -40969,16 +38677,44 @@ void main() {
40969
38677
  }
40970
38678
  }
40971
38679
  });
38680
+ let processedGroups = 0;
38681
+ const totalGroups = structureGroups.size;
38682
+ this.dispatchEvent("optimizationprogress", {
38683
+ phase: "merging",
38684
+ progress: 10,
38685
+ message: `Merging ${totalGroups} structure groups...`,
38686
+ current: 0,
38687
+ total: totalGroups,
38688
+ });
40972
38689
  for (const group of structureGroups.values()) {
40973
38690
  group.mapMeshes.clear();
40974
38691
  group.mapLines.clear();
40975
38692
  group.mapLineSegments.clear();
40976
38693
  group.mapPoints.clear();
40977
- this.mergeMeshGroups(group.meshes, group.rootGroup);
40978
- this.mergeLineGroups(group.lines, group.rootGroup);
40979
- this.mergeLineSegmentGroups(group.lineSegments, group.rootGroup);
40980
- this.mergePointsGroups(group.points, group.rootGroup);
38694
+ await this.mergeMeshGroups(group.meshes, group.rootGroup);
38695
+ await this.yieldToUI();
38696
+ await this.mergeLineGroups(group.lines, group.rootGroup);
38697
+ await this.yieldToUI();
38698
+ await this.mergeLineSegmentGroups(group.lineSegments, group.rootGroup);
38699
+ await this.yieldToUI();
38700
+ await this.mergePointsGroups(group.points, group.rootGroup);
38701
+ processedGroups++;
38702
+ const progress = 10 + Math.round((processedGroups / totalGroups) * 80);
38703
+ this.dispatchEvent("optimizationprogress", {
38704
+ phase: "merging",
38705
+ progress,
38706
+ message: `Processing structure ${processedGroups}/${totalGroups}...`,
38707
+ current: processedGroups,
38708
+ total: totalGroups,
38709
+ });
38710
+ console.log(`Optimization progress: ${processedGroups}/${totalGroups} structure groups processed (${progress}%)`);
38711
+ await this.yieldToUI();
40981
38712
  }
38713
+ this.dispatchEvent("optimizationprogress", {
38714
+ phase: "finalizing",
38715
+ progress: 95,
38716
+ message: "Finalizing optimization...",
38717
+ });
40982
38718
  this.originalObjects.forEach((obj) => {
40983
38719
  obj.visible = false;
40984
38720
  if (!(obj instanceof Points) && !obj.userData.isEdge) {
@@ -40987,9 +38723,15 @@ void main() {
40987
38723
  });
40988
38724
  this.initializeObjectVisibility();
40989
38725
  console.log(`Optimization complete. Total objects: ${this.maxObjectId}`);
38726
+ this.dispatchEvent("optimizationprogress", {
38727
+ phase: "complete",
38728
+ progress: 100,
38729
+ message: `Optimization complete! ${this.maxObjectId} objects processed.`,
38730
+ });
40990
38731
  this.dispatchEvent("update");
40991
38732
  }
40992
- mergeMeshGroups(materialGroups, rootGroup) {
38733
+ async mergeMeshGroups(materialGroups, rootGroup) {
38734
+ let processedGroups = 0;
40993
38735
  for (const group of materialGroups) {
40994
38736
  if (!group.material) {
40995
38737
  console.warn("Skipping mesh group with null material");
@@ -41063,6 +38805,10 @@ void main() {
41063
38805
  this.handleToOptimizedObjects.set(handle, mergedObjects);
41064
38806
  }
41065
38807
  });
38808
+ processedGroups++;
38809
+ if (processedGroups % 5 === 0) {
38810
+ await this.yieldToUI();
38811
+ }
41066
38812
  } catch (error) {
41067
38813
  console.error("Failed to merge meshes for material:", error);
41068
38814
  group.objects.forEach((mesh) => {
@@ -41071,7 +38817,8 @@ void main() {
41071
38817
  }
41072
38818
  }
41073
38819
  }
41074
- mergeLineGroups(materialGroups, rootGroup) {
38820
+ async mergeLineGroups(materialGroups, rootGroup) {
38821
+ let processedGroups = 0;
41075
38822
  for (const group of materialGroups) {
41076
38823
  if (group.objects.length === 0) continue;
41077
38824
  if (!group.material) {
@@ -41090,7 +38837,9 @@ void main() {
41090
38837
  let posOffset = 0;
41091
38838
  const indices = [];
41092
38839
  let vertexOffset = 0;
38840
+ let isEdge = false;
41093
38841
  group.objects.forEach((line) => {
38842
+ isEdge = line.userData.isEdge;
41094
38843
  const geometry = line.geometry;
41095
38844
  const positionAttr = geometry.attributes.position;
41096
38845
  const vertexCount = positionAttr.count;
@@ -41141,6 +38890,7 @@ void main() {
41141
38890
  geometry.setAttribute("visibility", new BufferAttribute(visibilityArray, 1));
41142
38891
  const visibilityMaterial = this.createVisibilityMaterial(group.material);
41143
38892
  const mergedLine = new LineSegments(geometry, visibilityMaterial);
38893
+ mergedLine.userData.isEdge = isEdge;
41144
38894
  const mergedObjects = [mergedLine];
41145
38895
  if (this.useVAO) {
41146
38896
  this.createVAO(mergedLine);
@@ -41163,9 +38913,14 @@ void main() {
41163
38913
  this.handleToOptimizedObjects.set(handle, mergedObjects);
41164
38914
  }
41165
38915
  });
38916
+ processedGroups++;
38917
+ if (processedGroups % 5 === 0) {
38918
+ await this.yieldToUI();
38919
+ }
41166
38920
  }
41167
38921
  }
41168
- mergeLineSegmentGroups(materialGroups, rootGroup) {
38922
+ async mergeLineSegmentGroups(materialGroups, rootGroup) {
38923
+ let processedGroups = 0;
41169
38924
  for (const group of materialGroups) {
41170
38925
  if (!group.material) {
41171
38926
  console.warn("Skipping line segment group with null material");
@@ -41177,7 +38932,9 @@ void main() {
41177
38932
  const handles = new Set();
41178
38933
  const objectMapping = new Map();
41179
38934
  let currentVertexOffset = 0;
38935
+ let isEdge = false;
41180
38936
  for (const line of group.objects) {
38937
+ isEdge = line.userData.isEdge;
41181
38938
  const geometry = line.geometry.clone();
41182
38939
  line.updateWorldMatrix(true, false);
41183
38940
  geometry.applyMatrix4(line.matrixWorld);
@@ -41213,6 +38970,7 @@ void main() {
41213
38970
  mergedGeometry.setAttribute("visibility", new BufferAttribute(visibilityArray, 1));
41214
38971
  const visibilityMaterial = this.createVisibilityMaterial(group.material);
41215
38972
  const mergedLine = new LineSegments(mergedGeometry, visibilityMaterial);
38973
+ mergedLine.userData.isEdge = isEdge;
41216
38974
  if (this.useVAO) {
41217
38975
  this.createVAO(mergedLine);
41218
38976
  }
@@ -41239,6 +38997,10 @@ void main() {
41239
38997
  this.handleToOptimizedObjects.set(handle, mergedObjects);
41240
38998
  }
41241
38999
  });
39000
+ processedGroups++;
39001
+ if (processedGroups % 5 === 0) {
39002
+ await this.yieldToUI();
39003
+ }
41242
39004
  } catch (error) {
41243
39005
  console.warn("Failed to merge line segments for material:", error);
41244
39006
  group.objects.forEach((line) => {
@@ -41247,7 +39009,8 @@ void main() {
41247
39009
  }
41248
39010
  }
41249
39011
  }
41250
- mergePointsGroups(materialGroups, rootGroup) {
39012
+ async mergePointsGroups(materialGroups, rootGroup) {
39013
+ let processedGroups = 0;
41251
39014
  for (const group of materialGroups) {
41252
39015
  if (!group.material) {
41253
39016
  console.warn("Skipping points group with null material");
@@ -41289,6 +39052,10 @@ void main() {
41289
39052
  this.handleToOptimizedObjects.set(handle, mergedObjects);
41290
39053
  }
41291
39054
  });
39055
+ processedGroups++;
39056
+ if (processedGroups % 5 === 0) {
39057
+ await this.yieldToUI();
39058
+ }
41292
39059
  } catch (error) {
41293
39060
  console.warn("Failed to merge points for material:", error);
41294
39061
  group.objects.forEach((points) => {
@@ -41524,8 +39291,225 @@ void main() {
41524
39291
  }
41525
39292
  }
41526
39293
 
41527
- class GLTFCloudDynamicLoader {
39294
+ class GLTFLoadingManager extends LoadingManager {
39295
+ constructor(file, params = {}) {
39296
+ super();
39297
+ this.path = "";
39298
+ this.resourcePath = "";
39299
+ this.fileURL = "";
39300
+ this.dataURLs = new Map();
39301
+ this.path = params.path || "";
39302
+ const externalFiles = params.externalFiles || new Map();
39303
+ if (typeof file === "string") {
39304
+ this.fileURL = file;
39305
+ this.resourcePath = LoaderUtils.extractUrlBase(file);
39306
+ }
39307
+ else {
39308
+ externalFiles.forEach((value, key) => (this.fileURL = value === file ? key : this.fileURL));
39309
+ externalFiles.set(this.fileURL, file);
39310
+ }
39311
+ externalFiles.forEach((value, key) => {
39312
+ let dataURL;
39313
+ if (typeof value === "string")
39314
+ dataURL = value;
39315
+ else
39316
+ dataURL = URL.createObjectURL(new Blob([value]));
39317
+ this.dataURLs.set(key, dataURL);
39318
+ });
39319
+ this.setURLModifier((url) => {
39320
+ const key = decodeURI(url)
39321
+ .replace(this.path, "")
39322
+ .replace(this.resourcePath, "")
39323
+ .replace(/^(\.?\/)/, "");
39324
+ const dataURL = this.dataURLs.get(key);
39325
+ return dataURL !== null && dataURL !== void 0 ? dataURL : url;
39326
+ });
39327
+ }
39328
+ dispose() {
39329
+ this.dataURLs.forEach((dataURL) => URL.revokeObjectURL(dataURL));
39330
+ }
39331
+ }
39332
+
39333
+ const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
39334
+ const BINARY_EXTENSION_HEADER_LENGTH = 12;
39335
+ const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4042 };
39336
+ class GLTFBinaryExtension {
39337
+ constructor(data) {
39338
+ const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
39339
+ const textDecoder = new TextDecoder();
39340
+ const magic = textDecoder.decode(new Uint8Array(data.slice(0, 4)));
39341
+ if (magic !== BINARY_EXTENSION_HEADER_MAGIC) {
39342
+ this.content = textDecoder.decode(data);
39343
+ return;
39344
+ }
39345
+ const header = {
39346
+ magic,
39347
+ version: headerView.getUint32(4, true),
39348
+ length: headerView.getUint32(8, true),
39349
+ };
39350
+ if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
39351
+ throw new Error("Unsupported glTF-Binary header.");
39352
+ }
39353
+ if (header.version < 2.0) {
39354
+ throw new Error("Legacy binary file detected.");
39355
+ }
39356
+ const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
39357
+ const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
39358
+ let chunkIndex = 0;
39359
+ while (chunkIndex < chunkContentsLength) {
39360
+ const chunkLength = chunkView.getUint32(chunkIndex, true);
39361
+ chunkIndex += 4;
39362
+ const chunkType = chunkView.getUint32(chunkIndex, true);
39363
+ chunkIndex += 4;
39364
+ if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
39365
+ const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
39366
+ this.content = textDecoder.decode(contentArray);
39367
+ }
39368
+ else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
39369
+ const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
39370
+ this.body = data.slice(byteOffset, byteOffset + chunkLength);
39371
+ }
39372
+ chunkIndex += chunkLength;
39373
+ }
39374
+ if (typeof this.content === "undefined") {
39375
+ throw new Error("JSON content not found.");
39376
+ }
39377
+ }
39378
+ }
39379
+
39380
+ class RangesLoader {
39381
+ constructor() {
39382
+ this.requestHeader = {};
39383
+ this.withCredentials = false;
39384
+ this.abortSignal = undefined;
39385
+ }
39386
+ setRequestHeader(requestHeader) {
39387
+ this.requestHeader = requestHeader;
39388
+ }
39389
+ setWithCredentials(withCredentials) {
39390
+ this.withCredentials = withCredentials;
39391
+ }
39392
+ setAbortSignal(abortSignal) {
39393
+ this.abortSignal = abortSignal;
39394
+ }
39395
+ async load(url, ranges) {
39396
+ const init = {
39397
+ headers: {
39398
+ ...this.requestHeader,
39399
+ Range: "bytes=" + ranges.map((x) => `${x.offset}-${x.offset + x.length - 1}`).join(","),
39400
+ },
39401
+ credentials: this.withCredentials ? "include" : "same-origin",
39402
+ signal: this.abortSignal,
39403
+ };
39404
+ const response = await fetch(url, init);
39405
+ if (!response.ok) {
39406
+ throw new Error(`Failed to fetch "${url}", status ${response.status}`);
39407
+ }
39408
+ if (response.status !== 206) {
39409
+ const arrayBuffer = await response.arrayBuffer();
39410
+ return this.extractRanges(arrayBuffer, ranges);
39411
+ }
39412
+ return response.arrayBuffer();
39413
+ }
39414
+ extractRanges(arrayBuffer, ranges) {
39415
+ const totalLength = ranges.reduce((sum, range) => sum + range.length, 0);
39416
+ const result = new Uint8Array(totalLength);
39417
+ let offset = 0;
39418
+ for (const range of ranges) {
39419
+ const chunk = new Uint8Array(arrayBuffer, range.offset, range.length);
39420
+ result.set(chunk, offset);
39421
+ offset += range.length;
39422
+ }
39423
+ return result.buffer;
39424
+ }
39425
+ }
39426
+
39427
+ class GLTFFileDynamicLoader extends Loader$1 {
41528
39428
  constructor(viewer) {
39429
+ super();
39430
+ this.viewer = viewer;
39431
+ }
39432
+ dispose() {
39433
+ if (this.gltfLoader)
39434
+ this.gltfLoader.clear();
39435
+ if (this.manager)
39436
+ this.manager.dispose();
39437
+ }
39438
+ isSupport(file, format) {
39439
+ return ((typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
39440
+ /(gltf|glb)$/i.test(format));
39441
+ }
39442
+ async load(file, format, params) {
39443
+ this.manager = new GLTFLoadingManager(file, params);
39444
+ const scene = new Group$1();
39445
+ this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, scene, this.viewer.renderer);
39446
+ this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
39447
+ this.gltfLoader.visibleEdges = this.viewer.options.edgeModel;
39448
+ const modelImpl = new DynamicModelImpl(scene);
39449
+ modelImpl.id = params.modelId || this.extractFileName(file);
39450
+ modelImpl.gltfLoader = this.gltfLoader;
39451
+ this.gltfLoader.addEventListener("databasechunk", () => {
39452
+ this.viewer.scene.add(scene);
39453
+ this.viewer.models.push(modelImpl);
39454
+ this.viewer.syncOptions();
39455
+ this.viewer.syncOverlay();
39456
+ this.viewer.update();
39457
+ this.viewer.emitEvent({ type: "databasechunk", data: scene, file });
39458
+ });
39459
+ this.gltfLoader.addEventListener("geometryerror", (data) => {
39460
+ this.viewer.emitEvent({ type: "geometryerror", data, file });
39461
+ });
39462
+ this.gltfLoader.addEventListener("update", (data) => {
39463
+ this.viewer.update();
39464
+ });
39465
+ const loadController = {
39466
+ loadJson: async () => {
39467
+ const loader = new FileLoader(this.manager);
39468
+ loader.setPath(this.manager.path);
39469
+ loader.setRequestHeader(params.requestHeader || {});
39470
+ loader.setWithCredentials(params.withCredentials || loader.withCredentials);
39471
+ loader.setResponseType("arraybuffer");
39472
+ const progress = (event) => {
39473
+ const { lengthComputable, loaded, total } = event;
39474
+ const progress = lengthComputable ? loaded / total : 1;
39475
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
39476
+ };
39477
+ const data = await loader.loadAsync(this.manager.fileURL, progress);
39478
+ const extension = new GLTFBinaryExtension(data);
39479
+ this.gltf = JSON.parse(extension.content);
39480
+ this.bin = extension.body;
39481
+ return this.gltf;
39482
+ },
39483
+ loadBinaryData: (ranges, uri = "") => {
39484
+ const loader = new RangesLoader();
39485
+ loader.setRequestHeader(params.requestHeader || {});
39486
+ loader.setWithCredentials(params.withCredentials || false);
39487
+ loader.setAbortSignal(this.gltfLoader.abortController.signal);
39488
+ if (this.bin)
39489
+ return loader.extractRanges(this.bin, ranges);
39490
+ const path = this.manager.path || this.manager.resourcePath;
39491
+ const url = LoaderUtils.resolveURL(uri, path);
39492
+ return loader.load(this.manager.resolveURL(url), ranges);
39493
+ },
39494
+ baseUrl: () => {
39495
+ const path = this.manager.path || this.manager.resourcePath;
39496
+ return Promise.resolve(path);
39497
+ },
39498
+ };
39499
+ const structure = new GltfStructure(modelImpl.id, loadController);
39500
+ await this.gltfLoader.loadStructure(structure);
39501
+ await this.gltfLoader.loadNodes();
39502
+ return this;
39503
+ }
39504
+ cancel() {
39505
+ if (this.gltfLoader)
39506
+ this.gltfLoader.abortLoading();
39507
+ }
39508
+ }
39509
+
39510
+ class GLTFCloudDynamicLoader extends Loader$1 {
39511
+ constructor(viewer) {
39512
+ super();
41529
39513
  this.requestId = 0;
41530
39514
  this.viewer = viewer;
41531
39515
  }
@@ -41540,17 +39524,15 @@ void main() {
41540
39524
  typeof file.downloadResourceRange === "function" &&
41541
39525
  /.gltf$/i.test(file.database));
41542
39526
  }
41543
- async load(model, format, params) {
39527
+ async load(model, format, params = {}) {
41544
39528
  const scene = new Group$1();
41545
39529
  this.gltfLoader = new DynamicGltfLoader(this.viewer.camera, scene, this.viewer.renderer);
41546
39530
  this.gltfLoader.memoryLimit = this.viewer.options.memoryLimit;
41547
39531
  this.gltfLoader.setVisibleEdges(this.viewer.options.edgeModel);
39532
+ const modelImpl = new DynamicModelImpl(scene);
39533
+ modelImpl.id = model.file.id;
39534
+ modelImpl.gltfLoader = this.gltfLoader;
41548
39535
  this.gltfLoader.addEventListener("databasechunk", (data) => {
41549
- const modelImpl = new DynamicModelImpl(scene);
41550
- modelImpl.loader = this;
41551
- modelImpl.viewer = this.viewer;
41552
- modelImpl.gltfLoader = this.gltfLoader;
41553
- modelImpl.modelId = model.id;
41554
39536
  this.viewer.scene.add(scene);
41555
39537
  this.viewer.models.push(modelImpl);
41556
39538
  this.viewer.syncOptions();
@@ -41558,10 +39540,6 @@ void main() {
41558
39540
  this.viewer.update();
41559
39541
  this.viewer.emitEvent({ type: "databasechunk", data: scene, file: model.file, model });
41560
39542
  });
41561
- this.gltfLoader.addEventListener("geometryprogress", (data) => {
41562
- const progress = data.loaded / data.total;
41563
- this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
41564
- });
41565
39543
  this.gltfLoader.addEventListener("geometryerror", (data) => {
41566
39544
  this.viewer.emitEvent({ type: "geometryerror", data, file: model.file, model });
41567
39545
  });
@@ -41571,7 +39549,7 @@ void main() {
41571
39549
  const loadController = {
41572
39550
  loadJson: async () => {
41573
39551
  const progress = (progress) => {
41574
- this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model });
39552
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
41575
39553
  };
41576
39554
  const arrayBuffer = await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
41577
39555
  const text = new TextDecoder().decode(arrayBuffer);
@@ -41588,7 +39566,7 @@ void main() {
41588
39566
  },
41589
39567
  baseUrl: () => Promise.resolve(`${model.httpClient.serverUrl}${model.path}/`),
41590
39568
  };
41591
- const structure = new GltfStructure(model.id, loadController);
39569
+ const structure = new GltfStructure(modelImpl.id, loadController);
41592
39570
  await this.gltfLoader.loadStructure(structure);
41593
39571
  await this.gltfLoader.loadNodes();
41594
39572
  return this;
@@ -41600,7 +39578,7 @@ void main() {
41600
39578
  }
41601
39579
 
41602
39580
  const loaders = loadersRegistry("threejs");
41603
- loaders.registerLoader("gltf-file", (viewer) => new GLTFFileLoader(viewer));
39581
+ loaders.registerLoader("gltf-file", (viewer) => new GLTFFileDynamicLoader(viewer));
41604
39582
  loaders.registerLoader("gltf-cloud", (viewer) => new GLTFCloudDynamicLoader(viewer));
41605
39583
 
41606
39584
  const CopyShader = {
@@ -56561,24 +54539,25 @@ js: import "konva/skia-backend";
56561
54539
  class Viewer extends EventEmitter2 {
56562
54540
  constructor(client) {
56563
54541
  super();
56564
- this._options = new Options(this);
56565
54542
  this.client = client;
56566
- this.canvasEvents = CANVAS_EVENTS;
56567
- this.canvaseventlistener = (event) => this.emit(event);
54543
+ this.options = new Options(this);
56568
54544
  this.loaders = [];
56569
54545
  this.models = [];
54546
+ this.canvasEvents = CANVAS_EVENTS.slice();
54547
+ this.canvaseventlistener = (event) => this.emit(event);
56570
54548
  this.selected = [];
56571
54549
  this.extents = new Box3();
56572
- this.target = new Vector3();
54550
+ this.target = new Vector3(0, 0, 0);
56573
54551
  this._activeDragger = null;
56574
54552
  this._components = [];
54553
+ this._renderNeeded = false;
56575
54554
  this._renderTime = 0;
56576
54555
  this.render = this.render.bind(this);
56577
54556
  this.update = this.update.bind(this);
56578
54557
  this._markup = new KonvaMarkup();
56579
54558
  }
56580
- get options() {
56581
- return this._options;
54559
+ get markup() {
54560
+ return this._markup;
56582
54561
  }
56583
54562
  get draggers() {
56584
54563
  return [...draggers.getDraggers().keys()];
@@ -56586,14 +54565,10 @@ js: import "konva/skia-backend";
56586
54565
  get components() {
56587
54566
  return [...components.getComponents().keys()];
56588
54567
  }
56589
- get markup() {
56590
- return this._markup;
56591
- }
56592
54568
  initialize(canvas, onProgress) {
56593
54569
  this.addEventListener("optionschange", (event) => this.syncOptions(event.data));
56594
54570
  this.scene = new Scene();
56595
54571
  this.helpers = new Helpers();
56596
- this.target = new Vector3(0, 0, 0);
56597
54572
  const pixelRatio = window.devicePixelRatio;
56598
54573
  const rect = canvas.parentElement.getBoundingClientRect();
56599
54574
  const width = rect.width || 1;
@@ -56744,21 +54719,25 @@ js: import "konva/skia-backend";
56744
54719
  async open(file, params = {}) {
56745
54720
  if (!this.renderer)
56746
54721
  return this;
56747
- if (params.mode !== "a" && params.mode !== "append") {
54722
+ const mode = params.mode || "file";
54723
+ if (mode !== "assembly" && mode !== "a" && mode !== "append") {
56748
54724
  this.cancel();
56749
54725
  this.clear();
56750
54726
  }
56751
- this.emitEvent({ type: "open", file });
54727
+ this.emitEvent({ type: "open", mode, file });
56752
54728
  let model = file;
56753
54729
  if (model && typeof model.getModels === "function") {
56754
54730
  const models = await model.getModels();
56755
54731
  model = models.find((model) => model.default) || models[0] || file;
56756
54732
  }
54733
+ if (model && typeof model.database === "string") {
54734
+ file = model.file;
54735
+ }
56757
54736
  if (!model)
56758
54737
  throw new Error(`Format not supported`);
56759
54738
  let format = params.format;
56760
- if (!format && typeof model.type === "string")
56761
- format = model.type.split(".").pop();
54739
+ if (!format && typeof file["type"] === "string")
54740
+ format = file["type"].split(".").pop();
56762
54741
  if (!format && typeof file === "string")
56763
54742
  format = file.split(".").pop();
56764
54743
  if (!format && file instanceof globalThis.File)
@@ -56785,7 +54764,7 @@ js: import "konva/skia-backend";
56785
54764
  }
56786
54765
  loadGltfFile(file, externalFiles, params = {}) {
56787
54766
  console.warn("Viewer.loadGltfFile() has been deprecated since 26.4 and will be removed in a future release, use Viewer.open() instead.");
56788
- return this.open(file, { ...params, format: "gltf", externalFiles, mode: "append" });
54767
+ return this.open(file, { ...params, format: "gltf", externalFiles, mode: "assembly" });
56789
54768
  }
56790
54769
  cancel() {
56791
54770
  this.loaders.forEach((loader) => loader.cancel());
@@ -56805,12 +54784,17 @@ js: import "konva/skia-backend";
56805
54784
  this.models = [];
56806
54785
  this.scene.clear();
56807
54786
  this.helpers.clear();
54787
+ this.extents.makeEmpty();
54788
+ this.target.set(0, 0, 0);
56808
54789
  this.syncOptions();
56809
54790
  this.syncOverlay();
56810
54791
  this.update(true);
56811
54792
  this.emitEvent({ type: "clear" });
56812
54793
  return this;
56813
54794
  }
54795
+ is3D() {
54796
+ return true;
54797
+ }
56814
54798
  syncOptions(options = this.options) {
56815
54799
  if (!this.renderer)
56816
54800
  return;
@@ -56842,9 +54826,15 @@ js: import "konva/skia-backend";
56842
54826
  getSelected() {
56843
54827
  return this.executeCommand("getSelected");
56844
54828
  }
54829
+ getSelected2() {
54830
+ return this.executeCommand("getSelected2");
54831
+ }
56845
54832
  setSelected(handles) {
56846
54833
  this.executeCommand("setSelected", handles);
56847
54834
  }
54835
+ setSelected2(handles) {
54836
+ this.executeCommand("setSelected2", handles);
54837
+ }
56848
54838
  clearSelected() {
56849
54839
  this.executeCommand("clearSelected");
56850
54840
  }
@@ -56904,37 +54894,8 @@ js: import "konva/skia-backend";
56904
54894
  getComponent(name) {
56905
54895
  return this._components.find((component) => component.name === name);
56906
54896
  }
56907
- is3D() {
56908
- return true;
56909
- }
56910
- screenToWorld(position) {
56911
- if (!this.renderer)
56912
- return { x: position.x, y: position.y, z: 0 };
56913
- const rect = this.canvas.getBoundingClientRect();
56914
- const x = position.x / (rect.width / 2) - 1;
56915
- const y = -position.y / (rect.height / 2) + 1;
56916
- const point = new Vector3(x, y, -1);
56917
- point.unproject(this.camera);
56918
- return { x: point.x, y: point.y, z: point.z };
56919
- }
56920
- worldToScreen(position) {
56921
- if (!this.renderer)
56922
- return { x: position.x, y: position.y };
56923
- const point = new Vector3(position.x, position.y, position.z);
56924
- point.project(this.camera);
56925
- const rect = this.canvas.getBoundingClientRect();
56926
- const x = (point.x + 1) * (rect.width / 2);
56927
- const y = (-point.y + 1) * (rect.height / 2);
56928
- return { x, y };
56929
- }
56930
- getScale() {
56931
- return { x: 1, y: 1, z: 1 };
56932
- }
56933
- executeCommand(id, ...args) {
56934
- return commands.executeCommand(id, this, ...args);
56935
- }
56936
54897
  drawViewpoint(viewpoint) {
56937
- var _a, _b, _c;
54898
+ var _a, _b, _c, _d;
56938
54899
  if (!this.renderer)
56939
54900
  return;
56940
54901
  const getVector3FromPoint3d = ({ x, y, z }) => new Vector3(x, y, z);
@@ -56986,11 +54947,13 @@ js: import "konva/skia-backend";
56986
54947
  }
56987
54948
  };
56988
54949
  const setClippingPlanes = (clipping_planes) => {
56989
- clipping_planes === null || clipping_planes === void 0 ? void 0 : clipping_planes.forEach((clipping_plane) => {
56990
- const plane = new Plane();
56991
- plane.setFromNormalAndCoplanarPoint(getVector3FromPoint3d(clipping_plane.direction), getVector3FromPoint3d(clipping_plane.location));
56992
- this.renderer.clippingPlanes.push(plane);
56993
- });
54950
+ if (clipping_planes) {
54951
+ clipping_planes.forEach((clipping_plane) => {
54952
+ const plane = new Plane();
54953
+ plane.setFromNormalAndCoplanarPoint(getVector3FromPoint3d(clipping_plane.direction), getVector3FromPoint3d(clipping_plane.location));
54954
+ this.renderer.clippingPlanes.push(plane);
54955
+ });
54956
+ }
56994
54957
  };
56995
54958
  const setSelection = (selection) => {
56996
54959
  if (selection)
@@ -57006,9 +54969,9 @@ js: import "konva/skia-backend";
57006
54969
  setOrthogonalCamera(viewpoint.orthogonal_camera);
57007
54970
  setPerspectiveCamera(viewpoint.perspective_camera);
57008
54971
  setClippingPlanes(viewpoint.clipping_planes);
57009
- setSelection(viewpoint.selection);
54972
+ setSelection(((_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.selection2) || viewpoint.selection);
57010
54973
  this._markup.setViewpoint(viewpoint);
57011
- this.target = getVector3FromPoint3d((_c = (_b = viewpoint.custom_fields) === null || _b === void 0 ? void 0 : _b.camera_target) !== null && _c !== void 0 ? _c : this.target);
54974
+ this.target.copy(getVector3FromPoint3d((_d = (_c = viewpoint.custom_fields) === null || _c === void 0 ? void 0 : _c.camera_target) !== null && _d !== void 0 ? _d : this.target));
57012
54975
  this.setActiveDragger(draggerName);
57013
54976
  this.emitEvent({ type: "drawviewpoint", data: viewpoint });
57014
54977
  this.update();
@@ -57055,6 +55018,9 @@ js: import "konva/skia-backend";
57055
55018
  const getSelection = () => {
57056
55019
  return this.getSelected().map((handle) => ({ handle }));
57057
55020
  };
55021
+ const getSelection2 = () => {
55022
+ return this.getSelected2().map((handle) => ({ handle }));
55023
+ };
57058
55024
  const viewpoint = { custom_fields: {} };
57059
55025
  viewpoint.orthogonal_camera = getOrthogonalCamera();
57060
55026
  viewpoint.perspective_camera = getPerspectiveCamera();
@@ -57063,9 +55029,36 @@ js: import "konva/skia-backend";
57063
55029
  viewpoint.description = new Date().toDateString();
57064
55030
  this._markup.getViewpoint(viewpoint);
57065
55031
  viewpoint.custom_fields.camera_target = getPoint3dFromVector3(this.target);
55032
+ viewpoint.custom_fields.selection2 = getSelection2();
57066
55033
  this.emitEvent({ type: "createviewpoint", data: viewpoint });
57067
55034
  return viewpoint;
57068
55035
  }
55036
+ screenToWorld(position) {
55037
+ if (!this.renderer)
55038
+ return { x: position.x, y: position.y, z: 0 };
55039
+ const rect = this.canvas.getBoundingClientRect();
55040
+ const x = position.x / (rect.width / 2) - 1;
55041
+ const y = -position.y / (rect.height / 2) + 1;
55042
+ const point = new Vector3(x, y, -1);
55043
+ point.unproject(this.camera);
55044
+ return { x: point.x, y: point.y, z: point.z };
55045
+ }
55046
+ worldToScreen(position) {
55047
+ if (!this.renderer)
55048
+ return { x: position.x, y: position.y };
55049
+ const point = new Vector3(position.x, position.y, position.z);
55050
+ point.project(this.camera);
55051
+ const rect = this.canvas.getBoundingClientRect();
55052
+ const x = (point.x + 1) * (rect.width / 2);
55053
+ const y = (-point.y + 1) * (rect.height / 2);
55054
+ return { x, y };
55055
+ }
55056
+ getScale() {
55057
+ return { x: 1, y: 1, z: 1 };
55058
+ }
55059
+ executeCommand(id, ...args) {
55060
+ return commands.executeCommand(id, this, ...args);
55061
+ }
57069
55062
  }
57070
55063
 
57071
55064
  if (typeof window !== "undefined")