itowns 2.34.0 → 2.36.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CONTRIBUTORS.md +1 -0
  2. package/changelog.md +150 -0
  3. package/dist/debug.js +2 -16
  4. package/dist/debug.js.LICENSE.txt +6 -0
  5. package/dist/debug.js.map +1 -1
  6. package/dist/itowns.js +2 -19
  7. package/dist/itowns.js.LICENSE.txt +28 -0
  8. package/dist/itowns.js.map +1 -1
  9. package/examples/3dtiles_basic.html +2 -2
  10. package/examples/config.json +2 -1
  11. package/examples/js/plugins/CSVnVRTParser.js +0 -1
  12. package/examples/layers/JSONLayers/Administrative.json +1 -1
  13. package/examples/layers/JSONLayers/Cada.json +1 -1
  14. package/examples/layers/JSONLayers/EtatMajor.json +1 -1
  15. package/examples/layers/JSONLayers/IGN_MNT.json +1 -1
  16. package/examples/layers/JSONLayers/IGN_MNT_HIGHRES.json +1 -1
  17. package/examples/layers/JSONLayers/Ortho.json +1 -1
  18. package/examples/layers/JSONLayers/WORLD_DTM.json +1 -1
  19. package/examples/misc_camera_traveling.html +148 -0
  20. package/examples/misc_custom_label.html +0 -2
  21. package/examples/plugins_vrt.html +0 -1
  22. package/examples/source_file_geojson_raster.html +0 -3
  23. package/examples/source_file_shapefile.html +0 -1
  24. package/examples/source_stream_wfs_25d.html +8 -16
  25. package/examples/vector_tile_raster_2d.html +2 -2
  26. package/examples/vector_tile_raster_3d.html +2 -2
  27. package/examples/view_25d_map.html +28 -0
  28. package/examples/view_multi_25d.html +1 -1
  29. package/lib/Controls/FirstPersonControls.js +12 -14
  30. package/lib/Controls/FlyControls.js +2 -10
  31. package/lib/Controls/GlobeControls.js +231 -303
  32. package/lib/Controls/PlanarControls.js +5 -16
  33. package/lib/Controls/StateControl.js +362 -96
  34. package/lib/Converter/Feature2Mesh.js +20 -5
  35. package/lib/Converter/Feature2Texture.js +2 -2
  36. package/lib/Converter/convertToTile.js +1 -1
  37. package/lib/Core/AnimationPlayer.js +15 -0
  38. package/lib/Core/Feature.js +39 -38
  39. package/lib/Core/Geographic/Coordinates.js +56 -0
  40. package/lib/Core/Geographic/Crs.js +15 -0
  41. package/lib/Core/Geographic/Extent.js +99 -11
  42. package/lib/Core/Label.js +1 -1
  43. package/lib/Core/Math/Ellipsoid.js +26 -8
  44. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +1 -1
  45. package/lib/Core/Prefab/PlanarView.js +1 -1
  46. package/lib/Core/Style.js +1 -0
  47. package/lib/Core/TileMesh.js +3 -2
  48. package/lib/Core/View.js +3 -3
  49. package/lib/Layer/ElevationLayer.js +9 -16
  50. package/lib/Layer/LabelLayer.js +7 -1
  51. package/lib/Main.js +1 -1
  52. package/lib/Parser/ShapefileParser.js +1 -2
  53. package/lib/Parser/VectorTileParser.js +1 -1
  54. package/lib/Process/3dTilesProcessing.js +8 -8
  55. package/lib/Process/FeatureProcessing.js +1 -2
  56. package/lib/Process/ObjectRemovalHelper.js +5 -2
  57. package/lib/Renderer/Label2DRenderer.js +15 -11
  58. package/lib/Renderer/LayeredMaterial.js +2 -1
  59. package/lib/Renderer/OBB.js +2 -2
  60. package/lib/Renderer/RasterTile.js +22 -4
  61. package/lib/Renderer/Shader/ShaderChunk.js +3 -3
  62. package/lib/Renderer/c3DEngine.js +14 -2
  63. package/lib/Source/FileSource.js +2 -7
  64. package/lib/Source/VectorTilesSource.js +19 -0
  65. package/lib/ThreeExtended/loaders/GLTFLoader.js +320 -76
  66. package/lib/Utils/CameraUtils.js +8 -8
  67. package/lib/Utils/DEMUtils.js +2 -2
  68. package/package.json +29 -29
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.GLTFLoader = void 0;
9
9
 
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+
10
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
13
 
