mage-engine 3.22.2 → 3.22.4

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 +418 -132
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -56408,7 +56408,7 @@ var Physics$1 = new Physics();var Scene = /*#__PURE__*/function () {
56408
56408
  return [{
56409
56409
  element: this.toJSON(),
56410
56410
  children: [this.getCamera().getHierarchy()].concat(_toConsumableArray(this.elements.filter(function (e) {
56411
- return !e.hasParent() && !e.isHelper();
56411
+ return !e.hasParent() && !e.isHelper() && e.isSerializable();
56412
56412
  }).map(function (e) {
56413
56413
  return e.getHierarchy();
56414
56414
  })))
@@ -57763,7 +57763,7 @@ function applyMiddleware() {
57763
57763
 
57764
57764
  var thunk = createThunkMiddleware();
57765
57765
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
57766
- var version$1 = "3.22.2";
57766
+ var version$1 = "3.22.4";
57767
57767
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
57768
57768
  var main = "dist/mage.js";
57769
57769
  var author$1 = {
@@ -60945,7 +60945,11 @@ var tweenTo = function tweenTo(origin, target) {
60945
60945
  tags: this.getTags(),
60946
60946
  name: this.getName(),
60947
60947
  uuid: this.uuid(),
60948
- data: this.getData()
60948
+ data: this.getData(),
60949
+ shadow: {
60950
+ cast: this.getBody().castShadow,
60951
+ receive: this.getBody().receiveShadow
60952
+ }
60949
60953
  };
60950
60954
  }
60951
60955
  }
@@ -61082,8 +61086,7 @@ var tweenTo = function tweenTo(origin, target) {
61082
61086
 
61083
61087
  return AnimationHandler;
61084
61088
  }(EventDispatcher);var _MATERIAL_TEXTURE_MAP;
61085
- var MATERIAL_TEXTURE_MAP = (_MATERIAL_TEXTURE_MAP = {}, _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.BASIC, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.SPECULAR]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.LAMBERT, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.SPECULAR, TEXTURES.EMISSIVE]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.PHONG, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.SPECULAR, TEXTURES.EMISSIVE, TEXTURES.BUMP, TEXTURES.DISPLACEMENT, TEXTURES.NORMAL]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.DEPTH, [TEXTURES.ALPHA, TEXTURES.MAP, TEXTURES.DISPLACEMENT]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.STANDARD, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.EMISSIVE, TEXTURES.BUMP, TEXTURES.DISPLACEMENT, TEXTURES.NORMAL, TEXTURES.METALNESS, TEXTURES.ROUGHNESS]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.THREE_TOON, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.BUMP, TEXTURES.DISPLACEMENT, TEXTURES.EMISSIVE, TEXTURES.GRADIENT, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.NORMAL]), _MATERIAL_TEXTURE_MAP);
61086
- var isTextureMapAllowedForMaterial = function isTextureMapAllowedForMaterial(materialType, textureType) {
61089
+ var MATERIAL_TEXTURE_MAP = (_MATERIAL_TEXTURE_MAP = {}, _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.BASIC, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.SPECULAR]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.LAMBERT, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.SPECULAR, TEXTURES.EMISSIVE]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.PHONG, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.SPECULAR, TEXTURES.EMISSIVE, TEXTURES.BUMP, TEXTURES.DISPLACEMENT, TEXTURES.NORMAL]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.DEPTH, [TEXTURES.ALPHA, TEXTURES.MAP, TEXTURES.DISPLACEMENT]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.STANDARD, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.ENV, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.EMISSIVE, TEXTURES.BUMP, TEXTURES.DISPLACEMENT, TEXTURES.NORMAL, TEXTURES.METALNESS, TEXTURES.ROUGHNESS]), _defineProperty$1(_MATERIAL_TEXTURE_MAP, MATERIALS.THREE_TOON, [TEXTURES.ALPHA, TEXTURES.AO, TEXTURES.BUMP, TEXTURES.DISPLACEMENT, TEXTURES.EMISSIVE, TEXTURES.GRADIENT, TEXTURES.LIGHT, TEXTURES.MAP, TEXTURES.NORMAL]), _MATERIAL_TEXTURE_MAP);var material_constants=/*#__PURE__*/Object.freeze({__proto__:null,MATERIAL_TEXTURE_MAP:MATERIAL_TEXTURE_MAP});var isTextureMapAllowedForMaterial = function isTextureMapAllowedForMaterial(materialType, textureType) {
61087
61090
  return MATERIAL_TEXTURE_MAP[materialType] && MATERIAL_TEXTURE_MAP[materialType].includes(textureType);
61088
61091
  };var _excluded$8 = ["position", "quaternion"],
61089
61092
  _excluded2 = ["applyPhysicsUpdate"],
@@ -62492,7 +62495,39 @@ var Sprite = /*#__PURE__*/function (_Element) {
62492
62495
  }]);
62493
62496
 
