mage-engine 3.19.0 → 3.20.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 (2) hide show
  1. package/dist/mage.js +415 -294
  2. package/package.json +2 -2
package/dist/mage.js CHANGED
@@ -24,14 +24,14 @@ function _objectSpread2$1(target) {
24
24
  return target;
25
25
  }
26
26
 
27
- function _typeof$1(obj) {
27
+ function _typeof(obj) {
28
28
  "@babel/helpers - typeof";
29
29
 
30
- return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
30
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
31
31
  return typeof obj;
32
32
  } : function (obj) {
33
33
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
34
- }, _typeof$1(obj);
34
+ }, _typeof(obj);
35
35
  }
36
36
 
37
37
  function _classCallCheck(instance, Constructor) {
@@ -121,6 +121,23 @@ function _isNativeReflectConstruct() {
121
121
  }
122
122
  }
123
123
 
124
+ function _construct(Parent, args, Class) {
125
+ if (_isNativeReflectConstruct()) {
126
+ _construct = Reflect.construct;
127
+ } else {
128
+ _construct = function _construct(Parent, args, Class) {
129
+ var a = [null];
130
+ a.push.apply(a, args);
131
+ var Constructor = Function.bind.apply(Parent, a);
132
+ var instance = new Constructor();
133
+ if (Class) _setPrototypeOf(instance, Class.prototype);
134
+ return instance;
135
+ };
136
+ }
137
+
138
+ return _construct.apply(null, arguments);
139
+ }
140
+
124
141
  function _objectWithoutPropertiesLoose(source, excluded) {
125
142
  if (source == null) return {};
126
143
  var target = {};
@@ -53661,7 +53678,7 @@ var LABEL_DOMELEMENT_MISSING = "".concat(PREFIX, " Could not create Label, domEl
53661
53678
  function BaseScript(name) {
53662
53679
  _classCallCheck(this, BaseScript);
53663
53680
 
53664
- this.__name = name || this.contructor.name;
53681
+ this.__name = name || this.constructor.name;
53665
53682
  this.hasStarted = false;
53666
53683
  this.options = {};
53667
53684
  }
@@ -53693,35 +53710,20 @@ var LABEL_DOMELEMENT_MISSING = "".concat(PREFIX, " Could not create Label, domEl
53693
53710
  }]);
53694
53711
 
53695
53712
  return BaseScript;
53696
- }();/*!
53697
- * hotkeys-js v3.7.2
53698
- * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
53699
- *
53700
- * Copyright (c) 2019 kenny wong <wowohoo@qq.com>
53701
- * http://jaywcjlove.github.io/hotkeys
53713
+ }();/**!
53714
+ * hotkeys-js v3.9.4
53715
+ * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
53702
53716
  *
53703
- * Licensed under the MIT license.
53717
+ * Copyright (c) 2022 kenny wong <wowohoo@qq.com>
53718
+ * http://jaywcjlove.github.io/hotkeys
53719
+ * Licensed under the MIT license
53704
53720
  */
53705
53721
 
53706
- function _typeof(obj) {
53707
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
53708
- _typeof = function (obj) {
53709
- return typeof obj;
53710
- };
53711
- } else {
53712
- _typeof = function (obj) {
53713
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
53714
- };
53715
- }
53716
-
53717
- return _typeof(obj);
53718
- }
53719
-
53720
53722
  var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; // 绑定事件
53721
53723
 
