redhotmagma-visualization 1.38.6 → 1.39.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.
@@ -15,6 +15,8 @@ var _GLTFLoader = require("three/examples/jsm/loaders/GLTFLoader");
15
15
 
16
16
  var _DRACOLoader = require("three/examples/jsm/loaders/DRACOLoader");
17
17
 
18
+ var _RGBELoader = require("three/examples/jsm/loaders/RGBELoader");
19
+
18
20
  var _get = _interopRequireDefault(require("lodash/get"));
19
21
 
20
22
  var _size = _interopRequireDefault(require("lodash/size"));
@@ -25,6 +27,12 @@ var _glTFExporter = require("./Exporters/glTFExporter");
25
27
 
26
28
  var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
27
29
 
30
+ var _merge = _interopRequireDefault(require("lodash/merge"));
31
+
32
+ var _createBakedShadow = _interopRequireDefault(require("../Utils/createBakedShadow"));
33
+
34
+ var _setLightShadow2 = _interopRequireDefault(require("../Utils/setLightShadow"));
35
+
28
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
29
37
 
30
38
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
@@ -182,24 +190,6 @@ function findImageBySrc(tree, src) {
182
190
  return result;
183
191
  }
184
192
 
185
- function setLightShadow(light) {
186
- var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
187
-
188
- // directional light has orthographic camera (due to the parallel ray direction)
189
- if (light.isDirectionalLight) {
190
- light.castShadow = true;
191
- light.shadow.mapSize.width = 1024;
192
- light.shadow.mapSize.height = 1024;
193
- light.shadow.camera.top = d;
194
- light.shadow.camera.bottom = -d;
195
- light.shadow.camera.left = -d;
196
- light.shadow.camera.right = d;
197
- light.shadow.camera.near = 0.0001;
198
- light.shadow.camera.far = 10000;
199
- light.shadow.camera.updateProjectionMatrix();
200
- }
201
- }
202
-
203
193
  function createIndexCounter() {
204
194
  var counters = {};
205
195
 
@@ -397,7 +387,21 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
397
387
 
398
388
  _defineProperty(_assertThisInitialized(_this), "config", {
399
389
  useShadowGround: true,
400
- removeGroundForScreenshot: true
390
+ removeGroundForScreenshot: true,
391
+ useEnvironmentMap: true,
392
+ useBakedShadows: false,
393
+ bakedShadow: {
394
+ lightPositionOffset: {
395
+ x: 0,
396
+ y: 0,
397
+ z: 0
398
+ },
399
+ shadowMapSize: 512,
400
+ groundScaling: 2,
401
+ shadowTextureScaling: 0.96,
402
+ blurRadius: 6,
403
+ shadowOpacity: 0.8
404
+ }
401
405
  });
402
406
 
403
407
  _defineProperty(_assertThisInitialized(_this), "animate", function () {
@@ -457,7 +461,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
457
461
  _createClass(Three3DScene, [{
458
462
  key: "setOptions3D",
459
463
  value: function setOptions3D(options) {
460
- Object.assign(this.config, options);
464
+ (0, _merge["default"])(this.config, options);
461
465
  }
462
466
  }, {
463
467
  key: "createLoadingManager",
@@ -519,8 +523,35 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
519
523
  renderer.setPixelRatio(window.devicePixelRatio);
520
524
  }
521
525
 
526
+ this.config.useEnvironmentMap && this.loadEnvMap(renderer);
522
527
  return renderer;
523
528
  }
529
+ }, {
530
+ key: "getDefaultEnvMapURL",
531
+ value: function getDefaultEnvMapURL() {
532
+ return "hdr/envmap.hdr";
533
+ }
534
+ }, {
535
+ key: "loadEnvMap",
536
+ value: function loadEnvMap(renderer) {
537
+ var _this2 = this;
538
+
539
+ var envMapURL = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getDefaultEnvMapURL();
540
+
541
+ if (this.config.useEnvironmentMap) {
542
+ var pmremGenerator = new _three.PMREMGenerator(renderer);
543
+ pmremGenerator.compileEquirectangularShader();
544
+ this.envMapPromise = new Promise(function (resolve, reject) {
545
+ new _RGBELoader.RGBELoader().setDataType(_three.UnsignedByteType).load(envMapURL, function (texture) {
546
+ _this2.envMap = pmremGenerator.fromEquirectangular(texture).texture;
547
+ _this2.scene.environment = _this2.envMap;
548
+ texture.dispose();
549
+ pmremGenerator.dispose();
550
+ resolve(_this2.envMap);
551
+ }, undefined, reject);
552
+ });
553
+ }
554
+ }
524
555
  }, {
525
556
  key: "createCamera",
526
557
  value: function createCamera() {
@@ -538,17 +569,33 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
538
569
  key: "createScene",
539
570
  value: function createScene() {
540
571
  var scene = new _three.Scene();
541
- scene.add(this.createHemiLight());
542
572
  scene.add(this.createDirLight());
543
573
  scene.add(this.sceneContainer);
574
+
575
+ if (this.config.useEnvironmentMap && this.envMap) {
576
+ scene.environment = this.envMap;
577
+ }
578
+
544
579
  return scene;
545
580
  }
546
581
  }, {
547
582
  key: "createGround",
548
583
  value: function createGround() {
549
- var mesh = new _three.Mesh(new _three.PlaneBufferGeometry(1, 1), new _three.MeshPhongMaterial({
550
- color: 0xffffff
551
- }));
584
+ this.ground && this.scene.remove(this.ground);
585
+ var shadowMaterial;
586
+
587
+ if (this.config.useBakedShadows) {
588
+ shadowMaterial = (0, _createBakedShadow["default"])(this.scene, {
589
+ withMaterial: true,
590
+ config: this.config.bakedShadow
591
+ });
592
+ } else {
593
+ shadowMaterial = new _three.ShadowMaterial({
594
+ color: 0x202020
595
+ });
596
+ }
597
+
598
+ var mesh = new _three.Mesh(new _three.PlaneBufferGeometry(1, 1), shadowMaterial);
552
599
  mesh.name = "ground";
553
600
  mesh.rotation.x = -Math.PI / 2;
554
601
  mesh.receiveShadow = true;
@@ -556,13 +603,16 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
556
603
  return mesh;
557
604
  }
558
605
  }, {
559
- key: "createHemiLight",
560
- value: function createHemiLight() {
561
- var hemiLight = new _three.HemisphereLight(0xffffff, 0x666666, 0.7);
562
- hemiLight.name = "hemiLight";
563
- hemiLight.position.set(0, 100, 0);
564
- this.hemiLight = hemiLight;
565
- return hemiLight;
606
+ key: "setLightShadow",
607
+ value: function setLightShadow(light) {
608
+ var d = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 50;
609
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
610
+ (0, _setLightShadow2["default"])(light, d, (0, _merge["default"])({}, {
611
+ shadowMapSize: 1024,
612
+ cameraProps: {
613
+ far: 10000
614
+ }
615
+ }, options));
566
616
  }
567
617
  }, {
568
618
  key: "createDirLight",
@@ -570,7 +620,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
570
620
  var dirLight = new _three.DirectionalLight(0xffffff, 1);
571
621
  dirLight.name = "dirLight";
572
622
  dirLight.position.set(1, 1, 1).normalize();
573
- setLightShadow(dirLight);
623
+ this.setLightShadow(dirLight);
574
624
  this.dirLight = dirLight;
575
625
  return dirLight;
576
626
  }
@@ -590,16 +640,17 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
590
640
  }, {
591
641
  key: "fixImportedScene",
592
642
  value: function fixImportedScene(scene) {
593
- var _this2 = this;
643
+ var _this3 = this;
594
644
 
595
645
  scene.traverse(function (object) {
596
646
  if (object.isMesh) {
597
647
  object.castShadow = true;
598
648
  }
599
649
 
600
- if (object.isLight && object.target && _this2.ground) {
601
- object.target = _this2.ground;
602
- setLightShadow(object);
650
+ if (object.isLight && object.target && _this3.ground) {
651
+ object.target = _this3.ground;
652
+
653
+ _this3.setLightShadow(object);
603
654
  }
604
655
  });
605
656
  }
@@ -607,7 +658,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
607
658
  key: "applyCustomizations",
608
659
  value: function () {
609
660
  var _applyCustomizations = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(model, item, imageLoader) {
610
- var _this3 = this;
661
+ var _this4 = this;
611
662
 
612
663
  var options,
613
664
  _options$saveAndResto,
@@ -772,7 +823,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
772
823
 
773
824
  case 5:
774
825
  texture = material[p] || material.map && material.map.clone() || new _three.Texture();
775
- _context.t1 = findImageBySrc(_this3.sceneContainer, "".concat(_this3._modelBasePath).concat(_params[p]));
826
+ _context.t1 = findImageBySrc(_this4.sceneContainer, "".concat(_this4._modelBasePath).concat(_params[p]));
776
827
 
777
828
  if (_context.t1) {
778
829
  _context.next = 11;
@@ -853,7 +904,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
853
904
  }, {
854
905
  key: "loadSceneContainer",
855
906
  value: function loadSceneContainer(item) {
856
- var _this4 = this;
907
+ var _this5 = this;
857
908
 
858
909
  var path;
859
910
 
@@ -890,7 +941,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
890
941
  model.userData.index = item.index;
891
942
  }
892
943
 
893
- _this4.fixImportedScene(model);
944
+ _this5.fixImportedScene(model);
894
945
 
895
946
  if (!("object" === itemType)) {
896
947
  _context4.next = 7;
@@ -898,7 +949,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
898
949
  }
899
950
 
900
951
  _context4.next = 7;
901
- return _this4.applyCustomizations(model, item, imageLoader);
952
+ return _this5.applyCustomizations(model, item, imageLoader);
902
953
 
903
954
  case 7:
904
955
  resolve(gltf);
@@ -1003,34 +1054,66 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1003
1054
  key: "loadSceneSync",
1004
1055
  value: function () {
1005
1056
  var _loadSceneSync = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(resourceList) {
1006
- var _disableRender, result;
1007
-
1057
+ var result;
1008
1058
  return regeneratorRuntime.wrap(function _callee6$(_context6) {
1009
1059
  while (1) {
1010
1060
  switch (_context6.prev = _context6.next) {
1011
1061
  case 0:
1012
- _context6.next = 2;
1062
+ _context6.prev = 0;
1063
+ _context6.next = 3;
1013
1064
  return this._loadScenePromise;
1014
1065
 
1015
- case 2:
1016
- _disableRender = this._disableRender;
1017
- this._disableRender = true;
1018
- this._loadScenePromise = this.loadScene(resourceList);
1066
+ case 3:
1019
1067
  _context6.next = 7;
1020
- return this._loadScenePromise;
1068
+ break;
1069
+
1070
+ case 5:
1071
+ _context6.prev = 5;
1072
+ _context6.t0 = _context6["catch"](0);
1021
1073
 
1022
1074
  case 7:
1075
+ _context6.prev = 7;
1076
+ this._loadScenePromise = this.loadScene(resourceList);
1077
+ _context6.next = 11;
1078
+ return this._loadScenePromise;
1079
+
1080
+ case 11:
1023
1081
  result = _context6.sent;
1024
- this._disableRender = _disableRender;
1025
- this.render();
1082
+ _context6.next = 17;
1083
+ break;
1084
+
1085
+ case 14:
1086
+ _context6.prev = 14;
1087
+ _context6.t1 = _context6["catch"](7);
1088
+ // remove promise if it is failed
1089
+ delete this._loadScenePromise;
1090
+
1091
+ case 17:
1092
+ _context6.prev = 17;
1093
+ _context6.next = 20;
1094
+ return this.envMapPromise;
1095
+
1096
+ case 20:
1097
+ _context6.next = 24;
1098
+ break;
1099
+
1100
+ case 22:
1101
+ _context6.prev = 22;
1102
+ _context6.t2 = _context6["catch"](17);
1103
+
1104
+ case 24:
1105
+ if (!this.isAnimating()) {
1106
+ this.render();
1107
+ }
1108
+
1026
1109
  return _context6.abrupt("return", result);
1027
1110
 
1028
- case 11:
1111
+ case 26:
1029
1112
  case "end":
1030
1113
  return _context6.stop();
1031
1114
  }
1032
1115
  }
1033
- }, _callee6, this);
1116
+ }, _callee6, this, [[0, 5], [7, 14], [17, 22]]);
1034
1117
  }));
1035
1118
 
1036
1119
  function loadSceneSync(_x8) {
@@ -1043,7 +1126,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1043
1126
  key: "loadScene",
1044
1127
  value: function () {
1045
1128
  var _loadScene = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(resourceList) {
1046
- var _this5 = this;
1129
+ var _this6 = this;
1047
1130
 
1048
1131
  var sceneContainer, _diffResourceLists, toBeRemoved, toBeAdded, toBeUpdated, toBeApplied, shouldResetScene, toBeDisposed, triggerLoadEvent, sceneParts, imageLoader, mixer, animations;
1049
1132
 
@@ -1077,7 +1160,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1077
1160
  triggerLoadEvent && this.onLoadStart();
1078
1161
  _context7.next = 13;
1079
1162
  return Promise.all(toBeAdded.map(function (item) {
1080
- return _this5.loadSceneContainer(item);
1163
+ return _this6.loadSceneContainer(item);
1081
1164
  }));
1082
1165
 
1083
1166
  case 13:
@@ -1088,11 +1171,11 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1088
1171
  sceneContainer.add(scene); // collect animations
1089
1172
 
1090
1173
  if (animations.length) {
1091
- var _this5$animations;
1174
+ var _this6$animations;
1092
1175
 
1093
- (_this5$animations = _this5.animations).push.apply(_this5$animations, _toConsumableArray(animations.filter(function (_ref11) {
1176
+ (_this6$animations = _this6.animations).push.apply(_this6$animations, _toConsumableArray(animations.filter(function (_ref11) {
1094
1177
  var name = _ref11.name;
1095
- return !_this5.animations.find(function (_ref12) {
1178
+ return !_this6.animations.find(function (_ref12) {
1096
1179
  var existingName = _ref12.name;
1097
1180
  return name !== existingName;
1098
1181
  });
@@ -1109,17 +1192,17 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1109
1192
  });
1110
1193
  var path = getSrc(item);
1111
1194
 
1112
- var _this5$parseModelPath = _this5.parseModelPath(path),
1113
- resourcePath = _this5$parseModelPath.resourcePath;
1195
+ var _this6$parseModelPath = _this6.parseModelPath(path),
1196
+ resourcePath = _this6$parseModelPath.resourcePath;
1114
1197
 
1115
1198
  var loaderOptions = {
1116
- basePath: _this5._modelBasePath,
1199
+ basePath: _this6._modelBasePath,
1117
1200
  resourcePath: resourcePath
1118
1201
  };
1119
1202
 
1120
- var imageLoader = _this5.createImageLoader(loaderOptions);
1203
+ var imageLoader = _this6.createImageLoader(loaderOptions);
1121
1204
 
1122
- return object && _this5.applyCustomizations(object, item, imageLoader);
1205
+ return object && _this6.applyCustomizations(object, item, imageLoader);
1123
1206
  }));
1124
1207
 
1125
1208
  case 18:
@@ -1148,7 +1231,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1148
1231
  })
1149
1232
  };
1150
1233
  return Promise.all(objects.map(function (object) {
1151
- return _this5.applyCustomizations(object, item, imageLoader, {
1234
+ return _this6.applyCustomizations(object, item, imageLoader, {
1152
1235
  saveAndRestore: false
1153
1236
  });
1154
1237
  }));
@@ -1173,11 +1256,7 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1173
1256
  this.startAnimation("builtin");
1174
1257
  }
1175
1258
 
1176
- if (!this.isAnimating()) {
1177
- this.render();
1178
- }
1179
-
1180
- case 30:
1259
+ case 29:
1181
1260
  case "end":
1182
1261
  return _context7.stop();
1183
1262
  }
@@ -1469,14 +1548,15 @@ var Three3DScene = /*#__PURE__*/function (_Three3D) {
1469
1548
  ground.position.y = box.min.y;
1470
1549
  ground.position.x = sphere.center.x;
1471
1550
  ground.position.z = sphere.center.z;
1472
- ground.scale.set(1, 1, 1).multiplyScalar(maxDistance * 2);
1551
+ var groundScaling = this.config.useBakedShadows ? sphere.radius * 4 : maxDistance * 2;
1552
+ ground.scale.set(1, 1, 1).multiplyScalar(groundScaling);
1473
1553
  }
1474
1554
 
1475
1555
  if (dirLight) {
1476
1556
  dirLight.position.copy(this.dirLightPosition).multiplyScalar(maxDistance).add(sphere.center);
1477
1557
  this.scene.add(dirLight.target);
1478
1558
  dirLight.target.position.copy(sphere.center);
1479
- setLightShadow(dirLight, minDistance);
1559
+ this.setLightShadow(dirLight, minDistance);
1480
1560
  }
1481
1561
 
1482
1562
  if (hemiLight) {
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.blur = void 0;
7
+
8
+ // source: https://github.com/davidenke/context-filter-polyfill/blob/master/src/filters/blur.filter.ts
9
+ var blur = function blur(context) {
10
+ var radius = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5;
11
+ var amount = radius; // do not manipulate without proper amount
12
+
13
+ if (amount <= 0) {
14
+ return context;
15
+ }
16
+
17
+ var _context$canvas = context.canvas,
18
+ height = _context$canvas.height,
19
+ width = _context$canvas.width;
20
+ var imageData = context.getImageData(0, 0, width, height);
21
+ var data = imageData.data; // http://www.quasimondo.com/BoxBlurForCanvas/FastBlur.js
22
+
23
+ var wm = width - 1;
24
+ var hm = height - 1;
25
+ var rad1 = amount + 1;
26
+ var mulTable = [1, 57, 41, 21, 203, 34, 97, 73, 227, 91, 149, 62, 105, 45, 39, 137, 241, 107, 3, 173, 39, 71, 65, 238, 219, 101, 187, 87, 81, 151, 141, 133, 249, 117, 221, 209, 197, 187, 177, 169, 5, 153, 73, 139, 133, 127, 243, 233, 223, 107, 103, 99, 191, 23, 177, 171, 165, 159, 77, 149, 9, 139, 135, 131, 253, 245, 119, 231, 224, 109, 211, 103, 25, 195, 189, 23, 45, 175, 171, 83, 81, 79, 155, 151, 147, 9, 141, 137, 67, 131, 129, 251, 123, 30, 235, 115, 113, 221, 217, 53, 13, 51, 50, 49, 193, 189, 185, 91, 179, 175, 43, 169, 83, 163, 5, 79, 155, 19, 75, 147, 145, 143, 35, 69, 17, 67, 33, 65, 255, 251, 247, 243, 239, 59, 29, 229, 113, 111, 219, 27, 213, 105, 207, 51, 201, 199, 49, 193, 191, 47, 93, 183, 181, 179, 11, 87, 43, 85, 167, 165, 163, 161, 159, 157, 155, 77, 19, 75, 37, 73, 145, 143, 141, 35, 138, 137, 135, 67, 33, 131, 129, 255, 63, 250, 247, 61, 121, 239, 237, 117, 29, 229, 227, 225, 111, 55, 109, 216, 213, 211, 209, 207, 205, 203, 201, 199, 197, 195, 193, 48, 190, 47, 93, 185, 183, 181, 179, 178, 176, 175, 173, 171, 85, 21, 167, 165, 41, 163, 161, 5, 79, 157, 78, 154, 153, 19, 75, 149, 74, 147, 73, 144, 143, 71, 141, 140, 139, 137, 17, 135, 134, 133, 66, 131, 65, 129, 1];
27
+ var mulSum = mulTable[amount];
28
+ var shgTable = [0, 9, 10, 10, 14, 12, 14, 14, 16, 15, 16, 15, 16, 15, 15, 17, 18, 17, 12, 18, 16, 17, 17, 19, 19, 18, 19, 18, 18, 19, 19, 19, 20, 19, 20, 20, 20, 20, 20, 20, 15, 20, 19, 20, 20, 20, 21, 21, 21, 20, 20, 20, 21, 18, 21, 21, 21, 21, 20, 21, 17, 21, 21, 21, 22, 22, 21, 22, 22, 21, 22, 21, 19, 22, 22, 19, 20, 22, 22, 21, 21, 21, 22, 22, 22, 18, 22, 22, 21, 22, 22, 23, 22, 20, 23, 22, 22, 23, 23, 21, 19, 21, 21, 21, 23, 23, 23, 22, 23, 23, 21, 23, 22, 23, 18, 22, 23, 20, 22, 23, 23, 23, 21, 22, 20, 22, 21, 22, 24, 24, 24, 24, 24, 22, 21, 24, 23, 23, 24, 21, 24, 23, 24, 22, 24, 24, 22, 24, 24, 22, 23, 24, 24, 24, 20, 23, 22, 23, 24, 24, 24, 24, 24, 24, 24, 23, 21, 23, 22, 23, 24, 24, 24, 22, 24, 24, 24, 23, 22, 24, 24, 25, 23, 25, 25, 23, 24, 25, 25, 24, 22, 25, 25, 25, 24, 23, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 23, 25, 23, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 24, 22, 25, 25, 23, 25, 25, 20, 24, 25, 24, 25, 25, 22, 24, 25, 24, 25, 24, 25, 25, 24, 25, 25, 25, 25, 22, 25, 25, 25, 24, 25, 24, 25, 18];
29
+ var shgSum = shgTable[amount];
30
+ var r = [];
31
+ var g = [];
32
+ var b = [];
33
+ var a = [];
34
+ var vmin = [];
35
+ var vmax = [];
36
+ var iterations = 3; // 1 - 3
37
+
38
+ var p, p1, p2, pa;
39
+
40
+ while (iterations-- > 0) {
41
+ var yw = 0;
42
+ var yi = 0;
43
+
44
+ for (var y = 0; y < height; y++) {
45
+ var rsum = data[yw] * rad1;
46
+ var gsum = data[yw + 1] * rad1;
47
+ var bsum = data[yw + 2] * rad1;
48
+ var asum = data[yw + 3] * rad1;
49
+
50
+ for (var i = 1; i <= amount; i++) {
51
+ // tslint:disable-next-line no-bitwise
52
+ p = yw + ((i > wm ? wm : i) << 2);
53
+ rsum += data[p++];
54
+ gsum += data[p++];
55
+ bsum += data[p++];
56
+ asum += data[p];
57
+ }
58
+
59
+ for (var x = 0; x < width; x++) {
60
+ r[yi] = rsum;
61
+ g[yi] = gsum;
62
+ b[yi] = bsum;
63
+ a[yi] = asum;
64
+
65
+ if (y === 0) {
66
+ // tslint:disable-next-line no-bitwise
67
+ vmin[x] = ((p = x + rad1) < wm ? p : wm) << 2; // tslint:disable-next-line no-bitwise
68
+
69
+ vmax[x] = (p = x - amount) > 0 ? p << 2 : 0;
70
+ }
71
+
72
+ p1 = yw + vmin[x];
73
+ p2 = yw + vmax[x];
74
+ rsum += data[p1++] - data[p2++];
75
+ gsum += data[p1++] - data[p2++];
76
+ bsum += data[p1++] - data[p2++];
77
+ asum += data[p1] - data[p2];
78
+ yi++;
79
+ } // tslint:disable-next-line no-bitwise
80
+
81
+
82
+ yw += width << 2;
83
+ }
84
+
85
+ for (var _x = 0; _x < width; _x++) {
86
+ var yp = _x;
87
+
88
+ var _rsum = r[yp] * rad1;
89
+
90
+ var _gsum = g[yp] * rad1;
91
+
92
+ var _bsum = b[yp] * rad1;
93
+
94
+ var _asum = a[yp] * rad1;
95
+
96
+ for (var _i = 1; _i <= amount; _i++) {
97
+ yp += _i > hm ? 0 : width;
98
+ _rsum += r[yp];
99
+ _gsum += g[yp];
100
+ _bsum += b[yp];
101
+ _asum += a[yp];
102
+ } // tslint:disable-next-line no-bitwise
103
+
104
+
105
+ yi = _x << 2;
106
+
107
+ for (var _y = 0; _y < height; _y++) {
108
+ // tslint:disable-next-line no-bitwise
109
+ data[yi + 3] = pa = _asum * mulSum >>> shgSum;
110
+
111
+ if (pa > 0) {
112
+ pa = 255 / pa; // tslint:disable-next-line no-bitwise
113
+
114
+ data[yi] = (_rsum * mulSum >>> shgSum) * pa; // tslint:disable-next-line no-bitwise
115
+
116
+ data[yi + 1] = (_gsum * mulSum >>> shgSum) * pa; // tslint:disable-next-line no-bitwise
117
+
118
+ data[yi + 2] = (_bsum * mulSum >>> shgSum) * pa;
119
+ } else {
120
+ data[yi] = data[yi + 1] = data[yi + 2] = 0;
121
+ }
122
+
123
+ if (_x === 0) {
124
+ vmin[_y] = ((p = _y + rad1) < hm ? p : hm) * width;
125
+ vmax[_y] = (p = _y - amount) > 0 ? p * width : 0;
126
+ }
127
+
128
+ p1 = _x + vmin[_y];
129
+ p2 = _x + vmax[_y];
130
+ _rsum += r[p1] - r[p2];
131
+ _gsum += g[p1] - g[p2];
132
+ _bsum += b[p1] - b[p2];
133
+ _asum += a[p1] - a[p2]; // tslint:disable-next-line no-bitwise
134
+
135
+ yi += width << 2;
136
+ }
137
+ }
138
+ } // set back image data to context
139
+
140
+
141
+ context.putImageData(imageData, 0, 0); // return the context itself
142
+
143
+ return context;
144
+ };
145
+
146
+ exports.blur = blur;
147
+ var _default = blur;
148
+ exports["default"] = _default;