62494
62497
  return Sprite;
62495
- }(Element$1);var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
62498
+ }(Element$1);var HelperSprite = /*#__PURE__*/function (_Sprite) {
62499
+ _inherits(HelperSprite, _Sprite);
62500
+
62501
+ var _super = _createSuper(HelperSprite);
62502
+
62503
+ function HelperSprite() {
62504
+ var _this;
62505
+
62506
+ _classCallCheck(this, HelperSprite);
62507
+
62508
+ for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) {
62509
+ options[_key] = arguments[_key];
62510
+ }
62511
+
62512
+ _this = _super.call.apply(_super, [this].concat(options));
62513
+ _this.helperTarget = undefined;
62514
+ return _this;
62515
+ }
62516
+
62517
+ _createClass(HelperSprite, [{
62518
+ key: "setHelperTarget",
62519
+ value: function setHelperTarget(element) {
62520
+ this.helperTarget = element;
62521
+ }
62522
+ }, {
62523
+ key: "getHelperTarget",
62524
+ value: function getHelperTarget() {
62525
+ return this.helperTarget;
62526
+ }
62527
+ }]);
62528
+
62529
+ return HelperSprite;
62530
+ }(Sprite);var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
62496
62531
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
62497
62532
  return new (P || (P = Promise))(function (resolve, reject) {
62498
62533
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -82931,7 +82966,7 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
82931
82966
  _defineProperty$1(_assertThisInitialized(_this), "addHolder", function () {
82932
82967
  var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "lightholder";
82933
82968
  var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.05;
82934
- var holderSprite = new Sprite(size, size, name, {
82969
+ var holderSprite = new HelperSprite(size, size, name, {
82935
82970
  name: name
82936
82971
  });
82937
82972
 
@@ -82942,6 +82977,7 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
82942
82977
  holderSprite.setSerializable(false);
82943
82978
  holderSprite.setPosition(_this.getPosition());
82944
82979
  holderSprite.addTags([TAGS.LIGHTS.HELPER, TAGS.LIGHTS.HOLDER, name]);
82980
+ holderSprite.setHelperTarget(_assertThisInitialized(_this));
82945
82981
  _this.holder = holderSprite;
82946
82982
  return true;
82947
82983
  } else {
@@ -82953,7 +82989,7 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
82953
82989
  _defineProperty$1(_assertThisInitialized(_this), "addTargetHolder", function () {
82954
82990
  var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "targetholder";
82955
82991
  var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.05;
82956
- var targetSprite = new Sprite(size, size, name, {
82992
+ var targetSprite = new HelperSprite(size, size, name, {
82957
82993
  name: name
82958
82994
  });
82959
82995
 
@@ -82962,8 +82998,9 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
82962
82998
  targetSprite.setDepthTest(false);
82963
82999
  targetSprite.setDepthWrite(false);
82964
83000
  targetSprite.setSerializable(false);
82965
- targetSprite.setPosition(_this.getTargetPosition());
83001
+ targetSprite.setPosition(_this.getTarget().getPosition());
82966
83002
  targetSprite.addTags([TAGS.LIGHTS.HELPER, TAGS.LIGHTS.TARGET, name]);
83003
+ targetSprite.setHelperTarget(_assertThisInitialized(_this));
82967
83004
  targetSprite.getBody().add(_this.getBody().target);
82968
83005
  _this.targetHolder = targetSprite;
82969
83006
  }
@@ -83078,6 +83115,17 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
83078
83115
  value: function getColor() {
83079
83116
  return this.body.color;
83080
83117
  }
83118
+ }, {
83119
+ key: "setCastShadow",
83120
+ value: function setCastShadow(castShadow) {
83121
+ this.castShadow = castShadow;
83122
+ this.getBody().castShadow = castShadow;
83123
+ }
83124
+ }, {
83125
+ key: "getCastShadow",
83126
+ value: function getCastShadow() {
83127
+ return this.castShadow;
83128
+ }
83081
83129
  }, {
83082
83130
  key: "dim",
83083
83131
  value: function dim() {
@@ -83133,7 +83181,8 @@ var MeshLoader$1 = new MeshLoader();var Light = /*#__PURE__*/function (_Entity)
83133
83181
  type: this.getEntityType(),
83134
83182
  color: this.getColor(),
83135
83183
  intensity: this.getIntensity(),
83136
- name: this.getName()
83184
+ name: this.getName(),
83185
+ castShadow: this.getCastShadow()
83137
83186
  });
83138
83187
  }
83139
83188
  }]);
@@ -83175,7 +83224,29 @@ var SunLight = /*#__PURE__*/function (_Light) {
83175
83224
  intensity: intensity,
83176
83225
  name: name
83177
83226
  });
83227
+
83228
+ _defineProperty$1(_assertThisInitialized(_this), "setShadowCameraNearFar", function () {
83229
+ var near = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_NEAR$2;
83230
+ var far = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_FAR$2;
83231
+ _this.near = near;
83232
+ _this.far = far;
83233
+ var d = _this.far / 2;
83234
+ _this.getBody().shadow.camera.left = -d;
83235
+ _this.getBody().shadow.camera.right = d;
83236
+ _this.getBody().shadow.camera.top = d;
83237
+ _this.getBody().shadow.camera.bottom = -d;
83238
+ _this.getBody().shadow.camera.near = near;
83239
+ _this.getBody().shadow.camera.far = far;
83240
+ });
83241
+
83242
+ _defineProperty$1(_assertThisInitialized(_this), "setBias", function () {
83243
+ var bias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_BIAS$2;
83244
+ _this.bias = bias;
83245
+ _this.getBody().shadow.bias = bias;
83246
+ });
83247
+
83178
83248
  _this.options = options;
83249
+ _this.target = ORIGIN;
83179
83250
 
83180
83251
  _this.setLight({
83181
83252
  color: color,
@@ -83215,51 +83286,77 @@ var SunLight = /*#__PURE__*/function (_Light) {
83215
83286
  }, {
83216
83287
  key: "postLightCreation",
83217
83288
  value: function postLightCreation() {
83218
- var _this$options = this.options,
83219
- _this$options$positio = _this$options.position,
83220
- position = _this$options$positio === void 0 ? DEFAULT_POSITION$3 : _this$options$positio,
83221
- target = _this$options.target;
83289
+ var _this$options$positio = this.options.position,
83290
+ position = _this$options$positio === void 0 ? DEFAULT_POSITION$3 : _this$options$positio;
83291
+ var emptyTarget = new Element$1({
83292
+ body: new Object3D()
83293
+ });
83222
83294
  this.setPosition(position);
83223
-
83224
- if (target) {
83225
- this.setTarget(target);
83226
- }
83227
-
83295
+ this.setTarget(emptyTarget);
83228
83296
  this.setLightShadows();
83229
83297
  this.addToScene();
83230
83298
  }
83231
83299
  }, {
83232
83300
  key: "setLightShadows",
83233
83301
  value: function setLightShadows() {
83234
- var _this$options2 = this.options,
83235
- _this$options2$near = _this$options2.near,
83236
- near = _this$options2$near === void 0 ? DEFAULT_NEAR$2 : _this$options2$near,
83237
- _this$options2$far = _this$options2.far,
83238
- far = _this$options2$far === void 0 ? DEFAULT_FAR$2 : _this$options2$far,
83239
- _this$options2$mapSiz = _this$options2.mapSize,
83240
- mapSize = _this$options2$mapSiz === void 0 ? DEFAULT_MAP_SIZE$2 : _this$options2$mapSiz,
83241
- _this$options2$bias = _this$options2.bias,
83242
- bias = _this$options2$bias === void 0 ? DEFAULT_BIAS$2 : _this$options2$bias,
83243
- _this$options2$fov = _this$options2.fov,
83244
- fov = _this$options2$fov === void 0 ? DEFAULT_FOV : _this$options2$fov,
83245
- _this$options2$castSh = _this$options2.castShadow,
83246
- castShadow = _this$options2$castSh === void 0 ? true : _this$options2$castSh;
83247
-
83248
- if (Config$1.lights().shadows && castShadow) {
83249
- this.body.castShadow = true;
83250
- var d = far / 1.5;
83251
- this.body.shadow.mapSize.height = mapSize;
83252
- this.body.shadow.mapSize.width = mapSize;
83253
- this.body.shadow.camera.left = -d;
83254
- this.body.shadow.camera.right = d;
83255
- this.body.shadow.camera.top = d;
83256
- this.body.shadow.camera.bottom = -d;
83257
- this.body.shadow.camera.near = near;
83258
- this.body.shadow.camera.far = far;
83259
- this.body.shadow.camera.fov = fov;
83260
- this.body.shadow.bias = bias;
83302
+ var _this$options = this.options,
83303
+ _this$options$near = _this$options.near,
83304
+ near = _this$options$near === void 0 ? DEFAULT_NEAR$2 : _this$options$near,
83305
+ _this$options$far = _this$options.far,
83306
+ far = _this$options$far === void 0 ? DEFAULT_FAR$2 : _this$options$far,
83307
+ _this$options$mapSize = _this$options.mapSize,
83308
+ mapSize = _this$options$mapSize === void 0 ? DEFAULT_MAP_SIZE$2 : _this$options$mapSize,
83309
+ _this$options$bias = _this$options.bias,
83310
+ bias = _this$options$bias === void 0 ? DEFAULT_BIAS$2 : _this$options$bias,
83311
+ _this$options$fov = _this$options.fov,
83312
+ fov = _this$options$fov === void 0 ? DEFAULT_FOV : _this$options$fov;
83313
+
83314
+ if (Config$1.lights().shadows) {
83315
+ this.setCastShadow(true);
83316
+ this.setMapSize(mapSize);
83317
+ this.setShadowCameraNearFar(near, far);
83318
+ this.setBias(bias);
83319
+ this.setShadowCameraFov(fov);
83261
83320
  }
83262
83321
  }
83322
+ }, {
83323
+ key: "getShadowCameraNearFar",
83324
+ value: function getShadowCameraNearFar() {
83325
+ return {
83326
+ near: this.near,
83327
+ far: this.far
83328
+ };
83329
+ }
83330
+ }, {
83331
+ key: "setShadowCameraFov",
83332
+ value: function setShadowCameraFov() {
83333
+ var fov = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_FOV;
83334
+ this.fov = fov;
83335
+ this.getBody().shadow.camera.fov = fov;
83336
+ }
83337
+ }, {
83338
+ key: "getShadowCameraFov",
83339
+ value: function getShadowCameraFov() {
83340
+ return this.fov;
83341
+ }
83342
+ }, {
83343
+ key: "setMapSize",
83344
+ value: function setMapSize() {
83345
+ var mapSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_MAP_SIZE$2;
83346
+ this.mapSize = mapSize;
83347
+ this.getBody().shadow.mapSize.height = mapSize;
83348
+ this.getBody().shadow.mapSize.width = mapSize;
83349
+ }
83350
+ }, {
83351
+ key: "getMapSize",
83352
+ value: function getMapSize() {
83353
+ return this.mapSize;
83354
+ }
83355
+ }, {
83356
+ key: "getBias",
83357
+ value: function getBias() {
83358
+ return this.bias;
83359
+ }
83263
83360
  }, {
83264
83361
  key: "hasTarget",
83265
83362
  value: function hasTarget() {
@@ -83268,14 +83365,13 @@ var SunLight = /*#__PURE__*/function (_Light) {
83268
83365
  }, {
83269
83366
  key: "setTarget",
83270
83367
  value: function setTarget(target) {
83271
- if (target.position) {
83272
- this.body.target = target;
83273
- Scene$1.add(this.body.target, null, false);
83274
- }
83368
+ this.target = target;
83369
+ this.getBody().target = target.getBody();
83370
+ Scene$1.add(this.getBody().target, null, false);
83275
83371
  }
83276
83372
  }, {
83277
- key: "getTargetPosition",
83278
- value: function getTargetPosition() {
83373
+ key: "getTarget",
83374
+ value: function getTarget() {
83279
83375
  return this.target;
83280
83376
  }
83281
83377
  }, {
@@ -83283,7 +83379,7 @@ var SunLight = /*#__PURE__*/function (_Light) {
83283
83379
  value: function addHelpers() {
83284
83380
  var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
83285
83381
  _ref2$holderName = _ref2.holderName,
83286
- holderName = _ref2$holderName === void 0 ? "sunlightHelper" : _ref2$holderName,
83382
+ holderName = _ref2$holderName === void 0 ? "sunlightholder" : _ref2$holderName,
83287
83383
  _ref2$holderSize = _ref2.holderSize,
83288
83384
  holderSize = _ref2$holderSize === void 0 ? 0.05 : _ref2$holderSize,
83289
83385
  _ref2$targetHolderNam = _ref2.targetHolderName,
@@ -83319,7 +83415,16 @@ var SunLight = /*#__PURE__*/function (_Light) {
83319
83415
  key: "toJSON",
83320
83416
  value: function toJSON() {
83321
83417
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SunLight.prototype), "toJSON", this).call(this)), {}, {
83322
- target: this.getTargetPosition()
83418
+ target: this.getTarget(),
83419
+ distance: this.getDistance(),
83420
+ decay: this.getDecay(),
83421
+ bias: this.getBias(),
83422
+ mapSize: this.getMapSize(),
83423
+ shadowCamera: _objectSpread2$1(_objectSpread2$1({}, this.getShadowCameraNearFar()), {}, {
83424
+ fov: this.setShadowCameraFov()
83425
+ }),
83426
+ penumbra: this.getPenumbra(),
83427
+ angle: this.getAngle()
83323
83428
  });
83324
83429
  }
83325
83430
  }]);
@@ -83467,6 +83572,27 @@ var PointLight = /*#__PURE__*/function (_Light) {
83467
83572
  intensity: intensity,
83468
83573
  name: name
83469
83574
  });
83575
+
83576
+ _defineProperty$1(_assertThisInitialized(_this), "setShadowCameraNearFar", function () {
83577
+ var near = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_NEAR$1;
83578
+ var far = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_FAR$1;
83579
+ _this.near = near;
83580
+ _this.far = far;
83581
+ var d = _this.far / 2;
83582
+ _this.getBody().shadow.camera.left = -d;
83583
+ _this.getBody().shadow.camera.right = d;
83584
+ _this.getBody().shadow.camera.top = d;
83585
+ _this.getBody().shadow.camera.bottom = -d;
83586
+ _this.getBody().shadow.camera.near = near;
83587
+ _this.getBody().shadow.camera.far = far;
83588
+ });
83589
+
83590
+ _defineProperty$1(_assertThisInitialized(_this), "setBias", function () {
83591
+ var bias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_BIAS$1;
83592
+ _this.bias = bias;
83593
+ _this.getBody().shadow.bias = bias;
83594
+ });
83595
+
83470
83596
  _this.options = options;
83471
83597
 
83472
83598
  _this.setLight({
@@ -83502,8 +83628,10 @@ var PointLight = /*#__PURE__*/function (_Light) {
83502
83628
  });
83503
83629
  } else {
83504
83630
  this.setBody({
83505
- body: new PointLight$1(color, intensity, distance, decay)
83631
+ body: new PointLight$1(color, intensity)
83506
83632
  });
83633
+ this.setDistance(distance);
83634
+ this.setDecay(decay);
83507
83635
  }
83508
83636
 
83509
83637
  if (this.hasBody()) {
@@ -83533,19 +83661,62 @@ var PointLight = /*#__PURE__*/function (_Light) {
83533
83661
  bias = _this$options$bias === void 0 ? DEFAULT_BIAS$1 : _this$options$bias;
83534
83662
 
83535
83663
  if (Config$1.lights().shadows) {
83536
- this.body.castShadow = true;
83537
- var d = far / 2;
83538
- this.body.shadow.mapSize.height = mapSize;
83539
- this.body.shadow.mapSize.width = mapSize;
83540
- this.body.shadow.camera.left = -d;
83541
- this.body.shadow.camera.right = d;
83542
- this.body.shadow.camera.top = d;
83543
- this.body.shadow.camera.bottom = -d;
83544
- this.body.shadow.camera.near = near;
83545
- this.body.shadow.camera.far = far;
83546
- this.body.shadow.bias = bias;
83664
+ this.setCastShadow(true);
83665
+ this.setMapSize(mapSize);
83666
+ this.setShadowCameraNearFar(near, far);
83667
+ this.setBias(bias);
83547
83668
  }
83548
83669
  }
83670
+ }, {
83671
+ key: "setDistance",
83672
+ value: function setDistance() {
83673
+ var distance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_DISTANCE;
83674
+ this.distance = distance;
83675
+ this.getBody().distance = distance;
83676
+ }
83677
+ }, {
83678
+ key: "getDistance",
83679
+ value: function getDistance() {
83680
+ return this.distance;
83681
+ }
83682
+ }, {
83683
+ key: "setDecay",
83684
+ value: function setDecay() {
83685
+ var decay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_DECAY;
83686
+ this.decay = decay;
83687
+ this.getBody().decay = decay;
83688
+ }
83689
+ }, {
83690
+ key: "getDecay",
83691
+ value: function getDecay() {
83692
+ return this.decay;
83693
+ }
83694
+ }, {
83695
+ key: "getShadowCameraNearFar",
83696
+ value: function getShadowCameraNearFar() {
83697
+ return {
83698
+ near: this.near,
83699
+ far: this.far
83700
+ };
83701
+ }
83702
+ }, {
83703
+ key: "setMapSize",
83704
+ value: function setMapSize() {
83705
+ var mapSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_MAP_SIZE$1;
83706
+ this.mapSize = mapSize;
83707
+ this.getBody().shadow.mapSize.height = mapSize;
83708
+ this.getBody().shadow.mapSize.width = mapSize;
83709
+ }
83710
+ }, {
83711
+ key: "getMapSize",
83712
+ value: function getMapSize() {
83713
+ return this.mapSize;
83714
+ }
83715
+ }, {
83716
+ key: "getBias",
83717
+ value: function getBias() {
83718
+ return this.bias;
83719
+ }
83549
83720
  }, {
83550
83721
  key: "addHelpers",
83551
83722
  value: function addHelpers() {
@@ -83582,7 +83753,11 @@ var PointLight = /*#__PURE__*/function (_Light) {
83582
83753
  key: "toJSON",
83583
83754
  value: function toJSON() {
83584
83755
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(PointLight.prototype), "toJSON", this).call(this)), {}, {
83585
- distance: this.distance
83756
+ distance: this.getDistance(),
83757
+ decay: this.getDecay(),
83758
+ bias: this.getBias(),
83759
+ mapSize: this.getMapSize(),
83760
+ shadowCamera: this.getShadowCameraNearFar()
83586
83761
  });
83587
83762
  }
83588
83763
  }]);
@@ -91397,11 +91572,6 @@ var DEFAULT_POSITION = {
91397
91572
  y: 0,
91398
91573
  z: 0
91399
91574
  };
91400
- var DEFAULT_TARGET_POSITION = {
91401
- x: 0,
91402
- y: 0,
91403
- z: 0
91404
- };
91405
91575
  var DEFAULT_INTENSITY$1 = 0.5;
91406
91576
  var DEFAULT_MAP_SIZE = 2048;
91407
91577
  var DEFAULT_BIAS = -0.0001;
@@ -91442,6 +91612,27 @@ var SpotLight = /*#__PURE__*/function (_Light) {
91442
91612
  intensity: intensity,
91443
91613
  name: name
91444
91614
  });
91615
+
91616
+ _defineProperty$1(_assertThisInitialized(_this), "setShadowCameraNearFar", function () {
91617
+ var near = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_NEAR;
91618
+ var far = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_FAR;
91619
+ _this.near = near;
91620
+ _this.far = far;
91621
+ var d = _this.far / 2;
91622
+ _this.getBody().shadow.camera.left = -d;
91623
+ _this.getBody().shadow.camera.right = d;
91624
+ _this.getBody().shadow.camera.top = d;
91625
+ _this.getBody().shadow.camera.bottom = -d;
91626
+ _this.getBody().shadow.camera.near = near;
91627
+ _this.getBody().shadow.camera.far = far;
91628
+ });
91629
+
91630
+ _defineProperty$1(_assertThisInitialized(_this), "setBias", function () {
91631
+ var bias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_BIAS;
91632
+ _this.bias = bias;
91633
+ _this.getBody().shadow.bias = bias;
91634
+ });
91635
+
91445
91636
  _this.options = options;
91446
91637
 
91447
91638
  _this.setLight({
@@ -91484,8 +91675,12 @@ var SpotLight = /*#__PURE__*/function (_Light) {
91484
91675
  });
91485
91676
  } else {
91486
91677
  this.setBody({
91487
- body: new SpotLight$1(color, intensity, distance, angle, penumbra, decay)
91678
+ body: new SpotLight$1(color, intensity)
91488
91679
  });
91680
+ this.setDistance(distance);
91681
+ this.setAngle(angle);
91682
+ this.setPenumbra(penumbra);
91683
+ this.setDecay(decay);
91489
91684
  }
91490
91685
 
91491
91686
  if (this.hasBody()) {
@@ -91495,60 +91690,120 @@ var SpotLight = /*#__PURE__*/function (_Light) {
91495
91690
  }, {
91496
91691
  key: "postLightCreation",
91497
91692
  value: function postLightCreation() {
91498
- var _this$options = this.options,
91499
- _this$options$positio = _this$options.position,
91500
- position = _this$options$positio === void 0 ? DEFAULT_POSITION : _this$options$positio,
91501
- _this$options$target = _this$options.target,
91502
- target = _this$options$target === void 0 ? DEFAULT_TARGET_POSITION : _this$options$target;
91693
+ var _this$options$positio = this.options.position,
91694
+ position = _this$options$positio === void 0 ? DEFAULT_POSITION : _this$options$positio;
91695
+ var emptyTarget = new Element$1({
91696
+ body: new Object3D()
91697
+ });
91503
91698
  this.setPosition(position);
91504
- this.setTargetPosition(target);
91699
+ this.setTarget(emptyTarget);
91505
91700
  this.setLightShadows();
91506
91701
  this.addToScene();
91507
91702
  }
91508
91703
  }, {
91509
91704
  key: "setLightShadows",
91510
91705
  value: function setLightShadows() {
91511
- var _this$options2 = this.options,
91512
- _this$options2$near = _this$options2.near,
91513
- near = _this$options2$near === void 0 ? DEFAULT_NEAR : _this$options2$near,
91514
- _this$options2$far = _this$options2.far,
91515
- far = _this$options2$far === void 0 ? DEFAULT_FAR : _this$options2$far,
91516
- _this$options2$mapSiz = _this$options2.mapSize,
91517
- mapSize = _this$options2$mapSiz === void 0 ? DEFAULT_MAP_SIZE : _this$options2$mapSiz,
91518
- _this$options2$bias = _this$options2.bias,
91519
- bias = _this$options2$bias === void 0 ? DEFAULT_BIAS : _this$options2$bias;
91706
+ var _this$options = this.options,
91707
+ _this$options$near = _this$options.near,
91708
+ near = _this$options$near === void 0 ? DEFAULT_NEAR : _this$options$near,
91709
+ _this$options$far = _this$options.far,
91710
+ far = _this$options$far === void 0 ? DEFAULT_FAR : _this$options$far,
91711
+ _this$options$mapSize = _this$options.mapSize,
91712
+ mapSize = _this$options$mapSize === void 0 ? DEFAULT_MAP_SIZE : _this$options$mapSize,
91713
+ _this$options$bias = _this$options.bias,
91714
+ bias = _this$options$bias === void 0 ? DEFAULT_BIAS : _this$options$bias;
91520
91715
 
91521
91716
  if (Config$1.lights().shadows) {
91522
- this.body.castShadow = true;
91523
- var d = far / 2;
91524
- this.body.shadow.mapSize.height = mapSize;
91525
- this.body.shadow.mapSize.width = mapSize;
91526
- this.body.shadow.camera.left = -d;
91527
- this.body.shadow.camera.right = d;
91528
- this.body.shadow.camera.top = d;
91529
- this.body.shadow.camera.bottom = -d;
91530
- this.body.shadow.camera.near = near;
91531
- this.body.shadow.camera.far = far;
91532
- this.body.shadow.bias = bias;
91533
- }
91534
- }
91535
- }, {
91536
- key: "setTargetPosition",
91537
- value: function setTargetPosition() {
91538
- var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
91539
- this.target = _objectSpread2$1(_objectSpread2$1({}, this.target), position);
91540
- var _this$target = this.target,
91541
- _this$target$x = _this$target.x,
91542
- x = _this$target$x === void 0 ? 0 : _this$target$x,
91543
- _this$target$y = _this$target.y,
91544
- y = _this$target$y === void 0 ? 0 : _this$target$y,
91545
- _this$target$z = _this$target.z,
91546
- z = _this$target$z === void 0 ? 0 : _this$target$z;
91547
- this.body.target.position.set(x, y, z);
91548
- }
91549
- }, {
91550
- key: "getTargetPosition",
91551
- value: function getTargetPosition() {
91717
+ this.setCastShadow(true);
91718
+ this.setMapSize(mapSize);
91719
+ this.setShadowCameraNearFar(near, far);
91720
+ this.setBias(bias);
91721
+ }
91722
+ }
91723
+ }, {
91724
+ key: "setDistance",
91725
+ value: function setDistance() {
91726
+ var distance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_FAR;
91727
+ this.distance = distance;
91728
+ this.getBody().distance = distance;
91729
+ }
91730
+ }, {
91731
+ key: "getDistance",
91732
+ value: function getDistance() {
91733
+ return this.distance;
91734
+ }
91735
+ }, {
91736
+ key: "setAngle",
91737
+ value: function setAngle() {
91738
+ var angle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_SPOTLIGHT_ANGLE;
91739
+ this.angle = angle;
91740
+ this.getBody().angle = angle;
91741
+ }
91742
+ }, {
91743
+ key: "getAngle",
91744
+ value: function getAngle() {
91745
+ return this.angle;
91746
+ }
91747
+ }, {
91748
+ key: "setPenumbra",
91749
+ value: function setPenumbra() {
91750
+ var penumbra = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_SPOTLIGHT_PENUMBRA;
91751
+ this.penumbra = penumbra;
91752
+ this.getBody().penumbra = penumbra;
91753
+ }
91754
+ }, {
91755
+ key: "getPenumbra",
91756
+ value: function getPenumbra() {
91757
+ return this.penumbra;
91758
+ }
91759
+ }, {
91760
+ key: "setDecay",
91761
+ value: function setDecay() {
91762
+ var decay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_SPOTLIGHT_DECAY;
91763
+ this.decay = decay;
91764
+ this.getBody().decay = decay;
91765
+ }
91766
+ }, {
91767
+ key: "getDecay",
91768
+ value: function getDecay() {
91769
+ return this.decay;
91770
+ }
91771
+ }, {
91772
+ key: "getShadowCameraNearFar",
91773
+ value: function getShadowCameraNearFar() {
91774
+ return {
91775
+ near: this.near,
91776
+ far: this.far
91777
+ };
91778
+ }
91779
+ }, {
91780
+ key: "setMapSize",
91781
+ value: function setMapSize() {
91782
+ var mapSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_MAP_SIZE;
91783
+ this.mapSize = mapSize;
91784
+ this.getBody().shadow.mapSize.height = mapSize;
91785
+ this.getBody().shadow.mapSize.width = mapSize;
91786
+ }
91787
+ }, {
91788
+ key: "getMapSize",
91789
+ value: function getMapSize() {
91790
+ return this.mapSize;
91791
+ }
91792
+ }, {
91793
+ key: "getBias",
91794
+ value: function getBias() {
91795
+ return this.bias;
91796
+ }
91797
+ }, {
91798
+ key: "setTarget",
91799
+ value: function setTarget(target) {
91800
+ this.target = target;
91801
+ this.getBody().target = target.getBody();
91802
+ Scene$1.add(this.getBody().target, null, false);
91803
+ }
91804
+ }, {
91805
+ key: "getTarget",
91806
+ value: function getTarget() {
91552
91807
  return this.target;
91553
91808
  }
91554
91809
  }, {
@@ -91597,7 +91852,14 @@ var SpotLight = /*#__PURE__*/function (_Light) {
91597
91852
  key: "toJSON",
91598
91853
  value: function toJSON() {
91599
91854
  return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(SpotLight.prototype), "toJSON", this).call(this)), {}, {
91600
- target: this.getTargetPosition()
91855
+ target: this.getTarget(),
91856
+ distance: this.getDistance(),
91857
+ decay: this.getDecay(),
91858
+ bias: this.getBias(),
91859
+ mapSize: this.getMapSize(),
91860
+ shadowCamera: this.getShadowCameraNearFar(),
91861
+ penumbra: this.getPenumbra(),
91862
+ angle: this.getAngle()
91601
91863
  });
91602
91864
  }