12
14
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -25,6 +27,12 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
25
27
 
26
28
  var _three = require("three");
27
29
 
30
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
31
+
32
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
33
+
34
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
35
+
28
36
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
29
37
 
30
38
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
@@ -60,6 +68,18 @@ var GLTFLoader = /*#__PURE__*/function (_Loader) {
60
68
  return new GLTFMaterialsTransmissionExtension(parser);
61
69
  });
62
70
 
71
+ _this.register(function (parser) {
72
+ return new GLTFMaterialsVolumeExtension(parser);
73
+ });
74
+
75
+ _this.register(function (parser) {
76
+ return new GLTFMaterialsIorExtension(parser);
77
+ });
78
+
79
+ _this.register(function (parser) {
80
+ return new GLTFMaterialsSpecularExtension(parser);
81
+ });
82
+
63
83
  _this.register(function (parser) {
64
84
  return new GLTFLightsExtension(parser);
65
85
  });
@@ -287,9 +307,12 @@ var EXTENSIONS = {
287
307
  KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
288
308
  KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
289
309
  KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
310
+ KHR_MATERIALS_IOR: 'KHR_materials_ior',
290
311
  KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
312
+ KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
291
313
  KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
292
314
  KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
315
+ KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
293
316
  KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
294
317
  KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
295
318
  KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
@@ -498,9 +521,8 @@ var GLTFMaterialsClearcoatExtension = /*#__PURE__*/function () {
498
521
  pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture));
499
522
 
500
523
  if (extension.clearcoatNormalTexture.scale !== undefined) {
501
- var scale = extension.clearcoatNormalTexture.scale; // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
502
-
503
- materialParams.clearcoatNormalScale = new _three.Vector2(scale, -scale);
524
+ var scale = extension.clearcoatNormalTexture.scale;
525
+ materialParams.clearcoatNormalScale = new _three.Vector2(scale, scale);
504
526
  }
505
527
  }
506
528
 
@@ -558,6 +580,147 @@ var GLTFMaterialsTransmissionExtension = /*#__PURE__*/function () {
558
580
  }]);
559
581
  return GLTFMaterialsTransmissionExtension;
560
582
  }();
