itowns 2.35.0 → 2.37.0

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 (110) hide show
  1. package/CONTRIBUTING.md +30 -17
  2. package/CONTRIBUTORS.md +1 -0
  3. package/changelog.md +146 -0
  4. package/dist/debug.js +1 -1
  5. package/dist/debug.js.LICENSE.txt +1 -1
  6. package/dist/debug.js.map +1 -1
  7. package/dist/itowns.js +1 -1
  8. package/dist/itowns.js.map +1 -1
  9. package/dist/itowns_widgets.js +2 -0
  10. package/dist/itowns_widgets.js.map +1 -0
  11. package/examples/3dtiles_basic.html +2 -2
  12. package/examples/config.json +25 -6
  13. package/examples/css/widgets.css +248 -0
  14. package/examples/geoid_geoidLayer.html +102 -0
  15. package/examples/images/compass.svg +60 -0
  16. package/examples/images/widget-logo.svg +66 -0
  17. package/examples/itowns-potree.html +252 -0
  18. package/examples/js/GUI/GuiTools.js +17 -0
  19. package/examples/js/Scale.js +1 -0
  20. package/examples/js/plugins/CSVnVRTParser.js +0 -1
  21. package/examples/layers/JSONLayers/Administrative.json +1 -1
  22. package/examples/layers/JSONLayers/Cada.json +1 -1
  23. package/examples/layers/JSONLayers/EtatMajor.json +1 -1
  24. package/examples/layers/JSONLayers/IGN_MNT.json +1 -1
  25. package/examples/layers/JSONLayers/IGN_MNT_HIGHRES.json +1 -1
  26. package/examples/layers/JSONLayers/WORLD_DTM.json +1 -1
  27. package/examples/misc_custom_label.html +0 -2
  28. package/examples/plugins_vrt.html +0 -1
  29. package/examples/source_file_from_fetched_data.html +90 -0
  30. package/examples/source_file_from_format.html +85 -0
  31. package/examples/source_file_from_methods.html +87 -0
  32. package/examples/source_file_from_parsed_data.html +104 -0
  33. package/examples/source_file_geojson_raster.html +21 -48
  34. package/examples/source_file_gpx_raster.html +28 -36
  35. package/examples/source_file_kml_raster.html +1 -4
  36. package/examples/source_file_shapefile.html +39 -35
  37. package/examples/source_stream_wfs_25d.html +29 -29
  38. package/examples/source_stream_wfs_3d.html +21 -12
  39. package/examples/source_stream_wfs_raster.html +20 -20
  40. package/examples/view_25d_map.html +28 -0
  41. package/examples/view_immersive.html +13 -14
  42. package/examples/view_multi_25d.html +1 -1
  43. package/examples/widgets_minimap.html +122 -0
  44. package/examples/widgets_navigation.html +119 -0
  45. package/lib/Controls/FirstPersonControls.js +10 -1
  46. package/lib/Controls/GlobeControls.js +26 -11
  47. package/lib/Controls/PlanarControls.js +1 -1
  48. package/lib/Converter/Feature2Mesh.js +1 -0
  49. package/lib/Converter/Feature2Texture.js +2 -2
  50. package/lib/Converter/convertToTile.js +6 -2
  51. package/lib/Core/3DTiles/C3DTBoundingVolume.js +4 -1
  52. package/lib/Core/Deprecated/Undeprecator.js +1 -1
  53. package/lib/Core/Feature.js +42 -42
  54. package/lib/Core/Geographic/Coordinates.js +56 -0
  55. package/lib/Core/Geographic/Crs.js +15 -0
  56. package/lib/Core/Geographic/Extent.js +100 -12
  57. package/lib/Core/Geographic/GeoidGrid.js +143 -0
  58. package/lib/Core/MainLoop.js +1 -1
  59. package/lib/Core/Math/Ellipsoid.js +27 -9
  60. package/lib/Core/Prefab/Globe/BuilderEllipsoidTile.js +1 -1
  61. package/lib/Core/Prefab/Globe/SkyShader.js +3 -1
  62. package/lib/Core/Prefab/Planar/PlanarLayer.js +3 -1
  63. package/lib/Core/Prefab/PlanarView.js +1 -1
  64. package/lib/Core/Style.js +2 -1
  65. package/lib/Core/TileGeometry.js +3 -1
  66. package/lib/Core/TileMesh.js +11 -16
  67. package/lib/Core/View.js +43 -5
  68. package/lib/Layer/ElevationLayer.js +15 -18
  69. package/lib/Layer/FeatureGeometryLayer.js +3 -1
  70. package/lib/Layer/GeoidLayer.js +131 -0
  71. package/lib/Layer/InfoLayer.js +1 -1
  72. package/lib/Layer/LabelLayer.js +7 -1
  73. package/lib/Layer/Layer.js +1 -1
  74. package/lib/Layer/LayerUpdateStrategy.js +1 -1
  75. package/lib/Layer/PotreeLayer.js +3 -1
  76. package/lib/Layer/TiledGeometryLayer.js +3 -1
  77. package/lib/Main.js +214 -174
  78. package/lib/MainBundle.js +1 -1
  79. package/lib/Parser/B3dmParser.js +2 -1
  80. package/lib/Parser/GDFParser.js +118 -0
  81. package/lib/Parser/GTXParser.js +92 -0
  82. package/lib/Parser/ISGParser.js +121 -0
  83. package/lib/Parser/LASParser.js +3 -1
  84. package/lib/Parser/ShapefileParser.js +0 -1
  85. package/lib/Parser/VectorTileParser.js +1 -1
  86. package/lib/Parser/XbilParser.js +1 -1
  87. package/lib/Process/3dTilesProcessing.js +10 -10
  88. package/lib/Process/FeatureProcessing.js +3 -1
  89. package/lib/Process/LayeredMaterialNodeProcessing.js +7 -4
  90. package/lib/Process/ObjectRemovalHelper.js +5 -2
  91. package/lib/Provider/URLBuilder.js +1 -1
  92. package/lib/Renderer/Label2DRenderer.js +14 -11
  93. package/lib/Renderer/LayeredMaterial.js +4 -3
  94. package/lib/Renderer/OBB.js +20 -27
  95. package/lib/Renderer/PointsMaterial.js +5 -6
  96. package/lib/Renderer/RasterTile.js +23 -5
  97. package/lib/Renderer/Shader/ShaderChunk.js +3 -3
  98. package/lib/Renderer/Shader/ShaderUtils.js +4 -2
  99. package/lib/Source/C3DTilesSource.js +3 -1
  100. package/lib/Source/EntwinePointTileSource.js +3 -1
  101. package/lib/Source/FileSource.js +2 -7
  102. package/lib/Source/PotreeSource.js +3 -1
  103. package/lib/Source/Source.js +15 -10
  104. package/lib/Source/VectorTilesSource.js +19 -0
  105. package/lib/Source/WMTSSource.js +3 -1
  106. package/lib/ThreeExtended/loaders/GLTFLoader.js +239 -98
  107. package/lib/Utils/CameraUtils.js +12 -2
  108. package/lib/Utils/DEMUtils.js +3 -3
  109. package/lib/Utils/FeaturesUtils.js +8 -4
  110. package/package.json +25 -25