91603
91865
  }]);
@@ -91634,6 +91896,23 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
91634
91896
  intensity: intensity,
91635
91897
  name: name
91636
91898
  });
91899
+
91900
+ _defineProperty$1(_assertThisInitialized(_this), "setColor", function () {
91901
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
91902
+ sky = _ref.sky,
91903
+ ground = _ref.ground;
91904
+
91905
+ _this.getBody().color = sky;
91906
+ _this.getBody().groundColor = ground;
91907
+ });
91908
+
91909
+ _defineProperty$1(_assertThisInitialized(_this), "getColor", function () {
91910
+ return {
91911
+ sky: _this.getBody().color,
91912
+ ground: _this.getBody().groundColor
91913
+ };
91914
+ });
91915
+
91637
91916
  _this.options = options;
91638
91917
 
91639
91918
  _this.setLight({
@@ -91650,15 +91929,15 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
91650
91929
 
91651
91930
  _createClass(HemisphereLight, [{
91652
91931
  key: "setLight",
91653
- value: function setLight(_ref) {
91654
- var light = _ref.light,
91655
- _ref$color = _ref.color,
91656
- color = _ref$color === void 0 ? {
91932
+ value: function setLight(_ref2) {
91933
+ var light = _ref2.light,
91934
+ _ref2$color = _ref2.color,
91935
+ color = _ref2$color === void 0 ? {
91657
91936
  sky: DEFAULT_SKY_COLOR,
91658
91937
  ground: DEFAULT_GROUND_COLOR
91659
- } : _ref$color,
91660
- _ref$intensity = _ref.intensity,
91661
- intensity = _ref$intensity === void 0 ? DEFAULT_INTENSITY : _ref$intensity;
91938
+ } : _ref2$color,
91939
+ _ref2$intensity = _ref2.intensity,
91940
+ intensity = _ref2$intensity === void 0 ? DEFAULT_INTENSITY : _ref2$intensity;
91662
91941
 
91663
91942
  if (light) {
91664
91943
  this.setBody({
@@ -91681,11 +91960,11 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
91681
91960
  }, {
91682
91961
  key: "addHelpers",
91683
91962
  value: function addHelpers() {
91684
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
91685
- _ref2$holderName = _ref2.holderName,
91686
- holderName = _ref2$holderName === void 0 ? "hemispherelightholder" : _ref2$holderName,
91687
- _ref2$holderSize = _ref2.holderSize,
91688
- holderSize = _ref2$holderSize === void 0 ? 0.05 : _ref2$holderSize;
91963
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
91964
+ _ref3$holderName = _ref3.holderName,
91965
+ holderName = _ref3$holderName === void 0 ? "hemispherelightholder" : _ref3$holderName,
91966
+ _ref3$holderSize = _ref3.holderSize,
91967
+ holderSize = _ref3$holderSize === void 0 ? 0.05 : _ref3$holderSize;
91689
91968
 
91690
91969
  this.helper = new HemisphereLightHelper(this.getBody(), 2, GREEN);
91691
91970
  this.addHolder(holderName, holderSize);
@@ -91703,6 +91982,13 @@ var HemisphereLight = /*#__PURE__*/function (_Light) {
91703
91982
  });
91704
91983
  }
91705
91984
  }
91985
+ }, {
91986
+ key: "toJSON",
91987
+ value: function toJSON() {
91988
+ return _objectSpread2$1(_objectSpread2$1({}, _get(_getPrototypeOf(HemisphereLight.prototype), "toJSON", this).call(this)), {}, {
91989
+ color: this.getColor()
91990
+ });
91991
+ }
91706
91992
  }]);
91707
91993
 
91708
91994
  return HemisphereLight;
@@ -93282,4 +93568,4 @@ var Shaders$1 = new Shaders();var Shader = function Shader(name, attributes, uni
93282
93568
  } else {
93283
93569
  this.instance = this.shader.instance;
93284
93570
  }
93285
- };var constants = _objectSpread2$1(_objectSpread2$1({}, lib_constants), light_contants);export{AUDIO_RAMPS,AmbientLight,AmbientSound,Atmosphere,Audio$1 as Audio,Axes,BUILTIN,BaseScript,Box,Camera,Color,Cone,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,index$3 as xstate};
93571
+ };var constants = _objectSpread2$1(_objectSpread2$1(_objectSpread2$1({}, lib_constants), light_contants), material_constants);export{AUDIO_RAMPS,AmbientLight,AmbientSound,Atmosphere,Audio$1 as Audio,Axes,BUILTIN,BaseScript,Box,Camera,Color,Cone,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,HelperSprite,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,index$3 as xstate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.22.2",
3
+ "version": "3.22.4",
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": {