53722
- function addEvent(object, event, method) {
53724
+ function addEvent(object, event, method, useCapture) {
53723
53725
  if (object.addEventListener) {
53724
- object.addEventListener(event, method, false);
53726
+ object.addEventListener(event, method, useCapture);
53725
53727
  } else if (object.attachEvent) {
53726
53728
  object.attachEvent("on".concat(event), function () {
53727
53729
  method(window.event);
@@ -53776,7 +53778,7 @@ var _keyMap = {
53776
53778
  tab: 9,
53777
53779
  clear: 12,
53778
53780
  enter: 13,
53779
- "return": 13,
53781
+ return: 13,
53780
53782
  esc: 27,
53781
53783
  escape: 27,
53782
53784
  space: 32,
@@ -53785,7 +53787,7 @@ var _keyMap = {
53785
53787
  right: 39,
53786
53788
  down: 40,
53787
53789
  del: 46,
53788
- "delete": 46,
53790
+ delete: 46,
53789
53791
  ins: 45,
53790
53792
  insert: 45,
53791
53793
  home: 36,
@@ -53793,6 +53795,22 @@ var _keyMap = {
53793
53795
  pageup: 33,
53794
53796
  pagedown: 34,
53795
53797
  capslock: 20,
53798
+ num_0: 96,
53799
+ num_1: 97,
53800
+ num_2: 98,
53801
+ num_3: 99,
53802
+ num_4: 100,
53803
+ num_5: 101,
53804
+ num_6: 102,
53805
+ num_7: 103,
53806
+ num_8: 104,
53807
+ num_9: 105,
53808
+ num_multiply: 106,
53809
+ num_add: 107,
53810
+ num_enter: 108,
53811
+ num_subtract: 109,
53812
+ num_decimal: 110,
53813
+ num_divide: 111,
53796
53814
  '⇪': 20,
53797
53815
  ',': 188,
53798
53816
  '.': 190,
@@ -53848,6 +53866,8 @@ for (var k$1 = 1; k$1 < 20; k$1++) {
53848
53866
 
53849
53867
  var _downKeys = []; // 记录摁下的绑定键
53850
53868
 
53869
+ var winListendFocus = false; // window是否已经监听了focus事件
53870
+
53851
53871
  var _scope = 'all'; // 默认热键范围
53852
53872
 
53853
53873
  var elementHasBindEvent = []; // 已绑定事件的节点记录
@@ -53879,7 +53899,7 @@ function filter$1(event) {
53879
53899
  var tagName = target.tagName;
53880
53900
  var flag = true; // ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select>
53881
53901
 
53882
- if (target.isContentEditable || tagName === 'TEXTAREA' || (tagName === 'INPUT' || tagName === 'TEXTAREA') && !target.readOnly) {
53902
+ if (target.isContentEditable || (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') && !target.readOnly) {
53883
53903
  flag = false;
53884
53904
  }
53885
53905
 
@@ -53946,7 +53966,7 @@ function clearModifier(event) {
53946
53966
 
53947
53967
  function unbind(keysInfo) {
53948
53968
  // unbind(), unbind all keys
53949
- if (!keysInfo) {
53969
+ if (typeof keysInfo === 'undefined') {
53950
53970
  Object.keys(_handlers).forEach(function (key) {
53951
53971
  return delete _handlers[key];
53952
53972
  });
@@ -53955,7 +53975,7 @@ function unbind(keysInfo) {
53955
53975
  keysInfo.forEach(function (info) {
53956
53976
  if (info.key) eachUnbind(info);
53957
53977
  });
53958
- } else if (_typeof(keysInfo) === 'object') {
53978
+ } else if (typeof keysInfo === 'object') {
53959
53979
  // support like unbind({key: 'ctrl+a, ctrl+b', scope:'abc'})
53960
53980
  if (keysInfo.key) eachUnbind(keysInfo);
53961
53981
  } else if (typeof keysInfo === 'string') {
@@ -53999,21 +54019,20 @@ var eachUnbind = function eachUnbind(_ref) {
53999
54019
 
54000
54020
  if (!scope) scope = getScope();
54001
54021
  var mods = len > 1 ? getMods(_modifier, unbindKeys) : [];
54002
- _handlers[keyCode] = _handlers[keyCode].map(function (record) {
54022
+ _handlers[keyCode] = _handlers[keyCode].filter(function (record) {
54003
54023
  // 通过函数判断,是否解除绑定,函数相等直接返回
54004
54024
  var isMatchingMethod = method ? record.method === method : true;
54005
-
54006
- if (isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)) {
54007
- return {};
54008
- }
54009
-
54010
- return record;
54025
+ return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods));
54011
54026
  });
54012
54027
  });
54013
54028
  }; // 对监听对应快捷键的回调函数进行处理
54014
54029
 
54015
54030
 
54016
- function eventHandler(event, handler, scope) {
54031
+ function eventHandler(event, handler, scope, element) {
54032
+ if (handler.element !== element) {
54033
+ return;
54034
+ }
54035
+
54017
54036
  var modifiersMatch; // 看它是否在当前范围
54018
54037
 
54019
54038
  if (handler.scope === scope || handler.scope === 'all') {
@@ -54040,7 +54059,7 @@ function eventHandler(event, handler, scope) {
54040
54059
  } // 处理keydown事件
54041
54060
 
54042
54061
 
54043
- function dispatch$9(event) {
54062
+ function dispatch$9(event, element) {
54044
54063
  var asterisk = _handlers['*'];
54045
54064
  var key = event.keyCode || event.which || event.charCode; // 表单控件过滤 默认表单控件不触发快捷键
54046
54065
 
@@ -54068,6 +54087,14 @@ function dispatch$9(event) {
54068
54087
  _downKeys.push(keyNum);
54069
54088
  } else if (!event[keyName] && _downKeys.indexOf(keyNum) > -1) {
54070
54089
  _downKeys.splice(_downKeys.indexOf(keyNum), 1);
54090
+ } else if (keyName === 'metaKey' && event[keyName] && _downKeys.length === 3) {
54091
+ /**
54092
+ * Fix if Command is pressed:
54093
+ * ===============================
54094
+ */
54095
+ if (!(event.ctrlKey || event.shiftKey || event.altKey)) {
54096
+ _downKeys = _downKeys.slice(_downKeys.indexOf(keyNum));
54097
+ }
54071
54098
  }
54072
54099
  });
54073
54100
  /**
@@ -54089,6 +54116,26 @@ function dispatch$9(event) {
54089
54116
  if (Object.prototype.hasOwnProperty.call(_mods, e)) {
54090
54117
  _mods[e] = event[modifierMap[e]];
54091
54118
  }
54119
+ }
54120
+ /**
54121
+ * https://github.com/jaywcjlove/hotkeys/pull/129
54122
+ * This solves the issue in Firefox on Windows where hotkeys corresponding to special characters would not trigger.
54123
+ * An example of this is ctrl+alt+m on a Swedish keyboard which is used to type μ.
54124
+ * Browser support: https://caniuse.com/#feat=keyboardevent-getmodifierstate
54125
+ */
54126
+
54127
+
54128
+ if (event.getModifierState && !(event.altKey && !event.ctrlKey) && event.getModifierState('AltGraph')) {
54129
+ if (_downKeys.indexOf(17) === -1) {
54130
+ _downKeys.push(17);
54131
+ }
54132
+
54133
+ if (_downKeys.indexOf(18) === -1) {
54134
+ _downKeys.push(18);
54135
+ }
54136
+
54137
+ _mods[17] = true;
54138
+ _mods[18] = true;
54092
54139
  } // 获取范围 默认为 `all`
54093
54140
 
54094
54141
 
@@ -54097,7 +54144,7 @@ function dispatch$9(event) {
54097
54144
  if (asterisk) {
54098
54145
  for (var i = 0; i < asterisk.length; i++) {
54099
54146
  if (asterisk[i].scope === scope && (event.type === 'keydown' && asterisk[i].keydown || event.type === 'keyup' && asterisk[i].keyup)) {
54100
- eventHandler(event, asterisk[i], scope);
54147
+ eventHandler(event, asterisk[i], scope, element);
54101
54148
  }
54102
54149
  }
54103
54150
  } // key 不在 _handlers 中返回
@@ -54119,7 +54166,7 @@ function dispatch$9(event) {
54119
54166
 
54120
54167
  if (_downKeysCurrent.sort().join('') === _downKeys.sort().join('')) {
54121
54168
  // 找到处理内容
54122
- eventHandler(event, record, scope);
54169
+ eventHandler(event, record, scope, element);
54123
54170
  }
54124
54171
  }
54125
54172
  }
@@ -54143,7 +54190,8 @@ function hotkeys(key, option, method) {
54143
54190
  var i = 0;
54144
54191
  var keyup = false;
54145
54192
  var keydown = true;
54146
- var splitKey = '+'; // 对为设定范围的判断
54193
+ var splitKey = '+';
54194
+ var capture = false; // 对为设定范围的判断
54147
54195
 
54148
54196
  if (method === undefined && typeof option === 'function') {
54149
54197
  method = option;
@@ -54158,6 +54206,8 @@ function hotkeys(key, option, method) {
54158
54206
 
54159
54207
  if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
54160
54208
 
54209
+ if (option.capture !== undefined) capture = option.capture; // eslint-disable-line
54210
+
54161
54211
  if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
54162
54212
  }
54163
54213
 
@@ -54184,7 +54234,8 @@ function hotkeys(key, option, method) {
54184
54234
  shortcut: keys[i],
54185
54235
  method: method,
54186
54236
  key: keys[i],
54187
- splitKey: splitKey
54237
+ splitKey: splitKey,
54238
+ element: element
54188
54239
  });
54189
54240
  } // 在全局document上设置快捷键
54190
54241
 
@@ -54192,18 +54243,36 @@ function hotkeys(key, option, method) {
54192
54243
  if (typeof element !== 'undefined' && !isElementBind(element) && window) {
54193
54244
  elementHasBindEvent.push(element);
54194
54245
  addEvent(element, 'keydown', function (e) {
54195
- dispatch$9(e);
54196
- });
54197
- addEvent(window, 'focus', function () {
54198
- _downKeys = [];
54199
- });
54246
+ dispatch$9(e, element);
54247
+ }, capture);
54248
+
54249
+ if (!winListendFocus) {
54250
+ winListendFocus = true;
54251
+ addEvent(window, 'focus', function () {
54252
+ _downKeys = [];
54253
+ }, capture);
54254
+ }
54255
+
54200
54256
  addEvent(element, 'keyup', function (e) {
54201
- dispatch$9(e);
54257
+ dispatch$9(e, element);
54202
54258
  clearModifier(e);
54203
- });
54259
+ }, capture);
54204
54260
  }
54205
54261
  }
54206
54262
 
54263
+ function trigger(shortcut) {
54264
+ var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all';
54265
+ Object.keys(_handlers).forEach(function (key) {
54266
+ var data = _handlers[key].find(function (item) {
54267
+ return item.scope === scope && item.shortcut === shortcut;
54268
+ });
54269
+
54270
+ if (data && data.method) {
54271
+ data.method();
54272
+ }
54273
+ });
54274
+ }
54275
+
54207
54276
  var _api = {
54208
54277
  setScope: setScope,
54209
54278
  getScope: getScope,
@@ -54211,7 +54280,11 @@ var _api = {
54211
54280
  getPressedKeyCodes: getPressedKeyCodes,
54212
54281
  isPressed: isPressed,
54213
54282
  filter: filter$1,
54214
- unbind: unbind
54283
+ trigger: trigger,
54284
+ unbind: unbind,
54285
+ keyMap: _keyMap,
54286
+ modifier: _modifier,
54287
+ modifierMap: modifierMap
54215
54288
  };
54216
54289
 
54217
54290
  for (var a in _api) {
@@ -54294,18 +54367,23 @@ var Keyboard = /*#__PURE__*/function (_EventDispatcher) {
54294
54367
  }, {
54295
54368
  key: "enable",
54296
54369
  value: function enable() {
54370
+ var cb = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (f) {
54371
+ return f;
54372
+ };
54297
54373
  this.enabled = true;
54298
- window.addEventListener(KEY_DOWN, this.handleKeydown.bind(this));
54299
- window.addEventListener(KEY_UP, this.handleKeyup.bind(this));
54300
- window.addEventListener(KEY_PRESS, this.handleKeypress.bind(this));
54374
+ this.register('*', cb);
54375
+ window.addEventListener(KEY_DOWN.toLowerCase(), this.handleKeydown.bind(this));
54376
+ window.addEventListener(KEY_UP.toLowerCase(), this.handleKeyup.bind(this));
54377
+ window.addEventListener(KEY_PRESS.toLowerCase(), this.handleKeypress.bind(this));
54301
54378
  }
54302
54379
  }, {
54303
54380
  key: "disable",
54304
54381
  value: function disable() {
54305
54382
  this.enabled = false;
54306
- window.removeEventListener(KEY_DOWN, this.handleKeydown.bind(this));
54307
- window.removeEventListener(KEY_UP, this.handleKeyup.bind(this));
54308
- window.removeEventListener(KEY_PRESS, this.handleKeypress.bind(this));
54383
+ hotkeys.unbind();
54384
+ window.removeEventListener(KEY_DOWN.toLowerCase(), this.handleKeydown.bind(this));
54385
+ window.removeEventListener(KEY_UP.toLowerCase(), this.handleKeyup.bind(this));
54386
+ window.removeEventListener(KEY_PRESS.toLowerCase(), this.handleKeypress.bind(this));
54309
54387
  }
54310
54388
  }, {
54311
54389
  key: "isPressed",
@@ -55937,7 +56015,7 @@ var DEFAULT_TAG = 'all';var Scene = /*#__PURE__*/function () {
55937
56015
  var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : generateRandomName('LevelName');
55938
56016
  var fog = Config$1.fog();
55939
56017
  this.scene = new Scene$2();
55940
- this.scene.name = name; // this.scene.overrideMaterial = null; // should be null by default, but it's not.
56018
+ this.scene.name = name;
55941
56019
 
55942
56020
  if (fog.enabled) {
55943
56021
  this.fog(fog.color, fog.density);
@@ -57333,7 +57411,7 @@ function applyMiddleware() {
57333
57411
 
57334
57412
  var thunk = createThunkMiddleware();
57335
57413
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
57336
- var version$1 = "3.19.0";
57414
+ var version$1 = "3.20.0";
57337
57415
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
57338
57416
  var main = "dist/mage.js";
57339
57417
  var author$1 = {
@@ -57375,7 +57453,7 @@ var dependencies = {
57375
57453
  "@babel/plugin-transform-runtime": "7.5.0",
57376
57454
  "@babel/runtime": "7.5.0",
57377
57455
  "between.js": "0.1.2-fix.2",
57378
- "hotkeys-js": "3.7.2",
57456
+ "hotkeys-js": "3.9.4",
57379
57457
  "html-to-image": "^1.9.0",
57380
57458
  html2canvas: "^1.4.1",
57381
57459
  inferno: "7.3.2",
@@ -58602,7 +58680,7 @@ if (!self.fetch) {
58602
58680
  self.Headers = Headers;
58603
58681
  self.Request = Request;
58604
58682
  self.Response = Response;
58605
- }var _excluded$7 = ["wheels", "accelerationKey", "brakingKey", "rightKey", "leftKey", "debug"];
58683
+ }var _excluded$7 = ["wheels", "accelerationKey", "brakingKey", "rightKey", "leftKey", "debug", "autostart"];
58606
58684
 
58607
58685
  var BaseCar = /*#__PURE__*/function (_BaseScript) {
58608
58686
  _inherits(BaseCar, _BaseScript);
@@ -58628,7 +58706,9 @@ var BaseCar = /*#__PURE__*/function (_BaseScript) {
58628
58706
  _options$leftKey = options.leftKey,
58629
58707
  leftKey = _options$leftKey === void 0 ? 'a' : _options$leftKey;
58630
58708
  options.debug;
58631
- var physicsOptions = _objectWithoutProperties(options, _excluded$7);
58709
+ var _options$autostart = options.autostart,
58710
+ autostart = _options$autostart === void 0 ? true : _options$autostart,
58711
+ physicsOptions = _objectWithoutProperties(options, _excluded$7);
58632
58712
 
58633
58713
  this.car = element;
58634
58714
  this.wheels = wheels;
@@ -58642,6 +58722,7 @@ var BaseCar = /*#__PURE__*/function (_BaseScript) {
58642
58722
  this.brakingKey = brakingKey;
58643
58723
  this.rightKey = rightKey;
58644
58724
  this.leftKey = leftKey;
58725
+ this.engineStarted = autostart;
58645
58726
  Input$1.enable();
58646
58727
  Physics$1.addVehicle(this.car, _objectSpread2$1({
58647
58728
  wheels: wheels.map(function (w) {
@@ -58649,6 +58730,16 @@ var BaseCar = /*#__PURE__*/function (_BaseScript) {
58649
58730
  })
58650
58731
  }, physicsOptions));
58651
58732
  }
58733
+ }, {
58734
+ key: "startEngine",
58735
+ value: function startEngine() {
58736
+ this.engineStarted = true;
58737
+ }
58738
+ }, {
58739
+ key: "stopEngine",
58740
+ value: function stopEngine() {
58741
+ this.engineStarted = false;
58742
+ }
58652
58743
  }, {
58653
58744
  key: "handleInput",
58654
58745
  value: function handleInput() {
@@ -58665,8 +58756,10 @@ var BaseCar = /*#__PURE__*/function (_BaseScript) {
58665
58756
  }, {
58666
58757
  key: "update",
58667
58758
  value: function update(dt) {
58668
- this.handleInput();
58669
- this.sendCarUpdate();
58759
+ if (this.engineStarted) {
58760
+ this.handleInput();
58761
+ this.sendCarUpdate();
58762
+ }
58670
58763
  }
58671
58764
  }]);
58672
58765
 
@@ -58707,7 +58800,8 @@ var SmoothCarFollow = /*#__PURE__*/function (_BaseScript) {
58707
58800
  _options$distanceSnap = options.distanceSnapTime,
58708
58801
  distanceSnapTime = _options$distanceSnap === void 0 ? DEFAULT_DISTANCE_SNAP_TIME : _options$distanceSnap,
58709
58802
  _options$distanceMult = options.distanceMultiplier,
58710
- distanceMultiplier = _options$distanceMult === void 0 ? DEFAULT_DISTANCE_MULTIPLIER : _options$distanceMult;
58803
+ distanceMultiplier = _options$distanceMult === void 0 ? DEFAULT_DISTANCE_MULTIPLIER : _options$distanceMult,
58804
+ lerpFactor = options.lerpFactor;
58711
58805
  this.camera = camera;
58712
58806
  this.target = target;
58713
58807
  this.height = height;
@@ -58716,6 +58810,7 @@ var SmoothCarFollow = /*#__PURE__*/function (_BaseScript) {
58716
58810
  this.rotationSnapTime = rotationSnapTime;
58717
58811
  this.distanceSnapTime = distanceSnapTime;
58718
58812
  this.distanceMultiplier = distanceMultiplier;
58813
+ this.lerpFactor = lerpFactor;
58719
58814
  this.lookAtVector = new Vector3$1(0, lookAtHeight, 0);
58720
58815
  }
58721
58816
  }, {
@@ -58731,9 +58826,9 @@ var SmoothCarFollow = /*#__PURE__*/function (_BaseScript) {
58731
58826
  var targetPosition = this.target.getPosition();
58732
58827
  var vector = new Vector3$1(x, y, z).negate().normalize().multiplyScalar(this.distance);
58733
58828
  vector.y = y + this.height;
58734
- var desiredPosition = targetPosition.add(vector); // const lerpFactor = 1 - Math.pow(0.1, dt);
58735
-
58736
- cameraPosition.lerpVectors(cameraPosition, desiredPosition, dt);
58829
+ var desiredPosition = targetPosition.add(vector);
58830
+ var lerpFactor = this.lerpFactor || 1 - Math.pow(0.1, dt);
58831
+ cameraPosition.lerpVectors(cameraPosition, desiredPosition, lerpFactor);
58737
58832
  this.camera.setPosition(cameraPosition);
58738
58833
  var lookAtTarget = new Vector3$1();
58739
58834
  lookAtTarget.copy(this.target.getPosition().add(this.lookAtVector));
@@ -58962,14 +59057,14 @@ var _bbox = new Box3();
58962
59057
 
58963
59058
  var _uniformArray = [];
58964
59059
  var _logArray = [];
58965
- var DEFAULT_MAX_FAR = 100000;
59060
+ var DEFAULT_MAX_FAR = 5000;
58966
59061
  var DEFAULT_MODE = 'practical';
58967
59062
  var DEFAULT_SHADOWMAP_SIZE = 2048;
58968
59063
  var DEFAULT_CASCADE = 3;
58969
59064
  var DEFAULT_BIAS$3 = 0.000001;
58970
59065
  var DEFAULT_INTENSITY$5 = 1;
58971
59066
  var DEFAULT_NEAR$3 = 1;
58972
- var DEFAULT_FAR$3 = 2000;
59067
+ var DEFAULT_FAR$3 = 1000;
58973
59068
  var DEFAULT_MARGIN = 200;
58974
59069
  var CascadeShadowMaps = /*#__PURE__*/function () {
58975
59070
  function CascadeShadowMaps(_ref) {
@@ -59304,33 +59399,30 @@ var CascadeShadowMaps = /*#__PURE__*/function () {
59304
59399
  }();var POINTLIGHT = 'pointlight';
59305
59400
  var AMBIENTLIGHT = 'ambientlight';
59306
59401
  var SUNLIGHT = 'sunlight';
59307
- var SPOTLIGHT = 'spotlight';
59308
- var HEMISPHERELIGHT = 'hemisphere';
59309
- var TIME_TO_UPDATE = 5;
59310
59402
  var Lights = /*#__PURE__*/function () {
59311
59403
  function Lights() {
59312
59404
  _classCallCheck(this, Lights);
59313
59405
 
59314
- this.delayFactor = 0.1;
59315
- this.delayStep = 30;
59316
- this.holderRadius = 0.01;
59317
- this.holderSegments = 1;
59318
- this.numLights = 0;
59319
- this.map = {};
59320
59406
  this.lights = [];
59321
59407
  this.csm = undefined;
59322
59408
  }
59323
59409
 
59324
59410
  _createClass(Lights, [{
59325
- key: "isUsingCSM",
59326
- value: function isUsingCSM() {
59411
+ key: "getLights",
59412
+ value: function getLights() {
59413
+ return this.lights;
59414
+ }
59415
+ }, {
59416
+ key: "isUsingCascadeShadowMaps",
59417
+ value: function isUsingCascadeShadowMaps() {
59327
59418
  return !!this.csm;
59328
59419
  }
59329
59420
  }, {
59330
- key: "setUpCSM",
59331
- value: function setUpCSM() {
59421
+ key: "createCascadeShadowMaps",
59422
+ value: function createCascadeShadowMaps() {
59332
59423
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
59333
59424
  this.csm = new CascadeShadowMaps(options);
59425
+ return this.csm;
59334
59426
  }
59335
59427
  }, {
59336
59428
  key: "add",
@@ -59340,17 +59432,9 @@ var Lights = /*#__PURE__*/function () {
59340
59432
  }, {
59341
59433
  key: "update",
59342
59434
  value: function update(dt) {
59343
- if (this.isUsingCSM()) {
59435
+ if (this.isUsingCascadeShadowMaps()) {
59344
59436
  this.csm.update();
59345
59437
  }
59346
-
59347
- var start = new Date();
59348
-
59349
- for (var index in this.lights) {
59350
- var light = this.lights[index];
59351
- light.update(dt);
59352
- if (+new Date() - start > TIME_TO_UPDATE) break;
59353
- }
59354
59438
  }
59355
59439
  }, {
59356
59440
  key: "toJSON",
@@ -59447,7 +59531,7 @@ var ToonMaterial = /*#__PURE__*/function (_ShaderMaterial) {
59447
59531
 
59448
59532
  if (hasMaterial(mesh)) {
59449
59533
  var setUpMaterial = function setUpMaterial(material) {
59450
- if (Lights$1.isUsingCSM()) {
59534
+ if (Lights$1.isUsingCascadeShadowMaps()) {
59451
59535
  Lights$1.csm.setupMaterial(material);
59452
59536
  }
59453
59537
 
@@ -59474,38 +59558,38 @@ var hasGeometry = function hasGeometry(mesh) {
59474
59558
  var processMaterial = function processMaterial(material, callback) {
59475
59559
  return Array.isArray(material) ? material.map(callback) : callback(material);
59476
59560
  };
59477
- var changeMaterialByName = function changeMaterialByName(name, mesh, materialOptions) {
59561
+ var replaceMaterialByName = function replaceMaterialByName(name, mesh, materialOptions) {
59478
59562
  if (!hasMaterial(mesh)) return;
59479
59563
 
59480
59564
  switch (name) {
59481
59565
  case MATERIALS.LAMBERT:
59482
- return cloneMaterial(MeshLambertMaterial, mesh, materialOptions);
59566
+ return replaceMaterial(MeshLambertMaterial, mesh, materialOptions);
59483
59567
 
59484
59568
  case MATERIALS.PHONG:
59485
- return cloneMaterial(MeshPhongMaterial, mesh, materialOptions);
59569
+ return replaceMaterial(MeshPhongMaterial, mesh, materialOptions);
59486
59570
 
59487
59571
  case MATERIALS.DEPTH:
59488
- return cloneMaterial(MeshDepthMaterial, mesh, materialOptions);
59572
+ return replaceMaterial(MeshDepthMaterial, mesh, materialOptions);
59489
59573
 
59490
59574
  case MATERIALS.STANDARD:
59491
- return cloneMaterial(MeshStandardMaterial, mesh, materialOptions);
59575
+ return replaceMaterial(MeshStandardMaterial, mesh, materialOptions);
59492
59576
 
59493
59577
  case MATERIALS.TOON:
59494
- return cloneMaterial(ToonMaterial, mesh, materialOptions);
59578
+ return replaceMaterial(ToonMaterial, mesh, materialOptions);
59495
59579
 
59496
59580
  case MATERIALS.THREE_TOON:
59497
- return cloneMaterial(MeshToonMaterial, mesh, materialOptions);
59581
+ return replaceMaterial(MeshToonMaterial, mesh, materialOptions);
59498
59582
 
59499
59583
  case MATERIALS.BASIC:
59500
59584
  default:
59501
- return cloneMaterial(MeshBasicMaterial, mesh, materialOptions);
59585
+ return replaceMaterial(MeshBasicMaterial, mesh, materialOptions);
59502
59586
  }
59503
59587
  };
59504
59588
 
59505
- var cloneMaterial = function cloneMaterial(MeshMaterial, mesh) {
59589
+ var replaceMaterial = function replaceMaterial(MeshMaterial, mesh) {
59506
59590
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
59507
59591
 
59508
- var _cloneMaterial = function _cloneMaterial(material) {
59592
+ var _replaceMaterial = function _replaceMaterial(material) {
59509
59593
  var clone = material.clone();
59510
59594
  var newMaterial = new MeshMaterial(_objectSpread2$1({
59511
59595
  map: clone.map,
@@ -59515,8 +59599,9 @@ var cloneMaterial = function cloneMaterial(MeshMaterial, mesh) {
59515
59599
  return newMaterial;
59516
59600
  };
59517
59601
 
59518
- mesh.material = processMaterial(mesh.material, _cloneMaterial);
59602
+ mesh.material = processMaterial(mesh.material, _replaceMaterial);
59519
59603
  setUpLightsAndShadows(mesh);
59604
+ return mesh.material;
59520
59605
  };
59521
59606
 
59522
59607
  var disposeTextures = function disposeTextures(mesh) {
@@ -59548,7 +59633,12 @@ var prepareModel = function prepareModel(model) {
59548
59633
  setUpLightsAndShadows(mesh);
59549
59634
  });
59550
59635
  return model;
59551
- };var Entity = /*#__PURE__*/function (_EventDispatcher) {
59636
+ };var LOOPING = {
59637
+ BOUNCE: 'bounce',
59638
+ REPEAT: 'repeat',
59639
+ NONE: false
59640
+ };
59641
+ var FUNCTIONS = _objectSpread2$1({}, Between.Easing);var easing=/*#__PURE__*/Object.freeze({__proto__:null,LOOPING:LOOPING,FUNCTIONS:FUNCTIONS});var Entity = /*#__PURE__*/function (_EventDispatcher) {
59552
59642
  _inherits(Entity, _EventDispatcher);
59553
59643
 
59554
59644
  var _super = _createSuper(Entity);
@@ -59577,7 +59667,7 @@ var prepareModel = function prepareModel(model) {
59577
59667
  });
59578
59668
 
59579
59669
  _defineProperty$1(_assertThisInitialized(_this), "addTag", function (tagName) {
59580
- if (!tagName) return;
59670
+ if (!tagName) return false;
59581
59671
 
59582
59672
  if (!_this.hasTag(tagName)) {
59583
59673
  _this.tags.push(tagName);
@@ -59714,7 +59804,10 @@ var prepareModel = function prepareModel(model) {
59714
59804
  }
59715
59805
  }, {
59716
59806
  key: "setBody",
59717
- value: function setBody(body) {
59807
+ value: function setBody() {
59808
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
59809
+ body = _ref3.body;
59810
+
59718
59811
  this.body = body;
59719
59812
  }
59720
59813
  }, {
@@ -59739,11 +59832,11 @@ var prepareModel = function prepareModel(model) {
59739
59832
 
59740
59833
  var container = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getBody();
59741
59834
 
59742
- var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
59743
- _ref3$waitForBody = _ref3.waitForBody,
59744
- waitForBody = _ref3$waitForBody === void 0 ? 0 : _ref3$waitForBody,
59745
- _ref3$waitForBodyMaxR = _ref3.waitForBodyMaxRetries,
59746
- waitForBodyMaxRetries = _ref3$waitForBodyMaxR === void 0 ? 1 : _ref3$waitForBodyMaxR;
59835
+ var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
59836
+ _ref4$waitForBody = _ref4.waitForBody,
59837
+ waitForBody = _ref4$waitForBody === void 0 ? 0 : _ref4$waitForBody,
59838
+ _ref4$waitForBodyMaxR = _ref4.waitForBodyMaxRetries,
59839
+ waitForBodyMaxRetries = _ref4$waitForBodyMaxR === void 0 ? 1 : _ref4$waitForBodyMaxR;
59747
59840
 
59748
59841
  if (this.hasBody()) {
59749
59842
  var _add = function _add(toAdd) {
@@ -59847,13 +59940,15 @@ var prepareModel = function prepareModel(model) {
59847
59940
  value: function removeTag(tagName) {
59848
59941
  if (tagName === DEFAULT_TAG) {
59849
59942
  console.log(TAG_CANT_BE_REMOVED);
59850
- return;
59943
+ return false;
59851
59944
  }
59852
59945
 
59853
59946
  if (this.hasTag(tagName)) {
59854
59947
  this.tags.splice(this.tags.indexOf(tagName), 1);
59948
+ return true;
59855
59949
  } else {
59856
59950
  console.log(TAG_NOT_EXISTING_REMOVAL);
59951
+ return false;
59857
59952
  }
59858
59953
  }
59859
59954
  }, {
@@ -59898,10 +59993,10 @@ var prepareModel = function prepareModel(model) {
59898
59993
  var _this4 = this;
59899
59994
 
59900
59995
  if (this.hasScripts()) {
59901
- this.scripts.forEach(function (_ref4) {
59902
- var script = _ref4.script,
59903
- enabled = _ref4.enabled,
59904
- options = _ref4.options;
59996
+ this.scripts.forEach(function (_ref5) {
59997
+ var script = _ref5.script,
59998
+ enabled = _ref5.enabled,
59999
+ options = _ref5.options;
59905
60000
 
59906
60001
  if (enabled) {
59907
60002
  script.start(_this4, options);
@@ -59915,9 +60010,9 @@ var prepareModel = function prepareModel(model) {
59915
60010
  key: "update",
59916
60011
  value: function update(dt) {
59917
60012
  if (this.hasScripts()) {
59918
- this.scripts.forEach(function (_ref5) {
59919
- var script = _ref5.script,
59920
- enabled = _ref5.enabled;
60013
+ this.scripts.forEach(function (_ref6) {
60014
+ var script = _ref6.script,
60015
+ enabled = _ref6.enabled;
59921
60016
 
59922
60017
  if (script && enabled) {
59923
60018
  script.update(dt);
@@ -59929,9 +60024,9 @@ var prepareModel = function prepareModel(model) {
59929
60024
  key: "onPhysicsUpdate",
59930
60025
  value: function onPhysicsUpdate(dt) {
59931
60026
  if (this.hasScripts()) {
59932
- this.scripts.forEach(function (_ref6) {
59933
- var script = _ref6.script,
59934
- enabled = _ref6.enabled;
60027
+ this.scripts.forEach(function (_ref7) {
60028
+ var script = _ref7.script,
60029
+ enabled = _ref7.enabled;
59935
60030
 
59936
60031
  if (script && enabled) {
59937
60032
  script.physicsUpdate(dt);
@@ -60021,6 +60116,7 @@ var prepareModel = function prepareModel(model) {
60021
60116
  return script;
60022
60117
  } else {
60023
60118
  console.warn(SCRIPT_NOT_FOUND);
60119
+ return false;
60024
60120
  }
60025
60121
  }
60026
60122
  }, {
@@ -60090,68 +60186,6 @@ var prepareModel = function prepareModel(model) {
60090
60186
  value: function getEntityType() {
60091
60187
  return this.entityType;
60092
60188
  }
60093
- }, {
60094
- key: "addLight",
60095
- // TODO: sounds should become entities
60096
- // addSound(name, options) {
60097
- // const { autoplay = false, ...opts } = options;
60098
- // this.isPlayingSound = autoplay;
60099
- // this.sound = new Sound(name, {
60100
- // autoplay,
60101
- // ...opts
60102
- // });
60103
- // this.sound.setTarget(this);
60104
- // return this.sound;
60105
- // }
60106
- // addDirectionalSound(name, options) {
60107
- // const { autoplay = false, ...opts } = options;
60108
- // this.isPlayingSound = autoplay;
60109
- // this.sound = new DirectionalSound(name, {
60110
- // autoplay,
60111
- // ...opts
60112
- // });
60113
- // this.sound.setTarget(this);
60114
- // return this.sound;
60115
- // }
60116
- // addAmbientSound(name, options) {
60117
- // const { autoplay = false, ...opts } = options;
60118
- // this.isPlayingSound = autoplay;
60119
- // this.sound = new AmbientSound(name, {
60120
- // body: this.body,
60121
- // autoplay,
60122
- // ...opts
60123
- // });
60124
- // return this.sound;
60125
- // }
60126
- value: function addLight(light) {
60127
- var _this$getPosition = this.getPosition(),
60128
- x = _this$getPosition.x,
60129
- y = _this$getPosition.y,
60130
- z = _this$getPosition.z;
60131
-
60132
- light.setPosition({
60133
- x: x,
60134
- y: y,
60135
- z: z
60136
- });
60137
- this.light = light;
60138
- }
60139
- }, {
60140
- key: "playSound",
60141
- value: function playSound() {
60142
- if (this.sound && !this.isPlayingSound) {
60143
- this.sound.play();
60144
- this.isPlayingSound = true;
60145
- }
60146
- }
60147
- }, {
60148
- key: "stopSound",
60149
- value: function stopSound() {
60150
- if (this.sound && this.isPlayingSound) {
60151
- this.sound.stop();
60152
- this.isPlayingSound = false;
60153
- }
60154
- }
60155
60189
  }, {
60156
60190
  key: "getScale",
60157
60191
  value: function getScale() {
@@ -60186,10 +60220,10 @@ var prepareModel = function prepareModel(model) {
60186
60220
  key: "setPosition",
60187
60221
  value: function setPosition(where) {
60188
60222
  if (this.hasBody()) {
60189
- var _this$getPosition2 = this.getPosition(),
60190
- x = _this$getPosition2.x,
60191
- y = _this$getPosition2.y,
60192
- z = _this$getPosition2.z;
60223
+ var _this$getPosition = this.getPosition(),
60224
+ x = _this$getPosition.x,
60225
+ y = _this$getPosition.y,
60226
+ z = _this$getPosition.z;
60193
60227
 
60194
60228
  var position = _objectSpread2$1({
60195
60229
  x: x,
@@ -60237,13 +60271,13 @@ var prepareModel = function prepareModel(model) {
60237
60271
  }
60238
60272
  }, {
60239
60273
  key: "translate",
60240
- value: function translate(_ref7) {
60241
- var _ref7$x = _ref7.x,
60242
- x = _ref7$x === void 0 ? 0 : _ref7$x,
60243
- _ref7$y = _ref7.y,
60244
- y = _ref7$y === void 0 ? 0 : _ref7$y,
60245
- _ref7$z = _ref7.z,
60246
- z = _ref7$z === void 0 ? 0 : _ref7$z;
60274
+ value: function translate(_ref8) {
60275
+ var _ref8$x = _ref8.x,
60276
+ x = _ref8$x === void 0 ? 0 : _ref8$x,
60277
+ _ref8$y = _ref8.y,
60278
+ y = _ref8$y === void 0 ? 0 : _ref8$y,
60279
+ _ref8$z = _ref8.z,
60280
+ z = _ref8$z === void 0 ? 0 : _ref8$z;
60247
60281
 
60248
60282
  if (this.hasBody()) {
60249
60283
  this.body.translateX(x);
@@ -60251,51 +60285,126 @@ var prepareModel = function prepareModel(model) {
60251
60285
  this.body.translateZ(z);
60252
60286
  }
60253
60287
  }
60288
+ }, {
60289
+ key: "scaleTo",
60290
+ value: function scaleTo() {
60291
+ var _this7 = this;
60292
+
60293
+ var scale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getScale();
60294
+ var time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
60295
+
60296
+ var _ref9 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
60297
+ _ref9$easing = _ref9.easing,
60298
+ easing = _ref9$easing === void 0 ? FUNCTIONS.Linear.None : _ref9$easing,
60299
+ _ref9$loop = _ref9.loop,
60300
+ loop = _ref9$loop === void 0 ? LOOPING.NONE : _ref9$loop;
60301
+
60302
+ var _this$getScale = this.getScale(),
60303
+ x = _this$getScale.x,
60304
+ y = _this$getScale.y,
60305
+ z = _this$getScale.z;
60306
+
60307
+ var targetScale = _objectSpread2$1({
60308
+ x: x,
60309
+ y: y,
60310
+ z: z
60311
+ }, scale);
60312
+
60313
+ return new Promise(function (resolve) {
60314
+ var between = new Between({
60315
+ x: x,
60316
+ y: y,
60317
+ z: z
60318
+ }, targetScale).time(time).easing(easing);
60319
+
60320
+ if (loop) {
60321
+ between.loop(loop);
60322
+ }
60323
+
60324
+ between.on('update', function (value) {
60325
+ return !_this7.isDisposed() && _this7.setScale(value);
60326
+ }).on('complete', resolve);
60327
+ });
60328
+ }
60254
60329
  }, {
60255
60330
  key: "rotateTo",
60256
60331
  value: function rotateTo() {
60257
- var _this7 = this;
60332
+ var _this8 = this;
60258
60333
 
60259
60334
  var rotation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getRotation();
60260
60335
  var time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
60261
- var easing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Between.Easing.Linear.None;
60336
+
60337
+ var _ref10 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
60338
+ _ref10$easing = _ref10.easing,
60339
+ easing = _ref10$easing === void 0 ? FUNCTIONS.Linear.None : _ref10$easing,
60340
+ _ref10$loop = _ref10.loop,
60341
+ loop = _ref10$loop === void 0 ? LOOPING.NONE : _ref10$loop;
60262
60342
 
60263
60343
  var _this$getRotation2 = this.getRotation(),
60264
60344
  x = _this$getRotation2.x,
60265
60345
  y = _this$getRotation2.y,
60266
60346
  z = _this$getRotation2.z;
60267
60347
 
60348
+ var targetRotation = _objectSpread2$1({
60349
+ x: x,
60350
+ y: y,
60351
+ z: z
60352
+ }, rotation);
60353
+
60268
60354
  return new Promise(function (resolve) {
60269
- return new Between({
60355
+ var between = new Between({
60270
60356
  x: x,
60271
60357
  y: y,
60272
60358
  z: z
60273
- }, rotation).time(time).easing(easing).on('update', function (value) {
60274
- return !_this7.isDisposed() && _this7.setRotation(value);
60359
+ }, targetRotation).time(time).easing(easing);
60360
+
60361
+ if (loop) {
60362
+ between.loop(loop);
60363
+ }
60364
+
60365
+ between.on('update', function (value) {
60366
+ return !_this8.isDisposed() && _this8.setRotation(value);
60275
60367
  }).on('complete', resolve);
60276
60368
  });
60277
60369
  }
60278
60370
  }, {
60279
60371
  key: "goTo",
60280
60372
  value: function goTo() {
60281
- var _this8 = this;
60373
+ var _this9 = this;
60282
60374
 
60283
60375
  var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getPosition();
60284
60376
  var time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 250;
60285
- var easing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Between.Easing.Linear.None;
60286
60377
 
60287
- var _this$getPosition3 = this.getPosition(),
60288
- x = _this$getPosition3.x,
60289
- y = _this$getPosition3.y,
60290
- z = _this$getPosition3.z;
60378
+ var _ref11 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
60379
+ _ref11$easing = _ref11.easing,
60380
+ easing = _ref11$easing === void 0 ? FUNCTIONS.Linear.None : _ref11$easing,
60381
+ _ref11$loop = _ref11.loop,
60382
+ loop = _ref11$loop === void 0 ? LOOPING.NONE : _ref11$loop;
60383
+
60384
+ var _this$getPosition2 = this.getPosition(),
60385
+ x = _this$getPosition2.x,
60386
+ y = _this$getPosition2.y,
60387
+ z = _this$getPosition2.z;
60388
+
60389
+ var targetPosition = _objectSpread2$1({
60390
+ x: x,
60391
+ y: y,
60392
+ z: z
60393
+ }, position);
60291
60394
 
60292
60395
  return new Promise(function (resolve) {
60293
- return new Between({
60396
+ var between = new Between({
60294
60397
  x: x,
60295
60398
  y: y,
60296
60399
  z: z
60297
- }, position).time(time).easing(easing).on('update', function (value) {
60298
- return !_this8.isDisposed() && _this8.setPosition(value);
60400
+ }, targetPosition).time(time).easing(easing);
60401
+
60402
+ if (loop) {
60403
+ between.loop(loop);
60404
+ }
60405
+
60406
+ between.on('update', function (value) {
60407
+ return !_this9.isDisposed() && _this9.setPosition(value);
60299
60408
  }).on('complete', resolve);
60300
60409
  });
60301
60410
  }
@@ -60368,10 +60477,10 @@ var prepareModel = function prepareModel(model) {
60368
60477
  }, {
60369
60478
  key: "mapScriptsToJSON",
60370
60479
  value: function mapScriptsToJSON() {
60371
- this.scripts.reduce(function (acc, _ref8) {
60372
- var name = _ref8.name,
60373
- _ref8$options = _ref8.options,
60374
- options = _ref8$options === void 0 ? {} : _ref8$options;
60480
+ this.scripts.reduce(function (acc, _ref12) {
60481
+ var name = _ref12.name,
60482
+ _ref12$options = _ref12.options,
60483
+ options = _ref12$options === void 0 ? {} : _ref12$options;
60375
60484
  acc.names.push(name);
60376
60485
  acc.options.push(options);
60377
60486
  return acc;
@@ -60397,8 +60506,11 @@ var prepareModel = function prepareModel(model) {
60397
60506
  }], [{
60398
60507
  key: "create",
60399
60508
  value: function create() {
60400
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
60401
- return new this(options);
60509
+ for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) {
60510
+ options[_key] = arguments[_key];
60511
+ }
60512
+
60513
+ return _construct(this, options);
60402
60514
  }
60403
60515
  }]);
60404
60516
 
@@ -60766,17 +60878,6 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
60766
60878
  }
60767
60879
 
60768
60880
  _createClass(Element, [{
60769
- key: "getMaterialType",
60770
- value: function getMaterialType() {
60771
- return this.materialType;
60772
- }
60773
- }, {
60774
- key: "setMaterialType",
60775
- value: function setMaterialType() {
60776
- var materialType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MATERIALS.BASIC;
60777
- this.materialType = materialType;
60778
- }
60779
- }, {
60780
60881
  key: "addTag",
60781
60882
  value: function addTag(tag) {
60782
60883
  _get(_getPrototypeOf(Element.prototype), "addTag", this).call(this, tag);
@@ -61149,20 +61250,48 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
61149
61250
  }
61150
61251
  }
61151
61252
  }
61253
+ }, {
61254
+ key: "getMaterial",
61255
+ value: function getMaterial() {
61256
+ if (hasMaterial(this.getBody())) {
61257
+ return this.getBody().material;
61258
+ }
61259
+
61260
+ var materials = [];
61261
+ this.getBody().traverse(function (child) {
61262
+ if (hasMaterial(child)) {
61263
+ materials.push(child.material);
61264
+ }
61265
+ });
61266
+ return materials;
61267
+ }
61268
+ }, {
61269
+ key: "getMaterialType",
61270
+ value: function getMaterialType() {
61271
+ return this.materialType;
61272
+ }
61273
+ }, {
61274
+ key: "setMaterialType",
61275
+ value: function setMaterialType() {
61276
+ var materialType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MATERIALS.BASIC;
61277
+ this.materialType = materialType;
61278
+ }
61152
61279
  }, {
61153
61280
  key: "setMaterialFromName",
61154
61281
  value: function setMaterialFromName(materialName) {
61155
61282
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
61156
61283
  this.setMaterialType(materialName);
61284
+ var newMaterials = [];
61157
61285
 
61158
61286
  if (hasMaterial(this.getBody())) {
61159
- changeMaterialByName(materialName, this.getBody(), options);
61287
+ return replaceMaterialByName(materialName, this.getBody(), options);
61160
61288
  } else {
61161
61289
  this.getBody().traverse(function (child) {
61162
61290
  if (hasMaterial(child)) {
61163
- changeMaterialByName(materialName, child, options);
61291
+ newMaterials.push(replaceMaterialByName(materialName, child, options));
61164
61292
  }
61165
61293
  });
61294
+ return newMaterials;
61166
61295
  }
61167
61296
  }
61168
61297
  }, {
@@ -61310,8 +61439,11 @@ var Element$1 = /*#__PURE__*/function (_Entity) {
61310
61439
  name: name
61311
61440
  });
61312
61441
  _this.options = options;
61442
+ var body = new PerspectiveCamera(fov, ratio, near, far);
61313
61443
 
61314
- _this.setBody(new PerspectiveCamera(fov, ratio, near, far));
61444
+ _this.setBody({
61445
+ body: body
61446
+ });
61315
61447
 
61316
61448
  _this.setEntityType(ENTITY_TYPES.CAMERA);
61317
61449
 
@@ -69199,7 +69331,7 @@ var engine = new Video();var GLTFLoader = function () {
69199
69331
 
69200
69332
  function assignExtrasToUserData(object, gltfDef) {
69201
69333
  if (gltfDef.extras !== undefined) {
69202
- if (_typeof$1(gltfDef.extras) === 'object') {
69334
+ if (_typeof(gltfDef.extras) === 'object') {
69203
69335
  Object.assign(object.userData, gltfDef.extras);
69204
69336
  } else {
69205
69337
  console.warn('THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras);
@@ -74252,7 +74384,7 @@ var FBXTreeParser = /*#__PURE__*/function () {
74252
74384
  var name = materialNode.attrName;
74253
74385
  var type = materialNode.ShadingModel; // Case where FBX wraps shading model in property object.
74254
74386
 
74255
- if (_typeof$1(type) === 'object') {
74387
+ if (_typeof(type) === 'object') {
74256
74388
  type = type.value;
74257
74389
  } // Ignore unused materials which don't have any connections.
74258
74390
 
@@ -82456,20 +82588,12 @@ var Light = /*#__PURE__*/function (_Entity) {
82456
82588
  }, {
82457
82589
  key: "toJSON",
82458
82590
  value: function toJSON() {
82459
- var _this$body$position = this.body.position,
82460
- x = _this$body$position.x,
82461
- y = _this$body$position.y,
82462
- z = _this$body$position.z;
82463
- return {
82464
- position: {
82465
- x: x,
82466
- y: y,
82467
- z: z
82468
- },
82591
+ return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(Light.prototype), "toJSON", this).call(this)), {}, {
82592
+ type: this.getEntityType(),
82469
82593
  color: this.color,
82470
82594
  intensity: this.intensity,
82471
82595
  name: this.name
82472
- };
82596
+ });
82473
82597
  }
82474
82598
  }]);
82475
82599
 
@@ -82534,9 +82658,13 @@ var SunLight = /*#__PURE__*/function (_Light) {
82534
82658
  intensity = _ref$intensity === void 0 ? DEFAULT_INTENSITY$4 : _ref$intensity;
82535
82659
 
82536
82660
  if (light) {
82537
- this.setBody(light);
82661
+ this.setBody({
82662
+ body: light
82663
+ });
82538
82664
  } else {
82539
- this.setBody(new DirectionalLight(color, intensity));
82665
+ this.setBody({
82666
+ body: new DirectionalLight(color, intensity)
82667
+ });
82540
82668
  }
82541
82669
 
82542
82670
  if (this.hasBody()) {
@@ -82572,9 +82700,11 @@ var SunLight = /*#__PURE__*/function (_Light) {
82572
82700
  _this$options2$bias = _this$options2.bias,
82573
82701
  bias = _this$options2$bias === void 0 ? DEFAULT_BIAS$2 : _this$options2$bias,
82574
82702
  _this$options2$fov = _this$options2.fov,
82575
- fov = _this$options2$fov === void 0 ? DEFAULT_FOV : _this$options2$fov;
82703
+ fov = _this$options2$fov === void 0 ? DEFAULT_FOV : _this$options2$fov,
82704
+ _this$options2$castSh = _this$options2.castShadow,
82705
+ castShadow = _this$options2$castSh === void 0 ? true : _this$options2$castSh;
82576
82706
 
82577
- if (Config$1.lights().shadows) {
82707
+ if (Config$1.lights().shadows && castShadow) {
82578
82708
  this.body.castShadow = true;
82579
82709
  var d = far / 1.5;
82580
82710
  this.body.shadow.mapSize.height = mapSize;
@@ -82642,13 +82772,6 @@ var SunLight = /*#__PURE__*/function (_Light) {
82642
82772
  });
82643
82773
  }
82644
82774
  }
82645
- }, {
82646
- key: "toJSON",
82647
- value: function toJSON() {
82648
- return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SunLight.prototype), "toJSON", this).call(this)), {}, {
82649
- type: SUNLIGHT
82650
- });
82651
- }
82652
82775
  }]);
82653
82776
 
82654
82777
  return SunLight;
@@ -82707,9 +82830,13 @@ var AmbientLight = /*#__PURE__*/function (_Light) {
82707
82830
  intensity = _ref$intensity === void 0 ? DEFAULT_INTENSITY$3 : _ref$intensity;
82708
82831
 
82709
82832
  if (light) {
82710
- this.setBody(light);
82833
+ this.setBody({
82834
+ body: light
82835
+ });
82711
82836
  } else {
82712
- this.setBody(new AmbientLight$1(color, intensity));
82837
+ this.setBody({
82838
+ body: new AmbientLight$1(color, intensity)
82839
+ });
82713
82840
  }
82714
82841
 
82715
82842
  if (this.hasBody()) {
@@ -82741,13 +82868,6 @@ var AmbientLight = /*#__PURE__*/function (_Light) {
82741
82868
  });
82742
82869
  }
82743
82870
  }
82744
- }, {
82745
- key: "toJSON",
82746
- value: function toJSON() {
82747
- return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(AmbientLight.prototype), "toJSON", this).call(this)), {}, {
82748
- type: AMBIENTLIGHT
82749
- });
82750
- }
82751
82871
  }]);
82752
82872
 
82753
82873
  return AmbientLight;
@@ -82819,9 +82939,13 @@ var PointLight = /*#__PURE__*/function (_Light) {
82819
82939
  decay = _ref$decay === void 0 ? DEFAULT_DECAY : _ref$decay;
82820
82940
 
82821
82941
  if (light) {
82822
- this.setBody(light);
82942
+ this.setBody({
82943
+ body: light
82944
+ });
82823
82945
  } else {
82824
- this.setBody(new PointLight$1(color, intensity, distance, decay));
82946
+ this.setBody({
82947
+ body: new PointLight$1(color, intensity, distance, decay)
82948
+ });
82825
82949
  }
82826
82950
 
82827
82951
  if (this.hasBody()) {
@@ -82893,8 +83017,7 @@ var PointLight = /*#__PURE__*/function (_Light) {
82893
83017
  key: "toJSON",
82894
83018
  value: function toJSON() {
82895
83019
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(PointLight.prototype), "toJSON", this).call(this)), {}, {
82896
- distance: this.distance,
82897
- type: POINTLIGHT
83020
+ distance: this.distance
82898
83021
  });
82899
83022
  }
82900
83023
  }]);
@@ -90062,21 +90185,25 @@ var Label = /*#__PURE__*/function (_Element) {
90062
90185
  Images$1.add(id, texture);
90063
90186
  }
90064
90187
 
90065
- texture.image.src = dataUrl;
90066
- texture.image.height = height;
90067
- texture.image.width = width;
90068
- texture.needsUpdate = true;
90188
+ if (texture.image.src !== dataUrl) {
90189
+ texture.image.src = dataUrl;
90190
+ texture.image.height = height;
90191
+ texture.image.width = width;
90192
+ texture.needsUpdate = true;
90193
+ }
90194
+
90069
90195
  return Promise.resolve(texture);
90070
90196
  };
90071
90197
  });
90072
90198
 
90073
90199
  _defineProperty$1(_assertThisInitialized(_this), "convertToPng", function (domElement) {
90074
90200
  return domElement ? toPng(domElement, {
90075
- cacheBust: true
90201
+ cacheBust: false
90076
90202
  }) : Promise.reject(LABEL_DOMELEMENT_MISSING);
90077
90203
  });
90078
90204
 
90079
- var name = _this.options.name;
90205
+ var _this$options$name = _this.options.name,
90206
+ name = _this$options$name === void 0 ? generateRandomName('label') : _this$options$name;
90080
90207
  _this.Component = Component;
90081
90208
  _this.format = format;
90082
90209
  _this.width = _width;
@@ -90832,9 +90959,13 @@ var SpotLight = /*#__PURE__*/function (_Light) {
90832
90959
  intensity = _ref$intensity === void 0 ? DEFAULT_INTENSITY$1 : _ref$intensity;
90833
90960
 
90834
90961
  if (light) {
90835
- this.setBody(light);
90962
+ this.setBody({
90963
+ body: light
90964
+ });
90836
90965
  } else {
90837
- this.setBody(new SpotLight$1(color, intensity));
90966
+ this.setBody({
90967
+ body: new SpotLight$1(color, intensity)
90968
+ });
90838
90969
  }
90839
90970
 
90840
90971
  if (this.hasBody()) {
@@ -90930,13 +91061,6 @@ var SpotLight = /*#__PURE__*/function (_Light) {
90930
91061
  });
90931
91062
  }
90932
91063
  }
90933
- }, {
90934
- key: "toJSON",
90935
- value: function toJSON() {
90936
- return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SpotLight.prototype), "toJSON", this).call(this)), {}, {
90937
- type: SPOTLIGHT
90938
- });
90939
- }
90940
91064
  }]);
90941
91065
 
90942
91066
  return SpotLight;
@@ -90998,13 +91122,17 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
90998
91122
  intensity = _ref$intensity === void 0 ? DEFAULT_INTENSITY : _ref$intensity;
90999
91123
 
91000
91124
  if (light) {
91001
- this.setBody(light);
91125
+ this.setBody({
91126
+ body: light
91127
+ });
91002
91128
  } else {
91003
91129
  var _color$sky = color.sky,
91004
91130
  sky = _color$sky === void 0 ? DEFAULT_SKY_COLOR : _color$sky,
91005
91131
  _color$ground = color.ground,
91006
91132
  ground = _color$ground === void 0 ? DEFAULT_GROUND_COLOR : _color$ground;
91007
- this.setBody(new HemisphereLight$1(sky, ground, intensity));
91133
+ this.setBody({
91134
+ body: new HemisphereLight$1(sky, ground, intensity)
91135
+ });
91008
91136
  }
91009
91137
 
91010
91138
  if (this.hasBody()) {
@@ -91017,13 +91145,6 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
91017
91145
  this.helper = new HemisphereLightHelper(this.body, 2, GREEN);
91018
91146
  Scene$1.add(this.helper, null, false);
91019
91147
  }
91020
- }, {
91021
- key: "toJSON",
91022
- value: function toJSON() {
91023
- return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(HemisphereLight.prototype), "toJSON", this).call(this)), {}, {
91024
- type: HEMISPHERELIGHT
91025
- });
91026
- }
91027
91148
  }]);
91028
91149
 
91029
91150
  return HemisphereLight;
@@ -92603,4 +92724,4 @@ var Shaders$1 = new Shaders();var Shader = function Shader(name, attributes, uni
92603
92724
  } else {
92604
92725
  this.instance = this.shader.instance;
92605
92726
  }
92606
- };var constants = _objectSpread2$1(_objectSpread2$1({}, lib_constants), light_contants);export{AUDIO_RAMPS,AmbientLight,Atmosphere,Audio$1 as Audio,Axes,BUILTIN,BackgroundSound,BaseScript,Box,Camera,Color,Config$1 as Config,Controls$1 as Controls,Cube,CurveLine,Cylinder,DirectionalSound,ENTITY_EVENTS,ENTITY_TYPES,Element$1 as Element,Entity,EventDispatcher,FEATURES,Features$1 as Features,GameRunner$1 as GameRunner,Grid,HemisphereLight,INPUT_EVENTS,Images$1 as Images,Input$1 as Input,Label,LabelComponent,Level,LightLoader$1 as LightLoader,Lights$1 as Lights,Line,MeshLoader$1 as MeshLoader,Mirror,Models$1 as Models,Ocean,PALETTES,PARTICLES,constants$1 as PHYSICS_CONSTANTS,PHYSICS_EVENTS,ParticleEmitter,ParticleEmitterGroup,Particles$1 as Particles,index$1 as Partykals,Physics$1 as Physics,Plane,PointLight,PostProcessing$1 as PostProcessing,Proton,ProtonParticleEmitter,Provider,Router$1 as Router,Scene$1 as Scene,Scripts$1 as Scripts,Shader,Sky,Skybox,Sound,Sphere,SpotLight,Sprite,Stats$1 as Stats,SunLight,three_module as THREE,Universe$1 as Universe,Vector3$1 as Vector3,Water,author,connect,constants,createElement,functions,hitbox as hitboxUtils,index_esm as inferno,math,utils as physicsUtils,index$2 as rxjs,index as store,strings,uuid$1 as uuid,workers};
92727
+ };var constants = _objectSpread2$1(_objectSpread2$1({}, lib_constants), light_contants);export{AUDIO_RAMPS,AmbientLight,Atmosphere,Audio$1 as Audio,Axes,BUILTIN,BackgroundSound,BaseScript,Box,Camera,Color,Config$1 as Config,Controls$1 as Controls,Cube,CurveLine,Cylinder,DirectionalSound,ENTITY_EVENTS,ENTITY_TYPES,Element$1 as Element,Entity,EventDispatcher,FEATURES,Features$1 as Features,GameRunner$1 as GameRunner,Grid,HemisphereLight,INPUT_EVENTS,Images$1 as Images,Input$1 as Input,Label,LabelComponent,Level,LightLoader$1 as LightLoader,Lights$1 as Lights,Line,MeshLoader$1 as MeshLoader,Mirror,Models$1 as Models,Ocean,PALETTES,PARTICLES,constants$1 as PHYSICS_CONSTANTS,PHYSICS_EVENTS,ParticleEmitter,ParticleEmitterGroup,Particles$1 as Particles,index$1 as Partykals,Physics$1 as Physics,Plane,PointLight,PostProcessing$1 as PostProcessing,Proton,ProtonParticleEmitter,Provider,Router$1 as Router,Scene$1 as Scene,Scripts$1 as Scripts,Shader,Sky,Skybox,Sound,Sphere,SpotLight,Sprite,Stats$1 as Stats,SunLight,three_module as THREE,Universe$1 as Universe,Vector3$1 as Vector3,Water,author,connect,constants,createElement,easing,functions,hitbox as hitboxUtils,index_esm as inferno,math,utils as physicsUtils,index$2 as rxjs,index as store,strings,uuid$1 as uuid,workers};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.19.0",
3
+ "version": "3.20.0",
4
4
  "description": "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.",
5
5
  "main": "dist/mage.js",
6
6
  "author": {
@@ -42,7 +42,7 @@
42
42
  "@babel/plugin-transform-runtime": "7.5.0",
43
43
  "@babel/runtime": "7.5.0",
44
44
  "between.js": "0.1.2-fix.2",
45
- "hotkeys-js": "3.7.2",
45
+ "hotkeys-js": "3.9.4",
46
46
  "html-to-image": "^1.9.0",
47
47
  "html2canvas": "^1.4.1",
48
48
  "inferno": "7.3.2",