@@ -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; } }
@@ -56,6 +64,10 @@ var GLTFLoader = /*#__PURE__*/function (_Loader) {
56
64
  return new GLTFTextureWebPExtension(parser);
57
65
  });
58
66
 
67
+ _this.register(function (parser) {
68
+ return new GLTFMaterialsSheenExtension(parser);
69
+ });
70
+
59
71
  _this.register(function (parser) {
60
72
  return new GLTFMaterialsTransmissionExtension(parser);
61
73
  });
@@ -262,6 +274,14 @@ var GLTFLoader = /*#__PURE__*/function (_Loader) {
262
274
  parser.setPlugins(plugins);
263
275
  parser.parse(onLoad, onError);
264
276
  }
277
+ }, {
278
+ key: "parseAsync",
279
+ value: function parseAsync(data, path) {
280
+ var scope = this;
281
+ return new Promise(function (resolve, reject) {
282
+ scope.parse(data, path, resolve, reject);
283
+ });
284
+ }
265
285
  }]);
266
286
  return GLTFLoader;
267
287
  }(_three.Loader);
@@ -301,6 +321,7 @@ var EXTENSIONS = {
301
321
  KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
302
322
  KHR_MATERIALS_IOR: 'KHR_materials_ior',
303
323
  KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
324
+ KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
304
325
  KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
305
326
  KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
306
327
  KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
@@ -513,9 +534,8 @@ var GLTFMaterialsClearcoatExtension = /*#__PURE__*/function () {
513
534
  pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture));
514
535
 
515
536
  if (extension.clearcoatNormalTexture.scale !== undefined) {
516
- var scale = extension.clearcoatNormalTexture.scale; // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
517
-
518
- materialParams.clearcoatNormalScale = new _three.Vector2(scale, -scale);
537
+ var scale = extension.clearcoatNormalTexture.scale;
538
+ materialParams.clearcoatNormalScale = new _three.Vector2(scale, scale);
519
539
  }
520
540
  }
521
541
 
@@ -524,6 +544,65 @@ var GLTFMaterialsClearcoatExtension = /*#__PURE__*/function () {
524
544
  }]);
525
545
  return GLTFMaterialsClearcoatExtension;
526
546
  }();