583
+ /**
584
+ * Materials Volume Extension
585
+ *
586
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
587
+ */
588
+
589
+
590
+ var GLTFMaterialsVolumeExtension = /*#__PURE__*/function () {
591
+ function GLTFMaterialsVolumeExtension(parser) {
592
+ (0, _classCallCheck2["default"])(this, GLTFMaterialsVolumeExtension);
593
+ this.parser = parser;
594
+ this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
595
+ }
596
+
597
+ (0, _createClass2["default"])(GLTFMaterialsVolumeExtension, [{
598
+ key: "getMaterialType",
599
+ value: function getMaterialType(materialIndex) {
600
+ var parser = this.parser;
601
+ var materialDef = parser.json.materials[materialIndex];
602
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
603
+ return _three.MeshPhysicalMaterial;
604
+ }
605
+ }, {
606
+ key: "extendMaterialParams",
607
+ value: function extendMaterialParams(materialIndex, materialParams) {
608
+ var parser = this.parser;
609
+ var materialDef = parser.json.materials[materialIndex];
610
+
611
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
612
+ return Promise.resolve();
613
+ }
614
+
615
+ var pending = [];
616
+ var extension = materialDef.extensions[this.name];
617
+ materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
618
+
619
+ if (extension.thicknessTexture !== undefined) {
620
+ pending.push(parser.assignTexture(materialParams, 'thicknessMap', extension.thicknessTexture));
621
+ }
622
+
623
+ materialParams.attenuationDistance = extension.attenuationDistance || 0;
624
+ var colorArray = extension.attenuationColor || [1, 1, 1];
625
+ materialParams.attenuationTint = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
626
+ return Promise.all(pending);
627
+ }
628
+ }]);
629
+ return GLTFMaterialsVolumeExtension;
630
+ }();
631
+ /**
632
+ * Materials ior Extension
633
+ *
634
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
635
+ */
636
+
637
+
638
+ var GLTFMaterialsIorExtension = /*#__PURE__*/function () {
639
+ function GLTFMaterialsIorExtension(parser) {
640
+ (0, _classCallCheck2["default"])(this, GLTFMaterialsIorExtension);
641
+ this.parser = parser;
642
+ this.name = EXTENSIONS.KHR_MATERIALS_IOR;
643
+ }
644
+
645
+ (0, _createClass2["default"])(GLTFMaterialsIorExtension, [{
646
+ key: "getMaterialType",
647
+ value: function getMaterialType(materialIndex) {
648
+ var parser = this.parser;
649
+ var materialDef = parser.json.materials[materialIndex];
650
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
651
+ return _three.MeshPhysicalMaterial;
652
+ }
653
+ }, {
654
+ key: "extendMaterialParams",
655
+ value: function extendMaterialParams(materialIndex, materialParams) {
656
+ var parser = this.parser;
657
+ var materialDef = parser.json.materials[materialIndex];
658
+
659
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
660
+ return Promise.resolve();
661
+ }
662
+
663
+ var extension = materialDef.extensions[this.name];
664
+ materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
665
+ return Promise.resolve();
666
+ }
667
+ }]);
668
+ return GLTFMaterialsIorExtension;
669
+ }();
670
+ /**
671
+ * Materials specular Extension
672
+ *
673
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
674
+ */
675
+
676
+
677
+ var GLTFMaterialsSpecularExtension = /*#__PURE__*/function () {
678
+ function GLTFMaterialsSpecularExtension(parser) {
679
+ (0, _classCallCheck2["default"])(this, GLTFMaterialsSpecularExtension);
680
+ this.parser = parser;
681
+ this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
682
+ }
683
+
684
+ (0, _createClass2["default"])(GLTFMaterialsSpecularExtension, [{
685
+ key: "getMaterialType",
686
+ value: function getMaterialType(materialIndex) {
687
+ var parser = this.parser;
688
+ var materialDef = parser.json.materials[materialIndex];
689
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
690
+ return _three.MeshPhysicalMaterial;
691
+ }
692
+ }, {
693
+ key: "extendMaterialParams",
694
+ value: function extendMaterialParams(materialIndex, materialParams) {
695
+ var parser = this.parser;
696
+ var materialDef = parser.json.materials[materialIndex];
697
+
698
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
699
+ return Promise.resolve();
700
+ }
701
+
702
+ var pending = [];
703
+ var extension = materialDef.extensions[this.name];
704
+ materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
705
+
706
+ if (extension.specularTexture !== undefined) {
707
+ pending.push(parser.assignTexture(materialParams, 'specularIntensityMap', extension.specularTexture));
708
+ }
709
+
710
+ var colorArray = extension.specularColorFactor || [1, 1, 1];
711
+ materialParams.specularTint = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
712
+
713
+ if (extension.specularColorTexture !== undefined) {
714
+ pending.push(parser.assignTexture(materialParams, 'specularTintMap', extension.specularColorTexture).then(function (texture) {
715
+ texture.encoding = _three.sRGBEncoding;
716
+ }));
717
+ }
718
+
719
+ return Promise.all(pending);
720
+ }
721
+ }]);
722
+ return GLTFMaterialsSpecularExtension;
723
+ }();
561
724
  /**
562
725
  * BasisU Texture Extension
563
726
  *
@@ -913,7 +1076,7 @@ var GLTFMeshStandardSGMaterial = /*#__PURE__*/function (_MeshStandardMaterial) {
913
1076
  var glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
914
1077
  var specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' texelSpecular = sRGBToLinear( texelSpecular );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
915
1078
  var glossinessMapFragmentChunk = ['float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif'].join('\n');
916
- var lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.specularRoughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.specularRoughness += geometryRoughness;', 'material.specularRoughness = min( material.specularRoughness, 1.0 );', 'material.specularColor = specularFactor;'].join('\n');
1079
+ var lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.roughness += geometryRoughness;', 'material.roughness = min( material.roughness, 1.0 );', 'material.specularColor = specularFactor;'].join('\n');
917
1080
  var uniforms = {
918
1081
  specular: {
919
1082
  value: new _three.Color().setHex(0xffffff)
@@ -1177,6 +1340,31 @@ GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
1177
1340
 
1178
1341
  return result;
1179
1342
  };
1343
+
1344
+ var _q = new _three.Quaternion();
1345
+
1346
+ var GLTFCubicSplineQuaternionInterpolant = /*#__PURE__*/function (_GLTFCubicSplineInter) {
1347
+ (0, _inherits2["default"])(GLTFCubicSplineQuaternionInterpolant, _GLTFCubicSplineInter);
1348
+
1349
+ var _super4 = _createSuper(GLTFCubicSplineQuaternionInterpolant);
1350
+
1351
+ function GLTFCubicSplineQuaternionInterpolant() {
1352
+ (0, _classCallCheck2["default"])(this, GLTFCubicSplineQuaternionInterpolant);
1353
+ return _super4.apply(this, arguments);
1354
+ }
1355
+
1356
+ (0, _createClass2["default"])(GLTFCubicSplineQuaternionInterpolant, [{
1357
+ key: "interpolate_",
1358
+ value: function interpolate_(i1, t0, t, t1) {
1359
+ var result = (0, _get2["default"])((0, _getPrototypeOf2["default"])(GLTFCubicSplineQuaternionInterpolant.prototype), "interpolate_", this).call(this, i1, t0, t, t1);
1360
+
1361
+ _q.fromArray(result).normalize().toArray(result);
1362
+
1363
+ return result;
1364
+ }
1365
+ }]);
1366
+ return GLTFCubicSplineQuaternionInterpolant;
1367
+ }(GLTFCubicSplineInterpolant);
1180
1368
  /*********************************/
1181
1369
 
1182
1370
  /********** INTERNALS ************/
@@ -1619,8 +1807,38 @@ var GLTFParser = /*#__PURE__*/function () {
1619
1807
  }, {
1620
1808
  key: "_getNodeRef",
1621
1809
  value: function _getNodeRef(cache, index, object) {
1810
+ var _this3 = this;
1811
+
1622
1812
  if (cache.refs[index] <= 1) return object;
1623
- var ref = object.clone();
1813
+ var ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
1814
+ // original object from being lost.
1815
+
1816
+ var updateMappings = function (original, clone) {
1817
+ var mappings = _this3.associations.get(original);
1818
+
1819
+ if (mappings != null) {
1820
+ _this3.associations.set(clone, mappings);
1821
+ }
1822
+
1823
+ var _iterator = _createForOfIteratorHelper(original.children.entries()),
1824
+ _step;
1825
+
1826
+ try {
1827
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1828
+ var _step$value = (0, _slicedToArray2["default"])(_step.value, 2),
1829
+ i = _step$value[0],
1830
+ child = _step$value[1];
1831
+
1832
+ updateMappings(child, clone.children[i]);
1833
+ }
1834
+ } catch (err) {
1835
+ _iterator.e(err);
1836
+ } finally {
1837
+ _iterator.f();
1838
+ }
1839
+ };
1840
+
1841
+ updateMappings(object, ref);
1624
1842
  ref.name += '_instance_' + cache.uses[index]++;
1625
1843
  return ref;
1626
1844
  }
@@ -1928,24 +2146,10 @@ var GLTFParser = /*#__PURE__*/function () {
1928
2146
  var URL = self.URL || self.webkitURL;
1929
2147
  var sourceURI = source.uri || '';
1930
2148
  var isObjectURL = false;
1931
- var hasAlpha = true;
1932
- var isJPEG = sourceURI.search(/\.jpe?g($|\?)/i) > 0 || sourceURI.search(/^data\:image\/jpeg/) === 0;
1933
- if (source.mimeType === 'image/jpeg' || isJPEG) hasAlpha = false;
1934
2149
 
1935
2150
  if (source.bufferView !== undefined) {
1936
2151
  // Load binary image data from bufferView, if provided.
1937
2152
  sourceURI = parser.getDependency('bufferView', source.bufferView).then(function (bufferView) {
1938
- if (source.mimeType === 'image/png') {
1939
- // Inspect the PNG 'IHDR' chunk to determine whether the image could have an
1940
- // alpha channel. This check is conservative — the image could have an alpha
1941
- // channel with all values == 1, and the indexed type (colorType == 3) only
1942
- // sometimes contains alpha.
1943
- //
1944
- // https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
1945
- var colorType = new DataView(bufferView, 25, 1).getUint8(0, false);
1946
- hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
1947
- }
1948
-
1949
2153
  isObjectURL = true;
1950
2154
  var blob = new Blob([bufferView], {
1951
2155
  type: source.mimeType
@@ -1963,7 +2167,9 @@ var GLTFParser = /*#__PURE__*/function () {
1963
2167
 
1964
2168
  if (loader.isImageBitmapLoader === true) {
1965
2169
  onLoad = function (imageBitmap) {
1966
- resolve(new _three.CanvasTexture(imageBitmap));
2170
+ var texture = new _three.Texture(imageBitmap);
2171
+ texture.needsUpdate = true;
2172
+ resolve(texture);
1967
2173
  };
1968
2174
  }
1969
2175
 
@@ -1976,9 +2182,7 @@ var GLTFParser = /*#__PURE__*/function () {
1976
2182
  }
1977
2183
 
1978
2184
  texture.flipY = false;
1979
- if (textureDef.name) texture.name = textureDef.name; // When there is definitely no alpha channel in the texture, set RGBFormat to save space.
1980
-
1981
- if (!hasAlpha) texture.format = _three.RGBFormat;
2185
+ if (textureDef.name) texture.name = textureDef.name;
1982
2186
  var samplers = json.samplers || {};
1983
2187
  var sampler = samplers[textureDef.sampler] || {};
1984
2188
  texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || _three.LinearFilter;
@@ -1986,10 +2190,12 @@ var GLTFParser = /*#__PURE__*/function () {
1986
2190
  texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || _three.RepeatWrapping;
1987
2191
  texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || _three.RepeatWrapping;
1988
2192
  parser.associations.set(texture, {
1989
- type: 'textures',
1990
- index: textureIndex
2193
+ textures: textureIndex
1991
2194
  });
1992
2195
  return texture;
2196
+ })["catch"](function () {
2197
+ console.error('THREE.GLTFLoader: Couldn\'t load texture', sourceURI);
2198
+ return null;
1993
2199
  });
1994
2200
  this.textureCache[cacheKey] = promise;
1995
2201
  return promise;
@@ -1999,7 +2205,7 @@ var GLTFParser = /*#__PURE__*/function () {
1999
2205
  * @param {Object} materialParams
2000
2206
  * @param {string} mapName
2001
2207
  * @param {Object} mapDef
2002
- * @return {Promise}
2208
+ * @return {Promise<Texture>}
2003
2209
  */
2004
2210
 
2005
2211
  }, {
@@ -2024,6 +2230,7 @@ var GLTFParser = /*#__PURE__*/function () {
2024
2230
  }
2025
2231
 
2026
2232
  materialParams[mapName] = texture;
2233
+ return texture;
2027
2234
  });
2028
2235
  }
2029
2236
  /**
@@ -2040,11 +2247,9 @@ var GLTFParser = /*#__PURE__*/function () {
2040
2247
  value: function assignFinalMaterial(mesh) {
2041
2248
  var geometry = mesh.geometry;
2042
2249
  var material = mesh.material;
2043
- var useVertexTangents = geometry.attributes.tangent !== undefined;
2250
+ var useDerivativeTangents = geometry.attributes.tangent === undefined;
2044
2251
  var useVertexColors = geometry.attributes.color !== undefined;
2045
2252
  var useFlatShading = geometry.attributes.normal === undefined;
2046
- var useMorphTargets = Object.keys(geometry.morphAttributes).length > 0;
2047
- var useMorphNormals = useMorphTargets && geometry.morphAttributes.normal !== undefined;
2048
2253
 
2049
2254
  if (mesh.isPoints) {
2050
2255
  var cacheKey = 'PointsMaterial:' + material.uuid;
@@ -2081,27 +2286,22 @@ var GLTFParser = /*#__PURE__*/function () {
2081
2286
  } // Clone the material if it will be modified
2082
2287
 
2083
2288
 
2084
- if (useVertexTangents || useVertexColors || useFlatShading || useMorphTargets) {
2289
+ if (useDerivativeTangents || useVertexColors || useFlatShading) {
2085
2290
  var _cacheKey2 = 'ClonedMaterial:' + material.uuid + ':';
2086
2291
 
2087
2292
  if (material.isGLTFSpecularGlossinessMaterial) _cacheKey2 += 'specular-glossiness:';
2088
- if (useVertexTangents) _cacheKey2 += 'vertex-tangents:';
2293
+ if (useDerivativeTangents) _cacheKey2 += 'derivative-tangents:';
2089
2294
  if (useVertexColors) _cacheKey2 += 'vertex-colors:';
2090
2295
  if (useFlatShading) _cacheKey2 += 'flat-shading:';
2091
- if (useMorphTargets) _cacheKey2 += 'morph-targets:';
2092
- if (useMorphNormals) _cacheKey2 += 'morph-normals:';
2093
2296
  var cachedMaterial = this.cache.get(_cacheKey2);
2094
2297
 
2095
2298
  if (!cachedMaterial) {
2096
2299
  cachedMaterial = material.clone();
2097
2300
  if (useVertexColors) cachedMaterial.vertexColors = true;
2098
2301
  if (useFlatShading) cachedMaterial.flatShading = true;
2099
- if (useMorphTargets) cachedMaterial.morphTargets = true;
2100
- if (useMorphNormals) cachedMaterial.morphNormals = true;
2101
-
2102
- if (useVertexTangents) {
2103
- cachedMaterial.vertexTangents = true; // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2104
2302
 
2303
+ if (useDerivativeTangents) {
2304
+ // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2105
2305
  if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
2106
2306
  if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
2107
2307
  }
@@ -2122,9 +2322,7 @@ var GLTFParser = /*#__PURE__*/function () {
2122
2322
  }
2123
2323
  }, {
2124
2324
  key: "getMaterialType",
2125
- value: function getMaterialType()
2126
- /* materialIndex */
2127
- {
2325
+ value: function getMaterialType() {
2128
2326
  return _three.MeshStandardMaterial;
2129
2327
  }
2130
2328
  /**
@@ -2197,6 +2395,7 @@ var GLTFParser = /*#__PURE__*/function () {
2197
2395
 
2198
2396
  materialParams.depthWrite = false;
2199
2397
  } else {
2398
+ materialParams.format = _three.RGBFormat;
2200
2399
  materialParams.transparent = false;
2201
2400
 
2202
2401
  if (alphaMode === ALPHA_MODES.MASK) {
@@ -2205,12 +2404,12 @@ var GLTFParser = /*#__PURE__*/function () {
2205
2404
  }
2206
2405
 
2207
2406
  if (materialDef.normalTexture !== undefined && materialType !== _three.MeshBasicMaterial) {
2208
- pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture)); // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2209
-
2210
- materialParams.normalScale = new _three.Vector2(1, -1);
2407
+ pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture));
2408
+ materialParams.normalScale = new _three.Vector2(1, 1);
2211
2409
 
2212
2410
  if (materialDef.normalTexture.scale !== undefined) {
2213
- materialParams.normalScale.set(materialDef.normalTexture.scale, -materialDef.normalTexture.scale);
2411
+ var scale = materialDef.normalTexture.scale;
2412
+ materialParams.normalScale.set(scale, scale);
2214
2413
  }
2215
2414
  }
2216
2415
 
@@ -2245,8 +2444,7 @@ var GLTFParser = /*#__PURE__*/function () {
2245
2444
  if (material.emissiveMap) material.emissiveMap.encoding = _three.sRGBEncoding;
2246
2445
  assignExtrasToUserData(material, materialDef);
2247
2446
  parser.associations.set(material, {
2248
- type: 'materials',
2249
- index: materialIndex
2447
+ materials: materialIndex
2250
2448
  });
2251
2449
  if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
2252
2450
  return material;
@@ -2395,14 +2593,24 @@ var GLTFParser = /*#__PURE__*/function () {
2395
2593
  meshes.push(mesh);
2396
2594
  }
2397
2595
 
2596
+ for (var _i5 = 0, _il4 = meshes.length; _i5 < _il4; _i5++) {
2597
+ parser.associations.set(meshes[_i5], {
2598
+ meshes: meshIndex,
2599
+ primitives: _i5
2600
+ });
2601
+ }
2602
+
2398
2603
  if (meshes.length === 1) {
2399
2604
  return meshes[0];
2400
2605
  }
2401
2606
 
2402
2607
  var group = new _three.Group();
2608
+ parser.associations.set(group, {
2609
+ meshes: meshIndex
2610
+ });
2403
2611
 
2404
- for (var _i5 = 0, _il4 = meshes.length; _i5 < _il4; _i5++) {
2405
- group.add(meshes[_i5]);
2612
+ for (var _i6 = 0, _il5 = meshes.length; _i6 < _il5; _i6++) {
2613
+ group.add(meshes[_i6]);
2406
2614
  }
2407
2615
 
2408
2616
  return group;
@@ -2499,12 +2707,12 @@ var GLTFParser = /*#__PURE__*/function () {
2499
2707
  var targets = dependencies[4];
2500
2708
  var tracks = [];
2501
2709
 
2502
- var _loop = function (_i6) {
2503
- var node = nodes[_i6];
2504
- var inputAccessor = inputAccessors[_i6];
2505
- var outputAccessor = outputAccessors[_i6];
2506
- var sampler = samplers[_i6];
2507
- var target = targets[_i6];
2710
+ var _loop = function (_i7) {
2711
+ var node = nodes[_i7];
2712
+ var inputAccessor = inputAccessors[_i7];
2713
+ var outputAccessor = outputAccessors[_i7];
2714
+ var sampler = samplers[_i7];
2715
+ var target = targets[_i7];
2508
2716
  if (node === undefined) return "continue";
2509
2717
  node.updateMatrix();
2510
2718
  node.matrixAutoUpdate = true;
@@ -2562,7 +2770,8 @@ var GLTFParser = /*#__PURE__*/function () {
2562
2770
  // A CUBICSPLINE keyframe in glTF has three output values for each input value,
2563
2771
  // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
2564
2772
  // must be divided by three to get the interpolant's sampleSize argument.
2565
- return new GLTFCubicSplineInterpolant(this.times, this.values, this.getValueSize() / 3, result);
2773
+ var interpolantType = this instanceof _three.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
2774
+ return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
2566
2775
  }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
2567
2776
 
2568
2777
 
@@ -2573,8 +2782,8 @@ var GLTFParser = /*#__PURE__*/function () {
2573
2782
  }
2574
2783
  };
2575
2784
 
2576
- for (var _i6 = 0, _il5 = nodes.length; _i6 < _il5; _i6++) {
2577
- var _ret = _loop(_i6, _il5);
2785
+ for (var _i7 = 0, _il6 = nodes.length; _i7 < _il6; _i7++) {
2786
+ var _ret = _loop(_i7, _il6);
2578
2787
 
2579
2788
  if (_ret === "continue") continue;
2580
2789
  }
@@ -2691,10 +2900,11 @@ var GLTFParser = /*#__PURE__*/function () {
2691
2900
  }
2692
2901
  }
2693
2902
 
2694
- parser.associations.set(node, {
2695
- type: 'nodes',
2696
- index: nodeIndex
2697
- });
2903
+ if (!parser.associations.has(node)) {
2904
+ parser.associations.set(node, {});
2905
+ }
2906
+
2907
+ parser.associations.get(node).nodes = nodeIndex;
2698
2908
  return node;
2699
2909
  });
2700
2910
  }
@@ -2721,10 +2931,44 @@ var GLTFParser = /*#__PURE__*/function () {
2721
2931
  var pending = [];
2722
2932
 
2723
2933
  for (var i = 0, il = nodeIds.length; i < il; i++) {
2724
- pending.push(buildNodeHierachy(nodeIds[i], scene, json, parser));
2934
+ pending.push(buildNodeHierarchy(nodeIds[i], scene, json, parser));
2725
2935
  }
2726
2936
 
2727
2937
  return Promise.all(pending).then(function () {
2938
+ // Removes dangling associations, associations that reference a node that
2939
+ // didn't make it into the scene.
2940
+ parser.associations = function reduceAssociations(node) {
2941
+ var reducedAssociations = new Map();
2942
+
2943
+ var _iterator2 = _createForOfIteratorHelper(parser.associations),
2944
+ _step2;
2945
+
2946
+ try {
2947
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2948
+ var _step2$value = (0, _slicedToArray2["default"])(_step2.value, 2),
2949
+ key = _step2$value[0],
2950
+ value = _step2$value[1];
2951
+
2952
+ if (key instanceof _three.Material || key instanceof _three.Texture) {
2953
+ reducedAssociations.set(key, value);
2954
+ }
2955
+ }
2956
+ } catch (err) {
2957
+ _iterator2.e(err);
2958
+ } finally {
2959
+ _iterator2.f();
2960
+ }
2961
+
2962
+ node.traverse(function (node) {
2963
+ var mappings = parser.associations.get(node);
2964
+
2965
+ if (mappings != null) {
2966
+ reducedAssociations.set(node, mappings);
2967
+ }
2968
+ });
2969
+ return reducedAssociations;
2970
+ }(scene);
2971
+
2728
2972
  return scene;
2729
2973
  });
2730
2974
  }
@@ -2732,7 +2976,7 @@ var GLTFParser = /*#__PURE__*/function () {
2732
2976
  return GLTFParser;
2733
2977
  }();
2734
2978
 
2735
- function buildNodeHierachy(nodeId, parentObject, json, parser) {
2979
+ function buildNodeHierarchy(nodeId, parentObject, json, parser) {
2736
2980
  var nodeDef = json.nodes[nodeId];
2737
2981
  return parser.getDependency('node', nodeId).then(function (node) {
2738
2982
  if (nodeDef.skin === undefined) return node; // build skeleton here as well
@@ -2784,7 +3028,7 @@ function buildNodeHierachy(nodeId, parentObject, json, parser) {
2784
3028
 
2785
3029
  for (var i = 0, il = children.length; i < il; i++) {
2786
3030
  var child = children[i];
2787
- pending.push(buildNodeHierachy(child, node, json, parser));
3031
+ pending.push(buildNodeHierarchy(child, node, json, parser));
2788
3032
  }
2789
3033
  }
2790
3034
 
@@ -2941,22 +3185,22 @@ function toTrianglesDrawMode(geometry, drawMode) {
2941
3185
 
2942
3186
  if (drawMode === _three.TriangleFanDrawMode) {
2943
3187
  // gl.TRIANGLE_FAN
2944
- for (var _i7 = 1; _i7 <= numberOfTriangles; _i7++) {
3188
+ for (var _i8 = 1; _i8 <= numberOfTriangles; _i8++) {
2945
3189
  newIndices.push(index.getX(0));
2946
- newIndices.push(index.getX(_i7));
2947
- newIndices.push(index.getX(_i7 + 1));
3190
+ newIndices.push(index.getX(_i8));
3191
+ newIndices.push(index.getX(_i8 + 1));
2948
3192
  }
2949
3193
  } else {
2950
3194
  // gl.TRIANGLE_STRIP
2951
- for (var _i8 = 0; _i8 < numberOfTriangles; _i8++) {
2952
- if (_i8 % 2 === 0) {
2953
- newIndices.push(index.getX(_i8));
2954
- newIndices.push(index.getX(_i8 + 1));
2955
- newIndices.push(index.getX(_i8 + 2));
3195
+ for (var _i9 = 0; _i9 < numberOfTriangles; _i9++) {
3196
+ if (_i9 % 2 === 0) {
3197
+ newIndices.push(index.getX(_i9));
3198
+ newIndices.push(index.getX(_i9 + 1));
3199
+ newIndices.push(index.getX(_i9 + 2));
2956
3200
  } else {
2957
- newIndices.push(index.getX(_i8 + 2));
2958
- newIndices.push(index.getX(_i8 + 1));
2959
- newIndices.push(index.getX(_i8));
3201
+ newIndices.push(index.getX(_i9 + 2));
3202
+ newIndices.push(index.getX(_i9 + 1));
3203
+ newIndices.push(index.getX(_i9));
2960
3204
  }
2961
3205
  }
2962
3206
  }