547
+ /**
548
+ * Sheen Materials Extension
549
+ *
550
+ * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
551
+ */
552
+
553
+
554
+ var GLTFMaterialsSheenExtension = /*#__PURE__*/function () {
555
+ function GLTFMaterialsSheenExtension(parser) {
556
+ (0, _classCallCheck2["default"])(this, GLTFMaterialsSheenExtension);
557
+ this.parser = parser;
558
+ this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
559
+ }
560
+
561
+ (0, _createClass2["default"])(GLTFMaterialsSheenExtension, [{
562
+ key: "getMaterialType",
563
+ value: function getMaterialType(materialIndex) {
564
+ var parser = this.parser;
565
+ var materialDef = parser.json.materials[materialIndex];
566
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) return null;
567
+ return _three.MeshPhysicalMaterial;
568
+ }
569
+ }, {
570
+ key: "extendMaterialParams",
571
+ value: function extendMaterialParams(materialIndex, materialParams) {
572
+ var parser = this.parser;
573
+ var materialDef = parser.json.materials[materialIndex];
574
+
575
+ if (!materialDef.extensions || !materialDef.extensions[this.name]) {
576
+ return Promise.resolve();
577
+ }
578
+
579
+ var pending = [];
580
+ materialParams.sheenColor = new _three.Color(0, 0, 0);
581
+ materialParams.sheenRoughness = 0;
582
+ materialParams.sheen = 1;
583
+ var extension = materialDef.extensions[this.name];
584
+
585
+ if (extension.sheenColorFactor !== undefined) {
586
+ materialParams.sheenColor.fromArray(extension.sheenColorFactor);
587
+ }
588
+
589
+ if (extension.sheenRoughnessFactor !== undefined) {
590
+ materialParams.sheenRoughness = extension.sheenRoughnessFactor;
591
+ }
592
+
593
+ if (extension.sheenColorTexture !== undefined) {
594
+ pending.push(parser.assignTexture(materialParams, 'sheenColorMap', extension.sheenColorTexture));
595
+ }
596
+
597
+ if (extension.sheenRoughnessTexture !== undefined) {
598
+ pending.push(parser.assignTexture(materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture));
599
+ }
600
+
601
+ return Promise.all(pending);
602
+ }
603
+ }]);
604
+ return GLTFMaterialsSheenExtension;
605
+ }();
527
606
  /**
528
607
  * Transmission Materials Extension
529
608
  *
@@ -615,7 +694,7 @@ var GLTFMaterialsVolumeExtension = /*#__PURE__*/function () {
615
694
 
616
695
  materialParams.attenuationDistance = extension.attenuationDistance || 0;
617
696
  var colorArray = extension.attenuationColor || [1, 1, 1];
618
- materialParams.attenuationTint = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
697
+ materialParams.attenuationColor = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
619
698
  return Promise.all(pending);
620
699
  }
621
700
  }]);
@@ -701,10 +780,10 @@ var GLTFMaterialsSpecularExtension = /*#__PURE__*/function () {
701
780
  }
702
781
 
703
782
  var colorArray = extension.specularColorFactor || [1, 1, 1];
704
- materialParams.specularTint = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
783
+ materialParams.specularColor = new _three.Color(colorArray[0], colorArray[1], colorArray[2]);
705
784
 
706
785
  if (extension.specularColorTexture !== undefined) {
707
- pending.push(parser.assignTexture(materialParams, 'specularTintMap', extension.specularColorTexture).then(function (texture) {
786
+ pending.push(parser.assignTexture(materialParams, 'specularColorMap', extension.specularColorTexture).then(function (texture) {
708
787
  texture.encoding = _three.sRGBEncoding;
709
788
  }));
710
789
  }
@@ -885,8 +964,7 @@ var BINARY_EXTENSION_CHUNK_TYPES = {
885
964
  JSON: 0x4E4F534A,
886
965
  BIN: 0x004E4942
887
966
  };
888
-
889
- var GLTFBinaryExtension = function GLTFBinaryExtension(data) {
967
+ var GLTFBinaryExtension = /*#__PURE__*/(0, _createClass2["default"])(function GLTFBinaryExtension(data) {
890
968
  (0, _classCallCheck2["default"])(this, GLTFBinaryExtension);
891
969
  this.name = EXTENSIONS.KHR_BINARY_GLTF;
892
970
  this.content = null;
@@ -929,14 +1007,13 @@ var GLTFBinaryExtension = function GLTFBinaryExtension(data) {
929
1007
  if (this.content === null) {
930
1008
  throw new Error('THREE.GLTFLoader: JSON content not found.');
931
1009
  }
932
- };
1010
+ });
933
1011
  /**
934
1012
  * DRACO Mesh Compression Extension
935
1013
  *
936
1014
  * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
937
1015
  */
938
1016
 
939
-
940
1017
  var GLTFDracoMeshCompressionExtension = /*#__PURE__*/function () {
941
1018
  function GLTFDracoMeshCompressionExtension(json, dracoLoader) {
942
1019
  (0, _classCallCheck2["default"])(this, GLTFDracoMeshCompressionExtension);
@@ -1069,7 +1146,7 @@ var GLTFMeshStandardSGMaterial = /*#__PURE__*/function (_MeshStandardMaterial) {
1069
1146
  var glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
1070
1147
  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');
1071
1148
  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');
1072
- 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');
1149
+ 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');
1073
1150
  var uniforms = {
1074
1151
  specular: {
1075
1152
  value: new _three.Color().setHex(0xffffff)
@@ -1258,10 +1335,10 @@ var GLTFMaterialsPbrSpecularGlossinessExtension = /*#__PURE__*/function () {
1258
1335
  */
1259
1336
 
1260
1337
 
1261
- var GLTFMeshQuantizationExtension = function GLTFMeshQuantizationExtension() {
1338
+ var GLTFMeshQuantizationExtension = /*#__PURE__*/(0, _createClass2["default"])(function GLTFMeshQuantizationExtension() {
1262
1339
  (0, _classCallCheck2["default"])(this, GLTFMeshQuantizationExtension);
1263
1340
  this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
1264
- };
1341
+ });
1265
1342
  /*********************************/
1266
1343
 
1267
1344
  /********** INTERPOLATION ********/
@@ -1270,7 +1347,6 @@ var GLTFMeshQuantizationExtension = function GLTFMeshQuantizationExtension() {
1270
1347
  // Spline Interpolation
1271
1348
  // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
1272
1349
 
1273
-
1274
1350
  var GLTFCubicSplineInterpolant = /*#__PURE__*/function (_Interpolant) {
1275
1351
  (0, _inherits2["default"])(GLTFCubicSplineInterpolant, _Interpolant);
1276
1352
 
@@ -1333,6 +1409,31 @@ GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
1333
1409
 
1334
1410
  return result;
1335
1411
  };
1412
+
1413
+ var _q = new _three.Quaternion();
1414
+
1415
+ var GLTFCubicSplineQuaternionInterpolant = /*#__PURE__*/function (_GLTFCubicSplineInter) {
1416
+ (0, _inherits2["default"])(GLTFCubicSplineQuaternionInterpolant, _GLTFCubicSplineInter);
1417
+
1418
+ var _super4 = _createSuper(GLTFCubicSplineQuaternionInterpolant);
1419
+
1420
+ function GLTFCubicSplineQuaternionInterpolant() {
1421
+ (0, _classCallCheck2["default"])(this, GLTFCubicSplineQuaternionInterpolant);
1422
+ return _super4.apply(this, arguments);
1423
+ }
1424
+
1425
+ (0, _createClass2["default"])(GLTFCubicSplineQuaternionInterpolant, [{
1426
+ key: "interpolate_",
1427
+ value: function interpolate_(i1, t0, t, t1) {
1428
+ var result = (0, _get2["default"])((0, _getPrototypeOf2["default"])(GLTFCubicSplineQuaternionInterpolant.prototype), "interpolate_", this).call(this, i1, t0, t, t1);
1429
+
1430
+ _q.fromArray(result).normalize().toArray(result);
1431
+
1432
+ return result;
1433
+ }
1434
+ }]);
1435
+ return GLTFCubicSplineQuaternionInterpolant;
1436
+ }(GLTFCubicSplineInterpolant);
1336
1437
  /*********************************/
1337
1438
 
1338
1439
  /********** INTERNALS ************/
@@ -1422,30 +1523,10 @@ var ALPHA_MODES = {
1422
1523
  MASK: 'MASK',
1423
1524
  BLEND: 'BLEND'
1424
1525
  };
1425
- /* UTILITY FUNCTIONS */
1426
-
1427
- function resolveURL(url, path) {
1428
- // Invalid URL
1429
- if (typeof url !== 'string' || url === '') return ''; // Host Relative URL
1430
-
1431
- if (/^https?:\/\//i.test(path) && /^\//.test(url)) {
1432
- path = path.replace(/(^https?:\/\/[^\/]+).*/i, '$1');
1433
- } // Absolute URL http://,https://,//
1434
-
1435
-
1436
- if (/^(https?:)?\/\//i.test(url)) return url; // Data URI
1437
-
1438
- if (/^data:.*,.*$/i.test(url)) return url; // Blob URL
1439
-
1440
- if (/^blob:.*$/i.test(url)) return url; // Relative URL
1441
-
1442
- return path + url;
1443
- }
1444
1526
  /**
1445
1527
  * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
1446
1528
  */
1447
1529
 
1448
-
1449
1530
  function createDefaultMaterial(cache) {
1450
1531
  if (cache['DefaultMaterial'] === undefined) {
1451
1532
  cache['DefaultMaterial'] = new _three.MeshStandardMaterial({
@@ -1775,8 +1856,38 @@ var GLTFParser = /*#__PURE__*/function () {
1775
1856
  }, {
1776
1857
  key: "_getNodeRef",
1777
1858
  value: function _getNodeRef(cache, index, object) {
1859
+ var _this3 = this;
1860
+
1778
1861
  if (cache.refs[index] <= 1) return object;
1779
- var ref = object.clone();
1862
+ var ref = object.clone(); // Propagates mappings to the cloned object, prevents mappings on the
1863
+ // original object from being lost.
1864
+
1865
+ var updateMappings = function (original, clone) {
1866
+ var mappings = _this3.associations.get(original);
1867
+
1868
+ if (mappings != null) {
1869
+ _this3.associations.set(clone, mappings);
1870
+ }
1871
+
1872
+ var _iterator = _createForOfIteratorHelper(original.children.entries()),
1873
+ _step;
1874
+
1875
+ try {
1876
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1877
+ var _step$value = (0, _slicedToArray2["default"])(_step.value, 2),
1878
+ i = _step$value[0],
1879
+ child = _step$value[1];
1880
+
1881
+ updateMappings(child, clone.children[i]);
1882
+ }
1883
+ } catch (err) {
1884
+ _iterator.e(err);
1885
+ } finally {
1886
+ _iterator.f();
1887
+ }
1888
+ };
1889
+
1890
+ updateMappings(object, ref);
1780
1891
  ref.name += '_instance_' + cache.uses[index]++;
1781
1892
  return ref;
1782
1893
  }
@@ -1928,7 +2039,7 @@ var GLTFParser = /*#__PURE__*/function () {
1928
2039
 
1929
2040
  var options = this.options;
1930
2041
  return new Promise(function (resolve, reject) {
1931
- loader.load(resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
2042
+ loader.load(_three.LoaderUtils.resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
1932
2043
  reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
1933
2044
  });
1934
2045
  });
@@ -2084,24 +2195,10 @@ var GLTFParser = /*#__PURE__*/function () {
2084
2195
  var URL = self.URL || self.webkitURL;
2085
2196
  var sourceURI = source.uri || '';
2086
2197
  var isObjectURL = false;
2087
- var hasAlpha = true;
2088
- var isJPEG = sourceURI.search(/\.jpe?g($|\?)/i) > 0 || sourceURI.search(/^data\:image\/jpeg/) === 0;
2089
- if (source.mimeType === 'image/jpeg' || isJPEG) hasAlpha = false;
2090
2198
 
2091
2199
  if (source.bufferView !== undefined) {
2092
2200
  // Load binary image data from bufferView, if provided.
2093
2201
  sourceURI = parser.getDependency('bufferView', source.bufferView).then(function (bufferView) {
2094
- if (source.mimeType === 'image/png') {
2095
- // Inspect the PNG 'IHDR' chunk to determine whether the image could have an
2096
- // alpha channel. This check is conservative — the image could have an alpha
2097
- // channel with all values == 1, and the indexed type (colorType == 3) only
2098
- // sometimes contains alpha.
2099
- //
2100
- // https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
2101
- var colorType = new DataView(bufferView, 25, 1).getUint8(0, false);
2102
- hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
2103
- }
2104
-
2105
2202
  isObjectURL = true;
2106
2203
  var blob = new Blob([bufferView], {
2107
2204
  type: source.mimeType
@@ -2125,7 +2222,7 @@ var GLTFParser = /*#__PURE__*/function () {
2125
2222
  };
2126
2223
  }
2127
2224
 
2128
- loader.load(resolveURL(sourceURI, options.path), onLoad, undefined, reject);
2225
+ loader.load(_three.LoaderUtils.resolveURL(sourceURI, options.path), onLoad, undefined, reject);
2129
2226
  });
2130
2227
  }).then(function (texture) {
2131
2228
  // Clean up resources and configure Texture.
@@ -2134,9 +2231,7 @@ var GLTFParser = /*#__PURE__*/function () {
2134
2231
  }
2135
2232
 
2136
2233
  texture.flipY = false;
2137
- if (textureDef.name) texture.name = textureDef.name; // When there is definitely no alpha channel in the texture, set RGBFormat to save space.
2138
-
2139
- if (!hasAlpha) texture.format = _three.RGBFormat;
2234
+ if (textureDef.name) texture.name = textureDef.name;
2140
2235
  var samplers = json.samplers || {};
2141
2236
  var sampler = samplers[textureDef.sampler] || {};
2142
2237
  texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || _three.LinearFilter;
@@ -2144,8 +2239,7 @@ var GLTFParser = /*#__PURE__*/function () {
2144
2239
  texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || _three.RepeatWrapping;
2145
2240
  texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || _three.RepeatWrapping;
2146
2241
  parser.associations.set(texture, {
2147
- type: 'textures',
2148
- index: textureIndex
2242
+ textures: textureIndex
2149
2243
  });
2150
2244
  return texture;
2151
2245
  })["catch"](function () {
@@ -2202,7 +2296,7 @@ var GLTFParser = /*#__PURE__*/function () {
2202
2296
  value: function assignFinalMaterial(mesh) {
2203
2297
  var geometry = mesh.geometry;
2204
2298
  var material = mesh.material;
2205
- var useVertexTangents = geometry.attributes.tangent !== undefined;
2299
+ var useDerivativeTangents = geometry.attributes.tangent === undefined;
2206
2300
  var useVertexColors = geometry.attributes.color !== undefined;
2207
2301
  var useFlatShading = geometry.attributes.normal === undefined;
2208
2302
 
@@ -2241,11 +2335,11 @@ var GLTFParser = /*#__PURE__*/function () {
2241
2335
  } // Clone the material if it will be modified
2242
2336
 
2243
2337
 
2244
- if (useVertexTangents || useVertexColors || useFlatShading) {
2338
+ if (useDerivativeTangents || useVertexColors || useFlatShading) {
2245
2339
  var _cacheKey2 = 'ClonedMaterial:' + material.uuid + ':';
2246
2340
 
2247
2341
  if (material.isGLTFSpecularGlossinessMaterial) _cacheKey2 += 'specular-glossiness:';
2248
- if (useVertexTangents) _cacheKey2 += 'vertex-tangents:';
2342
+ if (useDerivativeTangents) _cacheKey2 += 'derivative-tangents:';
2249
2343
  if (useVertexColors) _cacheKey2 += 'vertex-colors:';
2250
2344
  if (useFlatShading) _cacheKey2 += 'flat-shading:';
2251
2345
  var cachedMaterial = this.cache.get(_cacheKey2);
@@ -2255,7 +2349,7 @@ var GLTFParser = /*#__PURE__*/function () {
2255
2349
  if (useVertexColors) cachedMaterial.vertexColors = true;
2256
2350
  if (useFlatShading) cachedMaterial.flatShading = true;
2257
2351
 
2258
- if (useVertexTangents) {
2352
+ if (useDerivativeTangents) {
2259
2353
  // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2260
2354
  if (cachedMaterial.normalScale) cachedMaterial.normalScale.y *= -1;
2261
2355
  if (cachedMaterial.clearcoatNormalScale) cachedMaterial.clearcoatNormalScale.y *= -1;
@@ -2277,7 +2371,9 @@ var GLTFParser = /*#__PURE__*/function () {
2277
2371
  }
2278
2372
  }, {
2279
2373
  key: "getMaterialType",
2280
- value: function getMaterialType() {
2374
+ value: function
2375
+ /* materialIndex */
2376
+ getMaterialType() {
2281
2377
  return _three.MeshStandardMaterial;
2282
2378
  }
2283
2379
  /**
@@ -2350,6 +2446,7 @@ var GLTFParser = /*#__PURE__*/function () {
2350
2446
 
2351
2447
  materialParams.depthWrite = false;
2352
2448
  } else {
2449
+ materialParams.format = _three.RGBFormat;
2353
2450
  materialParams.transparent = false;
2354
2451
 
2355
2452
  if (alphaMode === ALPHA_MODES.MASK) {
@@ -2358,12 +2455,12 @@ var GLTFParser = /*#__PURE__*/function () {
2358
2455
  }
2359
2456
 
2360
2457
  if (materialDef.normalTexture !== undefined && materialType !== _three.MeshBasicMaterial) {
2361
- pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture)); // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
2362
-
2363
- materialParams.normalScale = new _three.Vector2(1, -1);
2458
+ pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture));
2459
+ materialParams.normalScale = new _three.Vector2(1, 1);
2364
2460
 
2365
2461
  if (materialDef.normalTexture.scale !== undefined) {
2366
- materialParams.normalScale.set(materialDef.normalTexture.scale, -materialDef.normalTexture.scale);
2462
+ var scale = materialDef.normalTexture.scale;
2463
+ materialParams.normalScale.set(scale, scale);
2367
2464
  }
2368
2465
  }
2369
2466
 
@@ -2398,8 +2495,7 @@ var GLTFParser = /*#__PURE__*/function () {
2398
2495
  if (material.emissiveMap) material.emissiveMap.encoding = _three.sRGBEncoding;
2399
2496
  assignExtrasToUserData(material, materialDef);
2400
2497
  parser.associations.set(material, {
2401
- type: 'materials',
2402
- index: materialIndex
2498
+ materials: materialIndex
2403
2499
  });
2404
2500
  if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
2405
2501
  return material;
@@ -2548,14 +2644,24 @@ var GLTFParser = /*#__PURE__*/function () {
2548
2644
  meshes.push(mesh);
2549
2645
  }
2550
2646
 
2647
+ for (var _i5 = 0, _il4 = meshes.length; _i5 < _il4; _i5++) {
2648
+ parser.associations.set(meshes[_i5], {
2649
+ meshes: meshIndex,
2650
+ primitives: _i5
2651
+ });
2652
+ }
2653
+
2551
2654
  if (meshes.length === 1) {
2552
2655
  return meshes[0];
2553
2656
  }
2554
2657
 
2555
2658
  var group = new _three.Group();
2659
+ parser.associations.set(group, {
2660
+ meshes: meshIndex
2661
+ });
2556
2662
 
2557
- for (var _i5 = 0, _il4 = meshes.length; _i5 < _il4; _i5++) {
2558
- group.add(meshes[_i5]);
2663
+ for (var _i6 = 0, _il5 = meshes.length; _i6 < _il5; _i6++) {
2664
+ group.add(meshes[_i6]);
2559
2665
  }
2560
2666
 
2561
2667
  return group;
@@ -2652,12 +2758,12 @@ var GLTFParser = /*#__PURE__*/function () {
2652
2758
  var targets = dependencies[4];
2653
2759
  var tracks = [];
2654
2760
 
2655
- var _loop = function (_i6) {
2656
- var node = nodes[_i6];
2657
- var inputAccessor = inputAccessors[_i6];
2658
- var outputAccessor = outputAccessors[_i6];
2659
- var sampler = samplers[_i6];
2660
- var target = targets[_i6];
2761
+ var _loop = function (_i7) {
2762
+ var node = nodes[_i7];
2763
+ var inputAccessor = inputAccessors[_i7];
2764
+ var outputAccessor = outputAccessors[_i7];
2765
+ var sampler = samplers[_i7];
2766
+ var target = targets[_i7];
2661
2767
  if (node === undefined) return "continue";
2662
2768
  node.updateMatrix();
2663
2769
  node.matrixAutoUpdate = true;
@@ -2684,9 +2790,8 @@ var GLTFParser = /*#__PURE__*/function () {
2684
2790
  var targetNames = [];
2685
2791
 
2686
2792
  if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
2687
- // Node may be a Group (glTF mesh with several primitives) or a Mesh.
2688
2793
  node.traverse(function (object) {
2689
- if (object.isMesh === true && object.morphTargetInfluences) {
2794
+ if (object.morphTargetInfluences) {
2690
2795
  targetNames.push(object.name ? object.name : object.uuid);
2691
2796
  }
2692
2797
  });
@@ -2715,7 +2820,8 @@ var GLTFParser = /*#__PURE__*/function () {
2715
2820
  // A CUBICSPLINE keyframe in glTF has three output values for each input value,
2716
2821
  // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
2717
2822
  // must be divided by three to get the interpolant's sampleSize argument.
2718
- return new GLTFCubicSplineInterpolant(this.times, this.values, this.getValueSize() / 3, result);
2823
+ var interpolantType = this instanceof _three.QuaternionKeyframeTrack ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
2824
+ return new interpolantType(this.times, this.values, this.getValueSize() / 3, result);
2719
2825
  }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
2720
2826
 
2721
2827
 
@@ -2726,8 +2832,8 @@ var GLTFParser = /*#__PURE__*/function () {
2726
2832
  }
2727
2833
  };
2728
2834
 
2729
- for (var _i6 = 0, _il5 = nodes.length; _i6 < _il5; _i6++) {
2730
- var _ret = _loop(_i6, _il5);
2835
+ for (var _i7 = 0, _il6 = nodes.length; _i7 < _il6; _i7++) {
2836
+ var _ret = _loop(_i7, _il6);
2731
2837
 
2732
2838
  if (_ret === "continue") continue;
2733
2839
  }
@@ -2844,10 +2950,11 @@ var GLTFParser = /*#__PURE__*/function () {
2844
2950
  }
2845
2951
  }
2846
2952
 
2847
- parser.associations.set(node, {
2848
- type: 'nodes',
2849
- index: nodeIndex
2850
- });
2953
+ if (!parser.associations.has(node)) {
2954
+ parser.associations.set(node, {});
2955
+ }
2956
+
2957
+ parser.associations.get(node).nodes = nodeIndex;
2851
2958
  return node;
2852
2959
  });
2853
2960
  }
@@ -2874,10 +2981,44 @@ var GLTFParser = /*#__PURE__*/function () {
2874
2981
  var pending = [];
2875
2982
 
2876
2983
  for (var i = 0, il = nodeIds.length; i < il; i++) {
2877
- pending.push(buildNodeHierachy(nodeIds[i], scene, json, parser));
2984
+ pending.push(buildNodeHierarchy(nodeIds[i], scene, json, parser));
2878
2985
  }
2879
2986
 
2880
2987
  return Promise.all(pending).then(function () {
2988
+ // Removes dangling associations, associations that reference a node that
2989
+ // didn't make it into the scene.
2990
+ parser.associations = function reduceAssociations(node) {
2991
+ var reducedAssociations = new Map();
2992
+
2993
+ var _iterator2 = _createForOfIteratorHelper(parser.associations),
2994
+ _step2;
2995
+
2996
+ try {
2997
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
2998
+ var _step2$value = (0, _slicedToArray2["default"])(_step2.value, 2),
2999
+ key = _step2$value[0],
3000
+ value = _step2$value[1];
3001
+
3002
+ if (key instanceof _three.Material || key instanceof _three.Texture) {
3003
+ reducedAssociations.set(key, value);
3004
+ }
3005
+ }
3006
+ } catch (err) {
3007
+ _iterator2.e(err);
3008
+ } finally {
3009
+ _iterator2.f();
3010
+ }
3011
+
3012
+ node.traverse(function (node) {
3013
+ var mappings = parser.associations.get(node);
3014
+
3015
+ if (mappings != null) {
3016
+ reducedAssociations.set(node, mappings);
3017
+ }
3018
+ });
3019
+ return reducedAssociations;
3020
+ }(scene);
3021
+
2881
3022
  return scene;
2882
3023
  });
2883
3024
  }
@@ -2885,7 +3026,7 @@ var GLTFParser = /*#__PURE__*/function () {
2885
3026
  return GLTFParser;
2886
3027
  }();
2887
3028
 
2888
- function buildNodeHierachy(nodeId, parentObject, json, parser) {
3029
+ function buildNodeHierarchy(nodeId, parentObject, json, parser) {
2889
3030
  var nodeDef = json.nodes[nodeId];
2890
3031
  return parser.getDependency('node', nodeId).then(function (node) {
2891
3032
  if (nodeDef.skin === undefined) return node; // build skeleton here as well
@@ -2937,7 +3078,7 @@ function buildNodeHierachy(nodeId, parentObject, json, parser) {
2937
3078
 
2938
3079
  for (var i = 0, il = children.length; i < il; i++) {
2939
3080
  var child = children[i];
2940
- pending.push(buildNodeHierachy(child, node, json, parser));
3081
+ pending.push(buildNodeHierarchy(child, node, json, parser));
2941
3082
  }
2942
3083
  }
2943
3084
 
@@ -3094,22 +3235,22 @@ function toTrianglesDrawMode(geometry, drawMode) {
3094
3235
 
3095
3236
  if (drawMode === _three.TriangleFanDrawMode) {
3096
3237
  // gl.TRIANGLE_FAN
3097
- for (var _i7 = 1; _i7 <= numberOfTriangles; _i7++) {
3238
+ for (var _i8 = 1; _i8 <= numberOfTriangles; _i8++) {
3098
3239
  newIndices.push(index.getX(0));
3099
- newIndices.push(index.getX(_i7));
3100
- newIndices.push(index.getX(_i7 + 1));
3240
+ newIndices.push(index.getX(_i8));
3241
+ newIndices.push(index.getX(_i8 + 1));
3101
3242
  }
3102
3243
  } else {
3103
3244
  // gl.TRIANGLE_STRIP
3104
- for (var _i8 = 0; _i8 < numberOfTriangles; _i8++) {
3105
- if (_i8 % 2 === 0) {
3106
- newIndices.push(index.getX(_i8));
3107
- newIndices.push(index.getX(_i8 + 1));
3108
- newIndices.push(index.getX(_i8 + 2));
3245
+ for (var _i9 = 0; _i9 < numberOfTriangles; _i9++) {
3246
+ if (_i9 % 2 === 0) {
3247
+ newIndices.push(index.getX(_i9));
3248
+ newIndices.push(index.getX(_i9 + 1));
3249
+ newIndices.push(index.getX(_i9 + 2));
3109
3250
  } else {
3110
- newIndices.push(index.getX(_i8 + 2));
3111
- newIndices.push(index.getX(_i8 + 1));
3112
- newIndices.push(index.getX(_i8));
3251
+ newIndices.push(index.getX(_i9 + 2));
3252
+ newIndices.push(index.getX(_i9 + 1));
3253
+ newIndices.push(index.getX(_i9));
3113
3254
  }
3114
3255
  }
3115
3256
  }